diff --git a/client/build.sh b/client/build.sh index 57dfd04..436208d 100755 --- a/client/build.sh +++ b/client/build.sh @@ -11,7 +11,7 @@ WRAPPER_SOURCE="main.js" EXPORTED_FUNCS="_load_certs,_perform_request" 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" if [ "$1" = "release" ]; then diff --git a/client/main.c b/client/main.c index 9e7f7fc..6b32d39 100644 --- a/client/main.c +++ b/client/main.c @@ -30,6 +30,7 @@ void perform_request(const char* url, const char* json_params, DataCallback data CURLM *multi_handle; int still_running = 1; int abort_on_redirect = 0; + char error_buffer[CURL_ERROR_SIZE]; curl_global_init(CURL_GLOBAL_DEFAULT); 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_CAINFO, "/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 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; struct CURLMsg *m; + error_buffer[0] = 0; + do { 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 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_AddItemToObject(response_json, "status", status_item); diff --git a/client/main.js b/client/main.js index d8ff917..5f13cb5 100644 --- a/client/main.js +++ b/client/main.js @@ -137,7 +137,6 @@ function perform_request(url, params, js_data_callback, js_end_callback, body=nu _free(url_ptr); _free(response_json_ptr); - if (error != 0) console.error("request failed with error code " + error); js_end_callback(error, response_info); } @@ -165,6 +164,7 @@ function merge_arrays(arrays) { } function create_response(response_data, response_info) { + delete response_info.error; response_info.ok = response_info.status >= 200 && response_info.status < 300; response_info.statusText = status_messages[response_info.status] || ""; @@ -214,7 +214,7 @@ function libcurl_fetch(url, params={}) { let finish_callback = (error, response_info) => { if (error != 0) { - reject("libcurl.js encountered an error: " + error); + reject("libcurl.js encountered an error: " + error + "\n" + response_info.error); return; } let response_data = merge_arrays(chunks); diff --git a/client/tools/all_deps.sh b/client/tools/all_deps.sh index e59f563..20fbeb5 100755 --- a/client/tools/all_deps.sh +++ b/client/tools/all_deps.sh @@ -4,13 +4,13 @@ mkdir -p build -OPENSSL_PREFIX=$(realpath build/openssl-wasm) +WOLFSSL_PREFIX=$(realpath build/wolfssl-wasm) CJSON_PREFIX=$(realpath build/cjson-wasm) CURL_PREFIX=$(realpath build/curl-wasm) ZLIB_PREFIX=$(realpath build/zlib-wasm) BROTLI_PREFIX=$(realpath build/brotli-wasm) -if [ ! -d $OPENSSL_PREFIX ]; then +if [ ! -d $WOLFSSL_PREFIX ]; then tools/openssl.sh fi if [ ! -d $CJSON_PREFIX ]; then @@ -26,7 +26,7 @@ if [ ! -d $CURL_PREFIX ]; then tools/curl.sh fi -cp -r $OPENSSL_PREFIX/* $CURL_PREFIX +cp -r $WOLFSSL_PREFIX/* $CURL_PREFIX cp -r $CJSON_PREFIX/* $CURL_PREFIX cp -r $ZLIB_PREFIX/* $CURL_PREFIX cp -r $BROTLI_PREFIX/* $CURL_PREFIX \ No newline at end of file diff --git a/client/tools/curl.sh b/client/tools/curl.sh index cd4e40e..a442565 100755 --- a/client/tools/curl.sh +++ b/client/tools/curl.sh @@ -7,7 +7,7 @@ set -e CORE_COUNT=$(nproc --all) PREFIX=$(realpath build/curl-wasm) -OPENSSL_PREFIX=$(realpath build/openssl-wasm) +WOLFSSL_PREFIX=$(realpath build/wolfssl-wasm) ZLIB_PREFIX=$(realpath build/zlib-wasm) BROTLI_PREFIX=$(realpath build/brotli-wasm) @@ -17,14 +17,13 @@ git clone -b master --depth=1 https://github.com/curl/curl cd curl 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 -emmake make -j$CORE_COUNT CFLAGS="-pthread" LIBS="-lbrotlicommon" +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="-Os -pthread" LIBS="-lbrotlicommon" rm -rf $PREFIX mkdir -p $PREFIX/include mkdir -p $PREFIX/lib cp -r include/curl $PREFIX/include cp lib/.libs/libcurl.a $PREFIX/lib -cp -r $OPENSSL_PREFIX/* $PREFIX cd ../../ \ No newline at end of file diff --git a/client/tools/openssl.sh b/client/tools/openssl.sh deleted file mode 100755 index c87781e..0000000 --- a/client/tools/openssl.sh +++ /dev/null @@ -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 ../../ \ No newline at end of file diff --git a/client/tools/wolfssl.sh b/client/tools/wolfssl.sh new file mode 100755 index 0000000..bd08831 --- /dev/null +++ b/client/tools/wolfssl.sh @@ -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 ../../ \ No newline at end of file