1
/*****************************************************************************
1
/***************************************************************************
3
3
* Project ___| | | | _ \| |
4
4
* / __| | | | |_) | |
5
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al.
10
* In order to be useful for every potential user, curl and libcurl are
11
* dual-licensed under the MPL and the MIT/X-derivate licenses.
8
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
10
* This software is licensed as described in the file COPYING, which
11
* you should have received as part of this distribution. The terms
12
* are also available at http://curl.haxx.se/docs/copyright.html.
13
14
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
14
15
* copies of the Software, and permit persons to whom the Software is
15
* furnished to do so, under the terms of the MPL or the MIT/X-derivate
16
* licenses. You may pick one of these licenses.
16
* furnished to do so, under the terms of the COPYING file.
18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: http_chunks.c,v 1.9 2001/10/11 09:32:19 bumblebury Exp $
22
*****************************************************************************/
21
* $Id: http_chunks.c,v 1.23 2004/03/04 15:25:06 bagder Exp $
22
***************************************************************************/
25
#ifndef CURL_DISABLE_HTTP
25
26
/* -- WIN32 approved -- */
27
28
#include <string.h>
32
33
#include "urldata.h" /* it includes http_chunks.h */
33
34
#include "sendf.h" /* for the client write stuff */
36
#include "content_encoding.h" /* 08/29/02 jhrg */
35
39
#define _MPRINTF_REPLACE /* use our functions only */
36
40
#include <curl/mprintf.h>
38
42
/* The last #include file should be: */
40
44
#include "memdebug.h"
97
101
CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
106
CURLcode result=CURLE_OK;
103
107
struct Curl_chunker *ch = &conn->proto.http->chunk;
105
*wrote = 0; /* nothing yet */
108
struct Curl_transfer_keeper *k = &conn->keep;
110
size_t length = (size_t)datalen;
111
size_t *wrote = (size_t *)wrotep;
113
*wrote = 0; /* nothing's written yet */
108
116
switch(ch->state) {
171
179
piece = (ch->datasize >= length)?length:ch->datasize;
173
181
/* Write the data portion available */
174
result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap, piece);
182
/* Added content-encoding here; untested but almost identical to the
183
tested code in transfer.c. 08/29/02 jhrg */
185
switch (conn->keep.content_encoding) {
189
result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap,
195
/* update conn->keep.str to point to the chunk data. */
196
conn->keep.str = datap;
197
result = Curl_unencode_deflate_write(conn->data, &conn->keep, piece);
201
/* update conn->keep.str to point to the chunk data. */
202
conn->keep.str = datap;
203
result = Curl_unencode_gzip_write(conn->data, &conn->keep, piece);
209
"Unrecognized content encoding type. "
210
"libcurl understands `identity', `deflate' and `gzip' "
211
"content encodings.");
212
return CHUNKE_BAD_ENCODING;
176
217
return CHUNKE_WRITE_ERROR;
179
221
ch->datasize -= piece; /* decrease amount left to expect */