ReactOS 0.4.16-dev-2534-gdcd45a5
url.c File Reference
#include <wchar.h>
#include "windef.h"
#include "winbase.h"
#include "ws2tcpip.h"
#include "winreg.h"
#include "winhttp.h"
#include "shlwapi.h"
#include "wine/debug.h"
#include "winhttp_private.h"
Include dependency graph for url.c:

Go to the source code of this file.

Classes

struct  url_component
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winhttp)
 
static DWORD set_component (struct url_component *comp, WCHAR *value, DWORD len, DWORD flags, BOOL *overflow)
 
static WCHARdecode_url (LPCWSTR url, DWORD *len)
 
static BOOL need_escape (WCHAR ch)
 
static BOOL escape_string (const WCHAR *src, DWORD src_len, WCHAR *dst, DWORD *dst_len)
 
static DWORD escape_url (const WCHAR *url, DWORD *len, WCHAR **ret)
 
static DWORD parse_port (const WCHAR *str, DWORD len, INTERNET_PORT *ret)
 
BOOL WINAPI WinHttpCrackUrl (const WCHAR *url, DWORD len, DWORD flags, URL_COMPONENTSW *uc)
 
static INTERNET_SCHEME get_scheme (const WCHAR *scheme, DWORD len)
 
static const WCHARget_scheme_string (INTERNET_SCHEME scheme)
 
static BOOL uses_default_port (INTERNET_SCHEME scheme, INTERNET_PORT port)
 
static DWORD get_comp_length (DWORD len, DWORD flags, WCHAR *comp)
 
static BOOL get_url_length (URL_COMPONENTS *uc, DWORD flags, DWORD *len)
 
BOOL WINAPI WinHttpCreateUrl (URL_COMPONENTS *uc, DWORD flags, WCHAR *url, DWORD *required)
 

Function Documentation

◆ decode_url()

static WCHAR * decode_url ( LPCWSTR  url,
DWORD len 
)
static

Definition at line 63 of file url.c.

64{
65 const WCHAR *p = url;
66 WCHAR hex[3], *q, *ret;
67
68 if (!(ret = malloc( *len * sizeof(WCHAR) ))) return NULL;
69 q = ret;
70 while (*len > 0)
71 {
72 if (p[0] == '%' && iswxdigit( p[1] ) && iswxdigit( p[2] ))
73 {
74 hex[0] = p[1];
75 hex[1] = p[2];
76 hex[2] = 0;
77 *q++ = wcstol( hex, NULL, 16 );
78 p += 3;
79 *len -= 3;
80 }
81 else
82 {
83 *q++ = *p++;
84 *len -= 1;
85 }
86 }
87 *len = q - ret;
88 return ret;
89}
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
_ACRTIMP __msvcrt_long __cdecl wcstol(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2747
return ret
Definition: mutex.c:146
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
int hex(char ch)
static const WCHAR url[]
Definition: encode.c:1384
#define iswxdigit(_c)
Definition: ctype.h:668
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by WinHttpCrackUrl().

◆ escape_string()

static BOOL escape_string ( const WCHAR src,
DWORD  src_len,
WCHAR dst,
DWORD dst_len 
)
static

Definition at line 103 of file url.c.

104{
105 static const WCHAR hex[] = L"0123456789ABCDEF";
106 WCHAR *p = dst;
107 DWORD i;
108
109 *dst_len = src_len;
110 for (i = 0; i < src_len; i++)
111 {
112 if (src[i] > 0xff) return FALSE;
113 if (need_escape( src[i] ))
114 {
115 if (dst)
116 {
117 p[0] = '%';
118 p[1] = hex[(src[i] >> 4) & 0xf];
119 p[2] = hex[src[i] & 0xf];
120 p += 3;
121 }
122 *dst_len += 2;
123 }
124 else if (dst) *p++ = src[i];
125 }
126
127 if (dst) dst[*dst_len] = 0;
128 return TRUE;
129}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BOOL need_escape(WCHAR ch)
Definition: url.c:91
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by escape_url(), and WinHttpCreateUrl().

◆ escape_url()

static DWORD escape_url ( const WCHAR url,
DWORD len,
WCHAR **  ret 
)
static

Definition at line 131 of file url.c.

132{
133 const WCHAR *p;
134 DWORD len_base, len_path;
135
136 if ((p = wcsrchr( url, '/' )))
137 {
138 len_base = p - url;
139 if (!escape_string( p, *len - len_base, NULL, &len_path )) return ERROR_INVALID_PARAMETER;
140 }
141 else
142 {
143 len_base = *len;
144 len_path = 0;
145 }
146
147 if (!(*ret = malloc( (len_base + len_path + 1) * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
148 memcpy( *ret, url, len_base * sizeof(WCHAR) );
149
150 if (p) escape_string( p, *len - (p - url), *ret + len_base, &len_path );
151 (*ret)[len_base + len_path] = 0;
152
153 *len = len_base + len_path;
154 return ERROR_SUCCESS;
155}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define wcsrchr
Definition: compat.h:16
static BOOL escape_string(const WCHAR *src, DWORD src_len, WCHAR *dst, DWORD *dst_len)
Definition: url.c:103
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by WinHttpCrackUrl().

◆ get_comp_length()

static DWORD get_comp_length ( DWORD  len,
DWORD  flags,
WCHAR comp 
)
static

Definition at line 371 of file url.c.

372{
373 DWORD ret;
374 unsigned int i;
375
376 ret = len ? len : lstrlenW( comp );
377 if (!(flags & ICU_ESCAPE)) return ret;
378 for (i = 0; i < len; i++) if (need_escape( comp[i] )) ret += 2;
379 return ret;
380}
#define lstrlenW
Definition: compat.h:750
GLbitfield flags
Definition: glext.h:7161
#define ICU_ESCAPE
Definition: winhttp.h:53

Referenced by get_url_length(), and WinHttpCreateUrl().

◆ get_scheme()

static INTERNET_SCHEME get_scheme ( const WCHAR scheme,
DWORD  len 
)
static

Definition at line 350 of file url.c.

351{
352 if (!wcsncmp( scheme, L"http", len )) return INTERNET_SCHEME_HTTP;
353 if (!wcsncmp( scheme, L"https", len )) return INTERNET_SCHEME_HTTPS;
354 return 0;
355}
_ACRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:518
DWORD scheme
#define INTERNET_SCHEME_HTTP
Definition: winhttp.h:47
#define INTERNET_SCHEME_HTTPS
Definition: winhttp.h:48

Referenced by get_url_length(), and WinHttpCreateUrl().

◆ get_scheme_string()

static const WCHAR * get_scheme_string ( INTERNET_SCHEME  scheme)
static

Definition at line 357 of file url.c.

358{
359 if (scheme == INTERNET_SCHEME_HTTP) return L"http";
360 if (scheme == INTERNET_SCHEME_HTTPS) return L"https";
361 return NULL;
362}

Referenced by get_url_length(), and WinHttpCreateUrl().

◆ get_url_length()

static BOOL get_url_length ( URL_COMPONENTS uc,
DWORD  flags,
DWORD len 
)
static

Definition at line 382 of file url.c.

383{
385
386 *len = 0;
387 if (uc->lpszScheme)
388 {
389 DWORD scheme_len = get_comp_length( uc->dwSchemeLength, 0, uc->lpszScheme );
390 *len += scheme_len;
391 scheme = get_scheme( uc->lpszScheme, scheme_len );
392 }
393 else
394 {
395 scheme = uc->nScheme;
398 }
399 *len += 3; /* "://" */
400
401 if (uc->lpszUserName)
402 {
404 *len += 1; /* "@" */
405 }
406 else
407 {
408 if (uc->lpszPassword)
409 {
411 return FALSE;
412 }
413 }
414 if (uc->lpszPassword)
415 {
416 *len += 1; /* ":" */
418 }
419 if (uc->lpszHostName)
420 {
422
423 if (!uses_default_port( scheme, uc->nPort ))
424 {
425 WCHAR port[sizeof("65535")];
426
427 *len += swprintf( port, ARRAY_SIZE(port), L"%u", uc->nPort );
428 *len += 1; /* ":" */
429 }
430 if (uc->lpszUrlPath && *uc->lpszUrlPath != '/') *len += 1; /* '/' */
431 }
434 return TRUE;
435}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define SetLastError(x)
Definition: compat.h:752
USHORT port
Definition: uri.c:228
static INTERNET_SCHEME get_scheme(const WCHAR *scheme, DWORD len)
Definition: url.c:350
static BOOL uses_default_port(INTERNET_SCHEME scheme, INTERNET_PORT port)
Definition: url.c:364
static const WCHAR * get_scheme_string(INTERNET_SCHEME scheme)
Definition: url.c:357
static DWORD get_comp_length(DWORD len, DWORD flags, WCHAR *comp)
Definition: url.c:371
#define swprintf
Definition: precomp.h:40
INTERNET_PORT nPort
Definition: winhttp.h:543
LPWSTR lpszScheme
Definition: winhttp.h:538
LPWSTR lpszUserName
Definition: winhttp.h:544
LPWSTR lpszExtraInfo
Definition: winhttp.h:550
DWORD dwPasswordLength
Definition: winhttp.h:547
LPWSTR lpszUrlPath
Definition: winhttp.h:548
DWORD dwHostNameLength
Definition: winhttp.h:542
DWORD dwExtraInfoLength
Definition: winhttp.h:551
DWORD dwUrlPathLength
Definition: winhttp.h:549
LPWSTR lpszHostName
Definition: winhttp.h:541
LPWSTR lpszPassword
Definition: winhttp.h:546
INTERNET_SCHEME nScheme
Definition: winhttp.h:540
DWORD dwUserNameLength
Definition: winhttp.h:545
DWORD dwSchemeLength
Definition: winhttp.h:539
INTERNET_SCHEME
Definition: wininet.h:135

Referenced by WinHttpCreateUrl().

◆ need_escape()

static BOOL need_escape ( WCHAR  ch)
inlinestatic

Definition at line 91 of file url.c.

92{
93 const WCHAR *p = L" \"#%<>[\\]^`{|}~";
94
95 if (ch <= 31 || ch >= 127) return TRUE;
96 while (*p)
97 {
98 if (ch == *p++) return TRUE;
99 }
100 return FALSE;
101}
unsigned char ch[4][2]
Definition: console.c:118

Referenced by escape_string(), and get_comp_length().

◆ parse_port()

static DWORD parse_port ( const WCHAR str,
DWORD  len,
INTERNET_PORT ret 
)
static

Definition at line 157 of file url.c.

158{
159 const WCHAR *p = str;
160 DWORD port = 0;
161 while (len && '0' <= *p && *p <= '9')
162 {
163 if ((port = port * 10 + *p - '0') > 65535) return ERROR_WINHTTP_INVALID_URL;
164 p++; len--;
165 }
166 *ret = port;
167 return ERROR_SUCCESS;
168}
const WCHAR * str
#define ERROR_WINHTTP_INVALID_URL
Definition: winhttp.h:237

Referenced by WinHttpCrackUrl().

◆ set_component()

static DWORD set_component ( struct url_component comp,
WCHAR value,
DWORD  len,
DWORD  flags,
BOOL overflow 
)
static

Definition at line 38 of file url.c.

39{
40 if (*comp->str && !*comp->len) return ERROR_INVALID_PARAMETER;
41 if (!*comp->len) return ERROR_SUCCESS;
42 if (!*comp->str)
43 {
44 if (len && *comp->len && (flags & (ICU_DECODE|ICU_ESCAPE))) return ERROR_INVALID_PARAMETER;
45 *comp->str = value;
46 *comp->len = len;
47 }
48 else
49 {
50 if (len >= *comp->len)
51 {
52 *comp->len = len + 1;
53 *overflow = TRUE;
54 return ERROR_SUCCESS;
55 }
56 memcpy( *comp->str, value, len * sizeof(WCHAR) );
57 (*comp->str)[len] = 0;
58 *comp->len = len;
59 }
60 return ERROR_SUCCESS;
61}
WCHAR ** str
Definition: url.c:34
DWORD * len
Definition: url.c:35
Definition: pdh_main.c:96
#define ICU_DECODE
Definition: winhttp.h:353

Referenced by WinHttpCrackUrl().

◆ uses_default_port()

static BOOL uses_default_port ( INTERNET_SCHEME  scheme,
INTERNET_PORT  port 
)
static

Definition at line 364 of file url.c.

365{
368 return FALSE;
369}
#define INTERNET_DEFAULT_HTTP_PORT
Definition: winhttp.h:41
#define INTERNET_DEFAULT_HTTPS_PORT
Definition: winhttp.h:42

Referenced by get_url_length(), and WinHttpCreateUrl().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winhttp  )

◆ WinHttpCrackUrl()

BOOL WINAPI WinHttpCrackUrl ( const WCHAR url,
DWORD  len,
DWORD  flags,
URL_COMPONENTSW uc 
)

Definition at line 173 of file url.c.

174{
175 WCHAR *p, *q, *r, *url_transformed = NULL;
179 DWORD err;
180
181 TRACE( "%s, %lu, %#lx, %p\n", debugstr_wn(url, len), len, flags, uc );
182
183 if (!url || !uc || uc->dwStructSize != sizeof(*uc))
184 {
186 return FALSE;
187 }
188 if (!len) len = lstrlenW( url );
189
190 if (flags & ICU_ESCAPE)
191 {
192 if ((err = escape_url( url, &len, &url_transformed )))
193 {
194 SetLastError( err );
195 return FALSE;
196 }
197 url = url_transformed;
198 }
199 else if (flags & ICU_DECODE)
200 {
201 if (!(url_transformed = decode_url( url, &len )))
202 {
204 return FALSE;
205 }
206 url = url_transformed;
207 }
208 if (!(p = wcschr( url, ':' )))
209 {
211 free( url_transformed );
212 return FALSE;
213 }
214 if (p - url == 4 && !wcsnicmp( url, L"http", 4 )) scheme_number = INTERNET_SCHEME_HTTP;
215 else if (p - url == 5 && !wcsnicmp( url, L"https", 5 )) scheme_number = INTERNET_SCHEME_HTTPS;
216 else
217 {
219 goto exit;
220 }
221
222 scheme.str = &uc->lpszScheme;
223 scheme.len = &uc->dwSchemeLength;
224
225 if ((err = set_component( &scheme, (WCHAR *)url, p - url, flags, &overflow ))) goto exit;
226
227 p++; /* skip ':' */
228 if (!p[0] || p[0] != '/' || p[1] != '/')
229 {
231 goto exit;
232 }
233 p += 2;
234 if (!p[0])
235 {
237 goto exit;
238 }
239
240 username.str = &uc->lpszUserName;
241 username.len = &uc->dwUserNameLength;
242
243 password.str = &uc->lpszPassword;
244 password.len = &uc->dwPasswordLength;
245
246 if ((q = wmemchr( p, '@', len - (p - url) )) && !(wmemchr( p, '/', q - p )))
247 {
248
249 if ((r = wmemchr( p, ':', q - p )))
250 {
251 if ((err = set_component( &username, p, r - p, flags, &overflow ))) goto exit;
252 r++;
253 if ((err = set_component( &password, r, q - r, flags, &overflow ))) goto exit;
254 }
255 else
256 {
257 if ((err = set_component( &username, p, q - p, flags, &overflow ))) goto exit;
258 if ((err = set_component( &password, NULL, 0, flags, &overflow ))) goto exit;
259 }
260 p = q + 1;
261 }
262 else
263 {
264 if ((err = set_component( &username, NULL, 0, flags, &overflow ))) goto exit;
265 if ((err = set_component( &password, NULL, 0, flags, &overflow ))) goto exit;
266 }
267
268 hostname.str = &uc->lpszHostName;
269 hostname.len = &uc->dwHostNameLength;
270
271 path.str = &uc->lpszUrlPath;
272 path.len = &uc->dwUrlPathLength;
273
274 extra.str = &uc->lpszExtraInfo;
275 extra.len = &uc->dwExtraInfoLength;
276
277 if ((q = wmemchr( p, '/', len - (p - url) )))
278 {
279 if ((r = wmemchr( p, ':', q - p )))
280 {
281 if ((err = set_component( &hostname, p, r - p, flags, &overflow ))) goto exit;
282 r++;
283 if (!(q - r))
284 {
287 }
288 else if ((err = parse_port( r, q - r, &uc->nPort ))) goto exit;
289 }
290 else
291 {
292 if ((err = set_component( &hostname, p, q - p, flags, &overflow ))) goto exit;
295 }
296
297 if ((r = wmemchr( q, '?', len - (q - url) )))
298 {
299 if (*extra.len)
300 {
301 if ((err = set_component( &path, q, r - q, flags, &overflow ))) goto exit;
302 if ((err = set_component( &extra, r, len - (r - url), flags, &overflow ))) goto exit;
303 }
304 else if ((err = set_component( &path, q, len - (q - url), flags, &overflow ))) goto exit;
305 }
306 else
307 {
308 if ((err = set_component( &path, q, len - (q - url), flags, &overflow ))) goto exit;
309 if ((err = set_component( &extra, (WCHAR *)url + len, 0, flags, &overflow ))) goto exit;
310 }
311 }
312 else
313 {
314 if ((r = wmemchr( p, ':', len - (p - url) )))
315 {
316 if ((err = set_component( &hostname, p, r - p, flags, &overflow ))) goto exit;
317 r++;
318 if (!*r)
319 {
322 }
323 else if ((err = parse_port( r, len - (r - url), &uc->nPort ))) goto exit;
324 }
325 else
326 {
327 if ((err = set_component( &hostname, p, len - (p - url), flags, &overflow ))) goto exit;
330 }
331 if ((err = set_component( &path, (WCHAR *)url + len, 0, flags, &overflow ))) goto exit;
332 if ((err = set_component( &extra, (WCHAR *)url + len, 0, flags, &overflow ))) goto exit;
333 }
334
335 TRACE("scheme(%s) host(%s) port(%d) path(%s) extra(%s)\n", debugstr_wn(*scheme.str, *scheme.len),
336 debugstr_wn(*hostname.str, *hostname.len ), uc->nPort, debugstr_wn(*path.str, *path.len),
337 debugstr_wn(*extra.str, *extra.len));
338
339exit:
340 if (!err)
341 {
342 if (overflow) err = ERROR_INSUFFICIENT_BUFFER;
344 }
345 free( url_transformed );
346 SetLastError( err );
347 return !err;
348}
char * hostname
Definition: ftp.c:88
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define free
Definition: debug_ros.c:5
#define wcschr
Definition: compat.h:17
#define wcsnicmp
Definition: compat.h:14
static wchar_t * wmemchr(const wchar_t *s, wchar_t c, size_t n)
Definition: wchar.h:48
URL_SCHEME scheme_number
Definition: url.c:64
static DWORD parse_port(const WCHAR *str, DWORD len, INTERNET_PORT *ret)
Definition: url.c:157
static WCHAR * decode_url(LPCWSTR url, DWORD *len)
Definition: url.c:63
static DWORD set_component(struct url_component *comp, WCHAR *value, DWORD len, DWORD flags, BOOL *overflow)
Definition: url.c:38
static DWORD escape_url(const WCHAR *url, DWORD *len, WCHAR **ret)
Definition: url.c:131
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
@ extra
Definition: id3.c:95
#define debugstr_wn
Definition: kernel32.h:33
static WCHAR password[]
Definition: url.c:33
static WCHAR username[]
Definition: url.c:32
#define err(...)
#define exit(n)
Definition: config.h:202
#define TRACE(s)
Definition: solgame.cpp:4
DWORD dwStructSize
Definition: wininet.h:211
DWORD dwUrlPathLength
Definition: wininet.h:223
DWORD dwExtraInfoLength
Definition: wininet.h:225
LPWSTR lpszPassword
Definition: wininet.h:220
LPWSTR lpszHostName
Definition: wininet.h:215
DWORD dwUserNameLength
Definition: wininet.h:219
DWORD dwHostNameLength
Definition: wininet.h:216
INTERNET_SCHEME nScheme
Definition: wininet.h:214
LPWSTR lpszScheme
Definition: wininet.h:212
LPWSTR lpszUserName
Definition: wininet.h:218
LPWSTR lpszUrlPath
Definition: wininet.h:222
LPWSTR lpszExtraInfo
Definition: wininet.h:224
DWORD dwPasswordLength
Definition: wininet.h:221
INTERNET_PORT nPort
Definition: wininet.h:217
DWORD dwSchemeLength
Definition: wininet.h:213
#define ERROR_WINHTTP_UNRECOGNIZED_SCHEME
Definition: winhttp.h:238

Referenced by download_script(), handle_redirect(), processFile(), run_script(), winhttp_request_Open(), and WinHttpCrackUrl_test().

◆ WinHttpCreateUrl()

BOOL WINAPI WinHttpCreateUrl ( URL_COMPONENTS uc,
DWORD  flags,
WCHAR url,
DWORD required 
)

Definition at line 440 of file url.c.

441{
442 DWORD len, len_escaped;
444
445 TRACE( "%p, %#lx, %p, %p\n", uc, flags, url, required );
446
447 if (!uc || uc->dwStructSize != sizeof(URL_COMPONENTS) || !required)
448 {
450 return FALSE;
451 }
452
453 if (!get_url_length( uc, flags, &len )) return FALSE;
454
455 if (*required < len)
456 {
457 *required = len + 1;
459 return FALSE;
460 }
461 if (!url)
462 {
464 return FALSE;
465 }
466
467 url[0] = 0;
468 *required = len;
469 if (uc->lpszScheme)
470 {
472 memcpy( url, uc->lpszScheme, len * sizeof(WCHAR) );
473 url += len;
474
476 }
477 else
478 {
479 const WCHAR *schemeW;
480 scheme = uc->nScheme;
481
483
484 schemeW = get_scheme_string( scheme );
485 len = lstrlenW( schemeW );
486 memcpy( url, schemeW, len * sizeof(WCHAR) );
487 url += len;
488 }
489
490 *url++ = ':';
491 *url++ = '/';
492 *url++ = '/';
493
494 if (uc->lpszUserName)
495 {
497 memcpy( url, uc->lpszUserName, len * sizeof(WCHAR) );
498 url += len;
499
500 if (uc->lpszPassword)
501 {
502 *url++ = ':';
504 memcpy( url, uc->lpszPassword, len * sizeof(WCHAR) );
505 url += len;
506 }
507 *url++ = '@';
508 }
509 if (uc->lpszHostName)
510 {
512 memcpy( url, uc->lpszHostName, len * sizeof(WCHAR) );
513 url += len;
514
515 if (!uses_default_port( scheme, uc->nPort ))
516 {
517 *url++ = ':';
518 url += swprintf( url, sizeof("65535"), L"%u", uc->nPort );
519 }
520
521 /* add slash between hostname and path if necessary */
522 if (uc->lpszUrlPath && *uc->lpszUrlPath != '/')
523 {
524 *url++ = '/';
525 }
526 }
527 if (uc->lpszUrlPath)
528 {
530 if (flags & ICU_ESCAPE)
531 {
532 if (!escape_string( uc->lpszUrlPath, len, url, &len_escaped ))
533 {
535 return FALSE;
536 }
537 url += len_escaped;
538 }
539 else
540 {
541 memcpy( url, uc->lpszUrlPath, len * sizeof(WCHAR) );
542 url += len;
543 }
544 }
545 if (uc->lpszExtraInfo)
546 {
548 if (flags & ICU_ESCAPE)
549 {
550 if (!escape_string( uc->lpszExtraInfo, len, url, &len_escaped ))
551 {
553 return FALSE;
554 }
555 url += len_escaped;
556 }
557 else
558 {
559 memcpy( url, uc->lpszExtraInfo, len * sizeof(WCHAR) );
560 url += len;
561 }
562 }
563 *url = 0;
565 return TRUE;
566}
static BOOL get_url_length(URL_COMPONENTS *uc, DWORD flags, DWORD *len)
Definition: url.c:382
DWORD dwStructSize
Definition: winhttp.h:537

Referenced by build_url(), and WinHttpCreateUrl_test().