user32/tests: Fix the listbox tests on Win9x and NT4.
[wine/multimedia.git] / dlls / urlmon / internet.c
blob8bde7b4790fe859e9c98f6eba3b1a89ea9fcde37
1 /*
2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "winreg.h"
21 #include "shlwapi.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
27 static HRESULT parse_schema(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
29 WCHAR *ptr;
30 DWORD len = 0;
32 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
34 if(flags)
35 ERR("wrong flags\n");
37 ptr = strchrW(url, ':');
38 if(ptr)
39 len = ptr-url;
41 if(len >= size)
42 return E_POINTER;
44 if(len)
45 memcpy(result, url, len*sizeof(WCHAR));
46 result[len] = 0;
48 if(rsize)
49 *rsize = len;
51 return S_OK;
54 static HRESULT parse_canonicalize_url(LPCWSTR url, DWORD flags, LPWSTR result,
55 DWORD size, DWORD *rsize)
57 IInternetProtocolInfo *protocol_info;
58 DWORD prsize = size;
59 HRESULT hres;
61 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
63 protocol_info = get_protocol_info(url);
65 if(protocol_info) {
66 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_CANONICALIZE,
67 flags, result, size, rsize, 0);
68 IInternetProtocolInfo_Release(protocol_info);
69 if(SUCCEEDED(hres))
70 return hres;
73 hres = UrlCanonicalizeW(url, result, &prsize, flags);
75 if(rsize)
76 *rsize = prsize;
77 return hres;
80 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
82 IInternetProtocolInfo *protocol_info;
83 HRESULT hres;
85 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
87 protocol_info = get_protocol_info(url);
89 if(protocol_info) {
90 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
91 flags, result, size, rsize, 0);
92 IInternetProtocolInfo_Release(protocol_info);
93 return hres;
96 return E_FAIL;
99 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
101 IInternetProtocolInfo *protocol_info;
102 DWORD prsize;
103 HRESULT hres;
105 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
107 protocol_info = get_protocol_info(url);
109 if(protocol_info) {
110 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
111 flags, result, size, rsize, 0);
112 IInternetProtocolInfo_Release(protocol_info);
113 if(SUCCEEDED(hres))
114 return hres;
117 prsize = size;
118 hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
120 if(rsize)
121 *rsize = prsize;
123 return hres;
126 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
128 IInternetProtocolInfo *protocol_info;
129 DWORD prsize;
130 HRESULT hres;
132 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
134 protocol_info = get_protocol_info(url);
136 if(protocol_info) {
137 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
138 flags, result, size, rsize, 0);
139 IInternetProtocolInfo_Release(protocol_info);
140 if(SUCCEEDED(hres))
141 return hres;
144 prsize = size;
145 hres = PathCreateFromUrlW(url, result, &prsize, 0);
147 if(rsize)
148 *rsize = prsize;
149 return hres;
152 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
153 DWORD size, DWORD *rsize)
155 IInternetProtocolInfo *protocol_info;
156 HRESULT hres;
158 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
160 protocol_info = get_protocol_info(url);
162 if(protocol_info) {
163 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
164 flags, result, size, rsize, 0);
165 IInternetProtocolInfo_Release(protocol_info);
166 if(SUCCEEDED(hres))
167 return hres;
170 return E_FAIL;
173 /**************************************************************************
174 * CoInternetParseUrl (URLMON.@)
176 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
177 LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
179 if(dwReserved)
180 WARN("dwReserved = %d\n", dwReserved);
182 switch(ParseAction) {
183 case PARSE_CANONICALIZE:
184 return parse_canonicalize_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
185 case PARSE_SECURITY_URL:
186 return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
187 case PARSE_ENCODE:
188 return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
189 case PARSE_PATH_FROM_URL:
190 return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
191 case PARSE_SCHEMA:
192 return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
193 case PARSE_SECURITY_DOMAIN:
194 return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
195 default:
196 FIXME("not supported action %d\n", ParseAction);
199 return E_NOTIMPL;
202 /**************************************************************************
203 * CoInternetCombineUrl (URLMON.@)
205 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
206 DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
207 DWORD dwReserved)
209 IInternetProtocolInfo *protocol_info;
210 DWORD size = cchResult;
211 HRESULT hres;
213 TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl),
214 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
215 dwReserved);
217 protocol_info = get_protocol_info(pwzBaseUrl);
219 if(protocol_info) {
220 hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl,
221 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
222 IInternetProtocolInfo_Release(protocol_info);
223 if(SUCCEEDED(hres))
224 return hres;
228 hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
230 if(pcchResult)
231 *pcchResult = size;
233 return hres;
236 /**************************************************************************
237 * CoInternetCompareUrl (URLMON.@)
239 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
241 IInternetProtocolInfo *protocol_info;
242 HRESULT hres;
244 TRACE("(%s,%s,%08x)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
246 protocol_info = get_protocol_info(pwzUrl1);
248 if(protocol_info) {
249 hres = IInternetProtocolInfo_CompareUrl(protocol_info, pwzUrl1, pwzUrl2, dwCompareFlags);
250 IInternetProtocolInfo_Release(protocol_info);
251 if(SUCCEEDED(hres))
252 return hres;
255 return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags) ? S_FALSE : S_OK;
258 /***********************************************************************
259 * CoInternetQueryInfo (URLMON.@)
261 * Retrieves information relevant to a specified URL
264 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
265 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD *pcbBuffer,
266 DWORD dwReserved)
268 IInternetProtocolInfo *protocol_info;
269 HRESULT hres;
271 TRACE("(%s, %x, %x, %p, %x, %p, %x): stub\n", debugstr_w(pwzUrl),
272 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
274 protocol_info = get_protocol_info(pwzUrl);
276 if(protocol_info) {
277 hres = IInternetProtocolInfo_QueryInfo(protocol_info, pwzUrl, QueryOption, dwQueryFlags,
278 pvBuffer, cbBuffer, pcbBuffer, dwReserved);
279 IInternetProtocolInfo_Release(protocol_info);
281 return SUCCEEDED(hres) ? hres : E_FAIL;
284 switch(QueryOption) {
285 case QUERY_USES_NETWORK:
286 if(!pvBuffer || cbBuffer < sizeof(DWORD))
287 return E_FAIL;
289 *(DWORD*)pvBuffer = 0;
290 if(pcbBuffer)
291 *pcbBuffer = sizeof(DWORD);
292 break;
294 default:
295 FIXME("Not supported option %d\n", QueryOption);
296 return E_NOTIMPL;
299 return S_OK;
302 /***********************************************************************
303 * CoInternetSetFeatureEnabled (URLMON.@)
305 HRESULT WINAPI CoInternetSetFeatureEnabled(INTERNETFEATURELIST feature, DWORD flags, BOOL enable)
307 FIXME("%d, 0x%08x, %x, stub\n", feature, flags, enable);
308 return E_NOTIMPL;