/***************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 2000, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. * * 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 MPL or the MIT/X-derivate * licenses. You may pick one of these licenses. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id: main.c,v 1.1.1.2 2001/04/24 18:49:15 wsanchez Exp $ *****************************************************************************/ /* This is now designed to have its own local setup.h */ #include "setup.h" #include #include #include #include #include #include #include #include #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */ #include #include "urlglob.h" #include "writeout.h" #define CURLseparator "--_curl_--" #if defined(WIN32)&&!defined(__CYGWIN32__) #include #endif #include "version.h" #ifdef HAVE_IO_H /* typical win32 habit */ #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_FCNTL_H #include #endif /* The last #include file should be: */ #ifdef MALLOCDEBUG /* this is low-level hard-hacking memory leak tracking shit */ #include "../lib/memdebug.h" #endif #define DEFAULT_MAXREDIRS 50L #ifndef __cplusplus /* (rabe) */ typedef char bool; #endif /* (rabe) */ #define CURL_PROGRESS_STATS 0 /* default progress display */ #define CURL_PROGRESS_BAR 1 typedef enum { HTTPREQ_UNSPEC, HTTPREQ_GET, HTTPREQ_HEAD, HTTPREQ_POST, HTTPREQ_SIMPLEPOST, HTTPREQ_CUSTOM, HTTPREQ_LAST } HttpReq; /* Just a set of bits */ #define CONF_DEFAULT 0 #define CONF_USEREMOTETIME (1<<0) /* set the remote time on the local file */ #define CONF_AUTO_REFERER (1<<4) /* the automatic referer-system please! */ #define CONF_VERBOSE (1<<5) /* talk a lot */ #define CONF_HEADER (1<<8) /* throw the header out too */ #define CONF_NOPROGRESS (1<<10) /* shut off the progress meter */ #define CONF_NOBODY (1<<11) /* use HEAD to get http document */ #define CONF_FAILONERROR (1<<12) /* no output on http error codes >= 300 */ #define CONF_UPLOAD (1<<14) /* this is an upload */ #define CONF_FTPLISTONLY (1<<16) /* Use NLST when listing ftp dir */ #define CONF_FTPAPPEND (1<<20) /* Append instead of overwrite on upload! */ #define CONF_NETRC (1<<22) /* read user+password from .netrc */ #define CONF_FOLLOWLOCATION (1<<23) /* use Location: Luke! */ #define CONF_GETTEXT (1<<24) /* use ASCII/text for transfer */ #define CONF_HTTPPOST (1<<25) /* multipart/form-data HTTP POST */ #define CONF_MUTE (1<<28) /* force NOPROGRESS */ #ifndef HAVE_STRDUP /* Ultrix doesn't have strdup(), so make a quick clone: */ char *strdup(char *str) { int len; char *newstr; len = strlen(str); newstr = (char *) malloc((len+1)*sizeof(char)); if (!newstr) return (char *)NULL; strcpy(newstr,str); return newstr; } #endif extern void hugehelp(void); /*********************************************************************** * Start with some silly functions to make win32-systems survive ***********************************************************************/ #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) static void win32_cleanup(void) { WSACleanup(); } static CURLcode win32_init(void) { WORD wVersionRequested; WSADATA wsaData; int err; wVersionRequested = MAKEWORD(1, 1); err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) /* Tell the user that we couldn't find a useable */ /* winsock.dll. */ return CURLE_FAILED_INIT; /* Confirm that the Windows Sockets DLL supports 1.1.*/ /* Note that if the DLL supports versions greater */ /* than 1.1 in addition to 1.1, it will still return */ /* 1.1 in wVersion since that is the version we */ /* requested. */ if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) { /* Tell the user that we couldn't find a useable */ /* winsock.dll. */ WSACleanup(); return CURLE_FAILED_INIT; } return CURLE_OK; } /* The Windows Sockets DLL is acceptable. Proceed. */ #else static CURLcode win32_init(void) { return CURLE_OK; } #define win32_cleanup() #endif /* * This is the main global constructor for the app. Call this before * _any_ libcurl usage. If this fails, *NO* libcurl functions may be * used, or havoc may be the result. */ CURLcode main_init(void) { return win32_init(); } /* * This is the main global destructor for the app. Call this after * _all_ libcurl usage is done. */ void main_free(void) { win32_cleanup(); } int SetHTTPrequest(HttpReq req, HttpReq *store) { if((*store == HTTPREQ_UNSPEC) || (*store == req)) { *store = req; return 0; } fprintf(stderr, "You can only select one HTTP request!\n"); return 1; } static void helpf(char *fmt, ...) { va_list ap; if(fmt) { va_start(ap, fmt); fputs("curl: ", stderr); /* prefix it */ vfprintf(stderr, fmt, ap); va_end(ap); } fprintf(stderr, "curl: try 'curl --help' for more information\n"); } /* * A chain of these nodes contain URL to get and where to put the URL's * contents. */ struct getout { struct getout *next; char *url; char *outfile; int flags; }; #define GETOUT_OUTFILE (1<<0) /* set when outfile is deemed done */ #define GETOUT_URL (1<<1) /* set when URL is deemed done */ #define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */ static void help(void) { printf(CURL_ID "%s\n" "Usage: curl [options...] \n" "Options: (H) means HTTP/HTTPS only, (F) means FTP only\n" " -a/--append Append to target file when uploading (F)\n" " -A/--user-agent User-Agent to send to server (H)\n" " -b/--cookie Cookie string or file to read cookies from (H)\n" " -B/--use-ascii Use ASCII/text transfer\n", curl_version()); puts(" -C/--continue-at Specify absolute resume offset\n" " -d/--data HTTP POST data (H)\n" " --data-ascii HTTP POST ASCII data (H)\n" " --data-binary HTTP POST binary data (H)\n" " -D/--dump-header Write the headers to this file\n" " --egd-file EGD socket path for random data (SSL)\n" " -e/--referer Referer page (H)"); puts(" -E/--cert Specifies your certificate file and password (HTTPS)\n" " --cacert CA certifciate to verify peer against (HTTPS)\n" " --connect-timeout Maximum time allowed for connection\n" " -f/--fail Fail silently (no output at all) on errors (H)\n" " -F/--form Specify HTTP POST data (H)\n" " -g/--globoff Disable URL sequences and ranges using {} and []\n" " -h/--help This help text\n" " -H/--header Custom header to pass to server. (H)"); puts(" -i/--include Include the HTTP-header in the output (H)\n" " -I/--head Fetch document info only (HTTP HEAD/FTP SIZE)\n" " --interface Specify the interface to be used\n" " --krb4 Enable krb4 with specified security level (F)\n" " -K/--config Specify which config file to read\n" " -l/--list-only List only names of an FTP directory (F)"); puts(" -L/--location Follow Location: hints (H)\n" " -m/--max-time Maximum time allowed for the transfer\n" " -M/--manual Display huge help text\n" " -n/--netrc Read .netrc for user name and password\n" " -N/--no-buffer Disables the buffering of the output stream"); puts(" -o/--output Write output to instead of stdout\n" " -O/--remote-name Write output to a file named as the remote file\n" " -p/--proxytunnel Perform non-HTTP services through a HTTP proxy\n" " -P/--ftpport
Use PORT with address instead of PASV when ftping (F)\n" " -q When used as the first parameter disables .curlrc\n" " -Q/--quote Send QUOTE command to FTP before file transfer (F)"); puts(" -r/--range Retrieve a byte range from a HTTP/1.1 or FTP server\n" " -s/--silent Silent mode. Don't output anything\n" " -S/--show-error Show error. With -s, make curl show errors when they occur\n" " --stderr Where to redirect stderr. - means stdout.\n" " -t/--telnet-option Set telnet option\n" " -T/--upload-file Transfer/upload to remote site\n" " --url Another way to specify URL to work with"); puts(" -u/--user Specify user and password to use\n" " -U/--proxy-user Specify Proxy authentication\n" " -v/--verbose Makes the operation more talkative\n" " -V/--version Outputs version number then quits\n" " -w/--write-out [format] What to output after completion\n" " -x/--proxy Use proxy. (Default port is 1080)\n" " --random-file File to use for reading random data from (SSL)\n" " -X/--request Specific request command to use"); puts(" -y/--speed-time Time needed to trig speed-limit abort. Defaults to 30\n" " -Y/--speed-limit Stop transfer if below speed-limit for 'speed-time' secs\n" " -z/--time-cond