-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove libcurl from Mac and Windows (#420)
* Add * Lint * Update github-utils.cpp * Update buildspec.json * Update build-project.yaml * Update WinRTHttpClient.cpp * Update CMakeLists.txt * Update FetchOpenCV.cmake * Update FetchOpenCV.cmake * Remove curl * Delete .gitmodules
- Loading branch information
Showing
16 changed files
with
242 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <string> | ||
#include <functional> | ||
|
||
void fetchStringFromUrl(const char *urlString, | ||
std::function<void(std::string, int)> callback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
add_library(CurlClient CurlClient.cpp) | ||
target_link_libraries(CurlClient PRIVATE OBS::libobs plugin-support) | ||
target_include_directories(CurlClient PRIVATE "${CMAKE_SOURCE_DIR}/src") | ||
|
||
find_package(CURL REQUIRED) | ||
target_link_libraries(CurlClient PRIVATE "${CURL_LIBRARIES}") | ||
target_include_directories(CurlClient SYSTEM PRIVATE "${CURL_INCLUDE_DIRS}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <string> | ||
#include <functional> | ||
|
||
#include <curl/curl.h> | ||
|
||
#include <obs.h> | ||
#include <plugin-support.h> | ||
|
||
const std::string userAgent = std::string(PLUGIN_NAME) + "/" + PLUGIN_VERSION; | ||
|
||
static std::size_t writeFunc(void *ptr, std::size_t size, size_t nmemb, | ||
std::string *data) | ||
{ | ||
data->append(static_cast<char *>(ptr), size * nmemb); | ||
return size * nmemb; | ||
} | ||
|
||
void fetchStringFromUrl(const char *urlString, | ||
std::function<void(std::string, int)> callback) | ||
{ | ||
CURL *curl = curl_easy_init(); | ||
if (!curl) { | ||
obs_log(LOG_INFO, "Failed to initialize curl"); | ||
callback("", CURL_LAST); | ||
return; | ||
} | ||
|
||
std::string responseBody; | ||
curl_easy_setopt(curl, CURLOPT_URL, urlString); | ||
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); | ||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFunc); | ||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBody); | ||
|
||
CURLcode code = curl_easy_perform(curl); | ||
curl_easy_cleanup(curl); | ||
|
||
if (code == CURLE_OK) { | ||
callback(responseBody, 0); | ||
} else { | ||
obs_log(LOG_INFO, "Failed to get latest release info"); | ||
callback("", code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_library(URLSessionClient URLSessionClient.mm) | ||
target_link_libraries(URLSessionClient PRIVATE OBS::libobs plugin-support) | ||
target_include_directories(URLSessionClient PRIVATE "${CMAKE_SOURCE_DIR}/src") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <string> | ||
#include <functional> | ||
|
||
#include <Foundation/Foundation.h> | ||
|
||
#include <obs.h> | ||
#include <plugin-support.h> | ||
|
||
void dispatch(const std::function<void(std::string, int)> &callback, | ||
std::string responseBody, int errorCode) | ||
{ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
callback(responseBody, errorCode); | ||
}); | ||
} | ||
|
||
void fetchStringFromUrl(const char *urlString, | ||
std::function<void(std::string, int)> callback) | ||
{ | ||
NSString *urlNsString = [[NSString alloc] initWithUTF8String:urlString]; | ||
NSURLSession *session = [NSURLSession sharedSession]; | ||
NSURL *url = [NSURL URLWithString:urlNsString]; | ||
NSURLSessionDataTask *task = [session | ||
dataTaskWithURL:url | ||
completionHandler:^(NSData *_Nullable data, | ||
NSURLResponse *_Nullable response, | ||
NSError *_Nullable error) { | ||
if (error != NULL) { | ||
obs_log(LOG_INFO, "error"); | ||
dispatch(callback, "", 1); | ||
} else if (response == NULL) { | ||
dispatch(callback, "", 2); | ||
} else if (data == NULL || data.length == 0) { | ||
dispatch(callback, "", 3); | ||
} else if (![response isKindOfClass:NSHTTPURLResponse | ||
.class]) { | ||
dispatch(callback, "", 4); | ||
} else { | ||
std::string responseBody( | ||
(const char *)data.bytes, data.length); | ||
NSHTTPURLResponse *httpResponse = | ||
(NSHTTPURLResponse *)response; | ||
NSInteger code = httpResponse.statusCode; | ||
dispatch(callback, responseBody, | ||
code < 200 || code > 299 ? 5 : 0); | ||
} | ||
}]; | ||
[task resume]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
add_library(WinRTHttpClient WinRTHttpClient.cpp) | ||
set_target_properties( | ||
WinRTHttpClient | ||
PROPERTIES CXX_STANDARD 17 | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_EXTENSIONS OFF | ||
VS_GLOBAL_CppWinRTOptimized true | ||
VS_GLOBAL_CppWinRTRootNamespaceAutoMerge true) | ||
target_link_libraries(WinRTHttpClient PRIVATE OBS::libobs plugin-support) | ||
target_include_directories(WinRTHttpClient PRIVATE "${CMAKE_SOURCE_DIR}/src") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <functional> | ||
|
||
#include <winrt/Windows.Foundation.h> | ||
#include <winrt/Windows.Web.Http.Headers.h> | ||
#include <winrt/windows.storage.streams.h> | ||
#include <plugin-support.h> | ||
|
||
using winrt::Windows::Foundation::Uri; | ||
using winrt::Windows::Storage::Streams::IBuffer; | ||
using winrt::Windows::Web::Http::HttpClient; | ||
using winrt::Windows::Web::Http::HttpResponseMessage; | ||
using winrt::Windows::Web::Http::IHttpContent; | ||
|
||
winrt::hstring userAgent = winrt::to_hstring(PLUGIN_NAME) + L"/" + | ||
winrt::to_hstring(PLUGIN_VERSION); | ||
|
||
void fetchStringFromUrl(const char *urlString, | ||
std::function<void(std::string, int)> callback) | ||
{ | ||
HttpClient httpClient; | ||
auto headers(httpClient.DefaultRequestHeaders()); | ||
headers.UserAgent().TryParseAdd(userAgent); | ||
Uri requestUri(winrt::to_hstring(urlString)); | ||
HttpResponseMessage httpResponseMessage; | ||
IBuffer httpResponseBuffer; | ||
try { | ||
httpResponseMessage = httpClient.GetAsync(requestUri).get(); | ||
httpResponseMessage.EnsureSuccessStatusCode(); | ||
IHttpContent httpContent = httpResponseMessage.Content(); | ||
httpResponseBuffer = httpContent.ReadAsBufferAsync().get(); | ||
|
||
uint8_t *data = httpResponseBuffer.data(); | ||
std::string str((const char *)data, | ||
httpResponseBuffer.Length()); | ||
callback(str, 0); | ||
} catch (winrt::hresult_error const &ex) { | ||
std::string str(winrt::to_string(ex.message())); | ||
callback(str, 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.