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 "test.h"
25
26 static char testdata[]="mooaaa";
27
28 struct WriteThis {
29 size_t sizeleft;
30 };
31
read_callback(char * ptr,size_t size,size_t nmemb,void * userp)32 static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp)
33 {
34 struct WriteThis *pooh = (struct 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
test(char * URL)50 CURLcode test(char *URL)
51 {
52 CURLcode res = CURLE_OK;
53 CURL *hnd;
54 curl_mime *mime1;
55 curl_mimepart *part1;
56 struct WriteThis pooh = { 1 };
57
58 mime1 = NULL;
59
60 global_init(CURL_GLOBAL_ALL);
61
62 hnd = curl_easy_init();
63 if(hnd) {
64 curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
65 curl_easy_setopt(hnd, CURLOPT_URL, URL);
66 curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
67 mime1 = curl_mime_init(hnd);
68 if(mime1) {
69 part1 = curl_mime_addpart(mime1);
70 curl_mime_data_cb(part1, -1, read_callback, NULL, NULL, &pooh);
71 curl_mime_filename(part1, "poetry.txt");
72 curl_mime_name(part1, "content");
73 curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
74 curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000");
75 curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
76 curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
77 curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION,
78 (long)CURL_HTTP_VERSION_2TLS);
79 curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
80 curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
81 curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
82 res = curl_easy_perform(hnd);
83 }
84 }
85
86 curl_easy_cleanup(hnd);
87 curl_mime_free(mime1);
88 curl_global_cleanup();
89 return res;
90 }
91