Deleted Added
full compact
http.c (87561) http.c (88769)
1/*-
2 * Copyright (c) 2000 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 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 87561 2001-12-09 15:05:58Z des $");
30__FBSDID("$FreeBSD: head/lib/libfetch/http.c 88769 2002-01-01 14:48:09Z 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

--- 102 unchanged lines hidden (view full) ---

141 c->chunksize = c->chunksize * 16 + *p - '0';
142 else
143 c->chunksize = c->chunksize * 16 + 10 + tolower(*p) - 'a';
144
145#ifndef NDEBUG
146 if (fetchDebug) {
147 c->total += c->chunksize;
148 if (c->chunksize == 0)
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

--- 102 unchanged lines hidden (view full) ---

141 c->chunksize = c->chunksize * 16 + *p - '0';
142 else
143 c->chunksize = c->chunksize * 16 + 10 + tolower(*p) - 'a';
144
145#ifndef NDEBUG
146 if (fetchDebug) {
147 c->total += c->chunksize;
148 if (c->chunksize == 0)
149 fprintf(stderr, "\033[1m_http_fillbuf(): "
150 "end of last chunk\033[m\n");
149 fprintf(stderr, "_http_fillbuf(): "
150 "end of last chunk\n");
151 else
151 else
152 fprintf(stderr, "\033[1m_http_fillbuf(): "
153 "new chunk: %lu (%lu)\033[m\n",
152 fprintf(stderr, "_http_fillbuf(): "
153 "new chunk: %lu (%lu)\n",
154 (unsigned long)c->chunksize, (unsigned long)c->total);
155 }
156#endif
157
158 return c->chunksize;
159}
160
161/*

--- 280 unchanged lines hidden (view full) ---

442
443 strncpy(locale, setlocale(LC_TIME, NULL), sizeof locale);
444 setlocale(LC_TIME, "C");
445 r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
446 /* XXX should add support for date-2 and date-3 */
447 setlocale(LC_TIME, locale);
448 if (r == NULL)
449 return -1;
154 (unsigned long)c->chunksize, (unsigned long)c->total);
155 }
156#endif
157
158 return c->chunksize;
159}
160
161/*

--- 280 unchanged lines hidden (view full) ---

442
443 strncpy(locale, setlocale(LC_TIME, NULL), sizeof locale);
444 setlocale(LC_TIME, "C");
445 r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
446 /* XXX should add support for date-2 and date-3 */
447 setlocale(LC_TIME, locale);
448 if (r == NULL)
449 return -1;
450 DEBUG(fprintf(stderr, "last modified: [\033[1m%04d-%02d-%02d "
451 "%02d:%02d:%02d\033[m]\n",
450 DEBUG(fprintf(stderr, "last modified: [%04d-%02d-%02d "
451 "%02d:%02d:%02d]\n",
452 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
453 tm.tm_hour, tm.tm_min, tm.tm_sec));
454 *mtime = timegm(&tm);
455 return 0;
456}
457
458/*
459 * Parse a content-length header
460 */
461static int
462_http_parse_length(const char *p, off_t *length)
463{
464 off_t len;
465
466 for (len = 0; *p && isdigit(*p); ++p)
467 len = len * 10 + (*p - '0');
468 if (*p)
469 return -1;
452 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
453 tm.tm_hour, tm.tm_min, tm.tm_sec));
454 *mtime = timegm(&tm);
455 return 0;
456}
457
458/*
459 * Parse a content-length header
460 */
461static int
462_http_parse_length(const char *p, off_t *length)
463{
464 off_t len;
465
466 for (len = 0; *p && isdigit(*p); ++p)
467 len = len * 10 + (*p - '0');
468 if (*p)
469 return -1;
470 DEBUG(fprintf(stderr, "content length: [\033[1m%lld\033[m]\n",
470 DEBUG(fprintf(stderr, "content length: [%lld]\n",
471 (long long)len));
472 *length = len;
473 return 0;
474}
475
476/*
477 * Parse a content-range header
478 */

--- 11 unchanged lines hidden (view full) ---

490 for (last = 0, ++p; *p && isdigit(*p); ++p)
491 last = last * 10 + *p - '0';
492 if (first > last || *p != '/')
493 return -1;
494 for (len = 0, ++p; *p && isdigit(*p); ++p)
495 len = len * 10 + *p - '0';
496 if (*p || len < last - first + 1)
497 return -1;
471 (long long)len));
472 *length = len;
473 return 0;
474}
475
476/*
477 * Parse a content-range header
478 */

--- 11 unchanged lines hidden (view full) ---

490 for (last = 0, ++p; *p && isdigit(*p); ++p)
491 last = last * 10 + *p - '0';
492 if (first > last || *p != '/')
493 return -1;
494 for (len = 0, ++p; *p && isdigit(*p); ++p)
495 len = len * 10 + *p - '0';
496 if (*p || len < last - first + 1)
497 return -1;
498 DEBUG(fprintf(stderr, "content range: [\033[1m%lld-%lld/%lld\033[m]\n",
498 DEBUG(fprintf(stderr, "content range: [%lld-%lld/%lld]\n",
499 (long long)first, (long long)last, (long long)len));
500 *offset = first;
501 *length = last - first + 1;
502 *size = len;
503 return 0;
504}
505
506

--- 61 unchanged lines hidden (view full) ---

568 * Encode username and password
569 */
570static int
571_http_basic_auth(int fd, const char *hdr, const char *usr, const char *pwd)
572{
573 char *upw, *auth;
574 int r;
575
499 (long long)first, (long long)last, (long long)len));
500 *offset = first;
501 *length = last - first + 1;
502 *size = len;
503 return 0;
504}
505
506

--- 61 unchanged lines hidden (view full) ---

568 * Encode username and password
569 */
570static int
571_http_basic_auth(int fd, const char *hdr, const char *usr, const char *pwd)
572{
573 char *upw, *auth;
574 int r;
575
576 DEBUG(fprintf(stderr, "usr: [\033[1m%s\033[m]\n", usr));
577 DEBUG(fprintf(stderr, "pwd: [\033[1m%s\033[m]\n", pwd));
576 DEBUG(fprintf(stderr, "usr: [%s]\n", usr));
577 DEBUG(fprintf(stderr, "pwd: [%s]\n", pwd));
578 if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
579 return -1;
580 auth = _http_base64(upw);
581 free(upw);
582 if (auth == NULL)
583 return -1;
584 r = _http_cmd(fd, "%s: Basic %s", hdr, auth);
585 free(auth);

--- 469 unchanged lines hidden ---
578 if (asprintf(&upw, "%s:%s", usr, pwd) == -1)
579 return -1;
580 auth = _http_base64(upw);
581 free(upw);
582 if (auth == NULL)
583 return -1;
584 r = _http_cmd(fd, "%s: Basic %s", hdr, auth);
585 free(auth);

--- 469 unchanged lines hidden ---