-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43bfbb6
commit 337c91b
Showing
27 changed files
with
677 additions
and
183 deletions.
There are no files selected for viewing
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,35 @@ | ||
## android building | ||
|
||
first it's time to clone openssl: | ||
|
||
```sh | ||
cd libs/ | ||
git clone https://github.com/openssl/openssl.git | ||
cd openssl | ||
``` | ||
|
||
then you want to configure it: | ||
|
||
```sh | ||
export NDK_HOME=/opt/android-ndk # set path to your ndk if it's different | ||
PATH=$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64:$PATH ./Configure android-arm -D__ANDROID_API__=24 | ||
``` | ||
|
||
then you want to build it, BUT keep in mind there's no need to build the whole thing. all you want is for codegen to run, you won't need the actual built libraries as they are already provided by geode. | ||
|
||
```sh | ||
make | ||
``` | ||
|
||
after you stop seeing lines that look similar to these: | ||
|
||
```sh | ||
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/x509.h.in > include/openssl/x509.h | ||
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/x509_vfy.h.in > include/openssl/x509_vfy.h | ||
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" include/openssl/x509v3.h.in > include/openssl/x509v3.h | ||
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" "-oMakefile" test/provider_internal_test.cnf.in > test/provider_internal_test.cnf | ||
``` | ||
|
||
you can Ctrl+C and stop the build. **If `make` fails and shows an error, that is fine! As long as the headers were generated properly, there is no need to worry.** | ||
|
||
after that's done you just proceed to build the mod like any other android mod. **make sure to set minimum SDK version to 24, or you will get linker errors!** |
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
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,117 @@ | ||
#include "client.hpp" | ||
|
||
#include <util/time.hpp> | ||
|
||
GLOBED_SINGLETON_DEF(GHTTPClient) | ||
|
||
GHTTPClient::GHTTPClient() { | ||
curl = curl_easy_init(); | ||
GLOBED_REQUIRE(curl != nullptr, "cURL failed to initialize") | ||
|
||
threadHandle = std::thread(&GHTTPClient::threadFunc, this); | ||
} | ||
|
||
GHTTPClient::~GHTTPClient() { | ||
_running = false; | ||
if (threadHandle.joinable()) threadHandle.join(); | ||
|
||
if (curl) { | ||
curl_easy_cleanup(curl); | ||
curl = nullptr; | ||
} | ||
|
||
geode::log::debug("HTTP client thread halted"); | ||
} | ||
|
||
void GHTTPClient::send(GHTTPRequestHandle request) { | ||
requests.push(request); | ||
} | ||
|
||
void GHTTPClient::threadFunc() { | ||
while (_running) { | ||
if (!requests.waitForMessages(util::time::secs(1))) continue; | ||
|
||
auto request = requests.pop(); | ||
auto response = this->performRequest(request); | ||
|
||
geode::Loader::get()->queueInMainThread([response, request] { | ||
request.maybeCallback(response); | ||
}); | ||
} | ||
} | ||
|
||
static size_t writeCallback(void* contents, size_t size, size_t nmemb, std::ostringstream* stream) { | ||
size_t totalSize = size * nmemb; | ||
*stream << std::string(static_cast<char*>(contents), totalSize); | ||
return totalSize; | ||
} | ||
|
||
GHTTPResponse GHTTPClient::performRequest(GHTTPRequestHandle handle) { | ||
GHTTPResponse response; | ||
|
||
GHTTPRequest& req = *handle.handle.get(); | ||
|
||
// clear leftover data from previous request | ||
curl_easy_reset(curl); | ||
|
||
switch (req.rType) { | ||
case GHTTPRequestType::GET: | ||
break; | ||
case GHTTPRequestType::POST: | ||
curl_easy_setopt(curl, CURLOPT_POST, 1L); | ||
break; | ||
case GHTTPRequestType::PUT: | ||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); | ||
break; | ||
case GHTTPRequestType::DELETE_: | ||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); | ||
break; | ||
} | ||
|
||
if (!req.rData.empty()) { | ||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req.rData.c_str()); | ||
} | ||
|
||
curl_easy_setopt(curl, CURLOPT_USERAGENT, req.rUserAgent.c_str()); | ||
curl_easy_setopt(curl, CURLOPT_URL, req.rUrl.c_str()); | ||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, req.rFollowRedirects); | ||
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, (long)req.rTimeout); | ||
|
||
// security is for nerds | ||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); | ||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); | ||
|
||
// http headers | ||
struct curl_slist* headerList = nullptr; | ||
if (!req.rHeaders.empty()) { | ||
for (const auto& header: req.rHeaders) { | ||
headerList = curl_slist_append(headerList, header.c_str()); | ||
} | ||
|
||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList); | ||
} | ||
|
||
std::ostringstream ss; | ||
|
||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); | ||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ss); | ||
|
||
response.resCode = curl_easy_perform(curl); | ||
response.failed = response.resCode != CURLE_OK; | ||
|
||
if (response.failed) { | ||
response.failMessage = curl_easy_strerror(response.resCode); | ||
} else { | ||
long httpCode; | ||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); | ||
|
||
response.statusCode = httpCode; | ||
response.response = ss.str(); | ||
} | ||
|
||
if (headerList != nullptr) { | ||
curl_slist_free_all(headerList); | ||
} | ||
|
||
return response; | ||
} |
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,28 @@ | ||
#pragma once | ||
#include <defs.hpp> | ||
|
||
#include <queue> | ||
#include <thread> | ||
|
||
#include "request.hpp" | ||
#include <util/sync.hpp> | ||
|
||
class GHTTPClient { | ||
GLOBED_SINGLETON(GHTTPClient) | ||
GHTTPClient(); | ||
~GHTTPClient(); | ||
|
||
// add the request to the queue of pending requests | ||
void send(GHTTPRequestHandle request); | ||
|
||
protected: | ||
CURL* curl; | ||
std::thread threadHandle; | ||
|
||
util::sync::AtomicBool _running = true; | ||
util::sync::SmartMessageQueue<GHTTPRequestHandle> requests; | ||
|
||
void threadFunc(); | ||
|
||
GHTTPResponse performRequest(GHTTPRequestHandle req); | ||
}; |
Oops, something went wrong.