~ubuntu-branches/ubuntu/hoary/curl/hoary-security

« back to all changes in this revision

Viewing changes to lib/http_chunks.c

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
 
1
/***************************************************************************
2
2
 *                                  _   _ ____  _     
3
3
 *  Project                     ___| | | |  _ \| |    
4
4
 *                             / __| | | | |_) | |    
5
5
 *                            | (__| |_| |  _ <| |___ 
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al.
9
 
 *
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.
12
 
 *
 
8
 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
 
9
 *
 
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
 * 
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.
17
17
 *
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
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
 ***************************************************************************/
23
23
#include "setup.h"
24
24
 
 
25
#ifndef CURL_DISABLE_HTTP
25
26
/* -- WIN32 approved -- */
26
27
#include <stdio.h>
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 */
34
35
 
 
36
#include "content_encoding.h"   /* 08/29/02 jhrg */
 
37
#include "http.h"
 
38
 
35
39
#define _MPRINTF_REPLACE /* use our functions only */
36
40
#include <curl/mprintf.h>
37
41
 
38
42
/* The last #include file should be: */
39
 
#ifdef MALLOCDEBUG
 
43
#ifdef CURLDEBUG
40
44
#include "memdebug.h"
41
45
#endif
42
46
 
96
100
 */
97
101
CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
98
102
                              char *datap,
99
 
                              size_t length,
100
 
                              size_t *wrote)
 
103
                              ssize_t datalen,
 
104
                              ssize_t *wrotep)
101
105
{
102
 
  CURLcode result;
 
106
  CURLcode result=CURLE_OK;
103
107
  struct Curl_chunker *ch = &conn->proto.http->chunk;
104
 
  int piece;
105
 
  *wrote = 0; /* nothing yet */
 
108
  struct Curl_transfer_keeper *k = &conn->keep;
 
109
  size_t piece;
 
110
  size_t length = (size_t)datalen;
 
111
  size_t *wrote = (size_t *)wrotep;
 
112
 
 
113
  *wrote = 0; /* nothing's written yet */
106
114
 
107
115
  while(length) {
108
116
    switch(ch->state) {
171
179
      piece = (ch->datasize >= length)?length:ch->datasize;
172
180
 
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 */
 
184
#ifdef HAVE_LIBZ
 
185
      switch (conn->keep.content_encoding) {
 
186
        case IDENTITY:
 
187
#endif
 
188
          if(!k->ignorebody)
 
189
            result = Curl_client_write(conn->data, CLIENTWRITE_BODY, datap,
 
190
                                       piece);
 
191
#ifdef HAVE_LIBZ
 
192
          break;
 
193
 
 
194
        case DEFLATE: 
 
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);
 
198
          break;
 
199
 
 
200
        case GZIP:
 
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);
 
204
          break;
 
205
 
 
206
        case COMPRESS:
 
207
        default:
 
208
          failf (conn->data,
 
209
                 "Unrecognized content encoding type. "
 
210
                 "libcurl understands `identity', `deflate' and `gzip' "
 
211
                 "content encodings.");
 
212
          return CHUNKE_BAD_ENCODING;
 
213
      }
 
214
#endif
 
215
 
175
216
      if(result)
176
217
        return CHUNKE_WRITE_ERROR;
 
218
 
177
219
      *wrote += piece;
178
220
 
179
221
      ch->datasize -= piece; /* decrease amount left to expect */
220
262
  }
221
263
  return CHUNKE_OK;
222
264
}
223
 
 
224
 
/*
225
 
 * local variables:
226
 
 * eval: (load-file "../curl-mode.el")
227
 
 * end:
228
 
 * vim600: fdm=marker
229
 
 * vim: et sw=2 ts=2 sts=2 tw=78
230
 
 */
 
265
#endif /* CURL_DISABLE_HTTP */