1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
#!/usr/bin/env perl
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 2017 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################
# Usage:
# perl mk-lib1521.pl < ../../include/curl/curl.h > lib1521.c
# minimum and maximum long signed values
my $minlong = "LONG_MIN";
my $maxlong = "LONG_MAX";
# maximum long unsigned value
my $maxulong = "ULONG_MAX";
print <<HEADER
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \\| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \\___|\\___/|_| \\_\\_____|
*
* Copyright (C) 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "test.h"
#include "memdebug.h"
#include <limits.h>
/* This source code is generated by mk-lib1521.pl ! */
struct data {
char *blaha;
};
#define LO $minlong
#define HI $maxlong
#define OFF_LO (curl_off_t) LO
#define OFF_HI (curl_off_t) $maxulong
#define OFF_NO (curl_off_t) 0
/* Unexpected error.
CURLE_NOT_BUILT_IN - means disabled at build
CURLE_UNKNOWN_OPTION - means no such option (anymore?)
CURLE_SSL_ENGINE_NOTFOUND - set unknown ssl engine
CURLE_UNSUPPORTED_PROTOCOL - set bad HTTP version
CURLE_BAD_FUNCTION_ARGUMENT - unsupported value
*/
#define UNEX(x) ((x) && \\
((x) != CURLE_NOT_BUILT_IN) && \\
((x) != CURLE_UNKNOWN_OPTION) && \\
((x) != CURLE_SSL_ENGINE_NOTFOUND) && \\
((x) != CURLE_UNSUPPORTED_PROTOCOL) && \\
((x) != CURLE_BAD_FUNCTION_ARGUMENT) )
static size_t writecb(char *buffer, size_t size, size_t nitems,
void *outstream)
{
(void)buffer;
(void)size;
(void)nitems;
(void)outstream;
return 0;
}
static size_t readcb(char *buffer,
size_t size,
size_t nitems,
void *instream)
{
(void)buffer;
(void)size;
(void)nitems;
(void)instream;
return 0;
}
static int err(const char *name, CURLcode val, int lineno)
{
printf("CURLOPT_%s returned %d, \\"%s\\" on line %d\\n",
name, val, curl_easy_strerror(val), lineno);
return (int)val;
}
static int geterr(const char *name, CURLcode val, int lineno)
{
printf("CURLINFO_%s returned %d, \\"%s\\" on line %d\\n",
name, val, curl_easy_strerror(val), lineno);
return (int)val;
}
static curl_progress_callback progresscb;
static curl_write_callback headercb;
static curl_debug_callback debugcb;
static curl_trailer_callback trailercb;
static curl_ssl_ctx_callback ssl_ctx_cb;
static curl_ioctl_callback ioctlcb;
static curl_sockopt_callback sockoptcb;
static curl_opensocket_callback opensocketcb;
static curl_seek_callback seekcb;
static curl_sshkeycallback ssh_keycb;
static curl_chunk_bgn_callback chunk_bgn_cb;
static curl_chunk_end_callback chunk_end_cb;
static curl_fnmatch_callback fnmatch_cb;
static curl_closesocket_callback closesocketcb;
static curl_xferinfo_callback xferinfocb;
static curl_resolver_start_callback resolver_start_cb;
int test(char *URL)
{
CURL *curl = NULL;
CURL *dep = NULL;
CURLSH *share = NULL;
char errorbuffer[CURL_ERROR_SIZE];
void *conv_from_network_cb = NULL;
void *conv_to_network_cb = NULL;
void *conv_from_utf8_cb = NULL;
void *interleavecb = NULL;
char *stringpointerextra = (char *)"moooo";
struct curl_slist *slist = NULL;
struct curl_httppost *httppost = NULL;
curl_mime *mimepost = NULL;
FILE *stream = stderr;
struct data object;
char *charp;
long val;
curl_off_t oval;
double dval;
curl_socket_t sockfd;
struct curl_certinfo *certinfo;
struct curl_tlssessioninfo *tlssession;
struct curl_blob blob = { (void *)"silly", 5, 0};
CURLcode res = CURLE_OK;
(void)URL; /* not used */
global_init(CURL_GLOBAL_ALL);
easy_init(dep);
easy_init(curl);
share = curl_share_init();
if(!share) {
res = CURLE_OUT_OF_MEMORY;
goto test_cleanup;
}
HEADER
;
while(<STDIN>) {
if($_ =~ /^ CURLOPT\(([^ ]*), ([^ ]*), (\d*)\)/) {
my ($name, $type, $val)=($1, $2, $3);
my $w=" ";
my $pref = "${w}res = curl_easy_setopt(curl, $name,";
my $i = ' ' x (length($w) + 23);
my $check = " if(UNEX(res)) {\n err(\"$name\", res, __LINE__);\n goto test_cleanup;\n }\n";
if($type eq "CURLOPTTYPE_STRINGPOINT") {
print "${pref} \"string\");\n$check";
print "${pref} NULL);\n$check";
}
elsif($type eq "CURLOPTTYPE_LONG") {
print "${pref} 0L);\n$check";
print "${pref} 22L);\n$check";
print "${pref} LO);\n$check";
print "${pref} HI);\n$check";
}
elsif($type eq "CURLOPTTYPE_OBJECTPOINT") {
if($name =~ /DEPENDS/) {
print "${pref} dep);\n$check";
}
elsif($name =~ "SHARE") {
print "${pref} share);\n$check";
}
elsif($name eq "CURLOPT_ERRORBUFFER") {
print "${pref} errorbuffer);\n$check";
}
elsif(($name eq "CURLOPT_POSTFIELDS") ||
($name eq "CURLOPT_COPYPOSTFIELDS")) {
# set size to zero to avoid it being "illegal"
print " (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);\n";
print "${pref} stringpointerextra);\n$check";
}
elsif($name eq "CURLOPT_HTTPPOST") {
print "${pref} httppost);\n$check";
}
elsif($name eq "CURLOPT_MIMEPOST") {
print "${pref} mimepost);\n$check";
}
elsif($name eq "CURLOPT_STDERR") {
print "${pref} stream);\n$check";
}
else {
print "${pref} &object);\n$check";
}
print "${pref} NULL);\n$check";
}
elsif($type eq "CURLOPTTYPE_SLISTPOINT") {
print "${pref} slist);\n$check";
}
elsif($type eq "CURLOPTTYPE_FUNCTIONPOINT") {
if($name =~ /([^ ]*)FUNCTION/) {
my $l=lc($1);
$l =~ s/^curlopt_//;
print "${pref}\n$i${l}cb);\n$check";
}
else {
print "${pref} &func);\n$check";
}
print "${pref} NULL);\n$check";
}
elsif($type eq "CURLOPTTYPE_OFF_T") {
# play conservative to work with 32bit curl_off_t
print "${pref} OFF_NO);\n$check";
print "${pref} OFF_HI);\n$check";
print "${pref} OFF_LO);\n$check";
}
elsif($type eq "CURLOPTTYPE_BLOB") {
print "${pref} &blob);\n$check";
}
else {
print STDERR "\n---- $type\n";
exit; # exit to make this noticed!
}
}
elsif($_ =~ /^ CURLINFO_NONE/) {
$infomode = 1;
}
elsif($infomode &&
($_ =~ /^ CURLINFO_([^ ]*) *= *CURLINFO_([^ ]*)/)) {
my ($info, $type)=($1, $2);
my $c = " res = curl_easy_getinfo(curl, CURLINFO_$info,";
my $check = " if(UNEX(res)) {\n geterr(\"$info\", res, __LINE__);\n goto test_cleanup;\n }\n";
if($type eq "STRING") {
print "$c &charp);\n$check";
}
elsif($type eq "LONG") {
print "$c &val);\n$check";
}
elsif($type eq "OFF_T") {
print "$c &oval);\n$check";
}
elsif($type eq "DOUBLE") {
print "$c &dval);\n$check";
}
elsif($type eq "SLIST") {
print "$c &slist);\n$check";
print " if(slist)\n curl_slist_free_all(slist);\n";
}
elsif($type eq "SOCKET") {
print "$c &sockfd);\n$check";
}
elsif($type eq "PTR") {
if($info eq "CERTINFO") {
print "$c &certinfo);\n$check";
}
elsif(($info eq "TLS_SESSION") ||
($info eq "TLS_SSL_PTR")) {
print "$c &tlssession);\n$check";
}
else {
print STDERR "$info/$type is unsupported\n";
}
}
else {
print STDERR "$type is unsupported\n";
}
}
}
print <<FOOTER
curl_easy_setopt(curl, 1, 0);
res = CURLE_OK;
test_cleanup:
curl_easy_cleanup(curl);
curl_easy_cleanup(dep);
curl_share_cleanup(share);
curl_global_cleanup();
return (int)res;
}
FOOTER
;
|