logo       

bagder: curl/lib http_chunks.c, 1.27, 1.28 http_chunks.h, 1.13, 1.14 transf: msg#00013

web.curl.cvs

Subject: bagder: curl/lib http_chunks.c, 1.27, 1.28 http_chunks.h, 1.13, 1.14 transfer.c, 1.280, 1.281 url.c, 1.465, 1.466 urldata.h, 1.267, 1.268

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

Modified Files:
http_chunks.c http_chunks.h transfer.c url.c urldata.h
Log Message:
Adrian Schuur added trailer support in the chunked encoding stream. The
trailer is then sent to the normal header callback/stream.


Index: http_chunks.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/http_chunks.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- http_chunks.c 31 Mar 2005 07:02:03 -0000 1.27
+++ http_chunks.c 12 Jul 2005 18:15:34 -0000 1.28
@@ -153,10 +153,17 @@
if(*datap == '\n') {
/* we're now expecting data to come, unless size was zero! */
if(0 == ch->datasize) {
- ch->state = CHUNK_STOP; /* stop reading! */
- if(1 == length) {
- /* This was the final byte, return right now */
- return CHUNKE_STOP;
+ if (conn->bits.trailerHdrPresent!=TRUE) {
+ /* No Trailer: header found - revert to original Curl processing */
+ ch->state = CHUNK_STOP;
+ if (1 == length) {
+ /* This is the final byte, return right now */
+ return CHUNKE_STOP;
+ }
+ }
+ else {
+ ch->state = CHUNK_TRAILER; /* attempt to read trailers */
+ conn->trlPos=0;
}
}
else
@@ -250,6 +257,64 @@
return CHUNKE_BAD_CHUNK;
break;

+ case CHUNK_TRAILER:
+ /* conn->trailer is assumed to be freed in url.c on a
+ connection basis */
+ if (conn->trlPos >= conn->trlMax) {
+ char *ptr;
+ if(conn->trlMax) {
+ conn->trlMax *= 2;
+ ptr = (char*)realloc(conn->trailer,conn->trlMax);
+ }
+ else {
+ conn->trlMax=128;
+ ptr = (char*)malloc(conn->trlMax);
+ }
+ if(!ptr)
+ return CHUNKE_OUT_OF_MEMORY;
+ conn->trailer = ptr;
+ }
+ conn->trailer[conn->trlPos++]=*datap;
+
+ if(*datap == '\r')
+ ch->state = CHUNK_TRAILER_CR;
+ else {
+ datap++;
+ length--;
+ }
+ break;
+
+ case CHUNK_TRAILER_CR:
+ if(*datap == '\r') {
+ ch->state = CHUNK_TRAILER_POSTCR;
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
+ case CHUNK_TRAILER_POSTCR:
+ if (*datap == '\n') {
+ conn->trailer[conn->trlPos++]='\n';
+ conn->trailer[conn->trlPos]=0;
+ if (conn->trlPos==2) {
+ ch->state = CHUNK_STOP;
+ return CHUNKE_STOP;
+ }
+ else {
+ Curl_client_write(conn->data, CLIENTWRITE_HEADER,
+ conn->trailer, conn->trlPos);
+ }
+ ch->state = CHUNK_TRAILER;
+ conn->trlPos=0;
+ datap++;
+ length--;
+ }
+ else
+ return CHUNKE_BAD_CHUNK;
+ break;
+
case CHUNK_STOP:
/* If we arrive here, there is data left in the end of the buffer
even if there's no more chunks to read */

Index: http_chunks.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/http_chunks.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- http_chunks.h 31 Mar 2005 07:02:03 -0000 1.13
+++ http_chunks.h 12 Jul 2005 18:15:34 -0000 1.14
@@ -52,8 +52,8 @@
/* POSTCR should get a CR and nothing else, then move to POSTLF */
CHUNK_POSTCR,

- /* POSTLF should get a LF and nothing else, then move back to HEX as
- the CRLF combination marks the end of a chunk */
+ /* POSTLF should get a LF and nothing else, then move back to HEX as the
+ CRLF combination marks the end of a chunk */
CHUNK_POSTLF,

/* This is mainly used to really mark that we're out of the game.
@@ -62,7 +62,22 @@
buffer! */
CHUNK_STOP,

+ /* At this point optional trailer headers can be found, unless the next line
+ is CRLF */
+ CHUNK_TRAILER,
+
+ /* A trailer CR has been found - next state is CHUNK_TRAILER_POSTCR.
+ Next char must be a LF */
+ CHUNK_TRAILER_CR,
+
+ /* A trailer LF must be found now, otherwise CHUNKE_BAD_CHUNK will be
+ signalled If this is an empty trailer CHUNKE_STOP will be signalled.
+ Otherwise the trailer will be broadcasted via Curl_client_write() and the
+ next state will be CHUNK_TRAILER */
+ CHUNK_TRAILER_POSTCR,
+
CHUNK_LAST /* never use */
+
} ChunkyState;

typedef enum {
@@ -74,6 +89,7 @@
CHUNKE_WRITE_ERROR,
CHUNKE_STATE_ERROR,
CHUNKE_BAD_ENCODING,
+ CHUNKE_OUT_OF_MEMORY,
CHUNKE_LAST
} CHUNKcode;


Index: url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.465
retrieving revision 1.466
diff -u -d -r1.465 -r1.466
--- url.c 22 Jun 2005 22:24:10 -0000 1.465
+++ url.c 12 Jul 2005 18:15:34 -0000 1.466
@@ -1496,6 +1496,7 @@
Curl_safefree(conn->allocptr.host);
Curl_safefree(conn->allocptr.cookiehost);
Curl_safefree(conn->ip_addr_str);
+ Curl_safefree(conn->trailer);

/* possible left-overs from the async name resolvers */
#if defined(USE_ARES)

Index: urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.267
retrieving revision 1.268
diff -u -d -r1.267 -r1.268
--- urldata.h 25 Apr 2005 21:39:48 -0000 1.267
+++ urldata.h 12 Jul 2005 18:15:34 -0000 1.268
@@ -421,6 +421,10 @@
LPRT doesn't work we disable it for the forthcoming
requests */
bool netrc; /* name+password provided by netrc */
+
+ bool trailerHdrPresent; /* Set when Trailer: header found in HTTP response.
+ Required to determine whether to look for
trailers
+ in case of Transfer-Encoding: chunking */
};

struct hostname {
@@ -726,6 +730,12 @@
transfer */

enum { NORMAL, SOURCE3RD, TARGET3RD } xfertype;
+
+ /* These three are used for chunked-encoding trailer support */
+ char *trailer; /* allocated buffer to store trailer in */
+ int trlMax; /* allocated buffer size */
+ int trlPos; /* index of where to store data */
+
};

/* The end of connectdata. */

Index: transfer.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/transfer.c,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -d -r1.280 -r1.281
--- transfer.c 29 May 2005 22:30:48 -0000 1.280
+++ transfer.c 12 Jul 2005 18:15:34 -0000 1.281
@@ -833,6 +833,20 @@
/* init our chunky engine */
Curl_httpchunk_init(conn);
}
+
+ else if (checkprefix("Trailer:", k->p) ||
+ checkprefix("Trailers:", k->p)) {
+ /*
+ * This test helps Curl_httpchunk_read() to determine to look
+ * for well formed trailers after the zero chunksize record. In
+ * this case a CRLF is required after the zero chunksize record
+ * when no trailers are sent, or after the last trailer record.
+ *
+ * It seems both Trailer: and Trailers: occur in the wild.
+ */
+ conn->bits.trailerHdrPresent = TRUE;
+ }
+
else if (checkprefix("Content-Encoding:", k->p) &&
data->set.encoding) {
/*
@@ -1074,6 +1088,7 @@
* the name says read, this function both reads and writes away
* the data. The returned 'nread' holds the number of actual
* data it wrote to the client. */
+
CHUNKcode res =
Curl_httpchunk_read(conn, k->str, nread, &nread);


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



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

News | FAQ | advertise