urlmon: Added registering name space test.
[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 %08lx %p %ld %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_security_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
65 {
66     IInternetProtocolInfo *protocol_info;
67     HRESULT hres;
68
69     TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
70
71     protocol_info = get_protocol_info(url);
72
73     if(protocol_info) {
74         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL,
75                 flags, result, size, rsize, 0);
76         return hres;
77     }
78
79     return E_FAIL;
80 }
81
82 static HRESULT parse_encode(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
83 {
84     IInternetProtocolInfo *protocol_info;
85     DWORD prsize;
86     HRESULT hres;
87
88     TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
89
90     protocol_info = get_protocol_info(url);
91
92     if(protocol_info) {
93         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_ENCODE,
94                 flags, result, size, rsize, 0);
95         if(SUCCEEDED(hres))
96             return hres;
97     }
98
99     prsize = size;
100     hres = UrlUnescapeW((LPWSTR)url, result, &prsize, flags);
101
102     if(rsize)
103         *rsize = prsize;
104
105     return hres;
106 }
107
108 static HRESULT parse_path_from_url(LPCWSTR url, DWORD flags, LPWSTR result, DWORD size, DWORD *rsize)
109 {
110     IInternetProtocolInfo *protocol_info;
111     DWORD prsize;
112     HRESULT hres;
113
114     TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
115
116     protocol_info = get_protocol_info(url);
117
118     if(protocol_info) {
119         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_PATH_FROM_URL,
120                 flags, result, size, rsize, 0);
121         if(SUCCEEDED(hres))
122             return hres;
123     }
124
125     prsize = size;
126     hres = PathCreateFromUrlW(url, result, &prsize, 0);
127
128     if(rsize)
129         *rsize = prsize;
130     return hres;
131 }
132
133 static HRESULT parse_security_domain(LPCWSTR url, DWORD flags, LPWSTR result,
134         DWORD size, DWORD *rsize)
135 {
136     IInternetProtocolInfo *protocol_info;
137     HRESULT hres;
138
139     TRACE("(%s %08lx %p %ld %p)\n", debugstr_w(url), flags, result, size, rsize);
140
141     protocol_info = get_protocol_info(url);
142
143     if(protocol_info) {
144         hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN,
145                 flags, result, size, rsize, 0);
146         if(SUCCEEDED(hres))
147             return hres;
148     }
149
150     return E_FAIL;
151 }
152
153 /**************************************************************************
154  *          CoInternetParseUrl    (URLMON.@)
155  */
156 HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
157         LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
158 {
159     if(dwReserved)
160         WARN("dwReserved = %ld\n", dwReserved);
161
162     switch(ParseAction) {
163     case PARSE_SECURITY_URL:
164         return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
165     case PARSE_ENCODE:
166         return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
167     case PARSE_PATH_FROM_URL:
168         return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
169     case PARSE_SCHEMA:
170         return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
171     case PARSE_SECURITY_DOMAIN:
172         return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
173     default:
174         FIXME("not supported action %d\n", ParseAction);
175     }
176
177     return E_NOTIMPL;
178 }
179
180 /**************************************************************************
181  *          CoInternetCombineUrl    (URLMON.@)
182  */
183 HRESULT WINAPI CoInternetCombineUrl(LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl,
184         DWORD dwCombineFlags, LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult,
185         DWORD dwReserved)
186 {
187     IInternetProtocolInfo *protocol_info;
188     DWORD size = cchResult;
189     HRESULT hres;
190     
191     TRACE("(%s,%s,0x%08lx,%p,%ld,%p,%ld)\n", debugstr_w(pwzBaseUrl),
192           debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult, pcchResult,
193           dwReserved);
194
195     protocol_info = get_protocol_info(pwzBaseUrl);
196
197     if(protocol_info) {
198         hres = IInternetProtocolInfo_CombineUrl(protocol_info, pwzBaseUrl, pwzRelativeUrl,
199                 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved);
200         if(SUCCEEDED(hres))
201             return hres;
202     }
203
204
205     hres = UrlCombineW(pwzBaseUrl, pwzRelativeUrl, pwzResult, &size, dwCombineFlags);
206
207     if(pcchResult)
208         *pcchResult = size;
209
210     return hres;
211 }