mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 14:30:02 -04:00
try to use wolfssl
This commit is contained in:
parent
bb31ef120f
commit
7550e3c1ff
7 changed files with 44 additions and 38 deletions
|
@ -11,7 +11,7 @@ WRAPPER_SOURCE="main.js"
|
||||||
|
|
||||||
EXPORTED_FUNCS="_load_certs,_perform_request"
|
EXPORTED_FUNCS="_load_certs,_perform_request"
|
||||||
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
|
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
|
||||||
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -I $INCLUDE_DIR -L $LIB_DIR"
|
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lwolfssl -lcjson -lz -lbrotlidec -lbrotlicommon -I $INCLUDE_DIR -L $LIB_DIR"
|
||||||
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sSINGLE_FILE -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
|
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sSINGLE_FILE -sASYNCIFY -sALLOW_TABLE_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
|
||||||
|
|
||||||
if [ "$1" = "release" ]; then
|
if [ "$1" = "release" ]; then
|
||||||
|
|
|
@ -30,6 +30,7 @@ void perform_request(const char* url, const char* json_params, DataCallback data
|
||||||
CURLM *multi_handle;
|
CURLM *multi_handle;
|
||||||
int still_running = 1;
|
int still_running = 1;
|
||||||
int abort_on_redirect = 0;
|
int abort_on_redirect = 0;
|
||||||
|
char error_buffer[CURL_ERROR_SIZE];
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
http_handle = curl_easy_init();
|
http_handle = curl_easy_init();
|
||||||
|
@ -39,6 +40,7 @@ void perform_request(const char* url, const char* json_params, DataCallback data
|
||||||
curl_easy_setopt(http_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
curl_easy_setopt(http_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
|
||||||
curl_easy_setopt(http_handle, CURLOPT_CAINFO, "/cacert.pem");
|
curl_easy_setopt(http_handle, CURLOPT_CAINFO, "/cacert.pem");
|
||||||
curl_easy_setopt(http_handle, CURLOPT_CAPATH, "/cacert.pem");
|
curl_easy_setopt(http_handle, CURLOPT_CAPATH, "/cacert.pem");
|
||||||
|
curl_easy_setopt(http_handle, CURLOPT_ERRORBUFFER, error_buffer);
|
||||||
|
|
||||||
//callbacks to pass the response data back to js
|
//callbacks to pass the response data back to js
|
||||||
curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, &write_function);
|
curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, &write_function);
|
||||||
|
@ -104,6 +106,8 @@ void perform_request(const char* url, const char* json_params, DataCallback data
|
||||||
|
|
||||||
CURLMcode mc;
|
CURLMcode mc;
|
||||||
struct CURLMsg *m;
|
struct CURLMsg *m;
|
||||||
|
error_buffer[0] = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
mc = curl_multi_perform(multi_handle, &still_running);
|
mc = curl_multi_perform(multi_handle, &still_running);
|
||||||
|
|
||||||
|
@ -134,6 +138,9 @@ void perform_request(const char* url, const char* json_params, DataCallback data
|
||||||
//create new json object with response info
|
//create new json object with response info
|
||||||
cJSON* response_json = cJSON_CreateObject();
|
cJSON* response_json = cJSON_CreateObject();
|
||||||
|
|
||||||
|
cJSON* error_item = cJSON_CreateString(error_buffer);
|
||||||
|
cJSON_AddItemToObject(response_json, "error", error_item);
|
||||||
|
|
||||||
cJSON* status_item = cJSON_CreateNumber(response_code);
|
cJSON* status_item = cJSON_CreateNumber(response_code);
|
||||||
cJSON_AddItemToObject(response_json, "status", status_item);
|
cJSON_AddItemToObject(response_json, "status", status_item);
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,6 @@ function perform_request(url, params, js_data_callback, js_end_callback, body=nu
|
||||||
_free(url_ptr);
|
_free(url_ptr);
|
||||||
_free(response_json_ptr);
|
_free(response_json_ptr);
|
||||||
|
|
||||||
if (error != 0) console.error("request failed with error code " + error);
|
|
||||||
js_end_callback(error, response_info);
|
js_end_callback(error, response_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +164,7 @@ function merge_arrays(arrays) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_response(response_data, response_info) {
|
function create_response(response_data, response_info) {
|
||||||
|
delete response_info.error;
|
||||||
response_info.ok = response_info.status >= 200 && response_info.status < 300;
|
response_info.ok = response_info.status >= 200 && response_info.status < 300;
|
||||||
response_info.statusText = status_messages[response_info.status] || "";
|
response_info.statusText = status_messages[response_info.status] || "";
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ function libcurl_fetch(url, params={}) {
|
||||||
|
|
||||||
let finish_callback = (error, response_info) => {
|
let finish_callback = (error, response_info) => {
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
reject("libcurl.js encountered an error: " + error);
|
reject("libcurl.js encountered an error: " + error + "\n" + response_info.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let response_data = merge_arrays(chunks);
|
let response_data = merge_arrays(chunks);
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
|
||||||
OPENSSL_PREFIX=$(realpath build/openssl-wasm)
|
WOLFSSL_PREFIX=$(realpath build/wolfssl-wasm)
|
||||||
CJSON_PREFIX=$(realpath build/cjson-wasm)
|
CJSON_PREFIX=$(realpath build/cjson-wasm)
|
||||||
CURL_PREFIX=$(realpath build/curl-wasm)
|
CURL_PREFIX=$(realpath build/curl-wasm)
|
||||||
ZLIB_PREFIX=$(realpath build/zlib-wasm)
|
ZLIB_PREFIX=$(realpath build/zlib-wasm)
|
||||||
BROTLI_PREFIX=$(realpath build/brotli-wasm)
|
BROTLI_PREFIX=$(realpath build/brotli-wasm)
|
||||||
|
|
||||||
if [ ! -d $OPENSSL_PREFIX ]; then
|
if [ ! -d $WOLFSSL_PREFIX ]; then
|
||||||
tools/openssl.sh
|
tools/openssl.sh
|
||||||
fi
|
fi
|
||||||
if [ ! -d $CJSON_PREFIX ]; then
|
if [ ! -d $CJSON_PREFIX ]; then
|
||||||
|
@ -26,7 +26,7 @@ if [ ! -d $CURL_PREFIX ]; then
|
||||||
tools/curl.sh
|
tools/curl.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp -r $OPENSSL_PREFIX/* $CURL_PREFIX
|
cp -r $WOLFSSL_PREFIX/* $CURL_PREFIX
|
||||||
cp -r $CJSON_PREFIX/* $CURL_PREFIX
|
cp -r $CJSON_PREFIX/* $CURL_PREFIX
|
||||||
cp -r $ZLIB_PREFIX/* $CURL_PREFIX
|
cp -r $ZLIB_PREFIX/* $CURL_PREFIX
|
||||||
cp -r $BROTLI_PREFIX/* $CURL_PREFIX
|
cp -r $BROTLI_PREFIX/* $CURL_PREFIX
|
|
@ -7,7 +7,7 @@ set -e
|
||||||
|
|
||||||
CORE_COUNT=$(nproc --all)
|
CORE_COUNT=$(nproc --all)
|
||||||
PREFIX=$(realpath build/curl-wasm)
|
PREFIX=$(realpath build/curl-wasm)
|
||||||
OPENSSL_PREFIX=$(realpath build/openssl-wasm)
|
WOLFSSL_PREFIX=$(realpath build/wolfssl-wasm)
|
||||||
ZLIB_PREFIX=$(realpath build/zlib-wasm)
|
ZLIB_PREFIX=$(realpath build/zlib-wasm)
|
||||||
BROTLI_PREFIX=$(realpath build/brotli-wasm)
|
BROTLI_PREFIX=$(realpath build/brotli-wasm)
|
||||||
|
|
||||||
|
@ -17,14 +17,13 @@ git clone -b master --depth=1 https://github.com/curl/curl
|
||||||
cd curl
|
cd curl
|
||||||
|
|
||||||
autoreconf -fi
|
autoreconf -fi
|
||||||
emconfigure ./configure --host i686-linux --disable-shared --disable-threaded-resolver --without-libpsl --disable-netrc --disable-ipv6 --disable-tftp --disable-ntlm-wb --with-ssl=$OPENSSL_PREFIX --with-zlib=$ZLIB_PREFIX --with-brotli=$BROTLI_PREFIX
|
emconfigure ./configure --host i686-linux --disable-shared --disable-threaded-resolver --without-libpsl --disable-netrc --disable-ipv6 --disable-tftp --disable-ntlm-wb --with-wolfssl=$WOLFSSL_PREFIX --with-zlib=$ZLIB_PREFIX --with-brotli=$BROTLI_PREFIX
|
||||||
emmake make -j$CORE_COUNT CFLAGS="-pthread" LIBS="-lbrotlicommon"
|
emmake make -j$CORE_COUNT CFLAGS="-Os -pthread" LIBS="-lbrotlicommon"
|
||||||
|
|
||||||
rm -rf $PREFIX
|
rm -rf $PREFIX
|
||||||
mkdir -p $PREFIX/include
|
mkdir -p $PREFIX/include
|
||||||
mkdir -p $PREFIX/lib
|
mkdir -p $PREFIX/lib
|
||||||
cp -r include/curl $PREFIX/include
|
cp -r include/curl $PREFIX/include
|
||||||
cp lib/.libs/libcurl.a $PREFIX/lib
|
cp lib/.libs/libcurl.a $PREFIX/lib
|
||||||
cp -r $OPENSSL_PREFIX/* $PREFIX
|
|
||||||
|
|
||||||
cd ../../
|
cd ../../
|
|
@ -1,28 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#compile openssl for use with emscripten
|
|
||||||
|
|
||||||
set -x
|
|
||||||
set -e
|
|
||||||
|
|
||||||
CORE_COUNT=$(nproc --all)
|
|
||||||
PREFIX=$(realpath build/openssl-wasm)
|
|
||||||
mkdir -p $PREFIX
|
|
||||||
|
|
||||||
cd build
|
|
||||||
rm -rf openssl
|
|
||||||
git clone -b master --depth=1 https://github.com/openssl/openssl
|
|
||||||
cd openssl
|
|
||||||
|
|
||||||
emconfigure ./Configure linux-x32 --prefix=$PREFIX -no-asm -static -no-afalgeng -no-dso -DOPENSSL_SYS_NETWARE -DSIG_DFL=0 -DSIG_IGN=0 -DHAVE_FORK=0 -DOPENSSL_NO_AFALGENG=1 -DOPENSSL_NO_SPEED=1 -DOPENSSL_NO_DYNAMIC_ENGINE -DDLOPEN_FLAG=0
|
|
||||||
sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile
|
|
||||||
emmake make -j$CORE_COUNT build_generated libssl.a libcrypto.a
|
|
||||||
|
|
||||||
rm -rf $PREFIX/include/*
|
|
||||||
rm -rf $PREFIX/lib/*
|
|
||||||
mkdir -p $PREFIX/include
|
|
||||||
mkdir -p $PREFIX/lib
|
|
||||||
cp -r include/openssl $PREFIX/include
|
|
||||||
cp libcrypto.a libssl.a $PREFIX/lib
|
|
||||||
|
|
||||||
cd ../../
|
|
28
client/tools/wolfssl.sh
Executable file
28
client/tools/wolfssl.sh
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#compile wolfssl for use with emscripten
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CORE_COUNT=$(nproc --all)
|
||||||
|
PREFIX=$(realpath build/wolfssl-wasm)
|
||||||
|
rm -rf $PREFIX
|
||||||
|
mkdir -p $PREFIX
|
||||||
|
|
||||||
|
cd build
|
||||||
|
rm -rf wolfssl
|
||||||
|
git clone -b master --depth=1 https://github.com/wolfSSL/wolfssl wolfssl
|
||||||
|
cd wolfssl
|
||||||
|
|
||||||
|
autoreconf -fi
|
||||||
|
CFLAGS="-Os -DSP_WORD_SIZE=32" emconfigure ./configure --prefix=$PREFIX --enable-curl --enable-distro --enable-static --disable-shared --host=i686-linux --disable-examples
|
||||||
|
emmake make -j$CORE_COUNT
|
||||||
|
make install
|
||||||
|
|
||||||
|
rm -rf $PREFIX/bin
|
||||||
|
rm -rf $PREFIX/share
|
||||||
|
#rm -rf $PREFIX/lib/pkgconfig
|
||||||
|
#rm -rf $PREFIX/lib/*.la
|
||||||
|
|
||||||
|
cd ../../
|
Loading…
Add table
Add a link
Reference in a new issue