]>
cygwin.com Git - cygwin-apps/setup.git/blob - nio-http.cc
2 * Copyright (c) 2000, 2001, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* This file is responsible for implementing all direct HTTP protocol
17 channels. It is intentionally simplistic. */
20 static const char *cvsid
=
37 static char six2pr
[64] = {
38 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
39 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
40 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
41 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
42 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
46 base64_encode (char *username
, char *password
)
53 rv
= new char[2 * (strlen (username
) + strlen (password
)) + 5];
55 char *up
= new char[strlen (username
) + strlen (password
) + 6];
56 strcpy (up
, username
);
58 strcat (up
, password
);
59 ep
= (unsigned char *) up
+ strlen (up
);
68 for (ep
= (unsigned char *) up
; *ep
; ep
+= 3)
70 block
[0] = six2pr
[ep
[0] >> 2];
71 block
[1] = six2pr
[((ep
[0] << 4) & 0x30) | ((ep
[1] >> 4) & 0x0f)];
72 block
[2] = six2pr
[((ep
[1] << 2) & 0x3c) | ((ep
[2] >> 6) & 0x03)];
73 block
[3] = six2pr
[ep
[2] & 0x3f];
76 block
[2] = block
[3] = '=';
79 memcpy (rp
, block
, 4);
89 NetIO_HTTP::NetIO_HTTP (char const *Purl
, BOOL allow_ftp_auth
):NetIO (Purl
, allow_ftp_auth
)
95 if (net_method
== IDC_NET_PROXY
)
96 s
= new SimpleSocket (net_proxy_host
, net_proxy_port
);
98 s
= new SimpleSocket (host
, port
);
108 if (net_method
== IDC_NET_PROXY
)
109 s
->printf ("GET %s HTTP/1.0\r\n", Purl
);
111 s
->printf ("GET %s HTTP/1.0\r\n", path
);
112 s
->printf ("Host: %s:%d\r\n", host
, port
);
114 if (net_user
&& net_passwd
)
115 s
->printf ("Authorization: Basic %s\r\n",
116 base64_encode (net_user
, net_passwd
));
118 if (net_proxy_user
&& net_proxy_passwd
)
119 s
->printf ("Proxy-Authorization: Basic %s\r\n",
120 base64_encode (net_proxy_user
, net_proxy_passwd
));
130 sscanf (l
, "%*s %d", &code
);
131 if (code
>= 300 && code
< 400)
133 while ((l
= s
->gets ()) != 0)
135 if (_strnicmp (l
, "Location:", 9) == 0)
139 while (*u
== ' ' || *u
== '\t')
148 if (code
== 401) /* authorization required */
155 if (code
== 407) /* proxy authorization required */
157 get_proxy_auth (NULL
);
162 if (code
== 500 /* ftp authentication through proxy required */
163 && net_method
== IDC_NET_PROXY
&& !strncmp (Purl
, "ftp://", 6))
166 if (net_ftp_user
&& net_ftp_passwd
)
170 Purl
= (String ("ftp://") + net_ftp_user
+
171 ":" + net_ftp_passwd
+ "@" + (Purl
+ 6)).cstr_oneuse();
183 // Eat the header, picking out the Content-Length in the process
184 while (((l
= s
->gets ()) != NULL
) && (*l
!= '\0'))
186 if (_strnicmp (l
, "Content-Length:", 15) == 0)
187 sscanf (l
, "%*s %d", &file_size
);
191 NetIO_HTTP::~NetIO_HTTP ()
206 NetIO_HTTP::read (char *buf
, int nbytes
)
208 return s
->read (buf
, nbytes
);
This page took 0.186469 seconds and 5 git commands to generate.