1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 07:38:49 -05:00

Improve code readbility

... by removing the else branch after a return, break or continue.

Closes #1310
This commit is contained in:
Sylvestre Ledru 2017-03-10 14:28:37 +01:00 committed by Daniel Stenberg
parent db87bcfcf2
commit 66de563482
37 changed files with 405 additions and 496 deletions

View File

@ -810,8 +810,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
return CURLE_OK; return CURLE_OK;
} }
else infof(data, "Connection failed\n");
infof(data, "Connection failed\n");
} }
else if(rc & CURL_CSELECT_ERR) else if(rc & CURL_CSELECT_ERR)
(void)verifyconnect(conn->tempsock[i], &error); (void)verifyconnect(conn->tempsock[i], &error);

View File

@ -130,8 +130,7 @@ inflate_stream(struct connectdata *conn,
free(decomp); free(decomp);
if(inflateEnd(z) == Z_OK) if(inflateEnd(z) == Z_OK)
return exit_zlib(z, &k->zlib_init, result); return exit_zlib(z, &k->zlib_init, result);
else return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
} }
/* Done with these bytes, exit */ /* Done with these bytes, exit */

View File

@ -929,9 +929,8 @@ static char *get_line(char *buf, int len, FILE *input)
} }
return b; return b;
} }
else /* read a partial, discard the next piece that ends with newline */
/* read a partial, discard the next piece that ends with newline */ partial = TRUE;
partial = TRUE;
} }
else else
break; break;

View File

@ -469,7 +469,7 @@ Curl_addrinfo *Curl_str2addr(char *address, int port)
/* This is a dotted IP address 123.123.123.123-style */ /* This is a dotted IP address 123.123.123.123-style */
return Curl_ip2addr(AF_INET, &in, address, port); return Curl_ip2addr(AF_INET, &in, address, port);
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
else { {
struct in6_addr in6; struct in6_addr in6;
if(Curl_inet_pton(AF_INET6, address, &in6) > 0) if(Curl_inet_pton(AF_INET6, address, &in6) > 0)
/* This is a dotted IPv6 address ::1-style */ /* This is a dotted IPv6 address ::1-style */

View File

@ -145,8 +145,7 @@ static int setcharset(unsigned char **p, unsigned char *charset)
else if(c == ']') { else if(c == ']') {
if(something_found) if(something_found)
return SETCHARSET_OK; return SETCHARSET_OK;
else something_found = TRUE;
something_found = TRUE;
state = CURLFNM_SCHS_RIGHTBR; state = CURLFNM_SCHS_RIGHTBR;
charset[c] = 1; charset[c] = 1;
(*p)++; (*p)++;
@ -244,7 +243,7 @@ static int setcharset(unsigned char **p, unsigned char *charset)
if(c == ']') { if(c == ']') {
return SETCHARSET_OK; return SETCHARSET_OK;
} }
else if(c == '\\') { if(c == '\\') {
c = *(++(*p)); c = *(++(*p));
if(ISPRINT(c)) { if(ISPRINT(c)) {
charset[c] = 1; charset[c] = 1;
@ -345,8 +344,7 @@ static int loop(const unsigned char *pattern, const unsigned char *string)
else if(*p == '\0') { else if(*p == '\0') {
if(*s == '\0') if(*s == '\0')
return CURL_FNMATCH_MATCH; return CURL_FNMATCH_MATCH;
else return CURL_FNMATCH_NOMATCH;
return CURL_FNMATCH_NOMATCH;
} }
else if(*p == '\\') { else if(*p == '\\') {
state = CURLFNM_LOOP_BACKSLASH; state = CURLFNM_LOOP_BACKSLASH;

View File

@ -773,8 +773,7 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
curl_multi_cleanup(multi); curl_multi_cleanup(multi);
if(mcode == CURLM_OUT_OF_MEMORY) if(mcode == CURLM_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
else return CURLE_FAILED_INIT;
return CURLE_FAILED_INIT;
} }
sigpipe_ignore(data, &pipe_st); sigpipe_ignore(data, &pipe_st);

View File

@ -113,9 +113,7 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
testing_ptr = Curl_saferealloc(ns, alloc); testing_ptr = Curl_saferealloc(ns, alloc);
if(!testing_ptr) if(!testing_ptr)
return NULL; return NULL;
else { ns = testing_ptr;
ns = testing_ptr;
}
} }
result = Curl_convert_to_network(data, &in, 1); result = Curl_convert_to_network(data, &in, 1);

View File

@ -355,8 +355,7 @@ static CURLcode file_upload(struct connectdata *conn)
failf(data, "Can't get the size of %s", file->path); failf(data, "Can't get the size of %s", file->path);
return CURLE_WRITE_ERROR; return CURLE_WRITE_ERROR;
} }
else data->state.resume_from = (curl_off_t)file_stat.st_size;
data->state.resume_from = (curl_off_t)file_stat.st_size;
} }
while(!result) { while(!result) {
@ -519,8 +518,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
failf(data, "Can't get the size of file."); failf(data, "Can't get the size of file.");
return CURLE_READ_ERROR; return CURLE_READ_ERROR;
} }
else data->state.resume_from += (curl_off_t)statbuf.st_size;
data->state.resume_from += (curl_off_t)statbuf.st_size;
} }
if(data->state.resume_from <= expected_size) if(data->state.resume_from <= expected_size)

View File

@ -630,70 +630,68 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
return_value = CURL_FORMADD_INCOMPLETE; return_value = CURL_FORMADD_INCOMPLETE;
break; break;
} }
else { if(((form->flags & HTTPPOST_FILENAME) ||
if(((form->flags & HTTPPOST_FILENAME) || (form->flags & HTTPPOST_BUFFER)) &&
(form->flags & HTTPPOST_BUFFER)) && !form->contenttype) {
!form->contenttype) { char *f = form->flags & HTTPPOST_BUFFER?
char *f = form->flags & HTTPPOST_BUFFER? form->showfilename : form->value;
form->showfilename : form->value;
/* our contenttype is missing */ /* our contenttype is missing */
form->contenttype = strdup(ContentTypeForFilename(f, prevtype)); form->contenttype = strdup(ContentTypeForFilename(f, prevtype));
if(!form->contenttype) { if(!form->contenttype) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->contenttype_alloc = TRUE;
}
if(!(form->flags & HTTPPOST_PTRNAME) &&
(form == first_form) ) {
/* Note that there's small risk that form->name is NULL here if the
app passed in a bad combo, so we better check for that first. */
if(form->name) {
/* copy name (without strdup; possibly contains null characters) */
form->name = Curl_memdup(form->name, form->namelength?
form->namelength:
strlen(form->name)+1);
}
if(!form->name) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->name_alloc = TRUE;
}
if(!(form->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE |
HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER |
HTTPPOST_CALLBACK)) && form->value) {
/* copy value (without strdup; possibly contains null characters) */
size_t clen = (size_t) form->contentslength;
if(!clen)
clen = strlen(form->value)+1;
form->value = Curl_memdup(form->value, clen);
if(!form->value) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->value_alloc = TRUE;
}
post = AddHttpPost(form->name, form->namelength,
form->value, form->contentslength,
form->buffer, form->bufferlength,
form->contenttype, form->flags,
form->contentheader, form->showfilename,
form->userp,
post, httppost,
last_post);
if(!post) {
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
break; break;
} }
form->contenttype_alloc = TRUE;
if(form->contenttype)
prevtype = form->contenttype;
} }
if(!(form->flags & HTTPPOST_PTRNAME) &&
(form == first_form) ) {
/* Note that there's small risk that form->name is NULL here if the
app passed in a bad combo, so we better check for that first. */
if(form->name) {
/* copy name (without strdup; possibly contains null characters) */
form->name = Curl_memdup(form->name, form->namelength?
form->namelength:
strlen(form->name)+1);
}
if(!form->name) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->name_alloc = TRUE;
}
if(!(form->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE |
HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER |
HTTPPOST_CALLBACK)) && form->value) {
/* copy value (without strdup; possibly contains null characters) */
size_t clen = (size_t) form->contentslength;
if(!clen)
clen = strlen(form->value)+1;
form->value = Curl_memdup(form->value, clen);
if(!form->value) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->value_alloc = TRUE;
}
post = AddHttpPost(form->name, form->namelength,
form->value, form->contentslength,
form->buffer, form->bufferlength,
form->contenttype, form->flags,
form->contentheader, form->showfilename,
form->userp,
post, httppost,
last_post);
if(!post) {
return_value = CURL_FORMADD_MEMORY;
break;
}
if(form->contenttype)
prevtype = form->contenttype;
} }
if(CURL_FORMADD_OK != return_value) { if(CURL_FORMADD_OK != return_value) {
/* On error, free allocated fields for nodes of the FormInfo linked /* On error, free allocated fields for nodes of the FormInfo linked
@ -1463,8 +1461,7 @@ static size_t readfromfile(struct Form *form, char *buffer,
if(callback) { if(callback) {
if(form->fread_func == ZERO_NULL) if(form->fread_func == ZERO_NULL)
return 0; return 0;
else nread = form->fread_func(buffer, 1, size, form->data->line);
nread = form->fread_func(buffer, 1, size, form->data->line);
} }
else { else {
if(!form->fp) { if(!form->fp) {

View File

@ -916,8 +916,7 @@ static int ftp_domore_getsock(struct connectdata *conn, curl_socket_t *socks,
return bits; return bits;
} }
else return Curl_pp_getsock(&conn->proto.ftpc.pp, socks, numsocks);
return Curl_pp_getsock(&conn->proto.ftpc.pp, socks, numsocks);
} }
/* This is called after the FTP_QUOTE state is passed. /* This is called after the FTP_QUOTE state is passed.
@ -1209,7 +1208,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
possibly_non_local = FALSE; /* don't try this again */ possibly_non_local = FALSE; /* don't try this again */
continue; continue;
} }
else if(error != EADDRINUSE && error != EACCES) { if(error != EADDRINUSE && error != EACCES) {
failf(data, "bind(port=%hu) failed: %s", port, failf(data, "bind(port=%hu) failed: %s", port,
Curl_strerror(conn, error) ); Curl_strerror(conn, error) );
Curl_closesocket(conn, portsock); Curl_closesocket(conn, portsock);
@ -1307,7 +1306,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
} }
break; break;
} }
else if(PORT == fcmd) { if(PORT == fcmd) {
char *source = myhost; char *source = myhost;
char *dest = tmp; char *dest = tmp;
@ -1674,31 +1673,29 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
} }
if(seekerr != CURL_SEEKFUNC_OK) { if(seekerr != CURL_SEEKFUNC_OK) {
curl_off_t passed=0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) { if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream"); failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST; return CURLE_FTP_COULDNT_USE_REST;
} }
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */ /* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
else { do {
curl_off_t passed=0; size_t readthisamountnow =
do { (data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
size_t readthisamountnow = BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread = size_t actuallyread =
data->state.fread_func(data->state.buffer, 1, readthisamountnow, data->state.fread_func(data->state.buffer, 1, readthisamountnow,
data->state.in); data->state.in);
passed += actuallyread; passed += actuallyread;
if((actuallyread == 0) || (actuallyread > readthisamountnow)) { if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
/* this checks for greater-than only to make sure that the /* this checks for greater-than only to make sure that the
CURL_READFUNC_ABORT return code still aborts */ CURL_READFUNC_ABORT return code still aborts */
failf(data, "Failed to read data"); failf(data, "Failed to read data");
return CURLE_FTP_COULDNT_USE_REST; return CURLE_FTP_COULDNT_USE_REST;
} }
} while(passed < data->state.resume_from); } while(passed < data->state.resume_from);
}
} }
/* now, decrease the size of the read */ /* now, decrease the size of the read */
if(data->state.infilesize>0) { if(data->state.infilesize>0) {
@ -2412,8 +2409,7 @@ static CURLcode ftp_state_stor_resp(struct connectdata *conn,
return CURLE_OK; return CURLE_OK;
} }
else return InitiateTransfer(conn);
return InitiateTransfer(conn);
} }
/* for LIST and RETR responses */ /* for LIST and RETR responses */
@ -2948,12 +2944,10 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
state(conn, FTP_NAMEFMT); state(conn, FTP_NAMEFMT);
break; break;
} }
else { /* Nothing special for the target server. */
/* Nothing special for the target server. */ /* remember target server OS */
/* remember target server OS */ Curl_safefree(ftpc->server_os);
Curl_safefree(ftpc->server_os); ftpc->server_os = os;
ftpc->server_os = os;
}
} }
else { else {
/* Cannot identify server OS. Continue anyway and cross fingers. */ /* Cannot identify server OS. Continue anyway and cross fingers. */
@ -3800,12 +3794,10 @@ static CURLcode init_wc_data(struct connectdata *conn)
result = ftp_parse_url_path(conn); result = ftp_parse_url_path(conn);
return result; return result;
} }
else { wildcard->pattern = strdup(last_slash);
wildcard->pattern = strdup(last_slash); if(!wildcard->pattern)
if(!wildcard->pattern) return CURLE_OUT_OF_MEMORY;
return CURLE_OUT_OF_MEMORY; last_slash[0] = '\0'; /* cut file from path */
last_slash[0] = '\0'; /* cut file from path */
}
} }
else { /* there is only 'wildcard pattern' or nothing */ else { /* there is only 'wildcard pattern' or nothing */
if(path[0]) { if(path[0]) {
@ -3890,8 +3882,7 @@ static CURLcode wc_statemach(struct connectdata *conn)
if(wildcard->state == CURLWC_CLEAN) if(wildcard->state == CURLWC_CLEAN)
/* only listing! */ /* only listing! */
break; break;
else wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING;
wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING;
break; break;
case CURLWC_MATCHING: { case CURLWC_MATCHING: {
@ -3909,7 +3900,7 @@ static CURLcode wc_statemach(struct connectdata *conn)
wildcard->state = CURLWC_CLEAN; wildcard->state = CURLWC_CLEAN;
return wc_statemach(conn); return wc_statemach(conn);
} }
else if(wildcard->filelist->size == 0) { if(wildcard->filelist->size == 0) {
/* no corresponding file */ /* no corresponding file */
wildcard->state = CURLWC_CLEAN; wildcard->state = CURLWC_CLEAN;
return CURLE_REMOTE_FILE_NOT_FOUND; return CURLE_REMOTE_FILE_NOT_FOUND;

View File

@ -433,10 +433,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
return bufflen; return bufflen;
} }
else { parser->state.UNIX.main = PL_UNIX_FILETYPE;
parser->state.UNIX.main = PL_UNIX_FILETYPE; finfo->b_used = 0;
finfo->b_used = 0;
}
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);

View File

@ -91,10 +91,8 @@ Curl_hash_init(struct curl_hash *h,
} }
return 0; /* fine */ return 0; /* fine */
} }
else { h->slots = 0;
h->slots = 0; return 1; /* failure */
return 1; /* failure */
}
} }
static struct curl_hash_element * static struct curl_hash_element *
@ -347,10 +345,8 @@ Curl_hash_next_element(struct curl_hash_iterator *iter)
struct curl_hash_element *he = iter->current_element->ptr; struct curl_hash_element *he = iter->current_element->ptr;
return he; return he;
} }
else { iter->current_element = NULL;
iter->current_element = NULL; return NULL;
return NULL;
}
} }
#if 0 /* useful function for debugging hashes and their contents */ #if 0 /* useful function for debugging hashes and their contents */

View File

@ -87,7 +87,7 @@ static int hostmatch(char *hostname, char *pattern)
if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0) if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
return CURL_HOST_NOMATCH; return CURL_HOST_NOMATCH;
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
else if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0) if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
return CURL_HOST_NOMATCH; return CURL_HOST_NOMATCH;
#endif #endif

View File

@ -1197,8 +1197,7 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
This needs FIXing. This needs FIXing.
*/ */
return CURLE_SEND_ERROR; return CURLE_SEND_ERROR;
else Curl_pipeline_leave_write(conn);
Curl_pipeline_leave_write(conn);
} }
} }
Curl_add_buffer_free(in); Curl_add_buffer_free(in);
@ -2156,32 +2155,31 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
} }
if(seekerr != CURL_SEEKFUNC_OK) { if(seekerr != CURL_SEEKFUNC_OK) {
curl_off_t passed=0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) { if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream"); failf(data, "Could not seek stream");
return CURLE_READ_ERROR; return CURLE_READ_ERROR;
} }
/* when seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */ /* when seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
else { do {
curl_off_t passed=0; size_t readthisamountnow =
do { (data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
size_t readthisamountnow = BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread = size_t actuallyread =
data->state.fread_func(data->state.buffer, 1, readthisamountnow, data->state.fread_func(data->state.buffer, 1, readthisamountnow,
data->state.in); data->state.in);
passed += actuallyread; passed += actuallyread;
if((actuallyread == 0) || (actuallyread > readthisamountnow)) { if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
/* this checks for greater-than only to make sure that the /* this checks for greater-than only to make sure that the
CURL_READFUNC_ABORT return code still aborts */ CURL_READFUNC_ABORT return code still aborts */
failf(data, "Could only read %" CURL_FORMAT_CURL_OFF_T failf(data, "Could only read %" CURL_FORMAT_CURL_OFF_T
" bytes from the input", passed); " bytes from the input", passed);
return CURLE_READ_ERROR; return CURLE_READ_ERROR;
} }
} while(passed < data->state.resume_from); } while(passed < data->state.resume_from);
}
} }
/* now, decrease the size of the read */ /* now, decrease the size of the read */
@ -2827,8 +2825,7 @@ checkrtspprefix(struct Curl_easy *data,
#endif /* CURL_DOES_CONVERSIONS */ #endif /* CURL_DOES_CONVERSIONS */
if(checkprefix("RTSP/", s)) if(checkprefix("RTSP/", s))
return TRUE; return TRUE;
else return FALSE;
return FALSE;
} }
#endif /* CURL_DISABLE_RTSP */ #endif /* CURL_DISABLE_RTSP */

View File

@ -293,10 +293,8 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
if(!Curl_conn_data_pending(conn, sockindex)) if(!Curl_conn_data_pending(conn, sockindex))
/* return so we'll be called again polling-style */ /* return so we'll be called again polling-style */
return CURLE_OK; return CURLE_OK;
else { DEBUGF(infof(data,
DEBUGF(infof(data, "Read response immediately from proxy CONNECT\n"));
"Read response immediately from proxy CONNECT\n"));
}
} }
/* at this point, the tunnel_connecting phase is over. */ /* at this point, the tunnel_connecting phase is over. */
@ -342,7 +340,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
} }
continue; continue;
} }
else if(result) { if(result) {
keepon = FALSE; keepon = FALSE;
break; break;
} }
@ -617,11 +615,9 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
if(conn->bits.proxy_connect_closed) if(conn->bits.proxy_connect_closed)
/* this is not an error, just part of the connection negotiation */ /* this is not an error, just part of the connection negotiation */
return CURLE_OK; return CURLE_OK;
else { failf(data, "Received HTTP code %d from proxy after CONNECT",
failf(data, "Received HTTP code %d from proxy after CONNECT", data->req.httpcode);
data->req.httpcode); return CURLE_RECV_ERROR;
return CURLE_RECV_ERROR;
}
} }
conn->tunnel_state[sockindex] = TUNNEL_COMPLETE; conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;

View File

@ -1096,8 +1096,7 @@ char *curl_maprintf(const char *format, ...)
info.buffer[info.len] = 0; /* we terminate this with a zero byte */ info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer; return info.buffer;
} }
else return strdup("");
return strdup("");
} }
char *curl_mvaprintf(const char *format, va_list ap_save) char *curl_mvaprintf(const char *format, va_list ap_save)
@ -1121,8 +1120,7 @@ char *curl_mvaprintf(const char *format, va_list ap_save)
info.buffer[info.len] = 0; /* we terminate this with a zero byte */ info.buffer[info.len] = 0; /* we terminate this with a zero byte */
return info.buffer; return info.buffer;
} }
else return strdup("");
return strdup("");
} }
static int storebuffer(int output, FILE *data) static int storebuffer(int output, FILE *data)

View File

@ -959,10 +959,8 @@ CURLMcode curl_multi_fdset(struct Curl_multi *multi,
if(s == CURL_SOCKET_BAD) if(s == CURL_SOCKET_BAD)
/* this socket is unused, break out of loop */ /* this socket is unused, break out of loop */
break; break;
else { if((int)s > this_max_fd)
if((int)s > this_max_fd) this_max_fd = (int)s;
this_max_fd = (int)s;
}
} }
data = data->next; /* check next handle */ data = data->next; /* check next handle */
@ -2277,8 +2275,7 @@ CURLMcode curl_multi_cleanup(struct Curl_multi *multi)
return CURLM_OK; return CURLM_OK;
} }
else return CURLM_BAD_HANDLE;
return CURLM_BAD_HANDLE;
} }
/* /*
@ -2313,8 +2310,7 @@ CURLMsg *curl_multi_info_read(struct Curl_multi *multi, int *msgs_in_queue)
return &msg->extmsg; return &msg->extmsg;
} }
else return NULL;
return NULL;
} }
/* /*
@ -2575,7 +2571,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
/* or should we fall-through and do the timer-based stuff? */ /* or should we fall-through and do the timer-based stuff? */
return result; return result;
} }
else if(s != CURL_SOCKET_TIMEOUT) { if(s != CURL_SOCKET_TIMEOUT) {
struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s); struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);

View File

@ -58,8 +58,7 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */
flags = sfcntl(sockfd, F_GETFL, 0); flags = sfcntl(sockfd, F_GETFL, 0);
if(nonblock) if(nonblock)
return sfcntl(sockfd, F_SETFL, flags | O_NONBLOCK); return sfcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
else return sfcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
return sfcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
#elif defined(HAVE_IOCTL_FIONBIO) #elif defined(HAVE_IOCTL_FIONBIO)

View File

@ -267,8 +267,8 @@ long Curl_pgrsLimitWaitTime(curl_off_t cursize,
if(actual < minimum) if(actual < minimum)
/* this is a conversion on some systems (64bit time_t => 32bit long) */ /* this is a conversion on some systems (64bit time_t => 32bit long) */
return (long)(minimum - actual); return (long)(minimum - actual);
else
return 0; return 0;
} }
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size) void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
@ -454,7 +454,7 @@ int Curl_pgrsUpdate(struct connectdata *conn)
failf(data, "Callback aborted"); failf(data, "Callback aborted");
return result; return result;
} }
else if(data->set.fprogress) { if(data->set.fprogress) {
/* The older deprecated callback is set, call that */ /* The older deprecated callback is set, call that */
result= data->set.fprogress(data->set.progress_client, result= data->set.fprogress(data->set.progress_client,
(double)data->progress.size_dl, (double)data->progress.size_dl,

View File

@ -216,7 +216,7 @@ static CURLcode rtsp_done(struct connectdata *conn,
CSeq_sent, CSeq_recv); CSeq_sent, CSeq_recv);
return CURLE_RTSP_CSEQ_ERROR; return CURLE_RTSP_CSEQ_ERROR;
} }
else if(data->set.rtspreq == RTSPREQ_RECEIVE && if(data->set.rtspreq == RTSPREQ_RECEIVE &&
(conn->proto.rtspc.rtp_channel == -1)) { (conn->proto.rtspc.rtp_channel == -1)) {
infof(data, "Got an RTP Receive with a CSeq of %ld\n", CSeq_recv); infof(data, "Got an RTP Receive with a CSeq of %ld\n", CSeq_recv);
/* TODO CPC: Server -> Client logic here */ /* TODO CPC: Server -> Client logic here */
@ -648,31 +648,29 @@ static CURLcode rtsp_rtp_readwrite(struct Curl_easy *data,
*readmore = TRUE; *readmore = TRUE;
break; break;
} }
else { /* We have the full RTP interleaved packet
/* We have the full RTP interleaved packet * Write out the header including the leading '$' */
* Write out the header including the leading '$' */ DEBUGF(infof(data, "RTP write channel %d rtp_length %d\n",
DEBUGF(infof(data, "RTP write channel %d rtp_length %d\n", rtspc->rtp_channel, rtp_length));
rtspc->rtp_channel, rtp_length)); result = rtp_client_write(conn, &rtp[0], rtp_length + 4);
result = rtp_client_write(conn, &rtp[0], rtp_length + 4); if(result) {
if(result) { failf(data, "Got an error writing an RTP packet");
failf(data, "Got an error writing an RTP packet"); *readmore = FALSE;
*readmore = FALSE; Curl_safefree(rtspc->rtp_buf);
Curl_safefree(rtspc->rtp_buf); rtspc->rtp_buf = NULL;
rtspc->rtp_buf = NULL; rtspc->rtp_bufsize = 0;
rtspc->rtp_bufsize = 0; return result;
return result; }
}
/* Move forward in the buffer */ /* Move forward in the buffer */
rtp_dataleft -= rtp_length + 4; rtp_dataleft -= rtp_length + 4;
rtp += rtp_length + 4; rtp += rtp_length + 4;
if(data->set.rtspreq == RTSPREQ_RECEIVE) { if(data->set.rtspreq == RTSPREQ_RECEIVE) {
/* If we are in a passive receive, give control back /* If we are in a passive receive, give control back
* to the app as often as we can. * to the app as often as we can.
*/ */
k->keepon &= ~KEEP_RECV; k->keepon &= ~KEEP_RECV;
}
} }
} }
else { else {
@ -703,20 +701,18 @@ static CURLcode rtsp_rtp_readwrite(struct Curl_easy *data,
*nread = 0; *nread = 0;
return CURLE_OK; return CURLE_OK;
} }
else { /* Fix up k->str to point just after the last RTP packet */
/* Fix up k->str to point just after the last RTP packet */ k->str += *nread - rtp_dataleft;
k->str += *nread - rtp_dataleft;
/* either all of the data has been read or... /* either all of the data has been read or...
* rtp now points at the next byte to parse * rtp now points at the next byte to parse
*/ */
if(rtp_dataleft > 0) if(rtp_dataleft > 0)
DEBUGASSERT(k->str[0] == rtp[0]); DEBUGASSERT(k->str[0] == rtp[0]);
DEBUGASSERT(rtp_dataleft <= *nread); /* sanity check */ DEBUGASSERT(rtp_dataleft <= *nread); /* sanity check */
*nread = rtp_dataleft; *nread = rtp_dataleft;
}
/* If we get here, we have finished with the leftover/merge buffer */ /* If we get here, we have finished with the leftover/merge buffer */
Curl_safefree(rtspc->rtp_buf); Curl_safefree(rtspc->rtp_buf);

View File

@ -565,10 +565,9 @@ CURLcode Curl_client_chop_write(struct connectdata *conn,
failf(data, "Write callback asked for PAUSE when not supported!"); failf(data, "Write callback asked for PAUSE when not supported!");
return CURLE_WRITE_ERROR; return CURLE_WRITE_ERROR;
} }
else return pausewrite(data, type, ptr, len);
return pausewrite(data, type, ptr, len);
} }
else if(wrote != chunklen) { if(wrote != chunklen) {
failf(data, "Failed writing body (%zu != %zu)", wrote, chunklen); failf(data, "Failed writing body (%zu != %zu)", wrote, chunklen);
return CURLE_WRITE_ERROR; return CURLE_WRITE_ERROR;
} }
@ -652,8 +651,7 @@ CURLcode Curl_read_plain(curl_socket_t sockfd,
#endif #endif
if(return_error) if(return_error)
return CURLE_AGAIN; return CURLE_AGAIN;
else return CURLE_RECV_ERROR;
return CURLE_RECV_ERROR;
} }
/* we only return number of bytes read when we return OK */ /* we only return number of bytes read when we return OK */

View File

@ -73,7 +73,7 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
result = Curl_read_plain(sockfd, buf, buffersize, &nread); result = Curl_read_plain(sockfd, buf, buffersize, &nread);
if(CURLE_AGAIN == result) if(CURLE_AGAIN == result)
continue; continue;
else if(result) if(result)
break; break;
if(buffersize == nread) { if(buffersize == nread) {
@ -416,7 +416,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
failf(conn->data, "SOCKS5: no connection here"); failf(conn->data, "SOCKS5: no connection here");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
else if(0 == result) { if(0 == result) {
failf(conn->data, "SOCKS5: connection timeout"); failf(conn->data, "SOCKS5: connection timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
@ -457,7 +457,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
failf(conn->data, "SOCKS5 nothing to read"); failf(conn->data, "SOCKS5 nothing to read");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
else if(0 == result) { if(0 == result) {
failf(conn->data, "SOCKS5 read timeout"); failf(conn->data, "SOCKS5 read timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
@ -553,7 +553,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
"SOCKS5 GSSAPI per-message authentication is not supported."); "SOCKS5 GSSAPI per-message authentication is not supported.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
else if(socksreq[1] == 255) { if(socksreq[1] == 255) {
#endif #endif
if(!proxy_name || !*proxy_name) { if(!proxy_name || !*proxy_name) {
failf(data, failf(data,
@ -772,9 +772,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
} }
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
else { infof(data, "SOCKS5 request granted.\n");
infof(data, "SOCKS5 request granted.\n");
}
(void)curlx_nonblock(sock, TRUE); (void)curlx_nonblock(sock, TRUE);
return CURLE_OK; /* Proxy was successful! */ return CURLE_OK; /* Proxy was successful! */

View File

@ -55,10 +55,8 @@ CURLcode Curl_speedcheck(struct Curl_easy *data,
data->set.low_speed_time); data->set.low_speed_time);
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
else { /* wait complete low_speed_time */
/* wait complete low_speed_time */ Curl_expire_latest(data, nextcheck);
Curl_expire_latest(data, nextcheck);
}
} }
else { else {
/* we keep up the required speed all right */ /* we keep up the required speed all right */

View File

@ -201,10 +201,8 @@ struct Curl_tree *Curl_splaygetbest(struct timeval i,
return x; return x;
} }
else { *removed = NULL; /* no match */
*removed = NULL; /* no match */ return t; /* It wasn't there */
return t; /* It wasn't there */
}
} }

311
lib/ssh.c
View File

@ -688,14 +688,11 @@ static CURLcode ssh_check_fingerprint(struct connectdata *conn)
sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION;
return sshc->actualcode; return sshc->actualcode;
} }
else { infof(data, "MD5 checksum match!\n");
infof(data, "MD5 checksum match!\n"); /* as we already matched, we skip the check for known hosts */
/* as we already matched, we skip the check for known hosts */ return CURLE_OK;
return CURLE_OK;
}
} }
else return ssh_knownhost(conn);
return ssh_knownhost(conn);
} }
/* /*
@ -738,7 +735,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc) { if(rc) {
failf(data, "Failure establishing ssh session"); failf(data, "Failure establishing ssh session");
state(conn, SSH_SESSION_FREE); state(conn, SSH_SESSION_FREE);
sshc->actualcode = CURLE_FAILED_INIT; sshc->actualcode = CURLE_FAILED_INIT;
@ -782,16 +779,14 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_AUTH_DONE); state(conn, SSH_AUTH_DONE);
break; break;
} }
err = libssh2_session_last_errno(sshc->ssh_session);
if(err == LIBSSH2_ERROR_EAGAIN)
rc = LIBSSH2_ERROR_EAGAIN;
else { else {
err = libssh2_session_last_errno(sshc->ssh_session); state(conn, SSH_SESSION_FREE);
if(err == LIBSSH2_ERROR_EAGAIN) sshc->actualcode = libssh2_session_error_to_CURLE(err);
rc = LIBSSH2_ERROR_EAGAIN;
else {
state(conn, SSH_SESSION_FREE);
sshc->actualcode = libssh2_session_error_to_CURLE(err);
}
break;
} }
break;
} }
infof(data, "SSH authentication methods available: %s\n", infof(data, "SSH authentication methods available: %s\n",
sshc->authlist); sshc->authlist);
@ -942,7 +937,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc == 0) { if(rc == 0) {
sshc->authed = TRUE; sshc->authed = TRUE;
infof(data, "Initialized password authentication\n"); infof(data, "Initialized password authentication\n");
state(conn, SSH_AUTH_DONE); state(conn, SSH_AUTH_DONE);
@ -1081,7 +1076,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc == 0) { if(rc == 0) {
sshc->authed = TRUE; sshc->authed = TRUE;
infof(data, "Initialized keyboard interactive authentication\n"); infof(data, "Initialized keyboard interactive authentication\n");
} }
@ -1120,21 +1115,19 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/ */
sshc->sftp_session = libssh2_sftp_init(sshc->ssh_session); sshc->sftp_session = libssh2_sftp_init(sshc->ssh_session);
if(!sshc->sftp_session) { if(!sshc->sftp_session) {
char *err_msg;
if(libssh2_session_last_errno(sshc->ssh_session) == if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) { LIBSSH2_ERROR_EAGAIN) {
rc = LIBSSH2_ERROR_EAGAIN; rc = LIBSSH2_ERROR_EAGAIN;
break; break;
} }
else {
char *err_msg;
(void)libssh2_session_last_error(sshc->ssh_session, (void)libssh2_session_last_error(sshc->ssh_session,
&err_msg, NULL, 0); &err_msg, NULL, 0);
failf(data, "Failure initializing sftp session: %s", err_msg); failf(data, "Failure initializing sftp session: %s", err_msg);
state(conn, SSH_SESSION_FREE); state(conn, SSH_SESSION_FREE);
sshc->actualcode = CURLE_FAILED_INIT; sshc->actualcode = CURLE_FAILED_INIT;
break; break;
}
} }
state(conn, SSH_SFTP_REALPATH); state(conn, SSH_SFTP_REALPATH);
break; break;
@ -1151,7 +1144,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc > 0) { if(rc > 0) {
/* It seems that this string is not always NULL terminated */ /* It seems that this string is not always NULL terminated */
tempHome[rc] = '\0'; tempHome[rc] = '\0';
sshc->homedir = strdup(tempHome); sshc->homedir = strdup(tempHome);
@ -1265,7 +1258,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_SFTP_NEXT_QUOTE); state(conn, SSH_SFTP_NEXT_QUOTE);
break; break;
} }
else if(cmd) { if(cmd) {
/* /*
* the arguments following the command must be separated from the * the arguments following the command must be separated from the
* command with a space so we can check for it unconditionally * command with a space so we can check for it unconditionally
@ -1325,7 +1318,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_SFTP_QUOTE_STAT); state(conn, SSH_SFTP_QUOTE_STAT);
break; break;
} }
else if(strncasecompare(cmd, "ln ", 3) || if(strncasecompare(cmd, "ln ", 3) ||
strncasecompare(cmd, "symlink ", 8)) { strncasecompare(cmd, "symlink ", 8)) {
/* symbolic linking */ /* symbolic linking */
/* sshc->quote_path1 is the source */ /* sshc->quote_path1 is the source */
@ -1447,7 +1440,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { /* get those attributes */ if(rc != 0 && !sshc->acceptfail) { /* get those attributes */
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
Curl_safefree(sshc->quote_path2); Curl_safefree(sshc->quote_path2);
@ -1518,7 +1511,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
Curl_safefree(sshc->quote_path2); Curl_safefree(sshc->quote_path2);
@ -1541,7 +1534,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
Curl_safefree(sshc->quote_path2); Curl_safefree(sshc->quote_path2);
@ -1562,7 +1555,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
failf(data, "mkdir command failed: %s", sftp_libssh2_strerror(err)); failf(data, "mkdir command failed: %s", sftp_libssh2_strerror(err));
@ -1586,7 +1579,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
Curl_safefree(sshc->quote_path2); Curl_safefree(sshc->quote_path2);
@ -1605,7 +1598,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
failf(data, "rmdir command failed: %s", sftp_libssh2_strerror(err)); failf(data, "rmdir command failed: %s", sftp_libssh2_strerror(err));
@ -1623,7 +1616,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
failf(data, "rm command failed: %s", sftp_libssh2_strerror(err)); failf(data, "rm command failed: %s", sftp_libssh2_strerror(err));
@ -1646,7 +1639,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc != 0 && !sshc->acceptfail) { if(rc != 0 && !sshc->acceptfail) {
err = sftp_libssh2_last_error(sshc->sftp_session); err = sftp_libssh2_last_error(sshc->sftp_session);
Curl_safefree(sshc->quote_path1); Curl_safefree(sshc->quote_path1);
failf(data, "statvfs command failed: %s", sftp_libssh2_strerror(err)); failf(data, "statvfs command failed: %s", sftp_libssh2_strerror(err));
@ -1709,7 +1702,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc == 0) { if(rc == 0) {
data->info.filetime = (long)attrs.mtime; data->info.filetime = (long)attrs.mtime;
} }
@ -1747,7 +1740,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc) { if(rc) {
data->state.resume_from = 0; data->state.resume_from = 0;
} }
else { else {
@ -1782,48 +1775,47 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(LIBSSH2_ERROR_EAGAIN == rc) if(LIBSSH2_ERROR_EAGAIN == rc)
break; break;
else {
if(LIBSSH2_ERROR_SFTP_PROTOCOL == rc)
/* only when there was an SFTP protocol error can we extract
the sftp error! */
err = sftp_libssh2_last_error(sshc->sftp_session);
else
err = -1; /* not an sftp error at all */
if(sshc->secondCreateDirs) { if(LIBSSH2_ERROR_SFTP_PROTOCOL == rc)
state(conn, SSH_SFTP_CLOSE); /* only when there was an SFTP protocol error can we extract
sshc->actualcode = err>= LIBSSH2_FX_OK? the sftp error! */
sftp_libssh2_error_to_CURLE(err):CURLE_SSH; err = sftp_libssh2_last_error(sshc->sftp_session);
failf(data, "Creating the dir/file failed: %s", else
sftp_libssh2_strerror(err)); err = -1; /* not an sftp error at all */
break;
} if(sshc->secondCreateDirs) {
else if(((err == LIBSSH2_FX_NO_SUCH_FILE) ||
(err == LIBSSH2_FX_FAILURE) ||
(err == LIBSSH2_FX_NO_SUCH_PATH)) &&
(data->set.ftp_create_missing_dirs &&
(strlen(sftp_scp->path) > 1))) {
/* try to create the path remotely */
rc = 0; /* clear rc and continue */
sshc->secondCreateDirs = 1;
state(conn, SSH_SFTP_CREATE_DIRS_INIT);
break;
}
state(conn, SSH_SFTP_CLOSE); state(conn, SSH_SFTP_CLOSE);
sshc->actualcode = err>= LIBSSH2_FX_OK? sshc->actualcode = err>= LIBSSH2_FX_OK?
sftp_libssh2_error_to_CURLE(err):CURLE_SSH; sftp_libssh2_error_to_CURLE(err):CURLE_SSH;
if(!sshc->actualcode) { failf(data, "Creating the dir/file failed: %s",
/* Sometimes, for some reason libssh2_sftp_last_error() returns sftp_libssh2_strerror(err));
zero even though libssh2_sftp_open() failed previously! We need
to work around that! */
sshc->actualcode = CURLE_SSH;
err=-1;
}
failf(data, "Upload failed: %s (%d/%d)",
err>= LIBSSH2_FX_OK?sftp_libssh2_strerror(err):"ssh error",
err, rc);
break; break;
} }
if(((err == LIBSSH2_FX_NO_SUCH_FILE) ||
(err == LIBSSH2_FX_FAILURE) ||
(err == LIBSSH2_FX_NO_SUCH_PATH)) &&
(data->set.ftp_create_missing_dirs &&
(strlen(sftp_scp->path) > 1))) {
/* try to create the path remotely */
rc = 0; /* clear rc and continue */
sshc->secondCreateDirs = 1;
state(conn, SSH_SFTP_CREATE_DIRS_INIT);
break;
}
state(conn, SSH_SFTP_CLOSE);
sshc->actualcode = err>= LIBSSH2_FX_OK?
sftp_libssh2_error_to_CURLE(err):CURLE_SSH;
if(!sshc->actualcode) {
/* Sometimes, for some reason libssh2_sftp_last_error() returns
zero even though libssh2_sftp_open() failed previously! We need
to work around that! */
sshc->actualcode = CURLE_SSH;
err=-1;
}
failf(data, "Upload failed: %s (%d/%d)",
err>= LIBSSH2_FX_OK?sftp_libssh2_strerror(err):"ssh error",
err, rc);
break;
} }
/* If we have a restart point then we need to seek to the correct /* If we have a restart point then we need to seek to the correct
@ -1836,32 +1828,30 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
} }
if(seekerr != CURL_SEEKFUNC_OK) { if(seekerr != CURL_SEEKFUNC_OK) {
curl_off_t passed=0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) { if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream"); failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST; return CURLE_FTP_COULDNT_USE_REST;
} }
/* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */ /* seekerr == CURL_SEEKFUNC_CANTSEEK (can't seek to offset) */
else { do {
curl_off_t passed=0; size_t readthisamountnow =
do { (data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
size_t readthisamountnow = BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
(data->state.resume_from - passed > CURL_OFF_T_C(BUFSIZE)) ?
BUFSIZE : curlx_sotouz(data->state.resume_from - passed);
size_t actuallyread = size_t actuallyread =
data->state.fread_func(data->state.buffer, 1, data->state.fread_func(data->state.buffer, 1,
readthisamountnow, data->state.in); readthisamountnow, data->state.in);
passed += actuallyread; passed += actuallyread;
if((actuallyread == 0) || (actuallyread > readthisamountnow)) { if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
/* this checks for greater-than only to make sure that the /* this checks for greater-than only to make sure that the
CURL_READFUNC_ABORT return code still aborts */ CURL_READFUNC_ABORT return code still aborts */
failf(data, "Failed to read data"); failf(data, "Failed to read data");
return CURLE_FTP_COULDNT_USE_REST; return CURLE_FTP_COULDNT_USE_REST;
} }
} while(passed < data->state.resume_from); } while(passed < data->state.resume_from);
}
} }
/* now, decrease the size of the read */ /* now, decrease the size of the read */
@ -1926,9 +1916,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_SFTP_CREATE_DIRS_MKDIR); state(conn, SSH_SFTP_CREATE_DIRS_MKDIR);
break; break;
} }
else { state(conn, SSH_SFTP_UPLOAD_INIT);
state(conn, SSH_SFTP_UPLOAD_INIT);
}
break; break;
case SSH_SFTP_CREATE_DIRS_MKDIR: case SSH_SFTP_CREATE_DIRS_MKDIR:
@ -1956,9 +1944,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->actualcode = result?result:CURLE_SSH; sshc->actualcode = result?result:CURLE_SSH;
break; break;
} }
else { rc = 0; /* clear rc and continue */
rc = 0; /* clear rc and continue */
}
} }
state(conn, SSH_SFTP_CREATE_DIRS); state(conn, SSH_SFTP_CREATE_DIRS);
break; break;
@ -1985,15 +1971,13 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
rc = LIBSSH2_ERROR_EAGAIN; rc = LIBSSH2_ERROR_EAGAIN;
break; break;
} }
else { err = sftp_libssh2_last_error(sshc->sftp_session);
err = sftp_libssh2_last_error(sshc->sftp_session); failf(data, "Could not open directory for reading: %s",
failf(data, "Could not open directory for reading: %s", sftp_libssh2_strerror(err));
sftp_libssh2_strerror(err)); state(conn, SSH_SFTP_CLOSE);
state(conn, SSH_SFTP_CLOSE); result = sftp_libssh2_error_to_CURLE(err);
result = sftp_libssh2_error_to_CURLE(err); sshc->actualcode = result?result:CURLE_SSH;
sshc->actualcode = result?result:CURLE_SSH; break;
break;
}
} }
sshc->readdir_filename = malloc(PATH_MAX+1); sshc->readdir_filename = malloc(PATH_MAX+1);
if(!sshc->readdir_filename) { if(!sshc->readdir_filename) {
@ -2200,15 +2184,13 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
rc = LIBSSH2_ERROR_EAGAIN; rc = LIBSSH2_ERROR_EAGAIN;
break; break;
} }
else { err = sftp_libssh2_last_error(sshc->sftp_session);
err = sftp_libssh2_last_error(sshc->sftp_session); failf(data, "Could not open remote file for reading: %s",
failf(data, "Could not open remote file for reading: %s", sftp_libssh2_strerror(err));
sftp_libssh2_strerror(err)); state(conn, SSH_SFTP_CLOSE);
state(conn, SSH_SFTP_CLOSE); result = sftp_libssh2_error_to_CURLE(err);
result = sftp_libssh2_error_to_CURLE(err); sshc->actualcode = result?result:CURLE_SSH;
sshc->actualcode = result?result:CURLE_SSH; break;
break;
}
} }
state(conn, SSH_SFTP_DOWNLOAD_STAT); state(conn, SSH_SFTP_DOWNLOAD_STAT);
break; break;
@ -2223,7 +2205,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc || if(rc ||
!(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) || !(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) ||
(attrs.filesize == 0)) { (attrs.filesize == 0)) {
/* /*
@ -2321,18 +2303,17 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_STOP); state(conn, SSH_STOP);
break; break;
} }
else { Curl_setup_transfer(conn, FIRSTSOCKET, data->req.size,
Curl_setup_transfer(conn, FIRSTSOCKET, data->req.size, FALSE, NULL, -1, NULL);
FALSE, NULL, -1, NULL);
/* not set by Curl_setup_transfer to preserve keepon bits */ /* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd; conn->writesockfd = conn->sockfd;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh2 recv function will deal
with both accordingly */
conn->cselect_bits = CURL_CSELECT_IN;
/* we want to use the _receiving_ function even when the socket turns
out writableable as the underlying libssh2 recv function will deal
with both accordingly */
conn->cselect_bits = CURL_CSELECT_IN;
}
if(result) { if(result) {
/* this should never occur; the close state should be entered /* this should never occur; the close state should be entered
at the time the error occurs */ at the time the error occurs */
@ -2350,7 +2331,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to close libssh2 file\n"); infof(data, "Failed to close libssh2 file\n");
} }
sshc->sftp_handle = NULL; sshc->sftp_handle = NULL;
@ -2384,7 +2365,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to close libssh2 file\n"); infof(data, "Failed to close libssh2 file\n");
} }
sshc->sftp_handle = NULL; sshc->sftp_handle = NULL;
@ -2394,7 +2375,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to stop libssh2 sftp subsystem\n"); infof(data, "Failed to stop libssh2 sftp subsystem\n");
} }
sshc->sftp_session = NULL; sshc->sftp_session = NULL;
@ -2439,22 +2420,21 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
SCP_SEND(sshc->ssh_session, sftp_scp->path, data->set.new_file_perms, SCP_SEND(sshc->ssh_session, sftp_scp->path, data->set.new_file_perms,
data->state.infilesize); data->state.infilesize);
if(!sshc->ssh_channel) { if(!sshc->ssh_channel) {
int ssh_err;
char *err_msg;
if(libssh2_session_last_errno(sshc->ssh_session) == if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) { LIBSSH2_ERROR_EAGAIN) {
rc = LIBSSH2_ERROR_EAGAIN; rc = LIBSSH2_ERROR_EAGAIN;
break; break;
} }
else {
int ssh_err;
char *err_msg;
ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session, ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session,
&err_msg, NULL, 0)); &err_msg, NULL, 0));
failf(conn->data, "%s", err_msg); failf(conn->data, "%s", err_msg);
state(conn, SSH_SCP_CHANNEL_FREE); state(conn, SSH_SCP_CHANNEL_FREE);
sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err); sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err);
break; break;
}
} }
/* upload data */ /* upload data */
@ -2509,22 +2489,22 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
#endif #endif
if(!sshc->ssh_channel) { if(!sshc->ssh_channel) {
int ssh_err;
char *err_msg;
if(libssh2_session_last_errno(sshc->ssh_session) == if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) { LIBSSH2_ERROR_EAGAIN) {
rc = LIBSSH2_ERROR_EAGAIN; rc = LIBSSH2_ERROR_EAGAIN;
break; break;
} }
else {
int ssh_err;
char *err_msg;
ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session,
&err_msg, NULL, 0)); ssh_err = (int)(libssh2_session_last_error(sshc->ssh_session,
failf(conn->data, "%s", err_msg); &err_msg, NULL, 0));
state(conn, SSH_SCP_CHANNEL_FREE); failf(conn->data, "%s", err_msg);
sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err); state(conn, SSH_SCP_CHANNEL_FREE);
break; sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err);
} break;
} }
/* download data */ /* download data */
@ -2562,7 +2542,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc) { if(rc) {
infof(data, "Failed to send libssh2 channel EOF\n"); infof(data, "Failed to send libssh2 channel EOF\n");
} }
} }
@ -2575,7 +2555,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc) { if(rc) {
infof(data, "Failed to get channel EOF: %d\n", rc); infof(data, "Failed to get channel EOF: %d\n", rc);
} }
} }
@ -2588,7 +2568,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc) { if(rc) {
infof(data, "Channel failed to close: %d\n", rc); infof(data, "Channel failed to close: %d\n", rc);
} }
} }
@ -2601,7 +2581,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to free libssh2 scp subsystem\n"); infof(data, "Failed to free libssh2 scp subsystem\n");
} }
sshc->ssh_channel = NULL; sshc->ssh_channel = NULL;
@ -2623,7 +2603,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to free libssh2 scp subsystem\n"); infof(data, "Failed to free libssh2 scp subsystem\n");
} }
sshc->ssh_channel = NULL; sshc->ssh_channel = NULL;
@ -2634,7 +2614,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to disconnect libssh2 session\n"); infof(data, "Failed to disconnect libssh2 session\n");
} }
} }
@ -2659,7 +2639,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to disconnect from libssh2 agent\n"); infof(data, "Failed to disconnect from libssh2 agent\n");
} }
libssh2_agent_free(sshc->ssh_agent); libssh2_agent_free(sshc->ssh_agent);
@ -2677,7 +2657,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(rc == LIBSSH2_ERROR_EAGAIN) { if(rc == LIBSSH2_ERROR_EAGAIN) {
break; break;
} }
else if(rc < 0) { if(rc < 0) {
infof(data, "Failed to free libssh2 session\n"); infof(data, "Failed to free libssh2 session\n");
} }
sshc->ssh_session = NULL; sshc->ssh_session = NULL;
@ -2843,6 +2823,7 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
while((sshc->state != SSH_STOP) && !result) { while((sshc->state != SSH_STOP) && !result) {
bool block; bool block;
long left; long left;
struct timeval now = Curl_tvnow();
result = ssh_statemach_act(conn, &block); result = ssh_statemach_act(conn, &block);
if(result) if(result)
@ -2850,12 +2831,10 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
if(Curl_pgrsUpdate(conn)) if(Curl_pgrsUpdate(conn))
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
else {
struct timeval now = Curl_tvnow(); result = Curl_speedcheck(data, now);
result = Curl_speedcheck(data, now); if(result)
if(result) break;
break;
}
left = Curl_timeleft(data, NULL, duringconnect); left = Curl_timeleft(data, NULL, duringconnect);
if(left < 0) { if(left < 0) {

View File

@ -125,9 +125,9 @@ int Curl_safe_strcasecompare(const char *first, const char *second)
if(first && second) if(first && second)
/* both pointers point to something then compare them */ /* both pointers point to something then compare them */
return Curl_strcasecompare(first, second); return Curl_strcasecompare(first, second);
else
/* if both pointers are NULL then treat them as equal */ /* if both pointers are NULL then treat them as equal */
return (NULL == first && NULL == second); return (NULL == first && NULL == second);
} }
/* /*

View File

@ -899,11 +899,9 @@ static CURLcode check_telnet_options(struct connectdata *conn)
result = CURLE_UNKNOWN_TELNET_OPTION; result = CURLE_UNKNOWN_TELNET_OPTION;
break; break;
} }
else { failf(data, "Syntax error in telnet option: %s", head->data);
failf(data, "Syntax error in telnet option: %s", head->data); result = CURLE_TELNET_OPTION_SYNTAX;
result = CURLE_TELNET_OPTION_SYNTAX; break;
break;
}
} }
if(result) { if(result) {
@ -1594,7 +1592,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
if(result == CURLE_AGAIN) if(result == CURLE_AGAIN)
break; break;
/* returned not-zero, this an error */ /* returned not-zero, this an error */
else if(result) { if(result) {
keepon = FALSE; keepon = FALSE;
break; break;
} }

View File

@ -359,7 +359,7 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
failf(data, "invalid blocksize value in OACK packet"); failf(data, "invalid blocksize value in OACK packet");
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
} }
else if(blksize > TFTP_BLKSIZE_MAX) { if(blksize > TFTP_BLKSIZE_MAX) {
failf(data, "%s (%d)", "blksize is larger than max supported", failf(data, "%s (%d)", "blksize is larger than max supported",
TFTP_BLKSIZE_MAX); TFTP_BLKSIZE_MAX);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
@ -1189,7 +1189,7 @@ static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
state->state = TFTP_STATE_FIN; state->state = TFTP_STATE_FIN;
return 0; return 0;
} }
else if(current > state->rx_time+state->retry_time) { if(current > state->rx_time+state->retry_time) {
if(event) if(event)
*event = TFTP_EVENT_TIMEOUT; *event = TFTP_EVENT_TIMEOUT;
time(&state->rx_time); /* update even though we received nothing */ time(&state->rx_time); /* update even though we received nothing */
@ -1223,7 +1223,7 @@ static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
failf(data, "TFTP response timeout"); failf(data, "TFTP response timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
else if(event != TFTP_EVENT_NONE) { if(event != TFTP_EVENT_NONE) {
result = tftp_state_machine(state, event); result = tftp_state_machine(state, event);
if(result) if(result)
return result; return result;

View File

@ -139,8 +139,7 @@ double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
if(newer.tv_sec != older.tv_sec) if(newer.tv_sec != older.tv_sec)
return (double)(newer.tv_sec-older.tv_sec)+ return (double)(newer.tv_sec-older.tv_sec)+
(double)(newer.tv_usec-older.tv_usec)/1000000.0; (double)(newer.tv_usec-older.tv_usec)/1000000.0;
else return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
} }
/* return the number of seconds in the given input timeval struct */ /* return the number of seconds in the given input timeval struct */

View File

@ -117,7 +117,8 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
*nreadp = 0; *nreadp = 0;
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
} }
else if(nread == CURL_READFUNC_PAUSE) { if(nread == CURL_READFUNC_PAUSE) {
struct SingleRequest *k = &data->req;
if(conn->handler->flags & PROTOPT_NONETWORK) { if(conn->handler->flags & PROTOPT_NONETWORK) {
/* protocols that work without network cannot be paused. This is /* protocols that work without network cannot be paused. This is
@ -126,16 +127,15 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
failf(data, "Read callback asked for PAUSE when not supported!"); failf(data, "Read callback asked for PAUSE when not supported!");
return CURLE_READ_ERROR; return CURLE_READ_ERROR;
} }
else {
struct SingleRequest *k = &data->req; /* CURL_READFUNC_PAUSE pauses read callbacks that feed socket writes */
/* CURL_READFUNC_PAUSE pauses read callbacks that feed socket writes */ k->keepon |= KEEP_SEND_PAUSE; /* mark socket send as paused */
k->keepon |= KEEP_SEND_PAUSE; /* mark socket send as paused */ if(data->req.upload_chunky) {
if(data->req.upload_chunky) {
/* Back out the preallocation done above */ /* Back out the preallocation done above */
data->req.upload_fromhere -= (8 + 2); data->req.upload_fromhere -= (8 + 2);
}
*nreadp = 0;
} }
*nreadp = 0;
return CURLE_OK; /* nothing was read */ return CURLE_OK; /* nothing was read */
} }
else if((size_t)nread > buffersize) { else if((size_t)nread > buffersize) {
@ -642,7 +642,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
failf(data, "%s in chunked-encoding", Curl_chunked_strerror(res)); failf(data, "%s in chunked-encoding", Curl_chunked_strerror(res));
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
} }
else if(CHUNKE_STOP == res) { if(CHUNKE_STOP == res) {
size_t dataleft; size_t dataleft;
/* we're done reading chunks! */ /* we're done reading chunks! */
k->keepon &= ~KEEP_RECV; /* read no more */ k->keepon &= ~KEEP_RECV; /* read no more */
@ -918,7 +918,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
/* this is a paused transfer */ /* this is a paused transfer */
break; break;
} }
else if(nread<=0) { if(nread<=0) {
result = done_sending(conn, k); result = done_sending(conn, k);
if(result) if(result)
return result; return result;
@ -1192,7 +1192,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->size - k->bytecount); k->size - k->bytecount);
return CURLE_PARTIAL_FILE; return CURLE_PARTIAL_FILE;
} }
else if(!(data->set.opt_no_body) && if(!(data->set.opt_no_body) &&
k->chunk && k->chunk &&
(conn->chunk.state != CHUNK_STOP)) { (conn->chunk.state != CHUNK_STOP)) {
/* /*

View File

@ -3684,7 +3684,7 @@ ConnectionExists(struct Curl_easy *data,
check->connection_id)); check->connection_id));
continue; continue;
} }
else if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete) { if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete) {
foundPendingCandidate = TRUE; foundPendingCandidate = TRUE;
DEBUGF(infof(data, DEBUGF(infof(data,
"Connection #%ld has not started SSL connect, " "Connection #%ld has not started SSL connect, "

View File

@ -775,7 +775,7 @@ int Curl_ossl_check_cxn(struct connectdata *conn)
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK); (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK);
if(nread == 0) if(nread == 0)
return 0; /* connection has been closed */ return 0; /* connection has been closed */
else if(nread == 1) if(nread == 1)
return 1; /* connection still in place */ return 1; /* connection still in place */
else if(nread == -1) { else if(nread == -1) {
int err = SOCKERRNO; int err = SOCKERRNO;
@ -2085,12 +2085,10 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
ssl_capath ? ssl_capath : "none"); ssl_capath ? ssl_capath : "none");
return CURLE_SSL_CACERT_BADFILE; return CURLE_SSL_CACERT_BADFILE;
} }
else { /* Just continue with a warning if no strict certificate verification
/* Just continue with a warning if no strict certificate verification is required. */
is required. */ infof(data, "error setting certificate verify locations,"
infof(data, "error setting certificate verify locations," " continuing anyway:\n");
" continuing anyway:\n");
}
} }
else { else {
/* Everything is fine. */ /* Everything is fine. */
@ -2120,12 +2118,11 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
failf(data, "error loading CRL file: %s", ssl_crlfile); failf(data, "error loading CRL file: %s", ssl_crlfile);
return CURLE_SSL_CRL_BADFILE; return CURLE_SSL_CRL_BADFILE;
} }
else { /* Everything is fine. */
/* Everything is fine. */ infof(data, "successfully load CRL file:\n");
infof(data, "successfully load CRL file:\n"); X509_STORE_set_flags(SSL_CTX_get_cert_store(connssl->ctx),
X509_STORE_set_flags(SSL_CTX_get_cert_store(connssl->ctx), X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL);
X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL);
}
infof(data, " CRLfile: %s\n", ssl_crlfile); infof(data, " CRLfile: %s\n", ssl_crlfile);
} }
@ -2253,7 +2250,7 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
connssl->connecting_state = ssl_connect_2_reading; connssl->connecting_state = ssl_connect_2_reading;
return CURLE_OK; return CURLE_OK;
} }
else if(SSL_ERROR_WANT_WRITE == detail) { if(SSL_ERROR_WANT_WRITE == detail) {
connssl->connecting_state = ssl_connect_2_writing; connssl->connecting_state = ssl_connect_2_writing;
return CURLE_OK; return CURLE_OK;
} }
@ -3066,16 +3063,14 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO); failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} }
else if(0 == what) { if(0 == what) {
if(nonblocking) { if(nonblocking) {
*done = FALSE; *done = FALSE;
return CURLE_OK; return CURLE_OK;
} }
else { /* timeout */
/* timeout */ failf(data, "SSL connection timeout");
failf(data, "SSL connection timeout"); return CURLE_OPERATION_TIMEDOUT;
return CURLE_OPERATION_TIMEDOUT;
}
} }
/* socket is readable or writable */ /* socket is readable or writable */
} }
@ -3145,8 +3140,7 @@ bool Curl_ossl_data_pending(const struct connectdata *conn, int connindex)
(conn->proxy_ssl[connindex].handle && (conn->proxy_ssl[connindex].handle &&
0 != SSL_pending(conn->proxy_ssl[connindex].handle))) ? 0 != SSL_pending(conn->proxy_ssl[connindex].handle))) ?
TRUE : FALSE; TRUE : FALSE;
else return FALSE;
return FALSE;
} }
static ssize_t ossl_send(struct connectdata *conn, static ssize_t ossl_send(struct connectdata *conn,

View File

@ -515,7 +515,7 @@ int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks,
socks[0] = conn->sock[FIRSTSOCKET]; socks[0] = conn->sock[FIRSTSOCKET];
return GETSOCK_WRITESOCK(0); return GETSOCK_WRITESOCK(0);
} }
else if(connssl->connecting_state == ssl_connect_2_reading) { if(connssl->connecting_state == ssl_connect_2_reading) {
/* read mode */ /* read mode */
socks[0] = conn->sock[FIRSTSOCKET]; socks[0] = conn->sock[FIRSTSOCKET];
return GETSOCK_READSOCK(0); return GETSOCK_READSOCK(0);

View File

@ -128,8 +128,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
hdrcbdata->honor_cd_filename = FALSE; hdrcbdata->honor_cd_filename = FALSE;
break; break;
} }
else return failure;
return failure;
} }
} }

View File

@ -783,11 +783,10 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(!url) if(!url)
return PARAM_NO_MEM; return PARAM_NO_MEM;
else {
/* fill in the URL */ /* fill in the URL */
GetStr(&url->url, nextarg); GetStr(&url->url, nextarg);
url->flags |= GETOUT_URL; url->flags |= GETOUT_URL;
}
} }
} }
break; break;
@ -878,7 +877,7 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
&config->localportrange); &config->localportrange);
if(!rc) if(!rc)
return PARAM_BAD_USE; return PARAM_BAD_USE;
else if(rc == 1) if(rc == 1)
config->localportrange = 1; /* default number of ports to try */ config->localportrange = 1; /* default number of ports to try */
else { else {
config->localportrange -= config->localport; config->localportrange -= config->localport;
@ -1728,21 +1727,20 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(!url) if(!url)
return PARAM_NO_MEM; return PARAM_NO_MEM;
else {
/* fill in the outfile */ /* fill in the outfile */
if('o' == letter) { if('o' == letter) {
GetStr(&url->outfile, nextarg); GetStr(&url->outfile, nextarg);
url->flags &= ~GETOUT_USEREMOTE; /* switch off */ url->flags &= ~GETOUT_USEREMOTE; /* switch off */
}
else {
url->outfile = NULL; /* leave it */
if(toggle)
url->flags |= GETOUT_USEREMOTE; /* switch on */
else
url->flags &= ~GETOUT_USEREMOTE; /* switch off */
}
url->flags |= GETOUT_OUTFILE;
} }
else {
url->outfile = NULL; /* leave it */
if(toggle)
url->flags |= GETOUT_USEREMOTE; /* switch on */
else
url->flags &= ~GETOUT_USEREMOTE; /* switch off */
}
url->flags |= GETOUT_OUTFILE;
} }
break; break;
case 'P': case 'P':
@ -1867,14 +1865,13 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
if(!url) if(!url)
return PARAM_NO_MEM; return PARAM_NO_MEM;
url->flags |= GETOUT_UPLOAD; /* mark -T used */
if(!*nextarg)
url->flags |= GETOUT_NOUPLOAD;
else { else {
url->flags |= GETOUT_UPLOAD; /* mark -T used */ /* "-" equals stdin, but keep the string around for now */
if(!*nextarg) GetStr(&url->infile, nextarg);
url->flags |= GETOUT_NOUPLOAD;
else {
/* "-" equals stdin, but keep the string around for now */
GetStr(&url->infile, nextarg);
}
} }
} }
break; break;

View File

@ -207,18 +207,16 @@ static bool ttyecho(bool enable, int fd)
#endif #endif
return TRUE; /* disabled */ return TRUE; /* disabled */
} }
else { /* re-enable echo, assumes we disabled it before (and set the structs we
/* re-enable echo, assumes we disabled it before (and set the structs we now use to reset the terminal status) */
now use to reset the terminal status) */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
tcsetattr(fd, TCSAFLUSH, &withecho); tcsetattr(fd, TCSAFLUSH, &withecho);
#elif defined(HAVE_TERMIO_H) #elif defined(HAVE_TERMIO_H)
ioctl(fd, TCSETA, &withecho); ioctl(fd, TCSETA, &withecho);
#else #else
return FALSE; /* not enabled */ return FALSE; /* not enabled */
#endif #endif
return TRUE; /* enabled */ return TRUE; /* enabled */
}
} }
char *getpass_r(const char *prompt, /* prompt to display */ char *getpass_r(const char *prompt, /* prompt to display */

View File

@ -135,8 +135,7 @@ double tool_tvdiff_secs(struct timeval newer, struct timeval older)
if(newer.tv_sec != older.tv_sec) if(newer.tv_sec != older.tv_sec)
return (double)(newer.tv_sec-older.tv_sec)+ return (double)(newer.tv_sec-older.tv_sec)+
(double)(newer.tv_usec-older.tv_usec)/1000000.0; (double)(newer.tv_usec-older.tv_usec)/1000000.0;
else return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
} }
/* return the number of seconds in the given input timeval struct */ /* return the number of seconds in the given input timeval struct */