http.c (67892) | http.c (68551) |
---|---|
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 --- 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) 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 --- 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 67892 2000-10-29 15:56:10Z des $ | 28 * $FreeBSD: head/lib/libfetch/http.c 68551 2000-11-10 08:43:40Z des $ |
29 */ 30 31/* 32 * The following copyright applies to the base64 code: 33 * 34 *- 35 * Copyright 1997 Massachusetts Institute of Technology 36 * --- 567 unchanged lines hidden (view full) --- 604} 605 606 607/***************************************************************************** 608 * Helper functions for connecting to a server or proxy 609 */ 610 611/* | 29 */ 30 31/* 32 * The following copyright applies to the base64 code: 33 * 34 *- 35 * Copyright 1997 Massachusetts Institute of Technology 36 * --- 567 unchanged lines hidden (view full) --- 604} 605 606 607/***************************************************************************** 608 * Helper functions for connecting to a server or proxy 609 */ 610 611/* |
612 * Return the default port for this scheme 613 */ 614static int 615_http_default_port(char *scheme) 616{ 617 struct servent *se; 618 619 if ((se = getservbyname(scheme, "tcp")) != NULL) 620 return ntohs(se->s_port); 621 if (strcasecmp(scheme, SCHEME_FTP) == 0) 622 return FTP_DEFAULT_PORT; 623 if (strcasecmp(scheme, SCHEME_HTTP) == 0) 624 return HTTP_DEFAULT_PORT; 625 return 0; 626} 627 628/* | |
629 * Connect to the correct HTTP server or proxy. 630 */ 631static int 632_http_connect(struct url *URL, struct url *purl, char *flags) 633{ 634 int verbose; 635 int af, fd; 636 --- 30 unchanged lines hidden (view full) --- 667{ 668 struct url *purl; 669 char *p; 670 671 if ((p = getenv("HTTP_PROXY")) && (purl = fetchParseURL(p))) { 672 if (!*purl->scheme) 673 strcpy(purl->scheme, SCHEME_HTTP); 674 if (!purl->port) | 612 * Connect to the correct HTTP server or proxy. 613 */ 614static int 615_http_connect(struct url *URL, struct url *purl, char *flags) 616{ 617 int verbose; 618 int af, fd; 619 --- 30 unchanged lines hidden (view full) --- 650{ 651 struct url *purl; 652 char *p; 653 654 if ((p = getenv("HTTP_PROXY")) && (purl = fetchParseURL(p))) { 655 if (!*purl->scheme) 656 strcpy(purl->scheme, SCHEME_HTTP); 657 if (!purl->port) |
675 purl->port = _http_default_port(SCHEME_HTTP); | 658 purl->port = _fetch_default_proxy_port(purl->scheme); |
676 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0) 677 return purl; 678 fetchFreeURL(purl); 679 } 680 return NULL; 681} 682 683 --- 44 unchanged lines hidden (view full) --- 728 offset = 0; 729 clength = -1; 730 length = -1; 731 size = -1; 732 mtime = 0; 733 retry: 734 /* check port */ 735 if (!url->port) | 659 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0) 660 return purl; 661 fetchFreeURL(purl); 662 } 663 return NULL; 664} 665 666 --- 44 unchanged lines hidden (view full) --- 711 offset = 0; 712 clength = -1; 713 length = -1; 714 size = -1; 715 mtime = 0; 716 retry: 717 /* check port */ 718 if (!url->port) |
736 url->port = _http_default_port(url->scheme); | 719 url->port = _fetch_default_port(url->scheme); |
737 738 /* connect to server or proxy */ 739 if ((fd = _http_connect(url, purl, flags)) == -1) 740 goto ouch; 741 742 host = url->host; 743#ifdef INET6 744 if (strchr(url->host, ':')) { --- 31 unchanged lines hidden (view full) --- 776 _http_authorize(fd, "Authorization", p); 777 else { 778 _http_seterr(HTTP_NEED_AUTH); 779 goto ouch; 780 } 781 } 782 783 /* other headers */ | 720 721 /* connect to server or proxy */ 722 if ((fd = _http_connect(url, purl, flags)) == -1) 723 goto ouch; 724 725 host = url->host; 726#ifdef INET6 727 if (strchr(url->host, ':')) { --- 31 unchanged lines hidden (view full) --- 759 _http_authorize(fd, "Authorization", p); 760 else { 761 _http_seterr(HTTP_NEED_AUTH); 762 goto ouch; 763 } 764 } 765 766 /* other headers */ |
784 if (url->port == _http_default_port(url->scheme)) | 767 if (url->port == _fetch_default_port(url->scheme)) |
785 _http_cmd(fd, "Host: %s", host); 786 else 787 _http_cmd(fd, "Host: %s:%d", host, url->port); 788 _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); 789 if (url->offset) 790 _http_cmd(fd, "Range: bytes=%lld-", url->offset); 791 _http_cmd(fd, "Connection: close"); 792 _http_cmd(fd, ""); --- 233 unchanged lines hidden --- | 768 _http_cmd(fd, "Host: %s", host); 769 else 770 _http_cmd(fd, "Host: %s:%d", host, url->port); 771 _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); 772 if (url->offset) 773 _http_cmd(fd, "Range: bytes=%lld-", url->offset); 774 _http_cmd(fd, "Connection: close"); 775 _http_cmd(fd, ""); --- 233 unchanged lines hidden --- |