4 * Copyright 2000 Huw D M Davies for CodeWeavers.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
30 #include "wine/unicode.h"
34 #define NO_SHLWAPI_STREAM
37 #include "wine/debug.h"
39 HMODULE WINAPI MLLoadLibraryW(LPCWSTR,HMODULE,DWORD);
40 BOOL WINAPI MLFreeLibrary(HMODULE);
41 HRESULT WINAPI MLBuildResURLW(LPCWSTR,HMODULE,DWORD,LPCWSTR,LPWSTR,DWORD);
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
45 /* The following schemes were identified in the native version of
46 * SHLWAPI.DLL version 5.50
49 URL_SCHEME scheme_number;
50 WCHAR scheme_name[12];
51 } shlwapi_schemes[] = {
52 {URL_SCHEME_FTP, {'f','t','p',0}},
53 {URL_SCHEME_HTTP, {'h','t','t','p',0}},
54 {URL_SCHEME_GOPHER, {'g','o','p','h','e','r',0}},
55 {URL_SCHEME_MAILTO, {'m','a','i','l','t','o',0}},
56 {URL_SCHEME_NEWS, {'n','e','w','s',0}},
57 {URL_SCHEME_NNTP, {'n','n','t','p',0}},
58 {URL_SCHEME_TELNET, {'t','e','l','n','e','t',0}},
59 {URL_SCHEME_WAIS, {'w','a','i','s',0}},
60 {URL_SCHEME_FILE, {'f','i','l','e',0}},
61 {URL_SCHEME_MK, {'m','k',0}},
62 {URL_SCHEME_HTTPS, {'h','t','t','p','s',0}},
63 {URL_SCHEME_SHELL, {'s','h','e','l','l',0}},
64 {URL_SCHEME_SNEWS, {'s','n','e','w','s',0}},
65 {URL_SCHEME_LOCAL, {'l','o','c','a','l',0}},
66 {URL_SCHEME_JAVASCRIPT, {'j','a','v','a','s','c','r','i','p','t',0}},
67 {URL_SCHEME_VBSCRIPT, {'v','b','s','c','r','i','p','t',0}},
68 {URL_SCHEME_ABOUT, {'a','b','o','u','t',0}},
69 {URL_SCHEME_RES, {'r','e','s',0}},
73 LPCWSTR pScheme; /* [out] start of scheme */
74 DWORD szScheme; /* [out] size of scheme (until colon) */
75 LPCWSTR pUserName; /* [out] start of Username */
76 DWORD szUserName; /* [out] size of Username (until ":" or "@") */
77 LPCWSTR pPassword; /* [out] start of Password */
78 DWORD szPassword; /* [out] size of Password (until "@") */
79 LPCWSTR pHostName; /* [out] start of Hostname */
80 DWORD szHostName; /* [out] size of Hostname (until ":" or "/") */
81 LPCWSTR pPort; /* [out] start of Port */
82 DWORD szPort; /* [out] size of Port (until "/" or eos) */
83 LPCWSTR pQuery; /* [out] start of Query */
84 DWORD szQuery; /* [out] size of Query (until eos) */
94 static const CHAR hexDigits[] = "0123456789ABCDEF";
96 static const WCHAR fileW[] = {'f','i','l','e','\0'};
98 static const unsigned char HashDataLookup[256] = {
99 0x01, 0x0E, 0x6E, 0x19, 0x61, 0xAE, 0x84, 0x77, 0x8A, 0xAA, 0x7D, 0x76, 0x1B,
100 0xE9, 0x8C, 0x33, 0x57, 0xC5, 0xB1, 0x6B, 0xEA, 0xA9, 0x38, 0x44, 0x1E, 0x07,
101 0xAD, 0x49, 0xBC, 0x28, 0x24, 0x41, 0x31, 0xD5, 0x68, 0xBE, 0x39, 0xD3, 0x94,
102 0xDF, 0x30, 0x73, 0x0F, 0x02, 0x43, 0xBA, 0xD2, 0x1C, 0x0C, 0xB5, 0x67, 0x46,
103 0x16, 0x3A, 0x4B, 0x4E, 0xB7, 0xA7, 0xEE, 0x9D, 0x7C, 0x93, 0xAC, 0x90, 0xB0,
104 0xA1, 0x8D, 0x56, 0x3C, 0x42, 0x80, 0x53, 0x9C, 0xF1, 0x4F, 0x2E, 0xA8, 0xC6,
105 0x29, 0xFE, 0xB2, 0x55, 0xFD, 0xED, 0xFA, 0x9A, 0x85, 0x58, 0x23, 0xCE, 0x5F,
106 0x74, 0xFC, 0xC0, 0x36, 0xDD, 0x66, 0xDA, 0xFF, 0xF0, 0x52, 0x6A, 0x9E, 0xC9,
107 0x3D, 0x03, 0x59, 0x09, 0x2A, 0x9B, 0x9F, 0x5D, 0xA6, 0x50, 0x32, 0x22, 0xAF,
108 0xC3, 0x64, 0x63, 0x1A, 0x96, 0x10, 0x91, 0x04, 0x21, 0x08, 0xBD, 0x79, 0x40,
109 0x4D, 0x48, 0xD0, 0xF5, 0x82, 0x7A, 0x8F, 0x37, 0x69, 0x86, 0x1D, 0xA4, 0xB9,
110 0xC2, 0xC1, 0xEF, 0x65, 0xF2, 0x05, 0xAB, 0x7E, 0x0B, 0x4A, 0x3B, 0x89, 0xE4,
111 0x6C, 0xBF, 0xE8, 0x8B, 0x06, 0x18, 0x51, 0x14, 0x7F, 0x11, 0x5B, 0x5C, 0xFB,
112 0x97, 0xE1, 0xCF, 0x15, 0x62, 0x71, 0x70, 0x54, 0xE2, 0x12, 0xD6, 0xC7, 0xBB,
113 0x0D, 0x20, 0x5E, 0xDC, 0xE0, 0xD4, 0xF7, 0xCC, 0xC4, 0x2B, 0xF9, 0xEC, 0x2D,
114 0xF4, 0x6F, 0xB6, 0x99, 0x88, 0x81, 0x5A, 0xD9, 0xCA, 0x13, 0xA5, 0xE7, 0x47,
115 0xE6, 0x8E, 0x60, 0xE3, 0x3E, 0xB3, 0xF6, 0x72, 0xA2, 0x35, 0xA0, 0xD7, 0xCD,
116 0xB4, 0x2F, 0x6D, 0x2C, 0x26, 0x1F, 0x95, 0x87, 0x00, 0xD8, 0x34, 0x3F, 0x17,
117 0x25, 0x45, 0x27, 0x75, 0x92, 0xB8, 0xA3, 0xC8, 0xDE, 0xEB, 0xF8, 0xF3, 0xDB,
118 0x0A, 0x98, 0x83, 0x7B, 0xE5, 0xCB, 0x4C, 0x78, 0xD1 };
120 static DWORD get_scheme_code(LPCWSTR scheme, DWORD scheme_len)
124 for(i=0; i < sizeof(shlwapi_schemes)/sizeof(shlwapi_schemes[0]); i++) {
125 if(scheme_len == strlenW(shlwapi_schemes[i].scheme_name)
126 && !memcmp(scheme, shlwapi_schemes[i].scheme_name, scheme_len*sizeof(WCHAR)))
127 return shlwapi_schemes[i].scheme_number;
130 return URL_SCHEME_UNKNOWN;
133 /*************************************************************************
136 * Parse a Url into its constituent parts.
140 * y [O] Undocumented structure holding the parsed information
143 * Success: S_OK. y contains the parsed Url details.
144 * Failure: An HRESULT error code.
146 HRESULT WINAPI ParseURLA(LPCSTR x, PARSEDURLA *y)
148 WCHAR scheme[INTERNET_MAX_SCHEME_LENGTH];
152 TRACE("%s %p\n", debugstr_a(x), y);
154 if(y->cbSize != sizeof(*y))
157 while(*ptr && (isalnum(*ptr) || *ptr == '-'))
160 if (*ptr != ':' || ptr <= x+1) {
161 y->pszProtocol = NULL;
162 return URL_E_INVALID_SYNTAX;
166 y->cchProtocol = ptr-x;
167 y->pszSuffix = ptr+1;
168 y->cchSuffix = strlen(y->pszSuffix);
170 len = MultiByteToWideChar(CP_ACP, 0, x, ptr-x,
171 scheme, sizeof(scheme)/sizeof(WCHAR));
172 y->nScheme = get_scheme_code(scheme, len);
177 /*************************************************************************
180 * Unicode version of ParseURLA.
182 HRESULT WINAPI ParseURLW(LPCWSTR x, PARSEDURLW *y)
184 const WCHAR *ptr = x;
186 TRACE("%s %p\n", debugstr_w(x), y);
188 if(y->cbSize != sizeof(*y))
191 while(*ptr && (isalnumW(*ptr) || *ptr == '-'))
194 if (*ptr != ':' || ptr <= x+1) {
195 y->pszProtocol = NULL;
196 return URL_E_INVALID_SYNTAX;
200 y->cchProtocol = ptr-x;
201 y->pszSuffix = ptr+1;
202 y->cchSuffix = strlenW(y->pszSuffix);
203 y->nScheme = get_scheme_code(x, ptr-x);
208 /*************************************************************************
209 * UrlCanonicalizeA [SHLWAPI.@]
211 * Canonicalize a Url.
214 * pszUrl [I] Url to cCanonicalize
215 * pszCanonicalized [O] Destination for converted Url.
216 * pcchCanonicalized [I/O] Length of pszUrl, destination for length of pszCanonicalized
217 * dwFlags [I] Flags controlling the conversion.
220 * Success: S_OK. The pszCanonicalized contains the converted Url.
221 * Failure: E_POINTER, if *pcchCanonicalized is too small.
223 * MSDN incorrectly describes the flags for this function. They should be:
224 *| URL_DONT_ESCAPE_EXTRA_INFO 0x02000000
225 *| URL_ESCAPE_SPACES_ONLY 0x04000000
226 *| URL_ESCAPE_PERCENT 0x00001000
227 *| URL_ESCAPE_UNSAFE 0x10000000
228 *| URL_UNESCAPE 0x10000000
229 *| URL_DONT_SIMPLIFY 0x08000000
230 *| URL_ESCAPE_SEGMENT_ONLY 0x00002000
232 HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized,
233 LPDWORD pcchCanonicalized, DWORD dwFlags)
235 LPWSTR base, canonical;
239 TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_a(pszUrl), pszCanonicalized,
240 pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1);
242 if(!pszUrl || !pszCanonicalized || !pcchCanonicalized)
245 base = HeapAlloc(GetProcessHeap(), 0,
246 (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
247 canonical = base + INTERNET_MAX_URL_LENGTH;
249 MultiByteToWideChar(0, 0, pszUrl, -1, base, INTERNET_MAX_URL_LENGTH);
250 len = INTERNET_MAX_URL_LENGTH;
252 ret = UrlCanonicalizeW(base, canonical, &len, dwFlags);
254 *pcchCanonicalized = len * 2;
255 HeapFree(GetProcessHeap(), 0, base);
259 len2 = WideCharToMultiByte(0, 0, canonical, -1, 0, 0, 0, 0);
260 if (len2 > *pcchCanonicalized) {
261 *pcchCanonicalized = len2;
262 HeapFree(GetProcessHeap(), 0, base);
265 WideCharToMultiByte(0, 0, canonical, -1, pszCanonicalized, *pcchCanonicalized, 0, 0);
266 *pcchCanonicalized = len;
267 HeapFree(GetProcessHeap(), 0, base);
271 /*************************************************************************
272 * UrlCanonicalizeW [SHLWAPI.@]
274 * See UrlCanonicalizeA.
276 HRESULT WINAPI UrlCanonicalizeW(LPCWSTR pszUrl, LPWSTR pszCanonicalized,
277 LPDWORD pcchCanonicalized, DWORD dwFlags)
281 LPWSTR lpszUrlCpy, wk1, wk2, mp, mp2, root;
283 DWORD nByteLen, nLen, nWkLen;
286 static const WCHAR wszFile[] = {'f','i','l','e',':'};
287 static const WCHAR wszRes[] = {'r','e','s',':'};
288 static const WCHAR wszLocalhost[] = {'l','o','c','a','l','h','o','s','t'};
290 TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_w(pszUrl), pszCanonicalized,
291 pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1);
293 if(!pszUrl || !pszCanonicalized || !pcchCanonicalized)
297 *pszCanonicalized = 0;
301 nByteLen = (strlenW(pszUrl) + 1) * sizeof(WCHAR); /* length in bytes */
302 lpszUrlCpy = HeapAlloc(GetProcessHeap(), 0,
303 INTERNET_MAX_URL_LENGTH * sizeof(WCHAR));
305 if((dwFlags & URL_FILE_USE_PATHURL) && nByteLen >= sizeof(wszFile)
306 && !memcmp(wszFile, pszUrl, sizeof(wszFile)))
309 if(nByteLen >= sizeof(wszRes) && !memcmp(wszRes, pszUrl, sizeof(wszRes))) {
310 dwFlags &= ~URL_FILE_USE_PATHURL;
317 * 1 have 2[+] alnum 2,3
318 * 2 have scheme (found :) 4,6,3
319 * 3 failed (no location)
321 * 5 have 1[+] alnum 6,3
322 * 6 have location (found /) save root location
325 wk1 = (LPWSTR)pszUrl;
329 if(pszUrl[1] == ':') { /* Assume path */
330 static const WCHAR wszFilePrefix[] = {'f','i','l','e',':','/','/','/'};
332 memcpy(wk2, wszFilePrefix, sizeof(wszFilePrefix));
333 wk2 += sizeof(wszFilePrefix)/sizeof(WCHAR);
334 if (dwFlags & URL_FILE_USE_PATHURL)
340 dwFlags |= URL_ESCAPE_UNSAFE;
347 if (!isalnumW(*wk1)) {state = 3; break;}
349 if (!isalnumW(*wk1)) {state = 3; break;}
355 if (*wk1++ == ':') state = 2;
359 if (*wk1 != '/') {state = 6; break;}
361 if((dwFlags & URL_FILE_USE_PATHURL) && nByteLen >= sizeof(wszLocalhost)
362 && !strncmpW(wszFile, pszUrl, sizeof(wszFile)/sizeof(WCHAR))
363 && !memcmp(wszLocalhost, wk1, sizeof(wszLocalhost))){
364 wk1 += sizeof(wszLocalhost)/sizeof(WCHAR);
365 while(*wk1 == '\\' && (dwFlags & URL_FILE_USE_PATHURL))
368 if(*wk1 == '/' && (dwFlags & URL_FILE_USE_PATHURL))
373 nWkLen = strlenW(wk1);
374 memcpy(wk2, wk1, (nWkLen + 1) * sizeof(WCHAR));
381 if(*mp == '/' || *mp == '\\')
388 if (!isalnumW(*wk1) && (*wk1 != '-') && (*wk1 != '.') && (*wk1 != ':'))
390 while(isalnumW(*wk1) || (*wk1 == '-') || (*wk1 == '.') || (*wk1 == ':'))
401 if (*wk1 != '/' && *wk1 != '\\') {state = 3; break;}
402 while(*wk1 == '/' || *wk1 == '\\') {
412 if(dwFlags & URL_DONT_SIMPLIFY) {
417 /* Now at root location, cannot back up any more. */
418 /* "root" will point at the '/' */
422 mp = strchrW(wk1, '/');
423 mp2 = strchrW(wk1, '\\');
424 if(mp2 && (!mp || mp2 < mp))
427 nWkLen = strlenW(wk1);
428 memcpy(wk2, wk1, (nWkLen + 1) * sizeof(WCHAR));
435 memcpy(wk2, wk1, nLen * sizeof(WCHAR));
446 TRACE("found '/.'\n");
447 if (wk1[1] == '/' || wk1[1] == '\\') {
448 /* case of /./ -> skip the ./ */
451 else if (wk1[1] == '.') {
452 /* found /.. look for next / */
453 TRACE("found '/..'\n");
454 if (wk1[2] == '/' || wk1[2] == '\\' ||wk1[2] == '?'
455 || wk1[2] == '#' || !wk1[2]) {
456 /* case /../ -> need to backup wk2 */
457 TRACE("found '/../'\n");
458 *(wk2-1) = '\0'; /* set end of string */
459 mp = strrchrW(root, '/');
460 mp2 = strrchrW(root, '\\');
461 if(mp2 && (!mp || mp2 < mp))
463 if (mp && (mp >= root)) {
464 /* found valid backup point */
466 if(wk1[2] != '/' && wk1[2] != '\\')
472 /* did not find point, restore '/' */
482 FIXME("how did we get here - state=%d\n", state);
483 HeapFree(GetProcessHeap(), 0, lpszUrlCpy);
487 TRACE("Simplified, orig <%s>, simple <%s>\n",
488 debugstr_w(pszUrl), debugstr_w(lpszUrlCpy));
490 nLen = lstrlenW(lpszUrlCpy);
491 while ((nLen > 0) && ((lpszUrlCpy[nLen-1] <= ' ')))
492 lpszUrlCpy[--nLen]=0;
494 if(dwFlags & (URL_UNESCAPE | URL_FILE_USE_PATHURL))
495 UrlUnescapeW(lpszUrlCpy, NULL, &nLen, URL_UNESCAPE_INPLACE);
497 if((EscapeFlags = dwFlags & (URL_ESCAPE_UNSAFE |
498 URL_ESCAPE_SPACES_ONLY |
500 URL_DONT_ESCAPE_EXTRA_INFO |
501 URL_ESCAPE_SEGMENT_ONLY ))) {
502 EscapeFlags &= ~URL_ESCAPE_UNSAFE;
503 hr = UrlEscapeW(lpszUrlCpy, pszCanonicalized, pcchCanonicalized,
505 } else { /* No escaping needed, just copy the string */
506 nLen = lstrlenW(lpszUrlCpy);
507 if(nLen < *pcchCanonicalized)
508 memcpy(pszCanonicalized, lpszUrlCpy, (nLen + 1)*sizeof(WCHAR));
513 *pcchCanonicalized = nLen;
516 HeapFree(GetProcessHeap(), 0, lpszUrlCpy);
519 TRACE("result %s\n", debugstr_w(pszCanonicalized));
524 /*************************************************************************
525 * UrlCombineA [SHLWAPI.@]
530 * pszBase [I] Base Url
531 * pszRelative [I] Url to combine with pszBase
532 * pszCombined [O] Destination for combined Url
533 * pcchCombined [O] Destination for length of pszCombined
534 * dwFlags [I] URL_ flags from "shlwapi.h"
537 * Success: S_OK. pszCombined contains the combined Url, pcchCombined
538 * contains its length.
539 * Failure: An HRESULT error code indicating the error.
541 HRESULT WINAPI UrlCombineA(LPCSTR pszBase, LPCSTR pszRelative,
542 LPSTR pszCombined, LPDWORD pcchCombined,
545 LPWSTR base, relative, combined;
546 DWORD ret, len, len2;
548 TRACE("(base %s, Relative %s, Combine size %d, flags %08x) using W version\n",
549 debugstr_a(pszBase),debugstr_a(pszRelative),
550 pcchCombined?*pcchCombined:0,dwFlags);
552 if(!pszBase || !pszRelative || !pcchCombined)
555 base = HeapAlloc(GetProcessHeap(), 0,
556 (3*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
557 relative = base + INTERNET_MAX_URL_LENGTH;
558 combined = relative + INTERNET_MAX_URL_LENGTH;
560 MultiByteToWideChar(0, 0, pszBase, -1, base, INTERNET_MAX_URL_LENGTH);
561 MultiByteToWideChar(0, 0, pszRelative, -1, relative, INTERNET_MAX_URL_LENGTH);
564 ret = UrlCombineW(base, relative, pszCombined?combined:NULL, &len, dwFlags);
567 HeapFree(GetProcessHeap(), 0, base);
571 len2 = WideCharToMultiByte(0, 0, combined, len, 0, 0, 0, 0);
572 if (len2 > *pcchCombined) {
573 *pcchCombined = len2;
574 HeapFree(GetProcessHeap(), 0, base);
577 WideCharToMultiByte(0, 0, combined, len+1, pszCombined, (*pcchCombined)+1,
579 *pcchCombined = len2;
580 HeapFree(GetProcessHeap(), 0, base);
584 /*************************************************************************
585 * UrlCombineW [SHLWAPI.@]
589 HRESULT WINAPI UrlCombineW(LPCWSTR pszBase, LPCWSTR pszRelative,
590 LPWSTR pszCombined, LPDWORD pcchCombined,
593 PARSEDURLW base, relative;
594 DWORD myflags, sizeloc = 0;
595 DWORD len, res1, res2, process_case = 0;
596 LPWSTR work, preliminary, mbase, mrelative;
597 static const WCHAR myfilestr[] = {'f','i','l','e',':','/','/','/','\0'};
600 TRACE("(base %s, Relative %s, Combine size %d, flags %08x)\n",
601 debugstr_w(pszBase),debugstr_w(pszRelative),
602 pcchCombined?*pcchCombined:0,dwFlags);
604 if(!pszBase || !pszRelative || !pcchCombined)
607 base.cbSize = sizeof(base);
608 relative.cbSize = sizeof(relative);
610 /* Get space for duplicates of the input and the output */
611 preliminary = HeapAlloc(GetProcessHeap(), 0, (3*INTERNET_MAX_URL_LENGTH) *
613 mbase = preliminary + INTERNET_MAX_URL_LENGTH;
614 mrelative = mbase + INTERNET_MAX_URL_LENGTH;
617 /* Canonicalize the base input prior to looking for the scheme */
618 myflags = dwFlags & (URL_DONT_SIMPLIFY | URL_UNESCAPE);
619 len = INTERNET_MAX_URL_LENGTH;
620 ret = UrlCanonicalizeW(pszBase, mbase, &len, myflags);
622 /* Canonicalize the relative input prior to looking for the scheme */
623 len = INTERNET_MAX_URL_LENGTH;
624 ret = UrlCanonicalizeW(pszRelative, mrelative, &len, myflags);
626 /* See if the base has a scheme */
627 res1 = ParseURLW(mbase, &base);
629 /* if pszBase has no scheme, then return pszRelative */
630 TRACE("no scheme detected in Base\n");
634 BOOL manual_search = FALSE;
636 /* mk is a special case */
637 if(base.nScheme == URL_SCHEME_MK) {
638 static const WCHAR wsz[] = {':',':',0};
640 WCHAR *ptr = strstrW(base.pszSuffix, wsz);
645 delta = ptr-base.pszSuffix;
646 base.cchProtocol += delta;
647 base.pszSuffix += delta;
648 base.cchSuffix -= delta;
651 /* get size of location field (if it exists) */
652 work = (LPWSTR)base.pszSuffix;
654 if (*work++ == '/') {
655 if (*work++ == '/') {
656 /* At this point have start of location and
657 * it ends at next '/' or end of string.
659 while(*work && (*work != '/')) work++;
660 sizeloc = (DWORD)(work - base.pszSuffix);
665 /* If there is a '#' and the characters immediately preceeding it are
666 * ".htm[l]", then begin looking for the last leaf starting from
667 * the '#'. Otherwise the '#' is not meaningful and just start
668 * looking from the end. */
669 if ((work = strchrW(base.pszSuffix + sizeloc, '#'))) {
670 const WCHAR htmlW[] = {'.','h','t','m','l',0};
671 const int len_htmlW = 5;
672 const WCHAR htmW[] = {'.','h','t','m',0};
673 const int len_htmW = 4;
675 if (work - base.pszSuffix > len_htmW * sizeof(WCHAR)) {
677 if (strncmpiW(work, htmW, len_htmW) == 0)
678 manual_search = TRUE;
682 if (!manual_search &&
683 work - base.pszSuffix > len_htmlW * sizeof(WCHAR)) {
685 if (strncmpiW(work, htmlW, len_htmlW) == 0)
686 manual_search = TRUE;
692 /* search backwards starting from the current position */
693 while (*work != '/' && work > base.pszSuffix + sizeloc)
695 if (work > base.pszSuffix + sizeloc)
696 base.cchSuffix = work - base.pszSuffix + 1;
698 /* search backwards starting from the end of the string */
699 work = strrchrW((base.pszSuffix+sizeloc), '/');
701 len = (DWORD)(work - base.pszSuffix + 1);
702 base.cchSuffix = len;
708 * .pszSuffix points to location (starting with '//')
709 * .cchSuffix length of location (above) and rest less the last
711 * sizeloc length of location (above) up to but not including
715 res2 = ParseURLW(mrelative, &relative);
717 /* no scheme in pszRelative */
718 TRACE("no scheme detected in Relative\n");
719 relative.pszSuffix = mrelative; /* case 3,4,5 depends on this */
720 relative.cchSuffix = strlenW(mrelative);
721 if (*pszRelative == ':') {
722 /* case that is either left alone or uses pszBase */
723 if (dwFlags & URL_PLUGGABLE_PROTOCOL) {
730 if (isalnum(*mrelative) && (*(mrelative + 1) == ':')) {
731 /* case that becomes "file:///" */
732 strcpyW(preliminary, myfilestr);
736 if ((*mrelative == '/') && (*(mrelative+1) == '/')) {
737 /* pszRelative has location and rest */
741 if (*mrelative == '/') {
742 /* case where pszRelative is root to location */
746 process_case = (*base.pszSuffix == '/' || base.nScheme == URL_SCHEME_MK) ? 5 : 3;
750 /* handle cases where pszRelative has scheme */
751 if ((base.cchProtocol == relative.cchProtocol) &&
752 (strncmpW(base.pszProtocol, relative.pszProtocol, base.cchProtocol) == 0)) {
754 /* since the schemes are the same */
755 if ((*relative.pszSuffix == '/') && (*(relative.pszSuffix+1) == '/')) {
756 /* case where pszRelative replaces location and following */
760 if (*relative.pszSuffix == '/') {
761 /* case where pszRelative is root to location */
765 /* replace either just location if base's location starts with a
766 * slash or otherwise everything */
767 process_case = (*base.pszSuffix == '/') ? 5 : 1;
770 if ((*relative.pszSuffix == '/') && (*(relative.pszSuffix+1) == '/')) {
771 /* case where pszRelative replaces scheme, location,
772 * and following and handles PLUGGABLE
779 } while(FALSE); /* a little trick to allow easy exit from nested if's */
782 switch (process_case) {
785 * Return pszRelative appended to what ever is in pszCombined,
786 * (which may the string "file:///"
788 strcatW(preliminary, mrelative);
791 case 2: /* case where pszRelative replaces scheme, and location */
792 strcpyW(preliminary, mrelative);
796 * Return the pszBase scheme with pszRelative. Basically
797 * keeps the scheme and replaces the domain and following.
799 memcpy(preliminary, base.pszProtocol, (base.cchProtocol + 1)*sizeof(WCHAR));
800 work = preliminary + base.cchProtocol + 1;
801 strcpyW(work, relative.pszSuffix);
805 * Return the pszBase scheme and location but everything
806 * after the location is pszRelative. (Replace document
809 memcpy(preliminary, base.pszProtocol, (base.cchProtocol+1+sizeloc)*sizeof(WCHAR));
810 work = preliminary + base.cchProtocol + 1 + sizeloc;
811 if (dwFlags & URL_PLUGGABLE_PROTOCOL)
813 strcpyW(work, relative.pszSuffix);
817 * Return the pszBase without its document (if any) and
818 * append pszRelative after its scheme.
820 memcpy(preliminary, base.pszProtocol,
821 (base.cchProtocol+1+base.cchSuffix)*sizeof(WCHAR));
822 work = preliminary + base.cchProtocol+1+base.cchSuffix - 1;
825 strcpyW(work, relative.pszSuffix);
829 FIXME("How did we get here????? process_case=%d\n", process_case);
834 /* Reuse mrelative as temp storage as its already allocated and not needed anymore */
835 ret = UrlCanonicalizeW(preliminary, mrelative, pcchCombined, (dwFlags & ~URL_FILE_USE_PATHURL));
836 if(SUCCEEDED(ret) && pszCombined) {
837 lstrcpyW(pszCombined, mrelative);
839 TRACE("return-%d len=%d, %s\n",
840 process_case, *pcchCombined, debugstr_w(pszCombined));
842 HeapFree(GetProcessHeap(), 0, preliminary);
846 /*************************************************************************
847 * UrlEscapeA [SHLWAPI.@]
850 HRESULT WINAPI UrlEscapeA(
856 WCHAR bufW[INTERNET_MAX_URL_LENGTH];
857 WCHAR *escapedW = bufW;
860 DWORD lenW = sizeof(bufW)/sizeof(WCHAR), lenA;
862 if (!pszEscaped || !pcchEscaped || !*pcchEscaped)
865 if(!RtlCreateUnicodeStringFromAsciiz(&urlW, pszUrl))
867 if((ret = UrlEscapeW(urlW.Buffer, escapedW, &lenW, dwFlags)) == E_POINTER) {
868 escapedW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
869 ret = UrlEscapeW(urlW.Buffer, escapedW, &lenW, dwFlags);
872 RtlUnicodeToMultiByteSize(&lenA, escapedW, lenW * sizeof(WCHAR));
873 if(*pcchEscaped > lenA) {
874 RtlUnicodeToMultiByteN(pszEscaped, *pcchEscaped - 1, &lenA, escapedW, lenW * sizeof(WCHAR));
875 pszEscaped[lenA] = 0;
878 *pcchEscaped = lenA + 1;
882 if(escapedW != bufW) HeapFree(GetProcessHeap(), 0, escapedW);
883 RtlFreeUnicodeString(&urlW);
887 #define WINE_URL_BASH_AS_SLASH 0x01
888 #define WINE_URL_COLLAPSE_SLASHES 0x02
889 #define WINE_URL_ESCAPE_SLASH 0x04
890 #define WINE_URL_ESCAPE_HASH 0x08
891 #define WINE_URL_ESCAPE_QUESTION 0x10
892 #define WINE_URL_STOP_ON_HASH 0x20
893 #define WINE_URL_STOP_ON_QUESTION 0x40
895 static inline BOOL URL_NeedEscapeW(WCHAR ch, DWORD dwFlags, DWORD int_flags)
901 if(dwFlags & URL_ESCAPE_SPACES_ONLY) {
908 if ((dwFlags & URL_ESCAPE_PERCENT) && (ch == '%'))
911 if (ch <= 31 || ch >= 127)
932 if (int_flags & WINE_URL_ESCAPE_SLASH) return TRUE;
936 if (int_flags & WINE_URL_ESCAPE_QUESTION) return TRUE;
940 if (int_flags & WINE_URL_ESCAPE_HASH) return TRUE;
950 /*************************************************************************
951 * UrlEscapeW [SHLWAPI.@]
953 * Converts unsafe characters in a Url into escape sequences.
956 * pszUrl [I] Url to modify
957 * pszEscaped [O] Destination for modified Url
958 * pcchEscaped [I/O] Length of pszUrl, destination for length of pszEscaped
959 * dwFlags [I] URL_ flags from "shlwapi.h"
962 * Success: S_OK. pszEscaped contains the escaped Url, pcchEscaped
963 * contains its length.
964 * Failure: E_POINTER, if pszEscaped is not large enough. In this case
965 * pcchEscaped is set to the required length.
967 * Converts unsafe characters into their escape sequences.
970 * - By default this function stops converting at the first '?' or
972 * - If dwFlags contains URL_ESCAPE_SPACES_ONLY then only spaces are
973 * converted, but the conversion continues past a '?' or '#'.
974 * - Note that this function did not work well (or at all) in shlwapi version 4.
977 * Only the following flags are implemented:
978 *| URL_ESCAPE_SPACES_ONLY
979 *| URL_DONT_ESCAPE_EXTRA_INFO
980 *| URL_ESCAPE_SEGMENT_ONLY
981 *| URL_ESCAPE_PERCENT
983 HRESULT WINAPI UrlEscapeW(
990 DWORD needed = 0, ret;
991 BOOL stop_escaping = FALSE;
992 WCHAR next[5], *dst = pszEscaped;
994 PARSEDURLW parsed_url;
997 static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
999 TRACE("(%s %p %p 0x%08x)\n", debugstr_w(pszUrl), pszEscaped,
1000 pcchEscaped, dwFlags);
1002 if(!pszUrl || !pcchEscaped)
1003 return E_INVALIDARG;
1005 if(dwFlags & ~(URL_ESCAPE_SPACES_ONLY |
1006 URL_ESCAPE_SEGMENT_ONLY |
1007 URL_DONT_ESCAPE_EXTRA_INFO |
1008 URL_ESCAPE_PERCENT))
1009 FIXME("Unimplemented flags: %08x\n", dwFlags);
1012 if (dwFlags & URL_ESCAPE_SPACES_ONLY)
1013 /* if SPACES_ONLY specified, reset the other controls */
1014 dwFlags &= ~(URL_DONT_ESCAPE_EXTRA_INFO |
1015 URL_ESCAPE_PERCENT |
1016 URL_ESCAPE_SEGMENT_ONLY);
1019 /* if SPACES_ONLY *not* specified the assume DONT_ESCAPE_EXTRA_INFO */
1020 dwFlags |= URL_DONT_ESCAPE_EXTRA_INFO;
1024 if(dwFlags & URL_ESCAPE_SEGMENT_ONLY) {
1025 int_flags = WINE_URL_ESCAPE_QUESTION | WINE_URL_ESCAPE_HASH | WINE_URL_ESCAPE_SLASH;
1027 parsed_url.cbSize = sizeof(parsed_url);
1028 if(ParseURLW(pszUrl, &parsed_url) != S_OK)
1029 parsed_url.nScheme = URL_SCHEME_INVALID;
1031 TRACE("scheme = %d (%s)\n", parsed_url.nScheme, debugstr_wn(parsed_url.pszProtocol, parsed_url.cchProtocol));
1033 if(dwFlags & URL_DONT_ESCAPE_EXTRA_INFO)
1034 int_flags = WINE_URL_STOP_ON_HASH | WINE_URL_STOP_ON_QUESTION;
1036 switch(parsed_url.nScheme) {
1037 case URL_SCHEME_FILE:
1038 int_flags |= WINE_URL_BASH_AS_SLASH | WINE_URL_COLLAPSE_SLASHES | WINE_URL_ESCAPE_HASH;
1039 int_flags &= ~WINE_URL_STOP_ON_HASH;
1042 case URL_SCHEME_HTTP:
1043 case URL_SCHEME_HTTPS:
1044 int_flags |= WINE_URL_BASH_AS_SLASH;
1045 if(parsed_url.pszSuffix[0] != '/' && parsed_url.pszSuffix[0] != '\\')
1046 int_flags |= WINE_URL_ESCAPE_SLASH;
1049 case URL_SCHEME_MAILTO:
1050 int_flags |= WINE_URL_ESCAPE_SLASH | WINE_URL_ESCAPE_QUESTION | WINE_URL_ESCAPE_HASH;
1051 int_flags &= ~(WINE_URL_STOP_ON_QUESTION | WINE_URL_STOP_ON_HASH);
1054 case URL_SCHEME_INVALID:
1057 case URL_SCHEME_FTP:
1059 if(parsed_url.pszSuffix[0] != '/')
1060 int_flags |= WINE_URL_ESCAPE_SLASH;
1065 for(src = pszUrl; *src; ) {
1069 if((int_flags & WINE_URL_COLLAPSE_SLASHES) && src == pszUrl + parsed_url.cchProtocol + 1) {
1070 int localhost_len = sizeof(localhost)/sizeof(WCHAR) - 1;
1071 while(cur == '/' || cur == '\\') {
1075 if(slashes == 2 && !strncmpiW(src, localhost, localhost_len)) { /* file://localhost/ -> file:/// */
1076 if(*(src + localhost_len) == '/' || *(src + localhost_len) == '\\')
1077 src += localhost_len + 1;
1084 next[0] = next[1] = next[2] = '/';
1091 next[0] = next[1] = '/';
1098 if(cur == '#' && (int_flags & WINE_URL_STOP_ON_HASH))
1099 stop_escaping = TRUE;
1101 if(cur == '?' && (int_flags & WINE_URL_STOP_ON_QUESTION))
1102 stop_escaping = TRUE;
1104 if(cur == '\\' && (int_flags & WINE_URL_BASH_AS_SLASH) && !stop_escaping) cur = '/';
1106 if(URL_NeedEscapeW(cur, dwFlags, int_flags) && stop_escaping == FALSE) {
1108 next[1] = hexDigits[(cur >> 4) & 0xf];
1109 next[2] = hexDigits[cur & 0xf];
1118 if(needed + len <= *pcchEscaped) {
1119 memcpy(dst, next, len*sizeof(WCHAR));
1125 if(needed < *pcchEscaped) {
1129 needed++; /* add one for the '\0' */
1132 *pcchEscaped = needed;
1137 /*************************************************************************
1138 * UrlUnescapeA [SHLWAPI.@]
1140 * Converts Url escape sequences back to ordinary characters.
1143 * pszUrl [I/O] Url to convert
1144 * pszUnescaped [O] Destination for converted Url
1145 * pcchUnescaped [I/O] Size of output string
1146 * dwFlags [I] URL_ESCAPE_ Flags from "shlwapi.h"
1149 * Success: S_OK. The converted value is in pszUnescaped, or in pszUrl if
1150 * dwFlags includes URL_ESCAPE_INPLACE.
1151 * Failure: E_POINTER if the converted Url is bigger than pcchUnescaped. In
1152 * this case pcchUnescaped is set to the size required.
1154 * If dwFlags includes URL_DONT_ESCAPE_EXTRA_INFO, the conversion stops at
1155 * the first occurrence of either a '?' or '#' character.
1157 HRESULT WINAPI UrlUnescapeA(
1160 LPDWORD pcchUnescaped,
1167 BOOL stop_unescaping = FALSE;
1169 TRACE("(%s, %p, %p, 0x%08x)\n", debugstr_a(pszUrl), pszUnescaped,
1170 pcchUnescaped, dwFlags);
1172 if (!pszUrl) return E_INVALIDARG;
1174 if(dwFlags & URL_UNESCAPE_INPLACE)
1178 if (!pszUnescaped || !pcchUnescaped) return E_INVALIDARG;
1182 for(src = pszUrl, needed = 0; *src; src++, needed++) {
1183 if(dwFlags & URL_DONT_UNESCAPE_EXTRA_INFO &&
1184 (*src == '#' || *src == '?')) {
1185 stop_unescaping = TRUE;
1187 } else if(*src == '%' && isxdigit(*(src + 1)) && isxdigit(*(src + 2))
1188 && stop_unescaping == FALSE) {
1191 memcpy(buf, src + 1, 2);
1193 ih = strtol(buf, NULL, 16);
1195 src += 2; /* Advance to end of escape */
1199 if(dwFlags & URL_UNESCAPE_INPLACE || needed < *pcchUnescaped)
1203 if(dwFlags & URL_UNESCAPE_INPLACE || needed < *pcchUnescaped) {
1207 needed++; /* add one for the '\0' */
1210 if(!(dwFlags & URL_UNESCAPE_INPLACE))
1211 *pcchUnescaped = needed;
1214 TRACE("result %s\n", (dwFlags & URL_UNESCAPE_INPLACE) ?
1215 debugstr_a(pszUrl) : debugstr_a(pszUnescaped));
1221 /*************************************************************************
1222 * UrlUnescapeW [SHLWAPI.@]
1226 HRESULT WINAPI UrlUnescapeW(
1228 LPWSTR pszUnescaped,
1229 LPDWORD pcchUnescaped,
1236 BOOL stop_unescaping = FALSE;
1238 TRACE("(%s, %p, %p, 0x%08x)\n", debugstr_w(pszUrl), pszUnescaped,
1239 pcchUnescaped, dwFlags);
1241 if(!pszUrl) return E_INVALIDARG;
1243 if(dwFlags & URL_UNESCAPE_INPLACE)
1247 if (!pszUnescaped || !pcchUnescaped) return E_INVALIDARG;
1251 for(src = pszUrl, needed = 0; *src; src++, needed++) {
1252 if(dwFlags & URL_DONT_UNESCAPE_EXTRA_INFO &&
1253 (*src == '#' || *src == '?')) {
1254 stop_unescaping = TRUE;
1256 } else if(*src == '%' && isxdigitW(*(src + 1)) && isxdigitW(*(src + 2))
1257 && stop_unescaping == FALSE) {
1259 WCHAR buf[5] = {'0','x',0};
1260 memcpy(buf + 2, src + 1, 2*sizeof(WCHAR));
1262 StrToIntExW(buf, STIF_SUPPORT_HEX, &ih);
1264 src += 2; /* Advance to end of escape */
1268 if(dwFlags & URL_UNESCAPE_INPLACE || needed < *pcchUnescaped)
1272 if(dwFlags & URL_UNESCAPE_INPLACE || needed < *pcchUnescaped) {
1276 needed++; /* add one for the '\0' */
1279 if(!(dwFlags & URL_UNESCAPE_INPLACE))
1280 *pcchUnescaped = needed;
1283 TRACE("result %s\n", (dwFlags & URL_UNESCAPE_INPLACE) ?
1284 debugstr_w(pszUrl) : debugstr_w(pszUnescaped));
1290 /*************************************************************************
1291 * UrlGetLocationA [SHLWAPI.@]
1293 * Get the location from a Url.
1296 * pszUrl [I] Url to get the location from
1299 * A pointer to the start of the location in pszUrl, or NULL if there is
1303 * - MSDN erroneously states that "The location is the segment of the Url
1304 * starting with a '?' or '#' character". Neither V4 nor V5 of shlwapi.dll
1305 * stop at '?' and always return a NULL in this case.
1306 * - MSDN also erroneously states that "If a file URL has a query string,
1307 * the returned string is the query string". In all tested cases, if the
1308 * Url starts with "fi" then a NULL is returned. V5 gives the following results:
1311 *| NULL file://aa/b/cd#hohoh
1312 *| #hohoh http://aa/b/cd#hohoh
1313 *| NULL fi://aa/b/cd#hohoh
1314 *| #hohoh ff://aa/b/cd#hohoh
1316 LPCSTR WINAPI UrlGetLocationA(
1322 base.cbSize = sizeof(base);
1323 res1 = ParseURLA(pszUrl, &base);
1324 if (res1) return NULL; /* invalid scheme */
1326 /* if scheme is file: then never return pointer */
1327 if (strncmp(base.pszProtocol, "file", min(4,base.cchProtocol)) == 0) return NULL;
1329 /* Look for '#' and return its addr */
1330 return strchr(base.pszSuffix, '#');
1333 /*************************************************************************
1334 * UrlGetLocationW [SHLWAPI.@]
1336 * See UrlGetLocationA.
1338 LPCWSTR WINAPI UrlGetLocationW(
1344 base.cbSize = sizeof(base);
1345 res1 = ParseURLW(pszUrl, &base);
1346 if (res1) return NULL; /* invalid scheme */
1348 /* if scheme is file: then never return pointer */
1349 if (strncmpW(base.pszProtocol, fileW, min(4,base.cchProtocol)) == 0) return NULL;
1351 /* Look for '#' and return its addr */
1352 return strchrW(base.pszSuffix, '#');
1355 /*************************************************************************
1356 * UrlCompareA [SHLWAPI.@]
1361 * pszUrl1 [I] First Url to compare
1362 * pszUrl2 [I] Url to compare to pszUrl1
1363 * fIgnoreSlash [I] TRUE = compare only up to a final slash
1366 * less than zero, zero, or greater than zero indicating pszUrl2 is greater
1367 * than, equal to, or less than pszUrl1 respectively.
1369 INT WINAPI UrlCompareA(
1374 INT ret, len, len1, len2;
1377 return strcmp(pszUrl1, pszUrl2);
1378 len1 = strlen(pszUrl1);
1379 if (pszUrl1[len1-1] == '/') len1--;
1380 len2 = strlen(pszUrl2);
1381 if (pszUrl2[len2-1] == '/') len2--;
1383 return strncmp(pszUrl1, pszUrl2, len1);
1384 len = min(len1, len2);
1385 ret = strncmp(pszUrl1, pszUrl2, len);
1386 if (ret) return ret;
1387 if (len1 > len2) return 1;
1391 /*************************************************************************
1392 * UrlCompareW [SHLWAPI.@]
1396 INT WINAPI UrlCompareW(
1402 size_t len, len1, len2;
1405 return strcmpW(pszUrl1, pszUrl2);
1406 len1 = strlenW(pszUrl1);
1407 if (pszUrl1[len1-1] == '/') len1--;
1408 len2 = strlenW(pszUrl2);
1409 if (pszUrl2[len2-1] == '/') len2--;
1411 return strncmpW(pszUrl1, pszUrl2, len1);
1412 len = min(len1, len2);
1413 ret = strncmpW(pszUrl1, pszUrl2, len);
1414 if (ret) return ret;
1415 if (len1 > len2) return 1;
1419 /*************************************************************************
1420 * HashData [SHLWAPI.@]
1422 * Hash an input block into a variable sized digest.
1425 * lpSrc [I] Input block
1426 * nSrcLen [I] Length of lpSrc
1427 * lpDest [I] Output for hash digest
1428 * nDestLen [I] Length of lpDest
1431 * Success: TRUE. lpDest is filled with the computed hash value.
1432 * Failure: FALSE, if any argument is invalid.
1434 HRESULT WINAPI HashData(const unsigned char *lpSrc, DWORD nSrcLen,
1435 unsigned char *lpDest, DWORD nDestLen)
1437 INT srcCount = nSrcLen - 1, destCount = nDestLen - 1;
1439 if (!lpSrc || !lpDest)
1440 return E_INVALIDARG;
1442 while (destCount >= 0)
1444 lpDest[destCount] = (destCount & 0xff);
1448 while (srcCount >= 0)
1450 destCount = nDestLen - 1;
1451 while (destCount >= 0)
1453 lpDest[destCount] = HashDataLookup[lpSrc[srcCount] ^ lpDest[destCount]];
1461 /*************************************************************************
1462 * UrlHashA [SHLWAPI.@]
1464 * Produce a Hash from a Url.
1467 * pszUrl [I] Url to hash
1468 * lpDest [O] Destinationh for hash
1469 * nDestLen [I] Length of lpDest
1472 * Success: S_OK. lpDest is filled with the computed hash value.
1473 * Failure: E_INVALIDARG, if any argument is invalid.
1475 HRESULT WINAPI UrlHashA(LPCSTR pszUrl, unsigned char *lpDest, DWORD nDestLen)
1477 if (IsBadStringPtrA(pszUrl, -1) || IsBadWritePtr(lpDest, nDestLen))
1478 return E_INVALIDARG;
1480 HashData((const BYTE*)pszUrl, (int)strlen(pszUrl), lpDest, nDestLen);
1484 /*************************************************************************
1485 * UrlHashW [SHLWAPI.@]
1489 HRESULT WINAPI UrlHashW(LPCWSTR pszUrl, unsigned char *lpDest, DWORD nDestLen)
1491 char szUrl[MAX_PATH];
1493 TRACE("(%s,%p,%d)\n",debugstr_w(pszUrl), lpDest, nDestLen);
1495 if (IsBadStringPtrW(pszUrl, -1) || IsBadWritePtr(lpDest, nDestLen))
1496 return E_INVALIDARG;
1498 /* Win32 hashes the data as an ASCII string, presumably so that both A+W
1499 * return the same digests for the same URL.
1501 WideCharToMultiByte(0, 0, pszUrl, -1, szUrl, MAX_PATH, 0, 0);
1502 HashData((const BYTE*)szUrl, (int)strlen(szUrl), lpDest, nDestLen);
1506 /*************************************************************************
1507 * UrlApplySchemeA [SHLWAPI.@]
1509 * Apply a scheme to a Url.
1512 * pszIn [I] Url to apply scheme to
1513 * pszOut [O] Destination for modified Url
1514 * pcchOut [I/O] Length of pszOut/destination for length of pszOut
1515 * dwFlags [I] URL_ flags from "shlwapi.h"
1518 * Success: S_OK: pszOut contains the modified Url, pcchOut contains its length.
1519 * Failure: An HRESULT error code describing the error.
1521 HRESULT WINAPI UrlApplySchemeA(LPCSTR pszIn, LPSTR pszOut, LPDWORD pcchOut, DWORD dwFlags)
1527 TRACE("(%s, %p, %p:out size %d, 0x%08x)\n", debugstr_a(pszIn),
1528 pszOut, pcchOut, pcchOut ? *pcchOut : 0, dwFlags);
1530 if (!pszIn || !pszOut || !pcchOut) return E_INVALIDARG;
1532 in = HeapAlloc(GetProcessHeap(), 0,
1533 (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
1534 out = in + INTERNET_MAX_URL_LENGTH;
1536 MultiByteToWideChar(CP_ACP, 0, pszIn, -1, in, INTERNET_MAX_URL_LENGTH);
1537 len = INTERNET_MAX_URL_LENGTH;
1539 ret = UrlApplySchemeW(in, out, &len, dwFlags);
1541 HeapFree(GetProcessHeap(), 0, in);
1545 len = WideCharToMultiByte(CP_ACP, 0, out, -1, NULL, 0, NULL, NULL);
1546 if (len > *pcchOut) {
1551 WideCharToMultiByte(CP_ACP, 0, out, -1, pszOut, *pcchOut, NULL, NULL);
1556 HeapFree(GetProcessHeap(), 0, in);
1560 static HRESULT URL_GuessScheme(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut)
1565 DWORD value_len, data_len, dwType, i;
1566 WCHAR reg_path[MAX_PATH];
1567 WCHAR value[MAX_PATH], data[MAX_PATH];
1570 MultiByteToWideChar(0, 0,
1571 "Software\\Microsoft\\Windows\\CurrentVersion\\URL\\Prefixes",
1572 -1, reg_path, MAX_PATH);
1573 RegOpenKeyExW(HKEY_LOCAL_MACHINE, reg_path, 0, 1, &newkey);
1575 while(value_len = data_len = MAX_PATH,
1576 RegEnumValueW(newkey, index, value, &value_len,
1577 0, &dwType, (LPVOID)data, &data_len) == 0) {
1578 TRACE("guess %d %s is %s\n",
1579 index, debugstr_w(value), debugstr_w(data));
1582 for(i=0; i<value_len; i++) {
1585 /* remember that TRUE is not-equal */
1586 j = ChrCmpIW(Wxx, Wyy);
1589 if ((i == value_len) && !j) {
1590 if (strlenW(data) + strlenW(pszIn) + 1 > *pcchOut) {
1591 *pcchOut = strlenW(data) + strlenW(pszIn) + 1;
1592 RegCloseKey(newkey);
1595 strcpyW(pszOut, data);
1596 strcatW(pszOut, pszIn);
1597 *pcchOut = strlenW(pszOut);
1598 TRACE("matched and set to %s\n", debugstr_w(pszOut));
1599 RegCloseKey(newkey);
1604 RegCloseKey(newkey);
1608 static HRESULT URL_ApplyDefault(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut)
1611 DWORD data_len, dwType;
1612 WCHAR data[MAX_PATH];
1614 static const WCHAR prefix_keyW[] =
1615 {'S','o','f','t','w','a','r','e',
1616 '\\','M','i','c','r','o','s','o','f','t',
1617 '\\','W','i','n','d','o','w','s',
1618 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
1620 '\\','D','e','f','a','u','l','t','P','r','e','f','i','x',0};
1622 /* get and prepend default */
1623 RegOpenKeyExW(HKEY_LOCAL_MACHINE, prefix_keyW, 0, 1, &newkey);
1624 data_len = sizeof(data);
1625 RegQueryValueExW(newkey, NULL, 0, &dwType, (LPBYTE)data, &data_len);
1626 RegCloseKey(newkey);
1627 if (strlenW(data) + strlenW(pszIn) + 1 > *pcchOut) {
1628 *pcchOut = strlenW(data) + strlenW(pszIn) + 1;
1631 strcpyW(pszOut, data);
1632 strcatW(pszOut, pszIn);
1633 *pcchOut = strlenW(pszOut);
1634 TRACE("used default %s\n", debugstr_w(pszOut));
1638 /*************************************************************************
1639 * UrlApplySchemeW [SHLWAPI.@]
1641 * See UrlApplySchemeA.
1643 HRESULT WINAPI UrlApplySchemeW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut, DWORD dwFlags)
1645 PARSEDURLW in_scheme;
1649 TRACE("(%s, %p, %p:out size %d, 0x%08x)\n", debugstr_w(pszIn),
1650 pszOut, pcchOut, pcchOut ? *pcchOut : 0, dwFlags);
1652 if (!pszIn || !pszOut || !pcchOut) return E_INVALIDARG;
1654 if (dwFlags & URL_APPLY_GUESSFILE) {
1655 FIXME("(%s %p %p(%d) 0x%08x): stub URL_APPLY_GUESSFILE not implemented\n",
1656 debugstr_w(pszIn), pszOut, pcchOut, *pcchOut, dwFlags);
1657 strcpyW(pszOut, pszIn);
1658 *pcchOut = strlenW(pszOut);
1662 in_scheme.cbSize = sizeof(in_scheme);
1663 /* See if the base has a scheme */
1664 res1 = ParseURLW(pszIn, &in_scheme);
1666 /* no scheme in input, need to see if we need to guess */
1667 if (dwFlags & URL_APPLY_GUESSSCHEME) {
1668 if ((ret = URL_GuessScheme(pszIn, pszOut, pcchOut)) != E_FAIL)
1673 /* we have a scheme, see if valid (known scheme) */
1674 if (in_scheme.nScheme) {
1675 /* have valid scheme, so just copy and exit */
1676 if (strlenW(pszIn) + 1 > *pcchOut) {
1677 *pcchOut = strlenW(pszIn) + 1;
1680 strcpyW(pszOut, pszIn);
1681 *pcchOut = strlenW(pszOut);
1682 TRACE("valid scheme, returning copy\n");
1687 /* If we are here, then either invalid scheme,
1688 * or no scheme and can't/failed guess.
1690 if ( ( ((res1 == 0) && (dwFlags & URL_APPLY_FORCEAPPLY)) ||
1692 (dwFlags & URL_APPLY_DEFAULT)) {
1693 /* find and apply default scheme */
1694 return URL_ApplyDefault(pszIn, pszOut, pcchOut);
1700 /*************************************************************************
1701 * UrlIsA [SHLWAPI.@]
1703 * Determine if a Url is of a certain class.
1706 * pszUrl [I] Url to check
1707 * Urlis [I] URLIS_ constant from "shlwapi.h"
1710 * TRUE if pszUrl belongs to the class type in Urlis.
1713 BOOL WINAPI UrlIsA(LPCSTR pszUrl, URLIS Urlis)
1719 TRACE("(%s %d)\n", debugstr_a(pszUrl), Urlis);
1724 base.cbSize = sizeof(base);
1725 res1 = ParseURLA(pszUrl, &base);
1726 if (res1) return FALSE; /* invalid scheme */
1727 switch (base.nScheme)
1729 case URL_SCHEME_MAILTO:
1730 case URL_SCHEME_SHELL:
1731 case URL_SCHEME_JAVASCRIPT:
1732 case URL_SCHEME_VBSCRIPT:
1733 case URL_SCHEME_ABOUT:
1739 return !StrCmpNA("file:", pszUrl, 5);
1741 case URLIS_DIRECTORY:
1742 last = pszUrl + strlen(pszUrl) - 1;
1743 return (last >= pszUrl && (*last == '/' || *last == '\\' ));
1746 return PathIsURLA(pszUrl);
1748 case URLIS_NOHISTORY:
1749 case URLIS_APPLIABLE:
1750 case URLIS_HASQUERY:
1752 FIXME("(%s %d): stub\n", debugstr_a(pszUrl), Urlis);
1757 /*************************************************************************
1758 * UrlIsW [SHLWAPI.@]
1762 BOOL WINAPI UrlIsW(LPCWSTR pszUrl, URLIS Urlis)
1764 static const WCHAR stemp[] = { 'f','i','l','e',':',0 };
1769 TRACE("(%s %d)\n", debugstr_w(pszUrl), Urlis);
1774 base.cbSize = sizeof(base);
1775 res1 = ParseURLW(pszUrl, &base);
1776 if (res1) return FALSE; /* invalid scheme */
1777 switch (base.nScheme)
1779 case URL_SCHEME_MAILTO:
1780 case URL_SCHEME_SHELL:
1781 case URL_SCHEME_JAVASCRIPT:
1782 case URL_SCHEME_VBSCRIPT:
1783 case URL_SCHEME_ABOUT:
1789 return !strncmpW(stemp, pszUrl, 5);
1791 case URLIS_DIRECTORY:
1792 last = pszUrl + strlenW(pszUrl) - 1;
1793 return (last >= pszUrl && (*last == '/' || *last == '\\'));
1796 return PathIsURLW(pszUrl);
1798 case URLIS_NOHISTORY:
1799 case URLIS_APPLIABLE:
1800 case URLIS_HASQUERY:
1802 FIXME("(%s %d): stub\n", debugstr_w(pszUrl), Urlis);
1807 /*************************************************************************
1808 * UrlIsNoHistoryA [SHLWAPI.@]
1810 * Determine if a Url should not be stored in the users history list.
1813 * pszUrl [I] Url to check
1816 * TRUE, if pszUrl should be excluded from the history list,
1819 BOOL WINAPI UrlIsNoHistoryA(LPCSTR pszUrl)
1821 return UrlIsA(pszUrl, URLIS_NOHISTORY);
1824 /*************************************************************************
1825 * UrlIsNoHistoryW [SHLWAPI.@]
1827 * See UrlIsNoHistoryA.
1829 BOOL WINAPI UrlIsNoHistoryW(LPCWSTR pszUrl)
1831 return UrlIsW(pszUrl, URLIS_NOHISTORY);
1834 /*************************************************************************
1835 * UrlIsOpaqueA [SHLWAPI.@]
1837 * Determine if a Url is opaque.
1840 * pszUrl [I] Url to check
1843 * TRUE if pszUrl is opaque,
1847 * An opaque Url is one that does not start with "<protocol>://".
1849 BOOL WINAPI UrlIsOpaqueA(LPCSTR pszUrl)
1851 return UrlIsA(pszUrl, URLIS_OPAQUE);
1854 /*************************************************************************
1855 * UrlIsOpaqueW [SHLWAPI.@]
1859 BOOL WINAPI UrlIsOpaqueW(LPCWSTR pszUrl)
1861 return UrlIsW(pszUrl, URLIS_OPAQUE);
1864 /*************************************************************************
1865 * Scans for characters of type "type" and when not matching found,
1866 * returns pointer to it and length in size.
1868 * Characters tested based on RFC 1738
1870 static LPCWSTR URL_ScanID(LPCWSTR start, LPDWORD size, WINE_URL_SCAN_TYPE type)
1872 static DWORD alwayszero = 0;
1881 if ( (islowerW(*start) && isalphaW(*start)) ||
1896 if ( isalphaW(*start) ||
1898 /* user/password only characters */
1903 /* *extra* characters */
1910 /* *safe* characters */
1919 } else if (*start == '%') {
1920 if (isxdigitW(*(start+1)) &&
1921 isxdigitW(*(start+2))) {
1933 if (isdigitW(*start)) {
1944 if (isalnumW(*start) ||
1956 FIXME("unknown type %d\n", type);
1957 return (LPWSTR)&alwayszero;
1959 /* TRACE("scanned %d characters next char %p<%c>\n",
1960 *size, start, *start); */
1964 /*************************************************************************
1965 * Attempt to parse URL into pieces.
1967 static LONG URL_ParseUrl(LPCWSTR pszUrl, WINE_PARSE_URL *pl)
1971 memset(pl, 0, sizeof(WINE_PARSE_URL));
1972 pl->pScheme = pszUrl;
1973 work = URL_ScanID(pl->pScheme, &pl->szScheme, SCHEME);
1974 if (!*work || (*work != ':')) goto ErrorExit;
1976 if ((*work != '/') || (*(work+1) != '/')) goto SuccessExit;
1977 pl->pUserName = work + 2;
1978 work = URL_ScanID(pl->pUserName, &pl->szUserName, USERPASS);
1979 if (*work == ':' ) {
1980 /* parse password */
1982 pl->pPassword = work;
1983 work = URL_ScanID(pl->pPassword, &pl->szPassword, USERPASS);
1985 /* what we just parsed must be the hostname and port
1986 * so reset pointers and clear then let it parse */
1987 pl->szUserName = pl->szPassword = 0;
1988 work = pl->pUserName - 1;
1989 pl->pUserName = pl->pPassword = 0;
1991 } else if (*work == '@') {
1995 } else if (!*work || (*work == '/') || (*work == '.')) {
1996 /* what was parsed was hostname, so reset pointers and let it parse */
1997 pl->szUserName = pl->szPassword = 0;
1998 work = pl->pUserName - 1;
1999 pl->pUserName = pl->pPassword = 0;
2000 } else goto ErrorExit;
2002 /* now start parsing hostname or hostnumber */
2004 pl->pHostName = work;
2005 work = URL_ScanID(pl->pHostName, &pl->szHostName, HOST);
2010 work = URL_ScanID(pl->pPort, &pl->szPort, PORT);
2013 /* see if query string */
2014 pl->pQuery = strchrW(work, '?');
2015 if (pl->pQuery) pl->szQuery = strlenW(pl->pQuery);
2018 TRACE("parse successful: scheme=%p(%d), user=%p(%d), pass=%p(%d), host=%p(%d), port=%p(%d), query=%p(%d)\n",
2019 pl->pScheme, pl->szScheme,
2020 pl->pUserName, pl->szUserName,
2021 pl->pPassword, pl->szPassword,
2022 pl->pHostName, pl->szHostName,
2023 pl->pPort, pl->szPort,
2024 pl->pQuery, pl->szQuery);
2027 FIXME("failed to parse %s\n", debugstr_w(pszUrl));
2028 return E_INVALIDARG;
2031 /*************************************************************************
2032 * UrlGetPartA [SHLWAPI.@]
2034 * Retrieve part of a Url.
2037 * pszIn [I] Url to parse
2038 * pszOut [O] Destination for part of pszIn requested
2039 * pcchOut [I] Size of pszOut
2040 * [O] length of pszOut string EXCLUDING '\0' if S_OK, otherwise
2041 * needed size of pszOut INCLUDING '\0'.
2042 * dwPart [I] URL_PART_ enum from "shlwapi.h"
2043 * dwFlags [I] URL_ flags from "shlwapi.h"
2046 * Success: S_OK. pszOut contains the part requested, pcchOut contains its length.
2047 * Failure: An HRESULT error code describing the error.
2049 HRESULT WINAPI UrlGetPartA(LPCSTR pszIn, LPSTR pszOut, LPDWORD pcchOut,
2050 DWORD dwPart, DWORD dwFlags)
2053 DWORD ret, len, len2;
2055 if(!pszIn || !pszOut || !pcchOut || *pcchOut <= 0)
2056 return E_INVALIDARG;
2058 in = HeapAlloc(GetProcessHeap(), 0,
2059 (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
2060 out = in + INTERNET_MAX_URL_LENGTH;
2062 MultiByteToWideChar(0, 0, pszIn, -1, in, INTERNET_MAX_URL_LENGTH);
2064 len = INTERNET_MAX_URL_LENGTH;
2065 ret = UrlGetPartW(in, out, &len, dwPart, dwFlags);
2068 HeapFree(GetProcessHeap(), 0, in);
2072 len2 = WideCharToMultiByte(0, 0, out, len, 0, 0, 0, 0);
2073 if (len2 > *pcchOut) {
2075 HeapFree(GetProcessHeap(), 0, in);
2078 len2 = WideCharToMultiByte(0, 0, out, len+1, pszOut, *pcchOut, 0, 0);
2080 HeapFree(GetProcessHeap(), 0, in);
2084 /*************************************************************************
2085 * UrlGetPartW [SHLWAPI.@]
2089 HRESULT WINAPI UrlGetPartW(LPCWSTR pszIn, LPWSTR pszOut, LPDWORD pcchOut,
2090 DWORD dwPart, DWORD dwFlags)
2094 DWORD scheme, size, schsize;
2095 LPCWSTR addr, schaddr;
2097 TRACE("(%s %p %p(%d) %08x %08x)\n",
2098 debugstr_w(pszIn), pszOut, pcchOut, *pcchOut, dwPart, dwFlags);
2100 if(!pszIn || !pszOut || !pcchOut || *pcchOut <= 0)
2101 return E_INVALIDARG;
2105 addr = strchrW(pszIn, ':');
2107 scheme = URL_SCHEME_UNKNOWN;
2109 scheme = get_scheme_code(pszIn, addr-pszIn);
2111 ret = URL_ParseUrl(pszIn, &pl);
2114 case URL_PART_SCHEME:
2115 if (!pl.szScheme || scheme == URL_SCHEME_UNKNOWN) {
2123 case URL_PART_HOSTNAME:
2125 case URL_SCHEME_FTP:
2126 case URL_SCHEME_HTTP:
2127 case URL_SCHEME_GOPHER:
2128 case URL_SCHEME_TELNET:
2129 case URL_SCHEME_FILE:
2130 case URL_SCHEME_HTTPS:
2137 if(scheme==URL_SCHEME_FILE && (!pl.szHostName ||
2138 (pl.szHostName==1 && *(pl.pHostName+1)==':'))) {
2143 if (!pl.szHostName) {
2147 addr = pl.pHostName;
2148 size = pl.szHostName;
2151 case URL_PART_USERNAME:
2152 if (!pl.szUserName) {
2156 addr = pl.pUserName;
2157 size = pl.szUserName;
2160 case URL_PART_PASSWORD:
2161 if (!pl.szPassword) {
2165 addr = pl.pPassword;
2166 size = pl.szPassword;
2178 case URL_PART_QUERY:
2189 return E_INVALIDARG;
2192 if (dwFlags == URL_PARTFLAG_KEEPSCHEME) {
2193 if(!pl.pScheme || !pl.szScheme) {
2197 schaddr = pl.pScheme;
2198 schsize = pl.szScheme;
2199 if (*pcchOut < schsize + size + 2) {
2200 *pcchOut = schsize + size + 2;
2203 memcpy(pszOut, schaddr, schsize*sizeof(WCHAR));
2204 pszOut[schsize] = ':';
2205 memcpy(pszOut+schsize+1, addr, size*sizeof(WCHAR));
2206 pszOut[schsize+1+size] = 0;
2207 *pcchOut = schsize + 1 + size;
2210 if (*pcchOut < size + 1) {*pcchOut = size+1; return E_POINTER;}
2211 memcpy(pszOut, addr, size*sizeof(WCHAR));
2215 TRACE("len=%d %s\n", *pcchOut, debugstr_w(pszOut));
2220 /*************************************************************************
2221 * PathIsURLA [SHLWAPI.@]
2223 * Check if the given path is a Url.
2226 * lpszPath [I] Path to check.
2229 * TRUE if lpszPath is a Url.
2230 * FALSE if lpszPath is NULL or not a Url.
2232 BOOL WINAPI PathIsURLA(LPCSTR lpstrPath)
2237 TRACE("%s\n", debugstr_a(lpstrPath));
2239 if (!lpstrPath || !*lpstrPath) return FALSE;
2242 base.cbSize = sizeof(base);
2243 hres = ParseURLA(lpstrPath, &base);
2244 return hres == S_OK && (base.nScheme != URL_SCHEME_INVALID);
2247 /*************************************************************************
2248 * PathIsURLW [SHLWAPI.@]
2252 BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
2257 TRACE("%s\n", debugstr_w(lpstrPath));
2259 if (!lpstrPath || !*lpstrPath) return FALSE;
2262 base.cbSize = sizeof(base);
2263 hres = ParseURLW(lpstrPath, &base);
2264 return hres == S_OK && (base.nScheme != URL_SCHEME_INVALID);
2267 /*************************************************************************
2268 * UrlCreateFromPathA [SHLWAPI.@]
2270 * See UrlCreateFromPathW
2272 HRESULT WINAPI UrlCreateFromPathA(LPCSTR pszPath, LPSTR pszUrl, LPDWORD pcchUrl, DWORD dwReserved)
2274 WCHAR bufW[INTERNET_MAX_URL_LENGTH];
2276 UNICODE_STRING pathW;
2278 DWORD lenW = sizeof(bufW)/sizeof(WCHAR), lenA;
2280 if(!RtlCreateUnicodeStringFromAsciiz(&pathW, pszPath))
2281 return E_INVALIDARG;
2282 if((ret = UrlCreateFromPathW(pathW.Buffer, urlW, &lenW, dwReserved)) == E_POINTER) {
2283 urlW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR));
2284 ret = UrlCreateFromPathW(pathW.Buffer, urlW, &lenW, dwReserved);
2286 if(ret == S_OK || ret == S_FALSE) {
2287 RtlUnicodeToMultiByteSize(&lenA, urlW, lenW * sizeof(WCHAR));
2288 if(*pcchUrl > lenA) {
2289 RtlUnicodeToMultiByteN(pszUrl, *pcchUrl - 1, &lenA, urlW, lenW * sizeof(WCHAR));
2293 *pcchUrl = lenA + 1;
2297 if(urlW != bufW) HeapFree(GetProcessHeap(), 0, urlW);
2298 RtlFreeUnicodeString(&pathW);
2302 /*************************************************************************
2303 * UrlCreateFromPathW [SHLWAPI.@]
2305 * Create a Url from a file path.
2308 * pszPath [I] Path to convert
2309 * pszUrl [O] Destination for the converted Url
2310 * pcchUrl [I/O] Length of pszUrl
2311 * dwReserved [I] Reserved, must be 0
2314 * Success: S_OK pszUrl contains the converted path, S_FALSE if the path is already a Url
2315 * Failure: An HRESULT error code.
2317 HRESULT WINAPI UrlCreateFromPathW(LPCWSTR pszPath, LPWSTR pszUrl, LPDWORD pcchUrl, DWORD dwReserved)
2322 WCHAR file_colonW[] = {'f','i','l','e',':',0};
2323 WCHAR three_slashesW[] = {'/','/','/',0};
2324 PARSEDURLW parsed_url;
2326 TRACE("(%s, %p, %p, 0x%08x)\n", debugstr_w(pszPath), pszUrl, pcchUrl, dwReserved);
2328 /* Validate arguments */
2329 if (dwReserved != 0)
2330 return E_INVALIDARG;
2331 if (!pszUrl || !pcchUrl)
2332 return E_INVALIDARG;
2335 parsed_url.cbSize = sizeof(parsed_url);
2336 if(ParseURLW(pszPath, &parsed_url) == S_OK) {
2337 if(parsed_url.nScheme != URL_SCHEME_INVALID && parsed_url.cchProtocol > 1) {
2338 needed = strlenW(pszPath);
2339 if (needed >= *pcchUrl) {
2340 *pcchUrl = needed + 1;
2344 strcpyW(pszUrl, pszPath);
2350 pszNewUrl = HeapAlloc(GetProcessHeap(), 0, (strlenW(pszPath) + 9) * sizeof(WCHAR)); /* "file:///" + pszPath_len + 1 */
2351 strcpyW(pszNewUrl, file_colonW);
2352 if(isalphaW(pszPath[0]) && pszPath[1] == ':')
2353 strcatW(pszNewUrl, three_slashesW);
2354 strcatW(pszNewUrl, pszPath);
2355 ret = UrlEscapeW(pszNewUrl, pszUrl, pcchUrl, URL_ESCAPE_PERCENT);
2357 HeapFree(GetProcessHeap(), 0, pszNewUrl);
2361 /*************************************************************************
2362 * SHAutoComplete [SHLWAPI.@]
2364 * Enable auto-completion for an edit control.
2367 * hwndEdit [I] Handle of control to enable auto-completion for
2368 * dwFlags [I] SHACF_ flags from "shlwapi.h"
2371 * Success: S_OK. Auto-completion is enabled for the control.
2372 * Failure: An HRESULT error code indicating the error.
2374 HRESULT WINAPI SHAutoComplete(HWND hwndEdit, DWORD dwFlags)
2380 /*************************************************************************
2381 * MLBuildResURLA [SHLWAPI.405]
2383 * Create a Url pointing to a resource in a module.
2386 * lpszLibName [I] Name of the module containing the resource
2387 * hMod [I] Callers module handle
2388 * dwFlags [I] Undocumented flags for loading the module
2389 * lpszRes [I] Resource name
2390 * lpszDest [O] Destination for resulting Url
2391 * dwDestLen [I] Length of lpszDest
2394 * Success: S_OK. lpszDest contains the resource Url.
2395 * Failure: E_INVALIDARG, if any argument is invalid, or
2396 * E_FAIL if dwDestLen is too small.
2398 HRESULT WINAPI MLBuildResURLA(LPCSTR lpszLibName, HMODULE hMod, DWORD dwFlags,
2399 LPCSTR lpszRes, LPSTR lpszDest, DWORD dwDestLen)
2401 WCHAR szLibName[MAX_PATH], szRes[MAX_PATH], szDest[MAX_PATH];
2405 MultiByteToWideChar(CP_ACP, 0, lpszLibName, -1, szLibName, sizeof(szLibName)/sizeof(WCHAR));
2408 MultiByteToWideChar(CP_ACP, 0, lpszRes, -1, szRes, sizeof(szRes)/sizeof(WCHAR));
2410 if (dwDestLen > sizeof(szLibName)/sizeof(WCHAR))
2411 dwDestLen = sizeof(szLibName)/sizeof(WCHAR);
2413 hRet = MLBuildResURLW(lpszLibName ? szLibName : NULL, hMod, dwFlags,
2414 lpszRes ? szRes : NULL, lpszDest ? szDest : NULL, dwDestLen);
2415 if (SUCCEEDED(hRet) && lpszDest)
2416 WideCharToMultiByte(CP_ACP, 0, szDest, -1, lpszDest, dwDestLen, 0, 0);
2421 /*************************************************************************
2422 * MLBuildResURLA [SHLWAPI.406]
2424 * See MLBuildResURLA.
2426 HRESULT WINAPI MLBuildResURLW(LPCWSTR lpszLibName, HMODULE hMod, DWORD dwFlags,
2427 LPCWSTR lpszRes, LPWSTR lpszDest, DWORD dwDestLen)
2429 static const WCHAR szRes[] = { 'r','e','s',':','/','/','\0' };
2430 #define szResLen ((sizeof(szRes) - sizeof(WCHAR))/sizeof(WCHAR))
2431 HRESULT hRet = E_FAIL;
2433 TRACE("(%s,%p,0x%08x,%s,%p,%d)\n", debugstr_w(lpszLibName), hMod, dwFlags,
2434 debugstr_w(lpszRes), lpszDest, dwDestLen);
2436 if (!lpszLibName || !hMod || hMod == INVALID_HANDLE_VALUE || !lpszRes ||
2437 !lpszDest || (dwFlags && dwFlags != 2))
2438 return E_INVALIDARG;
2440 if (dwDestLen >= szResLen + 1)
2442 dwDestLen -= (szResLen + 1);
2443 memcpy(lpszDest, szRes, sizeof(szRes));
2445 hMod = MLLoadLibraryW(lpszLibName, hMod, dwFlags);
2449 WCHAR szBuff[MAX_PATH];
2452 len = GetModuleFileNameW(hMod, szBuff, sizeof(szBuff)/sizeof(WCHAR));
2453 if (len && len < sizeof(szBuff)/sizeof(WCHAR))
2455 DWORD dwPathLen = strlenW(szBuff) + 1;
2457 if (dwDestLen >= dwPathLen)
2461 dwDestLen -= dwPathLen;
2462 memcpy(lpszDest + szResLen, szBuff, dwPathLen * sizeof(WCHAR));
2464 dwResLen = strlenW(lpszRes) + 1;
2465 if (dwDestLen >= dwResLen + 1)
2467 lpszDest[szResLen + dwPathLen-1] = '/';
2468 memcpy(lpszDest + szResLen + dwPathLen, lpszRes, dwResLen * sizeof(WCHAR));
2473 MLFreeLibrary(hMod);
2479 /***********************************************************************
2480 * UrlFixupW [SHLWAPI.462]
2482 * Checks the scheme part of a URL and attempts to correct misspellings.
2485 * lpszUrl [I] Pointer to the URL to be corrected
2486 * lpszTranslatedUrl [O] Pointer to a buffer to store corrected URL
2487 * dwMaxChars [I] Maximum size of corrected URL
2490 * success: S_OK if URL corrected or already correct
2491 * failure: S_FALSE if unable to correct / COM error code if other error
2494 HRESULT WINAPI UrlFixupW(LPCWSTR url, LPWSTR translatedUrl, DWORD maxChars)
2498 FIXME("(%s,%p,%d) STUB\n", debugstr_w(url), translatedUrl, maxChars);
2503 srcLen = lstrlenW(url) + 1;
2505 /* For now just copy the URL directly */
2506 lstrcpynW(translatedUrl, url, (maxChars < srcLen) ? maxChars : srcLen);