2009-12-13 05:54:01 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2013-02-15 18:03:42 +08:00
|
|
|
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2009-12-13 05:54:01 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* 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 COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* 'pingpong' is for generic back-and-forth support functions used by FTP,
|
|
|
|
* IMAP, POP3, SMTP and whatever more that likes them.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "select.h"
|
|
|
|
#include "progress.h"
|
|
|
|
#include "speedcheck.h"
|
|
|
|
#include "pingpong.h"
|
|
|
|
#include "multiif.h"
|
|
|
|
#include "non-ascii.h"
|
2013-12-18 06:32:47 +08:00
|
|
|
#include "vtls/vtls.h"
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
#define _MPRINTF_REPLACE /* use our functions only */
|
|
|
|
#include <curl/mprintf.h>
|
|
|
|
|
|
|
|
#include "curl_memory.h"
|
|
|
|
/* The last #include file should be: */
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h"
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
#ifdef USE_PINGPONG
|
|
|
|
|
|
|
|
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
|
|
|
triggered */
|
|
|
|
long Curl_pp_state_timeout(struct pingpong *pp)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
struct SessionHandle *data=conn->data;
|
2010-03-02 21:05:02 +08:00
|
|
|
long timeout_ms; /* in milliseconds */
|
2010-03-02 21:26:23 +08:00
|
|
|
long timeout2_ms; /* in milliseconds */
|
|
|
|
long response_time= (data->set.server_response_timeout)?
|
|
|
|
data->set.server_response_timeout: pp->response_time;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2010-03-02 21:26:23 +08:00
|
|
|
/* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine
|
|
|
|
remaining time, or use pp->response because SERVER_RESPONSE_TIMEOUT is
|
|
|
|
supposed to govern the response for any given server response, not for
|
|
|
|
the time from connect to the given server response. */
|
|
|
|
|
|
|
|
/* Without a requested timeout, we only wait 'response_time' seconds for the
|
|
|
|
full response to arrive before we bail out */
|
|
|
|
timeout_ms = response_time -
|
|
|
|
Curl_tvdiff(Curl_tvnow(), pp->response); /* spent time */
|
|
|
|
|
|
|
|
if(data->set.timeout) {
|
2009-12-13 05:54:01 +08:00
|
|
|
/* if timeout is requested, find out how much remaining time we have */
|
2010-03-02 21:26:23 +08:00
|
|
|
timeout2_ms = data->set.timeout - /* timeout time */
|
2009-12-13 05:54:01 +08:00
|
|
|
Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
|
2010-03-02 21:26:23 +08:00
|
|
|
|
|
|
|
/* pick the lowest number */
|
|
|
|
timeout_ms = CURLMIN(timeout_ms, timeout2_ms);
|
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
return timeout_ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-02-15 18:03:42 +08:00
|
|
|
* Curl_pp_statemach()
|
2009-12-13 05:54:01 +08:00
|
|
|
*/
|
2013-02-18 07:14:35 +08:00
|
|
|
CURLcode Curl_pp_statemach(struct pingpong *pp, bool block)
|
2009-12-13 05:54:01 +08:00
|
|
|
{
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
|
|
|
int rc;
|
|
|
|
long interval_ms;
|
|
|
|
long timeout_ms = Curl_pp_state_timeout(pp);
|
|
|
|
struct SessionHandle *data=conn->data;
|
2013-02-15 18:03:42 +08:00
|
|
|
CURLcode result = CURLE_OK;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
if(timeout_ms <=0 ) {
|
|
|
|
failf(data, "server response timeout");
|
|
|
|
return CURLE_OPERATION_TIMEDOUT; /* already too little time */
|
|
|
|
}
|
|
|
|
|
2013-02-18 07:14:35 +08:00
|
|
|
if(block) {
|
2013-02-15 18:03:42 +08:00
|
|
|
interval_ms = 1000; /* use 1 second timeout intervals */
|
|
|
|
if(timeout_ms < interval_ms)
|
|
|
|
interval_ms = timeout_ms;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
interval_ms = 0; /* immediate */
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-02-15 23:42:49 +08:00
|
|
|
if(Curl_pp_moredata(pp))
|
|
|
|
/* We are receiving and there is data in the cache so just read it */
|
|
|
|
rc = 1;
|
2013-09-09 07:05:14 +08:00
|
|
|
else if(!pp->sendleft && Curl_ssl_data_pending(conn, FIRSTSOCKET))
|
|
|
|
/* We are receiving and there is data ready in the SSL library */
|
|
|
|
rc = 1;
|
2013-02-15 23:42:49 +08:00
|
|
|
else
|
|
|
|
rc = Curl_socket_ready(pp->sendleft?CURL_SOCKET_BAD:sock, /* reading */
|
|
|
|
pp->sendleft?sock:CURL_SOCKET_BAD, /* writing */
|
|
|
|
interval_ms);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-02-18 07:14:35 +08:00
|
|
|
if(block) {
|
2013-02-15 18:03:42 +08:00
|
|
|
/* if we didn't wait, we don't have to spend time on this now */
|
|
|
|
if(Curl_pgrsUpdate(conn))
|
|
|
|
result = CURLE_ABORTED_BY_CALLBACK;
|
|
|
|
else
|
|
|
|
result = Curl_speedcheck(data, Curl_tvnow());
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-02-15 18:03:42 +08:00
|
|
|
if(rc == -1) {
|
2009-12-13 05:54:01 +08:00
|
|
|
failf(data, "select/poll error");
|
|
|
|
result = CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else if(rc)
|
|
|
|
result = pp->statemach_act(conn);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize stuff to prepare for reading a fresh new response */
|
|
|
|
void Curl_pp_init(struct pingpong *pp)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
pp->nread_resp = 0;
|
|
|
|
pp->linestart_resp = conn->data->state.buffer;
|
|
|
|
pp->pending_resp = TRUE;
|
|
|
|
pp->response = Curl_tvnow(); /* start response time-out now! */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
2010-12-17 11:57:39 +08:00
|
|
|
* Curl_pp_vsendf()
|
2009-12-13 05:54:01 +08:00
|
|
|
*
|
|
|
|
* Send the formated string as a command to a pingpong server. Note that
|
|
|
|
* the string should not have any CRLF appended, as this function will
|
|
|
|
* append the necessary things itself.
|
|
|
|
*
|
|
|
|
* made to never block
|
|
|
|
*/
|
|
|
|
CURLcode Curl_pp_vsendf(struct pingpong *pp,
|
|
|
|
const char *fmt,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
ssize_t bytes_written;
|
|
|
|
size_t write_len;
|
2011-08-29 20:27:06 +08:00
|
|
|
char *fmt_crlf;
|
|
|
|
char *s;
|
|
|
|
CURLcode error;
|
2009-12-13 05:54:01 +08:00
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2009-12-13 05:54:01 +08:00
|
|
|
enum protection_level data_sec = conn->data_prot;
|
|
|
|
#endif
|
|
|
|
|
2011-09-06 05:45:04 +08:00
|
|
|
DEBUGASSERT(pp->sendleft == 0);
|
|
|
|
DEBUGASSERT(pp->sendsize == 0);
|
|
|
|
DEBUGASSERT(pp->sendthis == NULL);
|
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
fmt_crlf = aprintf("%s\r\n", fmt); /* append a trailing CRLF */
|
|
|
|
if(!fmt_crlf)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
s = vaprintf(fmt_crlf, args); /* trailing CRLF appended */
|
|
|
|
free(fmt_crlf);
|
|
|
|
if(!s)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
bytes_written = 0;
|
2009-12-13 05:54:01 +08:00
|
|
|
write_len = strlen(s);
|
|
|
|
|
|
|
|
Curl_pp_init(pp);
|
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
error = Curl_convert_to_network(data, s, write_len);
|
2009-12-13 05:54:01 +08:00
|
|
|
/* Curl_convert_to_network calls failf if unsuccessful */
|
2011-08-29 20:27:06 +08:00
|
|
|
if(error) {
|
|
|
|
free(s);
|
|
|
|
return error;
|
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2010-11-14 06:42:34 +08:00
|
|
|
conn->data_prot = PROT_CMD;
|
2009-12-13 05:54:01 +08:00
|
|
|
#endif
|
2011-08-29 20:27:06 +08:00
|
|
|
error = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,
|
|
|
|
&bytes_written);
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2010-11-14 06:42:34 +08:00
|
|
|
DEBUGASSERT(data_sec > PROT_NONE && data_sec < PROT_LAST);
|
2009-12-13 05:54:01 +08:00
|
|
|
conn->data_prot = data_sec;
|
|
|
|
#endif
|
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
if(error) {
|
|
|
|
free(s);
|
|
|
|
return error;
|
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
if(conn->data->set.verbose)
|
|
|
|
Curl_debug(conn->data, CURLINFO_HEADER_OUT,
|
2011-08-29 20:27:06 +08:00
|
|
|
s, (size_t)bytes_written, conn);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
if(bytes_written != (ssize_t)write_len) {
|
2011-09-06 05:45:04 +08:00
|
|
|
/* the whole chunk was not sent, keep it around and adjust sizes */
|
2011-08-29 20:27:06 +08:00
|
|
|
pp->sendthis = s;
|
2011-09-06 05:45:04 +08:00
|
|
|
pp->sendsize = write_len;
|
|
|
|
pp->sendleft = write_len - bytes_written;
|
2009-12-13 05:54:01 +08:00
|
|
|
}
|
2011-08-29 20:27:06 +08:00
|
|
|
else {
|
|
|
|
free(s);
|
|
|
|
pp->sendthis = NULL;
|
|
|
|
pp->sendleft = pp->sendsize = 0;
|
2009-12-13 05:54:01 +08:00
|
|
|
pp->response = Curl_tvnow();
|
2011-08-29 20:27:06 +08:00
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
2011-08-29 20:27:06 +08:00
|
|
|
return CURLE_OK;
|
2009-12-13 05:54:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Curl_pp_sendf()
|
|
|
|
*
|
|
|
|
* Send the formated string as a command to a pingpong server. Note that
|
|
|
|
* the string should not have any CRLF appended, as this function will
|
|
|
|
* append the necessary things itself.
|
|
|
|
*
|
|
|
|
* made to never block
|
|
|
|
*/
|
|
|
|
CURLcode Curl_pp_sendf(struct pingpong *pp,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
CURLcode res;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
res = Curl_pp_vsendf(pp, fmt, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Curl_pp_readresp()
|
|
|
|
*
|
|
|
|
* Reads a piece of a server response.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_pp_readresp(curl_socket_t sockfd,
|
|
|
|
struct pingpong *pp,
|
|
|
|
int *code, /* return the server code if done */
|
|
|
|
size_t *size) /* size of the response */
|
|
|
|
{
|
|
|
|
ssize_t perline; /* count bytes per line */
|
|
|
|
bool keepon=TRUE;
|
|
|
|
ssize_t gotbytes;
|
|
|
|
char *ptr;
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
char * const buf = data->state.buffer;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
|
|
|
|
*code = 0; /* 0 for errors or not done */
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
ptr=buf + pp->nread_resp;
|
|
|
|
|
|
|
|
/* number of bytes in the current line, so far */
|
|
|
|
perline = (ssize_t)(ptr-pp->linestart_resp);
|
|
|
|
|
|
|
|
keepon=TRUE;
|
|
|
|
|
|
|
|
while((pp->nread_resp<BUFSIZE) && (keepon && !result)) {
|
|
|
|
|
|
|
|
if(pp->cache) {
|
|
|
|
/* we had data in the "cache", copy that instead of doing an actual
|
|
|
|
* read
|
|
|
|
*
|
2011-11-07 00:38:36 +08:00
|
|
|
* pp->cache_size is cast to ssize_t here. This should be safe, because
|
|
|
|
* it would have been populated with something of size int to begin
|
|
|
|
* with, even though its datatype may be larger than an int.
|
2009-12-13 05:54:01 +08:00
|
|
|
*/
|
|
|
|
DEBUGASSERT((ptr+pp->cache_size) <= (buf+BUFSIZE+1));
|
|
|
|
memcpy(ptr, pp->cache, pp->cache_size);
|
2010-08-03 00:53:03 +08:00
|
|
|
gotbytes = (ssize_t)pp->cache_size;
|
2009-12-13 05:54:01 +08:00
|
|
|
free(pp->cache); /* free the cache */
|
|
|
|
pp->cache = NULL; /* clear the pointer */
|
|
|
|
pp->cache_size = 0; /* zero the size just in case */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int res;
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2009-12-13 05:54:01 +08:00
|
|
|
enum protection_level prot = conn->data_prot;
|
2010-11-14 06:42:34 +08:00
|
|
|
conn->data_prot = PROT_CLEAR;
|
2009-12-13 05:54:01 +08:00
|
|
|
#endif
|
|
|
|
DEBUGASSERT((ptr+BUFSIZE-pp->nread_resp) <= (buf+BUFSIZE+1));
|
|
|
|
res = Curl_read(conn, sockfd, ptr, BUFSIZE-pp->nread_resp,
|
|
|
|
&gotbytes);
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2010-11-14 06:42:34 +08:00
|
|
|
DEBUGASSERT(prot > PROT_NONE && prot < PROT_LAST);
|
2009-12-13 05:54:01 +08:00
|
|
|
conn->data_prot = prot;
|
|
|
|
#endif
|
2010-05-07 21:05:34 +08:00
|
|
|
if(res == CURLE_AGAIN)
|
2009-12-13 05:54:01 +08:00
|
|
|
return CURLE_OK; /* return */
|
|
|
|
|
2011-04-20 06:48:20 +08:00
|
|
|
if((res == CURLE_OK) && (gotbytes > 0))
|
2009-12-13 05:54:01 +08:00
|
|
|
/* convert from the network encoding */
|
|
|
|
res = Curl_convert_from_network(data, ptr, gotbytes);
|
2011-04-20 06:48:20 +08:00
|
|
|
/* Curl_convert_from_network calls failf if unsuccessful */
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
if(CURLE_OK != res) {
|
|
|
|
result = (CURLcode)res; /* Set outer result variable to this error. */
|
|
|
|
keepon = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!keepon)
|
|
|
|
;
|
|
|
|
else if(gotbytes <= 0) {
|
|
|
|
keepon = FALSE;
|
|
|
|
result = CURLE_RECV_ERROR;
|
2010-10-29 06:47:57 +08:00
|
|
|
failf(data, "response reading failed");
|
2009-12-13 05:54:01 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we got a whole chunk of data, which can be anything from one
|
|
|
|
* byte to a set of lines and possible just a piece of the last
|
|
|
|
* line */
|
|
|
|
ssize_t i;
|
|
|
|
ssize_t clipamount = 0;
|
|
|
|
bool restart = FALSE;
|
|
|
|
|
2009-12-14 22:02:43 +08:00
|
|
|
data->req.headerbytecount += (long)gotbytes;
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
pp->nread_resp += gotbytes;
|
|
|
|
for(i = 0; i < gotbytes; ptr++, i++) {
|
|
|
|
perline++;
|
|
|
|
if(*ptr=='\n') {
|
2011-11-07 00:38:36 +08:00
|
|
|
/* a newline is CRLF in pp-talk, so the CR is ignored as
|
2009-12-13 05:54:01 +08:00
|
|
|
the line isn't really terminated until the LF comes */
|
|
|
|
|
|
|
|
/* output debug output if that is requested */
|
2013-08-23 22:16:42 +08:00
|
|
|
#ifdef HAVE_GSSAPI
|
2009-12-13 05:54:01 +08:00
|
|
|
if(!conn->sec_complete)
|
|
|
|
#endif
|
|
|
|
if(data->set.verbose)
|
2010-07-20 00:07:50 +08:00
|
|
|
Curl_debug(data, CURLINFO_HEADER_IN,
|
|
|
|
pp->linestart_resp, (size_t)perline, conn);
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We pass all response-lines to the callback function registered
|
|
|
|
* for "headers". The response lines can be seen as a kind of
|
|
|
|
* headers.
|
|
|
|
*/
|
|
|
|
result = Curl_client_write(conn, CLIENTWRITE_HEADER,
|
|
|
|
pp->linestart_resp, perline);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
2013-02-13 02:08:48 +08:00
|
|
|
if(pp->endofresp(conn, pp->linestart_resp, perline, code)) {
|
2009-12-13 05:54:01 +08:00
|
|
|
/* This is the end of the last line, copy the last line to the
|
2013-08-23 22:16:42 +08:00
|
|
|
start of the buffer and zero terminate, for old times sake */
|
2009-12-13 05:54:01 +08:00
|
|
|
char *meow;
|
|
|
|
int n;
|
|
|
|
for(meow=pp->linestart_resp, n=0; meow<ptr; meow++, n++)
|
|
|
|
buf[n] = *meow;
|
|
|
|
*meow=0; /* zero terminate */
|
|
|
|
keepon=FALSE;
|
|
|
|
pp->linestart_resp = ptr+1; /* advance pointer */
|
|
|
|
i++; /* skip this before getting out */
|
|
|
|
|
|
|
|
*size = pp->nread_resp; /* size of the response */
|
|
|
|
pp->nread_resp = 0; /* restart */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
perline=0; /* line starts over here */
|
|
|
|
pp->linestart_resp = ptr+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!keepon && (i != gotbytes)) {
|
|
|
|
/* We found the end of the response lines, but we didn't parse the
|
|
|
|
full chunk of data we have read from the server. We therefore need
|
|
|
|
to store the rest of the data to be checked on the next invoke as
|
|
|
|
it may actually contain another end of response already! */
|
|
|
|
clipamount = gotbytes - i;
|
|
|
|
restart = TRUE;
|
2012-11-05 01:22:48 +08:00
|
|
|
DEBUGF(infof(data, "Curl_pp_readresp_ %d bytes of trailing "
|
|
|
|
"server response left\n",
|
|
|
|
(int)clipamount));
|
2009-12-13 05:54:01 +08:00
|
|
|
}
|
|
|
|
else if(keepon) {
|
|
|
|
|
|
|
|
if((perline == gotbytes) && (gotbytes > BUFSIZE/2)) {
|
|
|
|
/* We got an excessive line without newlines and we need to deal
|
|
|
|
with it. We keep the first bytes of the line then we throw
|
|
|
|
away the rest. */
|
2011-04-20 21:17:42 +08:00
|
|
|
infof(data, "Excessive server response line length received, "
|
|
|
|
"%zd bytes. Stripping\n", gotbytes);
|
2009-12-13 05:54:01 +08:00
|
|
|
restart = TRUE;
|
|
|
|
|
|
|
|
/* we keep 40 bytes since all our pingpong protocols are only
|
|
|
|
interested in the first piece */
|
|
|
|
clipamount = 40;
|
|
|
|
}
|
|
|
|
else if(pp->nread_resp > BUFSIZE/2) {
|
2011-04-20 21:17:42 +08:00
|
|
|
/* We got a large chunk of data and there's potentially still
|
|
|
|
trailing data to take care of, so we put any such part in the
|
|
|
|
"cache", clear the buffer to make space and restart. */
|
2009-12-13 05:54:01 +08:00
|
|
|
clipamount = perline;
|
|
|
|
restart = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(i == gotbytes)
|
|
|
|
restart = TRUE;
|
|
|
|
|
|
|
|
if(clipamount) {
|
|
|
|
pp->cache_size = clipamount;
|
|
|
|
pp->cache = malloc(pp->cache_size);
|
|
|
|
if(pp->cache)
|
|
|
|
memcpy(pp->cache, pp->linestart_resp, pp->cache_size);
|
|
|
|
else
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if(restart) {
|
|
|
|
/* now reset a few variables to start over nicely from the start of
|
|
|
|
the big buffer */
|
|
|
|
pp->nread_resp = 0; /* start over from scratch in the buffer */
|
|
|
|
ptr = pp->linestart_resp = buf;
|
|
|
|
perline = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* there was data */
|
|
|
|
|
|
|
|
} /* while there's buffer left and loop is requested */
|
|
|
|
|
|
|
|
pp->pending_resp = FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Curl_pp_getsock(struct pingpong *pp,
|
|
|
|
curl_socket_t *socks,
|
|
|
|
int numsocks)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
|
|
|
|
if(!numsocks)
|
|
|
|
return GETSOCK_BLANK;
|
|
|
|
|
|
|
|
socks[0] = conn->sock[FIRSTSOCKET];
|
|
|
|
|
|
|
|
if(pp->sendleft) {
|
|
|
|
/* write mode */
|
|
|
|
return GETSOCK_WRITESOCK(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read mode */
|
|
|
|
return GETSOCK_READSOCK(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_pp_flushsend(struct pingpong *pp)
|
|
|
|
{
|
|
|
|
/* we have a piece of a command still left to send */
|
|
|
|
struct connectdata *conn = pp->conn;
|
|
|
|
ssize_t written;
|
|
|
|
CURLcode result = CURLE_OK;
|
|
|
|
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
|
|
|
|
|
|
|
result = Curl_write(conn, sock, pp->sendthis + pp->sendsize -
|
|
|
|
pp->sendleft, pp->sendleft, &written);
|
|
|
|
if(result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if(written != (ssize_t)pp->sendleft) {
|
|
|
|
/* only a fraction was sent */
|
|
|
|
pp->sendleft -= written;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
free(pp->sendthis);
|
|
|
|
pp->sendthis=NULL;
|
|
|
|
pp->sendleft = pp->sendsize = 0;
|
|
|
|
pp->response = Curl_tvnow();
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURLcode Curl_pp_disconnect(struct pingpong *pp)
|
|
|
|
{
|
|
|
|
if(pp->cache) {
|
|
|
|
free(pp->cache);
|
|
|
|
pp->cache = NULL;
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-15 02:36:43 +08:00
|
|
|
bool Curl_pp_moredata(struct pingpong *pp)
|
|
|
|
{
|
2013-03-03 21:55:01 +08:00
|
|
|
return (!pp->sendleft && pp->cache && pp->nread_resp < pp->cache_size) ?
|
|
|
|
TRUE : FALSE;
|
2013-02-15 02:36:43 +08:00
|
|
|
}
|
2009-12-13 05:54:01 +08:00
|
|
|
|
|
|
|
#endif
|