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

updated the chunked state-machine to deal with the trailing CRLF that comes

after the data part
This commit is contained in:
Daniel Stenberg 2001-03-13 22:16:42 +00:00
parent 048e654514
commit 195233ed5c
2 changed files with 40 additions and 6 deletions

View File

@ -181,17 +181,43 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
length -= piece; /* decrease space left in this round */ length -= piece; /* decrease space left in this round */
if(0 == ch->datasize) if(0 == ch->datasize)
/* end of data this round, go back to get a new size */ /* end of data this round, we now expect a trailing CRLF */
Curl_httpchunk_init(conn); ch->state = CHUNK_POSTCR;
break; break;
case CHUNK_POSTCR:
if(*datap == '\r') {
ch->state = CHUNK_POSTLF;
datap++;
length--;
}
else
return CHUNKE_BAD_CHUNK;
break;
case CHUNK_POSTLF:
if(*datap == '\n') {
/*
* The last one before we go back to hex state and start all
* over.
*/
Curl_httpchunk_init(conn);
datap++;
length--;
}
else
return CHUNKE_BAD_CHUNK;
break;
case CHUNK_STOP: case CHUNK_STOP:
/* If we arrive here, there is data left in the end of the buffer /* If we arrive here, there is data left in the end of the buffer
even if there's no more chunks to read */ even if there's no more chunks to read */
ch->dataleft = length; ch->dataleft = length;
return CHUNKE_STOP; /* return stop */ return CHUNKE_STOP; /* return stop */
#if 0
default: default:
return CHUNKE_STATE_ERROR; return CHUNKE_STATE_ERROR;
#endif
} }
} }
return CHUNKE_OK; return CHUNKE_OK;

View File

@ -30,7 +30,7 @@
#define MAXNUM_SIZE 16 #define MAXNUM_SIZE 16
typedef enum { typedef enum {
CHUNK_LOST, /* never use */ CHUNK_FIRST, /* never use */
/* In this we await and buffer all hexadecimal digits until we get one /* In this we await and buffer all hexadecimal digits until we get one
that isn't a hexadecimal digit. When done, we go POSTHEX */ that isn't a hexadecimal digit. When done, we go POSTHEX */
@ -45,10 +45,17 @@ typedef enum {
If the size given was zero, we set state to STOP and return. */ If the size given was zero, we set state to STOP and return. */
CHUNK_CR, CHUNK_CR,
/* We eat the amount of data specified. When done, we move back to the /* We eat the amount of data specified. When done, we move on to the
HEX state. */ POST_CR state. */
CHUNK_DATA, CHUNK_DATA,
/* 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 */
CHUNK_POSTLF,
/* This is mainly used to really mark that we're out of the game. /* This is mainly used to really mark that we're out of the game.
NOTE: that there's a 'dataleft' field in the struct that will tell how NOTE: that there's a 'dataleft' field in the struct that will tell how
many bytes that were not passed to the client in the end of the last many bytes that were not passed to the client in the end of the last
@ -63,6 +70,7 @@ typedef enum {
CHUNKE_OK = 0, CHUNKE_OK = 0,
CHUNKE_TOO_LONG_HEX = 1, CHUNKE_TOO_LONG_HEX = 1,
CHUNKE_ILLEGAL_HEX, CHUNKE_ILLEGAL_HEX,
CHUNKE_BAD_CHUNK,
CHUNKE_WRITE_ERROR, CHUNKE_WRITE_ERROR,
CHUNKE_STATE_ERROR, CHUNKE_STATE_ERROR,
CHUNKE_LAST CHUNKE_LAST