http.c (61896) | http.c (62811) |
---|---|
1/*- 2 * Copyright (c) 1998 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 * | 1/*- 2 * Copyright (c) 1998 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 * $FreeBSD: head/lib/libfetch/http.c 61896 2000-06-21 09:49:51Z des $ | 28 * $FreeBSD: head/lib/libfetch/http.c 62811 2000-07-08 08:08:58Z des $ |
29 */ 30 31/* 32 * The base64 code in this file is based on code from MIT fetch, which 33 * has the following copyright and license: 34 * 35 *- 36 * Copyright 1997 Massachusetts Institute of Technology --- 233 unchanged lines hidden (view full) --- 270} 271 272/* 273 * Encode username and password 274 */ 275char * 276_http_auth(char *usr, char *pwd) 277{ | 29 */ 30 31/* 32 * The base64 code in this file is based on code from MIT fetch, which 33 * has the following copyright and license: 34 * 35 *- 36 * Copyright 1997 Massachusetts Institute of Technology --- 233 unchanged lines hidden (view full) --- 270} 271 272/* 273 * Encode username and password 274 */ 275char * 276_http_auth(char *usr, char *pwd) 277{ |
278 int len, lu, lp; 279 char *str, *s; | 278 int len, lup; 279 char *uandp, *str = NULL; |
280 | 280 |
281 lu = strlen(usr); 282 lp = strlen(pwd); 283 284 len = (lu * 4 + 2) / 3 /* user name, round up */ 285 + 1 /* colon */ 286 + (lp * 4 + 2) / 3 /* password, round up */ 287 + 1; /* null */ 288 289 if ((s = str = (char *)malloc(len)) == NULL) 290 return NULL; 291 292 s += _http_base64(s, usr, lu); 293 *s++ = ':'; 294 s += _http_base64(s, pwd, lp); 295 *s = 0; 296 | 281 lup = strlen(usr) + 1 + strlen(pwd);/* length of "usr:pwd" */ 282 uandp = (char*)malloc(lup + 1); 283 if (uandp) { 284 len = ((lup + 2) / 3) * 4; /* length of base64 encoded "usr:pwd" incl. padding */ 285 str = (char*)malloc(len + 1); 286 if (str) { 287 strcpy(uandp, usr); 288 strcat(uandp, ":"); 289 strcat(uandp, pwd); 290 _http_base64(str, uandp, lup); 291 } 292 free(uandp); 293 } |
297 return str; 298} 299 300/* 301 * Connect to server or proxy 302 */ 303FILE * 304_http_connect(struct url *URL, char *flags) --- 156 unchanged lines hidden (view full) --- 461 /* start sending headers away */ 462 if (URL->user[0] || URL->pwd[0]) { 463 char *auth_str = _http_auth(URL->user, URL->pwd); 464 if (!auth_str) 465 return 999; /* XXX wrong */ 466 _http_cmd(f, "Authorization: Basic %s" ENDL, auth_str); 467 free(auth_str); 468 } | 294 return str; 295} 296 297/* 298 * Connect to server or proxy 299 */ 300FILE * 301_http_connect(struct url *URL, char *flags) --- 156 unchanged lines hidden (view full) --- 458 /* start sending headers away */ 459 if (URL->user[0] || URL->pwd[0]) { 460 char *auth_str = _http_auth(URL->user, URL->pwd); 461 if (!auth_str) 462 return 999; /* XXX wrong */ 463 _http_cmd(f, "Authorization: Basic %s" ENDL, auth_str); 464 free(auth_str); 465 } |
466 if (p = getenv("HTTP_PROXY_AUTH")) { 467 char *auth; 468 469 /* skip leading "basic:*:", if present */ 470 if (strncmp(p, "basic:*:", 6 + 2) == 0) 471 p += 6 + 2; 472 auth = strchr(p, ':'); 473 if (auth != NULL) { 474 int len = auth - p; 475 char *user; 476 char *auth_str; 477 478 if ((user = (char*)malloc(len + 1)) == NULL) { 479 free(auth); 480 return 999; /* XXX wrong */ 481 } 482 strncpy(user, p, len); 483 user[len] = 0; 484 auth++; 485 auth_str = _http_auth(user, auth); 486 free(user); 487 if (auth_str == NULL) 488 return 999; /* XXX wrong */ 489 _http_cmd(f, "Proxy-Authorization: Basic %s" ENDL, auth_str); 490 free(auth_str); 491 } else { 492 return 999; /* XXX wrong */ 493 } 494 } |
|
469 _http_cmd(f, "Host: %s:%d" ENDL, host, URL->port); 470 _http_cmd(f, "User-Agent: %s " _LIBFETCH_VER ENDL, __progname); 471 if (URL->offset) 472 _http_cmd(f, "Range: bytes=%lld-" ENDL, URL->offset); 473 _http_cmd(f, "Connection: close" ENDL ENDL); 474 475 /* get response */ 476 if ((ln = fgetln(f, &len)) == NULL) --- 229 unchanged lines hidden --- | 495 _http_cmd(f, "Host: %s:%d" ENDL, host, URL->port); 496 _http_cmd(f, "User-Agent: %s " _LIBFETCH_VER ENDL, __progname); 497 if (URL->offset) 498 _http_cmd(f, "Range: bytes=%lld-" ENDL, URL->offset); 499 _http_cmd(f, "Connection: close" ENDL ENDL); 500 501 /* get response */ 502 if ((ln = fgetln(f, &len)) == NULL) --- 229 unchanged lines hidden --- |