tool_easysrc: reset the handle between --next operations
No binary (build failed)
—
(log yok)
| @@ -42,6 +42,13 @@ int easysrc_mime_count; | |
| int easysrc_slist_count; | |
| static bool easysrc_performed; | |
| + | /* Set once a transfer has been performed, so that the next generated |
| + | statement resets the handle first: the tool uses a fresh easy handle per |
| + | operation, the generated code reuses one. Deferred rather than emitted |
| + | right after curl_easy_perform() so that no reset is generated when nothing |
| + | follows. */ |
| + | static bool easysrc_pending_reset = FALSE; |
| + | |
| static const char * const srchead[] = { | |
| "/********* Sample code generated by the curl command line tool **********", | |
| " * All curl_easy_setopt() options are documented at:", | |
| @@ -92,7 +99,15 @@ static void easysrc_free(void) | |
| CURLcode easysrc_add(struct slist_wc **plist, const char *line) | |
| { | |
| CURLcode result = CURLE_OK; | |
| - | struct slist_wc *list = slist_wc_append(*plist, line); |
| + | struct slist_wc *list; |
| + | if(easysrc_pending_reset && (plist == &easysrc_code)) { |
| + | /* cleared first: the recursive call adds to easysrc_code as well */ |
| + | easysrc_pending_reset = FALSE; |
| + | result = easysrc_add(&easysrc_code, "curl_easy_reset(curl);"); |
| + | if(result) |
| + | return result; |
| + | } |
| + | list = slist_wc_append(*plist, line); |
| if(!list) { | |
| easysrc_free(); | |
| result = CURLE_OUT_OF_MEMORY; | |
| @@ -165,12 +180,19 @@ CURLcode easysrc_perform(void) | |
| if(!result) | |
| easysrc_performed = TRUE; | |
| + | /* Options set for this operation must not leak into the next one */ |
| + | if(!result) |
| + | easysrc_pending_reset = TRUE; |
| + | |
| return result; | |
| } | |
| CURLcode easysrc_cleanup(void) | |
| { | |
| - | CURLcode result = easysrc_add(&easysrc_code, "curl_easy_cleanup(curl);"); |
| + | CURLcode result; |
| + | /* nothing follows, so no reset is needed before the cleanup */ |
| + | easysrc_pending_reset = FALSE; |
| + | result = easysrc_add(&easysrc_code, "curl_easy_cleanup(curl);"); |
| if(!result) | |
| result = easysrc_add(&easysrc_code, "curl = NULL;"); | |
| @@ -1708,6 +1708,7 @@ TESTCASES = \ | |
| test1684 \ | |
| test1685 \ | |
| test1686 \ | |
| + | test1687 \ |
| \ | |
| test1700 \ | |
| test1702 \ | |
| @@ -2157,6 +2158,7 @@ EXTRA_DIST = \ | |
| data1465.c \ | |
| data1481.c \ | |
| data1679.c \ | |
| + | data1687.c \ |
| data1705-1.md \ | |
| data1705-2.md \ | |
| data1705-3.md \ | |
| @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) | |
| result = curl_easy_perform(curl); | |
| + | curl_easy_reset(curl); |
| curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | |
| curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L); | |
| curl_easy_setopt(curl, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER"); | |
| @@ -0,0 +1,82 @@ | |
| + | /********* Sample code generated by the curl command line tool ********** |
| + | * All curl_easy_setopt() options are documented at: |
| + | * https://curl.se/libcurl/c/curl_easy_setopt.html |
| + | ************************************************************************/ |
| + | #include <curl/curl.h> |
| + | |
| + | int main(int argc, char *argv[]) |
| + | { |
| + | CURLcode result; |
| + | CURL *curl; |
| + | struct curl_slist *slist1; |
| + | |
| + | slist1 = NULL; |
| + | slist1 = curl_slist_append(slist1, "X-First: yes"); |
| + | |
| + | curl = curl_easy_init(); |
| + | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); |
| + | curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L); |
| + | curl_easy_setopt(curl, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER"); |
| + | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); |
| + | curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/%VERSION"); |
| + | curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); |
| + | curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); |
| + | |
| + | /* Here is a list of options the curl code used that cannot get generated |
| + | as source easily. You may choose to either not use them or implement |
| + | them yourself. |
| + | |
| + | CURLOPT_DEBUGFUNCTION was set to a function pointer |
| + | CURLOPT_DEBUGDATA was set to an object pointer |
| + | CURLOPT_WRITEDATA was set to an object pointer |
| + | CURLOPT_WRITEFUNCTION was set to a function pointer |
| + | CURLOPT_READDATA was set to an object pointer |
| + | CURLOPT_READFUNCTION was set to a function pointer |
| + | CURLOPT_SEEKDATA was set to an object pointer |
| + | CURLOPT_SEEKFUNCTION was set to a function pointer |
| + | CURLOPT_HEADERFUNCTION was set to a function pointer |
| + | CURLOPT_HEADERDATA was set to an object pointer |
| + | CURLOPT_ERRORBUFFER was set to an object pointer |
| + | CURLOPT_STDERR was set to an object pointer |
| + | |
| + | */ |
| + | |
| + | result = curl_easy_perform(curl); |
| + | |
| + | curl_easy_reset(curl); |
| + | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); |
| + | curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L); |
| + | curl_easy_setopt(curl, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER"); |
| + | curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/%VERSION"); |
| + | curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); |
| + | curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); |
| + | |
| + | /* Here is a list of options the curl code used that cannot get generated |
| + | as source easily. You may choose to either not use them or implement |
| + | them yourself. |
| + | |
| + | CURLOPT_DEBUGFUNCTION was set to a function pointer |
| + | CURLOPT_DEBUGDATA was set to an object pointer |
| + | CURLOPT_WRITEDATA was set to an object pointer |
| + | CURLOPT_WRITEFUNCTION was set to a function pointer |
| + | CURLOPT_READDATA was set to an object pointer |
| + | CURLOPT_READFUNCTION was set to a function pointer |
| + | CURLOPT_SEEKDATA was set to an object pointer |
| + | CURLOPT_SEEKFUNCTION was set to a function pointer |
| + | CURLOPT_HEADERFUNCTION was set to a function pointer |
| + | CURLOPT_HEADERDATA was set to an object pointer |
| + | CURLOPT_ERRORBUFFER was set to an object pointer |
| + | CURLOPT_STDERR was set to an object pointer |
| + | |
| + | */ |
| + | |
| + | result = curl_easy_perform(curl); |
| + | |
| + | curl_easy_cleanup(curl); |
| + | curl = NULL; |
| + | curl_slist_free_all(slist1); |
| + | slist1 = NULL; |
| + | |
| + | return (int)result; |
| + | } |
| + | /**** End of sample code ****/ |
| @@ -0,0 +1,75 @@ | |
| + | <?xml version="1.0" encoding="US-ASCII"?> |
| + | <testcase> |
| + | <info> |
| + | <keywords> |
| + | HTTP |
| + | HTTP GET |
| + | --libcurl |
| + | --next |
| + | </keywords> |
| + | </info> |
| + | |
| + | # Server-side |
| + | <reply> |
| + | <data nocheck="yes"> |
| + | HTTP/1.1 200 OK |
| + | Date: Thu, 29 Jul 2008 14:49:00 GMT |
| + | Server: test-server/fake |
| + | Content-Length: 0 |
| + | Connection: close |
| + | |
| + | </data> |
| + | </reply> |
| + | |
| + | # Client-side |
| + | <client> |
| + | <features> |
| + | --libcurl |
| + | </features> |
| + | <server> |
| + | http |
| + | </server> |
| + | <name> |
| + | --libcurl resets the handle between --next operations |
| + | </name> |
| + | <setenv> |
| + | SSL_CERT_FILE |
| + | </setenv> |
| + | <command> |
| + | http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -H "X-First: yes" --libcurl %LOGDIR/test%TESTNUMBER.c --next http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER |
| + | </command> |
| + | </client> |
| + | |
| + | # Verify data after the test has been "shot" |
| + | <verify> |
| + | <protocol crlf="headers"> |
| + | GET /we/want/%TESTNUMBER HTTP/1.1 |
| + | Host: %HOSTIP:%HTTPPORT |
| + | User-Agent: curl/%VERSION |
| + | Accept: */* |
| + | X-First: yes |
| + | |
| + | GET /we/want/%TESTNUMBER HTTP/1.1 |
| + | Host: %HOSTIP:%HTTPPORT |
| + | User-Agent: curl/%VERSION |
| + | Accept: */* |
| + | |
| + | </protocol> |
| + | <stripfile> |
| + | # CURLOPT_SSL_VERIFYPEER, SSL_VERIFYHOST, SSLVERSION, SSH_KNOWNHOSTS and |
| + | # HTTP_VERSION vary with configurations, CURLOPT_INTERLEAVEDATA requires |
| + | # RTSP protocol - ignore them |
| + | $_ = '' if /CURLOPT_SSL_VERIFYPEER/ |
| + | $_ = '' if /CURLOPT_SSL_VERIFYHOST/ |
| + | $_ = '' if /CURLOPT_SSLVERSION/ |
| + | $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/ |
| + | $_ = '' if /CURLOPT_HTTP_VERSION/ |
| + | $_ = '' if /CURLOPT_HTTP09_ALLOWED/ |
| + | $_ = '' if /CURLOPT_INTERLEAVEDATA/ |
| + | $_ = '' if /CURLOPT_TIMEOUT_MS/ |
| + | </stripfile> |
| + | <file name="%LOGDIR/test%TESTNUMBER.c" mode="text"> |
| + | %includetext %SRCDIR/data/data%TESTNUMBER.c% |
| + | </file> |
| + | </verify> |
| + | </testcase> |