lib651.c (2824B)
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 "memdebug.h" 27 28 static CURLcode test_lib651(char *URL) 29 { 30 static char testbuf[17000]; /* more than 16K */ 31 32 CURL *curl; 33 CURLcode res = CURLE_OK; 34 CURLFORMcode formrc; 35 struct curl_httppost *formpost = NULL; 36 struct curl_httppost *lastptr = NULL; 37 38 /* create a buffer with AAAA...BBBBB...CCCC...etc */ 39 int i; 40 int size = (int)sizeof(testbuf)/1000; 41 42 for(i = 0; i < size ; i++) 43 memset(&testbuf[i * 1000], 65 + i, 1000); 44 45 testbuf[sizeof(testbuf)-1] = 0; /* null-terminate */ 46 47 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 48 curl_mfprintf(stderr, "curl_global_init() failed\n"); 49 return TEST_ERR_MAJOR_BAD; 50 } 51 52 /* Check proper name and data copying. */ 53 formrc = curl_formadd(&formpost, &lastptr, 54 CURLFORM_COPYNAME, "hello", 55 CURLFORM_COPYCONTENTS, testbuf, 56 CURLFORM_END); 57 if(formrc) 58 curl_mprintf("curl_formadd(1) = %d\n", (int) formrc); 59 60 61 curl = curl_easy_init(); 62 if(!curl) { 63 curl_mfprintf(stderr, "curl_easy_init() failed\n"); 64 curl_formfree(formpost); 65 curl_global_cleanup(); 66 return TEST_ERR_MAJOR_BAD; 67 } 68 69 /* First set the URL that is about to receive our POST. */ 70 test_setopt(curl, CURLOPT_URL, URL); 71 72 /* send a multi-part formpost */ 73 test_setopt(curl, CURLOPT_HTTPPOST, formpost); 74 75 /* get verbose debug output please */ 76 test_setopt(curl, CURLOPT_VERBOSE, 1L); 77 78 /* include headers in the output */ 79 test_setopt(curl, CURLOPT_HEADER, 1L); 80 81 /* Perform the request, res will get the return code */ 82 res = curl_easy_perform(curl); 83 84 test_cleanup: 85 86 /* always cleanup */ 87 curl_easy_cleanup(curl); 88 89 /* now cleanup the formpost chain */ 90 curl_formfree(formpost); 91 92 curl_global_cleanup(); 93 94 return res; 95 }