Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1520.c
2651 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Steve Holme, <[email protected]>.
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
struct upload_status {
29
int lines_read;
30
};
31
32
static size_t t1520_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
33
{
34
static const char *payload_text[] = {
35
"From: different\r\n",
36
"To: another\r\n",
37
"\r\n",
38
"\r\n",
39
".\r\n",
40
".\r\n",
41
"\r\n",
42
".\r\n",
43
"\r\n",
44
"body",
45
NULL
46
};
47
48
struct upload_status *upload_ctx = (struct upload_status *)userp;
49
const char *data;
50
51
if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
52
return 0;
53
}
54
55
data = payload_text[upload_ctx->lines_read];
56
57
if(data) {
58
size_t len = strlen(data);
59
memcpy(ptr, data, len);
60
upload_ctx->lines_read++;
61
62
return len;
63
}
64
65
return 0;
66
}
67
68
static CURLcode test_lib1520(const char *URL)
69
{
70
CURLcode res;
71
CURL *curl;
72
struct curl_slist *rcpt_list = NULL;
73
struct upload_status upload_ctx = {0};
74
75
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
76
curl_mfprintf(stderr, "curl_global_init() failed\n");
77
return TEST_ERR_MAJOR_BAD;
78
}
79
80
curl = curl_easy_init();
81
if(!curl) {
82
curl_mfprintf(stderr, "curl_easy_init() failed\n");
83
curl_global_cleanup();
84
return TEST_ERR_MAJOR_BAD;
85
}
86
87
rcpt_list = curl_slist_append(rcpt_list, "<[email protected]>");
88
#if 0
89
/* more addresses can be added here */
90
rcpt_list = curl_slist_append(rcpt_list, "<[email protected]>");
91
#endif
92
test_setopt(curl, CURLOPT_URL, URL);
93
test_setopt(curl, CURLOPT_UPLOAD, 1L);
94
test_setopt(curl, CURLOPT_READFUNCTION, t1520_read_cb);
95
test_setopt(curl, CURLOPT_READDATA, &upload_ctx);
96
test_setopt(curl, CURLOPT_MAIL_FROM, "<[email protected]>");
97
test_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
98
test_setopt(curl, CURLOPT_VERBOSE, 1L);
99
100
res = curl_easy_perform(curl);
101
102
test_cleanup:
103
104
curl_slist_free_all(rcpt_list);
105
curl_easy_cleanup(curl);
106
curl_global_cleanup();
107
108
return res;
109
}
110
111