return CURLE_OK;
}
+/* initialize stuff to prepare for reading a fresh new response */
+static void ftp_respinit(struct connectdata *conn)
+{
+ struct FTP *ftp = conn->proto.ftp;
+ ftp->nread_resp = 0;
+ ftp->linestart_resp = conn->data->state.buffer;
+}
+
+/* macro to check for the last line in an FTP server response */
+#define lastline(line) (isdigit((int)line[0]) && isdigit((int)line[1]) && \
+ isdigit((int)line[2]) && (' ' == line[3]))
static CURLcode ftp_readresp(curl_socket_t sockfd,
struct connectdata *conn,
ssize_t gotbytes;
char *ptr;
struct SessionHandle *data = conn->data;
- char *line_start;
char *buf = data->state.buffer;
CURLcode result = CURLE_OK;
struct FTP *ftp = conn->proto.ftp;
if (ftpcode)
*ftpcode = 0; /* 0 for errors or not done */
- ptr=buf;
- line_start = buf;
+ ptr=buf + ftp->nread_resp;
- perline=0;
+ perline= ptr-ftp->linestart_resp; /* number of bytes in the current line,
+ so far */
keepon=TRUE;
while((ftp->nread_resp<BUFSIZE) && (keepon && !result)) {
/* output debug output if that is requested */
if(data->set.verbose)
- Curl_debug(data, CURLINFO_HEADER_IN, line_start, perline, conn);
+ Curl_debug(data, CURLINFO_HEADER_IN,
+ ftp->linestart_resp, perline, conn);
/*
* We pass all response-lines to the callback function registered
* headers.
*/
result = Curl_client_write(data, CLIENTWRITE_HEADER,
- line_start, perline);
+ ftp->linestart_resp, perline);
if(result)
return result;
-#define lastline(line) (isdigit((int)line[0]) && isdigit((int)line[1]) && \
- isdigit((int)line[2]) && (' ' == line[3]))
-
- if(perline>3 && lastline(line_start)) {
+ if(perline>3 && lastline(ftp->linestart_resp)) {
/* This is the end of the last line, copy the last line to the
start of the buffer and zero terminate, for old times sake (and
krb4)! */
char *meow;
int n;
- for(meow=line_start, n=0; meow<ptr; meow++, n++)
+ for(meow=ftp->linestart_resp, n=0; meow<ptr; meow++, n++)
buf[n] = *meow;
*meow=0; /* zero terminate */
keepon=FALSE;
- line_start = ptr+1; /* advance pointer */
+ ftp->linestart_resp = ptr+1; /* advance pointer */
i++; /* skip this before getting out */
*size = ftp->nread_resp; /* size of the response */
break;
}
perline=0; /* line starts over here */
- line_start = ptr+1;
+ ftp->linestart_resp = ptr+1;
}
}
if(!keepon && (i != gotbytes)) {
ftp->cache_size = gotbytes - i;
ftp->cache = (char *)malloc((int)ftp->cache_size);
if(ftp->cache)
- memcpy(ftp->cache, line_start, (int)ftp->cache_size);
+ memcpy(ftp->cache, ftp->linestart_resp, (int)ftp->cache_size);
else
return CURLE_OUT_OF_MEMORY; /**BANG**/
}
if(result)
return result;
-#define lastline(line) (isdigit((int)line[0]) && isdigit((int)line[1]) && \
- isdigit((int)line[2]) && (' ' == line[3]))
-
if(perline>3 && lastline(line_start)) {
/* This is the end of the last line, copy the last
* line to the start of the buffer and zero terminate,
if(conn->sec_complete)
/* BLOCKING */
Curl_sec_set_protection_level(conn);
-
+
/* We may need to issue a KAUTH here to have access to the files
* do it if user supplied a password
*/
/* When we connect, we start in the state where we await the 220
response */
+ ftp_respinit(conn); /* init the response reader stuff */
state(conn, FTP_WAIT220);
ftp->response = Curl_tvnow(); /* start response time-out now! */
bytes_written=0;
write_len = strlen(s);
+ ftp_respinit(conn);
+
res = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len,
&bytes_written);