wined3d: BaseVertexIndex can be negative.
[wine.git] / dlls / urlmon / internet.c
blob26269823610a0504a41b17bbaadda71bdc2fff67
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 IInternetProtocolInfo_Release(protocol_info);
79 if(SUCCEEDED(hres))
80 return hres;
83 hres = UrlCanonicalizeW(url, result, &prsize, flags);
85 if(rsize)
86 *rsize = prsize;
87 return hres;
90 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
92 IInternetProtocolInfo *protocol_info;
93 HRESULT hres;
95 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
97 protocol_info = get_protocol_info(url);
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;
106 return E_FAIL;
109 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
111 IInternetProtocolInfo *protocol_info;
112 DWORD prsize;
113 HRESULT hres;
115 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
117 protocol_info = get_protocol_info(url);
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;
127 prsize = size;
128 hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
130 if(rsize)
131 *rsize = prsize;
133 return hres;
136 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
138 IInternetProtocolInfo *protocol_info;
139 DWORD prsize;
140 HRESULT hres;
142 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
144 protocol_info = get_protocol_info(url);
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;
154 prsize = size;
155 hres = PathCreateFromUrlW(url, result, &prsize, 0);
157 if(rsize)
158 *rsize = prsize;
159 return hres;
162 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
163 DWORD size, DWORD *rsize)
165 IInternetProtocolInfo *protocol_info;
166 HRESULT hres;
168 TRACE("(%s %08x %p %d %p)\n", debugstr_w(url), flags, result, size, rsize);
170 protocol_info = get_protocol_info(url);
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;
180 return E_FAIL;
183 /**************************************************************************
184 * CoInternetParseUrl (URLMON.@)
186 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
187 LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
189 if(dwReserved)
190 WARN("dwReserved = %d\n", dwReserved);
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);
209 return E_NOTIMPL;
212 /**************************************************************************
213 * CoInternetCombineUrl (URLMON.@)
215 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
216 DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
217 DWORD dwReserved)
219 IInternetProtocolInfo *protocol_info;
220 DWORD size = cchResult;
221 HRESULT hres;
223 TRACE("(%s,%s,0x%08x,%p,%d,%p,%d)\n", debugstr_w(pwzBaseUrl),
224 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
225 dwReserved);
227 protocol_info = get_protocol_info(pwzBaseUrl);
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;
238 hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
240 if(pcchResult)
241 *pcchResult = size;
243 return hres;
246 /**************************************************************************
247 * CoInternetCompareUrl (URLMON.@)
249 HRESULT WINAPI CoInternetCompareUrl(LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
251 IInternetProtocolInfo *protocol_info;
252 HRESULT hres;
254 TRACE("(%s,%s,%08x)\n", debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
256 protocol_info = get_protocol_info(pwzUrl1);
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;
265 return UrlCompareW(pwzUrl1, pwzUrl2, dwCompareFlags) ? S_FALSE : S_OK;