Deleted Added
sdiff udiff text old ( 61896 ) new ( 62811 )
full compact
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 $
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;
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
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 }
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 ---