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