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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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)
42 TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
47 ptr = strchrW(url, ':');
55 memcpy(result, url, len*sizeof(WCHAR));
64 static IInternetProtocolInfo *get_protocol_info(LPCWSTR url)
66 IInternetProtocolInfo *ret = NULL;
67 WCHAR schema[64], str_clsid[64];
69 DWORD res, type, size, schema_len;
74 static const WCHAR wszProtocolsKey[] =
75 {'P','R','O','T','O','C','O','L','S','\\','H','a','n','d','l','e','r','\\'};
76 static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
78 hres = parse_schema(url, 0, schema, sizeof(schema)/sizeof(schema[0]), &schema_len);
79 if(FAILED(hres) || !schema_len)
82 wszKey = HeapAlloc(GetProcessHeap(), 0, sizeof(wszProtocolsKey)+(schema_len+1)*sizeof(WCHAR));
83 memcpy(wszKey, wszProtocolsKey, sizeof(wszProtocolsKey));
84 memcpy(wszKey + sizeof(wszProtocolsKey)/sizeof(WCHAR), schema, (schema_len+1)*sizeof(WCHAR));
86 res = RegOpenKeyW(HKEY_CLASSES_ROOT, wszKey, &hkey);
87 HeapFree(GetProcessHeap(), 0, wszKey);
88 if(res != ERROR_SUCCESS) {
89 TRACE("Could not open key %s\n", debugstr_w(wszKey));
93 size = sizeof(str_clsid);
94 res = RegQueryValueExW(hkey, wszCLSID, NULL, &type, (LPBYTE)str_clsid, &size);
96 if(res != ERROR_SUCCESS || type != REG_SZ) {
97 WARN("Could not get protocol CLSID res=%ld\n", res);
101 hres = CLSIDFromString(str_clsid, &clsid);
103 WARN("CLSIDFromString failed: %08lx\n", hres);
107 CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IInternetProtocolInfo, (void**)&ret);
111 static HRESULT parse_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
113 IInternetProtocolInfo *protocol_info;
116 TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
118 protocol_info = get_protocol_info(url);
121 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
122 flags, result, size, rsize, 0);
129 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
131 IInternetProtocolInfo *protocol_info;
135 TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
137 protocol_info = get_protocol_info(url);
140 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
141 flags, result, size, rsize, 0);
147 hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
155 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
157 IInternetProtocolInfo *protocol_info;
161 TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
163 protocol_info = get_protocol_info(url);
166 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
167 flags, result, size, rsize, 0);
173 hres = PathCreateFromUrlW(url, result, &prsize, 0);
180 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
181 DWORD size, DWORD *rsize)
183 IInternetProtocolInfo *protocol_info;
186 TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
188 protocol_info = get_protocol_info(url);
191 hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
192 flags, result, size, rsize, 0);
201 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
202 LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
205 WARN("dwReserved = %ld\n", dwReserved);
207 switch(ParseAction) {
208 case PARSE_SECURITY_URL:
209 return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
211 return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
212 case PARSE_PATH_FROM_URL:
213 return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
215 return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
216 case PARSE_SECURITY_DOMAIN:
217 return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
219 FIXME("not supported action %d\n", ParseAction);