31 #include <sys/types.h>
38 #define _MPRINTF_REPLACE
48 #ifdef USE_ENVIRONMENT
52 #define CURLseparator "--_curl_--"
54 #if defined(WIN32)&&!defined(__CYGWIN32__)
58 #ifdef __NOVELL_LIBC__
62 #ifdef TIME_WITH_SYS_TIME
67 #ifdef HAVE_SYS_TIME_H
68 # include <sys/time.h>
92 #ifdef HAVE_SYS_UTIME_H
93 #include <sys/utime.h>
102 #ifdef HAVE_SYS_POLL_H
103 #include <sys/poll.h>
116 #define DEFAULT_MAXREDIRS 50L
119 void *xmalloc(
size_t);
120 char *msdosify(
char *);
121 char *rename_if_dos_device_name(
char *);
128 int poll (
struct pollfd *,
int,
int);
137 #define CURL_PROGRESS_STATS 0
138 #define CURL_PROGRESS_BAR 1
145 #define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))
159 #define CONF_DEFAULT 0
161 #define CONF_AUTO_REFERER (1<<4)
162 #define CONF_VERBOSE (1<<5)
163 #define CONF_HEADER (1<<8)
164 #define CONF_NOPROGRESS (1<<10)
165 #define CONF_NOBODY (1<<11)
166 #define CONF_FAILONERROR (1<<12)
167 #define CONF_FTPLISTONLY (1<<16)
168 #define CONF_FTPAPPEND (1<<20)
169 #define CONF_NETRC (1<<22)
170 #define CONF_FOLLOWLOCATION (1<<23)
171 #define CONF_GETTEXT (1<<24)
172 #define CONF_HTTPPOST (1<<25)
173 #define CONF_MUTE (1<<28)
175 #define CONF_NETRC_OPT (1<<29)
177 #define CONF_UNRESTRICTED_AUTH (1<<30)
189 newstr = (
char *) malloc((len+1)*
sizeof(char));
203 #define mkdir(x,y) (mkdir)(x)
224 static void main_free(
void)
236 fprintf(stderr,
"You can only select one HTTP request!\n");
240 static void helpf(
const char *fmt, ...)
245 fputs(
"curl: ", stderr);
246 vfprintf(stderr, fmt, ap);
249 fprintf(stderr,
"curl: try 'curl --help' "
251 "or 'curl --manual' "
253 "for more information\n");
267 #define GETOUT_OUTFILE (1<<0)
268 #define GETOUT_URL (1<<1)
269 #define GETOUT_USEREMOTE (1<<2)
270 #define GETOUT_UPLOAD (1<<3)
271 #define GETOUT_NOUPLOAD (1<<4)
274 static void help(
void)
277 static const char *helptext[]={
278 "Usage: curl [options...] <url>",
279 "Options: (H) means HTTP/HTTPS only, (F) means FTP only",
280 " -a/--append Append to target file when uploading (F)",
281 " -A/--user-agent <string> User-Agent to send to server (H)",
282 " --anyauth Tell curl to choose authentication method (H)",
283 " -b/--cookie <name=string/file> Cookie string or file to read cookies from (H)",
284 " --basic Enable HTTP Basic Authentication (H)",
285 " -B/--use-ascii Use ASCII/text transfer",
286 " -c/--cookie-jar <file> Write cookies to this file after operation (H)",
287 " -C/--continue-at <offset> Resumed transfer offset",
288 " -d/--data <data> HTTP POST data (H)",
289 " --data-ascii <data> HTTP POST ASCII data (H)",
290 " --data-binary <data> HTTP POST binary data (H)",
291 " --negotiate Enable HTTP Negotiate Authentication (H)",
292 " --digest Enable HTTP Digest Authentication (H)",
293 " --disable-eprt Prevent curl from using EPRT or LPRT (F)",
294 " --disable-epsv Prevent curl from using EPSV (F)",
295 " -D/--dump-header <file> Write the headers to this file",
296 " --egd-file <file> EGD socket path for random data (SSL)",
297 #ifdef USE_ENVIRONMENT
298 " --environment Write result codes to environment variables (RISC OS)",
300 " -e/--referer Referer URL (H)",
301 " -E/--cert <cert[:passwd]> Client certificate file and password (SSL)",
302 " --cert-type <type> Certificate file type (DER/PEM/ENG) (SSL)",
303 " --key <key> Private key file name (SSL)",
304 " --key-type <type> Private key file type (DER/PEM/ENG) (SSL)",
305 " --pass <pass> Pass phrase for the private key (SSL)",
306 " --engine <eng> Crypto engine to use (SSL)",
307 " --cacert <file> CA certificate to verify peer against (SSL)",
308 " --capath <directory> CA directory (made using c_rehash) to verify",
309 " peer against (SSL)",
310 " --ciphers <list> SSL ciphers to use (SSL)",
311 " --compressed Request compressed response (using deflate or gzip)",
312 " --connect-timeout <seconds> Maximum time allowed for connection",
313 " --create-dirs Create necessary local directory hierarchy",
314 " --crlf Convert LF to CRLF in upload",
315 " -f/--fail Fail silently (no output at all) on errors (H)",
316 " --ftp-create-dirs Create the remote dirs if not present (F)",
317 " --ftp-pasv Use PASV instead of PORT (F)",
318 " --ftp-ssl Enable SSL/TLS for the ftp transfer (F)",
319 " -F/--form <name=content> Specify HTTP multipart POST data (H)",
320 " -g/--globoff Disable URL sequences and ranges using {} and []",
321 " -G/--get Send the -d data with a HTTP GET (H)",
322 " -h/--help This help text",
323 " -H/--header <line> Custom header to pass to server (H)",
324 " -i/--include Include protocol headers in the output (H/F)",
325 " -I/--head Show document info only",
326 " -j/--junk-session-cookies Ignore session cookies read from file (H)",
327 " --interface <interface> Specify network interface to use",
328 " --krb4 <level> Enable krb4 with specified security level (F)",
329 " -k/--insecure Allow curl to connect to SSL sites without certs (H)",
330 " -K/--config Specify which config file to read",
331 " -l/--list-only List only names of an FTP directory (F)",
332 " --limit-rate <rate> Limit transfer speed to this rate",
333 " -L/--location Follow Location: hints (H)",
334 " --location-trusted Follow Location: and send authentication even ",
335 " to other hostnames (H)",
336 " -m/--max-time <seconds> Maximum time allowed for the transfer",
337 " --max-redirs <num> Maximum number of redirects allowed (H)",
338 " --max-filesize <bytes> Maximum file size to download (H/F)",
339 " -M/--manual Display the full manual",
340 " -n/--netrc Must read .netrc for user name and password",
341 " --netrc-optional Use either .netrc or URL; overrides -n",
342 " --ntlm Enable HTTP NTLM authentication (H)",
343 " -N/--no-buffer Disable buffering of the output stream",
344 " -o/--output <file> Write output to <file> instead of stdout",
345 " -O/--remote-name Write output to a file named as the remote file",
346 " -p/--proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)",
347 " --proxy-ntlm Enable NTLM authentication on the proxy (H)",
348 " -P/--ftp-port <address> Use PORT with address instead of PASV (F)",
349 " -q If used as the first parameter disables .curlrc",
350 " -Q/--quote <cmd> Send command(s) to server before file transfer (F)",
351 " -r/--range <range> Retrieve a byte range from a HTTP/1.1 or FTP server",
352 " --random-file <file> File for reading random data from (SSL)",
353 " -R/--remote-time Set the remote file's time on the local output",
354 " -s/--silent Silent mode. Don't output anything",
355 " -S/--show-error Show error. With -s, make curl show errors when they occur",
356 " --socks <host[:port]> Use SOCKS5 proxy on given host + port",
357 " --stderr <file> Where to redirect stderr. - means stdout",
358 " -t/--telnet-option <OPT=val> Set telnet option",
359 " --trace <file> Dump a network/debug trace to the given file",
360 " --trace-ascii <file> Like --trace but without the hex output",
361 " -T/--upload-file <file> Transfer/upload <file> to remote site",
362 " --url <URL> Another way to specify URL to work with",
363 " -u/--user <user[:password]> Specify user and password to use",
364 " Overrides -n and --netrc-optional",
365 " -U/--proxy-user <user[:password]> Specify Proxy authentication",
366 " -v/--verbose Make the operation more talkative",
367 " -V/--version Show version number and quit",
369 " --wdebug Turn on WATT-32 debugging under DJGPP",
371 " -w/--write-out [format] What to output after completion",
372 " -x/--proxy <host[:port]> Use HTTP proxy on given port",
373 " -X/--request <command> Specify request command to use",
374 " -y/--speed-time Time needed to trig speed-limit abort. Defaults to 30",
375 " -Y/--speed-limit Stop transfer if below speed-limit for 'speed-time' secs",
376 " -z/--time-cond <time> Transfer based on a time condition",
377 " -0/--http1.0 Use HTTP 1.0 (H)",
378 " -1/--tlsv1 Use TLSv1 (SSL)",
379 " -2/--sslv2 Use SSLv2 (SSL)",
380 " -3/--sslv3 Use SSLv3 (SSL)",
381 " -4/--ipv4 Resolve name to IPv4 address",
382 " -6/--ipv6 Resolve name to IPv6 address",
383 " -#/--progress-bar Display transfer progress as a progress bar",
386 for(i=0; helptext[
i]; i++) {
388 #ifdef __NOVELL_LIBC__
389 if (i && ((i % 23) == 0))
514 static void parseconfig(
const char *filename,
516 static char *my_get_line(FILE *fp);
517 static int create_dir_hierarchy(
char *outfile);
519 static void GetStr(
char **
string,
530 static char *file2string(FILE *file)
539 while(fgets(buffer,
sizeof(buffer), file)) {
540 ptr= strchr(buffer,
'\r');
543 ptr= strchr(buffer,
'\n');
546 stringlen=strlen(buffer);
548 string = realloc(
string, len+stringlen+1);
550 string = malloc(stringlen+1);
552 strcpy(
string+len, buffer);
562 static char *file2memory(FILE *file,
long *
size)
566 char *newstring=
NULL;
571 while((len =
fread(buffer, 1,
sizeof(buffer), file))) {
573 newstring = realloc(
string, len+stringlen);
580 string = malloc(len);
581 memcpy(&
string[stringlen], buffer, len);
616 memset(node, 0,
sizeof(
struct getout));
641 AddMultiFiles (
const char *file_name,
642 const char *type_name,
643 const char *show_filename,
660 *multi_start = multi;
666 multi_type->
form.
option = CURLFORM_CONTENTTYPE;
668 multi->
next = multi_type;
683 multi->
next = multi_name;
694 (*multi_current)->next = multi;
696 *multi_current = multi;
698 return *multi_current;
703 static void FreeMultiInfo (
struct multi_files *multi_start)
706 while (multi_start) {
708 multi_start = multi_start->
next;
747 #define FORM_FILE_SEPARATOR ','
748 #define FORM_TYPE_SEPARATOR ';'
750 static int formparse(
char *
input,
767 contents = malloc(strlen(input));
768 contents[0] =
'\000';
770 if(1 <= sscanf(input,
"%255[^=]=%[^\n]", name, contents)) {
774 if(
'@' == contp[0]) {
779 multi_start = multi_current=
NULL;
791 if(sep2 && (sep2 < sep)) {
812 while(isspace((
int)*ptr))
821 if(2 != sscanf(type,
"%127[^/]/%127[^;,\n]",
823 fprintf(stderr,
"Illegally formatted content-type field!\n");
825 FreeMultiInfo (multi_start);
829 sep = (
char *)type + strlen(major)+strlen(minor)+1;
866 if (!AddMultiFiles (contp, type, filename, &multi_start,
868 fprintf(stderr,
"Error building form post!\n");
870 FreeMultiInfo (multi_start);
875 }
while(sep && *sep);
881 unsigned int i,
count = 0;
890 fprintf(stderr,
"Error building form post!\n");
892 FreeMultiInfo (multi_start);
895 for (i = 0, ptr = multi_start; i <
count; ++
i, ptr = ptr->
next)
897 forms[
i].
option = ptr->form.option;
898 forms[
i].
value = ptr->form.value;
901 FreeMultiInfo (multi_start);
903 CURLFORM_COPYNAME, name,
904 CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {
905 fprintf(stderr,
"curl_formadd failed!\n");
914 if( contp[0]==
'<' ) {
916 CURLFORM_COPYNAME, name,
917 CURLFORM_FILECONTENT, contp+1, CURLFORM_END) != 0) {
918 fprintf(stderr,
"curl_formadd failed!\n");
925 CURLFORM_COPYNAME, name,
926 CURLFORM_COPYCONTENTS, contp, CURLFORM_END) != 0) {
927 fprintf(stderr,
"curl_formadd failed!\n");
936 fprintf(stderr,
"Illegally formatted input field!\n");
958 static const char *param2text(
int res)
963 return "had unsupported trailing garbage";
967 return "is ambiguous";
969 return "requires parameter";
971 return "is badly used here";
973 return "expected a proper numerical parameter";
975 return "the installed libcurl version doesn't support this";
977 return "unknown error";
981 static void cleanarg(
char *str)
983 #ifdef HAVE_WRITABLE_ARGV
988 size_t len = strlen(str);
989 memset(str,
' ', len);
1003 static int str2num(
long *val,
char *str)
1006 if(isdigit((
int)*str))
1021 static int str2offset(
curl_off_t *val,
char *str)
1023 #if SIZEOF_CURL_OFF_T > 4
1029 #define LLONG_MAX (curl_off_t)0x7FFFFFFFFFFFFFFFi64
1030 #define LLONG_MIN (curl_off_t)0x8000000000000000i64
1032 #define LLONG_MAX (curl_off_t)0x7FFFFFFFFFFFFFFFLL
1033 #define LLONG_MIN (curl_off_t)0x8000000000000000LL
1040 if ((*val == LLONG_MAX || *val == LLONG_MIN) && errno == ERANGE)
1043 *val = strtol(str,
NULL, 0);
1050 static void checkpasswd(
const char *kind,
1053 char *ptr = strchr(*userpwd,
':');
1056 char passwd[256]=
"";
1059 size_t userlen = strlen(*userpwd);
1064 "Enter %s password for user '%s':",
1068 getpass_r(prompt, passwd,
sizeof(passwd));
1069 passwdlen = strlen(passwd);
1072 passptr = realloc(*userpwd,
1078 passptr[userlen]=
':';
1079 memcpy(&passptr[userlen+1], passwd, passwdlen+1);
1094 const char *parse=
NULL;
1099 bool singleopt=
FALSE;
1110 {
"*a",
"random-file",
TRUE},
1111 {
"*b",
"egd-file",
TRUE},
1112 {
"*c",
"connect-timeout",
TRUE},
1113 {
"*d",
"ciphers",
TRUE},
1114 {
"*e",
"disable-epsv",
FALSE},
1115 #ifdef USE_ENVIRONMENT
1116 {
"*f",
"environment",
FALSE},
1118 {
"*g",
"trace",
TRUE},
1119 {
"*h",
"trace-ascii",
TRUE},
1120 {
"*i",
"limit-rate",
TRUE},
1121 {
"*j",
"compressed",
FALSE},
1122 {
"*k",
"digest",
FALSE},
1123 {
"*l",
"negotiate",
FALSE},
1124 {
"*m",
"ntlm",
FALSE},
1125 {
"*n",
"basic",
FALSE},
1126 {
"*o",
"anyauth",
FALSE},
1128 {
"*p",
"wdebug",
FALSE},
1130 {
"*q",
"ftp-create-dirs",
FALSE},
1131 {
"*r",
"create-dirs",
FALSE},
1132 {
"*s",
"max-redirs",
TRUE},
1133 {
"*t",
"proxy-ntlm",
FALSE},
1134 {
"*u",
"crlf",
FALSE},
1135 {
"*v",
"stderr",
TRUE},
1136 {
"*w",
"interface",
TRUE},
1137 {
"*x",
"krb4",
TRUE},
1138 {
"*y",
"max-filesize",
TRUE},
1139 {
"*z",
"disable-eprt",
FALSE},
1140 {
"$a",
"ftp-ssl",
FALSE},
1141 {
"$b",
"ftp-pasv",
FALSE},
1142 {
"$c",
"socks5",
TRUE},
1143 {
"0",
"http1.0",
FALSE},
1144 {
"1",
"tlsv1",
FALSE},
1145 {
"2",
"sslv2",
FALSE},
1146 {
"3",
"sslv3",
FALSE},
1147 {
"4",
"ipv4",
FALSE},
1148 {
"6",
"ipv6",
FALSE},
1149 {
"a",
"append",
FALSE},
1150 {
"A",
"user-agent",
TRUE},
1151 {
"b",
"cookie",
TRUE},
1152 {
"B",
"use-ascii",
FALSE},
1153 {
"c",
"cookie-jar",
TRUE},
1154 {
"C",
"continue-at",
TRUE},
1155 {
"d",
"data",
TRUE},
1156 {
"da",
"data-ascii",
TRUE},
1157 {
"db",
"data-binary",
TRUE},
1158 {
"D",
"dump-header",
TRUE},
1159 {
"e",
"referer",
TRUE},
1160 {
"E",
"cert",
TRUE},
1161 {
"Ea",
"cacert",
TRUE},
1162 {
"Eb",
"cert-type",
TRUE},
1164 {
"Ed",
"key-type",
TRUE},
1165 {
"Ee",
"pass",
TRUE},
1166 {
"Ef",
"engine",
TRUE},
1167 {
"Eg",
"capath ",
TRUE},
1168 {
"f",
"fail",
FALSE},
1169 {
"F",
"form",
TRUE},
1170 {
"g",
"globoff",
FALSE},
1171 {
"G",
"get",
FALSE},
1172 {
"h",
"help",
FALSE},
1173 {
"H",
"header",
TRUE},
1174 {
"i",
"include",
FALSE},
1175 {
"I",
"head",
FALSE},
1176 {
"j",
"junk-session-cookies",
FALSE},
1177 {
"k",
"insecure",
FALSE},
1178 {
"K",
"config",
TRUE},
1179 {
"l",
"list-only",
FALSE},
1180 {
"L",
"location",
FALSE},
1181 {
"Lt",
"location-trusted",
FALSE},
1182 {
"m",
"max-time",
TRUE},
1183 {
"M",
"manual",
FALSE},
1184 {
"n",
"netrc",
FALSE},
1185 {
"no",
"netrc-optional",
FALSE},
1186 {
"N",
"no-buffer",
FALSE},
1187 {
"o",
"output",
TRUE},
1188 {
"O",
"remote-name",
FALSE},
1189 {
"p",
"proxytunnel",
FALSE},
1190 {
"P",
"ftpport",
TRUE},
1191 {
"P",
"ftp-port",
TRUE},
1192 {
"q",
"disable",
FALSE},
1193 {
"Q",
"quote",
TRUE},
1194 {
"r",
"range",
TRUE},
1195 {
"R",
"remote-time",
FALSE},
1196 {
"s",
"silent",
FALSE},
1197 {
"S",
"show-error",
FALSE},
1198 {
"t",
"telnet-options",
TRUE},
1199 {
"T",
"upload-file",
TRUE},
1200 {
"u",
"user",
TRUE},
1201 {
"U",
"proxy-user",
TRUE},
1202 {
"v",
"verbose",
FALSE},
1203 {
"V",
"version",
FALSE},
1204 {
"w",
"write-out",
TRUE},
1205 {
"x",
"proxy",
TRUE},
1206 {
"X",
"request",
TRUE},
1207 {
"X",
"http-request",
TRUE},
1208 {
"Y",
"speed-limit",
TRUE},
1209 {
"y",
"speed-time",
TRUE},
1210 {
"z",
"time-cond",
TRUE},
1211 {
"#",
"progress-bar",
FALSE},
1214 if((
'-' != flag[0]) ||
1215 ((
'-' == flag[0]) && (
'-' == flag[1]))) {
1217 char *
word=(
'-' == flag[0])?flag+2:flag;
1218 size_t fnam=strlen(word);
1220 for(j=0; j<
sizeof(aliases)/
sizeof(aliases[0]); j++) {
1252 letter = parse?(char)*parse:
'\0';
1255 subletter = parse[1];
1260 fprintf(stderr,
"OPTION: %c %s\n", letter, nextarg?nextarg:
"<null>");
1263 for(j=0; j<
sizeof(aliases)/
sizeof(aliases[0]); j++) {
1264 if(letter == aliases[j].letter[0]) {
1276 if(!longopt && aliases[hit].
extraparam && parse[1]) {
1277 nextarg=(
char *)&parse[1];
1280 else if(!nextarg && aliases[hit].
extraparam) {
1283 else if(nextarg && aliases[hit].extraparam)
1293 GetStr(&config->
egd_file, nextarg);
1305 #ifdef USE_ENVIRONMENT
1321 unsigned long value = strtol(nextarg, &unit, 0);
1322 switch(nextarg[strlen(nextarg)-1]) {
1325 value *= 1024*1024*1024;
1386 if(str2num(&config->
maxredirs, nextarg))
1400 if(
strcmp(nextarg,
"-")) {
1401 config->
errors = fopen(nextarg,
"wt");
1409 GetStr(&config->
iface, nextarg);
1443 url=new_getout(config);
1447 GetStr(&url->
url, nextarg);
1504 if(nextarg[0] ==
'@') {
1507 else if(strchr(nextarg,
'=')) {
1509 GetStr(&config->
cookie, nextarg);
1539 char *postdata=
NULL;
1541 if(
'@' == *nextarg) {
1551 file = fopen(nextarg,
"rb");
1553 if(subletter ==
'b')
1556 postdata = file2string(file);
1557 if(file && (file != stdin))
1561 GetStr(&postdata, nextarg);
1568 config->
postfields=aprintf(
"%s&%s", oldpost, postdata);
1589 char *ptr = strstr(nextarg,
";auto");
1596 GetStr(&config->
referer, nextarg);
1603 GetStr(&config->
cacert, nextarg);
1609 GetStr(&config->
key, nextarg);
1612 GetStr(&config->
key_type, nextarg);
1619 GetStr(&config->
engine, nextarg);
1623 GetStr(&config->
capath, nextarg);
1627 char *ptr = strchr(nextarg,
':');
1635 (ptr == &nextarg[1]) &&
1636 (nextarg[2] ==
'\\') &&
1637 (isalpha((
int)nextarg[0])) )
1642 ptr = strchr(&nextarg[3],
':');
1650 GetStr(&config->
cert, nextarg);
1662 if(formparse(nextarg,
1714 parseconfig(nextarg, config);
1721 switch (subletter) {
1731 if(str2num(&config->
timeout, nextarg))
1740 "curl: built-in manual was disabled at build-time!\n");
1779 url=new_getout(config);
1784 GetStr(&url->
outfile, nextarg);
1799 GetStr(&config->
ftpport, nextarg);
1811 switch(nextarg[0]) {
1828 GetStr(&config->
range, nextarg);
1866 url=new_getout(config);
1874 GetStr(&url->
infile, nextarg);
1881 GetStr(&config->
userpwd, nextarg);
1883 checkpasswd(
"host", &config->
userpwd);
1900 printf(
"Protocols: ");
1901 for (proto=curlinfo->
protocols; *proto; ++proto) {
1902 printf(
"%s ", *proto);
1912 struct feat feats[] = {
1924 printf(
"Features: ");
1925 for(i=0; i<
sizeof(feats)/
sizeof(feats[0]); i++) {
1926 if(curlinfo->
features & feats[i].bitmask)
1927 printf(
"%s ", feats[i].
name);
1935 if(
'@' == *nextarg) {
1943 file = fopen(nextarg,
"r");
1944 config->
writeout = file2string(file);
1945 if(file && (file != stdin))
1949 GetStr(&config->
writeout, nextarg);
1953 GetStr(&config->
proxy, nextarg);
1996 struct stat statbuf;
1997 if(-1 == stat(nextarg, &statbuf)) {
2003 config->
condtime = statbuf.st_mtime;
2012 }
while(!longopt && !singleopt && *++parse && !*usedarg);
2018 static void parseconfig(
const char *filename,
2023 char filebuffer[512];
2027 if(!filename || !*filename) {
2030 #define CURLRC DOT_CHAR "curlrc"
2036 if(strlen(home)<(
sizeof(filebuffer)-strlen(
CURLRC))) {
2037 snprintf(filebuffer,
sizeof(filebuffer),
2040 filename = filebuffer;
2048 filename =
"ENV:" CURLRC;
2054 file = fopen(filename,
"r");
2066 #define isseparator(x) (((x)=='=') || ((x) == ':'))
2068 while (
NULL != (aline = my_get_line(file))) {
2071 alloced_param=
FALSE;
2074 while(*line && isspace((
int)*line))
2090 while(*line && !isspace((
int)*line) && !
isseparator(*line))
2098 fprintf(stderr,
"GOT: %s\n", option);
2102 while(*line && (isspace((
int)*line) ||
isseparator(*line)))
2114 while(*line && (*line !=
'\"')) {
2120 switch(out = *line) {
2147 while(*line && !isspace((
int)*line))
2152 if (param && !*param) {
2161 fprintf(stderr,
"PARAM: \"%s\"\n",(param ? param :
"(null)"));
2163 res = getparameter(option, param, &usedarg, config);
2165 if (param && *param && !usedarg)
2171 if(!
strcmp(filename,
"-")) {
2172 filename=(
char *)
"<stdin>";
2175 const char *reason = param2text(res);
2176 fprintf(stderr,
"%s:%d: warning: '%s' %s\n",
2177 filename, lineno, option, reason);
2194 static void go_sleep(
long ms)
2198 poll((
void *)0, 0, ms);
2210 timeout.tv_usec = ms * 1000;
2224 static int my_fwrite(
void *buffer,
size_t size,
size_t nmemb,
void *stream)
2229 if(out && !out->
stream) {
2251 sleep_time = (size*nmemb)*1000/config->
recvpersecond - timediff*1000;
2261 go_sleep (sleep_time);
2281 static int my_fread(
void *buffer,
size_t size,
size_t nmemb,
void *userp)
2328 static int myprogress (
void *clientp,
2353 int prevblock = (
int)bar->
prev / 1024;
2354 int thisblock = (
int)point / 1024;
2355 while ( thisblock > prevblock ) {
2356 fprintf( bar->
out,
"#" );
2361 frac = point / total;
2362 percent = frac * 100.0f;
2363 barwidth = bar->
width - 7;
2364 num = (
int) (((
double)barwidth) * frac);
2366 for ( i = 0; i <
num; i++ ) {
2370 sprintf( format,
"%%-%ds %%5.1f%%%%", barwidth );
2371 sprintf( outline, format, line, percent );
2372 fprintf( bar->
out,
"\r%s", outline );
2406 bar->
width = atoi(colp);
2419 bar->
width = scr_size[0] - 1;
2426 void dump(
const char *text,
2427 FILE *stream,
unsigned char *ptr,
size_t size,
2433 unsigned int width=0x10;
2439 fprintf(stream,
"%s, %zd bytes (0x%zx)\n", text, size, size);
2443 fprintf(stream,
"%04zx: ", i);
2447 for(c = 0; c <
width; c++)
2449 fprintf(stream,
"%02x ", ptr[i+c]);
2454 for(c = 0; (c <
width) && (i+c < size); c++) {
2456 if (nohex && (i+c+1 < size) && ptr[i+
c]==0x0D && ptr[i+c+1]==0x0A) {
2460 fprintf(stream,
"%c",
2461 (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:
'.');
2463 if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
2468 fputc(
'\n', stream);
2475 unsigned char *
data,
size_t size,
2479 FILE *output=config->
errors;
2499 fprintf(output,
"== Info: %s", data);
2504 text =
"=> Send header";
2507 text =
"=> Send data";
2510 text =
"<= Recv header";
2513 text =
"<= Recv data";
2517 dump(text, output, data, size, config->
trace_ascii);
2521 static void free_config_fields(
struct Configurable *config)
2532 free(config->
proxy);
2546 free(config->
range);
2565 #if defined(WIN32) && !defined(__CYGWIN32__)
2577 static void FindWin32CACert(
struct Configurable *config,
2578 const char *bundle_file)
2584 char *retval = (
char *) malloc(
sizeof (TCHAR) * (MAX_PATH + 1));
2588 buflen = SearchPathA(
NULL, bundle_file,
NULL, MAX_PATH+2, retval, &ptr);
2590 GetStr(&config->
cacert, retval);
2599 operate(
struct Configurable *config,
int argc,
char *argv[])
2619 char *uploadfile=
NULL;
2625 FILE *headerfilep =
NULL;
2626 char *urlbuffer=
NULL;
2628 bool stillflags=
TRUE;
2630 bool allocuseragent=
FALSE;
2632 char *httpgetfields=
NULL;
2649 curl_memlimit(atoi(env));
2654 memset(&outs,0,
sizeof(outs));
2663 helpf(
"error initializing curl library\n");
2673 strchr(argv[1],
'q')) {
2681 parseconfig(
NULL, config);
2684 if ((argc < 2) && !config->
url_list) {
2690 for (i = 1; i < argc; i++) {
2692 (
'-' == argv[i][0])) {
2695 char *origopt=argv[
i];
2697 char *flag = argv[
i];
2704 nextarg= (i < argc - 1)? argv[i+1]:
NULL;
2706 res = getparameter(flag, nextarg, &passarg, config);
2708 const char *reason = param2text(res);
2710 helpf(
"option %s: %s\n", origopt, reason);
2711 clean_getout(config);
2722 res = getparameter((
char *)
"--url", argv[i], &used, config);
2729 clean_getout(config);
2730 helpf(
"no URL specified!\n");
2735 snprintf(useragent,
sizeof(useragent),
2740 allocuseragent =
TRUE;
2756 GetStr(&config->
cacert, env);
2759 #if defined(WIN32) && !defined(__CYGWIN32__)
2761 FindWin32CACert(config,
"curl-ca-bundle.crt");
2773 free(httpgetfields);
2789 clean_getout(config);
2806 heads.stream = headerfilep;
2811 while(urlnode && !res) {
2825 nextnode=urlnode->
next;
2832 outs.stream = stdout;
2838 infiles = urlnode->
infile;
2840 if(!config->
globoff && infiles) {
2842 res =
glob_url(&inglob, infiles, &infilenum,
2846 clean_getout(config);
2854 (!up && !infiles) ||
2855 (uploadfile = inglob?
2864 res =
glob_url(&urls, dourl, &urlnum,
2875 separator= ((!outfiles ||
curl_strequal(outfiles,
"-")) && urlnum > 1);
2882 outfile = outfiles?
strdup(outfiles):NULL;
2894 char * pc =strstr(url,
"://");
2899 pc = strrchr(pc,
'/');
2904 outfile = *pc ?
strdup(pc): NULL;
2906 if(!outfile || !*outfile) {
2907 helpf(
"Remote file name has no length!\n");
2912 #if defined(__DJGPP__)
2916 char *file1=xmalloc(PATH_MAX);
2917 strcpy(file1, msdosify(outfile));
2918 strcpy(outfile, rename_if_dos_device_name(file1));
2925 char *storefile = outfile;
2930 fprintf(stderr,
"bad output glob!\n");
2941 if (-1 == create_dir_hierarchy(outfile)) {
2949 struct stat fileinfo;
2952 if(0 == stat(outfile, &fileinfo))
2960 outs.filename = outfile;
2964 outs.stream=(FILE *) fopen(outfile, config->
resume_from?
"ab":
"wb");
2966 helpf(
"Can't open '%s'!\n", outfile);
2979 struct stat fileinfo;
2982 char *ptr=strstr(url,
"://");
2987 ptr = strrchr(ptr,
'/');
2988 if(!ptr || !strlen(++ptr)) {
2995 char *filep = strrchr(uploadfile,
'/');
2996 char *file2 = strrchr(filep?filep:uploadfile,
'\\');
3010 urlbuffer=(
char *)malloc(strlen(url) + strlen(filep) + 3);
3012 helpf(
"out of memory\n");
3017 sprintf(urlbuffer,
"%s%s", url, filep);
3020 sprintf(urlbuffer,
"%s/%s", url, filep);
3038 infd=(FILE *) fopen(uploadfile,
"rb");
3039 if (!infd || stat(uploadfile, &fileinfo)) {
3040 helpf(
"Can't open '%s'!\n", uploadfile);
3044 uploadfilesize=fileinfo.st_size;
3054 if(outs.stream && isatty(
fileno(outs.stream)))
3060 fprintf(stderr,
"\n[%d/%d]: %s --> %s\n",
3061 i+1, urlnum, url, outfile ? outfile :
"<stdout>");
3065 if (httpgetfields) {
3067 const char *pc =strstr(url,
"://");
3074 pc = strrchr(pc,
'/');
3087 urlbuffer=(
char *)malloc(strlen(url) + strlen(httpgetfields) + 2);
3089 helpf(
"out of memory\n");
3093 sprintf(urlbuffer,
"%s%c%s", url, sep, httpgetfields);
3098 sprintf(urlbuffer,
"%s/?%s", url, httpgetfields);
3111 setmode(
fileno(stdout), O_BINARY );
3124 input.stream = infd;
3125 input.config = config;
3240 progressbarinit(&progressbar, config);
3313 progressbar.calls) {
3316 fputs(
"\n", progressbar.out);
3322 #ifdef USE_ENVIRONMENT
3334 fprintf(config->
errors,
"curl: (%d) %s\n\n", res, errorbuffer);
3335 #define CURL_CA_CERT_ERRORMSG1 \
3336 "More details here: http://curl.haxx.se/docs/sslcerts.html\n\n" \
3337 "curl performs SSL certificate verification by default, using a \"bundle\"\n" \
3338 " of Certificate Authority (CA) public keys (CA certs). The default\n" \
3339 " bundle is named curl-ca-bundle.crt; you can specify an alternate file\n" \
3340 " using the --cacert option.\n"
3342 #define CURL_CA_CERT_ERRORMSG2 \
3343 "If this HTTPS server uses a certificate signed by a CA represented in\n" \
3344 " the bundle, the certificate verification probably failed due to a\n" \
3345 " problem with the certificate (it might be expired, or the name might\n" \
3346 " not match the domain name in the URL).\n" \
3347 "If you'd like to turn off curl's verification of the certificate, use\n" \
3348 " the -k (or --insecure) option.\n"
3350 fprintf(config->
errors,
"%s%s",
3355 fprintf(config->
errors,
"curl: (%d) %s\n", res, errorbuffer);
3360 fclose(outs.stream);
3370 struct utimbuf times;
3371 times.actime = filetime;
3372 times.modtime = filetime;
3373 utime(outs.filename, ×);
3380 if( strlen(url) > 78 )
3383 SetComment( outs.filename, url);
3387 fclose(headerfilep);
3390 free(httpgetfields);
3427 nextnode=urlnode->
next;
3433 if(config->
headerfile && !headerfilep && heads.stream)
3434 fclose(heads.stream);
3459 res = operate(&config, argc, argv);
3460 free_config_fields(&config);
3462 #ifdef __NOVELL_LIBC__
3473 static char *my_get_line(FILE *fp)
3477 char *retval =
NULL;
3480 if (NULL == fgets(buf,
sizeof(buf), fp))
3485 if (NULL == (retval = realloc(retval,
3486 strlen(retval) + strlen(buf) + 1)))
3488 strcat(retval, buf);
3491 while (NULL == (nl = strchr(retval,
'\n')));
3505 static int create_dir_hierarchy(
char *outfile)
3513 outdup =
strdup(outfile);
3514 dirbuildup = malloc(
sizeof(
char) * strlen(outfile));
3517 dirbuildup[0] =
'\0';
3519 tempdir = strtok(outdup,
DIR_CHAR);
3521 while (tempdir != NULL) {
3525 if (tempdir2 != NULL) {
3526 if (strlen(dirbuildup) > 0)
3530 sprintf(dirbuildup,
"%s",tempdir);
3534 if (access(dirbuildup,
F_OK) == -1) {
3535 result = mkdir(dirbuildup,(mode_t)0000750);
3540 fprintf(stderr,
"You don't have permission to create %s.\n",
3546 fprintf(stderr,
"The directory name %s is too long.\n",
3552 fprintf(stderr,
"%s resides on a read-only file system.\n",
3558 fprintf(stderr,
"No space left on the file system that will "
3559 "contain the directory %s.\n", dirbuildup);
3564 fprintf(stderr,
"Cannot create directory %s because you "
3565 "exceeded your quota.\n", dirbuildup);
3569 fprintf(stderr,
"Error creating directory %s.\n", dirbuildup);
3589 msdosify (
char *file_name)
3591 static char dos_name[PATH_MAX];
3592 static char illegal_chars_dos[] =
".+, ;=[]|<>\\\":?*";
3593 static char *illegal_chars_w95 = &illegal_chars_dos[8];
3595 char *
s = file_name, *d = dos_name;
3596 char *illegal_aliens = illegal_chars_dos;
3597 size_t len =
sizeof (illegal_chars_dos) - 1;
3601 if (_use_lfn (file_name))
3604 illegal_aliens = illegal_chars_w95;
3605 len -= (illegal_chars_w95 - illegal_chars_dos);
3609 if (s[0] >=
'A' && s[0] <=
'z' && s[1] ==
':') {
3614 for (idx = 0, dot_idx = -1; *
s; s++, d++) {
3615 if (memchr (illegal_aliens, *s, len)) {
3622 if (idx == 0 && (s[1] ==
'/' || (s[1] ==
'.' && s[2] ==
'/'))) {
3631 else if (dot_idx >= 0) {
3633 d[dot_idx - idx] =
'_';
3645 else if (*s ==
'+' && s[1] ==
'+') {
3646 if (idx - 2 == dot_idx) {
3652 memcpy (d,
"plus", 4);
3676 rename_if_dos_device_name (
char *file_name)
3681 extern char *basename (
const char *);
3684 char fname[PATH_MAX];
3686 strcpy (fname, file_name);
3687 base = basename (fname);
3688 if (((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
3689 size_t blen = strlen (base);
3692 memmove (base + 1, base, blen + 1);
3694 strcpy (file_name, fname);
char * glob_match_url(char *filename, URLGlob *glob)
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
struct curl_httppost * last_post
CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info,...)
int main(int argc, char *argv[])
GLsizei const GLfloat * value
struct Configurable * config
GLenum GLsizei GLenum format
#define CURL_VERSION_LIBZ
char * curl_getenv(const char *variable)
#define CONF_FOLLOWLOCATION
CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post,...)
time_t curl_getdate(const char *p, const time_t *now)
#define DEFAULT_MAXREDIRS
CURLcode curl_easy_perform(CURL *curl)
#define CURLAUTH_GSSNEGOTIATE
GLenum GLsizei const GLvoid * string
GLuint GLuint GLsizei GLenum type
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
void Sleep(const int time)
#define CURL_CA_CERT_ERRORMSG2
#define CONF_UNRESTRICTED_AUTH
#define CURL_VERSION_NTLM
void ourWriteOut(CURL *curl, char *writeinfo)
GLuint GLuint GLsizei count
struct multi_files * next
void curl_global_cleanup(void)
Globally cleanup cURL, uses the value of "init_flags" to determine what needs to be cleaned up and ...
struct curl_slist * quote
#define CURL_VERSION_DEBUG
void ourWriteEnv(CURL *curl)
char * getpass_r(const char *prompt, char *buffer, size_t buflen)
GLsizei GLsizei GLenum GLenum const GLvoid * data
#define CURL_GLOBAL_DEFAULT
void glob_cleanup(URLGlob *glob)
char * curl_escape(const char *string, int length)
char * glob_next_url(URLGlob *glob)
int() curl_strnequal(const char *s1, const char *s2, size_t n)
GLenum GLenum GLenum input
struct curl_slist * prequote
#define CURL_VERSION_IPV6
#define MIN(X, Y)
standard MIN macro
#define FORM_TYPE_SEPARATOR
#define CURL_VERSION_GSSNEGOTIATE
void curl_formfree(struct curl_httppost *form)
int glob_url(URLGlob **glob, char *url, int *urlnum, FILE *error)
#define FORM_FILE_SEPARATOR
struct Configurable * config
curl_version_info_data * curl_version_info(CURLversion)
char * curl_version(void)
int curl_msnprintf(char *buffer, size_t maxlength, const char *format,...)
struct curl_slist * postquote
struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
#define CONF_AUTO_REFERER
#define CURL_CA_CERT_ERRORMSG1
struct curl_httppost * httppost
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
void curl_slist_free_all(struct curl_slist *)
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
struct curl_slist * telnet_options
#define CURL_VERSION_ASYNCHDNS
int() curl_strequal(const char *s1, const char *s2)
void curl_easy_cleanup(CURL *curl)
struct curl_slist * headers
#define CURLOPT_WRITEDATA
#define CURL_VERSION_LARGEFILE
#define CURL_PROGRESS_BAR
int sprintf(idStr &string, const char *fmt,...)
#define CURL_VERSION_KERBEROS4
CURL * curl_easy_init(void)
int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
#define CURL_VERSION_SPNEGO