logo       

bagder: curl/lib ftp.c, 1.325, 1.326 http.c, 1.272, 1.273 http.h, 1.27, 1.2: msg#00003

web.curl.cvs

Subject: bagder: curl/lib ftp.c, 1.325, 1.326 http.c, 1.272, 1.273 http.h, 1.27, 1.28

Update of /cvsroot/curl/curl/lib
In directory labb:/tmp/cvs-serv10325/lib

Modified Files:
ftp.c http.c http.h
Log Message:
Andrew Bushnell provided enough info for me to tell that we badly needed to
fix the CONNECT authentication code with multi-pass auth methods (such as
NTLM) as it didn't previously properly ignore response-bodies - in fact it
stopped reading after all response headers had been received. This could
lead to libcurl sending the next request and reading the body from the first
request as response to the second request. (I also renamed the function,
which wasn't strictly necessary but...)

The best fix would to once and for all make the CONNECT code use the
ordinary request sending/receiving code, treating it as any ordinary request
instead of the special-purpose function we have now. It should make it
better for multi-interface too. And possibly lead to less code...

Added test case 265 for this. It doesn't work as a _really_ good test case
since the test proxy is too stupid, but the test case helps when running the
debugger to verify.


Index: http.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/http.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- http.h 9 Feb 2005 13:06:40 -0000 1.27
+++ http.h 3 Jul 2005 22:25:15 -0000 1.28
@@ -29,9 +29,9 @@
const char *content); /* content string to find */

/* ftp can use this as well */
-CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
- int tunnelsocket,
- char *hostname, int remote_port);
+CURLcode Curl_proxyCONNECT(struct connectdata *conn,
+ int tunnelsocket,
+ char *hostname, int remote_port);

/* protocol-specific functions set up to be called by the main engine */
CURLcode Curl_http(struct connectdata *conn, bool *done);

Index: ftp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/ftp.c,v
retrieving revision 1.325
retrieving revision 1.326
diff -u -d -r1.325 -r1.326
--- ftp.c 24 May 2005 09:39:56 -0000 1.325
+++ ftp.c 3 Jul 2005 22:25:15 -0000 1.326
@@ -1670,8 +1670,7 @@

/* BLOCKING */
/* We want "seamless" FTP operations through HTTP proxy tunnel */
- result = Curl_ConnectHTTPProxyTunnel(conn, SECONDARYSOCKET,
- newhost, newport);
+ result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, newhost, newport);
if(CURLE_OK != result)
return result;
}
@@ -2745,8 +2744,8 @@
if (conn->bits.tunnel_proxy) {
/* BLOCKING */
/* We want "seamless" FTP operations through HTTP proxy tunnel */
- result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET,
- conn->host.name, conn->remote_port);
+ result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
+ conn->host.name, conn->remote_port);
if(CURLE_OK != result)
return result;
}

Index: http.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/http.c,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -d -r1.272 -r1.273
--- http.c 11 May 2005 09:52:59 -0000 1.272
+++ http.c 3 Jul 2005 22:25:15 -0000 1.273
@@ -96,6 +96,7 @@
#include "memory.h"
#include "select.h"
#include "parsedate.h" /* for the week day and month names */
+#include "strtoofft.h"

#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -1053,10 +1054,9 @@
}

/*
- * ConnectHTTPProxyTunnel() requires that we're connected to a HTTP
- * proxy. This function will issue the necessary commands to get a seamless
- * tunnel through this proxy. After that, the socket can be used just as a
- * normal socket.
+ * Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
+ * function will issue the necessary commands to get a seamless tunnel through
+ * this proxy. After that, the socket can be used just as a normal socket.
*
* This badly needs to be rewritten. CONNECT should be sent and dealt with
* like any ordinary HTTP request, and not specially crafted like this. This
@@ -1064,10 +1064,10 @@
* much work to do at the moment.
*/

-CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
- int sockindex,
- char *hostname,
- int remote_port)
+CURLcode Curl_proxyCONNECT(struct connectdata *conn,
+ int sockindex,
+ char *hostname,
+ int remote_port)
{
int subversion=0;
struct SessionHandle *data=conn->data;
@@ -1076,7 +1076,7 @@
int res;
size_t nread; /* total size read */
int perline; /* count bytes per line */
- bool keepon=TRUE;
+ int keepon=TRUE;
ssize_t gotbytes;
char *ptr;
long timeout =
@@ -1085,6 +1085,7 @@
char *host_port;
curl_socket_t tunnelsocket = conn->sock[sockindex];
send_buffer *req_buffer;
+ curl_off_t cl=0;

#define SELECT_OK 0
#define SELECT_ERROR 1
@@ -1215,6 +1216,13 @@
int i;

nread += gotbytes;
+
+ if(keepon > TRUE) {
+ cl -= gotbytes;
+ if(!cl)
+ break;
+ }
+ else
for(i = 0; i < gotbytes; ptr++, i++) {
perline++; /* amount of bytes in this line so far */
if(*ptr=='\n') {
@@ -1242,7 +1250,21 @@
if(('\r' == line_start[0]) ||
('\n' == line_start[0])) {
/* end of response-headers from the proxy */
- keepon=FALSE;
+ if(cl && (407 == k->httpcode) && !data->state.authproblem) {
+ /* If we get a 407 response code with content length when we
+ * have no auth problem, we must ignore the whole
+ * response-body */
+ keepon = 2;
+ infof(data, "Ignore %" FORMAT_OFF_T
+ " bytes of response-body\n", cl);
+ cl -= (gotbytes - i);/* remove the remaining chunk of what
+ we already read */
+ if(cl<=0)
+ /* if the whole thing was already read, we are done! */
+ keepon=FALSE;
+ }
+ else
+ keepon = FALSE;
break; /* breaks out of for-loop, not switch() */
}

@@ -1257,6 +1279,10 @@
if(result)
return result;
}
+ else if(checkprefix("Content-Length:", line_start)) {
+ cl = curlx_strtoofft(line_start + strlen("Content-Length:"),
+ NULL, 10);
+ }
else if(2 == sscanf(line_start, "HTTP/1.%d %d",
&subversion,
&k->httpcode)) {
@@ -1323,9 +1349,9 @@
if(conn->bits.tunnel_proxy) {

/* either SSL over proxy, or explicitly asked for */
- result = Curl_ConnectHTTPProxyTunnel(conn, FIRSTSOCKET,
- conn->host.name,
- conn->remote_port);
+ result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
+ conn->host.name,
+ conn->remote_port);
if(CURLE_OK != result)
return result;
}

_______________________________________________
http://cool.haxx.se/mailman/listinfo/curl-commits



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise