Deleted Added
full compact
http.c (88769) http.c (88771)
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

--- 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 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

--- 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: head/lib/libfetch/http.c 88769 2002-01-01 14:48:09Z des $");
30__FBSDID("$FreeBSD: head/lib/libfetch/http.c 88771 2002-01-01 16:25:29Z 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

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

94#define HTTP_NEED_AUTH 401
95#define HTTP_NEED_PROXY_AUTH 407
96#define HTTP_PROTOCOL_ERROR 999
97
98#define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
99 || (xyz) == HTTP_MOVED_TEMP \
100 || (xyz) == HTTP_SEE_OTHER)
101
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

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

94#define HTTP_NEED_AUTH 401
95#define HTTP_NEED_PROXY_AUTH 407
96#define HTTP_PROTOCOL_ERROR 999
97
98#define HTTP_REDIRECT(xyz) ((xyz) == HTTP_MOVED_PERM \
99 || (xyz) == HTTP_MOVED_TEMP \
100 || (xyz) == HTTP_SEE_OTHER)
101
102#define HTTP_ERROR(xyz) ((xyz) > 400 && (xyz) < 599)
102
103
104/*****************************************************************************
105 * I/O functions for decoding chunked streams
106 */
107
108struct cookie
109{

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

670 purl->port = _fetch_default_proxy_port(purl->scheme);
671 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
672 return purl;
673 fetchFreeURL(purl);
674 }
675 return NULL;
676}
677
103
104
105/*****************************************************************************
106 * I/O functions for decoding chunked streams
107 */
108
109struct cookie
110{

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

671 purl->port = _fetch_default_proxy_port(purl->scheme);
672 if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
673 return purl;
674 fetchFreeURL(purl);
675 }
676 return NULL;
677}
678
679static void
680_http_print_html(FILE *out, FILE *in)
681{
682 size_t len;
683 char *line, *p, *q;
684 int comment, tag;
685
686 comment = tag = 0;
687 while ((line = fgetln(in, &len)) != NULL) {
688 while (len && isspace(line[len - 1]))
689 --len;
690 for (p = q = line; q < line + len; ++q) {
691 if (comment && *q == '-') {
692 if (q + 2 < line + len && strcmp(q, "-->") == 0) {
693 tag = comment = 0;
694 q += 2;
695 }
696 } if (tag && !comment && *q == '>') {
697 p = q + 1;
698 tag = 0;
699 } else if (!tag && *q == '<') {
700 if (q > p)
701 fwrite(p, q - p, 1, out);
702 tag = 1;
703 if (q + 3 < line + len && strcmp(q, "<!--") == 0) {
704 comment = 1;
705 q += 3;
706 }
707 }
708 }
709 if (!tag && q > p)
710 fwrite(p, q - p, 1, out);
711 fputc('\n', out);
712 }
713}
714
678
679/*****************************************************************************
680 * Core
681 */
682
683/*
684 * Send a request and process the reply
685 */

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

837 goto ouch;
838 case HTTP_PROTOCOL_ERROR:
839 /* fall through */
840 case -1:
841 _fetch_syserr();
842 goto ouch;
843 default:
844 _http_seterr(code);
715
716/*****************************************************************************
717 * Core
718 */
719
720/*
721 * Send a request and process the reply
722 */

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

874 goto ouch;
875 case HTTP_PROTOCOL_ERROR:
876 /* fall through */
877 case -1:
878 _fetch_syserr();
879 goto ouch;
880 default:
881 _http_seterr(code);
845 goto ouch;
882 if (!verbose)
883 goto ouch;
884 /* fall through so we can get the full error message */
846 }
847
848 /* get headers */
849 do {
850 switch ((h = _http_next_header(fd, &p))) {
851 case hdr_syserror:
852 _fetch_syserr();
853 goto ouch;

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

900 case hdr_end:
901 /* fall through */
902 case hdr_unknown:
903 /* ignore */
904 break;
905 }
906 } while (h > hdr_end);
907
885 }
886
887 /* get headers */
888 do {
889 switch ((h = _http_next_header(fd, &p))) {
890 case hdr_syserror:
891 _fetch_syserr();
892 goto ouch;

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

939 case hdr_end:
940 /* fall through */
941 case hdr_unknown:
942 /* ignore */
943 break;
944 }
945 } while (h > hdr_end);
946
908 /* we have a hit */
909 if (code == HTTP_OK || code == HTTP_PARTIAL)
947 /* we have a hit or an error */
948 if (code == HTTP_OK || code == HTTP_PARTIAL || HTTP_ERROR(code))
910 break;
911
912 /* we need to provide authentication */
913 if (code == HTTP_NEED_AUTH) {
914 need_auth = 1;
915 close(fd);
916 fd = -1;
917 continue;

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

978 _fetch_syserr();
979 goto ouch;
980 }
981
982 if (url != URL)
983 fetchFreeURL(url);
984 if (purl)
985 fetchFreeURL(purl);
949 break;
950
951 /* we need to provide authentication */
952 if (code == HTTP_NEED_AUTH) {
953 need_auth = 1;
954 close(fd);
955 fd = -1;
956 continue;

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

1017 _fetch_syserr();
1018 goto ouch;
1019 }
1020
1021 if (url != URL)
1022 fetchFreeURL(url);
1023 if (purl)
1024 fetchFreeURL(purl);
1025
1026 if (HTTP_ERROR(code)) {
1027 _http_print_html(stderr, f);
1028 fclose(f);
1029 f = NULL;
1030 }
986
987 return f;
988
989 ouch:
990 if (url != URL)
991 fetchFreeURL(url);
992 if (purl)
993 fetchFreeURL(purl);

--- 61 unchanged lines hidden ---
1031
1032 return f;
1033
1034 ouch:
1035 if (url != URL)
1036 fetchFreeURL(url);
1037 if (purl)
1038 fetchFreeURL(purl);

--- 61 unchanged lines hidden ---