lib1662.c (2847B)
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 struct t1662_WriteThis { 27 size_t sizeleft; 28 }; 29 30 static size_t t1662_read_cb(char *ptr, size_t size, size_t nmemb, void *userp) 31 { 32 static const char testdata[] = "mooaaa"; 33 34 struct t1662_WriteThis *pooh = (struct t1662_WriteThis *)userp; 35 size_t len = strlen(testdata); 36 37 if(size*nmemb < len) 38 return 0; 39 40 if(pooh->sizeleft) { 41 memcpy(ptr, testdata, strlen(testdata)); 42 pooh->sizeleft = 0; 43 return len; 44 } 45 46 return 0; /* no more data left to deliver */ 47 } 48 49 static CURLcode test_lib1662(char *URL) 50 { 51 CURLcode res = CURLE_OK; 52 CURL *hnd; 53 curl_mime *mime1; 54 curl_mimepart *part1; 55 struct t1662_WriteThis pooh = { 1 }; 56 57 mime1 = NULL; 58 59 global_init(CURL_GLOBAL_ALL); 60 61 hnd = curl_easy_init(); 62 if(hnd) { 63 curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L); 64 curl_easy_setopt(hnd, CURLOPT_URL, URL); 65 curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); 66 mime1 = curl_mime_init(hnd); 67 if(mime1) { 68 part1 = curl_mime_addpart(mime1); 69 curl_mime_data_cb(part1, -1, t1662_read_cb, NULL, NULL, &pooh); 70 curl_mime_filename(part1, "poetry.txt"); 71 curl_mime_name(part1, "content"); 72 curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1); 73 curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000"); 74 curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); 75 curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); 76 curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, 77 (long)CURL_HTTP_VERSION_2TLS); 78 curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); 79 curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); 80 curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); 81 res = curl_easy_perform(hnd); 82 } 83 } 84 85 curl_easy_cleanup(hnd); 86 curl_mime_free(mime1); 87 curl_global_cleanup(); 88 return res; 89 }