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"
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)
32 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
37 ptr = strchrW(url, ':');
48 memcpy(result, url, len*sizeof(WCHAR));
54 static HRESULT parse_canonicalize_url(LPCWSTR url, DWORD flags, LPWSTR result,
55 DWORD size, DWORD *rsize)
57 IInternetProtocolInfo *protocol_info;
61 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
63 protocol_info = get_protocol_info(url);
66 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_CANONICALIZE,
67 flags, result, size, rsize, 0);
68 IInternetProtocolInfo_Release(protocol_info);
73 hres = UrlCanonicalizeW(url, result, &prsize, flags);
80 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
82 IInternetProtocolInfo *protocol_info;
85 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
87 protocol_info = get_protocol_info(url);
90 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
91 flags, result, size, rsize, 0);
92 IInternetProtocolInfo_Release(protocol_info);
99 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
101 IInternetProtocolInfo *protocol_info;
105 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
107 protocol_info = get_protocol_info(url);
110 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
111 flags, result, size, rsize, 0);
112 IInternetProtocolInfo_Release(protocol_info);
118 hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
126 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
128 IInternetProtocolInfo *protocol_info;
132 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
134 protocol_info = get_protocol_info(url);
137 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
138 flags, result, size, rsize, 0);
139 IInternetProtocolInfo_Release(protocol_info);
145 hres = PathCreateFromUrlW(url, result, &prsize, 0);
152 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
153 DWORD size, DWORD *rsize)
155 IInternetProtocolInfo *protocol_info;
158 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
160 protocol_info = get_protocol_info(url);
163 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
164 flags, result, size, rsize, 0);
165 IInternetProtocolInfo_Release(protocol_info);
173 static HRESULT parse_domain(LPCWSTR url, DWORD flags, LPWSTR result,
174 DWORD size, DWORD *rsize)
176 IInternetProtocolInfo *protocol_info;
179 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
181 protocol_info = get_protocol_info(url);
184 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_DOMAIN,
185 flags, result, size, rsize, 0);
186 IInternetProtocolInfo_Release(protocol_info);
191 hres = UrlGetPartW(url, result, &size, URL_PART_HOSTNAME, flags);
195 if(hres == E_POINTER)
203 static HRESULT parse_rootdocument(LPCWSTR url, DWORD flags, LPWSTR result,
204 DWORD size, DWORD *rsize)
206 IInternetProtocolInfo *protocol_info;
210 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
212 protocol_info = get_protocol_info(url);
215 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ROOTDOCUMENT,
216 flags, result, size, rsize, 0);
217 IInternetProtocolInfo_Release(protocol_info);
222 url_info.cbSize = sizeof(url_info);
223 if(FAILED(ParseURLW(url, &url_info)))
226 switch(url_info.nScheme) {
228 case URL_SCHEME_HTTP:
229 case URL_SCHEME_HTTPS:
230 if(url_info.cchSuffix<3 || *(url_info.pszSuffix)!='/'
231 || *(url_info.pszSuffix+1)!='/')
234 if(size < url_info.cchProtocol+3) {
236 hres = UrlGetPartW(url, result, &size, URL_PART_HOSTNAME, flags);
239 *rsize = size+url_info.cchProtocol+3;
241 if(hres == E_POINTER)
247 size -= url_info.cchProtocol+3;
248 hres = UrlGetPartW(url, result+url_info.cchProtocol+3,
249 &size, URL_PART_HOSTNAME, flags);
251 if(hres == E_POINTER)
258 *rsize = size+url_info.cchProtocol+3;
260 memcpy(result, url, (url_info.cchProtocol+3)*sizeof(WCHAR));
267 /**************************************************************************
268 * CoInternetParseUrl (URLMON.@)
270 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
271 LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
274 WARN("dwReserved = %d\n", dwReserved);
276 switch(ParseAction) {
277 case PARSE_CANONICALIZE:
278 return parse_canonicalize_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
279 case PARSE_SECURITY_URL:
280 return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
282 return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
283 case PARSE_PATH_FROM_URL:
284 return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
286 return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
287 case PARSE_SECURITY_DOMAIN:
288 return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
290 return parse_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
291 case PARSE_ROOTDOCUMENT:
292 return parse_rootdocument(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
294 FIXME("not supported action %d\n", ParseAction);
300 /**************************************************************************
301 * CoInternetCombineUrl (URLMON.@)
303 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
304 DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
307 IInternetProtocolInfo *protocol_info;
308 DWORD size = cchResult;
311 TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl),
312 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
315 protocol_info = get_protocol_info(pwzBaseUrl);
318 hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl,
319 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
320 IInternetProtocolInfo_Release(protocol_info);
326 hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
334 /**************************************************************************
335 * CoInternetCompareUrl (URLMON.@)
337 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
339 IInternetProtocolInfo *protocol_info;
342 TRACE("(%s,%s,%08x)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
344 protocol_info = get_protocol_info(pwzUrl1);
347 hres = IInternetProtocolInfo_CompareUrl(protocol_info, pwzUrl1, pwzUrl2, dwCompareFlags);
348 IInternetProtocolInfo_Release(protocol_info);
353 return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags) ? S_FALSE : S_OK;
356 /***********************************************************************
357 * CoInternetQueryInfo (URLMON.@)
359 * Retrieves information relevant to a specified URL
362 HRESULT WINAPI CoInternetQueryInfo(LPCWSTR pwzUrl, QUERYOPTION QueryOption,
363 DWORD dwQueryFlags, LPVOID pvBuffer, DWORD cbBuffer, DWORD *pcbBuffer,
366 IInternetProtocolInfo *protocol_info;
369 TRACE("(%s, %x, %x, %p, %x, %p, %x): stub\n", debugstr_w(pwzUrl),
370 QueryOption, dwQueryFlags, pvBuffer, cbBuffer, pcbBuffer, dwReserved);
372 protocol_info = get_protocol_info(pwzUrl);
375 hres = IInternetProtocolInfo_QueryInfo(protocol_info, pwzUrl, QueryOption, dwQueryFlags,
376 pvBuffer, cbBuffer, pcbBuffer, dwReserved);
377 IInternetProtocolInfo_Release(protocol_info);
379 return SUCCEEDED(hres) ? hres : E_FAIL;
382 switch(QueryOption) {
383 case QUERY_USES_NETWORK:
384 if(!pvBuffer || cbBuffer < sizeof(DWORD))
387 *(DWORD*)pvBuffer = 0;
389 *pcbBuffer = sizeof(DWORD);
393 FIXME("Not supported option %d\n", QueryOption);
400 /***********************************************************************
401 * CoInternetSetFeatureEnabled (URLMON.@)
403 HRESULT WINAPI CoInternetSetFeatureEnabled(INTERNETFEATURELIST feature, DWORD flags, BOOL enable)
405 FIXME("%d, 0x%08x, %x, stub\n", feature, flags, enable);