char * ftp_readline(FILE *fp, SSL *ssl, size_t *lenp) { if (fp != NULL) return fparseln(fp, lenp, NULL, "\0\0\0", 0); #ifndef SMALL else if (ssl != NULL) return SSL_readline(ssl, lenp); #endif /* !SMALL */ else return NULL; }
int read_from_server(CHANNEL fs, short ssl, boolean accept_redirects) { ssize_t nr = 0; int total = 0; char reply_code; int first_line = TRUE; short body = FALSE; #ifdef OPENSSL int sslcode; #endif while (!body && !timeout_flag) { if (!ssl) nr = readline(fs.fs, big_recvline, MAXTOREAD, TRUE); #ifdef OPENSSL else { nr = SSL_readline(fs.ssl, big_recvline, MAXTOREAD, TRUE); if (nr < 0) { sslcode = ERR_get_error(); err_ret("SSL_readline error: %s", ERR_error_string(sslcode, NULL)); } } #endif #ifdef GNUTLS else { nr = TLS_readline(fs.tls, big_recvline, MAXTOREAD, TRUE); if (nr < 0) { err_ret("TLS_readline error: %s", gnutls_strerror(nr)); } } #endif /* * printf ("DEBUG: reading \"%s\"\n (%d chars)\n", * big_recvline, nr); */ /* * HTTP replies should be separated by CR-LF. Unfortunately, * some servers send only CR :-( */ body = ((nr == 2) || (nr == 1)); /* Empty line CR-LF seen */ if ((nr < 1) && (timeout_flag)) /* Probably a timeout */ return -1; if (nr < 1) /* SourceForge bug #109385 */ /* err_sys ("Error reading HTTP header"); */ return -1; /* * if ((int) big_recvline[nr-1] == 10) nr--; */ if (first_line) { reply_code = big_recvline[9]; /* 9 because "HTTP/1.x 200..." */ if (reply_code != '2' && !(reply_code == '3' && accept_redirects)) /* * Status codes beginning with 3 are not * errors See bug #850674 and RFC 2616, * section 10.3 */ err_quit("HTTP error \"%s\"", big_recvline); } total = total + nr; first_line = FALSE; }