Deleted Added
full compact
http.c (63012) http.c (63069)
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 63012 2000-07-12 10:39:56Z des $
28 * $FreeBSD: head/lib/libfetch/http.c 63069 2000-07-13 09:13:58Z des $
29 */
30
31#include <sys/param.h>
32#include <sys/socket.h>
33
34#include <ctype.h>
35#include <err.h>
36#include <errno.h>

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

727 char hbuf[MAXHOSTNAMELEN + 1];
728#endif
729
730 noredirect = (flags && strchr(flags, 'A'));
731 verbose = (flags && strchr(flags, 'v'));
732
733 n = noredirect ? 1 : MAX_REDIRECT;
734
29 */
30
31#include <sys/param.h>
32#include <sys/socket.h>
33
34#include <ctype.h>
35#include <err.h>
36#include <errno.h>

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

727 char hbuf[MAXHOSTNAMELEN + 1];
728#endif
729
730 noredirect = (flags && strchr(flags, 'A'));
731 verbose = (flags && strchr(flags, 'v'));
732
733 n = noredirect ? 1 : MAX_REDIRECT;
734
735 us->size = -1;
736 us->atime = us->mtime = 0;
735 /* just to appease compiler warnings */
736 code = HTTP_PROTOCOL_ERROR;
737 chunked = 0;
738 offset = 0;
739 fd = -1;
737 chunked = 0;
738 offset = 0;
739 fd = -1;
740 code = HTTP_PROTOCOL_ERROR; /* just to appease a compiler warning */
741
742 for (url = URL, i = 0; i < n; ++i) {
740
741 for (url = URL, i = 0; i < n; ++i) {
742 new = NULL;
743 us->size = -1;
744 us->atime = us->mtime = 0;
745 chunked = 0;
743 need_auth = 0;
746 need_auth = 0;
747 offset = 0;
748 fd = -1;
744 retry:
745 /* connect to server or proxy */
746 if ((fd = _http_connect(url, &proxy, flags)) == -1)
747 goto ouch;
748
749 host = url->host;
750#ifdef INET6
751 if (strchr(url->host, ':')) {

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

853 offset = _http_parse_range(p);
854 break;
855 case hdr_last_modified:
856 us->atime = us->mtime = _http_parse_mtime(p);
857 break;
858 case hdr_location:
859 if (!HTTP_REDIRECT(code))
860 break;
749 retry:
750 /* connect to server or proxy */
751 if ((fd = _http_connect(url, &proxy, flags)) == -1)
752 goto ouch;
753
754 host = url->host;
755#ifdef INET6
756 if (strchr(url->host, ':')) {

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

858 offset = _http_parse_range(p);
859 break;
860 case hdr_last_modified:
861 us->atime = us->mtime = _http_parse_mtime(p);
862 break;
863 case hdr_location:
864 if (!HTTP_REDIRECT(code))
865 break;
866 if (new)
867 free(new);
861 if (verbose)
862 _fetch_info("%d redirect to %s", code, p);
868 if (verbose)
869 _fetch_info("%d redirect to %s", code, p);
863 if ((new = fetchParseURL(p)) == NULL)
864 /* invalid location */
870 if (*p == '/')
871 /* absolute path */
872 new = fetchMakeURL(url->scheme, url->host, url->port, p,
873 url->user, url->pwd);
874 else
875 new = fetchParseURL(p);
876 if (new == NULL) {
877 /* XXX should set an error code */
878 DEBUG(fprintf(stderr, "failed to parse new URL\n"));
865 goto ouch;
879 goto ouch;
880 }
866 if (!*new->user && !*new->pwd) {
867 strcpy(new->user, url->user);
868 strcpy(new->pwd, url->pwd);
869 }
870 new->offset = url->offset;
871 new->length = url->length;
881 if (!*new->user && !*new->pwd) {
882 strcpy(new->user, url->user);
883 strcpy(new->pwd, url->pwd);
884 }
885 new->offset = url->offset;
886 new->length = url->length;
872 close(fd);
873 us->size = -1;
874 us->atime = us->mtime = 0;
875 chunked = 0;
876 offset = 0;
877 fd = -1;
878 if (url != URL)
879 fetchFreeURL(url);
880 url = new;
881 continue;
887 break;
882 case hdr_transfer_encoding:
883 /* XXX weak test*/
884 chunked = (strcasecmp(p, "chunked") == 0);
885 break;
886 case hdr_end:
887 /* fall through */
888 case hdr_unknown:
889 /* ignore */
890 break;
891 }
892 } while (h > hdr_end);
893
888 case hdr_transfer_encoding:
889 /* XXX weak test*/
890 chunked = (strcasecmp(p, "chunked") == 0);
891 break;
892 case hdr_end:
893 /* fall through */
894 case hdr_unknown:
895 /* ignore */
896 break;
897 }
898 } while (h > hdr_end);
899
894 if (code == HTTP_OK || code == HTTP_PARTIAL)
900 /* we either have a hit, or a redirect with no Location: header */
901 if (code == HTTP_OK || code == HTTP_PARTIAL || !new)
895 break;
902 break;
903
904 /* we have a redirect */
905 close(fd);
906 if (url != URL)
907 fetchFreeURL(url);
908 url = new;
896 }
897
898 /* no success */
899 if (fd == -1) {
900 _http_seterr(code);
901 goto ouch;
902 }
903

--- 72 unchanged lines hidden ---
909 }
910
911 /* no success */
912 if (fd == -1) {
913 _http_seterr(code);
914 goto ouch;
915 }
916

--- 72 unchanged lines hidden ---