/***************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is Curl. * * The Initial Developer of the Original Code is Daniel Stenberg. * * Portions created by the Initial Developer are Copyright (C) 1998. * All Rights Reserved. * * ------------------------------------------------------------ * Main author: * - Daniel Stenberg * * http://curl.haxx.se * * $Source$ * $Revision$ * $Date$ * $Author$ * $State$ * $Locker$ * * ------------------------------------------------------------ ****************************************************************************/ #include #include #include #include #include #include #include #include /* new for v7 */ #include /* new for v7 */ #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */ #include #include "urlglob.h" #define CURLseparator "--_curl_--" #define MIMEseparator "_curl_" /* This define make use of the "Curlseparator" as opposed to the MIMEseparator. We might add support for the latter one in the future, and that's why this is left in the source. */ #define CURL_SEPARATORS /* This is now designed to have its own local setup.h */ #include "setup.h" #ifdef WIN32 #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 DEBUG_CONFIG #ifndef __cplusplus /* (rabe) */ typedef char bool; #endif /* (rabe) */ 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_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_POST (1<<15) /* HTTP POST method */ #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_PUT (1<<27) /* PUT the input file */ #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"); } 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" " -c/--continue Resume a previous transfer where we left it\n" " -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" " -e/--referer Referer page (H)\n" " -E/--cert Specifies your certificate file and password (HTTPS)\n" " -f/--fail Fail silently (no output at all) on errors (H)\n" " -F/--form Specify HTTP POST data (H)\n" " -h/--help This help text\n" " -H/--header Custom header to pass to server. (H)\n" " -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)\n" " -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\n" " -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)\n" " -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" " -t/--upload Transfer/upload stdin to remote site\n" " -T/--upload-file Transfer/upload to remote site\n" " -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" " -X/--request Specific request command to use\n" " -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