user32: Renamed the user/ directory to user32.
[wine.git] / dlls / urlmon / internet.c
blob0897e93d7eaab23dfe585f0973e04ffef7fb0f61
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "shlwapi.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "urlmon_main.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37 static HRESULT parse_schema(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
39 WCHAR *ptr;
40 DWORD len = 0;
42 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
44 if(flags)
45 ERR("wrong flags\n");
47 ptr = strchrW(url, ':');
48 if(ptr)
49 len = ptr-url;
51 if(len >= size)
52 return E_POINTER;
54 if(len)
55 memcpy(result, url, len*sizeof(WCHAR));
56 result[len] = 0;
58 if(rsize)
59 *rsize = len;
61 return S_OK;
64 static HRESULT parse_canonicalize_url(LPCWSTR url, DWORD flags, LPWSTR result,
65 DWORD size, DWORD *rsize)
67 IInternetProtocolInfo *protocol_info;
68 DWORD prsize = size;
69 HRESULT hres;
71 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
73 protocol_info = get_protocol_info(url);
75 if(protocol_info) {
76 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_CANONICALIZE,
77 flags, result, size, rsize, 0);
78 if(SUCCEEDED(hres))
79 return hres;
82 hres = UrlCanonicalizeW(url, result, &prsize, flags);
84 if(rsize)
85 *rsize = prsize;
86 return hres;
89 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
91 IInternetProtocolInfo *protocol_info;
92 HRESULT hres;
94 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
96 protocol_info = get_protocol_info(url);
98 if(protocol_info) {
99 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
100 flags, result, size, rsize, 0);
101 return hres;
104 return E_FAIL;
107 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
109 IInternetProtocolInfo *protocol_info;
110 DWORD prsize;
111 HRESULT hres;
113 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
115 protocol_info = get_protocol_info(url);
117 if(protocol_info) {
118 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
119 flags, result, size, rsize, 0);
120 if(SUCCEEDED(hres))
121 return hres;
124 prsize = size;
125 hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
127 if(rsize)
128 *rsize = prsize;
130 return hres;
133 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
135 IInternetProtocolInfo *protocol_info;
136 DWORD prsize;
137 HRESULT hres;
139 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
141 protocol_info = get_protocol_info(url);
143 if(protocol_info) {
144 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
145 flags, result, size, rsize, 0);
146 if(SUCCEEDED(hres))
147 return hres;
150 prsize = size;
151 hres = PathCreateFromUrlW(url, result, &prsize, 0);
153 if(rsize)
154 *rsize = prsize;
155 return hres;
158 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
159 DWORD size, DWORD *rsize)
161 IInternetProtocolInfo *protocol_info;
162 HRESULT hres;
164 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
166 protocol_info = get_protocol_info(url);
168 if(protocol_info) {
169 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
170 flags, result, size, rsize, 0);
171 if(SUCCEEDED(hres))
172 return hres;
175 return E_FAIL;
178 /**************************************************************************
179 * CoInternetParseUrl (URLMON.@)
181 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
182 LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
184 if(dwReserved)
185 WARN("dwReserved = %d\n", dwReserved);
187 switch(ParseAction) {
188 case PARSE_CANONICALIZE:
189 return parse_canonicalize_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
190 case PARSE_SECURITY_URL:
191 return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
192 case PARSE_ENCODE:
193 return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
194 case PARSE_PATH_FROM_URL:
195 return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
196 case PARSE_SCHEMA:
197 return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
198 case PARSE_SECURITY_DOMAIN:
199 return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
200 default:
201 FIXME("not supported action %d\n", ParseAction);
204 return E_NOTIMPL;
207 /**************************************************************************
208 * CoInternetCombineUrl (URLMON.@)
210 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
211 DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
212 DWORD dwReserved)
214 IInternetProtocolInfo *protocol_info;
215 DWORD size = cchResult;
216 HRESULT hres;
218 TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl),
219 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
220 dwReserved);
222 protocol_info = get_protocol_info(pwzBaseUrl);
224 if(protocol_info) {
225 hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl,
226 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
227 if(SUCCEEDED(hres))
228 return hres;
232 hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
234 if(pcchResult)
235 *pcchResult = size;
237 return hres;