mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
Update lua-https to love2d/lua-https@0b2346f.
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
// We want std::string that contains null byte, hence length of 1.
|
||||
// NOLINTNEXTLINE
|
||||
static std::string null("", 1);
|
||||
|
||||
static std::string replace(const std::string &str, const std::string &from, const std::string &to)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@@ -31,9 +35,6 @@ static std::string replace(const std::string &str, const std::string &from, cons
|
||||
|
||||
static jstring newStringUTF(JNIEnv *env, const std::string &str)
|
||||
{
|
||||
// We want std::string that contains null byte, hence length of 1.
|
||||
static std::string null("", 1);
|
||||
|
||||
std::string newStr = replace(str, null, "\xC0\x80");
|
||||
jstring jstr = env->NewStringUTF(newStr.c_str());
|
||||
return jstr;
|
||||
@@ -41,9 +42,6 @@ static jstring newStringUTF(JNIEnv *env, const std::string &str)
|
||||
|
||||
static std::string getStringUTF(JNIEnv *env, jstring str)
|
||||
{
|
||||
// We want std::string that contains null byte, hence length of 1.
|
||||
static std::string null("", 1);
|
||||
|
||||
const char *c = env->GetStringUTFChars(str, nullptr);
|
||||
std::string result = replace(c, "\xC0\x80", null);
|
||||
|
||||
@@ -53,7 +51,6 @@ static std::string getStringUTF(JNIEnv *env, jstring str)
|
||||
|
||||
AndroidClient::AndroidClient()
|
||||
: HTTPSClient()
|
||||
, SDL_AndroidGetJNIEnv(nullptr)
|
||||
{
|
||||
// Look for SDL_AndroidGetJNIEnv
|
||||
SDL_AndroidGetJNIEnv = (decltype(SDL_AndroidGetJNIEnv)) dlsym(RTLD_DEFAULT, "SDL_AndroidGetJNIEnv");
|
||||
@@ -116,12 +113,14 @@ HTTPSClient::Reply AndroidClient::request(const HTTPSClient::Request &req)
|
||||
env->DeleteLocalRef(method);
|
||||
|
||||
// Set post data
|
||||
if (req.postdata.size() > 0)
|
||||
if (!req.postdata.empty())
|
||||
{
|
||||
jmethodID setPostData = env->GetMethodID(httpsClass, "setPostData", "([B)V");
|
||||
jbyteArray byteArray = env->NewByteArray((jsize) req.postdata.length());
|
||||
jbyte *byteArrayData = env->GetByteArrayElements(byteArray, nullptr);
|
||||
|
||||
// The usage of memcpy is intentional.
|
||||
// NOLINTNEXTLINE
|
||||
memcpy(byteArrayData, req.postdata.data(), req.postdata.length());
|
||||
env->ReleaseByteArrayElements(byteArray, byteArrayData, 0);
|
||||
|
||||
@@ -156,9 +155,9 @@ HTTPSClient::Reply AndroidClient::request(const HTTPSClient::Request &req)
|
||||
{
|
||||
// Get headers
|
||||
jobjectArray interleavedHeaders = (jobjectArray) env->CallObjectMethod(httpsObject, getInterleavedHeaders);
|
||||
int len = env->GetArrayLength(interleavedHeaders);
|
||||
int headerLen = env->GetArrayLength(interleavedHeaders);
|
||||
|
||||
for (int i = 0; i < len; i += 2)
|
||||
for (int i = 0; i < headerLen; i += 2)
|
||||
{
|
||||
jstring key = (jstring) env->GetObjectArrayElement(interleavedHeaders, i);
|
||||
jstring value = (jstring) env->GetObjectArrayElement(interleavedHeaders, i + 1);
|
||||
@@ -176,15 +175,17 @@ HTTPSClient::Reply AndroidClient::request(const HTTPSClient::Request &req)
|
||||
|
||||
if (responseData)
|
||||
{
|
||||
int len = env->GetArrayLength(responseData);
|
||||
int responseLen = env->GetArrayLength(responseData);
|
||||
jbyte *responseByte = env->GetByteArrayElements(responseData, nullptr);
|
||||
|
||||
response.body = std::string((char *) responseByte, len);
|
||||
response.body = std::string((char *) responseByte, responseLen);
|
||||
|
||||
env->DeleteLocalRef(responseData);
|
||||
}
|
||||
}
|
||||
|
||||
env->DeleteLocalRef(httpsObject);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
// MSVC warnings
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#if defined(HTTPS_HAVE_CONFIG_GENERATED_H)
|
||||
#include "common/config-generated.h"
|
||||
#elif defined(WIN32) || defined(_WIN32)
|
||||
@@ -10,6 +15,12 @@
|
||||
// WinINet is only supported on desktop.
|
||||
#define HTTPS_BACKEND_WININET
|
||||
#endif
|
||||
// Visual Studio 2017 supports __has_include
|
||||
#if defined __has_include
|
||||
#if __has_include(<curl/curl.h>)
|
||||
#define HTTPS_BACKEND_CURL
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__ANDROID__)
|
||||
#define HTTPS_BACKEND_ANDROID
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
Reference in New Issue
Block a user