Deleted Added
full compact
http.c (242606) http.c (251001)
1/*-
2 * Copyright (c) 2000-2011 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-2011 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: stable/9/lib/libfetch/http.c 242606 2012-11-05 10:42:31Z des $");
30__FBSDID("$FreeBSD: stable/9/lib/libfetch/http.c 251001 2013-05-26 16:48:51Z 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

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

1368 */
1369
1370/*
1371 * Connect to the correct HTTP server or proxy.
1372 */
1373static conn_t *
1374http_connect(struct url *URL, struct url *purl, const char *flags)
1375{
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

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

1368 */
1369
1370/*
1371 * Connect to the correct HTTP server or proxy.
1372 */
1373static conn_t *
1374http_connect(struct url *URL, struct url *purl, const char *flags)
1375{
1376 struct url *curl;
1376 conn_t *conn;
1377 int verbose;
1378 int af, val;
1379
1380#ifdef INET6
1381 af = AF_UNSPEC;
1382#else
1383 af = AF_INET;
1384#endif
1385
1386 verbose = CHECK_FLAG('v');
1387 if (CHECK_FLAG('4'))
1388 af = AF_INET;
1389#ifdef INET6
1390 else if (CHECK_FLAG('6'))
1391 af = AF_INET6;
1392#endif
1393
1377 conn_t *conn;
1378 int verbose;
1379 int af, val;
1380
1381#ifdef INET6
1382 af = AF_UNSPEC;
1383#else
1384 af = AF_INET;
1385#endif
1386
1387 verbose = CHECK_FLAG('v');
1388 if (CHECK_FLAG('4'))
1389 af = AF_INET;
1390#ifdef INET6
1391 else if (CHECK_FLAG('6'))
1392 af = AF_INET6;
1393#endif
1394
1394 if (purl && strcasecmp(URL->scheme, SCHEME_HTTPS) != 0) {
1395 URL = purl;
1396 } else if (strcasecmp(URL->scheme, SCHEME_FTP) == 0) {
1397 /* can't talk http to an ftp server */
1398 /* XXX should set an error code */
1399 return (NULL);
1400 }
1395 curl = (purl != NULL) ? purl : URL;
1401
1396
1402 if ((conn = fetch_connect(URL->host, URL->port, af, verbose)) == NULL)
1397 if ((conn = fetch_connect(curl->host, curl->port, af, verbose)) == NULL)
1403 /* fetch_connect() has already set an error code */
1404 return (NULL);
1398 /* fetch_connect() has already set an error code */
1399 return (NULL);
1400 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 && purl) {
1401 http_cmd(conn, "CONNECT %s:%d HTTP/1.1",
1402 URL->host, URL->port);
1403 http_cmd(conn, "");
1404 if (http_get_reply(conn) != HTTP_OK) {
1405 fetch_close(conn);
1406 return (NULL);
1407 }
1408 http_get_reply(conn);
1409 }
1405 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
1406 fetch_ssl(conn, verbose) == -1) {
1407 fetch_close(conn);
1408 /* grrr */
1409 errno = EAUTH;
1410 fetch_syserr();
1411 return (NULL);
1412 }

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

1747 http_seterr(conn->err);
1748 if (!verbose)
1749 goto ouch;
1750 /* fall through so we can get the full error message */
1751 }
1752
1753 /* get headers. http_next_header expects one line readahead */
1754 if (fetch_getln(conn) == -1) {
1410 if (strcasecmp(URL->scheme, SCHEME_HTTPS) == 0 &&
1411 fetch_ssl(conn, verbose) == -1) {
1412 fetch_close(conn);
1413 /* grrr */
1414 errno = EAUTH;
1415 fetch_syserr();
1416 return (NULL);
1417 }

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

1752 http_seterr(conn->err);
1753 if (!verbose)
1754 goto ouch;
1755 /* fall through so we can get the full error message */
1756 }
1757
1758 /* get headers. http_next_header expects one line readahead */
1759 if (fetch_getln(conn) == -1) {
1755 fetch_syserr();
1756 goto ouch;
1760 fetch_syserr();
1761 goto ouch;
1757 }
1758 do {
1762 }
1763 do {
1759 switch ((h = http_next_header(conn, &headerbuf, &p))) {
1764 switch ((h = http_next_header(conn, &headerbuf, &p))) {
1760 case hdr_syserror:
1761 fetch_syserr();
1762 goto ouch;
1763 case hdr_error:
1764 http_seterr(HTTP_PROTOCOL_ERROR);
1765 goto ouch;
1766 case hdr_content_length:
1767 http_parse_length(p, &clength);

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

1780 * temporary redirects.
1781 */
1782 if (noredirect &&
1783 conn->err != HTTP_MOVED_PERM &&
1784 conn->err != HTTP_PERM_REDIRECT &&
1785 conn->err != HTTP_USE_PROXY) {
1786 n = 1;
1787 break;
1765 case hdr_syserror:
1766 fetch_syserr();
1767 goto ouch;
1768 case hdr_error:
1769 http_seterr(HTTP_PROTOCOL_ERROR);
1770 goto ouch;
1771 case hdr_content_length:
1772 http_parse_length(p, &clength);

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

1785 * temporary redirects.
1786 */
1787 if (noredirect &&
1788 conn->err != HTTP_MOVED_PERM &&
1789 conn->err != HTTP_PERM_REDIRECT &&
1790 conn->err != HTTP_USE_PROXY) {
1791 n = 1;
1792 break;
1788 }
1793 }
1789 if (new)
1790 free(new);
1791 if (verbose)
1792 fetch_info("%d redirect to %s", conn->err, p);
1793 if (*p == '/')
1794 /* absolute path */
1795 new = fetchMakeURL(url->scheme, url->host, url->port, p,
1796 url->user, url->pwd);

--- 231 unchanged lines hidden ---
1794 if (new)
1795 free(new);
1796 if (verbose)
1797 fetch_info("%d redirect to %s", conn->err, p);
1798 if (*p == '/')
1799 /* absolute path */
1800 new = fetchMakeURL(url->scheme, url->host, url->port, p,
1801 url->user, url->pwd);

--- 231 unchanged lines hidden ---