curl-8.5.0/0000755000175000001760000000000014534017617007503 500000000000000curl-8.5.0/libcurl.pc.in0000644000175000017500000000277614525676160012027 00000000000000#*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # Copyright (C) Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is # furnished to do so, under the terms of the COPYING file. # # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # # SPDX-License-Identifier: curl # ########################################################################### # This should most probably benefit from getting a "Requires:" field added # dynamically by configure. # prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ supported_protocols="@SUPPORT_PROTOCOLS@" supported_features="@SUPPORT_FEATURES@" Name: libcurl URL: https://curl.se/ Description: Library to transfer files with ftp, http, etc. Version: @CURLVERSION@ Libs: -L${libdir} -lcurl @LIBCURL_NO_SHARED@ Libs.private: @LIBCURL_LIBS@ Cflags: -I${includedir} @CPPFLAG_CURL_STATICLIB@ curl-8.5.0/tests/0000755000175000001760000000000014534017616010644 500000000000000curl-8.5.0/tests/libtest/0000755000175000001760000000000014534017615012311 500000000000000curl-8.5.0/tests/libtest/lib1500.c0000644000175000017500000000446114525676160013463 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 int test(char *URL) { CURL *curls = NULL; CURLM *multi = NULL; int still_running; int i = TEST_ERR_FAILURE; int res = 0; CURLMsg *msg; start_test_timing(); global_init(CURL_GLOBAL_ALL); multi_init(multi); easy_init(curls); easy_setopt(curls, CURLOPT_URL, URL); easy_setopt(curls, CURLOPT_HEADER, 1L); multi_add_handle(multi, curls); multi_perform(multi, &still_running); abort_on_test_timeout(); while(still_running) { int num; res = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num); if(res != CURLM_OK) { printf("curl_multi_wait() returned %d\n", res); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } abort_on_test_timeout(); multi_perform(multi, &still_running); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &still_running); if(msg) /* this should now contain a result code from the easy handle, get it */ i = msg->data.result; test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(curls); curl_global_cleanup(); if(res) i = res; return i; /* return the final return code */ } curl-8.5.0/tests/libtest/lib1908.c0000644000175000017500000000406214525676160013474 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Linus Nielsen Feltzing, * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" int test(char *URL) { CURLcode ret = CURLE_OK; CURL *hnd; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); hnd = curl_easy_init(); if(hnd) { curl_easy_setopt(hnd, CURLOPT_URL, URL); curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(hnd, CURLOPT_ALTSVC, libtest_arg2); ret = curl_easy_perform(hnd); if(!ret) { /* make a copy and check that this also has alt-svc activated */ CURL *also = curl_easy_duphandle(hnd); if(also) { ret = curl_easy_perform(also); /* we close the second handle first, which makes it store the alt-svc file only to get overwritten when the next handle is closed! */ curl_easy_cleanup(also); } } curl_easy_reset(hnd); /* using the same file name for the alt-svc cache, this clobbers the content just written from the 'also' handle */ curl_easy_cleanup(hnd); } curl_global_cleanup(); return (int)ret; } curl-8.5.0/tests/libtest/lib1970.c0000644000175000017500000000444214525676160013475 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *list = NULL; struct curl_slist *connect_to = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_INFILESIZE, 0L); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "aws:amz:us-east-1:s3"); test_setopt(curl, CURLOPT_USERPWD, "xxx"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); list = curl_slist_append(list, "Content-Type: application/json"); if(!list) goto test_cleanup; test_setopt(curl, CURLOPT_HTTPHEADER, list); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1912.c0000644000175000017500000000561014525676160013467 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define print_err(name, exp) \ fprintf(stderr, "Type mismatch for CURLOPT_%s (expected %s)\n", name, exp); int test(char *URL) { /* Only test if GCC typechecking is available */ int error = 0; #ifdef CURLINC_TYPECHECK_GCC_H const struct curl_easyoption *o; for(o = curl_easy_option_next(NULL); o; o = curl_easy_option_next(o)) { CURL_IGNORE_DEPRECATION( /* Test for mismatch OR missing typecheck macros */ if(curlcheck_long_option(o->id) != (o->type == CURLOT_LONG || o->type == CURLOT_VALUES)) { print_err(o->name, "CURLOT_LONG or CURLOT_VALUES"); error++; } if(curlcheck_off_t_option(o->id) != (o->type == CURLOT_OFF_T)) { print_err(o->name, "CURLOT_OFF_T"); error++; } if(curlcheck_string_option(o->id) != (o->type == CURLOT_STRING)) { print_err(o->name, "CURLOT_STRING"); error++; } if(curlcheck_slist_option(o->id) != (o->type == CURLOT_SLIST)) { print_err(o->name, "CURLOT_SLIST"); error++; } if(curlcheck_cb_data_option(o->id) != (o->type == CURLOT_CBPTR)) { print_err(o->name, "CURLOT_CBPTR"); error++; } /* From here: only test that the type matches if macro is known */ if(curlcheck_write_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) { print_err(o->name, "CURLOT_FUNCTION"); error++; } if(curlcheck_conv_cb_option(o->id) && (o->type != CURLOT_FUNCTION)) { print_err(o->name, "CURLOT_FUNCTION"); error++; } if(curlcheck_postfields_option(o->id) && (o->type != CURLOT_OBJECT)) { print_err(o->name, "CURLOT_OBJECT"); error++; } /* Todo: no gcc typecheck for CURLOPTTYPE_BLOB types? */ ) } #endif (void)URL; return error; } curl-8.5.0/tests/libtest/lib1528.c0000644000175000017500000000435114525676160013473 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl = NULL; CURLcode res = CURLE_FAILED_INIT; /* http header list */ struct curl_slist *hhl = NULL; struct curl_slist *phl = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } hhl = curl_slist_append(hhl, "User-Agent: Http Agent"); phl = curl_slist_append(phl, "Proxy-User-Agent: Http Agent2"); if(!hhl) { goto test_cleanup; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_HTTPHEADER, hhl); test_setopt(curl, CURLOPT_PROXYHEADER, phl); test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); test_setopt(curl, CURLOPT_HEADER, 1L); res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_slist_free_all(hhl); curl_slist_free_all(phl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib500.c0000644000175000017500000001231314525676160013375 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testtrace.h" #include "memdebug.h" #ifdef LIB585 static int counter; static curl_socket_t tst_opensocket(void *clientp, curlsocktype purpose, struct curl_sockaddr *addr) { (void)clientp; (void)purpose; printf("[OPEN] counter: %d\n", ++counter); return socket(addr->family, addr->socktype, addr->protocol); } static int tst_closesocket(void *clientp, curl_socket_t sock) { (void)clientp; printf("[CLOSE] counter: %d\n", counter--); return sclose(sock); } static void setupcallbacks(CURL *curl) { curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, tst_opensocket); curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, tst_closesocket); counter = 0; } #else #define setupcallbacks(x) Curl_nop_stmt #endif int test(char *URL) { CURLcode res; CURL *curl; char *ipstr = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); libtest_debug_config.nohex = 1; libtest_debug_config.tracetime = 1; test_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config); test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); test_setopt(curl, CURLOPT_VERBOSE, 1L); if(libtest_arg3 && !strcmp(libtest_arg3, "activeftp")) test_setopt(curl, CURLOPT_FTPPORT, "-"); setupcallbacks(curl); res = curl_easy_perform(curl); if(!res) { res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr); if(libtest_arg2) { FILE *moo = fopen(libtest_arg2, "wb"); if(moo) { curl_off_t time_namelookup; curl_off_t time_connect; curl_off_t time_pretransfer; curl_off_t time_starttransfer; curl_off_t time_total; fprintf(moo, "IP %s\n", ipstr); curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME_T, &time_namelookup); curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &time_connect); curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME_T, &time_pretransfer); curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME_T, &time_starttransfer); curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &time_total); /* since the timing will always vary we only compare relative differences between these 5 times */ if(time_namelookup > time_connect) { fprintf(moo, "namelookup vs connect: %" CURL_FORMAT_CURL_OFF_T ".%06ld %" CURL_FORMAT_CURL_OFF_T ".%06ld\n", (time_namelookup / 1000000), (long)(time_namelookup % 1000000), (time_connect / 1000000), (long)(time_connect % 1000000)); } if(time_connect > time_pretransfer) { fprintf(moo, "connect vs pretransfer: %" CURL_FORMAT_CURL_OFF_T ".%06ld %" CURL_FORMAT_CURL_OFF_T ".%06ld\n", (time_connect / 1000000), (long)(time_connect % 1000000), (time_pretransfer / 1000000), (long)(time_pretransfer % 1000000)); } if(time_pretransfer > time_starttransfer) { fprintf(moo, "pretransfer vs starttransfer: %" CURL_FORMAT_CURL_OFF_T ".%06ld %" CURL_FORMAT_CURL_OFF_T ".%06ld\n", (time_pretransfer / 1000000), (long)(time_pretransfer % 1000000), (time_starttransfer / 1000000), (long)(time_starttransfer % 1000000)); } if(time_starttransfer > time_total) { fprintf(moo, "starttransfer vs total: %" CURL_FORMAT_CURL_OFF_T ".%06ld %" CURL_FORMAT_CURL_OFF_T ".%06ld\n", (time_starttransfer / 1000000), (long)(time_starttransfer % 1000000), (time_total / 1000000), (long)(time_total % 1000000)); } fclose(moo); } } } test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib576.c0000644000175000017500000000722214530646363013413 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "memdebug.h" struct chunk_data { int remains; int print_content; }; static long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains) { struct chunk_data *ch_d = ptr; ch_d->remains = remains; printf("=============================================================\n"); printf("Remains: %d\n", remains); printf("Filename: %s\n", finfo->filename); if(finfo->strings.perm) { printf("Permissions: %s", finfo->strings.perm); if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM) printf(" (parsed => %o)", finfo->perm); printf("\n"); } printf("Size: %ldB\n", (long)finfo->size); if(finfo->strings.user) printf("User: %s\n", finfo->strings.user); if(finfo->strings.group) printf("Group: %s\n", finfo->strings.group); if(finfo->strings.time) printf("Time: %s\n", finfo->strings.time); printf("Filetype: "); switch(finfo->filetype) { case CURLFILETYPE_FILE: printf("regular file\n"); break; case CURLFILETYPE_DIRECTORY: printf("directory\n"); break; case CURLFILETYPE_SYMLINK: printf("symlink\n"); printf("Target: %s\n", finfo->strings.target); break; default: printf("other type\n"); break; } if(finfo->filetype == CURLFILETYPE_FILE) { ch_d->print_content = 1; printf("Content:\n" "-------------------------------------------------------------\n"); } if(strcmp(finfo->filename, "someothertext.txt") == 0) { printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n"); return CURL_CHUNK_BGN_FUNC_SKIP; } return CURL_CHUNK_BGN_FUNC_OK; } static long chunk_end(void *ptr) { struct chunk_data *ch_d = ptr; if(ch_d->print_content) { ch_d->print_content = 0; printf("-------------------------------------------------------------\n"); } if(ch_d->remains == 1) printf("=============================================================\n"); return CURL_CHUNK_END_FUNC_OK; } int test(char *URL) { CURL *handle = NULL; CURLcode res = CURLE_OK; struct chunk_data chunk_data = {0, 0}; curl_global_init(CURL_GLOBAL_ALL); handle = curl_easy_init(); if(!handle) { res = CURLE_OUT_OF_MEMORY; goto test_cleanup; } test_setopt(handle, CURLOPT_URL, URL); test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn); test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end); test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data); res = curl_easy_perform(handle); test_cleanup: if(handle) curl_easy_cleanup(handle); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1934.c0000644000175000017500000000422314525676160013472 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *connect_to = NULL; struct curl_slist *list = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "xxx:yyy"); test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); list = curl_slist_append(list, "Content-Type: application/json"); test_setopt(curl, CURLOPT_HTTPHEADER, list); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib516.c0000644000175000017500000000365214525676160013412 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* First set the URL that is about to receive our POST. */ test_setopt(curl, CURLOPT_URL, URL); CURL_IGNORE_DEPRECATION( test_setopt(curl, CURLOPT_HTTPPOST, NULL); ) test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */ test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */ /* Now, we should be making a zero byte POST request */ res = curl_easy_perform(curl); test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib524.c0000644000175000017500000000322114525676160013401 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib654.c0000644000175000017500000001140514525676160013410 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" static char data[]= "dummy\n"; struct WriteThis { char *readptr; curl_off_t sizeleft; int freecount; }; static void free_callback(void *userp) { struct WriteThis *pooh = (struct WriteThis *) userp; pooh->freecount++; } static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; int eof = !*pooh->readptr; if(size*nmemb < 1) return 0; eof = pooh->sizeleft <= 0; if(!eof) pooh->sizeleft--; if(!eof) { *ptr = *pooh->readptr; /* copy one single byte */ pooh->readptr++; /* advance pointer */ return 1; /* we return 1 byte at a time! */ } return 0; /* no more data left to deliver */ } int test(char *URL) { CURL *easy = NULL; CURL *easy2 = NULL; curl_mime *mime = NULL; curl_mimepart *part; struct curl_slist *hdrs = NULL; CURLcode result; int res = TEST_ERR_FAILURE; struct WriteThis pooh; /* * Check proper copy/release of mime post data bound to a duplicated * easy handle. */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } easy = curl_easy_init(); /* First set the URL that is about to receive our POST. */ test_setopt(easy, CURLOPT_URL, URL); /* get verbose debug output please */ test_setopt(easy, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(easy, CURLOPT_HEADER, 1L); /* Prepare the callback structure. */ pooh.readptr = data; pooh.sizeleft = (curl_off_t) strlen(data); pooh.freecount = 0; /* Build the mime tree. */ mime = curl_mime_init(easy); part = curl_mime_addpart(mime); curl_mime_data(part, "hello", CURL_ZERO_TERMINATED); curl_mime_name(part, "greeting"); curl_mime_type(part, "application/X-Greeting"); curl_mime_encoder(part, "base64"); hdrs = curl_slist_append(hdrs, "X-Test-Number: 654"); curl_mime_headers(part, hdrs, TRUE); part = curl_mime_addpart(mime); curl_mime_filedata(part, libtest_arg2); part = curl_mime_addpart(mime); curl_mime_data_cb(part, (curl_off_t) -1, read_callback, NULL, free_callback, &pooh); /* Bind mime data to its easy handle. */ test_setopt(easy, CURLOPT_MIMEPOST, mime); /* Duplicate the handle. */ easy2 = curl_easy_duphandle(easy); if(!easy2) { fprintf(stderr, "curl_easy_duphandle() failed\n"); res = TEST_ERR_FAILURE; goto test_cleanup; } /* Now free the mime structure: it should unbind it from the first easy handle. */ curl_mime_free(mime); mime = NULL; /* Already cleaned up. */ /* Perform on the first handle: should not send any data. */ result = curl_easy_perform(easy); if(result) { fprintf(stderr, "curl_easy_perform(original) failed\n"); res = (int) result; goto test_cleanup; } /* Perform on the second handle: if the bound mime structure has not been duplicated properly, it should cause a valgrind error. */ result = curl_easy_perform(easy2); if(result) { fprintf(stderr, "curl_easy_perform(duplicated) failed\n"); res = (int) result; goto test_cleanup; } /* Free the duplicated handle: it should call free_callback again. If the mime copy was bad or not automatically released, valgrind will signal it. */ curl_easy_cleanup(easy2); easy2 = NULL; /* Already cleaned up. */ if(pooh.freecount != 2) { fprintf(stderr, "free_callback() called %d times instead of 2\n", pooh.freecount); res = TEST_ERR_FAILURE; goto test_cleanup; } test_cleanup: curl_easy_cleanup(easy); curl_easy_cleanup(easy2); curl_mime_free(mime); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib510.c0000644000175000017500000000665014525676160013405 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" static const char *post[]={ "one", "two", "three", "and a final longer crap: four", NULL }; struct WriteThis { int counter; }; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; const char *data; if(size*nmemb < 1) return 0; data = post[pooh->counter]; if(data) { size_t len = strlen(data); if(size*nmemb < len) { fprintf(stderr, "read buffer is too small to run test\n"); return 0; } memcpy(ptr, data, len); pooh->counter++; /* advance pointer */ return len; } return 0; /* no more data left to deliver */ } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; struct curl_slist *slist = NULL; struct WriteThis pooh; pooh.counter = 0; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } slist = curl_slist_append(slist, "Transfer-Encoding: chunked"); if(!slist) { fprintf(stderr, "curl_slist_append() failed\n"); curl_easy_cleanup(curl); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* First set the URL that is about to receive our POST. */ test_setopt(curl, CURLOPT_URL, URL); /* Now specify we want to POST data */ test_setopt(curl, CURLOPT_POST, 1L); /* we want to use our own read function */ test_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* pointer to pass to our read function */ test_setopt(curl, CURLOPT_READDATA, &pooh); /* get verbose debug output please */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(curl, CURLOPT_HEADER, 1L); /* enforce chunked transfer by setting the header */ test_setopt(curl, CURLOPT_HTTPHEADER, slist); #ifdef LIB565 test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST); test_setopt(curl, CURLOPT_USERPWD, "foo:bar"); #endif /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); test_cleanup: /* clean up the headers list */ if(slist) curl_slist_free_all(slist); /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib591.c0000644000175000017500000000716114530646363013412 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" /* lib591 is used for test cases 591, 592, 593 and 594 */ #include #include #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 int test(char *URL) { CURL *easy = NULL; CURLM *multi = NULL; int res = 0; int running; int msgs_left; CURLMsg *msg; FILE *upload = NULL; start_test_timing(); upload = fopen(libtest_arg3, "rb"); if(!upload) { fprintf(stderr, "fopen() failed with error: %d (%s)\n", errno, strerror(errno)); fprintf(stderr, "Error opening file: (%s)\n", libtest_arg3); return TEST_ERR_FOPEN; } res_global_init(CURL_GLOBAL_ALL); if(res) { fclose(upload); return res; } easy_init(easy); /* go verbose */ easy_setopt(easy, CURLOPT_VERBOSE, 1L); /* specify target */ easy_setopt(easy, CURLOPT_URL, URL); /* enable uploading */ easy_setopt(easy, CURLOPT_UPLOAD, 1L); /* data pointer for the file read function */ easy_setopt(easy, CURLOPT_READDATA, upload); /* use active mode FTP */ easy_setopt(easy, CURLOPT_FTPPORT, "-"); /* server connection timeout */ easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS, strtol(libtest_arg2, NULL, 10)*1000); multi_init(multi); multi_add_handle(multi, easy); for(;;) { struct timeval interval; fd_set fdread; fd_set fdwrite; fd_set fdexcep; long timeout = -99; int maxfd = -99; multi_perform(multi, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ multi_timeout(multi, &timeout); /* At this point, timeout is guaranteed to be greater or equal than -1. */ if(timeout != -1L) { int itimeout; #if LONG_MAX > INT_MAX itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout; #else itimeout = (int)timeout; #endif interval.tv_sec = itimeout/1000; interval.tv_usec = (itimeout%1000)*1000; } else { interval.tv_sec = 0; interval.tv_usec = 100000L; /* 100 ms */ } select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &interval); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &msgs_left); if(msg) res = msg->data.result; test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(easy); curl_global_cleanup(); /* close the local file */ fclose(upload); return res; } curl-8.5.0/tests/libtest/lib555.c0000644000175000017500000001017714525676160013415 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* This test case is supposed to be identical to 547 except that this uses the * multi interface and 547 is easy interface. * * argv1 = URL * argv2 = proxy * argv3 = proxyuser:password */ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 static const char uploadthis[] = "this is the blurb we want to upload\n"; static size_t readcallback(char *ptr, size_t size, size_t nmemb, void *clientp) { int *counter = (int *)clientp; if(*counter) { /* only do this once and then require a clearing of this */ fprintf(stderr, "READ ALREADY DONE!\n"); return 0; } (*counter)++; /* bump */ if(size * nmemb > strlen(uploadthis)) { fprintf(stderr, "READ!\n"); strcpy(ptr, uploadthis); return strlen(uploadthis); } fprintf(stderr, "READ NOT FINE!\n"); return 0; } static curlioerr ioctlcallback(CURL *handle, int cmd, void *clientp) { int *counter = (int *)clientp; (void)handle; /* unused */ if(cmd == CURLIOCMD_RESTARTREAD) { fprintf(stderr, "REWIND!\n"); *counter = 0; /* clear counter to make the read callback restart */ } return CURLIOE_OK; } int test(char *URL) { int res = 0; CURL *curl = NULL; int counter = 0; CURLM *m = NULL; int running = 1; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(curl); easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_VERBOSE, 1L); easy_setopt(curl, CURLOPT_HEADER, 1L); /* read the POST data from a callback */ CURL_IGNORE_DEPRECATION( easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback); easy_setopt(curl, CURLOPT_IOCTLDATA, &counter); ) easy_setopt(curl, CURLOPT_READFUNCTION, readcallback); easy_setopt(curl, CURLOPT_READDATA, &counter); /* We CANNOT do the POST fine without setting the size (or choose chunked)! */ easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(uploadthis)); easy_setopt(curl, CURLOPT_POST, 1L); easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); easy_setopt(curl, CURLOPT_PROXYAUTH, (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); multi_init(m); multi_add_handle(m, curl); while(running) { struct timeval timeout; fd_set fdread, fdwrite, fdexcep; int maxfd = -99; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, curl); curl_multi_cleanup(m); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib566.c0000644000175000017500000000367414525676160013423 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; double content_length = 3; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); res = curl_easy_perform(curl); if(!res) { FILE *moo; CURL_IGNORE_DEPRECATION( res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length); ) moo = fopen(libtest_arg2, "wb"); if(moo) { fprintf(moo, "CL %.0f\n", content_length); fclose(moo); } } test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib503.c0000644000175000017500000000503214525676160013400 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 /* * Source code in here hugely as reported in bug report 651460 by * Christopher R. Palmer. * * Use multi interface to get HTTPS document over proxy, and provide * auth info. */ int test(char *URL) { CURL *c = NULL; CURLM *m = NULL; int res = 0; int running; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(c); easy_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */ easy_setopt(c, CURLOPT_URL, URL); easy_setopt(c, CURLOPT_USERPWD, "test:ing"); easy_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing"); easy_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L); easy_setopt(c, CURLOPT_HEADER, 1L); easy_setopt(c, CURLOPT_VERBOSE, 1L); multi_init(m); multi_add_handle(m, c); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, c); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib564.c0000644000175000017500000000441014525676160013406 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 int test(char *URL) { int res = 0; CURL *curl = NULL; int running; CURLM *m = NULL; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(curl); easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_VERBOSE, 1L); easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); easy_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS4); multi_init(m); multi_add_handle(m, curl); fprintf(stderr, "Start at URL 0\n"); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* undocumented cleanup sequence - type UB */ curl_easy_cleanup(curl); curl_multi_cleanup(m); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib543.c0000644000175000017500000000400014525676160013376 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* Based on Alex Fishman's bug report on September 30, 2007 */ #include "test.h" #include "memdebug.h" int test(char *URL) { static const unsigned char a[] = { 0x9c, 0x26, 0x4b, 0x3d, 0x49, 0x4, 0xa1, 0x1, 0xe0, 0xd8, 0x7c, 0x20, 0xb7, 0xef, 0x53, 0x29, 0xfa, 0x1d, 0x57, 0xe1}; CURL *easy; CURLcode res = CURLE_OK; (void)URL; global_init(CURL_GLOBAL_ALL); easy = curl_easy_init(); if(!easy) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; } else { int asize = (int)sizeof(a); char *s = curl_easy_escape(easy, (const char *)a, asize); if(s) { printf("%s\n", s); curl_free(s); } s = curl_easy_escape(easy, "", 0); if(s) { printf("IN: '' OUT: '%s'\n", s); curl_free(s); } s = curl_easy_escape(easy, " 123", 3); if(s) { printf("IN: ' 12' OUT: '%s'\n", s); curl_free(s); } curl_easy_cleanup(easy); } curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1156.c0000644000175000001760000001365714533635145013477 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" /* Check range/resume returned error codes and data presence. The input parameters are: - CURLOPT_RANGE/CURLOPT_RESUME_FROM - CURLOPT_FAILONERROR - Returned http code (2xx/416) - Content-Range header present in reply. */ #include "memdebug.h" #define F_RESUME (1 << 0) /* resume/range. */ #define F_HTTP416 (1 << 1) /* Server returns http code 416. */ #define F_FAIL (1 << 2) /* Fail on error. */ #define F_CONTENTRANGE (1 << 3) /* Server sends content-range hdr. */ #define F_IGNOREBODY (1 << 4) /* Body should be ignored. */ struct testparams { unsigned int flags; /* ORed flags as above. */ CURLcode result; /* Code that should be returned by curl_easy_perform(). */ }; static const struct testparams params[] = { { 0, CURLE_OK }, { F_CONTENTRANGE, CURLE_OK }, { F_FAIL, CURLE_OK }, { F_FAIL | F_CONTENTRANGE, CURLE_OK }, { F_HTTP416, CURLE_OK }, { F_HTTP416 | F_CONTENTRANGE, CURLE_OK }, { F_HTTP416 | F_FAIL | F_IGNOREBODY, CURLE_HTTP_RETURNED_ERROR }, { F_HTTP416 | F_FAIL | F_CONTENTRANGE | F_IGNOREBODY, CURLE_HTTP_RETURNED_ERROR }, { F_RESUME | F_IGNOREBODY, CURLE_RANGE_ERROR }, { F_RESUME | F_CONTENTRANGE, CURLE_OK }, { F_RESUME | F_FAIL | F_IGNOREBODY, CURLE_RANGE_ERROR }, { F_RESUME | F_FAIL | F_CONTENTRANGE, CURLE_OK }, { F_RESUME | F_HTTP416 | F_IGNOREBODY, CURLE_OK }, { F_RESUME | F_HTTP416 | F_CONTENTRANGE | F_IGNOREBODY, CURLE_OK }, { F_RESUME | F_HTTP416 | F_FAIL | F_IGNOREBODY, CURLE_OK }, { F_RESUME | F_HTTP416 | F_FAIL | F_CONTENTRANGE | F_IGNOREBODY, CURLE_OK } }; static int hasbody; static size_t writedata(char *data, size_t size, size_t nmemb, void *userdata) { (void) data; (void) userdata; if(size && nmemb) hasbody = 1; return size * nmemb; } static int onetest(CURL *curl, const char *url, const struct testparams *p, size_t num) { CURLcode res; unsigned int replyselector; char urlbuf[256]; replyselector = (p->flags & F_CONTENTRANGE)? 1: 0; if(p->flags & F_HTTP416) replyselector += 2; msnprintf(urlbuf, sizeof(urlbuf), "%s%04u", url, replyselector); test_setopt(curl, CURLOPT_URL, urlbuf); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_RESUME_FROM, (p->flags & F_RESUME)? 3: 0); test_setopt(curl, CURLOPT_RANGE, !(p->flags & F_RESUME)? "3-1000000": (char *) NULL); test_setopt(curl, CURLOPT_FAILONERROR, (p->flags & F_FAIL)? 1: 0); hasbody = 0; res = curl_easy_perform(curl); if(res != p->result) { printf("%zd: bad error code (%d): resume=%s, fail=%s, http416=%s, " "content-range=%s, expected=%d\n", num, res, (p->flags & F_RESUME)? "yes": "no", (p->flags & F_FAIL)? "yes": "no", (p->flags & F_HTTP416)? "yes": "no", (p->flags & F_CONTENTRANGE)? "yes": "no", p->result); return 1; } if(hasbody && (p->flags & F_IGNOREBODY)) { printf("body should be ignored and is not: resume=%s, fail=%s, " "http416=%s, content-range=%s\n", (p->flags & F_RESUME)? "yes": "no", (p->flags & F_FAIL)? "yes": "no", (p->flags & F_HTTP416)? "yes": "no", (p->flags & F_CONTENTRANGE)? "yes": "no"); return 1; } return 0; test_cleanup: return 1; } /* for debugging: */ /* #define SINGLETEST 9 */ int test(char *URL) { CURLcode res; CURL *curl; size_t i; int status = 0; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } for(i = 0; i < sizeof(params) / sizeof(params[0]); i++) { curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_WRITEFUNCTION, writedata); #ifdef SINGLETEST if(SINGLETEST == i) #endif status |= onetest(curl, URL, params + i, i); curl_easy_cleanup(curl); } curl_global_cleanup(); printf("%d\n", status); return status; test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1534.c0000644000175000017500000000765614525676160013503 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" /* Test CURLINFO_FILETIME */ int test(char *URL) { CURL *curl, *dupe = NULL; long filetime; CURLcode res = CURLE_OK; global_init(CURL_GLOBAL_ALL); easy_init(curl); /* Test that a filetime is properly initialized on curl_easy_init. */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if(res) { fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", __FILE__, __LINE__, res, curl_easy_strerror(res)); goto test_cleanup; } if(filetime != -1) { fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n", __FILE__, __LINE__, filetime); res = CURLE_FAILED_INIT; goto test_cleanup; } easy_setopt(curl, CURLOPT_URL, URL); easy_setopt(curl, CURLOPT_FILETIME, 1L); res = curl_easy_perform(curl); if(res) { fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n", __FILE__, __LINE__, res, curl_easy_strerror(res)); goto test_cleanup; } /* Test that a filetime is properly set after receiving an HTTP resource. */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if(res) { fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", __FILE__, __LINE__, res, curl_easy_strerror(res)); goto test_cleanup; } if(filetime != 30) { fprintf(stderr, "%s:%d filetime of http resource is incorrect; " "expected 30 but is %ld\n", __FILE__, __LINE__, filetime); res = CURLE_HTTP_RETURNED_ERROR; goto test_cleanup; } /* Test that a filetime is properly initialized on curl_easy_duphandle. */ dupe = curl_easy_duphandle(curl); if(!dupe) { fprintf(stderr, "%s:%d curl_easy_duphandle() failed\n", __FILE__, __LINE__); res = CURLE_FAILED_INIT; goto test_cleanup; } res = curl_easy_getinfo(dupe, CURLINFO_FILETIME, &filetime); if(res) { fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", __FILE__, __LINE__, res, curl_easy_strerror(res)); goto test_cleanup; } if(filetime != -1) { fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n", __FILE__, __LINE__, filetime); res = CURLE_FAILED_INIT; goto test_cleanup; } /* Test that a filetime is properly initialized on curl_easy_reset. */ curl_easy_reset(curl); res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if(res) { fprintf(stderr, "%s:%d curl_easy_getinfo() failed with code %d (%s)\n", __FILE__, __LINE__, res, curl_easy_strerror(res)); goto test_cleanup; } if(filetime != -1) { fprintf(stderr, "%s:%d filetime init failed; expected -1 but is %ld\n", __FILE__, __LINE__, filetime); res = CURLE_FAILED_INIT; goto test_cleanup; } test_cleanup: curl_easy_cleanup(curl); curl_easy_cleanup(dupe); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib578.c0000644000175000017500000000575414525676160013427 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */ static char data[]="this is a short string.\n"; static size_t data_size = sizeof(data) / sizeof(char); static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { FILE *moo = fopen(libtest_arg2, "wb"); (void)clientp; /* UNUSED */ (void)dltotal; /* UNUSED */ (void)dlnow; /* UNUSED */ if(moo) { if((size_t)ultotal == data_size && (size_t)ulnow == data_size) fprintf(moo, "PASSED, UL data matched data size\n"); else fprintf(moo, "Progress callback called with UL %f out of %f\n", ulnow, ultotal); fclose(moo); } return 0; } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* First set the URL that is about to receive our POST. */ test_setopt(curl, CURLOPT_URL, URL); /* Now specify we want to POST data */ test_setopt(curl, CURLOPT_POST, 1L); /* Set the expected POST size */ test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data_size); test_setopt(curl, CURLOPT_POSTFIELDS, data); /* we want to use our own progress function */ CURL_IGNORE_DEPRECATION( test_setopt(curl, CURLOPT_NOPROGRESS, 0L); test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); ) /* get verbose debug output please */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(curl, CURLOPT_HEADER, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/testtrace.c0000644000175000017500000001007214525676160014400 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "testtrace.h" #include "memdebug.h" struct libtest_trace_cfg libtest_debug_config; static time_t epoch_offset; /* for test time tracing */ static int known_offset; /* for test time tracing */ static void libtest_debug_dump(const char *timebuf, const char *text, FILE *stream, const unsigned char *ptr, size_t size, int nohex) { size_t i; size_t c; unsigned int width = 0x10; if(nohex) /* without the hex output, we can fit more on screen */ width = 0x40; fprintf(stream, "%s%s, %zu bytes (0x%zx)\n", timebuf, text, size, size); for(i = 0; i < size; i += width) { fprintf(stream, "%04zx: ", i); if(!nohex) { /* hex not disabled, show it */ for(c = 0; c < width; c++) if(i + c < size) fprintf(stream, "%02x ", ptr[i + c]); else fputs(" ", stream); } for(c = 0; (c < width) && (i + c < size); c++) { /* check for 0D0A; if found, skip past and start a new line of output */ if(nohex && (i + c + 1 < size) && (ptr[i + c] == 0x0D) && (ptr[i + c + 1] == 0x0A)) { i += (c + 2 - width); break; } fprintf(stream, "%c", ((ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80)) ? ptr[i + c] : '.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ if(nohex && (i + c + 2 < size) && (ptr[i + c + 1] == 0x0D) && (ptr[i + c + 2] == 0x0A)) { i += (c + 3 - width); break; } } fputc('\n', stream); /* newline */ } fflush(stream); } int libtest_debug_cb(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) { struct libtest_trace_cfg *trace_cfg = userp; const char *text; struct timeval tv; char timebuf[20]; char *timestr; time_t secs; (void)handle; timebuf[0] = '\0'; timestr = &timebuf[0]; if(trace_cfg->tracetime) { struct tm *now; tv = tutil_tvnow(); if(!known_offset) { epoch_offset = time(NULL) - tv.tv_sec; known_offset = 1; } secs = epoch_offset + tv.tv_sec; now = localtime(&secs); /* not thread safe but we don't care */ msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld ", now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec); } switch(type) { case CURLINFO_TEXT: fprintf(stderr, "%s== Info: %s", timestr, (char *)data); /* FALLTHROUGH */ default: /* in case a new one is introduced to shock us */ return 0; case CURLINFO_HEADER_OUT: text = "=> Send header"; break; case CURLINFO_DATA_OUT: text = "=> Send data"; break; case CURLINFO_SSL_DATA_OUT: text = "=> Send SSL data"; break; case CURLINFO_HEADER_IN: text = "<= Recv header"; break; case CURLINFO_DATA_IN: text = "<= Recv data"; break; case CURLINFO_SSL_DATA_IN: text = "<= Recv SSL data"; break; } libtest_debug_dump(timebuf, text, stderr, data, size, trace_cfg->nohex); return 0; } curl-8.5.0/tests/libtest/lib553.c0000644000175000017500000000572014525676160013411 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* This test case and code is based on the bug recipe Joe Malicki provided for * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release. */ #include "test.h" #include "memdebug.h" #define POSTLEN 40960 static size_t myreadfunc(char *ptr, size_t size, size_t nmemb, void *stream) { static size_t total = POSTLEN; static char buf[1024]; (void)stream; memset(buf, 'A', sizeof(buf)); size *= nmemb; if(size > total) size = total; if(size > sizeof(buf)) size = sizeof(buf); memcpy(ptr, buf, size); total -= size; return size; } #define NUM_HEADERS 8 #define SIZE_HEADERS 5000 static char buf[SIZE_HEADERS + 100]; int test(char *URL) { CURL *curl; CURLcode res = CURLE_FAILED_INIT; int i; struct curl_slist *headerlist = NULL, *hl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } for(i = 0; i < NUM_HEADERS; i++) { int len = msnprintf(buf, sizeof(buf), "Header%d: ", i); memset(&buf[len], 'A', SIZE_HEADERS); buf[len + SIZE_HEADERS] = 0; /* null-terminate */ hl = curl_slist_append(headerlist, buf); if(!hl) goto test_cleanup; headerlist = hl; } hl = curl_slist_append(headerlist, "Expect: "); if(!hl) goto test_cleanup; headerlist = hl; test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HTTPHEADER, headerlist); test_setopt(curl, CURLOPT_POST, 1L); test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_HEADER, 1L); test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc); res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_slist_free_all(headerlist); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1538.c0000644000175000017500000000415314525676160013474 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { int res = 0; CURLcode easyret; CURLMcode multiret; CURLSHcode shareret; CURLUcode urlret; (void)URL; curl_easy_strerror((CURLcode)INT_MAX); curl_multi_strerror((CURLMcode)INT_MAX); curl_share_strerror((CURLSHcode)INT_MAX); curl_url_strerror((CURLUcode)INT_MAX); curl_easy_strerror((CURLcode)-INT_MAX); curl_multi_strerror((CURLMcode)-INT_MAX); curl_share_strerror((CURLSHcode)-INT_MAX); curl_url_strerror((CURLUcode)-INT_MAX); for(easyret = CURLE_OK; easyret <= CURL_LAST; easyret++) { printf("e%d: %s\n", (int)easyret, curl_easy_strerror(easyret)); } for(multiret = CURLM_CALL_MULTI_PERFORM; multiret <= CURLM_LAST; multiret++) { printf("m%d: %s\n", (int)multiret, curl_multi_strerror(multiret)); } for(shareret = CURLSHE_OK; shareret <= CURLSHE_LAST; shareret++) { printf("s%d: %s\n", (int)shareret, curl_share_strerror(shareret)); } for(urlret = CURLUE_OK; urlret <= CURLUE_LAST; urlret++) { printf("u%d: %s\n", (int)urlret, curl_url_strerror(urlret)); } return (int)res; } curl-8.5.0/tests/libtest/lib559.c0000644000175000017500000000327614525676160013423 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testtrace.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); test_setopt(curl, CURLOPT_BUFFERSIZE, 1L); /* the smallest! */ res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib3102.c0000644000175000017500000001023614530646363013456 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" /* * Verify correct order of certificates in the chain by comparing the * subject and issuer attributes of each certificate. */ static bool is_chain_in_order(struct curl_certinfo *cert_info) { char *last_issuer = NULL; int cert; /* Chains with only a single certificate are always in order */ if(cert_info->num_of_certs <= 1) return 1; /* Enumerate each certificate in the chain */ for(cert = 0; cert < cert_info->num_of_certs; cert++) { struct curl_slist *slist = cert_info->certinfo[cert]; char *issuer = NULL; char *subject = NULL; /* Find the certificate issuer and subject by enumerating each field */ for(; slist && (!issuer || !subject); slist = slist->next) { const char issuer_prefix[] = "Issuer:"; const char subject_prefix[] = "Subject:"; if(!strncmp(slist->data, issuer_prefix, sizeof(issuer_prefix)-1)) { issuer = slist->data + sizeof(issuer_prefix)-1; } if(!strncmp(slist->data, subject_prefix, sizeof(subject_prefix)-1)) { subject = slist->data + sizeof(subject_prefix)-1; } } if(subject && issuer) { printf("cert %d\n", cert); printf(" subject: %s\n", subject); printf(" issuer: %s\n", issuer); if(last_issuer) { /* If the last certificate's issuer matches the current certificate's * subject, then the chain is in order */ if(strcmp(last_issuer, subject) != 0) { fprintf(stderr, "cert %d issuer does not match cert %d subject\n", cert - 1, cert); fprintf(stderr, "certificate chain is not in order\n"); return false; } } } last_issuer = issuer; } printf("certificate chain is in order\n"); return true; } static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) { (void)stream; (void)ptr; return size * nmemb; } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* Set the HTTPS url to retrieve. */ test_setopt(curl, CURLOPT_URL, URL); /* Capture certificate information */ test_setopt(curl, CURLOPT_CERTINFO, 1L); /* Ignore output */ test_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu); /* No peer verify */ test_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); test_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); if(!res || res == CURLE_GOT_NOTHING) { struct curl_certinfo *cert_info = NULL; /* Get the certificate information */ res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_info); if(!res) { /* Check to see if the certificate chain is ordered correctly */ if(!is_chain_in_order(cert_info)) res = TEST_ERR_FAILURE; } } test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/stub_gssapi.h0000644000175000017500000001556114525676160014742 00000000000000#ifndef HEADER_CURL_GSSAPI_STUBS_H #define HEADER_CURL_GSSAPI_STUBS_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* Roughly based on Heimdal's gssapi.h */ #include #include #define GSS_ERROR(status) (status & 0x80000000) #define GSS_S_COMPLETE 0 #define GSS_S_FAILURE (0x80000000) #define GSS_S_CONTINUE_NEEDED (1ul) #define GSS_C_QOP_DEFAULT 0 #define GSS_C_NO_OID ((gss_OID) 0) #define GSS_C_NO_NAME ((gss_name_t) 0) #define GSS_C_NO_BUFFER ((gss_buffer_t) 0) #define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0) #define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0) #define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0) #define GSS_C_NULL_OID GSS_C_NO_OID #define GSS_C_EMPTY_BUFFER {0, NULL} #define GSS_C_AF_INET 2 #define GSS_C_GSS_CODE 1 #define GSS_C_MECH_CODE 2 #define GSS_C_DELEG_FLAG 1 #define GSS_C_MUTUAL_FLAG 2 #define GSS_C_REPLAY_FLAG 4 #define GSS_C_CONF_FLAG 16 #define GSS_C_INTEG_FLAG 32 /* * Expiration time of 2^32-1 seconds means infinite lifetime for a * credential or security context */ #define GSS_C_INDEFINITE 0xfffffffful #define GSS_C_NT_HOSTBASED_SERVICE NULL typedef uint32_t OM_uint32; typedef OM_uint32 gss_qop_t; typedef struct gss_buffer_desc_struct { size_t length; void *value; } gss_buffer_desc, *gss_buffer_t; struct gss_cred_id_t_desc_struct; typedef struct gss_cred_id_t_desc_struct *gss_cred_id_t; typedef const struct gss_cred_id_t_desc_struct *gss_const_cred_id_t; struct gss_ctx_id_t_desc_struct; typedef struct gss_ctx_id_t_desc_struct *gss_ctx_id_t; typedef const struct gss_ctx_id_t_desc_struct *gss_const_ctx_id_t; struct gss_name_t_desc_struct; typedef struct gss_name_t_desc_struct *gss_name_t; typedef const struct gss_name_t_desc_struct *gss_const_name_t; typedef struct gss_OID_desc_struct { OM_uint32 length; void *elements; } gss_OID_desc, *gss_OID; typedef struct gss_channel_bindings_struct { OM_uint32 initiator_addrtype; gss_buffer_desc initiator_address; OM_uint32 acceptor_addrtype; gss_buffer_desc acceptor_address; gss_buffer_desc application_data; } *gss_channel_bindings_t; OM_uint32 gss_release_buffer(OM_uint32 * /* minor_status */, gss_buffer_t /* buffer */); OM_uint32 gss_init_sec_context(OM_uint32 * /* minor_status */, gss_const_cred_id_t /* initiator_cred_handle */, gss_ctx_id_t * /* context_handle */, gss_const_name_t /* target_name */, const gss_OID /* mech_type */, OM_uint32 /* req_flags */, OM_uint32 /* time_req */, const gss_channel_bindings_t /* input_chan_bindings */, const gss_buffer_t /* input_token */, gss_OID * /* actual_mech_type */, gss_buffer_t /* output_token */, OM_uint32 * /* ret_flags */, OM_uint32 * /* time_rec */); OM_uint32 gss_delete_sec_context(OM_uint32 * /* minor_status */, gss_ctx_id_t * /* context_handle */, gss_buffer_t /* output_token */); OM_uint32 gss_inquire_context(OM_uint32 * /* minor_status */, gss_const_ctx_id_t /* context_handle */, gss_name_t * /* src_name */, gss_name_t * /* targ_name */, OM_uint32 * /* lifetime_rec */, gss_OID * /* mech_type */, OM_uint32 * /* ctx_flags */, int * /* locally_initiated */, int * /* open_context */); OM_uint32 gss_wrap(OM_uint32 * /* minor_status */, gss_const_ctx_id_t /* context_handle */, int /* conf_req_flag */, gss_qop_t /* qop_req */, const gss_buffer_t /* input_message_buffer */, int * /* conf_state */, gss_buffer_t /* output_message_buffer */); OM_uint32 gss_unwrap(OM_uint32 * /* minor_status */, gss_const_ctx_id_t /* context_handle */, const gss_buffer_t /* input_message_buffer */, gss_buffer_t /* output_message_buffer */, int * /* conf_state */, gss_qop_t * /* qop_state */); OM_uint32 gss_seal(OM_uint32 * /* minor_status */, gss_ctx_id_t /* context_handle n */, int /* conf_req_flag */, int /* qop_req */, gss_buffer_t /* input_message_buffer */, int * /* conf_state */, gss_buffer_t /* output_message_buffer */); OM_uint32 gss_unseal(OM_uint32 * /* minor_status */, gss_ctx_id_t /* context_handle */, gss_buffer_t /* input_message_buffer */, gss_buffer_t /* output_message_buffer */, int * /* conf_state */, int * /* qop_state */); OM_uint32 gss_import_name(OM_uint32 * /* minor_status */, const gss_buffer_t /* input_name_buffer */, const gss_OID /* input_name_type */, gss_name_t * /* output_name */); OM_uint32 gss_release_name(OM_uint32 * /* minor_status */, gss_name_t * /* input_name */); OM_uint32 gss_display_name(OM_uint32 * /* minor_status */, gss_const_name_t /* input_name */, gss_buffer_t /* output_name_buffer */, gss_OID * /* output_name_type */); OM_uint32 gss_display_status(OM_uint32 * /* minor_status */, OM_uint32 /* status_value */, int /* status_type */, const gss_OID /* mech_type */, OM_uint32 * /* message_context */, gss_buffer_t /* status_string */); #endif /* HEADER_CURL_GSSAPI_STUBS_H */ curl-8.5.0/tests/libtest/lib1973.c0000644000175000017500000000440614525676160013500 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *list = NULL; struct curl_slist *connect_to = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_POSTFIELDS, "post fields\n"); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "aws:amz:us-east-1:s3"); test_setopt(curl, CURLOPT_USERPWD, "xxx"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); list = curl_slist_append(list, "Content-Type: application/json"); if(!list) goto test_cleanup; test_setopt(curl, CURLOPT_HTTPHEADER, list); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib598.c0000644000175000017500000000421714525676160013422 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); test_setopt(curl, CURLOPT_REFERER, "http://example.com/the-moo"); test_setopt(curl, CURLOPT_USERAGENT, "the-moo agent next generation"); test_setopt(curl, CURLOPT_COOKIE, "name=moo"); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); if(res) { fprintf(stderr, "retrieve 1 failed\n"); goto test_cleanup; } curl_easy_reset(curl); test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); if(res) fprintf(stderr, "retrieve 2 failed\n"); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib651.c0000644000175000017500000000544314525676160013412 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #define CURL_DISABLE_DEPRECATION /* Using and testing the form api */ #include "test.h" #include "memdebug.h" static char buffer[17000]; /* more than 16K */ int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; CURLFORMcode formrc; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; /* create a buffer with AAAA...BBBBB...CCCC...etc */ int i; int size = (int)sizeof(buffer)/1000; for(i = 0; i < size ; i++) memset(&buffer[i * 1000], 65 + i, 1000); buffer[ sizeof(buffer)-1] = 0; /* null-terminate */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } /* Check proper name and data copying. */ formrc = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "hello", CURLFORM_COPYCONTENTS, buffer, CURLFORM_END); if(formrc) printf("curl_formadd(1) = %d\n", (int) formrc); curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_formfree(formpost); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* First set the URL that is about to receive our POST. */ test_setopt(curl, CURLOPT_URL, URL); /* send a multi-part formpost */ test_setopt(curl, CURLOPT_HTTPPOST, formpost); /* get verbose debug output please */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(curl, CURLOPT_HEADER, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); /* now cleanup the formpost chain */ curl_formfree(formpost); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/test613.pl0000755000175000001760000001250614533635145014011 00000000000000#!/usr/bin/env perl #*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # Copyright (C) Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is # furnished to do so, under the terms of the COPYING file. # # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # # SPDX-License-Identifier: curl # ########################################################################### # Prepare a directory with known files and clean up afterwards use Time::Local; if ( $#ARGV < 1 ) { print "Usage: $0 prepare|postprocess dir [logfile]\n"; exit 1; } # expects an error message on stdout sub errout { print $_[0] . "\n"; exit 1; } if ($ARGV[0] eq "prepare") { my $dirname = $ARGV[1]; mkdir $dirname || errout "$!"; chdir $dirname; # Create the files in alphabetical order, to increase the chances # of receiving a consistent set of directory contents regardless # of whether the server alphabetizes the results or not. mkdir "asubdir" || errout "$!"; chmod 0777, "asubdir"; open(FILE, ">plainfile.txt") || errout "$!"; binmode FILE; print FILE "Test file to support curl test suite\n"; close(FILE); # The mtime is specifically chosen to be an even number so that it can be # represented exactly on a FAT filesystem. utime time, timegm(0,0,12,1,0,100), "plainfile.txt"; chmod 0666, "plainfile.txt"; open(FILE, ">rofile.txt") || errout "$!"; binmode FILE; print FILE "Read-only test file to support curl test suite\n"; close(FILE); # The mtime is specifically chosen to be an even number so that it can be # represented exactly on a FAT filesystem. utime time, timegm(0,0,12,31,11,100), "rofile.txt"; chmod 0444, "rofile.txt"; exit 0; } elsif ($ARGV[0] eq "postprocess") { my $dirname = $ARGV[1]; my $logfile = $ARGV[2]; # Clean up the test directory unlink "$dirname/rofile.txt"; unlink "$dirname/plainfile.txt"; rmdir "$dirname/asubdir"; rmdir $dirname || die "$!"; if ($logfile && -s $logfile) { # Process the directory file to remove all information that # could be inconsistent from one test run to the next (e.g. # file date) or may be unsupported on some platforms (e.g. # Windows). Also, since 7.17.0, the sftp directory listing # format can be dependent on the server (with a recent # enough version of libssh2) so this script must also # canonicalize the format. Here are examples of the general # format supported: # -r--r--r-- 12 ausername grp 47 Dec 31 2000 rofile.txt # -r--r--r-- 1 1234 4321 47 Dec 31 2000 rofile.txt # The "canonical" format is similar to the first (which is # the one generated on a typical Linux installation): # -r-?r-?r-? 12 U U 47 Dec 31 2000 rofile.txt my @canondir; open(IN, "<$logfile") || die "$!"; while () { /^(.)(..).(..).(..).\s*(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+\s+\S+\s+\S+)\s+(.*)$/; if ($1 eq "d") { # Skip current and parent directory listing, because some SSH # servers (eg. OpenSSH for Windows) are not listing those if ($8 eq "." || $8 eq "..") { next; } # Erase all directory metadata except for the name, as it is not # consistent for across all test systems and filesystems push @canondir, "d????????? N U U N ??? N NN:NN $8\n"; } elsif ($1 eq "-") { # Replace missing group and other permissions with user # permissions (eg. on Windows) due to them being shown as * my ($u, $g, $o) = ($2, $3, $4); if($g eq "**") { $g = $u; } if($o eq "**") { $o = $u; } # Erase user and group names, as they are not consistent across # all test systems my $line = sprintf("%s%s?%s?%s?%5d U U %15d %s %s\n", $1,$u,$g,$o,$5,$6,$7,$8); push @canondir, $line; } else { # Unexpected format; just pass it through and let the test fail push @canondir, $_; } } close(IN); @canondir = sort {substr($a,57) cmp substr($b,57)} @canondir; my $newfile = $logfile . ".new"; open(OUT, ">$newfile") || die "$!"; print OUT join('', @canondir); close(OUT); unlink $logfile; rename $newfile, $logfile; } exit 0; } print "Unsupported command $ARGV[0]\n"; exit 1; curl-8.5.0/tests/libtest/lib3027.c0000644000175000017500000000346414525676160013473 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" int test(char *URL) { CURLcode ret = CURLE_OK; CURL *hnd; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); hnd = curl_easy_init(); if(hnd) { curl_easy_setopt(hnd, CURLOPT_URL, URL); curl_easy_setopt(hnd, CURLOPT_FILETIME, 1L); ret = curl_easy_perform(hnd); if(CURLE_OK == ret) { long filetime; ret = curl_easy_getinfo(hnd, CURLINFO_FILETIME, &filetime); /* MTDM fails with 550, so filetime should be -1 */ if((CURLE_OK == ret) && (filetime != -1)) { /* we just need to return something which is not CURLE_OK */ ret = CURLE_UNSUPPORTED_PROTOCOL; } } curl_easy_cleanup(hnd); } curl_global_cleanup(); return (int)ret; } curl-8.5.0/tests/libtest/lib1958.c0000644000175000017500000000435714525676160013510 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *list = NULL; struct curl_slist *connect_to = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "xxx"); test_setopt(curl, CURLOPT_USERPWD, "xxx"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); list = curl_slist_append(list, "Content-Type: application/json"); if(!list) goto test_cleanup; if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); curl_slist_append(list, "X-Xxx-Content-Sha256: \tarbitrary "); test_setopt(curl, CURLOPT_HTTPHEADER, list); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib513.c0000644000175000017500000000461514525676160013407 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { (void)ptr; (void)size; (void)nmemb; (void)userp; return CURL_READFUNC_ABORT; } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } /* First set the URL that is about to receive our POST. */ test_setopt(curl, CURLOPT_URL, URL); /* Now specify we want to POST data */ test_setopt(curl, CURLOPT_POST, 1L); /* Set the expected POST size */ test_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L); /* we want to use our own read function */ test_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* pointer to pass to our read function */ test_setopt(curl, CURLOPT_READDATA, NULL); /* get verbose debug output please */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(curl, CURLOPT_HEADER, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1938.c0000644000175000017500000000463314525676160013503 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *connect_to = NULL; struct curl_slist *list = NULL; unsigned char data[] = {0x70, 0x6f, 0x73, 0x74, 0, 0x44, 0x61, 0x74, 0x61}; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_POST, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "provider1:provider2:region:service"); test_setopt(curl, CURLOPT_USERPWD, "keyId:SecretKey"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); list = curl_slist_append(list, "Content-Type: application/json"); test_setopt(curl, CURLOPT_HTTPHEADER, list); test_setopt(curl, CURLOPT_POSTFIELDS, data); test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(data)); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1552.c0000644000175000017500000000463314525676160013473 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 int test(char *URL) { CURL *curls = NULL; CURLM *multi = NULL; int still_running; int i = 0; int res = 0; CURLMsg *msg; int counter = 3; start_test_timing(); global_init(CURL_GLOBAL_ALL); multi_init(multi); easy_init(curls); easy_setopt(curls, CURLOPT_URL, URL); easy_setopt(curls, CURLOPT_HEADER, 1L); easy_setopt(curls, CURLOPT_VERBOSE, 1L); easy_setopt(curls, CURLOPT_USERPWD, "u:s"); multi_add_handle(multi, curls); multi_perform(multi, &still_running); abort_on_test_timeout(); while(still_running && counter--) { int num; res = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num); if(res != CURLM_OK) { printf("curl_multi_wait() returned %d\n", res); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } abort_on_test_timeout(); multi_perform(multi, &still_running); abort_on_test_timeout(); } msg = curl_multi_info_read(multi, &still_running); if(msg) /* this should now contain a result code from the easy handle, get it */ i = msg->data.result; test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(multi); curl_easy_cleanup(curls); curl_global_cleanup(); if(res) i = res; return i; /* return the final return code */ } curl-8.5.0/tests/libtest/lib3010.c0000644000175000017500000000434614530646363013461 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Nicolas Sterchele, * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode ret = CURLE_OK; CURL *curl = NULL; curl_off_t retry_after; char *follow_url = NULL; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, URL); ret = curl_easy_perform(curl); if(ret) { fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n", __FILE__, __LINE__, ret, curl_easy_strerror(ret)); goto test_cleanup; } curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &follow_url); curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry_after); printf("Retry-After %" CURL_FORMAT_CURL_OFF_T "\n", retry_after); curl_easy_setopt(curl, CURLOPT_URL, follow_url); ret = curl_easy_perform(curl); if(ret) { fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n", __FILE__, __LINE__, ret, curl_easy_strerror(ret)); goto test_cleanup; } curl_easy_reset(curl); curl_easy_getinfo(curl, CURLINFO_RETRY_AFTER, &retry_after); printf("Retry-After %" CURL_FORMAT_CURL_OFF_T "\n", retry_after); } test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return ret; } curl-8.5.0/tests/libtest/lib1567.c0000644000175000017500000000343014530646363013471 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" #include int test(char *URL) { CURL *curl = NULL; CURLcode res = CURLE_OK; CURLU *u = NULL; global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { u = curl_url(); if(u) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_url_set(u, CURLUPART_URL, URL, 0); curl_easy_setopt(curl, CURLOPT_CURLU, u); res = curl_easy_perform(curl); if(res) goto test_cleanup; fprintf(stderr, "****************************** Do it again\n"); res = curl_easy_perform(curl); } } test_cleanup: curl_url_cleanup(u); curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1957.c0000644000175000017500000000435414525676160013504 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *list = NULL; struct curl_slist *connect_to = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "xxx"); test_setopt(curl, CURLOPT_USERPWD, "xxx"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); list = curl_slist_append(list, "Content-Type: application/json"); if(!list) goto test_cleanup; if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); curl_slist_append(list, "X-Xxx-Content-Sha256: arbitrary"); test_setopt(curl, CURLOPT_HTTPHEADER, list); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1906.c0000644000175000017500000000555614530646363013501 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" int test(char *URL) { CURLcode res = CURLE_OK; char *url_after = NULL; CURLU *curlu = curl_url(); char error_buffer[CURL_ERROR_SIZE] = ""; CURL *curl; easy_init(curl); curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME); easy_setopt(curl, CURLOPT_CURLU, curlu); easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* msys2 times out instead of CURLE_COULDNT_CONNECT, so make it faster */ easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000L); /* set a port number that makes this request fail */ easy_setopt(curl, CURLOPT_PORT, 1L); res = curl_easy_perform(curl); if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) { fprintf(stderr, "failure expected, " "curl_easy_perform returned %d: <%s>, <%s>\n", (int) res, curl_easy_strerror(res), error_buffer); if(res == CURLE_OK) res = TEST_ERR_MAJOR_BAD; /* force an error return */ goto test_cleanup; } res = CURLE_OK; /* reset for next use */ /* print the used url */ curl_url_get(curlu, CURLUPART_URL, &url_after, 0); fprintf(stderr, "curlu now: <%s>\n", url_after); curl_free(url_after); url_after = NULL; /* now reset CURLOP_PORT to go back to originally set port number */ easy_setopt(curl, CURLOPT_PORT, 0L); res = curl_easy_perform(curl); if(res) fprintf(stderr, "success expected, " "curl_easy_perform returned %ld: <%s>, <%s>\n", (long) res, curl_easy_strerror(res), error_buffer); /* print url */ curl_url_get(curlu, CURLUPART_URL, &url_after, 0); fprintf(stderr, "curlu now: <%s>\n", url_after); test_cleanup: curl_free(url_after); curl_easy_cleanup(curl); curl_url_cleanup(curlu); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib2304.c0000644000175000017500000000755114530646363013467 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #ifdef USE_WEBSOCKETS static int ping(CURL *curl, const char *send_payload) { size_t sent; CURLcode result = curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0, CURLWS_PING); fprintf(stderr, "ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent); return (int)result; } static int recv_pong(CURL *curl, const char *expected_payload) { size_t rlen; const struct curl_ws_frame *meta; char buffer[256]; CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta); if(!result) { if(meta->flags & CURLWS_PONG) { int same = 0; fprintf(stderr, "ws: got PONG back\n"); if(rlen == strlen(expected_payload)) { if(!memcmp(expected_payload, buffer, rlen)) { fprintf(stderr, "ws: got the same payload back\n"); same = 1; } } if(!same) fprintf(stderr, "ws: did NOT get the same payload back\n"); } else { fprintf(stderr, "recv_pong: got %u bytes rflags %x\n", (int)rlen, meta->flags); } } fprintf(stderr, "ws: curl_ws_recv returned %u, received %u\n", (int)result, (int)rlen); return (int)result; } static int recv_any(CURL *curl) { size_t rlen; const struct curl_ws_frame *meta; char buffer[256]; CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta); if(result) return result; fprintf(stderr, "recv_any: got %u bytes rflags %x\n", (int)rlen, meta->flags); return 0; } /* just close the connection */ static void websocket_close(CURL *curl) { size_t sent; CURLcode result = curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE); fprintf(stderr, "ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent); } static void websocket(CURL *curl) { int i = 0; fprintf(stderr, "ws: websocket() starts\n"); do { recv_any(curl); fprintf(stderr, "Send ping\n"); if(ping(curl, "foobar")) return; fprintf(stderr, "Receive pong\n"); if(recv_pong(curl, "foobar")) { printf("Connection closed\n"); return; } sleep(2); } while(i++ < 10); websocket_close(curl); } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, URL); /* use the callback style */ curl_easy_setopt(curl, CURLOPT_USERAGENT, "websocket/2304"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */ res = curl_easy_perform(curl); fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res); if(res == CURLE_OK) websocket(curl); /* always cleanup */ curl_easy_cleanup(curl); } curl_global_cleanup(); return (int)res; } #else NO_SUPPORT_BUILT_IN #endif curl-8.5.0/tests/libtest/lib655.c0000644000175000017500000000607414525676160013417 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" static const char *TEST_DATA_STRING = "Test data"; static int cb_count = 0; static int resolver_alloc_cb_fail(void *resolver_state, void *reserved, void *userdata) { (void)resolver_state; (void)reserved; cb_count++; if(strcmp(userdata, TEST_DATA_STRING)) { fprintf(stderr, "Invalid test data received"); exit(1); } return 1; } static int resolver_alloc_cb_pass(void *resolver_state, void *reserved, void *userdata) { (void)resolver_state; (void)reserved; cb_count++; if(strcmp(userdata, TEST_DATA_STRING)) { fprintf(stderr, "Invalid test data received"); exit(1); } return 0; } int test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } /* First set the URL that is about to receive our request. */ test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_RESOLVER_START_DATA, TEST_DATA_STRING); test_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, resolver_alloc_cb_fail); /* this should fail */ res = curl_easy_perform(curl); if(res != CURLE_COULDNT_RESOLVE_HOST) { fprintf(stderr, "curl_easy_perform should have returned " "CURLE_COULDNT_RESOLVE_HOST but instead returned error %d\n", res); if(res == CURLE_OK) res = TEST_ERR_FAILURE; goto test_cleanup; } test_setopt(curl, CURLOPT_RESOLVER_START_FUNCTION, resolver_alloc_cb_pass); /* this should succeed */ res = curl_easy_perform(curl); if(res) { fprintf(stderr, "curl_easy_perform failed.\n"); goto test_cleanup; } if(cb_count != 2) { fprintf(stderr, "Unexpected number of callbacks: %d\n", cb_count); res = TEST_ERR_FAILURE; goto test_cleanup; } test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1501.c0000644000175000017500000000541014525676160013457 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 30 * 1000 /* 500 milliseconds allowed. An extreme number but lets be really conservative to allow old and slow machines to run this test too */ #define MAX_BLOCKED_TIME_MS 500 int test(char *URL) { CURL *handle = NULL; CURLM *mhandle = NULL; int res = 0; int still_running = 0; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(handle); easy_setopt(handle, CURLOPT_URL, URL); easy_setopt(handle, CURLOPT_VERBOSE, 1L); multi_init(mhandle); multi_add_handle(mhandle, handle); multi_perform(mhandle, &still_running); abort_on_test_timeout(); while(still_running) { struct timeval timeout; fd_set fdread; fd_set fdwrite; fd_set fdexcep; int maxfd = -99; struct timeval before; struct timeval after; long e; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); abort_on_test_timeout(); fprintf(stderr, "ping\n"); before = tutil_tvnow(); multi_perform(mhandle, &still_running); abort_on_test_timeout(); after = tutil_tvnow(); e = tutil_tvdiff(after, before); fprintf(stderr, "pong = %ld\n", e); if(e > MAX_BLOCKED_TIME_MS) { res = 100; break; } } test_cleanup: /* undocumented cleanup sequence - type UA */ curl_multi_cleanup(mhandle); curl_easy_cleanup(handle); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1520.c0000644000175000017500000000564114525676160013466 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Steve Holme, . * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" /* * This is the list of basic details you need to tweak to get things right. */ #define TO "" #define FROM "" static const char *payload_text[] = { "From: different\r\n", "To: another\r\n", "\r\n", "\r\n", ".\r\n", ".\r\n", "\r\n", ".\r\n", "\r\n", "body", NULL }; struct upload_status { int lines_read; }; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct upload_status *upload_ctx = (struct upload_status *)userp; const char *data; if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { return 0; } data = payload_text[upload_ctx->lines_read]; if(data) { size_t len = strlen(data); memcpy(ptr, data, len); upload_ctx->lines_read++; return len; } return 0; } int test(char *URL) { CURLcode res; CURL *curl; struct curl_slist *rcpt_list = NULL; struct upload_status upload_ctx = {0}; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } rcpt_list = curl_slist_append(rcpt_list, TO); /* more addresses can be added here rcpt_list = curl_slist_append(rcpt_list, ""); */ test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_READDATA, &upload_ctx); test_setopt(curl, CURLOPT_MAIL_FROM, FROM); test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(rcpt_list); curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib511.c0000644000175000017500000000327414525676160013405 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_FILETIME, 1L); test_setopt(curl, CURLOPT_NOBODY, 1L); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1935.c0000644000175000017500000000422714525676160013477 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *connect_to = NULL; struct curl_slist *list = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "xxx:yyy:rrr"); test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); list = curl_slist_append(list, "Content-Type: application/json"); test_setopt(curl, CURLOPT_HTTPHEADER, list); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_slist_free_all(list); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/test610.pl0000755000175000017500000000336314525676160014011 00000000000000#!/usr/bin/env perl #*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # Copyright (C) Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is # furnished to do so, under the terms of the COPYING file. # # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # # SPDX-License-Identifier: curl # ########################################################################### # Perform simple file and directory manipulation in a portable way if ( $#ARGV <= 0 ) { print "Usage: $0 mkdir|rmdir|rm|move|gone path1 [path2] [more commands...]\n"; exit 1; } use File::Copy; while(@ARGV) { my $cmd = shift @ARGV; my $arg = shift @ARGV; if ($cmd eq "mkdir") { mkdir $arg || die "$!"; } elsif ($cmd eq "rmdir") { rmdir $arg || die "$!"; } elsif ($cmd eq "rm") { unlink $arg || die "$!"; } elsif ($cmd eq "move") { my $arg2 = shift @ARGV; move($arg,$arg2) || die "$!"; } elsif ($cmd eq "gone") { ! -e $arg || die "Path $arg exists"; } else { print "Unsupported command $cmd\n"; exit 1; } } exit 0; curl-8.5.0/tests/libtest/lib1910.c0000644000175000017500000000312614525676160013465 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Linus Nielsen Feltzing, * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" int test(char *URL) { CURLcode ret = CURLE_OK; CURL *hnd; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); hnd = curl_easy_init(); if(hnd) { curl_easy_setopt(hnd, CURLOPT_URL, URL); curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(hnd, CURLOPT_USERPWD, "user\nname:pass\nword"); ret = curl_easy_perform(hnd); curl_easy_cleanup(hnd); } curl_global_cleanup(); return (int)ret; } curl-8.5.0/tests/libtest/lib676.c0000644000175000017500000000401214525676160013410 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_HEADER, 1L); test_setopt(curl, CURLOPT_USERAGENT, "the-moo agent next generation"); test_setopt(curl, CURLOPT_COOKIEFILE, libtest_arg2); test_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); if(res) { fprintf(stderr, "retrieve 1 failed\n"); goto test_cleanup; } /* now clear the cookies */ test_setopt(curl, CURLOPT_COOKIEFILE, NULL); res = curl_easy_perform(curl); if(res) fprintf(stderr, "retrieve 2 failed\n"); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib501.c0000644000175000017500000000331014525676160013373 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl; (void)URL; /* we don't use this */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_HEADER, 1L); /* just verify that setting this to -1 is fine */ test_setopt(curl, CURLOPT_MAXREDIRS, -1L); res = curl_easy_perform(curl); test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib661.c0000644000175000017500000001300014530646363013375 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURLcode res; CURL *curl = NULL; char *newURL = NULL; struct curl_slist *slist = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } /* test: CURLFTPMETHOD_SINGLECWD with absolute path should skip CWD to entry path */ newURL = aprintf("%s/folderA/661", URL); test_setopt(curl, CURLOPT_URL, newURL); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); res = curl_easy_perform(curl); if(res != CURLE_REMOTE_FILE_NOT_FOUND) goto test_cleanup; curl_free(newURL); newURL = aprintf("%s/folderB/661", URL); test_setopt(curl, CURLOPT_URL, newURL); res = curl_easy_perform(curl); if(res != CURLE_REMOTE_FILE_NOT_FOUND) goto test_cleanup; /* test: CURLFTPMETHOD_NOCWD with absolute path should never emit CWD (for both new and reused easy handle) */ curl_easy_cleanup(curl); curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } curl_free(newURL); newURL = aprintf("%s/folderA/661", URL); test_setopt(curl, CURLOPT_URL, newURL); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, 1L); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); res = curl_easy_perform(curl); if(res != CURLE_REMOTE_FILE_NOT_FOUND) goto test_cleanup; /* curve ball: CWD /folderB before reusing connection with _NOCWD */ curl_free(newURL); newURL = aprintf("%s/folderB/661", URL); test_setopt(curl, CURLOPT_URL, newURL); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); res = curl_easy_perform(curl); if(res != CURLE_REMOTE_FILE_NOT_FOUND) goto test_cleanup; curl_free(newURL); newURL = aprintf("%s/folderA/661", URL); test_setopt(curl, CURLOPT_URL, newURL); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); res = curl_easy_perform(curl); if(res != CURLE_REMOTE_FILE_NOT_FOUND) goto test_cleanup; /* test: CURLFTPMETHOD_NOCWD with home-relative path should not emit CWD for first FTP access after login */ curl_easy_cleanup(curl); curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } slist = curl_slist_append(NULL, "SYST"); if(!slist) { fprintf(stderr, "curl_slist_append() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_NOBODY, 1L); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); test_setopt(curl, CURLOPT_QUOTE, slist); res = curl_easy_perform(curl); if(res) goto test_cleanup; /* test: CURLFTPMETHOD_SINGLECWD with home-relative path should not emit CWD for first FTP access after login */ curl_easy_cleanup(curl); curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_NOBODY, 1L); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); test_setopt(curl, CURLOPT_QUOTE, slist); res = curl_easy_perform(curl); if(res) goto test_cleanup; /* test: CURLFTPMETHOD_NOCWD with home-relative path should not emit CWD for second FTP access when not needed + bonus: see if path buffering survives curl_easy_reset() */ curl_easy_reset(curl); test_setopt(curl, CURLOPT_URL, URL); test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_NOBODY, 1L); test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); test_setopt(curl, CURLOPT_QUOTE, slist); res = curl_easy_perform(curl); test_cleanup: if(res) fprintf(stderr, "test encountered error %d\n", res); curl_slist_free_all(slist); curl_free(newURL); curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/lib1974.c0000644000175000017500000000376714525676160013512 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2022, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { CURL *curl; CURLcode res = TEST_ERR_MAJOR_BAD; struct curl_slist *connect_to = NULL; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); curl_global_cleanup(); return TEST_ERR_MAJOR_BAD; } test_setopt(curl, CURLOPT_VERBOSE, 1L); test_setopt(curl, CURLOPT_AWS_SIGV4, "aws:amz:us-east-1:s3"); test_setopt(curl, CURLOPT_USERPWD, "xxx"); test_setopt(curl, CURLOPT_HEADER, 0L); test_setopt(curl, CURLOPT_URL, URL); if(libtest_arg2) { connect_to = curl_slist_append(connect_to, libtest_arg2); } test_setopt(curl, CURLOPT_CONNECT_TO, connect_to); res = curl_easy_perform(curl); test_cleanup: curl_slist_free_all(connect_to); curl_easy_cleanup(curl); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib666.c0000644000175000017500000000651714525676160013423 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" static char buffer[17000]; /* more than 16K */ int test(char *URL) { CURL *curl = NULL; CURLcode res = CURLE_OK; curl_mime *mime = NULL; curl_mimepart *part; size_t i; /* Checks huge binary-encoded mime post. */ /* Create a buffer with pseudo-binary data. */ for(i = 0; i < sizeof(buffer); i++) if(i % 77 == 76) buffer[i] = '\n'; else buffer[i] = (char) (0x41 + i % 26); /* A...Z */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); res = (CURLcode) TEST_ERR_MAJOR_BAD; goto test_cleanup; } /* Build mime structure. */ mime = curl_mime_init(curl); if(!mime) { fprintf(stderr, "curl_mime_init() failed\n"); res = (CURLcode) TEST_ERR_MAJOR_BAD; goto test_cleanup; } part = curl_mime_addpart(mime); if(!part) { fprintf(stderr, "curl_mime_addpart() failed\n"); res = (CURLcode) TEST_ERR_MAJOR_BAD; goto test_cleanup; } res = curl_mime_name(part, "upfile"); if(res) { fprintf(stderr, "curl_mime_name() failed\n"); goto test_cleanup; } res = curl_mime_filename(part, "myfile.txt"); if(res) { fprintf(stderr, "curl_mime_filename() failed\n"); goto test_cleanup; } res = curl_mime_data(part, buffer, sizeof(buffer)); if(res) { fprintf(stderr, "curl_mime_data() failed\n"); goto test_cleanup; } res = curl_mime_encoder(part, "binary"); if(res) { fprintf(stderr, "curl_mime_encoder() failed\n"); goto test_cleanup; } /* First set the URL that is about to receive our mime mail. */ test_setopt(curl, CURLOPT_URL, URL); /* Post form */ test_setopt(curl, CURLOPT_MIMEPOST, mime); /* Shorten upload buffer. */ test_setopt(curl, CURLOPT_UPLOAD_BUFFERSIZE, 16411L); /* get verbose debug output please */ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers in the output */ test_setopt(curl, CURLOPT_HEADER, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); test_cleanup: /* always cleanup */ curl_easy_cleanup(curl); /* now cleanup the mime structure */ curl_mime_free(mime); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib2404.c0000644000175000017500000000737414530646363013473 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Linus Nielsen Feltzing * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 #define NUM_HANDLES 4 int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES] = {0}; int running; CURLM *m = NULL; int i; char target_url[256]; char dnsentry[256]; struct curl_slist *slist = NULL; char *port = libtest_arg3; char *address = libtest_arg2; (void)URL; msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", port, address); printf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); if(!slist) { fprintf(stderr, "curl_slist_append() failed\n"); goto test_cleanup; } start_test_timing(); global_init(CURL_GLOBAL_ALL); multi_init(m); multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L); /* get NUM_HANDLES easy handles */ for(i = 0; i < NUM_HANDLES; i++) { /* get an easy handle */ easy_init(curl[i]); /* specify target */ msnprintf(target_url, sizeof(target_url), "https://localhost:%s/path/2404%04i", port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go http2 */ easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); /* no peer verify */ easy_setopt(curl[i], CURLOPT_SSL_VERIFYPEER, 0L); easy_setopt(curl[i], CURLOPT_SSL_VERIFYHOST, 0L); /* wait for first connection established to see if we can share it */ easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L); /* go verbose */ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); /* include headers */ easy_setopt(curl[i], CURLOPT_HEADER, 1L); easy_setopt(curl[i], CURLOPT_RESOLVE, slist); easy_setopt(curl[i], CURLOPT_STREAM_WEIGHT, (long)128 + i); } fprintf(stderr, "Start at URL 0\n"); for(i = 0; i < NUM_HANDLES; i++) { /* add handle to multi */ multi_add_handle(m, curl[i]); for(;;) { struct timeval interval; fd_set rd, wr, exc; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; multi_perform(m, &running); abort_on_test_timeout(); if(!running) break; /* done */ FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } wait_ms(1); /* to ensure different end times */ } test_cleanup: /* proper cleanup sequence - type PB */ for(i = 0; i < NUM_HANDLES; i++) { curl_multi_remove_handle(m, curl[i]); curl_easy_cleanup(curl[i]); } curl_slist_free_all(slist); curl_multi_cleanup(m); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1913.c0000644000175000017500000000311114525676160013462 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" int test(char *URL) { CURLcode ret = CURLE_OK; CURL *hnd; start_test_timing(); curl_global_init(CURL_GLOBAL_ALL); hnd = curl_easy_init(); if(hnd) { curl_easy_setopt(hnd, CURLOPT_URL, URL); curl_easy_setopt(hnd, CURLOPT_NOBODY, 1L); if(libtest_arg2) /* test1914 sets this extra arg */ curl_easy_setopt(hnd, CURLOPT_FILETIME, 1L); ret = curl_easy_perform(hnd); curl_easy_cleanup(hnd); } curl_global_cleanup(); return (int)ret; } curl-8.5.0/tests/libtest/lib1537.c0000644000175000017500000000525014525676160013472 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "memdebug.h" int test(char *URL) { const unsigned char a[] = {0x2f, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7}; CURLcode res = CURLE_OK; char *ptr = NULL; int asize; int outlen = 0; char *raw; (void)URL; /* we don't use this */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } asize = (int)sizeof(a); ptr = curl_easy_escape(NULL, (char *)a, asize); printf("%s\n", ptr); curl_free(ptr); /* deprecated API */ ptr = curl_escape((char *)a, asize); if(!ptr) { res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } printf("%s\n", ptr); raw = curl_easy_unescape(NULL, ptr, (int)strlen(ptr), &outlen); printf("outlen == %d\n", outlen); printf("unescape == original? %s\n", memcmp(raw, a, outlen) ? "no" : "YES"); curl_free(raw); /* deprecated API */ raw = curl_unescape(ptr, (int)strlen(ptr)); if(!raw) { res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } outlen = (int)strlen(raw); printf("[old] outlen == %d\n", outlen); printf("[old] unescape == original? %s\n", memcmp(raw, a, outlen) ? "no" : "YES"); curl_free(raw); curl_free(ptr); /* weird input length */ ptr = curl_easy_escape(NULL, (char *)a, -1); printf("escape -1 length: %s\n", ptr); /* weird input length */ outlen = 2017; /* just a value */ ptr = curl_easy_unescape(NULL, (char *)"moahahaha", -1, &outlen); printf("unescape -1 length: %s %d\n", ptr, outlen); test_cleanup: curl_free(ptr); curl_global_cleanup(); return (int)res; } curl-8.5.0/tests/libtest/test.h0000644000175000001760000005012314533635145013365 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* Now include the curl_setup.h file from libcurl's private libdir (the source version, but that might include "curl_config.h" from the build dir so we need both of them in the include path), so that we get good in-depth knowledge about the system we're building this on */ #define CURL_NO_OLDIES #include "curl_setup.h" #include #ifdef HAVE_SYS_SELECT_H /* since so many tests use select(), we can just as well include it here */ #include #elif defined(HAVE_UNISTD_H) #include #endif #include "curl_printf.h" #ifdef _WIN32 #define sleep(sec) Sleep ((sec)*1000) #endif #define test_setopt(A,B,C) \ if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) \ goto test_cleanup #define test_multi_setopt(A,B,C) \ if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK) \ goto test_cleanup extern char *libtest_arg2; /* set by first.c to the argv[2] or NULL */ extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */ /* argc and argv as passed in to the main() function */ extern int test_argc; extern char **test_argv; extern struct timeval tv_test_start; /* for test timing */ extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc, struct timeval *tv); extern void wait_ms(int ms); /* wait this many milliseconds */ extern int test(char *URL); /* the actual test function provided by each individual libXXX.c file */ extern char *hexdump(const unsigned char *buffer, size_t len); extern int unitfail; /* ** TEST_ERR_* values must be greater than CURL_LAST CURLcode in order ** to avoid confusion with any CURLcode or CURLMcode. These TEST_ERR_* ** codes are returned to signal test specific situations and should ** not get mixed with CURLcode or CURLMcode values. ** ** For portability reasons TEST_ERR_* values should be less than 127. */ #define TEST_ERR_MAJOR_BAD (CURLcode) 126 #define TEST_ERR_RUNS_FOREVER (CURLcode) 125 #define TEST_ERR_EASY_INIT (CURLcode) 124 #define TEST_ERR_MULTI (CURLcode) 123 #define TEST_ERR_NUM_HANDLES (CURLcode) 122 #define TEST_ERR_SELECT (CURLcode) 121 #define TEST_ERR_SUCCESS (CURLcode) 120 #define TEST_ERR_FAILURE (CURLcode) 119 #define TEST_ERR_USAGE (CURLcode) 118 #define TEST_ERR_FOPEN (CURLcode) 117 #define TEST_ERR_FSTAT (CURLcode) 116 #define TEST_ERR_BAD_TIMEOUT (CURLcode) 115 /* ** Macros for test source code readability/maintainability. ** ** All of the following macros require that an int data type 'res' variable ** exists in scope where macro is used, and that it has been initialized to ** zero before the macro is used. ** ** exe_* and chk_* macros are helper macros not intended to be used from ** outside of this header file. Arguments 'Y' and 'Z' of these represent ** source code file and line number, while Arguments 'A', 'B', etc, are ** the arguments used to actually call a libcurl function. ** ** All easy_* and multi_* macros call a libcurl function and evaluate if ** the function has succeeded or failed. When the function succeeds 'res' ** variable is not set nor cleared and program continues normal flow. On ** the other hand if function fails 'res' variable is set and a jump to ** label 'test_cleanup' is performed. ** ** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro ** counterpart that operates in the same way with the exception that no ** jump takes place in case of failure. res_easy_* and res_multi_* macros ** should be immediately followed by checking if 'res' variable has been ** set. ** ** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the ** TEST_ERR_* values defined above. It is advisable to return this value ** as test result. */ /* ---------------------------------------------------------------- */ #define exe_easy_init(A,Y,Z) do { \ if(((A) = curl_easy_init()) == NULL) { \ fprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \ res = TEST_ERR_EASY_INIT; \ } \ } while(0) #define res_easy_init(A) \ exe_easy_init((A), (__FILE__), (__LINE__)) #define chk_easy_init(A,Y,Z) do { \ exe_easy_init((A), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define easy_init(A) \ chk_easy_init((A), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_init(A,Y,Z) do { \ if(((A) = curl_multi_init()) == NULL) { \ fprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \ res = TEST_ERR_MULTI; \ } \ } while(0) #define res_multi_init(A) \ exe_multi_init((A), (__FILE__), (__LINE__)) #define chk_multi_init(A,Y,Z) do { \ exe_multi_init((A), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_init(A) \ chk_multi_init((A), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_easy_setopt(A,B,C,Y,Z) do { \ CURLcode ec; \ if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) { \ fprintf(stderr, "%s:%d curl_easy_setopt() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_easy_strerror(ec)); \ res = ec; \ } \ } while(0) #define res_easy_setopt(A, B, C) \ exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__)) #define chk_easy_setopt(A, B, C, Y, Z) do { \ exe_easy_setopt((A), (B), (C), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define easy_setopt(A, B, C) \ chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_setopt(A, B, C, Y, Z) do { \ CURLMcode ec; \ if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_setopt() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ } while(0) #define res_multi_setopt(A,B,C) \ exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__)) #define chk_multi_setopt(A,B,C,Y,Z) do { \ exe_multi_setopt((A), (B), (C), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_setopt(A,B,C) \ chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_add_handle(A,B,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ } while(0) #define res_multi_add_handle(A, B) \ exe_multi_add_handle((A), (B), (__FILE__), (__LINE__)) #define chk_multi_add_handle(A, B, Y, Z) do { \ exe_multi_add_handle((A), (B), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_add_handle(A, B) \ chk_multi_add_handle((A), (B), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_remove_handle(A,B,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ } while(0) #define res_multi_remove_handle(A, B) \ exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__)) #define chk_multi_remove_handle(A, B, Y, Z) do { \ exe_multi_remove_handle((A), (B), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_remove_handle(A, B) \ chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_perform(A,B,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_perform((A), (B))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_perform() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ else if(*((B)) < 0) { \ fprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \ "but returned invalid running_handles value (%d)\n", \ (Y), (Z), (int)*((B))); \ res = TEST_ERR_NUM_HANDLES; \ } \ } while(0) #define res_multi_perform(A, B) \ exe_multi_perform((A), (B), (__FILE__), (__LINE__)) #define chk_multi_perform(A, B, Y, Z) do { \ exe_multi_perform((A), (B), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_perform(A,B) \ chk_multi_perform((A), (B), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_fdset(A, B, C, D, E, Y, Z) do { \ CURLMcode ec; \ if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_fdset() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ else if(*((E)) < -1) { \ fprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \ "but returned invalid max_fd value (%d)\n", \ (Y), (Z), (int)*((E))); \ res = TEST_ERR_NUM_HANDLES; \ } \ } while(0) #define res_multi_fdset(A, B, C, D, E) \ exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) #define chk_multi_fdset(A, B, C, D, E, Y, Z) do { \ exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_fdset(A, B, C, D, E) \ chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_timeout(A,B,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_timeout() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_BAD_TIMEOUT; \ } \ else if(*((B)) < -1L) { \ fprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \ "but returned invalid timeout value (%ld)\n", \ (Y), (Z), (long)*((B))); \ res = TEST_ERR_BAD_TIMEOUT; \ } \ } while(0) #define res_multi_timeout(A, B) \ exe_multi_timeout((A), (B), (__FILE__), (__LINE__)) #define chk_multi_timeout(A, B, Y, Z) do { \ exe_multi_timeout((A), (B), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_timeout(A, B) \ chk_multi_timeout((A), (B), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_poll(A,B,C,D,E,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_poll((A), (B), (C), (D), (E))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_poll() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ else if(*((E)) < 0) { \ fprintf(stderr, "%s:%d curl_multi_poll() succeeded, " \ "but returned invalid numfds value (%d)\n", \ (Y), (Z), (int)*((E))); \ res = TEST_ERR_NUM_HANDLES; \ } \ } while(0) #define res_multi_poll(A, B, C, D, E) \ exe_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) #define chk_multi_poll(A, B, C, D, E, Y, Z) do { \ exe_multi_poll((A), (B), (C), (D), (E), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_poll(A, B, C, D, E) \ chk_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_multi_wakeup(A,Y,Z) do { \ CURLMcode ec; \ if((ec = curl_multi_wakeup((A))) != CURLM_OK) { \ fprintf(stderr, "%s:%d curl_multi_wakeup() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \ res = TEST_ERR_MULTI; \ } \ } while(0) #define res_multi_wakeup(A) \ exe_multi_wakeup((A), (__FILE__), (__LINE__)) #define chk_multi_wakeup(A, Y, Z) do { \ exe_multi_wakeup((A), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define multi_wakeup(A) \ chk_multi_wakeup((A), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_select_test(A, B, C, D, E, Y, Z) do { \ int ec; \ if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \ ec = SOCKERRNO; \ fprintf(stderr, "%s:%d select() failed, with " \ "errno %d (%s)\n", \ (Y), (Z), ec, strerror(ec)); \ res = TEST_ERR_SELECT; \ } \ } while(0) #define res_select_test(A, B, C, D, E) \ exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) #define chk_select_test(A, B, C, D, E, Y, Z) do { \ exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \ if(res) \ goto test_cleanup; \ } while(0) #define select_test(A, B, C, D, E) \ chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define start_test_timing() do { \ tv_test_start = tutil_tvnow(); \ } while(0) #define exe_test_timedout(Y,Z) do { \ long timediff = tutil_tvdiff(tutil_tvnow(), tv_test_start); \ if(timediff > (TEST_HANG_TIMEOUT)) { \ fprintf(stderr, "%s:%d ABORTING TEST, since it seems " \ "that it would have run forever (%ld ms > %ld ms)\n", \ (Y), (Z), timediff, (long) (TEST_HANG_TIMEOUT)); \ res = TEST_ERR_RUNS_FOREVER; \ } \ } while(0) #define res_test_timedout() \ exe_test_timedout((__FILE__), (__LINE__)) #define chk_test_timedout(Y, Z) do { \ exe_test_timedout(Y, Z); \ if(res) \ goto test_cleanup; \ } while(0) #define abort_on_test_timeout() \ chk_test_timedout((__FILE__), (__LINE__)) /* ---------------------------------------------------------------- */ #define exe_global_init(A,Y,Z) do { \ CURLcode ec; \ if((ec = curl_global_init((A))) != CURLE_OK) { \ fprintf(stderr, "%s:%d curl_global_init() failed, " \ "with code %d (%s)\n", \ (Y), (Z), (int)ec, curl_easy_strerror(ec)); \ res = ec; \ } \ } while(0) #define res_global_init(A) \ exe_global_init((A), (__FILE__), (__LINE__)) #define chk_global_init(A, Y, Z) do { \ exe_global_init((A), (Y), (Z)); \ if(res) \ return res; \ } while(0) /* global_init() is different than other macros. In case of failure it 'return's instead of going to 'test_cleanup'. */ #define global_init(A) \ chk_global_init((A), (__FILE__), (__LINE__)) #define NO_SUPPORT_BUILT_IN \ int test(char *URL) \ { \ (void)URL; \ fprintf(stderr, "Missing support\n"); \ return 1; \ } /* ---------------------------------------------------------------- */ curl-8.5.0/tests/libtest/lib504.c0000644000175000017500000000572214525676160013407 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 /* * Source code in here hugely as reported in bug report 651464 by * Christopher R. Palmer. * * Use multi interface to get document over proxy with bad port number. * This caused the interface to "hang" in libcurl 7.10.2. */ int test(char *URL) { CURL *c = NULL; int res = 0; CURLM *m = NULL; fd_set rd, wr, exc; int running; start_test_timing(); global_init(CURL_GLOBAL_ALL); easy_init(c); /* The point here is that there must not be anything running on the given proxy port */ if(libtest_arg2) easy_setopt(c, CURLOPT_PROXY, libtest_arg2); easy_setopt(c, CURLOPT_URL, URL); easy_setopt(c, CURLOPT_VERBOSE, 1L); multi_init(m); multi_add_handle(m, c); for(;;) { struct timeval interval; int maxfd = -99; interval.tv_sec = 1; interval.tv_usec = 0; fprintf(stderr, "curl_multi_perform()\n"); multi_perform(m, &running); abort_on_test_timeout(); if(!running) { /* This is where this code is expected to reach */ int numleft; CURLMsg *msg = curl_multi_info_read(m, &numleft); fprintf(stderr, "Expected: not running\n"); if(msg && !numleft) res = TEST_ERR_SUCCESS; /* this is where we should be */ else res = TEST_ERR_FAILURE; /* not correct */ break; /* done */ } fprintf(stderr, "running == %d\n", running); FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&exc); fprintf(stderr, "curl_multi_fdset()\n"); multi_fdset(m, &rd, &wr, &exc, &maxfd); /* At this point, maxfd is guaranteed to be greater or equal than -1. */ select_test(maxfd + 1, &rd, &wr, &exc, &interval); abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PA */ curl_multi_remove_handle(m, c); curl_multi_cleanup(m); curl_easy_cleanup(c); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1510.c0000644000175000017500000000531514530646363013461 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Linus Nielsen Feltzing * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #include "test.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" #define TEST_HANG_TIMEOUT 60 * 1000 #define NUM_URLS 4 int test(char *URL) { int res = 0; CURL *curl = NULL; int i; char target_url[256]; char dnsentry[256]; struct curl_slist *slist = NULL, *slist2; char *port = libtest_arg3; char *address = libtest_arg2; (void)URL; /* Create fake DNS entries for serverX.example.com for all handles */ for(i = 0; i < NUM_URLS; i++) { msnprintf(dnsentry, sizeof(dnsentry), "server%d.example.com:%s:%s", i + 1, port, address); printf("%s\n", dnsentry); slist2 = curl_slist_append(slist, dnsentry); if(!slist2) { fprintf(stderr, "curl_slist_append() failed\n"); goto test_cleanup; } slist = slist2; } start_test_timing(); global_init(CURL_GLOBAL_ALL); /* get an easy handle */ easy_init(curl); /* go verbose */ easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* include headers */ easy_setopt(curl, CURLOPT_HEADER, 1L); easy_setopt(curl, CURLOPT_RESOLVE, slist); easy_setopt(curl, CURLOPT_MAXCONNECTS, 3L); /* get NUM_HANDLES easy handles */ for(i = 0; i < NUM_URLS; i++) { /* specify target */ msnprintf(target_url, sizeof(target_url), "http://server%d.example.com:%s/path/1510%04i", i + 1, port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl, CURLOPT_URL, target_url); res = curl_easy_perform(curl); if(res) goto test_cleanup; abort_on_test_timeout(); } test_cleanup: /* proper cleanup sequence - type PB */ curl_easy_cleanup(curl); curl_slist_free_all(slist); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/lib1512.c0000644000175000017500000000560514530646363013465 00000000000000/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) Linus Nielsen Feltzing * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ /* * Use global DNS cache (while deprecated it should still work), populate it * with CURLOPT_RESOLVE in the first request and then make sure a subsequent * easy transfer finds and uses the populated stuff. */ #include "test.h" #include "memdebug.h" #define NUM_HANDLES 2 int test(char *URL) { int res = 0; CURL *curl[NUM_HANDLES] = {NULL, NULL}; char *port = libtest_arg3; char *address = libtest_arg2; char dnsentry[256]; struct curl_slist *slist = NULL; int i; char target_url[256]; (void)URL; /* URL is setup in the code */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); return TEST_ERR_MAJOR_BAD; } msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s", port, address); printf("%s\n", dnsentry); slist = curl_slist_append(slist, dnsentry); /* get NUM_HANDLES easy handles */ for(i = 0; i < NUM_HANDLES; i++) { /* get an easy handle */ easy_init(curl[i]); /* specify target */ msnprintf(target_url, sizeof(target_url), "http://server.example.curl:%s/path/1512%04i", port, i + 1); target_url[sizeof(target_url) - 1] = '\0'; easy_setopt(curl[i], CURLOPT_URL, target_url); /* go verbose */ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); /* include headers */ easy_setopt(curl[i], CURLOPT_HEADER, 1L); CURL_IGNORE_DEPRECATION( easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L); ) } /* make the first one populate the GLOBAL cache */ easy_setopt(curl[0], CURLOPT_RESOLVE, slist); /* run NUM_HANDLES transfers */ for(i = 0; (i < NUM_HANDLES) && !res; i++) { res = curl_easy_perform(curl[i]); if(res) goto test_cleanup; } test_cleanup: curl_easy_cleanup(curl[0]); curl_easy_cleanup(curl[1]); curl_slist_free_all(slist); curl_global_cleanup(); return res; } curl-8.5.0/tests/libtest/mk-lib1521.pl0000755000175000017500000002647314525676160014276 00000000000000#!/usr/bin/env perl #*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # Copyright (C) Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is # furnished to do so, under the terms of the COPYING file. # # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # # SPDX-License-Identifier: curl # ########################################################################### # Usage: # perl mk-lib1521.pl < ../../include/curl/curl.h > lib1521.c # minimum and maximum long signed values my $minlong = "LONG_MIN"; my $maxlong = "LONG_MAX"; # maximum long unsigned value my $maxulong = "ULONG_MAX"; my $line = ""; my $incomment = 0; print <
, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * SPDX-License-Identifier: curl * ***************************************************************************/ #define CURL_DISABLE_DEPRECATION /* Deprecated options are tested too */ #include "test.h" #include "memdebug.h" #include /* This source code is generated by mk-lib1521.pl ! */ struct data { char *blaha; }; #define LO $minlong #define HI $maxlong #define OFF_LO (curl_off_t) LO #define OFF_HI (curl_off_t) $maxulong #define OFF_NO (curl_off_t) 0 /* Unexpected error. CURLE_NOT_BUILT_IN - means disabled at build CURLE_UNKNOWN_OPTION - means no such option (anymore?) CURLE_SSL_ENGINE_NOTFOUND - set unknown ssl engine CURLE_UNSUPPORTED_PROTOCOL - set bad HTTP version CURLE_BAD_FUNCTION_ARGUMENT - unsupported value */ #define UNEX(x) ((x) && \\ ((x) != CURLE_NOT_BUILT_IN) && \\ ((x) != CURLE_UNKNOWN_OPTION) && \\ ((x) != CURLE_SSL_ENGINE_NOTFOUND) && \\ ((x) != CURLE_UNSUPPORTED_PROTOCOL) && \\ ((x) != CURLE_BAD_FUNCTION_ARGUMENT) ) static size_t writecb(char *buffer, size_t size, size_t nitems, void *outstream) { (void)buffer; (void)size; (void)nitems; (void)outstream; return 0; } static size_t readcb(char *buffer, size_t size, size_t nitems, void *instream) { (void)buffer; (void)size; (void)nitems; (void)instream; return 0; } static int err(const char *name, CURLcode val, int lineno) { printf("CURLOPT_%s returned %d, \\"%s\\" on line %d\\n", name, val, curl_easy_strerror(val), lineno); return (int)val; } static int geterr(const char *name, CURLcode val, int lineno) { printf("CURLINFO_%s returned %d, \\"%s\\" on line %d\\n", name, val, curl_easy_strerror(val), lineno); return (int)val; } static curl_progress_callback progresscb; static curl_write_callback headercb; static curl_debug_callback debugcb; static curl_trailer_callback trailercb; static curl_ssl_ctx_callback ssl_ctx_cb; static curl_ioctl_callback ioctlcb; static curl_sockopt_callback sockoptcb; static curl_opensocket_callback opensocketcb; static curl_seek_callback seekcb; static curl_sshkeycallback ssh_keycb; static curl_sshhostkeycallback ssh_hostkeycb; static curl_chunk_bgn_callback chunk_bgn_cb; static curl_chunk_end_callback chunk_end_cb; static curl_fnmatch_callback fnmatch_cb; static curl_closesocket_callback closesocketcb; static curl_xferinfo_callback xferinfocb; static curl_hstsread_callback hstsreadcb; static curl_hstswrite_callback hstswritecb; static curl_resolver_start_callback resolver_start_cb; static curl_prereq_callback prereqcb; int test(char *URL) { CURL *curl = NULL; CURL *dep = NULL; CURLSH *share = NULL; char errorbuffer[CURL_ERROR_SIZE]; void *conv_from_network_cb = NULL; void *conv_to_network_cb = NULL; void *conv_from_utf8_cb = NULL; void *interleavecb = NULL; char *stringpointerextra = (char *)"moooo"; struct curl_slist *slist = NULL; struct curl_httppost *httppost = NULL; curl_mime *mimepost = NULL; FILE *stream = stderr; struct data object; char *charp; long val; curl_off_t oval; double dval; curl_socket_t sockfd; struct curl_certinfo *certinfo; struct curl_tlssessioninfo *tlssession; struct curl_blob blob = { (void *)"silly", 5, 0}; CURLcode res = CURLE_OK; (void)URL; /* not used */ global_init(CURL_GLOBAL_ALL); easy_init(dep); easy_init(curl); share = curl_share_init(); if(!share) { res = CURLE_OUT_OF_MEMORY; goto test_cleanup; } HEADER ; while() { s/^\s*(.*?)\s*$/$1/; # Trim. # Remove multi-line comment trail. if($incomment) { if($_ !~ /.*?\*\/\s*(.*)$/) { next; } $_ = $1; $incomment = 0; } if($line ne "") { # Unfold line. $_ = "$line $1"; $line = ""; } # Remove comments. while($_ =~ /^(.*?)\/\*.*?\*\/(.*)$/) { $_ = "$1 $2"; } s/^\s*(.*?)\s*$/$1/; # Trim again. if($_ =~ /^(.*)\/\*/) { $_ = $1; $incomment = 1; } # Ignore preprocessor directives and blank lines. if($_ =~ /^(?:#|$)/) { next; } # Handle lines that may be continued as if they were folded. if($_ !~ /[;,{}]$/) { # Folded line. $line = $_; next; } if($_ =~ / CURL_DEPRECATED\(/) { # Drop deprecation info. if($_ !~ /^(.*?) CURL_DEPRECATED\(.*?"\)(.*)$/) { # Needs unfolding. $line = $_; next; } $_ = $1 . $2; } if($_ =~ /^CURLOPT(?:DEPRECATED)?\(/ && $_ !~ /\),$/) { # Multi-line CURLOPTs need unfolding. $line = $_; next; } if($_ =~ /^CURLOPT(?:DEPRECATED)?\(([^ ]*), ([^ ]*), (\d*)[,)]/) { my ($name, $type, $val)=($1, $2, $3); my $w=" "; my $pref = "${w}res = curl_easy_setopt(curl, $name,"; my $i = ' ' x (length($w) + 23); my $check = " if(UNEX(res)) {\n err(\"$name\", res, __LINE__);\n goto test_cleanup;\n }\n"; if($type eq "CURLOPTTYPE_STRINGPOINT") { print "${pref} \"string\");\n$check"; print "${pref} NULL);\n$check"; } elsif(($type eq "CURLOPTTYPE_LONG") || ($type eq "CURLOPTTYPE_VALUES")) { print "${pref} 0L);\n$check"; print "${pref} 22L);\n$check"; print "${pref} LO);\n$check"; print "${pref} HI);\n$check"; } elsif(($type eq "CURLOPTTYPE_OBJECTPOINT") || ($type eq "CURLOPTTYPE_CBPOINT")) { if($name =~ /DEPENDS/) { print "${pref} dep);\n$check"; } elsif($name =~ "SHARE") { print "${pref} share);\n$check"; } elsif($name eq "CURLOPT_ERRORBUFFER") { print "${pref} errorbuffer);\n$check"; } elsif(($name eq "CURLOPT_POSTFIELDS") || ($name eq "CURLOPT_COPYPOSTFIELDS")) { # set size to zero to avoid it being "illegal" print " (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);\n"; print "${pref} stringpointerextra);\n$check"; } elsif($name eq "CURLOPT_HTTPPOST") { print "${pref} httppost);\n$check"; } elsif($name eq "CURLOPT_MIMEPOST") { print "${pref} mimepost);\n$check"; } elsif($name eq "CURLOPT_STDERR") { print "${pref} stream);\n$check"; } else { print "${pref} &object);\n$check"; } print "${pref} NULL);\n$check"; } elsif($type eq "CURLOPTTYPE_SLISTPOINT") { print "${pref} slist);\n$check"; } elsif($type eq "CURLOPTTYPE_FUNCTIONPOINT") { if($name =~ /([^ ]*)FUNCTION/) { my $l=lc($1); $l =~ s/^curlopt_//; print "${pref}\n$i${l}cb);\n$check"; } else { print "${pref} &func);\n$check"; } print "${pref} NULL);\n$check"; } elsif($type eq "CURLOPTTYPE_OFF_T") { # play conservative to work with 32bit curl_off_t print "${pref} OFF_NO);\n$check"; print "${pref} OFF_HI);\n$check"; print "${pref} OFF_LO);\n$check"; } elsif($type eq "CURLOPTTYPE_BLOB") { print "${pref} &blob);\n$check"; } else { print STDERR "\nUnknown type: $type\n"; exit 22; # exit to make this noticed! } } elsif($_ =~ /^CURLINFO_NONE/) { $infomode = 1; } elsif($infomode && ($_ =~ /^CURLINFO_([^ ]*) *= *CURLINFO_([^ ]*)/)) { my ($info, $type)=($1, $2); my $c = " res = curl_easy_getinfo(curl, CURLINFO_$info,"; my $check = " if(UNEX(res)) {\n geterr(\"$info\", res, __LINE__);\n goto test_cleanup;\n }\n"; if($type eq "STRING") { print "$c &charp);\n$check"; } elsif($type eq "LONG") { print "$c &val);\n$check"; } elsif($type eq "OFF_T") { print "$c &oval);\n$check"; } elsif($type eq "DOUBLE") { print "$c &dval);\n$check"; } elsif($type eq "SLIST") { print "$c &slist);\n$check"; print " if(slist)\n curl_slist_free_all(slist);\n"; } elsif($type eq "SOCKET") { print "$c &sockfd);\n$check"; } elsif($type eq "PTR") { if($info eq "CERTINFO") { print "$c &certinfo);\n$check"; } elsif(($info eq "TLS_SESSION") || ($info eq "TLS_SSL_PTR")) { print "$c &tlssession);\n$check"; } else { print STDERR "$info/$type is unsupported\n"; } } else { print STDERR "$type is unsupported\n"; } } } print <