4 * Copyright 2000 Huw D M Davies for CodeWeavers.
13 #include "wine/unicode.h"
16 #define NO_SHLWAPI_STREAM
18 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(shell
);
24 LPCWSTR pScheme
; /* [out] start of scheme */
25 DWORD szScheme
; /* [out] size of scheme (until colon) */
26 LPCWSTR pUserName
; /* [out] start of Username */
27 DWORD szUserName
; /* [out] size of Username (until ":" or "@") */
28 LPCWSTR pPassword
; /* [out] start of Password */
29 DWORD szPassword
; /* [out] size of Password (until "@") */
30 LPCWSTR pHostName
; /* [out] start of Hostname */
31 DWORD szHostName
; /* [out] size of Hostname (until ":" or "/") */
32 LPCWSTR pPort
; /* [out] start of Port */
33 DWORD szPort
; /* [out] size of Port (until "/" or eos) */
34 LPCWSTR pQuery
; /* [out] start of Query */
35 DWORD szQuery
; /* [out] size of Query (until eos) */
45 static const WCHAR fileW
[] = {'f','i','l','e','\0'};
47 static const unsigned char HashDataLookup
[256] = {
48 0x01, 0x0E, 0x6E, 0x19, 0x61, 0xAE, 0x84, 0x77, 0x8A, 0xAA, 0x7D, 0x76, 0x1B,
49 0xE9, 0x8C, 0x33, 0x57, 0xC5, 0xB1, 0x6B, 0xEA, 0xA9, 0x38, 0x44, 0x1E, 0x07,
50 0xAD, 0x49, 0xBC, 0x28, 0x24, 0x41, 0x31, 0xD5, 0x68, 0xBE, 0x39, 0xD3, 0x94,
51 0xDF, 0x30, 0x73, 0x0F, 0x02, 0x43, 0xBA, 0xD2, 0x1C, 0x0C, 0xB5, 0x67, 0x46,
52 0x16, 0x3A, 0x4B, 0x4E, 0xB7, 0xA7, 0xEE, 0x9D, 0x7C, 0x93, 0xAC, 0x90, 0xB0,
53 0xA1, 0x8D, 0x56, 0x3C, 0x42, 0x80, 0x53, 0x9C, 0xF1, 0x4F, 0x2E, 0xA8, 0xC6,
54 0x29, 0xFE, 0xB2, 0x55, 0xFD, 0xED, 0xFA, 0x9A, 0x85, 0x58, 0x23, 0xCE, 0x5F,
55 0x74, 0xFC, 0xC0, 0x36, 0xDD, 0x66, 0xDA, 0xFF, 0xF0, 0x52, 0x6A, 0x9E, 0xC9,
56 0x3D, 0x03, 0x59, 0x09, 0x2A, 0x9B, 0x9F, 0x5D, 0xA6, 0x50, 0x32, 0x22, 0xAF,
57 0xC3, 0x64, 0x63, 0x1A, 0x96, 0x10, 0x91, 0x04, 0x21, 0x08, 0xBD, 0x79, 0x40,
58 0x4D, 0x48, 0xD0, 0xF5, 0x82, 0x7A, 0x8F, 0x37, 0x69, 0x86, 0x1D, 0xA4, 0xB9,
59 0xC2, 0xC1, 0xEF, 0x65, 0xF2, 0x05, 0xAB, 0x7E, 0x0B, 0x4A, 0x3B, 0x89, 0xE4,
60 0x6C, 0xBF, 0xE8, 0x8B, 0x06, 0x18, 0x51, 0x14, 0x7F, 0x11, 0x5B, 0x5C, 0xFB,
61 0x97, 0xE1, 0xCF, 0x15, 0x62, 0x71, 0x70, 0x54, 0xE2, 0x12, 0xD6, 0xC7, 0xBB,
62 0x0D, 0x20, 0x5E, 0xDC, 0xE0, 0xD4, 0xF7, 0xCC, 0xC4, 0x2B, 0xF9, 0xEC, 0x2D,
63 0xF4, 0x6F, 0xB6, 0x99, 0x88, 0x81, 0x5A, 0xD9, 0xCA, 0x13, 0xA5, 0xE7, 0x47,
64 0xE6, 0x8E, 0x60, 0xE3, 0x3E, 0xB3, 0xF6, 0x72, 0xA2, 0x35, 0xA0, 0xD7, 0xCD,
65 0xB4, 0x2F, 0x6D, 0x2C, 0x26, 0x1F, 0x95, 0x87, 0x00, 0xD8, 0x34, 0x3F, 0x17,
66 0x25, 0x45, 0x27, 0x75, 0x92, 0xB8, 0xA3, 0xC8, 0xDE, 0xEB, 0xF8, 0xF3, 0xDB,
67 0x0A, 0x98, 0x83, 0x7B, 0xE5, 0xCB, 0x4C, 0x78, 0xD1 };
69 static BOOL
URL_NeedEscapeA(CHAR ch
, DWORD dwFlags
)
75 if(dwFlags
& URL_ESCAPE_SPACES_ONLY
) {
82 if ((dwFlags
& URL_ESCAPE_PERCENT
) && (ch
== '%'))
85 if (ch
<= 31 || ch
>= 127)
107 if (dwFlags
& URL_ESCAPE_SEGMENT_ONLY
) return TRUE
;
114 static BOOL
URL_NeedEscapeW(WCHAR ch
, DWORD dwFlags
)
120 if(dwFlags
& URL_ESCAPE_SPACES_ONLY
) {
127 if ((dwFlags
& URL_ESCAPE_PERCENT
) && (ch
== L
'%'))
130 if (ch
<= 31 || ch
>= 127)
152 if (dwFlags
& URL_ESCAPE_SEGMENT_ONLY
) return TRUE
;
159 static BOOL
URL_JustLocation(LPCWSTR str
)
161 while(*str
&& (*str
== L
'/')) str
++;
163 while (*str
&& ((*str
== L
'-') ||
165 isalnumW(*str
))) str
++;
166 if (*str
== L
'/') return FALSE
;
172 /*************************************************************************
173 * UrlCanonicalizeA [SHLWAPI.@]
175 * Uses the W version to do job.
177 HRESULT WINAPI
UrlCanonicalizeA(LPCSTR pszUrl
, LPSTR pszCanonicalized
,
178 LPDWORD pcchCanonicalized
, DWORD dwFlags
)
180 LPWSTR base
, canonical
;
181 DWORD ret
, len
, len2
;
183 TRACE("(%s %p %p 0x%08lx) using W version\n",
184 debugstr_a(pszUrl
), pszCanonicalized
,
185 pcchCanonicalized
, dwFlags
);
187 base
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0,
188 (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
189 canonical
= base
+ INTERNET_MAX_URL_LENGTH
;
191 MultiByteToWideChar(0, 0, pszUrl
, -1, base
, INTERNET_MAX_URL_LENGTH
);
192 len
= INTERNET_MAX_URL_LENGTH
;
194 ret
= UrlCanonicalizeW(base
, canonical
, &len
, dwFlags
);
196 HeapFree(GetProcessHeap(), 0, base
);
200 len2
= WideCharToMultiByte(0, 0, canonical
, len
, 0, 0, 0, 0);
201 if (len2
> *pcchCanonicalized
) {
202 *pcchCanonicalized
= len
;
203 HeapFree(GetProcessHeap(), 0, base
);
206 WideCharToMultiByte(0, 0, canonical
, len
+1, pszCanonicalized
,
207 *pcchCanonicalized
, 0, 0);
208 *pcchCanonicalized
= len2
;
209 HeapFree(GetProcessHeap(), 0, base
);
213 /*************************************************************************
214 * UrlCanonicalizeW [SHLWAPI.@]
217 * MSDN is wrong (at 10/30/01 - go figure). This should support the
218 * following flags: GLA
219 * URL_DONT_ESCAPE_EXTRA_INFO 0x02000000
220 * URL_ESCAPE_SPACES_ONLY 0x04000000
221 * URL_ESCAPE_PERCENT 0x00001000
222 * URL_ESCAPE_UNSAFE 0x10000000
223 * URL_UNESCAPE 0x10000000
224 * URL_DONT_SIMPLIFY 0x08000000
225 * URL_ESCAPE_SEGMENT_ONLY 0x00002000
227 HRESULT WINAPI
UrlCanonicalizeW(LPCWSTR pszUrl
, LPWSTR pszCanonicalized
,
228 LPDWORD pcchCanonicalized
, DWORD dwFlags
)
232 LPWSTR lpszUrlCpy
, wk1
, wk2
, mp
, root
;
233 INT nLen
, nByteLen
, state
;
235 TRACE("(%s %p %p 0x%08lx)\n", debugstr_w(pszUrl
), pszCanonicalized
,
236 pcchCanonicalized
, dwFlags
);
238 nByteLen
= (lstrlenW(pszUrl
) + 1) * sizeof(WCHAR
); /* length in bytes */
239 lpszUrlCpy
= HeapAlloc(GetProcessHeap(), 0, nByteLen
);
241 if (dwFlags
& URL_DONT_SIMPLIFY
)
242 memcpy(lpszUrlCpy
, pszUrl
, nByteLen
);
248 * 1 have 2[+] alnum 2,3
249 * 2 have scheme (found :) 4,6,3
250 * 3 failed (no location)
252 * 5 have 1[+] alnum 6,3
253 * 6 have location (found /) save root location
256 wk1
= (LPWSTR
)pszUrl
;
262 if (!isalnumW(*wk1
)) {state
= 3; break;}
264 if (!isalnumW(*wk1
)) {state
= 3; break;}
270 if (*wk1
++ == L
':') state
= 2;
273 if (*wk1
!= L
'/') {state
= 3; break;}
275 if (*wk1
!= L
'/') {state
= 6; break;}
285 if (!isalnumW(*wk1
) && (*wk1
!= L
'-')) {state
= 3; break;}
286 while(isalnumW(*wk1
) || (*wk1
== L
'-')) *wk2
++ = *wk1
++;
290 if (*wk1
!= L
'/') {state
= 3; break;}
295 /* Now at root location, cannot back up any more. */
296 /* "root" will point at the '/' */
299 TRACE("wk1=%c\n", (CHAR
)*wk1
);
300 mp
= strchrW(wk1
, L
'/');
308 strncpyW(wk2
, wk1
, nLen
);
312 TRACE("found '/.'\n");
313 if (*(wk1
+1) == L
'/') {
314 /* case of /./ -> skip the ./ */
317 else if (*(wk1
+1) == L
'.') {
318 /* found /.. look for next / */
319 TRACE("found '/..'\n");
320 if (*(wk1
+2) == L
'/') {
321 /* case /../ -> need to backup wk2 */
322 TRACE("found '/../'\n");
323 *(wk2
-1) = L
'\0'; /* set end of string */
324 mp
= strrchrW(root
, L
'/');
325 if (mp
&& (mp
>= root
)) {
326 /* found valid backup point */
331 /* did not find point, restore '/' */
341 FIXME("how did we get here - state=%d\n", state
);
346 TRACE("Simplified, orig <%s>, simple <%s>\n",
347 debugstr_w(pszUrl
), debugstr_w(lpszUrlCpy
));
350 if(dwFlags
& URL_UNESCAPE
)
351 UrlUnescapeW(lpszUrlCpy
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
353 if((EscapeFlags
= dwFlags
& (URL_ESCAPE_UNSAFE
|
354 URL_ESCAPE_SPACES_ONLY
|
356 URL_DONT_ESCAPE_EXTRA_INFO
|
357 URL_ESCAPE_SEGMENT_ONLY
))) {
358 EscapeFlags
&= ~URL_ESCAPE_UNSAFE
;
359 hr
= UrlEscapeW(lpszUrlCpy
, pszCanonicalized
, pcchCanonicalized
,
361 } else { /* No escaping needed, just copy the string */
362 nLen
= lstrlenW(lpszUrlCpy
);
363 if(nLen
< *pcchCanonicalized
)
364 memcpy(pszCanonicalized
, lpszUrlCpy
, (nLen
+ 1)*sizeof(WCHAR
));
369 *pcchCanonicalized
= nLen
;
372 HeapFree(GetProcessHeap(), 0, lpszUrlCpy
);
375 TRACE("result %s\n", debugstr_w(pszCanonicalized
));
380 /*************************************************************************
381 * UrlCombineA [SHLWAPI.@]
383 * Uses the W version to do job.
385 HRESULT WINAPI
UrlCombineA(LPCSTR pszBase
, LPCSTR pszRelative
,
386 LPSTR pszCombined
, LPDWORD pcchCombined
,
389 LPWSTR base
, relative
, combined
;
390 DWORD ret
, len
, len2
;
392 TRACE("(base %s, Relative %s, Combine size %ld, flags %08lx) using W version\n",
393 debugstr_a(pszBase
),debugstr_a(pszRelative
),
394 *pcchCombined
,dwFlags
);
396 base
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0,
397 (3*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
398 relative
= base
+ INTERNET_MAX_URL_LENGTH
;
399 combined
= relative
+ INTERNET_MAX_URL_LENGTH
;
401 MultiByteToWideChar(0, 0, pszBase
, -1, base
, INTERNET_MAX_URL_LENGTH
);
402 MultiByteToWideChar(0, 0, pszRelative
, -1, relative
, INTERNET_MAX_URL_LENGTH
);
403 len
= INTERNET_MAX_URL_LENGTH
;
405 ret
= UrlCombineW(base
, relative
, combined
, &len
, dwFlags
);
407 HeapFree(GetProcessHeap(), 0, base
);
411 len2
= WideCharToMultiByte(0, 0, combined
, len
, 0, 0, 0, 0);
412 if (len2
> *pcchCombined
) {
413 *pcchCombined
= len2
;
414 HeapFree(GetProcessHeap(), 0, base
);
417 WideCharToMultiByte(0, 0, combined
, len
+1, pszCombined
, *pcchCombined
,
419 *pcchCombined
= len2
;
420 HeapFree(GetProcessHeap(), 0, base
);
424 /*************************************************************************
425 * UrlCombineW [SHLWAPI.@]
427 HRESULT WINAPI
UrlCombineW(LPCWSTR pszBase
, LPCWSTR pszRelative
,
428 LPWSTR pszCombined
, LPDWORD pcchCombined
,
431 UNKNOWN_SHLWAPI_2 base
, relative
;
432 DWORD myflags
, sizeloc
= 0;
433 DWORD len
, res1
, res2
, process_case
= 0;
434 LPWSTR work
, preliminary
, mbase
, mrelative
;
435 WCHAR myfilestr
[] = {'f','i','l','e',':','/','/','/','\0'};
436 WCHAR single_slash
[] = {'/','\0'};
439 TRACE("(base %s, Relative %s, Combine size %ld, flags %08lx)\n",
440 debugstr_w(pszBase
),debugstr_w(pszRelative
),
441 *pcchCombined
,dwFlags
);
446 /* Get space for duplicates of the input and the output */
447 preliminary
= HeapAlloc(GetProcessHeap(), 0, (3*INTERNET_MAX_URL_LENGTH
) *
449 mbase
= preliminary
+ INTERNET_MAX_URL_LENGTH
;
450 mrelative
= mbase
+ INTERNET_MAX_URL_LENGTH
;
451 *preliminary
= L
'\0';
453 /* Canonicalize the base input prior to looking for the scheme */
454 myflags
= dwFlags
& (URL_DONT_SIMPLIFY
| URL_UNESCAPE
);
455 len
= INTERNET_MAX_URL_LENGTH
;
456 ret
= UrlCanonicalizeW(pszBase
, mbase
, &len
, myflags
);
458 /* Canonicalize the relative input prior to looking for the scheme */
459 len
= INTERNET_MAX_URL_LENGTH
;
460 ret
= UrlCanonicalizeW(pszRelative
, mrelative
, &len
, myflags
);
462 /* See if the base has a scheme */
463 res1
= SHLWAPI_2(mbase
, &base
);
465 /* if pszBase has no scheme, then return pszRelative */
466 TRACE("no scheme detected in Base\n");
471 /* get size of location field (if it exists) */
472 work
= (LPWSTR
)base
.ap2
;
474 if (*work
++ == L
'/') {
475 if (*work
++ == L
'/') {
476 /* At this point have start of location and
477 * it ends at next '/' or end of string.
479 while(*work
&& (*work
!= L
'/')) work
++;
480 sizeloc
= work
- base
.ap2
;
484 /* Change .sizep2 to not have the last leaf in it,
485 * Note: we need to start after the location (if it exists)
487 work
= strrchrW((base
.ap2
+sizeloc
), L
'/');
489 len
= work
- base
.ap2
+ 1;
494 * .ap2 points to location (starting with '//')
495 * .sizep2 length of location (above) and rest less the last
497 * sizeloc length of location (above) up to but not including
501 res2
= SHLWAPI_2(mrelative
, &relative
);
503 /* no scheme in pszRelative */
504 TRACE("no scheme detected in Relative\n");
505 relative
.ap2
= mrelative
; /* case 3,4,5 depends on this */
506 relative
.sizep2
= strlenW(mrelative
);
507 if (*pszRelative
== L
':') {
508 /* case that is either left alone or uses pszBase */
509 if (dwFlags
& URL_PLUGGABLE_PROTOCOL
) {
516 if (isalnum(*mrelative
) && (*(mrelative
+ 1) == L
':')) {
517 /* case that becomes "file:///" */
518 strcpyW(preliminary
, myfilestr
);
522 if ((*mrelative
== L
'/') && (*(mrelative
+1) == L
'/')) {
523 /* pszRelative has location and rest */
527 if (*mrelative
== L
'/') {
528 /* case where pszRelative is root to location */
532 process_case
= (*base
.ap2
== L
'/') ? 5 : 3;
536 /* handle cases where pszRelative has scheme */
537 if ((base
.sizep1
== relative
.sizep1
) &&
538 (strncmpW(base
.ap1
, relative
.ap1
, base
.sizep1
) == 0)) {
540 /* since the schemes are the same */
541 if ((*relative
.ap2
== L
'/') && (*(relative
.ap2
+1) == L
'/')) {
542 /* case where pszRelative replaces location and following */
546 if (*relative
.ap2
== L
'/') {
547 /* case where pszRelative is root to location */
551 /* case where scheme is followed by document path */
555 if ((*relative
.ap2
== L
'/') && (*(relative
.ap2
+1) == L
'/')) {
556 /* case where pszRelative replaces scheme, location,
557 * and following and handles PLUGGABLE
564 } while(FALSE
); /* a litte trick to allow easy exit from nested if's */
568 switch (process_case
) {
571 * Return pszRelative appended to what ever is in pszCombined,
572 * (which may the string "file:///"
574 len
= strlenW(mrelative
) + strlenW(preliminary
);
575 if (len
+1 > *pcchCombined
) {
580 strcatW(preliminary
, mrelative
);
584 * Same as case 1, but if URL_PLUGGABLE_PROTOCOL was specified
585 * and pszRelative starts with "//", then append a "/"
587 len
= strlenW(mrelative
) + 1;
588 if (len
+1 > *pcchCombined
) {
593 strcpyW(preliminary
, mrelative
);
594 if (!(dwFlags
& URL_PLUGGABLE_PROTOCOL
) &&
595 URL_JustLocation(relative
.ap2
))
596 strcatW(preliminary
, single_slash
);
600 * Return the pszBase scheme with pszRelative. Basicly
601 * keeps the scheme and replaces the domain and following.
603 len
= base
.sizep1
+ 1 + relative
.sizep2
+ 1;
604 if (len
+1 > *pcchCombined
) {
609 strncpyW(preliminary
, base
.ap1
, base
.sizep1
+ 1);
610 work
= preliminary
+ base
.sizep1
+ 1;
611 strcpyW(work
, relative
.ap2
);
612 if (!(dwFlags
& URL_PLUGGABLE_PROTOCOL
) &&
613 URL_JustLocation(relative
.ap2
))
614 strcatW(work
, single_slash
);
618 * Return the pszBase scheme and location but everything
619 * after the location is pszRelative. (Replace document
622 len
= base
.sizep1
+ 1 + sizeloc
+ relative
.sizep2
+ 1;
623 if (len
+1 > *pcchCombined
) {
628 strncpyW(preliminary
, base
.ap1
, base
.sizep1
+1+sizeloc
);
629 work
= preliminary
+ base
.sizep1
+ 1 + sizeloc
;
630 if (dwFlags
& URL_PLUGGABLE_PROTOCOL
)
632 strcpyW(work
, relative
.ap2
);
636 * Return the pszBase without its document (if any) and
637 * append pszRelative after its scheme.
639 len
= base
.sizep1
+ 1 + base
.sizep2
+ relative
.sizep2
;
640 if (len
+1 > *pcchCombined
) {
645 strncpyW(preliminary
, base
.ap1
, base
.sizep1
+1+base
.sizep2
);
646 work
= preliminary
+ base
.sizep1
+1+base
.sizep2
- 1;
649 strcpyW(work
, relative
.ap2
);
653 FIXME("How did we get here????? process_case=%ld\n", process_case
);
659 * Now that the combining is done, process the escape options if
660 * necessary, otherwise just copy the string.
662 myflags
= dwFlags
& (URL_ESCAPE_PERCENT
|
663 URL_ESCAPE_SPACES_ONLY
|
664 URL_DONT_ESCAPE_EXTRA_INFO
|
665 URL_ESCAPE_SEGMENT_ONLY
);
667 ret
= UrlEscapeW(preliminary
, pszCombined
,
668 pcchCombined
, myflags
);
670 len
= (strlenW(preliminary
) + 1) * sizeof(WCHAR
);
671 memcpy(pszCombined
, preliminary
, len
);
672 *pcchCombined
= strlenW(preliminary
);
674 TRACE("return-%ld len=%ld, %s\n",
675 process_case
, *pcchCombined
, debugstr_w(pszCombined
));
677 HeapFree(GetProcessHeap(), 0, preliminary
);
681 /*************************************************************************
682 * UrlEscapeA [SHLWAPI.@]
684 * Converts unsafe characters into their escape sequences.
686 * The converted string is returned in pszEscaped if the buffer size
687 * (which should be supplied in pcchEscaped) is large enough, in this
688 * case the function returns S_OK and pcchEscaped contains the length
689 * of the escaped string. If the buffer is not large enough the
690 * function returns E_POINTER and pcchEscaped contains the required
691 * buffer size (including room for the '\0').
693 * By default the function stops converting at the first '?' or
694 * '#'. [MSDN says differently]. If URL_ESCAPE_SPACE_ONLY flag is set
695 * then only spaces are converted, but the conversion continues past a
699 * Have now implemented the following flags:
700 * URL_ESCAPE_SPACES_ONLY
701 * URL_DONT_ESCAPE_EXTRA_INFO
702 * URL_ESCAPE_SEGMENT_ONLY
704 * Initial testing seems to indicate that this is now working like
705 * native shlwapi version 5. Note that these functions did not work
706 * well (or at all) in shlwapi version 4.
709 HRESULT WINAPI
UrlEscapeA(
716 DWORD needed
= 0, ret
;
717 BOOL stop_escaping
= FALSE
;
718 char next
[3], *dst
= pszEscaped
;
719 char hex
[] = "0123456789ABCDEF";
722 TRACE("(%s %p %p 0x%08lx)\n", debugstr_a(pszUrl
), pszEscaped
,
723 pcchEscaped
, dwFlags
);
725 if(dwFlags
& ~(URL_ESCAPE_SPACES_ONLY
|
726 URL_ESCAPE_SEGMENT_ONLY
|
727 URL_DONT_ESCAPE_EXTRA_INFO
|
729 FIXME("Unimplemented flags: %08lx\n", dwFlags
);
732 if (dwFlags
& URL_ESCAPE_SPACES_ONLY
)
733 /* if SPACES_ONLY specified, reset the other controls */
734 dwFlags
&= ~(URL_DONT_ESCAPE_EXTRA_INFO
|
736 URL_ESCAPE_SEGMENT_ONLY
);
739 /* if SPACES_ONLY *not* specified the assume DONT_ESCAPE_EXTRA_INFO */
740 dwFlags
|= URL_DONT_ESCAPE_EXTRA_INFO
;
742 for(src
= pszUrl
; *src
; src
++) {
743 if(!(dwFlags
& URL_ESCAPE_SEGMENT_ONLY
) &&
744 (dwFlags
& URL_DONT_ESCAPE_EXTRA_INFO
) &&
745 (*src
== '#' || *src
== '?'))
746 stop_escaping
= TRUE
;
748 if(URL_NeedEscapeA(*src
, dwFlags
) && stop_escaping
== FALSE
) {
749 /* TRACE("escaping %c\n", *src); */
751 next
[1] = hex
[(*src
>> 4) & 0xf];
752 next
[2] = hex
[*src
& 0xf];
755 /* TRACE("passing %c\n", *src); */
760 if(needed
+ len
<= *pcchEscaped
) {
761 memcpy(dst
, next
, len
);
767 if(needed
< *pcchEscaped
) {
771 needed
++; /* add one for the '\0' */
774 *pcchEscaped
= needed
;
778 /*************************************************************************
779 * UrlEscapeW [SHLWAPI.@]
781 * See UrlEscapeA for list of assumptions, bugs, and FIXMEs
783 HRESULT WINAPI
UrlEscapeW(
790 DWORD needed
= 0, ret
;
791 BOOL stop_escaping
= FALSE
;
792 WCHAR next
[5], *dst
= pszEscaped
;
793 CHAR hex
[] = "0123456789ABCDEF";
796 TRACE("(%s %p %p 0x%08lx)\n", debugstr_w(pszUrl
), pszEscaped
,
797 pcchEscaped
, dwFlags
);
799 if(dwFlags
& ~(URL_ESCAPE_SPACES_ONLY
|
800 URL_ESCAPE_SEGMENT_ONLY
|
801 URL_DONT_ESCAPE_EXTRA_INFO
|
803 FIXME("Unimplemented flags: %08lx\n", dwFlags
);
806 if (dwFlags
& URL_ESCAPE_SPACES_ONLY
)
807 /* if SPACES_ONLY specified, reset the other controls */
808 dwFlags
&= ~(URL_DONT_ESCAPE_EXTRA_INFO
|
810 URL_ESCAPE_SEGMENT_ONLY
);
813 /* if SPACES_ONLY *not* specified the assume DONT_ESCAPE_EXTRA_INFO */
814 dwFlags
|= URL_DONT_ESCAPE_EXTRA_INFO
;
816 for(src
= pszUrl
; *src
; src
++) {
818 * if(!(dwFlags & URL_ESCAPE_SPACES_ONLY) &&
819 * (*src == L'#' || *src == L'?'))
820 * stop_escaping = TRUE;
822 if(!(dwFlags
& URL_ESCAPE_SEGMENT_ONLY
) &&
823 (dwFlags
& URL_DONT_ESCAPE_EXTRA_INFO
) &&
824 (*src
== L
'#' || *src
== L
'?'))
825 stop_escaping
= TRUE
;
827 if(URL_NeedEscapeW(*src
, dwFlags
) && stop_escaping
== FALSE
) {
828 /* TRACE("escaping %c\n", *src); */
831 * I would have assumed that the W form would escape
832 * the character with 4 hex digits (or even 8),
833 * however, experiments show that native shlwapi escapes
834 * with only 2 hex digits.
835 * next[1] = hex[(*src >> 12) & 0xf];
836 * next[2] = hex[(*src >> 8) & 0xf];
837 * next[3] = hex[(*src >> 4) & 0xf];
838 * next[4] = hex[*src & 0xf];
841 next
[1] = hex
[(*src
>> 4) & 0xf];
842 next
[2] = hex
[*src
& 0xf];
845 /* TRACE("passing %c\n", *src); */
850 if(needed
+ len
<= *pcchEscaped
) {
851 memcpy(dst
, next
, len
*sizeof(WCHAR
));
857 if(needed
< *pcchEscaped
) {
861 needed
++; /* add one for the '\0' */
864 *pcchEscaped
= needed
;
869 /*************************************************************************
870 * UrlUnescapeA [SHLWAPI.@]
872 * Converts escape sequences back to ordinary characters.
874 * If URL_ESCAPE_INPLACE is set in dwFlags then pszUnescaped and
875 * pcchUnescaped are ignored and the converted string is returned in
876 * pszUrl, otherwise the string is returned in pszUnescaped.
877 * pcchUnescaped should contain the size of pszUnescaped on calling
878 * and will contain the length the the returned string on return if
879 * the buffer is big enough else it will contain the buffer size
880 * required (including room for the '\0'). The function returns S_OK
881 * on success or E_POINTER if the buffer is not large enough. If the
882 * URL_DONT_ESCAPE_EXTRA_INFO flag is set then the conversion stops at
883 * the first occurrence of either '?' or '#'.
886 HRESULT WINAPI
UrlUnescapeA(
889 LPDWORD pcchUnescaped
,
896 BOOL stop_unescaping
= FALSE
;
898 TRACE("(%s, %p, %p, 0x%08lx)\n", debugstr_a(pszUrl
), pszUnescaped
,
899 pcchUnescaped
, dwFlags
);
901 if(dwFlags
& URL_UNESCAPE_INPLACE
)
906 for(src
= pszUrl
, needed
= 0; *src
; src
++, needed
++) {
907 if(dwFlags
& URL_DONT_UNESCAPE_EXTRA_INFO
&&
908 (*src
== '#' || *src
== '?')) {
909 stop_unescaping
= TRUE
;
911 } else if(*src
== '%' && isxdigit(*(src
+ 1)) && isxdigit(*(src
+ 2))
912 && stop_unescaping
== FALSE
) {
915 memcpy(buf
, src
+ 1, 2);
917 ih
= strtol(buf
, NULL
, 16);
919 src
+= 2; /* Advance to end of escape */
923 if(dwFlags
& URL_UNESCAPE_INPLACE
|| needed
< *pcchUnescaped
)
927 if(dwFlags
& URL_UNESCAPE_INPLACE
|| needed
< *pcchUnescaped
) {
931 needed
++; /* add one for the '\0' */
934 if(!(dwFlags
& URL_UNESCAPE_INPLACE
))
935 *pcchUnescaped
= needed
;
938 TRACE("result %s\n", (dwFlags
& URL_UNESCAPE_INPLACE
) ?
939 debugstr_a(pszUrl
) : debugstr_a(pszUnescaped
));
945 /*************************************************************************
946 * UrlUnescapeW [SHLWAPI.@]
948 * See UrlUnescapeA for list of assumptions, bugs, and FIXMEs
950 HRESULT WINAPI
UrlUnescapeW(
953 LPDWORD pcchUnescaped
,
960 BOOL stop_unescaping
= FALSE
;
962 TRACE("(%s, %p, %p, 0x%08lx)\n", debugstr_w(pszUrl
), pszUnescaped
,
963 pcchUnescaped
, dwFlags
);
965 if(dwFlags
& URL_UNESCAPE_INPLACE
)
966 dst
= (WCHAR
*)pszUrl
;
970 for(src
= pszUrl
, needed
= 0; *src
; src
++, needed
++) {
971 if(dwFlags
& URL_DONT_UNESCAPE_EXTRA_INFO
&&
972 (*src
== L
'#' || *src
== L
'?')) {
973 stop_unescaping
= TRUE
;
975 } else if(*src
== L
'%' && isxdigitW(*(src
+ 1)) && isxdigitW(*(src
+ 2))
976 && stop_unescaping
== FALSE
) {
979 memcpy(buf
, src
+ 1, 2*sizeof(WCHAR
));
983 src
+= 2; /* Advance to end of escape */
987 if(dwFlags
& URL_UNESCAPE_INPLACE
|| needed
< *pcchUnescaped
)
991 if(dwFlags
& URL_UNESCAPE_INPLACE
|| needed
< *pcchUnescaped
) {
995 needed
++; /* add one for the '\0' */
998 if(!(dwFlags
& URL_UNESCAPE_INPLACE
))
999 *pcchUnescaped
= needed
;
1002 TRACE("result %s\n", (dwFlags
& URL_UNESCAPE_INPLACE
) ?
1003 debugstr_w(pszUrl
) : debugstr_w(pszUnescaped
));
1009 /*************************************************************************
1010 * UrlGetLocationA [SHLWAPI.@]
1013 * MSDN (as of 2001-11-01) says that:
1014 * "The location is the segment of the URL starting with a ?
1016 * Neither V4 nor V5 of shlwapi.dll implement the '?' and always return
1018 * MSDN further states that:
1019 * "If a file URL has a query string, ther returned string
1020 * the query string."
1021 * In all test cases if the scheme starts with "fi" then a NULL is
1022 * returned. V5 gives the following results:
1023 * NULL file://aa/b/cd#hohoh
1024 * #hohoh http://aa/b/cd#hohoh
1025 * NULL fi://aa/b/cd#hohoh
1026 * #hohoh ff://aa/b/cd#hohoh
1028 LPCSTR WINAPI
UrlGetLocationA(
1031 UNKNOWN_SHLWAPI_1 base
;
1035 res1
= SHLWAPI_1(pszUrl
, &base
);
1036 if (res1
) return NULL
; /* invalid scheme */
1038 /* if scheme is file: then never return pointer */
1039 if (strncmp(base
.ap1
, "file", min(4,base
.sizep1
)) == 0) return NULL
;
1041 /* Look for '#' and return its addr */
1042 return strchr(base
.ap2
, '#');
1045 /*************************************************************************
1046 * UrlGetLocationW [SHLWAPI.@]
1048 * See UrlGetLocationA for list of assumptions, bugs, and FIXMEs
1050 LPCWSTR WINAPI
UrlGetLocationW(
1053 UNKNOWN_SHLWAPI_2 base
;
1057 res1
= SHLWAPI_2(pszUrl
, &base
);
1058 if (res1
) return NULL
; /* invalid scheme */
1060 /* if scheme is file: then never return pointer */
1061 if (strncmpW(base
.ap1
, fileW
, min(4,base
.sizep1
)) == 0) return NULL
;
1063 /* Look for '#' and return its addr */
1064 return strchrW(base
.ap2
, L
'#');
1067 /*************************************************************************
1068 * UrlCompareA [SHLWAPI.@]
1070 INT WINAPI
UrlCompareA(
1075 INT ret
, len
, len1
, len2
;
1078 return strcmp(pszUrl1
, pszUrl2
);
1079 len1
= strlen(pszUrl1
);
1080 if (pszUrl1
[len1
-1] == L
'/') len1
--;
1081 len2
= strlen(pszUrl2
);
1082 if (pszUrl2
[len2
-1] == L
'/') len2
--;
1084 return strncmp(pszUrl1
, pszUrl2
, len1
);
1085 len
= min(len1
, len2
);
1086 ret
= strncmp(pszUrl1
, pszUrl2
, len
);
1087 if (ret
) return ret
;
1088 if (len1
> len2
) return 1;
1092 /*************************************************************************
1093 * UrlCompareW [SHLWAPI.@]
1095 INT WINAPI
UrlCompareW(
1100 INT ret
, len
, len1
, len2
;
1103 return strcmpW(pszUrl1
, pszUrl2
);
1104 len1
= strlenW(pszUrl1
);
1105 if (pszUrl1
[len1
-1] == L
'/') len1
--;
1106 len2
= strlenW(pszUrl2
);
1107 if (pszUrl2
[len2
-1] == L
'/') len2
--;
1109 return strncmpW(pszUrl1
, pszUrl2
, len1
);
1110 len
= min(len1
, len2
);
1111 ret
= strncmpW(pszUrl1
, pszUrl2
, len
);
1112 if (ret
) return ret
;
1113 if (len1
> len2
) return 1;
1117 /*************************************************************************
1118 * HashData [SHLWAPI.@]
1120 * Hash an input block into a variable sized digest.
1122 BOOL WINAPI
HashData(const unsigned char *lpSrc
, INT nSrcLen
,
1123 unsigned char *lpDest
, INT nDestLen
)
1125 INT srcCount
= nSrcLen
- 1, destCount
= nDestLen
- 1;
1127 if (IsBadReadPtr(lpSrc
, nSrcLen
) ||
1128 IsBadWritePtr(lpDest
, nDestLen
))
1131 while (destCount
>= 0)
1133 lpDest
[destCount
] = (destCount
& 0xff);
1137 while (srcCount
>= 0)
1139 destCount
= nDestLen
- 1;
1140 while (destCount
>= 0)
1142 lpDest
[destCount
] = HashDataLookup
[lpSrc
[srcCount
] ^ lpDest
[destCount
]];
1150 /*************************************************************************
1151 * UrlHashA [SHLWAPI.@]
1153 * Hash an ASCII URL.
1155 HRESULT WINAPI
UrlHashA(LPCSTR pszUrl
, unsigned char *lpDest
, INT nDestLen
)
1157 if (IsBadStringPtrA(pszUrl
, -1) || IsBadWritePtr(lpDest
, nDestLen
))
1158 return E_INVALIDARG
;
1160 HashData(pszUrl
, strlen(pszUrl
), lpDest
, nDestLen
);
1164 /*************************************************************************
1165 * UrlApplySchemeA [SHLWAPI.@]
1167 HRESULT WINAPI
UrlApplySchemeA(LPCSTR pszIn
, LPSTR pszOut
, LPDWORD pcchOut
, DWORD dwFlags
)
1170 DWORD ret
, len
, len2
;
1172 TRACE("(in %s, out size %ld, flags %08lx) using W version\n",
1173 debugstr_a(pszIn
), *pcchOut
, dwFlags
);
1175 in
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0,
1176 (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
1177 out
= in
+ INTERNET_MAX_URL_LENGTH
;
1179 MultiByteToWideChar(0, 0, pszIn
, -1, in
, INTERNET_MAX_URL_LENGTH
);
1180 len
= INTERNET_MAX_URL_LENGTH
;
1182 ret
= UrlApplySchemeW(in
, out
, &len
, dwFlags
);
1183 if ((ret
!= S_OK
) && (ret
!= S_FALSE
)) {
1184 HeapFree(GetProcessHeap(), 0, in
);
1188 len2
= WideCharToMultiByte(0, 0, out
, len
+1, 0, 0, 0, 0);
1189 if (len2
> *pcchOut
) {
1191 HeapFree(GetProcessHeap(), 0, in
);
1194 WideCharToMultiByte(0, 0, out
, len
+1, pszOut
, *pcchOut
, 0, 0);
1196 HeapFree(GetProcessHeap(), 0, in
);
1200 HRESULT
URL_GuessScheme(LPCWSTR pszIn
, LPWSTR pszOut
, LPDWORD pcchOut
)
1205 DWORD value_len
, data_len
, dwType
;
1206 WCHAR reg_path
[MAX_PATH
];
1207 WCHAR value
[MAX_PATH
], data
[MAX_PATH
];
1210 MultiByteToWideChar(0, 0,
1211 "Software\\Microsoft\\Windows\\CurrentVersion\\URL\\Prefixes",
1212 -1, reg_path
, MAX_PATH
);
1213 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, reg_path
, 0, 1, &newkey
);
1215 while(value_len
= data_len
= MAX_PATH
,
1216 RegEnumValueW(newkey
, index
, value
, &value_len
,
1217 0, &dwType
, (LPVOID
)data
, &data_len
) == 0) {
1218 TRACE("guess %d %s is %s\n",
1219 index
, debugstr_w(value
), debugstr_w(data
));
1222 for(i
=0; i
<value_len
; i
++) {
1225 /* remember that TRUE is not-equal */
1226 j
= ChrCmpIW(Wxx
, Wyy
);
1229 if ((i
== value_len
) && !j
) {
1230 if (strlenW(data
) + strlenW(pszIn
) + 1 > *pcchOut
) {
1231 *pcchOut
= strlenW(data
) + strlenW(pszIn
) + 1;
1232 RegCloseKey(newkey
);
1235 strcpyW(pszOut
, data
);
1236 strcatW(pszOut
, pszIn
);
1237 *pcchOut
= strlenW(pszOut
);
1238 TRACE("matched and set to %s\n", debugstr_w(pszOut
));
1239 RegCloseKey(newkey
);
1244 RegCloseKey(newkey
);
1248 HRESULT
URL_ApplyDefault(LPCWSTR pszIn
, LPWSTR pszOut
, LPDWORD pcchOut
)
1251 DWORD data_len
, dwType
;
1252 WCHAR reg_path
[MAX_PATH
];
1253 WCHAR value
[MAX_PATH
], data
[MAX_PATH
];
1255 /* get and prepend default */
1256 MultiByteToWideChar(0, 0,
1257 "Software\\Microsoft\\Windows\\CurrentVersion\\URL\\DefaultPrefix",
1258 -1, reg_path
, MAX_PATH
);
1259 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, reg_path
, 0, 1, &newkey
);
1260 data_len
= MAX_PATH
;
1263 RegQueryValueExW(newkey
, value
, 0, &dwType
, (LPBYTE
)data
, &data_len
);
1264 RegCloseKey(newkey
);
1265 if (strlenW(data
) + strlenW(pszIn
) + 1 > *pcchOut
) {
1266 *pcchOut
= strlenW(data
) + strlenW(pszIn
) + 1;
1269 strcpyW(pszOut
, data
);
1270 strcatW(pszOut
, pszIn
);
1271 *pcchOut
= strlenW(pszOut
);
1272 TRACE("used default %s\n", debugstr_w(pszOut
));
1276 /*************************************************************************
1277 * UrlApplySchemeW [SHLWAPI.@]
1279 HRESULT WINAPI
UrlApplySchemeW(LPCWSTR pszIn
, LPWSTR pszOut
, LPDWORD pcchOut
, DWORD dwFlags
)
1281 UNKNOWN_SHLWAPI_2 in_scheme
;
1285 TRACE("(in %s, out size %ld, flags %08lx)\n",
1286 debugstr_w(pszIn
), *pcchOut
, dwFlags
);
1288 if (dwFlags
& URL_APPLY_GUESSFILE
) {
1289 FIXME("(%s %p %p(%ld) 0x%08lx): stub URL_APPLY_GUESSFILE not implemented\n",
1290 debugstr_w(pszIn
), pszOut
, pcchOut
, *pcchOut
, dwFlags
);
1291 strcpyW(pszOut
, pszIn
);
1292 *pcchOut
= strlenW(pszOut
);
1296 in_scheme
.size
= 24;
1297 /* See if the base has a scheme */
1298 res1
= SHLWAPI_2(pszIn
, &in_scheme
);
1300 /* no scheme in input, need to see if we need to guess */
1301 if (dwFlags
& URL_APPLY_GUESSSCHEME
) {
1302 if ((ret
= URL_GuessScheme(pszIn
, pszOut
, pcchOut
)) != -1)
1307 /* we have a scheme, see if valid (known scheme) */
1308 if (in_scheme
.fcncde
) {
1309 /* have valid scheme, so just copy and exit */
1310 if (strlenW(pszIn
) + 1 > *pcchOut
) {
1311 *pcchOut
= strlenW(pszIn
) + 1;
1314 strcpyW(pszOut
, pszIn
);
1315 *pcchOut
= strlenW(pszOut
);
1316 TRACE("valid scheme, returing copy\n");
1321 /* If we are here, then either invalid scheme,
1322 * or no scheme and can't/failed guess.
1324 if ( ( ((res1
== 0) && (dwFlags
& URL_APPLY_FORCEAPPLY
)) ||
1326 (dwFlags
& URL_APPLY_DEFAULT
)) {
1327 /* find and apply default scheme */
1328 return URL_ApplyDefault(pszIn
, pszOut
, pcchOut
);
1331 /* just copy and give proper return code */
1332 if (strlenW(pszIn
) + 1 > *pcchOut
) {
1333 *pcchOut
= strlenW(pszIn
) + 1;
1336 strcpyW(pszOut
, pszIn
);
1337 *pcchOut
= strlenW(pszOut
);
1338 TRACE("returing copy, left alone\n");
1342 /*************************************************************************
1343 * UrlIsA [SHLWAPI.@]
1345 BOOL WINAPI
UrlIsA(LPCSTR pszUrl
, URLIS Urlis
)
1347 UNKNOWN_SHLWAPI_1 base
;
1354 res1
= SHLWAPI_1(pszUrl
, &base
);
1355 if (res1
) return FALSE
; /* invalid scheme */
1356 if ((*base
.ap2
== '/') && (*(base
.ap2
+1) == '/'))
1357 /* has scheme followed by 2 '/' */
1362 case URLIS_NOHISTORY
:
1364 case URLIS_APPLIABLE
:
1365 case URLIS_DIRECTORY
:
1366 case URLIS_HASQUERY
:
1368 FIXME("(%s %d): stub\n", debugstr_a(pszUrl
), Urlis
);
1373 /*************************************************************************
1374 * UrlIsW [SHLWAPI.@]
1376 BOOL WINAPI
UrlIsW(LPCWSTR pszUrl
, URLIS Urlis
)
1378 UNKNOWN_SHLWAPI_2 base
;
1385 res1
= SHLWAPI_2(pszUrl
, &base
);
1386 if (res1
) return FALSE
; /* invalid scheme */
1387 if ((*base
.ap2
== L
'/') && (*(base
.ap2
+1) == L
'/'))
1388 /* has scheme followed by 2 '/' */
1393 case URLIS_NOHISTORY
:
1395 case URLIS_APPLIABLE
:
1396 case URLIS_DIRECTORY
:
1397 case URLIS_HASQUERY
:
1399 FIXME("(%s %d): stub\n", debugstr_w(pszUrl
), Urlis
);
1404 /*************************************************************************
1405 * UrlIsNoHistoryA [SHLWAPI.@]
1407 BOOL WINAPI
UrlIsNoHistoryA(LPCSTR pszUrl
)
1409 return UrlIsA(pszUrl
, URLIS_NOHISTORY
);
1412 /*************************************************************************
1413 * UrlIsNoHistoryW [SHLWAPI.@]
1415 BOOL WINAPI
UrlIsNoHistoryW(LPCWSTR pszUrl
)
1417 return UrlIsW(pszUrl
, URLIS_NOHISTORY
);
1420 /*************************************************************************
1421 * UrlIsOpaqueA [SHLWAPI.@]
1423 BOOL WINAPI
UrlIsOpaqueA(LPCSTR pszUrl
)
1425 return UrlIsA(pszUrl
, URLIS_OPAQUE
);
1428 /*************************************************************************
1429 * UrlIsOpaqueW [SHLWAPI.@]
1431 BOOL WINAPI
UrlIsOpaqueW(LPCWSTR pszUrl
)
1433 return UrlIsW(pszUrl
, URLIS_OPAQUE
);
1436 /*************************************************************************
1437 * Scans for characters of type "type" and when not matching found,
1438 * returns pointer to it and length in size.
1440 * Characters tested based on RFC 1738
1442 LPCWSTR
URL_ScanID(LPCWSTR start
, LPDWORD size
, WINE_URL_SCAN_TYPE type
)
1444 static DWORD alwayszero
= 0;
1453 if ( (islowerW(*start
) && isalphaW(*start
)) ||
1468 if ( isalphaW(*start
) ||
1470 /* user/password only characters */
1475 /* *extra* characters */
1478 (*start
== L
'\'') ||
1482 /* *safe* characters */
1490 } else if (*start
== L
'%') {
1491 if (isxdigitW(*(start
+1)) &&
1492 isxdigitW(*(start
+2))) {
1504 if (isdigitW(*start
)) {
1515 if (isalnumW(*start
) ||
1517 (*start
== L
'.') ) {
1526 FIXME("unknown type %d\n", type
);
1527 return (LPWSTR
)&alwayszero
;
1529 /* TRACE("scanned %ld characters next char %p<%c>\n",
1530 *size, start, *start); */
1534 /*************************************************************************
1535 * Attempt to parse URL into pieces.
1537 LONG
URL_ParseUrl(LPCWSTR pszUrl
, WINE_PARSE_URL
*pl
)
1541 memset(pl
, 0, sizeof(WINE_PARSE_URL
));
1542 pl
->pScheme
= pszUrl
;
1543 work
= URL_ScanID(pl
->pScheme
, &pl
->szScheme
, SCHEME
);
1544 if (!*work
|| (*work
!= L
':')) goto ERROR
;
1546 if ((*work
!= L
'/') || (*(work
+1) != L
'/')) goto ERROR
;
1547 pl
->pUserName
= work
+ 2;
1548 work
= URL_ScanID(pl
->pUserName
, &pl
->szUserName
, USERPASS
);
1549 if (*work
== L
':' ) {
1550 /* parse password */
1552 pl
->pPassword
= work
;
1553 work
= URL_ScanID(pl
->pPassword
, &pl
->szPassword
, USERPASS
);
1554 if (*work
!= L
'@') {
1555 /* what we just parsed must be the hostname and port
1556 * so reset pointers and clear then let it parse */
1557 pl
->szUserName
= pl
->szPassword
= 0;
1558 work
= pl
->pUserName
- 1;
1559 pl
->pUserName
= pl
->pPassword
= 0;
1561 } else if (*work
== L
'@') {
1565 } else if (!*work
|| (*work
== L
'/') || (*work
== L
'.')) {
1566 /* what was parsed was hostname, so reset pointers and let it parse */
1567 pl
->szUserName
= pl
->szPassword
= 0;
1568 work
= pl
->pUserName
- 1;
1569 pl
->pUserName
= pl
->pPassword
= 0;
1572 /* now start parsing hostname or hostnumber */
1574 pl
->pHostName
= work
;
1575 work
= URL_ScanID(pl
->pHostName
, &pl
->szHostName
, HOST
);
1576 if (*work
== L
':') {
1580 work
= URL_ScanID(pl
->pPort
, &pl
->szPort
, PORT
);
1582 if (*work
== L
'/') {
1583 /* see if query string */
1584 pl
->pQuery
= strchrW(work
, L
'?');
1585 if (pl
->pQuery
) pl
->szQuery
= strlenW(pl
->pQuery
);
1587 TRACE("parse successful: scheme=%p(%ld), user=%p(%ld), pass=%p(%ld), host=%p(%ld), port=%p(%ld), query=%p(%ld)\n",
1588 pl
->pScheme
, pl
->szScheme
,
1589 pl
->pUserName
, pl
->szUserName
,
1590 pl
->pPassword
, pl
->szPassword
,
1591 pl
->pHostName
, pl
->szHostName
,
1592 pl
->pPort
, pl
->szPort
,
1593 pl
->pQuery
, pl
->szQuery
);
1596 FIXME("failed to parse %s\n", debugstr_w(pszUrl
));
1597 return E_INVALIDARG
;
1600 /*************************************************************************
1601 * UrlGetPartA [SHLWAPI.@]
1603 HRESULT WINAPI
UrlGetPartA(LPCSTR pszIn
, LPSTR pszOut
, LPDWORD pcchOut
,
1604 DWORD dwPart
, DWORD dwFlags
)
1607 DWORD ret
, len
, len2
;
1609 in
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0,
1610 (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
1611 out
= in
+ INTERNET_MAX_URL_LENGTH
;
1613 MultiByteToWideChar(0, 0, pszIn
, -1, in
, INTERNET_MAX_URL_LENGTH
);
1615 len
= INTERNET_MAX_URL_LENGTH
;
1616 ret
= UrlGetPartW(in
, out
, &len
, dwPart
, dwFlags
);
1619 HeapFree(GetProcessHeap(), 0, in
);
1623 len2
= WideCharToMultiByte(0, 0, out
, len
, 0, 0, 0, 0);
1624 if (len2
> *pcchOut
) {
1626 HeapFree(GetProcessHeap(), 0, in
);
1629 WideCharToMultiByte(0, 0, out
, len
+1, pszOut
, *pcchOut
, 0, 0);
1631 HeapFree(GetProcessHeap(), 0, in
);
1635 /*************************************************************************
1636 * UrlGetPartW [SHLWAPI.@]
1638 HRESULT WINAPI
UrlGetPartW(LPCWSTR pszIn
, LPWSTR pszOut
, LPDWORD pcchOut
,
1639 DWORD dwPart
, DWORD dwFlags
)
1643 DWORD size
, schsize
;
1644 LPCWSTR addr
, schaddr
;
1647 TRACE("(%s %p %p(%ld) %08lx %08lx)\n",
1648 debugstr_w(pszIn
), pszOut
, pcchOut
, *pcchOut
, dwPart
, dwFlags
);
1650 ret
= URL_ParseUrl(pszIn
, &pl
);
1652 schaddr
= pl
.pScheme
;
1653 schsize
= pl
.szScheme
;
1656 case URL_PART_SCHEME
:
1657 if (!pl
.szScheme
) return E_INVALIDARG
;
1662 case URL_PART_HOSTNAME
:
1663 if (!pl
.szHostName
) return E_INVALIDARG
;
1664 addr
= pl
.pHostName
;
1665 size
= pl
.szHostName
;
1668 case URL_PART_USERNAME
:
1669 if (!pl
.szUserName
) return E_INVALIDARG
;
1670 addr
= pl
.pUserName
;
1671 size
= pl
.szUserName
;
1674 case URL_PART_PASSWORD
:
1675 if (!pl
.szPassword
) return E_INVALIDARG
;
1676 addr
= pl
.pPassword
;
1677 size
= pl
.szPassword
;
1681 if (!pl
.szPort
) return E_INVALIDARG
;
1686 case URL_PART_QUERY
:
1687 if (!pl
.szQuery
) return E_INVALIDARG
;
1693 return E_INVALIDARG
;
1696 if (dwFlags
== URL_PARTFLAG_KEEPSCHEME
) {
1697 if (*pcchOut
< size
+ schsize
+ 2) {
1698 *pcchOut
= size
+ schsize
+ 2;
1701 strncpyW(pszOut
, schaddr
, schsize
);
1702 work
= pszOut
+ schsize
;
1704 strncpyW(work
+1, addr
, size
);
1705 *pcchOut
= size
+ schsize
+ 1;
1710 if (*pcchOut
< size
+ 1) {*pcchOut
= size
+1; return E_POINTER
;}
1711 strncpyW(pszOut
, addr
, size
);
1713 work
= pszOut
+ size
;
1716 TRACE("len=%ld %s\n", *pcchOut
, debugstr_w(pszOut
));