cryptnet: Implement CryptRetrieveObjectByUrlW for the http protocol.
[wine] / dlls / urlmon / internet.c
1 /*
2  * Copyright 2005 Jacek Caban
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
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"
31
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
36
37 static HRESULT parse_schema(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
38 {
39     WCHAR *ptr;
40     DWORD len = 0;
41
42     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
43
44     if(flags)
45         ERR("wrong flags\n");
46     
47     ptr = strchrW(url, ':');
48     if(ptr)
49         len = ptr-url;
50
51     if(len >= size)
52         return E_POINTER;
53
54     if(len)
55         memcpy(result, url, len*sizeof(WCHAR));
56     result[len] = 0;
57
58     if(rsize)
59         *rsize = len;
60
61     return S_OK;
62 }
63
64 static HRESULT parse_canonicalize_url(LPCWSTR url, DWORD flags, LPWSTR result,
65         DWORD size, DWORD *rsize)
66 {
67     IInternetProtocolInfo *protocol_info;
68     DWORD prsize = size;
69     HRESULT hres;
70
71     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
72
73     protocol_info = get_protocol_info(url);
74
75     if(protocol_info) {
76         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_CANONICALIZE,
77                 flags, result, size, rsize, 0);
78         IInternetProtocolInfo_Release(protocol_info);
79         if(SUCCEEDED(hres))
80             return hres;
81     }
82
83     hres = UrlCanonicalizeW(url, result, &prsize, flags);
84
85     if(rsize)
86         *rsize = prsize;
87     return hres;
88 }
89
90 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
91 {
92     IInternetProtocolInfo *protocol_info;
93     HRESULT hres;
94
95     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
96
97     protocol_info = get_protocol_info(url);
98
99     if(protocol_info) {
100         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
101                 flags, result, size, rsize, 0);
102         IInternetProtocolInfo_Release(protocol_info);
103         return hres;
104     }
105
106     return E_FAIL;
107 }
108
109 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
110 {
111     IInternetProtocolInfo *protocol_info;
112     DWORD prsize;
113     HRESULT hres;
114
115     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
116
117     protocol_info = get_protocol_info(url);
118
119     if(protocol_info) {
120         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
121                 flags, result, size, rsize, 0);
122         IInternetProtocolInfo_Release(protocol_info);
123         if(SUCCEEDED(hres))
124             return hres;
125     }
126
127     prsize = size;
128     hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
129
130     if(rsize)
131         *rsize = prsize;
132
133     return hres;
134 }
135
136 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
137 {
138     IInternetProtocolInfo *protocol_info;
139     DWORD prsize;
140     HRESULT hres;
141
142     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
143
144     protocol_info = get_protocol_info(url);
145
146     if(protocol_info) {
147         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
148                 flags, result, size, rsize, 0);
149         IInternetProtocolInfo_Release(protocol_info);
150         if(SUCCEEDED(hres))
151             return hres;
152     }
153
154     prsize = size;
155     hres = PathCreateFromUrlW(url, result, &prsize, 0);
156
157     if(rsize)
158         *rsize = prsize;
159     return hres;
160 }
161
162 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
163         DWORD size, DWORD *rsize)
164 {
165     IInternetProtocolInfo *protocol_info;
166     HRESULT hres;
167
168     TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
169
170     protocol_info = get_protocol_info(url);
171
172     if(protocol_info) {
173         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
174                 flags, result, size, rsize, 0);
175         IInternetProtocolInfo_Release(protocol_info);
176         if(SUCCEEDED(hres))
177             return hres;
178     }
179
180     return E_FAIL;
181 }
182
183 /**************************************************************************
184  *          CoInternetParseUrl    (URLMON.@)
185  */
186 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
187         LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
188 {
189     if(dwReserved)
190         WARN("dwReserved = %d\n", dwReserved);
191
192     switch(ParseAction) {
193     case PARSE_CANONICALIZE:
194         return parse_canonicalize_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
195     case PARSE_SECURITY_URL:
196         return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
197     case PARSE_ENCODE:
198         return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
199     case PARSE_PATH_FROM_URL:
200         return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
201     case PARSE_SCHEMA:
202         return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
203     case PARSE_SECURITY_DOMAIN:
204         return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
205     default:
206         FIXME("not supported action %d\n", ParseAction);
207     }
208
209     return E_NOTIMPL;
210 }
211
212 /**************************************************************************
213  *          CoInternetCombineUrl    (URLMON.@)
214  */
215 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
216         DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
217         DWORD dwReserved)
218 {
219     IInternetProtocolInfo *protocol_info;
220     DWORD size = cchResult;
221     HRESULT hres;
222     
223     TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl),
224           debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
225           dwReserved);
226
227     protocol_info = get_protocol_info(pwzBaseUrl);
228
229     if(protocol_info) {
230         hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl,
231                 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
232         IInternetProtocolInfo_Release(protocol_info);
233         if(SUCCEEDED(hres))
234             return hres;
235     }
236
237
238     hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
239
240     if(pcchResult)
241         *pcchResult = size;
242
243     return hres;
244 }
245
246 /**************************************************************************
247  *          CoInternetCompareUrl    (URLMON.@)
248  */
249 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
250 {
251     IInternetProtocolInfo *protocol_info;
252     HRESULT hres;
253
254     TRACE("(%s,%s,%08x)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
255
256     protocol_info = get_protocol_info(pwzUrl1);
257
258     if(protocol_info) {
259         hres = IInternetProtocolInfo_CompareUrl(protocol_info, pwzUrl1, pwzUrl2, dwCompareFlags);
260         IInternetProtocolInfo_Release(protocol_info);
261         if(SUCCEEDED(hres))
262             return hres;
263     }
264
265     return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags) ? S_FALSE : S_OK;
266 }