http.c (174752) | http.c (174761) |
---|---|
1/*- 2 * Copyright (c) 2000-2004 Dag-Erling Co�dan 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-2004 Dag-Erling Co�dan 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 174752 2007-12-18 11:03:07Z des $"); | 30__FBSDID("$FreeBSD: head/lib/libfetch/http.c 174761 2007-12-19 00:26:36Z 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 --- 93 unchanged lines hidden (view full) --- 132static int 133http_new_chunk(struct httpio *io) 134{ 135 char *p; 136 137 if (fetch_getln(io->conn) == -1) 138 return (-1); 139 | 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 --- 93 unchanged lines hidden (view full) --- 132static int 133http_new_chunk(struct httpio *io) 134{ 135 char *p; 136 137 if (fetch_getln(io->conn) == -1) 138 return (-1); 139 |
140 if (io->conn->buflen < 2 || !isxdigit((int)*io->conn->buf)) | 140 if (io->conn->buflen < 2 || !isxdigit((unsigned char)*io->conn->buf)) |
141 return (-1); 142 | 141 return (-1); 142 |
143 for (p = io->conn->buf; *p && !isspace((int)*p); ++p) { | 143 for (p = io->conn->buf; *p && !isspace((unsigned char)*p); ++p) { |
144 if (*p == ';') 145 break; | 144 if (*p == ';') 145 break; |
146 if (!isxdigit((int)*p)) | 146 if (!isxdigit((unsigned char)*p)) |
147 return (-1); | 147 return (-1); |
148 if (isdigit((int)*p)) { | 148 if (isdigit((unsigned char)*p)) { |
149 io->chunksize = io->chunksize * 16 + 150 *p - '0'; 151 } else { 152 io->chunksize = io->chunksize * 16 + 153 10 + tolower(*p) - 'a'; 154 } 155 } 156 --- 255 unchanged lines hidden (view full) --- 412 if (strncmp(conn->buf, "HTTP", 4) != 0) 413 return (HTTP_PROTOCOL_ERROR); 414 p = conn->buf + 4; 415 if (*p == '/') { 416 if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1')) 417 return (HTTP_PROTOCOL_ERROR); 418 p += 4; 419 } | 149 io->chunksize = io->chunksize * 16 + 150 *p - '0'; 151 } else { 152 io->chunksize = io->chunksize * 16 + 153 10 + tolower(*p) - 'a'; 154 } 155 } 156 --- 255 unchanged lines hidden (view full) --- 412 if (strncmp(conn->buf, "HTTP", 4) != 0) 413 return (HTTP_PROTOCOL_ERROR); 414 p = conn->buf + 4; 415 if (*p == '/') { 416 if (p[1] != '1' || p[2] != '.' || (p[3] != '0' && p[3] != '1')) 417 return (HTTP_PROTOCOL_ERROR); 418 p += 4; 419 } |
420 if (*p != ' ' || !isdigit((int)p[1]) || 421 !isdigit((int)p[2]) || !isdigit((int)p[3])) | 420 if (*p != ' ' || 421 !isdigit((unsigned char)p[1]) || 422 !isdigit((unsigned char)p[2]) || 423 !isdigit((unsigned char)p[3])) |
422 return (HTTP_PROTOCOL_ERROR); 423 424 conn->err = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0'); 425 return (conn->err); 426} 427 428/* 429 * Check a header; if the type matches the given string, return a pointer 430 * to the beginning of the value. 431 */ 432static const char * 433http_match(const char *str, const char *hdr) 434{ 435 while (*str && *hdr && tolower(*str++) == tolower(*hdr++)) 436 /* nothing */; 437 if (*str || *hdr != ':') 438 return (NULL); | 424 return (HTTP_PROTOCOL_ERROR); 425 426 conn->err = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0'); 427 return (conn->err); 428} 429 430/* 431 * Check a header; if the type matches the given string, return a pointer 432 * to the beginning of the value. 433 */ 434static const char * 435http_match(const char *str, const char *hdr) 436{ 437 while (*str && *hdr && tolower(*str++) == tolower(*hdr++)) 438 /* nothing */; 439 if (*str || *hdr != ':') 440 return (NULL); |
439 while (*hdr && isspace((int)*++hdr)) | 441 while (*hdr && isspace((unsigned char)*++hdr)) |
440 /* nothing */; 441 return (hdr); 442} 443 444/* 445 * Get the next header and return the appropriate symbolic code. 446 */ 447static hdr_t 448http_next_header(conn_t *conn, const char **p) 449{ 450 int i; 451 452 if (fetch_getln(conn) == -1) 453 return (hdr_syserror); | 442 /* nothing */; 443 return (hdr); 444} 445 446/* 447 * Get the next header and return the appropriate symbolic code. 448 */ 449static hdr_t 450http_next_header(conn_t *conn, const char **p) 451{ 452 int i; 453 454 if (fetch_getln(conn) == -1) 455 return (hdr_syserror); |
454 while (conn->buflen && isspace((int)conn->buf[conn->buflen - 1])) | 456 while (conn->buflen && isspace((unsigned char)conn->buf[conn->buflen - 1])) |
455 conn->buflen--; 456 conn->buf[conn->buflen] = '\0'; 457 if (conn->buflen == 0) 458 return (hdr_end); 459 /* 460 * We could check for malformed headers but we don't really care. 461 * A valid header starts with a token immediately followed by a 462 * colon; a token is any sequence of non-control, non-whitespace --- 32 unchanged lines hidden (view full) --- 495/* 496 * Parse a content-length header 497 */ 498static int 499http_parse_length(const char *p, off_t *length) 500{ 501 off_t len; 502 | 457 conn->buflen--; 458 conn->buf[conn->buflen] = '\0'; 459 if (conn->buflen == 0) 460 return (hdr_end); 461 /* 462 * We could check for malformed headers but we don't really care. 463 * A valid header starts with a token immediately followed by a 464 * colon; a token is any sequence of non-control, non-whitespace --- 32 unchanged lines hidden (view full) --- 497/* 498 * Parse a content-length header 499 */ 500static int 501http_parse_length(const char *p, off_t *length) 502{ 503 off_t len; 504 |
503 for (len = 0; *p && isdigit((int)*p); ++p) | 505 for (len = 0; *p && isdigit((unsigned char)*p); ++p) |
504 len = len * 10 + (*p - '0'); 505 if (*p) 506 return (-1); 507 DEBUG(fprintf(stderr, "content length: [%lld]\n", 508 (long long)len)); 509 *length = len; 510 return (0); 511} --- 8 unchanged lines hidden (view full) --- 520 521 if (strncasecmp(p, "bytes ", 6) != 0) 522 return (-1); 523 p += 6; 524 if (*p == '*') { 525 first = last = -1; 526 ++p; 527 } else { | 506 len = len * 10 + (*p - '0'); 507 if (*p) 508 return (-1); 509 DEBUG(fprintf(stderr, "content length: [%lld]\n", 510 (long long)len)); 511 *length = len; 512 return (0); 513} --- 8 unchanged lines hidden (view full) --- 522 523 if (strncasecmp(p, "bytes ", 6) != 0) 524 return (-1); 525 p += 6; 526 if (*p == '*') { 527 first = last = -1; 528 ++p; 529 } else { |
528 for (first = 0; *p && isdigit((int)*p); ++p) | 530 for (first = 0; *p && isdigit((unsigned char)*p); ++p) |
529 first = first * 10 + *p - '0'; 530 if (*p != '-') 531 return (-1); | 531 first = first * 10 + *p - '0'; 532 if (*p != '-') 533 return (-1); |
532 for (last = 0, ++p; *p && isdigit((int)*p); ++p) | 534 for (last = 0, ++p; *p && isdigit((unsigned char)*p); ++p) |
533 last = last * 10 + *p - '0'; 534 } 535 if (first > last || *p != '/') 536 return (-1); | 535 last = last * 10 + *p - '0'; 536 } 537 if (first > last || *p != '/') 538 return (-1); |
537 for (len = 0, ++p; *p && isdigit((int)*p); ++p) | 539 for (len = 0, ++p; *p && isdigit((unsigned char)*p); ++p) |
538 len = len * 10 + *p - '0'; 539 if (*p || len < last - first + 1) 540 return (-1); 541 if (first == -1) { 542 DEBUG(fprintf(stderr, "content range: [*/%lld]\n", 543 (long long)len)); 544 *length = 0; 545 } else { --- 199 unchanged lines hidden (view full) --- 745http_print_html(FILE *out, FILE *in) 746{ 747 size_t len; 748 char *line, *p, *q; 749 int comment, tag; 750 751 comment = tag = 0; 752 while ((line = fgetln(in, &len)) != NULL) { | 540 len = len * 10 + *p - '0'; 541 if (*p || len < last - first + 1) 542 return (-1); 543 if (first == -1) { 544 DEBUG(fprintf(stderr, "content range: [*/%lld]\n", 545 (long long)len)); 546 *length = 0; 547 } else { --- 199 unchanged lines hidden (view full) --- 747http_print_html(FILE *out, FILE *in) 748{ 749 size_t len; 750 char *line, *p, *q; 751 int comment, tag; 752 753 comment = tag = 0; 754 while ((line = fgetln(in, &len)) != NULL) { |
753 while (len && isspace((int)line[len - 1])) | 755 while (len && isspace((unsigned char)line[len - 1])) |
754 --len; 755 for (p = q = line; q < line + len; ++q) { 756 if (comment && *q == '-') { 757 if (q + 2 < line + len && 758 strcmp(q, "-->") == 0) { 759 tag = comment = 0; 760 q += 2; 761 } --- 457 unchanged lines hidden --- | 756 --len; 757 for (p = q = line; q < line + len; ++q) { 758 if (comment && *q == '-') { 759 if (q + 2 < line + len && 760 strcmp(q, "-->") == 0) { 761 tag = comment = 0; 762 q += 2; 763 } --- 457 unchanged lines hidden --- |