Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http debug #89

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/jni/lib_http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <log.h>
#include <curl/curl.h>
#include <thread>
#ifndef HTTPCLIENT_NDEBUG
#include <iostream>
#endif

using namespace std::placeholders;

Expand All @@ -29,7 +32,8 @@ std::shared_ptr<HttpClientRequest> HttpClientRequest::createClientRequest() {
}

void HttpClientRequest::setHttpUrl(std::shared_ptr<FakeJni::JString> url) {
#ifndef NDEBUG
#ifndef HTTPCLIENT_NDEBUG
this->url = url->asStdString();
Log::trace("HttpClient", "URL: %s", url->asStdString().c_str());
#endif
curl_easy_setopt(curl, CURLOPT_URL, url->asStdString().c_str());
Expand Down Expand Up @@ -64,7 +68,9 @@ void HttpClientRequest::setHttpMethodAndBody(std::shared_ptr<FakeJni::JString> m
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userdata) {
auto stream = (NativeInputStream *)userdata;
try {
return stream->Read(ptr, size * nmemb);
auto ret = stream->Read(ptr, size * nmemb);
std::cout << "HTTPContent:\n" << std::string_view(ptr, ret) << "\n";
return ret;
} catch(...) {
#ifdef CURL_READFUNC_ABORT
return CURL_READFUNC_ABORT;
Expand Down Expand Up @@ -98,15 +104,15 @@ void HttpClientRequest::setHttpMethodAndBody2(std::shared_ptr<FakeJni::JString>
} else if (this->method == "PUT") {
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) contentLength);
}
#ifndef NDEBUG
#ifndef HTTPCLIENT_NDEBUG
Log::trace("HttpClient", "setHttpMethodAndBody2 called, sent request");
#endif
} else {
if (this->method == "POST") {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
}
#ifndef NDEBUG
#ifndef HTTPCLIENT_NDEBUG
Log::trace("HttpClient", "setHttpMethodAndBody2 called, method: %s", this->method.c_str());
#endif
}
Expand All @@ -120,8 +126,11 @@ void HttpClientRequest::setHttpMethodAndBody2(std::shared_ptr<FakeJni::JString>
}

void HttpClientRequest::setHttpHeader(std::shared_ptr<FakeJni::JString> name, std::shared_ptr<FakeJni::JString> value) {
#ifndef NDEBUG
Log::trace("HttpClient", "setHttpHeader called, name: %s, value: %s", name->asStdString().c_str(), value->asStdString().c_str());
#ifndef HTTPCLIENT_NDEBUG
Log::trace("HttpClient", "%s setHttpHeader called, name: %s, value: %s", url.data(), name->asStdString().c_str(), value->asStdString().c_str());
if(name->asStdString() == "Authorization") {
Log::trace("HttpClient", "Auth");
}
#endif
header = curl_slist_append(header, (name->asStdString() + ": " + value->asStdString()).c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
Expand All @@ -141,7 +150,7 @@ void HttpClientRequest::doRequestAsync(FakeJni::JLong sourceCall) {
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
FakeJni::LocalFrame frame;
if(ret == CURLE_OK) {
#ifndef NDEBUG
#ifndef HTTPCLIENT_NDEBUG
Log::trace("HttpClient", "Response: code: %ld", response_code);
#endif
auto method = getClass().getMethod("(JLcom/xbox/httpclient/HttpClientResponse;)V", "OnRequestCompleted");
Expand Down Expand Up @@ -192,6 +201,9 @@ HttpClientResponse::HttpClientResponse(FakeJni::JLong call_handle, int response_

size_t HttpClientRequest::write_callback(char *ptr, size_t size, size_t nmemb) {
try {
#ifndef HTTPCLIENT_NDEBUG
std::cout << "HTTPBody: " << url.data() << "\n" << std::string_view(ptr, size * nmemb) << "\n";
#endif
auto byteArray = std::make_shared<FakeJni::JByteArray>(nmemb);
memcpy(byteArray->getArray(), ptr, nmemb);
std::make_shared<NativeOutputStream>(call_handle)->WriteAll(byteArray);
Expand Down
2 changes: 1 addition & 1 deletion src/jni/lib_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NativeInputStream : public FakeJni::JObject {

class HttpClientRequest : public FakeJni::JObject {
std::shared_ptr<NativeInputStream> inputStream;

std::string url;
public:
DEFINE_CLASS_NAME("com/xbox/httpclient/HttpClientRequest")
HttpClientRequest();
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ Hardware : Qualcomm Technologies, Inc MSM8998
// GLFW needs a window to let eglGetProcAddress return symbols
FakeLooper::initWindow();
MinecraftUtils::setupGLES2Symbols(fake_egl::eglGetProcAddress);
// preinit Mods using libGLESv2 can only load now
modLoader.loadModsFromDirectory(PathHelper::getPrimaryDataDirectory() + "mods/", true);
// Try load the game again
handle = MinecraftUtils::loadMinecraftLib(reinterpret_cast<void*>(&CorePatches::showMousePointer), reinterpret_cast<void*>(&CorePatches::hideMousePointer), reinterpret_cast<void*>(&CorePatches::setFullscreen));
}
Expand Down
Loading