2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.haxx.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 ###########################################################################
25 # perl mk-lib1521.pl < ../../include/curl/curl.h > lib1521.c
27 # minimum and maximum long signed values
28 my $minlong = "LONG_MIN";
29 my $maxlong = "LONG_MAX";
30 # maximum long unsigned value
31 my $maxulong = "ULONG_MAX";
34 /***************************************************************************
36 * Project ___| | | | _ \\| |
38 * | (__| |_| | _ <| |___
39 * \\___|\\___/|_| \\_\\_____|
41 * Copyright (C) 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
43 * This software is licensed as described in the file COPYING, which
44 * you should have received as part of this distribution. The terms
45 * are also available at https://curl.haxx.se/docs/copyright.html.
47 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
48 * copies of the Software, and permit persons to whom the Software is
49 * furnished to do so, under the terms of the COPYING file.
51 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
52 * KIND, either express or implied.
54 ***************************************************************************/
59 /* This source code is generated by mk-lib1521.pl ! */
67 #define OFF_LO (curl_off_t) LO
68 #define OFF_HI (curl_off_t) $maxulong
69 #define OFF_NO (curl_off_t) 0
72 CURLE_NOT_BUILT_IN - means disabled at build
73 CURLE_UNKNOWN_OPTION - means no such option (anymore?)
74 CURLE_SSL_ENGINE_NOTFOUND - set unknown ssl engine
75 CURLE_UNSUPPORTED_PROTOCOL - set bad HTTP version
76 CURLE_BAD_FUNCTION_ARGUMENT - unsupported value
78 #define UNEX(x) ((x) && \\
79 ((x) != CURLE_NOT_BUILT_IN) && \\
80 ((x) != CURLE_UNKNOWN_OPTION) && \\
81 ((x) != CURLE_SSL_ENGINE_NOTFOUND) && \\
82 ((x) != CURLE_UNSUPPORTED_PROTOCOL) && \\
83 ((x) != CURLE_BAD_FUNCTION_ARGUMENT) )
85 static size_t writecb(char *buffer, size_t size, size_t nitems,
95 static size_t readcb(char *buffer,
107 static int err(const char *name, CURLcode val, int lineno)
109 printf("CURLOPT_%s returned %d, \\"%s\\" on line %d\\n",
110 name, val, curl_easy_strerror(val), lineno);
114 static int geterr(const char *name, CURLcode val, int lineno)
116 printf("CURLINFO_%s returned %d, \\"%s\\" on line %d\\n",
117 name, val, curl_easy_strerror(val), lineno);
121 static curl_progress_callback progresscb;
122 static curl_write_callback headercb;
123 static curl_debug_callback debugcb;
124 static curl_ssl_ctx_callback ssl_ctx_cb;
125 static curl_ioctl_callback ioctlcb;
126 static curl_sockopt_callback sockoptcb;
127 static curl_opensocket_callback opensocketcb;
128 static curl_seek_callback seekcb;
129 static curl_sshkeycallback ssh_keycb;
130 static curl_chunk_bgn_callback chunk_bgn_cb;
131 static curl_chunk_end_callback chunk_end_cb;
132 static curl_fnmatch_callback fnmatch_cb;
133 static curl_closesocket_callback closesocketcb;
134 static curl_xferinfo_callback xferinfocb;
135 static curl_resolver_start_callback resolver_start_cb;
141 CURLSH *share = NULL;
142 char errorbuffer[CURL_ERROR_SIZE];
143 void *conv_from_network_cb = NULL;
144 void *conv_to_network_cb = NULL;
145 void *conv_from_utf8_cb = NULL;
146 void *interleavecb = NULL;
147 char *stringpointerextra = (char *)"moooo";
148 struct curl_slist *slist = NULL;
149 struct curl_httppost *httppost = NULL;
150 curl_mime *mimepost = NULL;
151 FILE *stream = stderr;
157 curl_socket_t sockfd;
158 struct curl_certinfo *certinfo;
159 struct curl_tlssessioninfo *tlssession;
160 CURLcode res = CURLE_OK;
161 (void)URL; /* not used */
162 global_init(CURL_GLOBAL_ALL);
165 share = curl_share_init();
167 res = CURLE_OUT_OF_MEMORY;
175 if($_ =~ /^ CINIT\(([^ ]*), ([^ ]*), (\d*)\)/) {
176 my ($name, $type, $val)=($1, $2, $3);
178 my $pref = "${w}res = curl_easy_setopt(curl, CURLOPT_$name,";
179 my $i = ' ' x (length($w) + 23);
180 my $check = " if(UNEX(res)) {\n err(\"$name\", res, __LINE__); goto test_cleanup; }\n";
181 if($type eq "STRINGPOINT") {
182 print "${pref} \"string\");\n$check";
183 print "${pref} NULL);\n$check";
185 elsif($type eq "LONG") {
186 print "${pref} 0L);\n$check";
187 print "${pref} 22L);\n$check";
188 print "${pref} LO);\n$check";
189 print "${pref} HI);\n$check";
191 elsif($type eq "OBJECTPOINT") {
192 if($name =~ /DEPENDS/) {
193 print "${pref} dep);\n$check";
195 elsif($name =~ "SHARE") {
196 print "${pref} share);\n$check";
198 elsif($name eq "ERRORBUFFER") {
199 print "${pref} errorbuffer);\n$check";
201 elsif(($name eq "POSTFIELDS") ||
202 ($name eq "COPYPOSTFIELDS")) {
203 # set size to zero to avoid it being "illegal"
204 print " (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);\n";
205 print "${pref} stringpointerextra);\n$check";
207 elsif(($name eq "HTTPHEADER") ||
208 ($name eq "POSTQUOTE") ||
209 ($name eq "PREQUOTE") ||
210 ($name eq "HTTP200ALIASES") ||
211 ($name eq "TELNETOPTIONS") ||
212 ($name eq "MAIL_RCPT") ||
213 ($name eq "RESOLVE") ||
214 ($name eq "PROXYHEADER") ||
215 ($name eq "QUOTE")) {
216 print "${pref} slist);\n$check";
218 elsif($name eq "HTTPPOST") {
219 print "${pref} httppost);\n$check";
221 elsif($name eq "MIMEPOST") {
222 print "${pref} mimepost);\n$check";
224 elsif($name eq "STDERR") {
225 print "${pref} stream);\n$check";
228 print "${pref} &object);\n$check";
230 print "${pref} NULL);\n$check";
232 elsif($type eq "FUNCTIONPOINT") {
233 if($name =~ /([^ ]*)FUNCTION/) {
235 print "${pref}\n$i${l}cb);\n$check";
238 print "${pref} &func);\n$check";
240 print "${pref} NULL);\n$check";
242 elsif($type eq "OFF_T") {
243 # play conservative to work with 32bit curl_off_t
244 print "${pref} OFF_NO);\n$check";
245 print "${pref} OFF_HI);\n$check";
246 print "${pref} OFF_LO);\n$check";
249 print STDERR "\n---- $type\n";
252 elsif($_ =~ /^ CURLINFO_NONE/) {
256 ($_ =~ /^ CURLINFO_([^ ]*) *= *CURLINFO_([^ ]*)/)) {
257 my ($info, $type)=($1, $2);
258 my $c = " res = curl_easy_getinfo(curl, CURLINFO_$info,";
259 my $check = " if(UNEX(res)) {\n geterr(\"$info\", res, __LINE__); goto test_cleanup; }\n";
260 if($type eq "STRING") {
261 print "$c &charp);\n$check";
263 elsif($type eq "LONG") {
264 print "$c &val);\n$check";
266 elsif($type eq "OFF_T") {
267 print "$c &oval);\n$check";
269 elsif($type eq "DOUBLE") {
270 print "$c &dval);\n$check";
272 elsif($type eq "SLIST") {
273 print "$c &slist);\n$check";
274 print " if(slist)\n curl_slist_free_all(slist);\n";
276 elsif($type eq "SOCKET") {
277 print "$c &sockfd);\n$check";
279 elsif($type eq "PTR") {
280 if($info eq "CERTINFO") {
281 print "$c &certinfo);\n$check";
283 elsif(($info eq "TLS_SESSION") ||
284 ($info eq "TLS_SSL_PTR")) {
285 print "$c &tlssession);\n$check";
288 print STDERR "$info/$type is unsupported\n";
292 print STDERR "$type is unsupported\n";
299 curl_easy_setopt(curl, 1, 0);
302 curl_easy_cleanup(curl);
303 curl_easy_cleanup(dep);
304 curl_share_cleanup(share);
305 curl_global_cleanup();