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