comparison libmpdemux/network.c @ 4146:925046ea34ec

Added support for the environment variable http_proxy.
author bertrand
date Mon, 14 Jan 2002 06:44:30 +0000
parents c66fddd8867c
children 0c809c541aa1
comparison
equal deleted inserted replaced
4145:c66fddd8867c 4146:925046ea34ec
171 return -1; 171 return -1;
172 } 172 }
173 return socket_server_fd; 173 return socket_server_fd;
174 } 174 }
175 175
176 URL_t*
177 check4proxies( URL_t *url ) {
178 if( !strcasecmp(url->protocol, "http_proxy") ) {
179 printf("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port );
180 return url;
181 }
182 // Check if the http_proxy environment variable is set.
183 if( !strcasecmp(url->protocol, "http") ) {
184 char *proxy;
185 proxy = getenv("http_proxy");
186 if( proxy!=NULL ) {
187 // We got a proxy, build the URL to use it
188 int len;
189 char *new_url;
190 URL_t *tmp_url;
191 URL_t *proxy_url = url_new( proxy );
192
193 if( proxy_url==NULL ) {
194 printf("Invalid proxy setting...Trying without proxy.\n");
195 return url;
196 }
197
198 printf("Using HTTP proxy: %s\n", proxy_url->url );
199 len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port
200 new_url = malloc( len+1 );
201 if( new_url==NULL ) {
202 printf("Memory allocation failed\n");
203 return url;
204 }
205 sprintf( new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url);
206 tmp_url = url_new( new_url );
207 if( tmp_url==NULL ) {
208 return url;
209 }
210 url_free( url );
211 url = tmp_url;
212 free( new_url );
213 url_free( proxy_url );
214 }
215 }
216 return url;
217 }
218
176 int 219 int
177 http_send_request( URL_t *url ) { 220 http_send_request( URL_t *url ) {
178 HTTP_header_t *http_hdr; 221 HTTP_header_t *http_hdr;
179 URL_t *server_url; 222 URL_t *server_url;
180 char str[80]; 223 char str[80];
324 return 0; 367 return 0;
325 } 368 }
326 369
327 // HTTP based protocol 370 // HTTP based protocol
328 if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "http_proxy") ) { 371 if( !strcasecmp(url->protocol, "http") || !strcasecmp(url->protocol, "http_proxy") ) {
329 //if( url->port==0 ) url->port = 80;
330
331 fd = http_send_request( url ); 372 fd = http_send_request( url );
332 if( fd<0 ) { 373 if( fd<0 ) {
333 return -1; 374 return -1;
334 } 375 }
335 376