win32: fix leak
[vlc.git] / src / win32 / netconf.c
blobfe4e03ea9194f783ed3fed1c0253f4594a985af3
1 /*****************************************************************************
2 * netconf.c : Network configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2008 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <string.h>
26 #include <windows.h>
28 #include <vlc_common.h>
29 #include <vlc_network.h>
30 #include <vlc_url.h>
32 char *vlc_getProxyUrl(const char *psz_url)
34 VLC_UNUSED(psz_url);
36 char *proxy = config_GetPsz( (vlc_object_t *)(NULL), "http-proxy" );
37 if (proxy == NULL)
38 return NULL;
40 char *proxy_pwd = config_GetPsz( (vlc_object_t *)(NULL), "http-proxy-pwd" );
41 if (proxy_pwd == NULL)
42 return proxy;
44 vlc_url_t url;
45 if (vlc_UrlParse(&url, proxy) < 0) {
46 vlc_UrlClean(&url);
47 free (proxy);
48 free (proxy_pwd);
49 return NULL;
52 if (url.psz_password == NULL )
53 url.psz_password = vlc_uri_encode(proxy_pwd);
55 char *proxy_url = vlc_uri_compose (&url);
56 vlc_UrlClean (&url);
58 free (proxy_pwd);
59 free (proxy);
61 #if 0
62 /* Try to get the proxy server address from Windows internet settings. */
63 HKEY h_key;
65 /* Open the key */
66 if( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft"
67 "\\Windows\\CurrentVersion\\Internet Settings",
68 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
69 return NULL;
71 DWORD len = sizeof( DWORD );
72 BYTE proxyEnable;
74 /* Get the proxy enable value */
75 if( RegQueryValueEx( h_key, "ProxyEnable", NULL, NULL,
76 &proxyEnable, &len ) != ERROR_SUCCESS
77 || !proxyEnable )
78 goto out;
80 /* Proxy is enabled */
81 /* Get the proxy URL :
82 Proxy server value in the registry can be something like "address:port"
83 or "ftp=address1:port1;http=address2:port2 ..."
84 depending of the configuration. */
85 unsigned char key[256];
87 len = sizeof( key );
88 if( RegQueryValueEx( h_key, "ProxyServer", NULL, NULL,
89 key, &len ) == ERROR_SUCCESS )
91 /* FIXME: This is lame. The string should be tokenized. */
92 #warning FIXME.
93 char *psz_proxy = strstr( (char *)key, "http=" );
94 if( psz_proxy != NULL )
96 psz_proxy += 5;
97 char *end = strchr( psz_proxy, ';' );
98 if( end != NULL )
99 *end = '\0';
101 else
102 psz_proxy = (char *)key;
103 proxy_url = strdup( psz_proxy );
106 out:
107 RegCloseKey( h_key );
108 #endif
109 return proxy_url;