diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-16 21:42:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-16 21:42:35 +0200 |
commit | 726e1c9b1d4bb50e0b13be3a0e527a37032dc1e5 (patch) | |
tree | e320777033a3eebe2cb32f37c652c9e49aebbafe | |
parent | 5ac6f8fd99df95071953c4c92947f4a28326cc39 (diff) | |
download | twister-726e1c9b1d4bb50e0b13be3a0e527a37032dc1e5.tar.gz twister-726e1c9b1d4bb50e0b13be3a0e527a37032dc1e5.tar.bz2 twister-726e1c9b1d4bb50e0b13be3a0e527a37032dc1e5.zip |
set size of upload if available
-rw-r--r-- | src/twister/taler-twister-service.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c index ea26ad0..1fb27c5 100644 --- a/src/twister/taler-twister-service.c +++ b/src/twister/taler-twister-service.c @@ -248,7 +248,7 @@ static char *target_server_base_url; static unsigned int hack_response_code; /** - * Will point to a JSON object to delete + * Will point to a JSON object to delete */ static char delete_path[TWISTER_PATH_LENGTH] = {'\0'}; @@ -261,7 +261,7 @@ static char flip_path_dl[TWISTER_PATH_LENGTH] = {'\0'}; static char flip_path_ul[TWISTER_PATH_LENGTH] = {'\0'}; /** - * Will point to a JSON object to modify + * Will point to a JSON object to modify */ static char modify_path[TWISTER_PATH_LENGTH] = {'\0'}; @@ -585,9 +585,9 @@ curl_upload_cb (void *buf, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Uploader cb, size: %u.\n", - size); + (unsigned int) size); - if (REQUEST_STATE_UPLOAD_STARTED != hr->state) + if (REQUEST_STATE_UPLOAD_STARTED != hr->state) { GNUNET_break (0); return CURL_READFUNC_ABORT; @@ -844,7 +844,7 @@ con_val_iter (void *cls, if (GNUNET_YES == malform_upload) { - if (0 == strcmp ("Content-Length", key)) + if (0 == strcmp ("Content-Length", key)) { GNUNET_asprintf (&new_value, "%lu", @@ -919,7 +919,7 @@ walk_response_object (const char *path, last_token, last_token); if (NULL == token) return GNUNET_SYSERR; // path was ".", refuse to process it. - + if (NULL != (cur = json_object_get (element, token))) { @@ -954,7 +954,7 @@ walk_response_object (const char *path, (token, NULL, 10))) ) { TALER_LOG_WARNING ("(Last) path token '%s' not found\n", - last_token); + last_token); GNUNET_free (path_dup); return GNUNET_NO; } @@ -994,7 +994,7 @@ modify_object (struct MHD_Connection *con, new_value = json_true (); goto perform_modbody; } - + if (NULL != (new_value = json_loads (modify_value, JSON_REJECT_DUPLICATES | JSON_DISABLE_EOF_CHECK, @@ -1011,7 +1011,7 @@ modify_object (struct MHD_Connection *con, } TALER_LOG_ERROR ("Unvalid new value given: %s\n", modify_value); - modify_path[0] = '\0'; + modify_path[0] = '\0'; GNUNET_free (target); json_decref (new_value); return; @@ -1029,7 +1029,7 @@ modify_object (struct MHD_Connection *con, new_value); if (-1 == ret_modify) TALER_LOG_WARNING ("Could not replace '%s'\n", target); - + modify_path[0] = '\0'; GNUNET_free (target); json_decref (new_value); @@ -1246,7 +1246,7 @@ create_response (void *cls, (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len); hr->io_len = malformed_size; } - + if ('\0' != flip_path_ul[0]) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1317,7 +1317,7 @@ create_response (void *cls, 0); { char *curlurl; - + GNUNET_asprintf (&curlurl, "%s%s", target_server_base_url, @@ -1339,6 +1339,21 @@ create_response (void *cls, curl_easy_setopt (hr->curl, CURLOPT_READDATA, hr); + { + const char *us; + long upload_size; + + us = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + MHD_HTTP_HEADER_CONTENT_LENGTH); + if ( (1 == sscanf (us, + "%ld", + &upload_size)) && + (upload_size >= 0) ) + curl_easy_setopt (hr->curl, + CURLOPT_INFILESIZE, + upload_size); + } curl_easy_setopt (hr->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); @@ -1359,6 +1374,23 @@ create_response (void *cls, curl_easy_setopt (hr->curl, CURLOPT_READDATA, hr); + { + const char *us; + long upload_size; + + us = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + MHD_HTTP_HEADER_CONTENT_LENGTH); + if ( (1 == sscanf (us, + "%ld", + &upload_size)) && + (upload_size >= 0) ) + { + curl_easy_setopt (hr->curl, + CURLOPT_INFILESIZE, + upload_size); + } + } curl_easy_setopt (hr->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); @@ -1452,7 +1484,7 @@ create_response (void *cls, if (REQUEST_STATE_DOWNLOAD_DONE != hr->state) return MHD_YES; /* wait for curl */ - + if (0 != hack_response_code) { hr->response_code = hack_response_code; @@ -1499,7 +1531,7 @@ create_response (void *cls, ("Will (badly) truncate the response.\n"); fake_len = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, hr->io_len); - hr->io_len = fake_len; + hr->io_len = fake_len; malform = GNUNET_NO; } @@ -1780,7 +1812,7 @@ run_mhd_now (void) static void do_shutdown (void *cls) { - (void) cls; + (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); kill_httpd (); |