http.c (254650) | http.c (261230) |
---|---|
1/*- 2 * Copyright (c) 2000-2013 Dag-Erling Sm��rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000-2013 Dag-Erling Sm��rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/lib/libfetch/http.c 254650 2013-08-22 07:43:36Z des $"); | 30__FBSDID("$FreeBSD: head/lib/libfetch/http.c 261230 2014-01-28 12:48:17Z des $"); |
31 32/* 33 * The following copyright applies to the base64 code: 34 * 35 *- 36 * Copyright 1997 Massachusetts Institute of Technology 37 * 38 * Permission to use, copy, modify, and distribute this software and --- 164 unchanged lines hidden (view full) --- 203 204/* 205 * Fill the input buffer, do chunk decoding on the fly 206 */ 207static int 208http_fillbuf(struct httpio *io, size_t len) 209{ 210 ssize_t nbytes; | 31 32/* 33 * The following copyright applies to the base64 code: 34 * 35 *- 36 * Copyright 1997 Massachusetts Institute of Technology 37 * 38 * Permission to use, copy, modify, and distribute this software and --- 164 unchanged lines hidden (view full) --- 203 204/* 205 * Fill the input buffer, do chunk decoding on the fly 206 */ 207static int 208http_fillbuf(struct httpio *io, size_t len) 209{ 210 ssize_t nbytes; |
211 char ch; |
|
211 212 if (io->error) 213 return (-1); 214 if (io->eof) 215 return (0); 216 217 if (io->chunked == 0) { 218 if (http_growbuf(io, len) == -1) --- 25 unchanged lines hidden (view full) --- 244 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) { 245 io->error = errno; 246 return (-1); 247 } 248 io->buflen = nbytes; 249 io->chunksize -= io->buflen; 250 251 if (io->chunksize == 0) { | 212 213 if (io->error) 214 return (-1); 215 if (io->eof) 216 return (0); 217 218 if (io->chunked == 0) { 219 if (http_growbuf(io, len) == -1) --- 25 unchanged lines hidden (view full) --- 245 if ((nbytes = fetch_read(io->conn, io->buf, len)) == -1) { 246 io->error = errno; 247 return (-1); 248 } 249 io->buflen = nbytes; 250 io->chunksize -= io->buflen; 251 252 if (io->chunksize == 0) { |
252 char endl[2]; 253 254 if (fetch_read(io->conn, endl, 2) != 2 || 255 endl[0] != '\r' || endl[1] != '\n') | 253 if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' || 254 fetch_read(io->conn, &ch, 1) != 1 || ch != '\n') |
256 return (-1); 257 } 258 259 io->bufpos = 0; 260 261 return (io->buflen); 262} 263 264/* 265 * Read function 266 */ 267static int 268http_readfn(void *v, char *buf, int len) 269{ 270 struct httpio *io = (struct httpio *)v; | 255 return (-1); 256 } 257 258 io->bufpos = 0; 259 260 return (io->buflen); 261} 262 263/* 264 * Read function 265 */ 266static int 267http_readfn(void *v, char *buf, int len) 268{ 269 struct httpio *io = (struct httpio *)v; |
271 int l, pos; | 270 int rlen; |
272 273 if (io->error) 274 return (-1); 275 if (io->eof) 276 return (0); 277 | 271 272 if (io->error) 273 return (-1); 274 if (io->eof) 275 return (0); 276 |
278 for (pos = 0; len > 0; pos += l, len -= l) { 279 /* empty buffer */ 280 if (!io->buf || io->bufpos == io->buflen) 281 if (http_fillbuf(io, len) < 1) 282 break; 283 l = io->buflen - io->bufpos; 284 if (len < l) 285 l = len; 286 memcpy(buf + pos, io->buf + io->bufpos, l); 287 io->bufpos += l; | 277 /* empty buffer */ 278 if (!io->buf || io->bufpos == io->buflen) { 279 if (http_fillbuf(io, len) < 1) { 280 if (io->error == EINTR) 281 io->error = 0; 282 return (-1); 283 } |
288 } 289 | 284 } 285 |
290 if (!pos && io->error) { 291 if (io->error == EINTR) 292 io->error = 0; 293 return (-1); 294 } 295 return (pos); | 286 rlen = io->buflen - io->bufpos; 287 if (len < rlen) 288 rlen = len; 289 memcpy(buf, io->buf + io->bufpos, rlen); 290 io->bufpos += rlen; 291 return (rlen); |
296} 297 298/* 299 * Write function 300 */ 301static int 302http_writefn(void *v, const char *buf, int len) 303{ --- 1737 unchanged lines hidden --- | 292} 293 294/* 295 * Write function 296 */ 297static int 298http_writefn(void *v, const char *buf, int len) 299{ --- 1737 unchanged lines hidden --- |