unsigned long i, x = 0;
for(i = 0, s = src; i < 4; i++, s++) {
- unsigned long v = 0;
-
if(*s == '=') {
x = (x << 6);
padding++;
}
else {
+ unsigned long v = 0;
p = base64;
while(*p && (*p != *s)) {
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
struct connectdata **connp)
{
- curl_socket_t sockfd;
-
DEBUGASSERT(data);
/* this works for an easy handle:
if(connp)
/* only store this if the caller cares for it */
*connp = c;
- sockfd = c->sock[FIRSTSOCKET];
+ return c->sock[FIRSTSOCKET];
}
else
return CURL_SOCKET_BAD;
-
- return sockfd;
}
/*
z_stream *z = &zp->z; /* zlib state structure */
uInt nread = z->avail_in;
Bytef *orig_in = z->next_in;
- int status; /* zlib status */
bool done = FALSE;
CURLcode result = CURLE_OK; /* Curl_client_write status */
char *decomp; /* Put the decompressed data here. */
/* because the buffer size is fixed, iteratively decompress and transfer to
the client via downstream_write function. */
while(!done) {
+ int status; /* zlib status */
done = TRUE;
/* (re)set buffer for decompressed output for every iteration */
const content_encoding * const *cep;
const content_encoding *ce;
char *ace;
- char *p;
for(cep = encodings; *cep; cep++) {
ce = *cep;
ace = malloc(len);
if(ace) {
- p = ace;
+ char *p = ace;
for(cep = encodings; *cep; cep++) {
ce = *cep;
if(!strcasecompare(ce->name, CONTENT_ENCODING_DEFAULT)) {
static const content_encoding *find_encoding(const char *name, size_t len)
{
const content_encoding * const *cep;
- const content_encoding *ce;
for(cep = encodings; *cep; cep++) {
- ce = *cep;
+ const content_encoding *ce = *cep;
if((strncasecompare(name, ce->name, len) && !ce->name[len]) ||
(ce->alias && strncasecompare(name, ce->alias, len) && !ce->alias[len]))
return ce;
*/
static void remove_expired(struct CookieInfo *cookies)
{
- struct Cookie *co, *nx, *pv;
+ struct Cookie *co, *nx;
curl_off_t now = (curl_off_t)time(NULL);
unsigned int i;
for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ struct Cookie *pv = NULL;
co = cookies->cookies[i];
- pv = NULL;
while(co) {
nx = co->next;
if(co->expires && co->expires < now) {
****************************************************************************/
void Curl_cookie_cleanup(struct CookieInfo *c)
{
- unsigned int i;
-
if(c) {
+ unsigned int i;
free(c->filename);
for(i = 0; i < COOKIE_HASH_SIZE; i++)
Curl_cookie_freelist(c->cookies[i]);
const char *value, size_t len)
{
CURLcode result = CURLE_OK;
- unsigned int mechbit;
size_t mechlen;
if(!len)
if(!strncmp(value, "*", len))
sasl->prefmech = SASL_AUTH_DEFAULT;
else {
- mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
+ unsigned int mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
if(mechbit && mechlen == len)
sasl->prefmech |= mechbit;
else
{
char *newp = NULL;
char *dictp;
- char *ptr;
size_t len;
- char ch;
- int olen = 0;
CURLcode result = Curl_urldecode(data, inputbuff, 0, &newp, &len, FALSE);
if(!newp || result)
dictp = malloc(((size_t)len)*2 + 1); /* add one for terminating zero */
if(dictp) {
+ char *ptr;
+ char ch;
+ int olen = 0;
/* According to RFC2229 section 2.2, these letters need to be escaped with
\[letter] */
for(ptr = newp;
size_t alloc;
char *ns;
char *testing_ptr = NULL;
- unsigned char in; /* we need to treat the characters unsigned */
size_t newlen;
size_t strindex = 0;
size_t length;
length = alloc-1;
while(length--) {
- in = *string;
+ unsigned char in = *string; /* we need to treat the characters unsigned */
if(Curl_isunreserved(in))
/* just copy this */
{
size_t alloc = (length?length:strlen(string)) + 1;
char *ns = malloc(alloc);
- unsigned char in;
size_t strindex = 0;
unsigned long hex;
CURLcode result;
return CURLE_OUT_OF_MEMORY;
while(--alloc > 0) {
- in = *string;
+ unsigned char in = *string;
if(('%' == in) && (alloc > 2) &&
ISXDIGIT(string[1]) && ISXDIGIT(string[2])) {
/* this is two hexadecimal digits following a '%' */
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
char *buf = data->state.buffer;
- size_t nread;
- size_t nwrite;
curl_off_t bytecount = 0;
struct_stat file_stat;
const char *buf2;
}
while(!result) {
+ size_t nread;
+ size_t nwrite;
int readcount;
result = Curl_fillreadbuffer(conn, (int)data->set.buffer_size, &readcount);
if(result)
curl_off_t expected_size = 0;
bool size_known;
bool fstated = FALSE;
- ssize_t nread;
struct Curl_easy *data = conn->data;
char *buf = data->state.buffer;
curl_off_t bytecount = 0;
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
while(!result) {
+ ssize_t nread;
/* Don't fill a whole buffer if we want less than all data */
size_t bytestoread;
{
CURLcode result = CURLE_OK;
curl_mime *form = NULL;
- curl_mime *multipart;
curl_mimepart *part;
struct curl_httppost *file;
/* Process each top part. */
for(; !result && post; post = post->next) {
/* If we have more than a file here, create a mime subpart and fill it. */
- multipart = form;
+ curl_mime *multipart = form;
if(post->more) {
part = curl_mime_addpart(form);
if(!part)
static void freedirs(struct ftp_conn *ftpc)
{
- int i;
if(ftpc->dirs) {
+ int i;
for(i = 0; i < ftpc->dirdepth; i++) {
free(ftpc->dirs[i]);
ftpc->dirs[i] = NULL;
* line in a response or continue reading. */
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
- time_t timeout; /* timeout in milliseconds */
- time_t interval_ms;
struct Curl_easy *data = conn->data;
CURLcode result = CURLE_OK;
struct ftp_conn *ftpc = &conn->proto.ftpc;
while(!*ftpcode && !result) {
/* check and reset timeout value every lap */
- timeout = Curl_pp_state_timeout(pp);
+ time_t timeout = Curl_pp_state_timeout(pp); /* timeout in milliseconds */
+ time_t interval_ms;
if(timeout <= 0) {
failf(data, "FTP response timeout");
struct FTP *ftp = conn->data->req.protop;
struct Curl_easy *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
- int seekerr = CURL_SEEKFUNC_OK;
if((data->state.resume_from && !sizechecked) ||
((data->state.resume_from > 0) && sizechecked)) {
/* 3. pass file-size number of bytes in the source file */
/* 4. lower the infilesize counter */
/* => transfer as usual */
+ int seekerr = CURL_SEEKFUNC_OK;
if(data->state.resume_from < 0) {
/* Got no given size to start from, figure it out */
char *ptr = &data->state.buffer[4]; /* start on the first letter */
const size_t buf_size = data->set.buffer_size;
char *dir;
- char *store;
bool entry_extracted = FALSE;
dir = malloc(nread + 1);
if('\"' == *ptr) {
/* it started good */
+ char *store;
ptr++;
for(store = dir; *ptr;) {
if('\"' == *ptr) {
{
struct Curl_easy *data = conn->data;
char *type;
- char command;
struct FTP *ftp;
conn->data->req.protop = ftp = malloc(sizeof(struct FTP));
type = strstr(conn->host.rawalloc, ";type=");
if(type) {
+ char command;
*type = 0; /* it was in the middle of the hostname */
command = Curl_raw_toupper(type[6]);
conn->bits.type_set = TRUE;
comp_function comparator,
curl_hash_dtor dtor)
{
- int i;
-
if(!slots || !hfunc || !comparator ||!dtor) {
return 1; /* failure */
}
h->table = malloc(slots * sizeof(struct curl_llist));
if(h->table) {
+ int i;
for(i = 0; i < slots; ++i)
Curl_llist_init(&h->table[i], (curl_llist_dtor) hash_element_dtor);
return 0; /* fine */
int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
{
struct curl_llist_element *le;
- struct curl_hash_element *he;
struct curl_llist *l = FETCH_LIST(h, key, key_len);
for(le = l->head; le; le = le->next) {
- he = le->ptr;
+ struct curl_hash_element *he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *) h);
--h->size;
Curl_hash_pick(struct curl_hash *h, void *key, size_t key_len)
{
struct curl_llist_element *le;
- struct curl_hash_element *he;
struct curl_llist *l;
if(h) {
l = FETCH_LIST(h, key, key_len);
for(le = l->head; le; le = le->next) {
- he = le->ptr;
+ struct curl_hash_element *he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) {
return he->ptr;
}
struct curl_hash_element *
Curl_hash_next_element(struct curl_hash_iterator *iter)
{
- int i;
struct curl_hash *h = iter->hash;
/* Get the next element in the current list, if any */
/* If we have reached the end of the list, find the next one */
if(!iter->current_element) {
+ int i;
for(i = iter->slot_index; i < h->slots; i++) {
if(h->table[i].head) {
iter->current_element = h->table[i].head;
CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size)
{
char *new_rb;
- size_t new_size;
if(~size < in->size_used) {
/* If resulting used size of send buffer would wrap size_t, cleanup
if(!in->buffer ||
((in->size_used + size) > (in->size_max - 1))) {
-
/* If current buffer size isn't enough to hold the result, use a
buffer size that doubles the required size. If this new size
would wrap size_t, then just use the largest possible one */
+ size_t new_size;
if((size > (size_t)-1 / 2) || (in->size_used > (size_t)-1 / 2) ||
(~(size * 2) < (in->size_used * 2)))
Curl_send_buffer *req_buffer)
{
CURLcode result = CURLE_OK;
- const char *ptr;
data->state.expect100header = FALSE; /* default to false unless it is set
to TRUE below */
if(use_http_1_1plus(data, conn) &&
/* if not doing HTTP 1.0 or version 2, or disabled explicitly, we add an
Expect: 100-continue to the headers which actually speeds up post
operations (as there is one packet coming back from the web server) */
- ptr = Curl_checkheaders(conn, "Expect");
+ const char *ptr = Curl_checkheaders(conn, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
const char *httpstring;
Curl_send_buffer *req_buffer;
curl_off_t postsize = 0; /* curl_off_t to handle large file sizes */
- int seekerr = CURL_SEEKFUNC_CANTSEEK;
/* Always consider the DO phase done after this function call, even if there
may be parts of the request that is not yet sent, since we can deal with
else {
/* If the host begins with '[', we start searching for the port after
the bracket has been closed */
- int startsearch = 0;
if(*cookiehost == '[') {
char *closingbracket;
/* since the 'cookiehost' is an allocated memory area that will be
*closingbracket = 0;
}
else {
+ int startsearch = 0;
char *colon = strchr(cookiehost + startsearch, ':');
if(colon)
*colon = 0; /* The host must not include an embedded port number */
/* Now, let's read off the proper amount of bytes from the
input. */
+ int seekerr = CURL_SEEKFUNC_CANTSEEK;
if(conn->seek_func) {
Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
struct SingleRequest *k = &data->req;
CURLcode result;
curl_socket_t tunnelsocket = conn->sock[sockindex];
- timediff_t check;
struct http_connect_state *s = conn->connect_state;
#define SELECT_OK 0
conn->bits.proxy_connect_closed = FALSE;
do {
+ timediff_t check;
if(TUNNEL_INIT == s->tunnel_state) {
/* BEGIN CONNECT PHASE */
char *host_port;
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct IMAP *imap = data->req.protop;
- char *mailbox;
if(imap->custom)
/* Send the custom request */
imap->custom_params ? imap->custom_params : "");
else {
/* Make sure the mailbox is in the correct atom format if necessary */
- mailbox = imap->mailbox ? imap_atom(imap->mailbox, true) : strdup("");
+ char *mailbox = imap->mailbox ? imap_atom(imap->mailbox, true)
+ : strdup("");
if(!mailbox)
return CURLE_OUT_OF_MEMORY;
struct Curl_easy *data = conn->data;
struct imap_conn *imapc = &conn->proto.imapc;
const char *line = data->state.buffer;
- size_t wordlen;
(void)instate; /* no use for this yet */
/* Loop through the data line */
for(;;) {
+ size_t wordlen;
while(*line &&
(*line == ' ' || *line == '\t' ||
*line == '\r' || *line == '\n')) {
struct IMAP *imap = conn->data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
const char *line = data->state.buffer;
- char tmp[20];
(void)instate; /* no use for this yet */
if(imapcode == '*') {
/* See if this is an UIDVALIDITY response */
+ char tmp[20];
if(sscanf(line + 2, "OK [UIDVALIDITY %19[0123456789]]", tmp) == 1) {
Curl_safefree(imapc->mailbox_uidvalidity);
imapc->mailbox_uidvalidity = strdup(tmp);
mime_encoder_state *st = &part->encstate;
char *ptr = buffer;
size_t cursize = 0;
- int i;
- size_t len;
- size_t consumed;
int softlinebreak;
char buf[4];
character constants that can be interpreted as non-ascii on some
platforms. Preserve ASCII encoding on output too. */
while(st->bufbeg < st->bufend) {
- len = 1;
- consumed = 1;
- i = st->buf[st->bufbeg];
+ size_t len = 1;
+ size_t consumed = 1;
+ int i = st->buf[st->bufbeg];
buf[0] = (char) i;
buf[1] = aschex[(i >> 4) & 0xF];
buf[2] = aschex[i & 0xF];
char *buffer, size_t bufsize)
{
size_t cursize = 0;
- size_t sz;
- struct curl_slist *hdr;
#ifdef CURL_DOES_CONVERSIONS
char *convbuf = buffer;
#endif
/* Readback from part. */
while(bufsize) {
- sz = 0;
- hdr = (struct curl_slist *) part->state.ptr;
+ size_t sz = 0;
+ struct curl_slist *hdr = (struct curl_slist *) part->state.ptr;
switch(part->state.state) {
case MIMESTATE_BEGIN:
mimesetstate(&part->state, part->flags & MIME_BODY_ONLY? MIMESTATE_BODY:
{
curl_mime *mime = (curl_mime *) instream;
size_t cursize = 0;
- size_t sz;
- curl_mimepart *part;
#ifdef CURL_DOES_CONVERSIONS
char *convbuf = buffer;
#endif
(void) size; /* Always 1. */
while(nitems) {
- sz = 0;
- part = mime->state.ptr;
+ size_t sz = 0;
+ curl_mimepart *part = mime->state.ptr;
switch(mime->state.state) {
case MIMESTATE_BEGIN:
case MIMESTATE_BODY:
curl_mime *mime = (curl_mime *) instream;
curl_mimepart *part;
int result = CURL_SEEKFUNC_OK;
- int res;
if(whence != SEEK_SET || offset)
return CURL_SEEKFUNC_CANTSEEK; /* Only support full rewind. */
return CURL_SEEKFUNC_OK; /* Already rewound. */
for(part = mime->firstpart; part; part = part->nextpart) {
- res = mime_part_rewind(part);
+ int res = mime_part_rewind(part);
if(res != CURL_SEEKFUNC_OK)
result = res;
}
CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename)
{
CURLcode result = CURLE_OK;
- char *base;
if(!part)
return CURLE_BAD_FUNCTION_ARGUMENT;
cleanup_part_content(part);
if(filename) {
+ char *base;
struct_stat sbuf;
if(stat(filename, &sbuf) || access(filename, R_OK))
static curl_off_t multipart_size(curl_mime *mime)
{
curl_off_t size;
- curl_off_t sz;
size_t boundarysize;
curl_mimepart *part;
size = boundarysize; /* Final boundary - CRLF after headers. */
for(part = mime->firstpart; part; part = part->nextpart) {
- sz = Curl_mime_size(part);
+ curl_off_t sz = Curl_mime_size(part);
if(sz < 0)
size = sz;
const char *Curl_mime_contenttype(const char *filename)
{
- unsigned int i;
-
/*
* If no content type was specified, we scan through a few well-known
* extensions and pick the first we match!
if(filename) {
size_t len1 = strlen(filename);
const char *nameend = filename + len1;
+ unsigned int i;
for(i = 0; i < sizeof(ctts) / sizeof(ctts[0]); i++) {
size_t len2 = strlen(ctts[i].extension);
struct Curl_easy *data;
int this_max_fd = -1;
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
- int bitmap;
int i;
(void)exc_fd_set; /* not used */
data = multi->easyp;
while(data) {
- bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
+ int bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
for(i = 0; i< MAX_SOCKSPEREASYHANDLE; i++) {
curl_socket_t s = CURL_SOCKET_BAD;
{
struct Curl_multi *multi = data->multi;
struct curltime *nowp = &data->state.expiretime;
- int rc;
struct curltime set;
/* this is only interesting while there is still an associated multi struct
Compare if the new time is earlier, and only remove-old/add-new if it
is. */
timediff_t diff = Curl_timediff(set, *nowp);
+ int rc;
if(diff > 0) {
/* The current splay tree entry is sooner than this new expiry time.
{
struct Curl_multi *multi = data->multi;
struct curltime *nowp = &data->state.expiretime;
- int rc;
/* this is only interesting while there is still an associated multi struct
remaining! */
/* Since this is an cleared time, we must remove the previous entry from
the splay tree */
struct curl_llist *list = &data->state.timeoutlist;
+ int rc;
rc = Curl_splayremovebyaddr(multi->timetree,
&data->state.timenode,
struct connectdata *conn = pp->conn;
struct Curl_easy *data = conn->data;
time_t timeout_ms; /* in milliseconds */
- time_t timeout2_ms; /* in milliseconds */
long response_time = (data->set.server_response_timeout)?
data->set.server_response_timeout: pp->response_time;
if(data->set.timeout) {
/* if timeout is requested, find out how much remaining time we have */
- timeout2_ms = data->set.timeout - /* timeout time */
+ time_t timeout2_ms = data->set.timeout - /* timeout time */
Curl_timediff(Curl_now(), conn->now); /* spent time */
/* pick the lowest number */
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t i;
(void)instate; /* no use for this yet */
/* Does the server support APOP authentication? */
if(len >= 4 && line[len - 2] == '>') {
/* Look for the APOP timestamp */
+ size_t i;
for(i = 3; i < len - 2; ++i) {
if(line[i] == '<') {
/* Calculate the length of the timestamp */
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t wordlen;
(void)instate; /* no use for this yet */
/* Loop through the data line */
for(;;) {
size_t llen;
+ size_t wordlen;
unsigned int mechbit;
while(len &&
byte) */
static void time2str(char *r, curl_off_t seconds)
{
- curl_off_t d, h, m, s;
+ curl_off_t h;
if(seconds <= 0) {
strcpy(r, "--:--:--");
return;
}
h = seconds / CURL_OFF_T_C(3600);
if(h <= CURL_OFF_T_C(99)) {
- m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
- s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
+ curl_off_t m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
+ curl_off_t s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
snprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
}
else {
/* this equals to more than 99 hours, switch to a more suitable output
format to fit within the limits. */
- d = seconds / CURL_OFF_T_C(86400);
+ curl_off_t d = seconds / CURL_OFF_T_C(86400);
h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
if(d <= CURL_OFF_T_C(999))
snprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
int Curl_pgrsUpdate(struct connectdata *conn)
{
struct curltime now;
- int result;
- char max5[6][10];
- curl_off_t dlpercen = 0;
- curl_off_t ulpercen = 0;
- curl_off_t total_percen = 0;
- curl_off_t total_transfer;
- curl_off_t total_expected_transfer;
curl_off_t timespent;
curl_off_t timespent_ms; /* milliseconds */
struct Curl_easy *data = conn->data;
int nowindex = data->progress.speeder_c% CURR_TIME;
- int checkindex;
- int countindex; /* amount of seconds stored in the speeder array */
- char time_left[10];
- char time_total[10];
- char time_spent[10];
- curl_off_t ulestimate = 0;
- curl_off_t dlestimate = 0;
- curl_off_t total_estimate;
bool shownow = FALSE;
curl_off_t dl = data->progress.downloaded;
curl_off_t ul = data->progress.uploaded;
/* Calculations done at most once a second, unless end is reached */
if(data->progress.lastshow != now.tv_sec) {
+ int countindex; /* amount of seconds stored in the speeder array */
shownow = TRUE;
data->progress.lastshow = now.tv_sec;
/* first of all, we don't do this if there's no counted seconds yet */
if(countindex) {
+ int checkindex;
timediff_t span_ms;
/* Get the index position to compare with the 'nowindex' position.
if(!(data->progress.flags & PGRS_HIDE)) {
/* progress meter has not been shut off */
+ char max5[6][10];
+ curl_off_t dlpercen = 0;
+ curl_off_t ulpercen = 0;
+ curl_off_t total_percen = 0;
+ curl_off_t total_transfer;
+ curl_off_t total_expected_transfer;
+ char time_left[10];
+ char time_total[10];
+ char time_spent[10];
+ curl_off_t ulestimate = 0;
+ curl_off_t dlestimate = 0;
+ curl_off_t total_estimate;
if(data->set.fxferinfo) {
+ int result;
/* There's a callback set, call that */
Curl_set_in_callback(data, true);
result = data->set.fxferinfo(data->set.progress_client,
return result;
}
if(data->set.fprogress) {
+ int result;
/* The older deprecated callback is set, call that */
Curl_set_in_callback(data, true);
result = data->set.fprogress(data->set.progress_client,
struct Curl_easy *data = conn->data;
struct RTSP *rtsp = data->req.protop;
CURLcode httpStatus;
- long CSeq_sent;
- long CSeq_recv;
/* Bypass HTTP empty-reply checks on receive */
if(data->set.rtspreq == RTSPREQ_RECEIVE)
if(rtsp) {
/* Check the sequence numbers */
- CSeq_sent = rtsp->CSeq_sent;
- CSeq_recv = rtsp->CSeq_recv;
+ long CSeq_sent = rtsp->CSeq_sent;
+ long CSeq_recv = rtsp->CSeq_recv;
if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) {
failf(data,
"The CSeq of this request %ld did not match the response %ld",
#endif
struct curltime initial_tv;
int pending_ms;
- int error;
#endif
int r = 0;
pending_ms = timeout_ms;
initial_tv = Curl_now();
do {
+ int error;
#if defined(HAVE_POLL_FINE)
r = poll(NULL, 0, pending_ms);
#else
#endif
struct curltime initial_tv = {0, 0};
int pending_ms = 0;
- int error;
int r;
int ret;
}
do {
+ int error;
if(timeout_ms < 0)
pending_ms = -1;
else if(!timeout_ms)
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do {
+ int error;
if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
bool fds_none = TRUE;
unsigned int i;
int pending_ms = 0;
- int error;
int r;
if(ufds) {
#ifdef HAVE_POLL_FINE
do {
+ int error;
if(timeout_ms < 0)
pending_ms = -1;
else if(!timeout_ms)
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do {
+ int error;
if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
{
int rc;
if(data->set.printhost && conn && conn->host.dispname) {
- char buffer[160];
const char *t = NULL;
const char *w = "Data";
switch(type) {
}
if(t) {
+ char buffer[160];
snprintf(buffer, sizeof(buffer), "[%s %s %s]", w, t,
conn->host.dispname);
rc = showit(data, CURLINFO_TEXT, buffer, strlen(buffer));
ssize_t *written);
/* the function used to output verbose information */
-int Curl_debug(struct Curl_easy *handle, curl_infotype type,
- char *data, size_t size,
+int Curl_debug(struct Curl_easy *data, curl_infotype type,
+ char *ptr, size_t size,
struct connectdata *conn);
static int sha256_compress(struct sha256_state *md,
unsigned char *buf)
{
- unsigned long S[8], W[64], t0, t1;
- unsigned long t;
+ unsigned long S[8], W[64];
int i;
/* copy state into S */
for(i = 0; i < 8; i++) {
W[i - 16];
}
/* Compress */
-#define RND(a,b,c,d,e,f,g,h,i) \
- t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
- t1 = Sigma0(a) + Maj(a, b, c); \
- d += t0; \
+#define RND(a,b,c,d,e,f,g,h,i) \
+ unsigned long t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
+ unsigned long t1 = Sigma0(a) + Maj(a, b, c); \
+ d += t0; \
h = t0 + t1;
for(i = 0; i < 64; ++i) {
+ unsigned long t;
RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4];
S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
struct smtp_conn *smtpc = &conn->proto.smtpc;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t wordlen;
(void)instate; /* no use for this yet */
/* Loop through the data line */
for(;;) {
size_t llen;
+ size_t wordlen;
unsigned int mechbit;
while(len &&
ssize_t nread;
ssize_t allread = 0;
int result;
- timediff_t timeleft;
*n = 0;
for(;;) {
- timeleft = Curl_timeleft(conn->data, NULL, TRUE);
+ timediff_t timeleft = Curl_timeleft(conn->data, NULL, TRUE);
if(timeleft < 0) {
/* we already got the timeout */
result = CURLE_OPERATION_TIMEDOUT;
#define SOCKS4REQLEN 262
unsigned char socksreq[SOCKS4REQLEN]; /* room for SOCKS4 request incl. user
id */
- int result;
CURLcode code;
curl_socket_t sock = conn->sock[sockindex];
struct Curl_easy *data = conn->data;
* Make connection
*/
{
+ int result;
ssize_t actualread;
ssize_t written;
ssize_t hostnamelen = 0;
if(dns)
hp = dns->addr;
if(hp) {
- int i;
char buf[64];
Curl_printable_address(hp, buf, sizeof(buf));
if(hp->ai_family == AF_INET) {
+ int i;
struct sockaddr_in *saddr_in;
socksreq[len++] = 1; /* ATYP: IPv4 = 1 */
}
#ifdef ENABLE_IPV6
else if(hp->ai_family == AF_INET6) {
+ int i;
struct sockaddr_in6 *saddr_in6;
socksreq[len++] = 4; /* ATYP: IPv6 = 4 */
struct Curl_tree *t)
{
struct Curl_tree N, *l, *r, *y;
- long comp;
if(t == NULL)
return t;
l = r = &N;
for(;;) {
- comp = compare(i, t->key);
+ long comp = compare(i, t->key);
if(comp < 0) {
if(t->smaller == NULL)
break;
static void negotiate(struct connectdata *);
static void send_negotiation(struct connectdata *, int cmd, int option);
-static void set_local_option(struct connectdata *, int cmd, int option);
-static void set_remote_option(struct connectdata *, int cmd, int option);
+static void set_local_option(struct connectdata *conn,
+ int option, int newstate);
+static void set_remote_option(struct connectdata *conn,
+ int option, int newstate);
static void printsub(struct Curl_easy *data,
int direction, unsigned char *pointer,
static void printoption(struct Curl_easy *data,
const char *direction, int cmd, int option)
{
- const char *fmt;
- const char *opt;
-
if(data->set.verbose) {
if(cmd == CURL_IAC) {
if(CURL_TELCMD_OK(option))
infof(data, "%s IAC %d\n", direction, option);
}
else {
- fmt = (cmd == CURL_WILL) ? "WILL" : (cmd == CURL_WONT) ? "WONT" :
- (cmd == CURL_DO) ? "DO" : (cmd == CURL_DONT) ? "DONT" : 0;
+ const char *fmt = (cmd == CURL_WILL) ? "WILL" :
+ (cmd == CURL_WONT) ? "WONT" :
+ (cmd == CURL_DO) ? "DO" :
+ (cmd == CURL_DONT) ? "DONT" : 0;
if(fmt) {
+ const char *opt;
if(CURL_TELOPT_OK(option))
opt = CURL_TELOPT(option);
else if(option == CURL_TELOPT_EXOPL)
{
unsigned char buf[3];
ssize_t bytes_written;
- int err;
struct Curl_easy *data = conn->data;
buf[0] = CURL_IAC;
bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0) {
- err = SOCKERRNO;
+ int err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
unsigned char *pointer, /* where suboption data is */
size_t length) /* length of suboption data */
{
- unsigned int i = 0;
-
if(data->set.verbose) {
+ unsigned int i = 0;
if(direction) {
infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT");
if(length >= 3) {
unsigned char temp[2048];
ssize_t bytes_written;
size_t len;
- size_t tmplen;
int err;
char varname[128] = "";
char varval[128] = "";
len = 4;
for(v = tn->telnet_vars; v; v = v->next) {
- tmplen = (strlen(v->data) + 1);
+ size_t tmplen = (strlen(v->data) + 1);
/* Add the variable only if it fits */
if(len + tmplen < (int)sizeof(temp)-6) {
if(sscanf(v->data, "%127[^,],%127s", varname, varval)) {
static CURLcode send_telnet_data(struct connectdata *conn,
char *buffer, ssize_t nread)
{
- ssize_t escapes, i, j, outlen;
+ ssize_t escapes, i, outlen;
unsigned char *outbuf = NULL;
CURLcode result = CURLE_OK;
ssize_t bytes_written, total_written;
if(outlen == nread)
outbuf = (unsigned char *)buffer;
else {
+ ssize_t j;
outbuf = malloc(nread + escapes + 1);
if(!outbuf)
return CURLE_OUT_OF_MEMORY;
HANDLE objs[2];
DWORD obj_count;
DWORD wait_timeout;
- DWORD waitret;
DWORD readfile_read;
int err;
#else
/* Keep on listening and act on events */
while(keepon) {
const DWORD buf_size = (DWORD)data->set.buffer_size;
- waitret = WaitForMultipleObjects(obj_count, objs, FALSE, wait_timeout);
+ DWORD waitret = WaitForMultipleObjects(obj_count, objs,
+ FALSE, wait_timeout);
switch(waitret) {
case WAIT_TIMEOUT:
{
ssize_t senddata;
const char *mode = "octet";
char *filename;
- char buf[64];
struct Curl_easy *data = state->conn->data;
CURLcode result = CURLE_OK;
/* optional addition of TFTP options */
if(!data->set.tftp_no_options) {
+ char buf[64];
/* add tsize option */
if(data->set.upload && (data->state.infilesize != -1))
snprintf(buf, sizeof(buf), "%" CURL_FORMAT_CURL_OFF_T,
{
struct Curl_easy *data = state->conn->data;
ssize_t sbytes;
- int rblock;
CURLcode result = CURLE_OK;
struct SingleRequest *k = &data->req;
int cb; /* Bytes currently read */
case TFTP_EVENT_OACK:
if(event == TFTP_EVENT_ACK) {
/* Ack the packet */
- rblock = getrpacketblock(&state->rpacket);
+ int rblock = getrpacketblock(&state->rpacket);
if(rblock != state->block &&
/* There's a bug in tftpd-hpa that causes it to send us an ack for
static CURLcode tftp_connect(struct connectdata *conn, bool *done)
{
tftp_state_data_t *state;
- int blksize, rc;
+ int blksize;
blksize = TFTP_BLKSIZE_DEFAULT;
* assume uses the same IP version and thus hopefully this works for both
* IPv4 and IPv6...
*/
- rc = bind(state->sockfd, (struct sockaddr *)&state->local_addr,
- conn->ip_addr->ai_addrlen);
+ int rc = bind(state->sockfd, (struct sockaddr *)&state->local_addr,
+ conn->ip_addr->ai_addrlen);
if(rc) {
failf(conn->data, "bind() failed; %s",
Curl_strerror(conn, SOCKERRNO));
**********************************************************/
static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
{
- int rc;
tftp_event_t event;
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
}
else {
/* no timeouts to handle, check our socket */
- rc = SOCKET_READABLE(state->sockfd, 0);
+ int rc = SOCKET_READABLE(state->sockfd, 0);
if(rc == -1) {
/* bail out */
{
struct Curl_easy *data = conn->data;
char *type;
- char command;
conn->socktype = SOCK_DGRAM; /* UDP datagram based */
type = strstr(conn->host.rawalloc, ";mode=");
if(type) {
+ char command;
*type = 0; /* it was in the middle of the hostname */
command = Curl_raw_toupper(type[6]);
CURLcode result = CURLE_OK;
ssize_t nread; /* number of bytes read */
size_t excess = 0; /* excess bytes read */
- bool is_empty_data = FALSE;
bool readmore = FALSE; /* used by RTP to signal for more data */
int maxloops = 100;
/* This is where we loop until we have read everything there is to
read or we get a CURLE_AGAIN */
do {
+ bool is_empty_data = FALSE;
size_t buffersize = data->set.buffer_size;
size_t bytestoread = buffersize;
char *fragment;
char *path = data->state.path;
char *query;
- int i;
int rc;
const char *protop = "";
CURLcode result;
; /* do nothing */
}
else { /* check for a scheme */
+ int i;
for(i = 0; i < 16 && data->change.url[i]; ++i) {
if(data->change.url[i] == '/')
break;
* not be proxied, or an asterisk to override
* all proxy variables)
*/
- size_t tok_start;
- size_t tok_end;
- const char *separator = ", ";
- size_t no_proxy_len;
- size_t namelen;
- char *endptr;
-
if(no_proxy && no_proxy[0]) {
+ size_t tok_start;
+ size_t tok_end;
+ const char *separator = ", ";
+ size_t no_proxy_len;
+ size_t namelen;
+ char *endptr;
if(strcasecompare("*", no_proxy)) {
return TRUE;
}
/* Perform quoted-string escaping as described in RFC2616 and its errata */
static char *auth_digest_string_quoted(const char *source)
{
- char *dest, *d;
+ char *dest;
const char *s = source;
size_t n = 1; /* null terminator */
dest = malloc(n);
if(dest) {
+ char *d = dest;
s = source;
- d = dest;
while(*s) {
if(*s == '"' || *s == '\\') {
*d++ = '\\';
unsigned char ha1[65]; /* 64 digits and 1 zero byte */
unsigned char ha2[65]; /* 64 digits and 1 zero byte */
char userh[65];
- char cnoncebuf[33];
char *cnonce = NULL;
size_t cnonce_sz = 0;
char *userp_quoted;
digest->nc = 1;
if(!digest->cnonce) {
+ char cnoncebuf[33];
result = Curl_rand_hex(data, (unsigned char *)cnoncebuf,
sizeof(cnoncebuf));
if(result)
FILE *output = config->errors;
const char *text;
struct timeval tv;
- struct tm *now;
char timebuf[20];
time_t secs;
- static time_t epoch_offset;
- static int known_offset;
(void)handle; /* not used */
if(config->tracetime) {
+ struct tm *now;
+ static time_t epoch_offset;
+ static int known_offset;
tv = tvnow();
if(!known_offset) {
epoch_offset = time(NULL) - tv.tv_sec;
static const char * const s_infotype[] = {
"*", "<", ">", "{", "}", "{", "}"
};
- size_t i;
- size_t st = 0;
static bool newl = FALSE;
static bool traced_data = FALSE;
switch(type) {
case CURLINFO_HEADER_OUT:
if(size > 0) {
+ size_t st = 0;
+ size_t i;
for(i = 0; i < size - 1; i++) {
if(data[i] == '\n') { /* LF */
if(!newl) {
/* The original progress-bar source code was written for curl by Lars Aas,
and this new edition inherits some of his concepts. */
- char line[MAX_BARLENGTH + 1];
- char format[40];
- double frac;
- double percent;
- int barwidth;
- int num;
struct timeval now = tvnow();
struct ProgressData *bar = (struct ProgressData *)clientp;
curl_off_t total;
bar->calls++;
if((total > 0) && (point != bar->prev)) {
+ char line[MAX_BARLENGTH + 1];
+ char format[40];
+ double frac;
+ double percent;
+ int barwidth;
+ int num;
if(point > total)
/* we have got more than the expected total! */
total = point;
{
size_t hdrlen = 0;
size_t pos = 0;
- int c;
bool incomment = FALSE;
int lineno = 1;
char hdrbuf[999]; /* Max. header length + 1. */
for(;;) {
- c = getc(fp);
+ int c = getc(fp);
if(c == EOF || (!pos && !ISSPACE(c))) {
/* Strip and flush the current header. */
while(hdrlen && ISSPACE(hdrbuf[hdrlen - 1]))
struct curl_slist *headers = NULL;
curl_mimepart *part = NULL;
CURLcode res;
- int sep = '\0';
/* Allocate the main mime structure if needed. */
if(!*mimepost) {
/* Scan for the end of the name. */
contp = strchr(contents, '=');
if(contp) {
+ int sep = '\0';
if(contp > contents)
name = contents;
*contp++ = '\0';
*usedarg = FALSE; /* default is that we don't use the arg */
- if(('-' != flag[0]) ||
- (('-' == flag[0]) && ('-' == flag[1]))) {
+ if(('-' != flag[0]) || ('-' == flag[1])) {
/* this should be a long name */
const char *word = ('-' == flag[0]) ? flag + 2 : flag;
size_t fnam = strlen(word);
orig_opt = argv[i];
if(stillflags && ('-' == argv[i][0])) {
- char *nextarg;
bool passarg;
char *flag = argv[i];
following (URL) argument to start with -. */
stillflags = FALSE;
else {
- nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
+ char *nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
result = getparameter(flag, nextarg, &passarg, config, operation);
if(result == PARAM_NEXT_OPERATION) {
{ NULL, 0 }
};
- struct proto_name_pattern const *p;
const char *const *proto;
/* Pointer to libcurl's run-time version information */
built_in_protos = 0;
if(curlinfo->protocols) {
for(proto = curlinfo->protocols; *proto; proto++) {
+ struct proto_name_pattern const *p;
for(p = possibly_built_in; p->proto_name; p++) {
if(curl_strequal(*proto, p->proto_name)) {
built_in_protos |= p->proto_pattern;
void helpf(FILE *errors, const char *fmt, ...)
{
- va_list ap;
if(fmt) {
+ va_list ap;
va_start(ap, fmt);
fputs("curl: ", errors); /* prefix it */
vfprintf(errors, fmt, ap);
ParameterError file2string(char **bufp, FILE *file)
{
- char buffer[256];
char *ptr;
char *string = NULL;
- size_t stringlen = 0;
- size_t buflen;
if(file) {
+ char buffer[256];
+ size_t stringlen = 0;
while(fgets(buffer, sizeof(buffer), file)) {
+ size_t buflen;
ptr = strchr(buffer, '\r');
if(ptr)
*ptr = '\0';
{
char *newbuf;
char *buffer = NULL;
- size_t alloc = 512;
size_t nused = 0;
- size_t nread;
if(file) {
+ size_t nread;
+ size_t alloc = 512;
do {
if(!buffer || (alloc == nused)) {
/* size_t overflow detection for huge files */
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
{
- int res;
FILE *file;
char filebuffer[512];
bool usedarg = FALSE;
- char *home;
int rc = 0;
struct OperationConfig *operation = global->first;
/* NULL or no file name attempts to load .curlrc from the homedir! */
#ifndef __AMIGA__
+ char *home = homedir(); /* portable homedir finder */
filename = CURLRC; /* sensible default */
- home = homedir(); /* portable homedir finder */
if(home) {
if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
snprintf(filebuffer, sizeof(filebuffer),
char *option;
char *param;
int lineno = 0;
- bool alloced_param;
bool dashed_option;
while(NULL != (aline = my_get_line(file))) {
+ int res;
+ bool alloced_param = FALSE;
lineno++;
line = aline;
- alloced_param = FALSE;
/* line with # in the first non-blank column is a comment! */
while(*line && ISSPACE(*line))
while(*filename) {
if(*filename == '#' && ISDIGIT(filename[1])) {
- unsigned long i;
char *ptr = filename;
unsigned long num = strtoul(&filename[1], &filename, 10);
URLPattern *pat = NULL;
if(num < glob->size) {
+ unsigned long i;
num--; /* make it zero based */
/* find the correct glob entry */
for(i = 0; i<glob->size; i++) {
else {
/* this is meant as a variable to output */
char *end;
- char keepit;
- int i;
if('{' == ptr[1]) {
+ char keepit;
+ int i;
bool match = FALSE;
end = strchr(ptr, '}');
ptr += 2; /* pass the % and the { */
asize = (int)sizeof(a);
ptr = curl_easy_escape(NULL, (char *)a, asize);
printf("%s\n", ptr);
- if(ptr)
- curl_free(ptr);
+ curl_free(ptr);
/* deprecated API */
ptr = curl_escape((char *)a, asize);
printf("outlen == %d\n", outlen);
printf("unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
- if(raw)
- curl_free(raw);
+ curl_free(raw);
/* deprecated API */
raw = curl_unescape(ptr, (int)strlen(ptr));
printf("[old] outlen == %d\n", outlen);
printf("[old] unescape == original? %s\n",
memcmp(raw, a, outlen) ? "no" : "YES");
- if(raw)
- curl_free(raw);
- if(ptr)
- curl_free(ptr);
+ curl_free(raw);
+ curl_free(ptr);
/* weird input length */
ptr = curl_easy_escape(NULL, (char *)a, -1);
printf("unescape -1 length: %s %d\n", ptr, outlen);
test_cleanup:
- if(ptr)
- curl_free(ptr);
+ curl_free(ptr);
curl_global_cleanup();
return (int)res;
/* test function */
int test(char *URL)
{
- CURL *curl;
CURLcode res = CURLE_OK;
CURLSH *share;
int i;
still reuse connections since the pool is in the shared object! */
for(i = 0; i < 3; i++) {
- curl = curl_easy_init();
+ CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
return 0;
while(!feof(f)) {
- if(fscanf(f, "%d %s\n", &filetime, buf)) {
+ if(fscanf(f, "%d %199s\n", &filetime, buf)) {
urltime[num_handles] = filetime;
urlstring[num_handles] = strdup(buf);
num_handles++;
continue;
}
- if(fscanf(f, "blacklist_site %s\n", buf)) {
+ if(fscanf(f, "blacklist_site %199s\n", buf)) {
site_blacklist[blacklist_num_sites] = strdup(buf);
blacklist_num_sites++;
continue;
do {
msg = curl_multi_info_read(m, &msgs_left);
if(msg && msg->msg == CURLMSG_DONE) {
- int i, found = 0;
+ int i;
/* Find out which handle this message is about */
for(i = 0; i < num_handles; i++) {
- found = (msg->easy_handle == handles[i]);
+ int found = (msg->easy_handle == handles[i]);
if(found)
break;
}
struct curl_slist *headers;
struct Tdata *tdata = (struct Tdata*)ptr;
CURL *curl;
- int i = 0;
curl = curl_easy_init();
if(!curl) {
printf("PERFORM\n");
code = curl_easy_perform(curl);
if(code) {
+ int i = 0;
fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
tdata->url, i, (int)code);
}
int test(char *URL)
{
CURLcode code;
- CURL *curl;
- CURL *curl2;
int rc = 99;
code = curl_global_init(CURL_GLOBAL_ALL);
if(code == CURLE_OK) {
-
- curl = curl_easy_init();
+ CURL *curl = curl_easy_init();
if(curl) {
+ CURL *curl2;
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
"Host: ninja\r\n\r\n";
#endif
size_t iolen;
- char buf[1024];
res = curl_easy_send(curl, request, strlen(request), &iolen);
/* we assume that sending always work */
do {
+ char buf[1024];
/* busy-read like crazy */
res = curl_easy_recv(curl, buf, sizeof(buf), &iolen);
static int progress_callback(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow)
{
- FILE *moo;
static int prev_ultotal = -1;
static int prev_ulnow = -1;
(void)clientp; /* UNUSED */
if((prev_ultotal != (int)ultotal) ||
(prev_ulnow != (int)ulnow)) {
- moo = fopen(libtest_arg2, "ab");
+ FILE *moo = fopen(libtest_arg2, "ab");
if(moo) {
fprintf(moo, "Progress callback called with UL %d out of %d\n",
(int)ulnow, (int)ultotal);
CURLcode code;
struct Tdata *tdata = (struct Tdata*)ptr;
CURL *curl;
- int i = 0;
curl = curl_easy_init();
if(!curl) {
printf("PERFORM\n");
code = curl_easy_perform(curl);
if(code != CURLE_OK) {
+ int i = 0;
fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
tdata->url, i, (int)code);
}
struct libtest_trace_cfg *trace_cfg = userp;
const char *text;
struct timeval tv;
- struct tm *now;
char timebuf[20];
char *timestr;
time_t secs;
timestr = &timebuf[0];
if(trace_cfg->tracetime) {
+ struct tm *now;
tv = tutil_tvnow();
if(!known_offset) {
epoch_offset = time(NULL) - tv.tv_sec;
static int readline(char **buffer, size_t *bufsize, FILE *stream)
{
size_t offset = 0;
- size_t length;
char *newptr;
if(!*buffer) {
}
for(;;) {
+ size_t length;
int bytestoread = curlx_uztosi(*bufsize - offset);
if(!fgets(*buffer + offset, bytestoread, stream))
static char request[REQUEST_KEYWORD_SIZE];
static char doc[MAXDOCNAMELEN];
static char prot_str[5];
- char logbuf[256];
int prot_major, prot_minor;
- char *end;
- int error;
- end = strstr(line, END_OF_HEADERS);
+ char *end = strstr(line, END_OF_HEADERS);
logmsg("ProcessRequest() called with testno %ld and line [%s]",
req->testno, line);
&prot_major,
&prot_minor) == 5) {
char *ptr;
+ char logbuf[256];
if(!strcmp(prot_str, "HTTP")) {
req->protocol = RPROT_HTTP;
stream = fopen(filename, "rb");
if(!stream) {
- error = errno;
+ int error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", req->testno);
int rtp_channel = 0;
int rtp_size = 0;
int rtp_partno = -1;
- int i = 0;
char *rtp_scratch = NULL;
/* get the custom server control "commands" */
- error = getpart(&cmd, &cmdsize, "reply", "servercmd", stream);
+ int error = getpart(&cmd, &cmdsize, "reply", "servercmd", stream);
fclose(stream);
if(error) {
logmsg("getpart() failed with error: %d", error);
&rtp_partno, &rtp_channel, &rtp_size)) {
if(rtp_partno == req->partno) {
+ int i = 0;
logmsg("RTP: part %d channel %d size %d",
rtp_partno, rtp_channel, rtp_size);
size_t count;
const char *buffer;
char *ptr = NULL;
- FILE *stream;
char *cmd = NULL;
size_t cmdsize = 0;
FILE *dump;
static char weare[256];
- char partbuf[80]="data";
-
logmsg("Send response number %ld part %ld", req->testno, req->partno);
switch(req->rcmd) {
}
else {
char *filename = test2file(req->testno);
-
+ char partbuf[80]="data";
+ FILE *stream;
if(0 != req->partno)
snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno);
static ssize_t fullread(int filedes, void *buffer, size_t nbytes)
{
int error;
- ssize_t rc;
ssize_t nread = 0;
do {
- rc = read(filedes, (unsigned char *)buffer + nread, nbytes - nread);
+ ssize_t rc = read(filedes,
+ (unsigned char *)buffer + nread, nbytes - nread);
if(got_exit_signal) {
logmsg("signalled to die");
static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)
{
int error;
- ssize_t wc;
ssize_t nwrite = 0;
do {
- wc = write(filedes, (const unsigned char *)buffer + nwrite,
- nbytes - nwrite);
+ ssize_t wc = write(filedes, (const unsigned char *)buffer + nwrite,
+ nbytes - nwrite);
if(got_exit_signal) {
logmsg("signalled to die");
WSANETWORKEVENTS wsanetevents;
struct select_ws_data *data;
HANDLE handle, *handles;
- curl_socket_t sock;
- long networkevents;
WSAEVENT wsaevent;
int error, fds;
HANDLE waitevent = NULL;
/* allocate internal array for the internal data */
data = calloc(nfds, sizeof(struct select_ws_data));
if(data == NULL) {
+ CloseHandle(waitevent);
errno = ENOMEM;
return -1;
}
/* allocate internal array for the internal event handles */
handles = calloc(nfds, sizeof(HANDLE));
if(handles == NULL) {
+ CloseHandle(waitevent);
free(data);
errno = ENOMEM;
return -1;
/* loop over the handles in the input descriptor sets */
for(fds = 0; fds < nfds; fds++) {
- networkevents = 0;
+ long networkevents = 0;
handles[nfd] = 0;
if(FD_ISSET(fds, readfds))
/* loop over the internal handles returned in the descriptors */
for(idx = 0; idx < nfd; idx++) {
+ curl_socket_t sock = data[idx].fd;
handle = handles[idx];
- sock = data[idx].fd;
fds = curlx_sktosi(sock);
/* check if the current internal handle was triggered */
curl_socket_t sockfd = CURL_SOCKET_BAD;
int maxfd = -99;
ssize_t rc;
- ssize_t nread_socket;
- ssize_t bytes_written;
- ssize_t buffer_len;
int error = 0;
/* 'buffer' is this excessively large only to be able to support things like
if(FD_ISSET(fileno(stdin), &fds_read)) {
+ ssize_t buffer_len;
/* read from stdin, commands/data to be dealt with and possibly passed on
to the socket
}
else {
/* send away on the socket */
- bytes_written = swrite(sockfd, buffer, buffer_len);
+ ssize_t bytes_written = swrite(sockfd, buffer, buffer_len);
if(bytes_written != buffer_len) {
logmsg("Not all data was sent. Bytes to send: %zd sent: %zd",
buffer_len, bytes_written);
if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read)) ) {
-
- curl_socket_t newfd = CURL_SOCKET_BAD; /* newly accepted socket */
-
+ ssize_t nread_socket;
if(*mode == PASSIVE_LISTEN) {
/* there's no stream set up yet, this is an indication that there's a
client connecting. */
- newfd = accept(sockfd, NULL, NULL);
+ curl_socket_t newfd = accept(sockfd, NULL, NULL);
if(CURL_SOCKET_BAD == newfd) {
error = SOCKERRNO;
logmsg("accept(%d, NULL, NULL) failed with error: (%d) %s",
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
doc, &prot_major, &prot_minor) == 3) {
char *portp = NULL;
- unsigned long part = 0;
snprintf(logbuf, sizeof(logbuf),
"Received a CONNECT %s HTTP/%d.%d request",
if(doc[0] == '[') {
char *p = &doc[1];
+ unsigned long part = 0;
/* scan through the hexgroups and store the value of the last group
in the 'part' variable and use as test case number!! */
while(*p && (ISXDIGIT(*p) || (*p == ':') || (*p == '.'))) {
is no data waiting, or < 0 if it should be closed */
static int get_request(curl_socket_t sock, struct httprequest *req)
{
- int error;
int fail = 0;
char *reqbuf = req->reqbuf;
ssize_t got = 0;
fail = 1;
}
else if(got < 0) {
- error = SOCKERRNO;
+ int error = SOCKERRNO;
if(EAGAIN == error || EWOULDBLOCK == error) {
/* nothing to read at the moment */
return 0;
int main(int argc, char **argv)
{
- int rc;
char *part;
- size_t partlen, i;
+ size_t partlen;
if(argc< 3) {
printf("./testpart main sub\n");
}
else {
- rc = getpart(&part, &partlen, argv[1], argv[2], stdin);
+ int rc = getpart(&part, &partlen, argv[1], argv[2], stdin);
+ size_t i;
if(rc)
return rc;
for(i = 0; i < partlen; i++)
int first = 1, ecode;
struct formats *pf;
char *filename, *mode = NULL;
- int error;
- FILE *server;
#ifdef USE_WINSOCK
DWORD recvtimeout, recvtimeoutbak;
#endif
int toggle = 1;
/* Open request dump file. */
- server = fopen(REQUEST_DUMP, "ab");
+ FILE *server = fopen(REQUEST_DUMP, "ab");
if(!server) {
- error = errno;
+ int error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", REQUEST_DUMP);
return -1;
const char *filename, int mode)
{
char *ptr;
- long testno, partno;
- int error;
- char partbuf[80]="data";
logmsg("trying to get file: %s mode %x", filename, mode);
ptr = strrchr(filename, '/');
if(ptr) {
+ char partbuf[80]="data";
+ long partno;
+ long testno;
char *file;
ptr++; /* skip the slash */
if(file) {
FILE *stream = fopen(file, "rb");
if(!stream) {
- error = errno;
+ int error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", file);
logmsg("Couldn't open test file: %s", file);
}
else {
size_t count;
- error = getpart(&test->buffer, &count, "reply", partbuf, stream);
+ int error = getpart(&test->buffer, &count, "reply", partbuf, stream);
fclose(stream);
if(error) {
logmsg("getpart() failed with error: %d", error);
va_list ap;
char buffer[2048 + 1];
FILE *logfp;
- int error;
struct timeval tv;
time_t sec;
struct tm *now;
fclose(logfp);
}
else {
- error = errno;
+ int error = errno;
fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error));
fprintf(stderr, "Error opening file: %s\n", serverlogfile);
#endif
struct timeval initial_tv;
int pending_ms;
- int error;
#endif
int r = 0;
pending_ms = timeout_ms;
initial_tv = tvnow();
do {
+ int error;
#if defined(HAVE_POLL_FINE)
r = poll(NULL, 0, pending_ms);
#else
fail_unless(llist_destination.tail != NULL,
"llist_destination tail set to null after moving an element");
- fail_unless(llist_destination.tail == llist_destination.tail,
+ fail_unless(llist_destination.tail == llist_destination.head,
"llist_destination tail doesn't equal llist_destination head");
}
UNITTEST_STOP
UNITTEST_START
{
struct curltime now;
- time_t timeout;
unsigned int i;
const struct timetest run[] = {
data->progress.t_startop.tv_usec = 0;
for(i = 0; i < sizeof(run)/sizeof(run[0]); i++) {
+ time_t timeout;
NOW(run[i].now_s, run[i].now_us);
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
timeout = Curl_timeleft(data, &now, run[i].connecting);
UNITTEST_START
{
int testnum = sizeof(tests) / sizeof(struct testcase);
- int i, rc;
+ int i;
enum system machine;
#ifdef HAVE_FNMATCH
for(i = 0; i < testnum; i++) {
int result = tests[i].result;
- rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
+ int rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
if(result & (LINUX_DIFFER|MAC_DIFFER)) {
if((result & LINUX_DIFFER) && (machine == SYSTEM_LINUX))
result >>= LINUX_SHIFT;