2017-06-05 17:57:47 +08:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
# Usage:
|
2017-06-14 04:03:35 +08:00
|
|
|
# perl mk-lib1521.pl < ../../include/curl/curl.h > lib1521.c
|
2017-06-05 17:57:47 +08:00
|
|
|
|
2017-06-09 07:02:12 +08:00
|
|
|
# minimum and maximum long signed values
|
|
|
|
my $minlong = "LONG_MIN";
|
|
|
|
my $maxlong = "LONG_MAX";
|
2017-06-24 22:39:27 +08:00
|
|
|
# maximum long unsigned value
|
|
|
|
my $maxulong = "ULONG_MAX";
|
2017-06-05 17:57:47 +08:00
|
|
|
|
|
|
|
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"
|
2017-06-09 07:02:12 +08:00
|
|
|
#include <limits.h>
|
2017-06-05 17:57:47 +08:00
|
|
|
|
|
|
|
/* 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
|
2017-06-24 22:39:27 +08:00
|
|
|
#define OFF_HI (curl_off_t) $maxulong
|
2017-06-05 17:57:47 +08:00
|
|
|
#define OFF_NO (curl_off_t) 0
|
|
|
|
|
2017-06-19 15:29:41 +08:00
|
|
|
/* Unexpected error.
|
|
|
|
CURLE_NOT_BUILT_IN - means disabled at build
|
|
|
|
CURLE_UNKNOWN_OPTION - means no such option (anymore?)
|
|
|
|
CURLE_SSL_ENGINE_NOTFOUND - set unkown 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) )
|
|
|
|
|
2017-06-06 06:21:12 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-19 15:29:41 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-22 00:11:11 +08:00
|
|
|
static curl_progress_callback progresscb;
|
|
|
|
static curl_write_callback headercb;
|
|
|
|
static curl_debug_callback debugcb;
|
|
|
|
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;
|
2017-06-06 06:21:12 +08:00
|
|
|
|
2017-06-05 17:57:47 +08:00
|
|
|
int test(char *URL)
|
|
|
|
{
|
2017-06-14 04:03:35 +08:00
|
|
|
CURL *curl = NULL;
|
|
|
|
CURL *dep = NULL;
|
|
|
|
CURLSH *share = NULL;
|
2017-06-05 20:56:32 +08:00
|
|
|
char errorbuffer[CURL_ERROR_SIZE];
|
2017-06-06 06:21:12 +08:00
|
|
|
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";
|
2017-06-05 20:56:32 +08:00
|
|
|
struct curl_slist *slist=NULL;
|
|
|
|
struct curl_httppost *httppost=NULL;
|
|
|
|
FILE *stream = stderr;
|
2017-06-14 04:03:35 +08:00
|
|
|
struct data object;
|
2017-06-19 15:29:41 +08:00
|
|
|
char *charp;
|
|
|
|
long val;
|
2017-06-19 15:31:37 +08:00
|
|
|
curl_off_t oval;
|
2017-06-19 15:29:41 +08:00
|
|
|
double dval;
|
|
|
|
curl_socket_t sockfd;
|
|
|
|
struct curl_certinfo *certinfo;
|
|
|
|
struct curl_tlssessioninfo *tlssession;
|
|
|
|
CURLcode res = CURLE_OK;
|
2017-06-06 06:21:12 +08:00
|
|
|
(void)URL; /* not used */
|
2017-06-14 04:03:35 +08:00
|
|
|
easy_init(dep);
|
|
|
|
easy_init(curl);
|
2017-06-05 17:57:47 +08:00
|
|
|
share = curl_share_init();
|
2017-06-14 04:03:35 +08:00
|
|
|
if(!share) {
|
|
|
|
res = CURLE_OUT_OF_MEMORY;
|
|
|
|
goto test_cleanup;
|
|
|
|
}
|
|
|
|
|
2017-06-05 17:57:47 +08:00
|
|
|
HEADER
|
|
|
|
;
|
|
|
|
|
|
|
|
while(<STDIN>) {
|
|
|
|
if($_ =~ /^ CINIT\(([^ ]*), ([^ ]*), (\d*)\)/) {
|
|
|
|
my ($name, $type, $val)=($1, $2, $3);
|
2017-06-14 04:03:35 +08:00
|
|
|
my $w=" ";
|
2017-06-19 15:29:41 +08:00
|
|
|
my $pref = "${w}res = curl_easy_setopt(curl, CURLOPT_$name,";
|
2017-06-05 17:57:47 +08:00
|
|
|
my $i = ' ' x (length($w) + 23);
|
2017-06-19 15:29:41 +08:00
|
|
|
my $check = " if(UNEX(res)) {\n err(\"$name\", res, __LINE__); goto test_cleanup; }\n";
|
2017-06-05 17:57:47 +08:00
|
|
|
if($type eq "STRINGPOINT") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} \"string\");\n$check";
|
|
|
|
print "${pref} NULL);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
elsif($type eq "LONG") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} 0L);\n$check";
|
|
|
|
print "${pref} 22L);\n$check";
|
|
|
|
print "${pref} LO);\n$check";
|
|
|
|
print "${pref} HI);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
elsif($type eq "OBJECTPOINT") {
|
|
|
|
if($name =~ /DEPENDS/) {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} dep);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
2017-06-05 20:56:32 +08:00
|
|
|
elsif($name =~ "SHARE") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} share);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
2017-06-05 20:56:32 +08:00
|
|
|
elsif($name eq "ERRORBUFFER") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} errorbuffer);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
|
|
|
elsif(($name eq "POSTFIELDS") ||
|
|
|
|
($name eq "COPYPOSTFIELDS")) {
|
2017-06-19 15:29:41 +08:00
|
|
|
# set size to zero to avoid it being "illegal"
|
|
|
|
print " (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);\n";
|
|
|
|
print "${pref} stringpointerextra);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
|
|
|
elsif(($name eq "HTTPHEADER") ||
|
|
|
|
($name eq "POSTQUOTE") ||
|
|
|
|
($name eq "PREQUOTE") ||
|
|
|
|
($name eq "HTTP200ALIASES") ||
|
|
|
|
($name eq "TELNETOPTIONS") ||
|
|
|
|
($name eq "MAIL_RCPT") ||
|
|
|
|
($name eq "RESOLVE") ||
|
|
|
|
($name eq "PROXYHEADER") ||
|
|
|
|
($name eq "QUOTE")) {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} slist);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
|
|
|
elsif($name eq "HTTPPOST") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} httppost);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
|
|
|
elsif($name eq "STDERR") {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} stream);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
2017-06-05 17:57:47 +08:00
|
|
|
else {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} &object);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} NULL);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
elsif($type eq "FUNCTIONPOINT") {
|
2017-06-05 20:56:32 +08:00
|
|
|
if($name =~ /([^ ]*)FUNCTION/) {
|
|
|
|
my $l=lc($1);
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref}\n$i${l}cb);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
|
|
|
else {
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} &func);\n$check";
|
2017-06-05 20:56:32 +08:00
|
|
|
}
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} NULL);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
elsif($type eq "OFF_T") {
|
|
|
|
# play conservative to work with 32bit curl_off_t
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} OFF_NO);\n$check";
|
2017-06-24 22:39:27 +08:00
|
|
|
print "${pref} OFF_HI);\n$check";
|
2017-06-19 15:29:41 +08:00
|
|
|
print "${pref} OFF_LO);\n$check";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
else {
|
2017-06-19 15:29:41 +08:00
|
|
|
print STDERR "\n---- $type\n";
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 15:29:41 +08:00
|
|
|
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__); goto test_cleanup; }\n";
|
|
|
|
if($type eq "STRING") {
|
|
|
|
print "$c &charp);\n$check";
|
|
|
|
}
|
|
|
|
elsif($type eq "LONG") {
|
|
|
|
print "$c &val);\n$check";
|
|
|
|
}
|
2017-06-19 15:31:37 +08:00
|
|
|
elsif($type eq "OFF_T") {
|
|
|
|
print "$c &oval);\n$check";
|
|
|
|
}
|
2017-06-19 15:29:41 +08:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print <<FOOTER
|
2017-06-14 04:03:35 +08:00
|
|
|
curl_easy_setopt(curl, 1, 0);
|
2017-06-19 15:29:41 +08:00
|
|
|
res = CURLE_OK;
|
2017-06-14 04:03:35 +08:00
|
|
|
test_cleanup:
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_easy_cleanup(dep);
|
|
|
|
curl_share_cleanup(share);
|
|
|
|
|
2017-06-19 15:29:41 +08:00
|
|
|
return (int)res;
|
2017-06-05 17:57:47 +08:00
|
|
|
}
|
|
|
|
FOOTER
|
|
|
|
;
|