lib1553.c (3244B)
1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at https://curl.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 #include "first.h" 25 26 #include "testtrace.h" 27 #include "memdebug.h" 28 29 static int t1553_xferinfo(void *p, 30 curl_off_t dltotal, curl_off_t dlnow, 31 curl_off_t ultotal, curl_off_t ulnow) 32 { 33 (void)p; 34 (void)dlnow; 35 (void)dltotal; 36 (void)ulnow; 37 (void)ultotal; 38 curl_mfprintf(stderr, "xferinfo fail!\n"); 39 return 1; /* fail as fast as we can */ 40 } 41 42 static CURLcode test_lib1553(char *URL) 43 { 44 CURL *curls = NULL; 45 CURLM *multi = NULL; 46 int still_running; 47 CURLcode i = CURLE_OK; 48 CURLcode res = CURLE_OK; 49 curl_mimepart *field = NULL; 50 curl_mime *mime = NULL; 51 int counter = 1; 52 53 start_test_timing(); 54 55 global_init(CURL_GLOBAL_ALL); 56 57 multi_init(multi); 58 59 easy_init(curls); 60 61 mime = curl_mime_init(curls); 62 field = curl_mime_addpart(mime); 63 curl_mime_name(field, "name"); 64 curl_mime_data(field, "value", CURL_ZERO_TERMINATED); 65 66 easy_setopt(curls, CURLOPT_URL, URL); 67 easy_setopt(curls, CURLOPT_HEADER, 1L); 68 easy_setopt(curls, CURLOPT_VERBOSE, 1L); 69 easy_setopt(curls, CURLOPT_MIMEPOST, mime); 70 easy_setopt(curls, CURLOPT_USERPWD, "u:s"); 71 easy_setopt(curls, CURLOPT_XFERINFOFUNCTION, t1553_xferinfo); 72 easy_setopt(curls, CURLOPT_NOPROGRESS, 1L); 73 74 libtest_debug_config.nohex = 1; 75 libtest_debug_config.tracetime = 1; 76 test_setopt(curls, CURLOPT_DEBUGDATA, &libtest_debug_config); 77 easy_setopt(curls, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); 78 easy_setopt(curls, CURLOPT_VERBOSE, 1L); 79 80 multi_add_handle(multi, curls); 81 82 multi_perform(multi, &still_running); 83 84 abort_on_test_timeout(); 85 86 while(still_running && counter--) { 87 CURLMcode mres; 88 int num; 89 mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num); 90 if(mres != CURLM_OK) { 91 curl_mprintf("curl_multi_wait() returned %d\n", mres); 92 res = TEST_ERR_MAJOR_BAD; 93 goto test_cleanup; 94 } 95 96 abort_on_test_timeout(); 97 98 multi_perform(multi, &still_running); 99 100 abort_on_test_timeout(); 101 } 102 103 test_cleanup: 104 105 curl_mime_free(mime); 106 curl_multi_remove_handle(multi, curls); 107 curl_multi_cleanup(multi); 108 curl_easy_cleanup(curls); 109 curl_global_cleanup(); 110 111 if(res) 112 i = res; 113 114 return i; /* return the final return code */ 115 }