3 /*****************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
17 * License for the specific language governing rights and limitations
20 * The Original Code is Curl.
22 * The Initial Developer of the Original Code is Daniel Stenberg.
24 * Portions created by the Initial Developer are Copyright (C) 1998.
25 * All Rights Reserved.
27 * ------------------------------------------------------------
29 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
40 * ------------------------------------------------------------
41 ****************************************************************************/
43 /* The include stuff here is mainly for time_t! */
48 # include <sys/types.h>
49 # if TIME_WITH_SYS_TIME
50 # include <sys/time.h>
54 # include <sys/time.h>
59 #endif /* defined (vms) */
68 #include <curl/types.h>
72 struct HttpHeader *next; /* next entry in the list */
73 char *header; /* pointer to allocated line without newline */
77 struct HttpPost *next; /* next entry in the list */
78 char *name; /* pointer to allocated name */
79 char *contents; /* pointer to allocated data contents */
80 char *contenttype; /* Content-Type */
81 struct HttpPost *more; /* if one field name has more than one file, this
82 link should link to following files */
83 long flags; /* as defined below */
84 #define HTTPPOST_FILENAME (1<<0) /* specified content is a file name */
87 /* All possible error codes from this version of urlget(). Future versions
88 may return other values, stay prepared. */
92 CURLE_UNSUPPORTED_PROTOCOL,
95 CURLE_URL_MALFORMAT_USER,
96 CURLE_COULDNT_RESOLVE_PROXY,
97 CURLE_COULDNT_RESOLVE_HOST,
98 CURLE_COULDNT_CONNECT,
99 CURLE_FTP_WEIRD_SERVER_REPLY,
100 CURLE_FTP_ACCESS_DENIED,
101 CURLE_FTP_USER_PASSWORD_INCORRECT,
102 CURLE_FTP_WEIRD_PASS_REPLY,
103 CURLE_FTP_WEIRD_USER_REPLY,
104 CURLE_FTP_WEIRD_PASV_REPLY,
105 CURLE_FTP_WEIRD_227_FORMAT,
106 CURLE_FTP_CANT_GET_HOST,
107 CURLE_FTP_CANT_RECONNECT,
108 CURLE_FTP_COULDNT_SET_BINARY,
110 CURLE_FTP_COULDNT_RETR_FILE,
111 CURLE_FTP_WRITE_ERROR,
112 CURLE_FTP_QUOTE_ERROR,
113 CURLE_HTTP_NOT_FOUND,
116 CURLE_MALFORMAT_USER, /* the user name is illegally specified */
117 CURLE_FTP_COULDNT_STOR_FILE, /* failed FTP upload */
118 CURLE_READ_ERROR, /* could open/read from file */
121 CURLE_OPERATION_TIMEOUTED, /* the timeout time was reached */
122 CURLE_FTP_COULDNT_SET_ASCII, /* TYPE A failed */
124 CURLE_FTP_PORT_FAILED, /* FTP PORT operation failed */
126 CURLE_FTP_COULDNT_USE_REST, /* the REST command failed */
127 CURLE_FTP_COULDNT_GET_SIZE, /* the SIZE command failed */
129 CURLE_HTTP_RANGE_ERROR, /* The RANGE "command" didn't seem to work */
131 CURLE_HTTP_POST_ERROR,
133 CURLE_SSL_CONNECT_ERROR, /* something was wrong when connecting with SSL */
135 CURLE_FTP_BAD_DOWNLOAD_RESUME, /* couldn't resume download */
137 CURLE_FILE_COULDNT_READ_FILE,
139 CURLE_LDAP_CANNOT_BIND,
140 CURLE_LDAP_SEARCH_FAILED,
141 CURLE_LIBRARY_NOT_FOUND,
142 CURLE_FUNCTION_NOT_FOUND,
144 CURLE_ABORTED_BY_CALLBACK,
146 CURLE_BAD_FUNCTION_ARGUMENT,
147 CURLE_BAD_CALLING_ORDER,
152 /* This is just to make older programs not break: */
153 #define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE
155 #define URLGET_ERROR_SIZE 256
157 /* maximum URL length we deal with */
158 #define URL_MAX_LENGTH 4096
159 #define URL_MAX_LENGTH_TXT "4095"
161 /* name is uppercase CURLOPT_<name>,
162 type is one of the defined CURLOPTTYPE_<type>
163 number is unique identifier */
164 #define T(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number
166 /* long may be 32 or 64 bits, but we should never depend on anything else
168 #define CURLOPTTYPE_LONG 0
169 #define CURLOPTTYPE_OBJECTPOINT 10000
170 #define CURLOPTTYPE_FUNCTIONPOINT 20000
173 T(NOTHING, LONG, 0), /********* the first one is unused ************/
175 /* This is the FILE * the regular output should be written to. */
176 T(FILE, OBJECTPOINT, 1),
178 /* The full URL to get/put */
179 T(URL, OBJECTPOINT, 2),
181 /* Port number to connect to, if other than default. Specify the CONF_PORT
182 flag in the CURLOPT_FLAGS to activate this */
185 /* Name of proxy to use. Specify the CONF_PROXY flag in the CURLOPT_FLAGS to
187 T(PROXY, OBJECTPOINT, 4),
189 /* Name and password to use when fetching. Specify the CONF_USERPWD flag in
190 the CURLOPT_FLAGS to activate this */
191 T(USERPWD, OBJECTPOINT, 5),
193 /* Name and password to use with Proxy. Specify the CONF_PROXYUSERPWD
194 flag in the CURLOPT_FLAGS to activate this */
195 T(PROXYUSERPWD, OBJECTPOINT, 6),
197 /* Range to get, specified as an ASCII string. Specify the CONF_RANGE flag
198 in the CURLOPT_FLAGS to activate this */
199 T(RANGE, OBJECTPOINT, 7),
202 /* Configuration flags */
205 /* Specified file stream to upload from (use as input): */
206 T(INFILE, OBJECTPOINT, 9),
208 /* Buffer to receive error messages in, must be at least URLGET_ERROR_SIZE
209 bytes big. If this is not used, error messages go to stderr instead: */
210 T(ERRORBUFFER, OBJECTPOINT, 10),
212 /* Function that will be called to store the output (instead of fwrite). The
213 parameters will use fwrite() syntax, make sure to follow them. */
214 T(WRITEFUNCTION, FUNCTIONPOINT, 11),
216 /* Function that will be called to read the input (instead of fread). The
217 parameters will use fread() syntax, make sure to follow them. */
218 T(READFUNCTION, FUNCTIONPOINT, 12),
220 /* Time-out the read operation after this amount of seconds */
221 T(TIMEOUT, LONG, 13),
223 /* If the CURLOPT_INFILE is used, this can be used to inform urlget about how
224 large the file being sent really is. That allows better error checking
225 and better verifies that the upload was succcessful. -1 means unknown
227 T(INFILESIZE, LONG, 14),
229 /* POST input fields. */
230 T(POSTFIELDS, OBJECTPOINT, 15),
232 /* Set the referer page (needed by some CGIs) */
233 T(REFERER, OBJECTPOINT, 16),
235 /* Set the FTP PORT string (interface name, named or numerical IP address)
236 Use i.e '-' to use default address. */
237 T(FTPPORT, OBJECTPOINT, 17),
239 /* Set the User-Agent string (examined by some CGIs) */
240 T(USERAGENT, OBJECTPOINT, 18),
242 /* If the download receives less than "low speed limit" bytes/second
243 * during "low speed time" seconds, the operations is aborted.
244 * You could i.e if you have a pretty high speed connection, abort if
245 * it is less than 2000 bytes/sec during 20 seconds.
248 /* Set the "low speed limit" */
249 T(LOW_SPEED_LIMIT, LONG , 19),
251 /* Set the "low speed time" */
252 T(LOW_SPEED_TIME, LONG, 20),
254 /* Set the continuation offset */
255 T(RESUME_FROM, LONG, 21),
257 /* Set cookie in request: */
258 T(COOKIE, OBJECTPOINT, 22),
260 /* This points to a linked list of headers, struct HttpHeader kind */
261 T(HTTPHEADER, OBJECTPOINT, 23),
263 /* This points to a linked list of post entries, struct HttpPost */
264 T(HTTPPOST, OBJECTPOINT, 24),
266 /* name of the file keeping your private SSL-certificate */
267 T(SSLCERT, OBJECTPOINT, 25),
269 /* password for the SSL-certificate */
270 T(SSLCERTPASSWD, OBJECTPOINT, 26),
272 /* send TYPE parameter? */
275 /* send linked-list of QUOTE commands */
276 T(QUOTE, OBJECTPOINT, 28),
278 /* send FILE * to store headers to */
279 T(WRITEHEADER, OBJECTPOINT, 29),
282 /* send linked list of MoreDoc structs */
283 T(MOREDOCS, OBJECTPOINT, 30),
286 /* point to a file to read the initial cookies from, also enables
287 "cookie awareness" */
288 T(COOKIEFILE, OBJECTPOINT, 31),
290 /* What version to specifly try to use.
291 3 = SSLv3, 2 = SSLv2, all else makes it try v3 first then v2 */
292 T(SSLVERSION, LONG, 32),
294 /* What kind of HTTP time condition to use, see defines */
295 T(TIMECONDITION, LONG, 33),
297 /* Time to use with the above condition. Specified in number of seconds
299 T(TIMEVALUE, LONG, 34),
301 /* HTTP request, for odd commands like DELETE, TRACE and others */
302 /* OBSOLETE DEFINE, left for tradition only */
303 T(HTTPREQUEST, OBJECTPOINT, 35),
305 /* Custom request, for customizing the get command like
306 HTTP: DELETE, TRACE and others
307 FTP: to use a different list command
309 T(CUSTOMREQUEST, OBJECTPOINT, 36),
311 /* HTTP request, for odd commands like DELETE, TRACE and others */
312 T(STDERR, OBJECTPOINT, 37),
314 /* Progress mode sets alternative progress mode displays, the only
315 one defined today is 1 which makes the #-style progress bar. */
316 T(PROGRESSMODE, LONG, 38),
318 /* send linked-list of post-transfer QUOTE commands */
319 T(POSTQUOTE, OBJECTPOINT, 39),
321 /* Pass a pointer to string of the output using full variable-replacement
322 as described elsewhere. */
323 T(WRITEINFO, OBJECTPOINT, 40),
325 /* Previous FLAG bits */
326 T(VERBOSE, LONG, 41), /* talk a lot */
327 T(HEADER, LONG, 42), /* throw the header out too */
328 T(NOPROGRESS, LONG, 43), /* shut off the progress meter */
329 T(NOBODY, LONG, 44), /* use HEAD to get http document */
330 T(FAILONERROR, LONG, 45), /* no output on http error codes >= 300 */
331 T(UPLOAD, LONG, 46), /* this is an upload */
332 T(POST, LONG, 47), /* HTTP POST method */
333 T(FTPLISTONLY, LONG, 48), /* Use NLST when listing ftp dir */
335 T(FTPAPPEND, LONG, 50), /* Append instead of overwrite on upload! */
336 T(NETRC, LONG, 51), /* read user+password from .netrc */
337 T(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */
338 T(FTPASCII, LONG, 53), /* use TYPE A for transfer */
339 T(PUT, LONG, 54), /* PUT the input file */
340 T(MUTE, LONG, 55), /* force NOPROGRESS */
342 CURLOPT_LASTENTRY /* the last unusued */
345 #define CURL_PROGRESS_STATS 0 /* default progress display */
346 #define CURL_PROGRESS_BAR 1
352 TIMECOND_IFUNMODSINCE,
359 #include <support/SupportDefs.h>
361 #ifndef __cplusplus /* (rabe) */
367 /* At last, I stand here in front of you today and can officially proclaim
368 this function prototype as history... 17th of May, 2000 */
369 UrgError curl_urlget(UrgTag, ...);
372 /* external form function */
373 int curl_FormParse(char *string,
374 struct HttpPost **httppost,
375 struct HttpPost **last_post);
377 /* Unix and Win32 getenv function call */
378 char *curl_GetEnv(char *variable);
380 /* returns ascii string of the libcurl version */
381 char *curl_version(void);
383 /* This is the version number */
384 #define LIBCURL_VERSION "7.0beta"
385 #define LIBCURL_VERSION_NUM 0x070000
387 /* linked-list structure for the CURLOPT_QUOTE option */
390 struct curl_slist *next;
393 struct curl_slist *curl_slist_append(struct curl_slist *list, char *data);
394 void curl_slist_free_all(struct curl_slist *list);
401 * Inits libcurl globally. This must be used before any libcurl calls can
402 * be used. This may install global plug-ins or whatever. (This does not
403 * do winsock inits in Windows.)
410 CURLcode curl_init(void);
417 * Frees libcurl globally. This must be used after all libcurl calls have
418 * been used. This may remove global plug-ins or whatever. (This does not
419 * do winsock cleanups in Windows.)
426 void curl_free(void);
433 * Opens a general curl session. It does not try to connect or do anything
434 * on the network because of this call. The specified URL is only required
435 * to enable curl to figure out what protocol to "activate".
437 * A session should be looked upon as a series of requests to a single host. A
438 * session interacts with one host only, using one single protocol.
440 * The URL is not required. If set to "" or NULL, it can still be set later
441 * using the curl_setopt() function. If the curl_connect() function is called
442 * without the URL being known, it will return error.
448 * result = curl_open(&curl, "http://curl.haxx.nu/libcurl/");
449 * if(result != CURL_OK) {
453 CURLcode curl_open(CURL **curl, char *url);
460 * Sets a particular option to the specified value.
465 * curl_setopt(curl, CURL_HTTP_FOLLOW_LOCATION, TRUE);
467 CURLcode curl_setopt(CURL *handle, CURLoption option, ...);
474 * Closes a session previously opened with curl_open()
481 * result = curl_close(curl);
483 CURLcode curl_close(CURL *curl); /* the opposite of curl_open() */
485 CURLcode curl_read(CURLconnect *c_conn, char *buf, size_t buffersize,
487 CURLcode curl_write(CURLconnect *c_conn, char *buf, size_t amount,
491 * NAME curl_connect()
495 * Connects to the peer server and performs the initial setup. This function
496 * writes a connect handle to its second argument that is a unique handle for
497 * this connect. This allows multiple connects from the same handle returned
504 * CURLconnect connect;
505 * result = curl_connect(curl, &connect);
508 CURLcode curl_connect(CURL *curl, CURLconnect **in_connect);
515 * (Note: May 3rd 2000: this function does not currently allow you to
516 * specify a document, it will use the one set previously)
518 * This function asks for the particular document, file or resource that
519 * resides on the server we have connected to. You may specify a full URL,
520 * just an absolute path or even a relative path. That means, if you're just
521 * getting one file from the remote site, you can use the same URL as input
522 * for both curl_open() as well as for this function.
524 * In the even there is a host name, port number, user name or password parts
525 * in the URL, you can use the 'flags' argument to ignore them completely, or
526 * at your choice, make the function fail if you're trying to get a URL from
527 * different host than you connected to with curl_connect().
529 * You can only get one document at a time using the same connection. When one
530 * document has been received you can although request again.
532 * When the transfer is done, curl_done() MUST be called.
538 * CURLconnect *connect;
539 * result = curl_do(connect, url, CURL_DO_NONE); */
540 CURLcode curl_do(CURLconnect *in_conn);
547 * When the transfer following a curl_do() call is done, this function should
554 * CURLconnect *connect;
555 * result = curl_done(connect); */
556 CURLcode curl_done(CURLconnect *connect);
559 * NAME curl_disconnect()
563 * Disconnects from the peer server and performs connection cleanup.
568 * CURLconnect *connect;
569 * result = curl_disconnect(connect); */
570 CURLcode curl_disconnect(CURLconnect *connect);
573 * NAME curl_getdate()
577 * Returns the time, in seconds since 1 Jan 1970 of the time string given in
578 * the first argument. The time argument in the second parameter is for cases
579 * where the specified time is relative now, like 'two weeks' or 'tomorrow'
582 time_t curl_getdate(const char *p, const time_t *now);
584 #endif /* __CURL_CURL_H */