32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
42 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
46 #ifdef HAVE_SYS_SOCKET_H
47 #include <sys/socket.h>
49 #ifdef HAVE_NETINET_IN_H
50 #include <netinet/in.h>
57 #ifdef HAVE_ARPA_INET_H
58 #include <arpa/inet.h>
63 #ifdef HAVE_SYS_IOCTL_H
64 #include <sys/ioctl.h>
68 #ifdef HAVE_SYS_PARAM_H
69 #include <sys/param.h>
72 #ifdef HAVE_SYS_SELECT_H
73 #include <sys/select.h>
77 #error "We can't compile without select() support!"
80 #error "We can't compile without socket() support!"
106 #define _MPRINTF_REPLACE
114 #define CURL_TIMEOUT_EXPECT_100 1000
124 static struct timeval notimeout={0,0};
133 int buffersize = bytes;
138 buffersize -= (8 + 2 + 2);
148 int hexlen =
snprintf(hexbuffer,
sizeof(hexbuffer),
160 if((nread - hexlen) == 0) {
215 FD_ZERO(&extrareadfd);
216 FD_SET(conn->
sockfd, &extrareadfd);
217 readfdp = &extrareadfd;
224 FD_ZERO(&extrawritefd);
226 writefdp = &extrawritefd;
238 (!readfdp || FD_ISSET(conn->
sockfd, readfdp))) {
240 bool readdone =
TRUE;
276 else if (0 >= nread) {
291 bool stop_reading =
FALSE;
317 failf (data,
"Failed to alloc memory for big header!");
342 nread -= rest_length;
354 if (k->
hbuflen + full_length >=
362 failf (data,
"Failed to alloc memory for big header!");
372 k->
hbufp += full_length;
401 if ((
'\n' == *k->
p) || (
'\r' == *k->
p)) {
447 if (data->
set.http_include_header)
472 failf (data,
"HTTP server doesn't seem to support "
473 "byte ranges. Cannot resume.");
510 if(-1 != conn->
size) {
543 int httpversion_major;
544 int nc=sscanf (k->
p,
" HTTP/%d.%d %3d",
555 nc=sscanf (k->
p,
" HTTP %3d", &k->
httpcode);
562 if (checkhttpprefix(data, k->
p)) {
581 failf (data,
"The requested URL returned error: %d",
631 failf(data,
"Maximum file size exceeded");
634 conn->
size = contentlength;
644 *start && isspace((
int)*start);
647 end = strchr(start,
'\r');
649 end = strchr(start,
'\n');
653 for(; isspace((
int)*end) && (end >
start); end--);
673 "Proxy-Connection:",
"keep-alive")) {
681 infof(data,
"HTTP/1.0 proxy connection set to keep alive!\n");
692 infof(data,
"HTTP/1.0 connection set to keep alive!\n");
704 "Transfer-Encoding:",
"chunked")) {
731 *start && isspace((
int)*start);
754 char *ptr = strstr(k->
p,
"bytes");
782 time_t secs=time(
NULL);
808 while(*start && isspace((
int)*start ))
817 while((ptr>=start) && isspace((
int)*ptr))
832 infof(data,
"We ignore this location header as instructed\n");
842 if (data->
set.http_include_header)
860 while (!stop_reading && *k->
str);
875 if (k->
str && !k->
header && (nread > 0)) {
896 infof(data,
"Ignoring the response-body\n");
909 "The requested document is not new enough\n");
917 "The requested document is not old enough\n");
954 failf(data,
"Failed writing data");
957 failf(data,
"Received problem %d in the chunky parser", res);
1027 failf (data,
"Unrecognized content encoding type. "
1028 "libcurl understands `identity', `deflate' and `gzip' "
1029 "content encodings.");
1052 (!writefdp || FD_ISSET(conn->
writesockfd, writefdp)) ) {
1057 bool writedone=
TRUE;
1095 nread = fillbuffer(conn,
BUFSIZE);
1118 failf (data,
"Failed to alloc scratch buffer!");
1121 for(i = 0, si = 0; i < nread; i++, si++) {
1189 }
while(!writedone);
1255 " bytes remaining to read",
1260 failf(data,
"transfer closed with at least %d bytes remaining",
1354 fd_set *read_fd_set,
1355 fd_set *write_fd_set,
1361 FD_SET(conn->
sockfd, read_fd_set);
1376 *exc_fd_set = *exc_fd_set;
1422 interval.tv_sec = 1;
1423 interval.tv_usec = 0;
1499 #if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
1504 data->
state.prev_signal = signal(SIGPIPE, SIG_IGN);
1515 #if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
1518 signal(SIGPIPE, data->
state.prev_signal);
1526 static int strlen_url(
char *url)
1532 for(ptr=url; *ptr; ptr++) {
1550 static void strcpy_url(
char *output,
char *url)
1555 char *optr = output;
1615 if(2 != sscanf(newurl,
"%15[^?&/:]://%c", prot, &letter)) {
1627 char *useurl = newurl;
1638 protsep=strstr(url_clone,
"//");
1644 if(
'/' != newurl[0]) {
1649 pathsep = strrchr(protsep,
'?');
1655 pathsep = strrchr(protsep,
'/');
1661 pathsep = strchr(protsep,
'/');
1663 protsep = pathsep+1;
1670 if((useurl[0] ==
'.') && (useurl[1] ==
'/'))
1673 while((useurl[0] ==
'.') &&
1674 (useurl[1] ==
'.') &&
1675 (useurl[2] ==
'/')) {
1683 pathsep = strrchr(protsep,
'/');
1696 pathsep = strchr(protsep,
'/');
1704 pathsep = strchr(protsep,
'?');
1715 newlen = strlen_url(useurl);
1717 urllen = strlen(url_clone);
1719 newest=(
char *)malloc( urllen + 1 +
1726 memcpy(newest, url_clone, urllen);
1729 if((
'/' == useurl[0]) || (protsep && !*protsep))
1732 newest[urllen++]=
'/';
1735 strcpy_url(&newest[urllen], useurl);
1745 if(strchr(newurl,
' ')) {
1748 newlen = strlen_url(newurl);
1750 newest = malloc(newlen+1);
1752 strcpy_url(newest, newurl);
1769 infof(data,
"Issue another request to this URL: '%s'\n", data->
change.
url);
1808 "Violate RFC 2616/10.3.2 and switch from POST to GET\n");
1835 infof(data,
"Disables POST, goes with %s\n",
1881 int urlchanged =
FALSE;
1903 if ((
CURLE_OK == res) && urlchanged) {
1912 }
while (urlchanged && res ==
CURLE_OK) ;
1918 res = Transfer(conn);
1929 infof(data,
"Connection reset, retrying a fresh connect\n");
2014 curlassert((sockindex <= 1) && (sockindex >= -1));
2017 conn->
sockfd = sockindex==-1?
CURLcode Curl_pretransfer(struct SessionHandle *data)
CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, ssize_t length, ssize_t *wrote)
CURLcode Curl_unencode_gzip_write(struct SessionHandle *data, struct Curl_transfer_keeper *k, ssize_t nread)
void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size)
struct CookieInfo * cookies
enum UrlState::@12 used_interface
CURLcode Curl_initinfo(struct SessionHandle *data)
struct Curl_transfer_keeper keep
union connectdata::@11 proto
CURLcode Curl_unencode_deflate_write(struct SessionHandle *data, struct Curl_transfer_keeper *k, ssize_t nread)
void Curl_speedinit(struct SessionHandle *data)
void Curl_pgrsTime(struct SessionHandle *data, timerid timer)
CURLcode Curl_posttransfer(struct SessionHandle *data)
struct ssl_config_data ssl
void Curl_httpchunk_init(struct connectdata *conn)
struct DynamicStatic change
struct curl_slist * http200aliases
CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr, size_t len)
time_t curl_getdate(const char *p, const time_t *now)
CURLcode Curl_connect(struct SessionHandle *data, struct connectdata **in_connect, bool *asyncp)
CURLcode Curl_do(struct connectdata **connp)
int Curl_read(struct connectdata *conn, curl_socket_t sockfd, char *buf, size_t buffersize, ssize_t *n)
void Curl_single_fdset(struct connectdata *conn, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd)
enum Curl_transfer_keeper::@10 badheader
CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, void *mem, size_t len, ssize_t *written)
bool write_after_100_header
struct Cookie * Curl_cookie_add(struct SessionHandle *data, struct CookieInfo *c, bool httpheader, char *lineptr, char *domain, char *path)
int Curl_pgrsUpdate(struct connectdata *conn)
void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size)
CURLcode Curl_http_auth(struct connectdata *conn, int httpcode, char *header)
char uploadbuffer[BUFSIZE+1]
void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size)
void Curl_pgrsResetTimes(struct SessionHandle *data)
CURLcode Curl_SSL_InitSessions(struct SessionHandle *, long)
GLsizei GLsizei GLenum GLenum const GLvoid * data
CURLcode Curl_follow(struct SessionHandle *data, char *newurl)
CURLcode Curl_async_resolved(struct connectdata *conn)
#define CLIENTWRITE_HEADER
CURLcode Curl_Transfer(struct connectdata *c_conn, int sockindex, curl_off_t size, bool getheader, curl_off_t *bytecountp, int writesockindex, curl_off_t *writecountp)
void Curl_http_auth_act(struct connectdata *conn)
long Curl_tvdiff(struct timeval newer, struct timeval older)
CURLcode Curl_speedcheck(struct SessionHandle *data, struct timeval now)
struct SessionHandle * data
#define checkprefix(a, b)
struct curl_slist * cookielist
curl_socket_t writesockfd
int Curl_debug(struct SessionHandle *data, curl_infotype type, char *ptr, size_t size)
bool wait100_after_headers
curl_off_t * writebytecountp
CURLcode Curl_readwrite(struct connectdata *conn, bool *done)
CURLcode Curl_wait_for_resolv(struct connectdata *conn, struct Curl_dns_entry **entry)
#define CURL_TIMEOUT_EXPECT_100
void Curl_safefree(void *ptr)
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
struct timeval Curl_tvnow(void)
CURLSHcode Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access accesstype)
bool Curl_compareheader(char *headerline, const char *header, const char *content)
struct Curl_chunker chunk
void curl_slist_free_all(struct curl_slist *)
CURLcode Curl_perform(struct SessionHandle *data)
CURLcode Curl_readwrite_init(struct connectdata *conn)
void Curl_pgrsStartNow(struct SessionHandle *data)
bool http_follow_location
struct CookieInfo * Curl_cookie_init(struct SessionHandle *data, char *file, struct CookieInfo *inc, bool newsession)
struct connectdata::dynamically_allocated_data allocptr
curl_TimeCond timecondition
CURLSHcode Curl_share_unlock(struct SessionHandle *data, curl_lock_data type)
CURLcode Curl_done(struct connectdata *conn)