Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1308.c
2066 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, 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 "curlcheck.h"
25
26
#include <curl/curl.h>
27
28
static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
29
{
30
fwrite(buf, len, 1, stdout);
31
(*(size_t *) arg) += len;
32
return len;
33
}
34
35
CURLcode test(char *URL)
36
{
37
CURLFORMcode rc;
38
int res;
39
struct curl_httppost *post = NULL;
40
struct curl_httppost *last = NULL;
41
size_t total_size = 0;
42
char buffer[] = "test buffer";
43
44
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
45
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
46
fail_unless(rc == 0, "curl_formadd returned error");
47
48
/* after the first curl_formadd when there's a single entry, both pointers
49
should point to the same struct */
50
fail_unless(post == last, "post and last weren't the same");
51
52
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
53
CURLFORM_COPYCONTENTS, "<HTML></HTML>",
54
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
55
fail_unless(rc == 0, "curl_formadd returned error");
56
57
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
58
CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
59
fail_unless(rc == 0, "curl_formadd returned error");
60
61
res = curl_formget(post, &total_size, print_httppost_callback);
62
fail_unless(res == 0, "curl_formget returned error");
63
64
fail_unless(total_size == 518, "curl_formget got wrong size back");
65
66
curl_formfree(post);
67
68
/* start a new formpost with a file upload and formget */
69
post = last = NULL;
70
71
rc = curl_formadd(&post, &last,
72
CURLFORM_PTRNAME, "name of file field",
73
CURLFORM_FILE, URL,
74
CURLFORM_FILENAME, "custom named file",
75
CURLFORM_END);
76
fail_unless(rc == 0, "curl_formadd returned error");
77
78
res = curl_formget(post, &total_size, print_httppost_callback);
79
80
fail_unless(res == 0, "curl_formget returned error");
81
fail_unless(total_size == 899, "curl_formget got wrong size back");
82
83
curl_formfree(post);
84
85
return CURLE_OK;
86
}
87
88