source: trunk/src/shlwapi/url_odin.cpp@ 6608

Last change on this file since 6608 was 6608, checked in by phaller, 24 years ago

SHLWAPI update

File size: 21.7 KB
Line 
1/* $Id: url_odin.cpp,v 1.2 2001-08-30 19:19:59 phaller Exp $ */
2
3/*
4 * Win32 Lightweight SHELL32 API for OS/2
5 *
6 * 2000/04/20 Patrick Haller (haller@zebra.fh-weingarten.de)
7 *
8 * @(#) url.cpp 1.0.0 2000/04/20 PH Start from scratch
9 */
10
11
12/*****************************************************************************
13 * Remark *
14 *****************************************************************************
15
16 */
17
18
19/*****************************************************************************
20 * Includes *
21 *****************************************************************************/
22
23#include <odin.h>
24#include <odinwrap.h>
25#include <os2sel.h>
26
27#include <string.h>
28#include <ctype.h>
29#include <wctype.h>
30#include <wcstr.h>
31#define HAVE_WCTYPE_H
32
33#include <winreg.h>
34
35#include <heapstring.h>
36#include <misc.h>
37#include <win\shell.h>
38#include <win\winerror.h>
39
40#include "shlwapi_odin.h"
41
42ODINDEBUGCHANNEL(SHLWAPI-URL)
43
44
45/*****************************************************************************
46 * Defines *
47 *****************************************************************************/
48
49
50typedef struct tagURLSCHEME
51{
52 LPSTR pszName; /* such as http:// */
53 BOOL flagOpaque; /* has a double-slash '// */
54 BOOL flagNoHistory; /* usually not in history of browsers */
55 DWORD dwType; /* URL type */
56
57} URLSCHEME, *PURLSCHEME;
58
59
60typedef enum tagURLIS
61{
62 URLIS_APPLIABLE, /* Attempt to determine a valid scheme for the URL. */
63 URLIS_DIRECTORY, /* Does the URL string end with a directory? */
64 URLIS_FILEURL, /* Is the URL a file URL? */
65 URLIS_HASQUERY, /* Does the URL have an appended query string? */
66 URLIS_NOHISTORY, /* Is the URL a "No History" URL? */
67 URLIS_OPAQUE, /* Is the URL opaque? */
68 URLIS_URL /* Is the URL valid? */
69} URLIS;
70
71
72static URLSCHEME arrUrlSchemes[] =
73{ /* scheme opaque hist type */
74 {"http://", FALSE, FALSE, 0},
75 {"https://", FALSE, FALSE, 0},
76 {"shttp://", FALSE, FALSE, 0},
77 {"file://", FALSE, FALSE, 0},
78 {"ftp://", FALSE, FALSE, 0},
79 {"telnet://", FALSE, TRUE, 0},
80 {"news://", FALSE, TRUE, 0},
81 {"snews://", FALSE, TRUE, 0},
82 {"mailto:", TRUE, TRUE, 0},
83 {"gopher://", FALSE, FALSE, 0},
84 {"wais://", FALSE, FALSE, 0},
85};
86
87
88
89
90/*****************************************************************************
91 * Name : UrlApplyScheme
92 * Purpose : Takes a URL string, determines a scheme for it, and returns a
93 * string with an appropriate prefix.
94 * Parameters: pszIn [in] A NULL-terminated URL string.
95 * pszOut [out] A buffer to receive a NULL-terminated string,
96 * set to the URL specified by pszIn, converted
97 * to the standard scheme://URL_string format.
98 * pcchOut [in/out] Address of a value set to the number of
99 * characters in the pszOut buffer. When the
100 * function returns, the value depends on whether
101 * the function is successful or returns
102 * E_POINTER. For other return values, the value
103 * of this parameter is meaningless.
104 * dwFlags [in] Flags that specify how to determine the
105 * scheme. The following flags can be combined.
106 * URL_APPLY_DEFAULT
107 * Apply the default scheme if UrlApplyScheme
108 * can't determine one. The default prefix is
109 * stored in the registry but is typically "http".
110 * URL_APPLY_GUESSSCHEME
111 * Attempt to determine the scheme by examining
112 * pszIn.
113 * URL_APPLY_GUESSFILE
114 * Attempt to determine a file URL from pszIn.
115 * URL_APPLY_FORCEAPPLY
116 * Force UrlApplyScheme to determine a scheme
117 * for pszIn.
118 * Variables :
119 * Result : S_OK A scheme was determined. pszOut points to a string
120 * containing the URL with the scheme's prefix. The value
121 * of pcchOut is set to the number of characters in the
122 * string, not counting the terminating NULL character.
123 * S_FALSE There were no errors, but no prefix was prepended.
124 * E_POINTER The buffer was too small. The value of pcchOut is
125 * set to the minimum number of characters that the
126 * buffer must be able to contain, including the
127 * terminating NULL character.
128 * Other errors - A standard OLE error value is returned.
129 * Remark : If the URL has a valid scheme, the string will not be modified.
130 * However, almost any combination of two or more characters
131 * followed by a colon will be parsed as a scheme. Valid
132 * characters include some common punctuation marks, such as ".".
133 * If your input string fits this description, UrlApplyScheme may
134 * treat it as valid and not apply a scheme. To force the function
135 * to apply a scheme to a URL, set the URL_APPLY_FORCEAPPLY and
136 * URL_APPLY_DEFAULT flags in dwFlags. This combination of flags
137 * forces the function to apply a scheme to the URL. Typically,
138 * the function will not be able to determine a valid scheme. The
139 * second flag guarantees that, if no valid scheme can be
140 * determined, the function will apply the default scheme to the URL.
141 * Status : PARTIALLY IMPLEMENTED UNTESTED
142 *
143 * Author : Patrick Haller [Thu, 2000/04/20 19:46]
144 *****************************************************************************/
145
146ODINFUNCTION4(HRESULT, UrlApplySchemeA,
147 LPCSTR, pszIn,
148 LPSTR, pszOut,
149 LPDWORD, pcchOut,
150 DWORD, dwFlags)
151{
152 dprintf(("not implemented."));
153
154 strncpy(pszOut,
155 pszIn,
156 *pcchOut);
157 *pcchOut = 0;
158
159 return S_OK;
160}
161
162
163/*****************************************************************************
164 * Name : UrlCombine
165 * Purpose : Takes a relative URL and its base and returns a URL in canonical form.
166 * Parameters: pszBase [in] Pointer to a string with the base URL.
167 * pszRelative [in] Pointer to a string with the relative URL.
168 * pszCombined [out] Pointer to a buffer to receive a
169 * NULL-terminated string containing the combined URL.
170 * pcchCombined [in/out] Pointer to a value set to the number of
171 * characters in the pszCombined buffer. When the
172 * function returns, the value depends on whether
173 * the function is successful or returns E_POINTER.
174 * For other return values, the value of this
175 * parameter is meaningless.
176 * dwFlags [in] Flags that specify how the URL will be converted
177 * to canonical form. The following flags can be combined.
178 * URL_DONT_SIMPLIFY
179 * Treat '/./' and '/../' in a URL string as literal
180 * characters, not as shorthand for
181 * navigation. See Remarks for further discussion.
182 * URL_ESCAPE_PERCENT
183 * Convert any occurrence of '%' to its escape sequence.
184 * URL_ESCAPE_SPACES_ONLY
185 * Replace only spaces with escape sequences. This flag
186 * takes precedence over
187 * URL_ESCAPE_UNSAFE, but does not apply to opaque URLs.
188 * URL_ESCAPE_UNSAFE
189 * Replace unsafe values with their escape sequences.
190 * This flag applies to all URLs,
191 * including opaque URLs.
192 * URL_PLUGGABLE_PROTOCOL
193 * Combine URLs with client-defined pluggable protocols,
194 * according to the W3C specification. This flag does not
195 * apply to standard protocols such as ftp, http,
196 * gopher, and so on. If this flag is set,
197 * UrlCombine will not simplify URLs, so there is
198 * no need to also set URL_DONT_SIMPLIFY.
199 * URL_UNESCAPE
200 * Unescape any escape sequences that the URLs contain,
201 * with two exceptions. The escape sequences
202 * for '?' and '#' will not be unescaped.
203 * If one of the URL_ESCAPE_XXX flags is also
204 * set, the two URLs will unescaped, then
205 * combined, then escaped.
206 * Variables :
207 * Result : S_OK pszCombined points to a string containing the
208 * combined URLs. The value of pcchCombined is set to
209 * the number of characters in the string, not counting
210 * the terminating NULL character.
211 * E_POINTER The buffer was too small. The value of pcchCombined
212 * is set to the minimum number of characters that the
213 * buffer must be able to contain, including the
214 * terminating NULL character.
215 * Other errors A standard OLE error value is returned.
216 * Remark : SHLWAPI.
217 * Status : STUB UNTESTED
218 *
219 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
220 *****************************************************************************/
221
222ODINFUNCTION5(HRESULT,UrlCombineA,
223 LPCSTR, pszBase,
224 LPCSTR, pszRelative,
225 LPSTR, pszCombined,
226 LPDWORD,pcchCombined,
227 DWORD, dwFlags)
228{
229 dprintf(("not implemented."));
230
231 return S_OK;
232}
233
234
235/**
236 * @status stub
237 */
238ODINFUNCTION5(HRESULT, UrlCombineW,
239 LPCWSTR, pszBase,
240 LPCWSTR, pszRelative,
241 LPWSTR, pszCombined,
242 LPDWORD, pcchCombined,
243 DWORD, dwFlags)
244{
245 dprintf(("not implemented."));
246
247 return S_OK;
248}
249
250
251/*****************************************************************************
252 * Name : UrlCompare
253 * Purpose : Does a case-sensitive comparison of two URL strings.
254 * Parameters: pszURL1 [in] NULL-terminated string with the first URL.
255 * pszURL2 [in] NULL-terminated string with the second URL.
256 * fIgnoreSlash [in] Value that is set to TRUE to have UrlCompare
257 * ignore a trailing '/' character on either or
258 * both URLs.
259 * Variables :
260 * Result : Returns zero if the two strings are equal, apart from a
261 * trailing '\' character if fIgnoreSlash is set to TRUE.
262 * Returns a negative integer if the string pointed to by pszURL1
263 * is less than the string pointed to by pszURL2. Otherwise, it
264 * returns a positive integer.
265 * Remark : SHLWAPI.
266 * For the best results, you should first canonicalize the URLs
267 * with UrlCanonicalize. Then, compare the canonicalized URLs with
268 * UrlCompare.
269 * Status : PARTIALLY IMPLEMENTED UNTESTED
270 *
271 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
272 *****************************************************************************/
273
274ODINFUNCTION3(int, UrlCompareA,
275 LPCSTR, pszURL1,
276 LPCSTR, pszURL2,
277 BOOL, fIgnoreSlash)
278{
279 dprintf(("not correctly implemented."));
280
281 return strcmp(pszURL1,
282 pszURL2);
283}
284
285/**
286 * @status stub
287 */
288ODINFUNCTION3(int, UrlCompareW,
289 LPCWSTR, pszURL1,
290 LPCWSTR, pszURL2,
291 BOOL, fIgnoreSlash)
292{
293 dprintf(("not correctly implemented."));
294
295 return wcscmp((const wchar_t *)pszURL1,
296 (const wchar_t *)pszURL2);
297}
298
299
300/*****************************************************************************
301 * Name : UrlCreateFromPath
302 * Purpose : Takes a DOS path and converts it to a canonicalized URL.
303 * Parameters: pszPath Pointer to the string with the DOS path.
304 * pszUrl Value used to return the URL.
305 * pcchPath Length of pszUrl.
306 * dwReserved Reserved. Set this parameter to NULL.
307 * Variables :
308 * Result : Returns S_FALSE if pszPath is already in URL format. In this
309 * case, pszPath will simply be copied to pszUrl. Otherwise, it
310 * returns S_OK if successful or a standard OLE error value if not.
311 * Remark : SHLWAPI.
312 * Status : STUB UNTESTED
313 *
314 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
315 *****************************************************************************/
316
317ODINFUNCTION4(HRESULT,UrlCreateFromPathA,
318 LPCSTR, pszPath,
319 LPSTR, pszUrl,
320 LPDWORD,pcchUrl,
321 DWORD, dwReserved)
322{
323 dprintf(("not implemented."));
324
325 return S_FALSE;
326}
327
328
329/**
330 * @status stub
331 */
332ODINFUNCTION4(HRESULT,UrlCreateFromPathW,
333 LPCWSTR,pszPath,
334 LPWSTR, pszUrl,
335 LPDWORD,pcchUrl,
336 DWORD, dwReserved)
337{
338 dprintf(("not implemented."));
339
340 return S_FALSE;
341}
342
343
344
345
346/*****************************************************************************
347 * Name : UrlGetLocation
348 * Purpose : Retrieves the location from a URL.
349 * Parameters: pszURL [in] Pointer to a NULL-terminated string that contains
350 * the location.
351 * Variables :
352 * Result : Returns a pointer to a NULL-terminated string with the
353 * location, or NULL otherwise.
354 * Remark : SHLWAPI.
355 * The location is the segment of the URL starting with a ? or #
356 * character. If a file URL has a query string, the returned
357 * string includes the query string.
358 * Status : STUB UNTESTED
359 *
360 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
361 *****************************************************************************/
362
363ODINFUNCTION1(LPCSTR, UrlGetLocationA,
364 LPCSTR, pszURL)
365{
366 dprintf(("not implemented."));
367
368 return pszURL;
369}
370
371
372/**
373 * @status stub
374 */
375ODINFUNCTION1(LPCWSTR, UrlGetLocationW,
376 LPCWSTR, pszURL)
377{
378 dprintf(("not implemented."));
379
380 return pszURL;
381}
382
383
384/*****************************************************************************
385 * Name : UrlGetPart
386 * Purpose : Takes a URL string and returns a specified part.
387 * Parameters: pszIn [in] NULL-terminated string that contains the URL.
388 * pszOut [out] A buffer that will receive a NULL-terminated
389 * string with the specified part.
390 * pcchOut [in/out] Address of a value set to the number of
391 * characters in the pszOut buffer. When the
392 * function returns, the value depends on whether
393 * the function is successful or returns E_POINTER.
394 * For other return values, the value of this
395 * parameter is meaningless.
396 * dwPart [in] Flags that specify which part of the URL to retrieve.
397 * It can have one of the following values.
398 * Flag Description
399 * URL_PART_HOSTNAME The host name.
400 * URL_PART_PASSWORD The password.
401 * URL_PART_PORT The port number.
402 * URL_PART_QUERY The query portion of the URL.
403 * URL_PART_SCHEME The URL scheme.
404 * URL_PART_USERNAME The username.
405 *
406 * dwFlags [in] Flag that can be set to keep the URL scheme,
407 * in addition to the part that is specified by dwPart.
408 * Flag Description
409 * URL_PARTFLAG_KEEPSCHEME Keep the URL scheme.
410 * Variables :
411 * Result :
412 * Remark : SHLWAPI.
413 * Returns an OLE success code if successful. The value pointed to
414 * by pcchOut will be set to the number of characters written to
415 * the output buffer, excluding the terminating NULL. If the buffer
416 * was too small, E_POINTER is returned, and the value pointed to
417 * by pcchOut will be set to the minimum number of characters that
418 * the buffer must be able to contain, including the terminating
419 * NULL character. Otherwise, an OLE error value is returned.
420 * Status : STUB UNTESTED
421 *
422 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
423 *****************************************************************************/
424
425ODINFUNCTION5(HRESULT, UrlGetPartA,
426 LPCSTR, pszIn,
427 LPSTR, pszOut,
428 LPDWORD, pcchOut,
429 DWORD, dwPart,
430 DWORD, dwFlags)
431{
432 dprintf(("not implemented."));
433
434 return S_OK;
435}
436
437
438/**
439 * @status stub
440 */
441ODINFUNCTION5(HRESULT, UrlGetPartW,
442 LPCWSTR, pszIn,
443 LPWSTR, pszOut,
444 LPDWORD, pcchOut,
445 DWORD, dwPart,
446 DWORD, dwFlags)
447{
448 dprintf(("not implemented."));
449
450 return S_OK;
451}
452
453
454
455
456/**
457 * @status stub
458 */
459ODINFUNCTION3(HRESULT,UrlHashW,
460 LPCWSTR,pszURL,
461 LPBYTE, pbHash,
462 DWORD, cbHash)
463{
464 dprintf(("not implemented."));
465
466 return S_OK;
467}
468
469
470/*****************************************************************************
471 * Name : UrlIs
472 * Purpose : Tests whether or not a URL is a specified type.
473 * Parameters: pszUrl [in] Pointer to a string containing the URL.
474 * UrlIs [in] Type of URL to be tested for.
475 * UrlIs can take one of the following values:
476 * URLIS_APPLIABLE Attempt to determine a valid scheme for the URL.
477 * URLIS_DIRECTORY Does the URL string end with a directory?
478 * URLIS_FILEURL Is the URL a file URL?
479 * URLIS_HASQUERY Does the URL have an appended query string?
480 * URLIS_NOHISTORY Is the URL a "No History" URL?
481 * URLIS_OPAQUE Is the URL opaque?
482 * URLIS_URL Is the URL valid?
483 * Variables :
484 * Result : For all but one of the URL types, UrlIs returns TRUE if the URL
485 * is the specified type, or FALSE if not. If UrlIs is set to
486 * URLIS_APPLIABLE, UrlIs will attempt to determine the URL scheme.
487 * If the function is able to determine a scheme, it returns TRUE,
488 * or FALSE otherwise.
489 * Remark : SHLWAPI.
490 * Status : STUB UNTESTED
491 *
492 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
493 *****************************************************************************/
494
495ODINFUNCTION2(BOOL, UrlIsA,
496 LPCSTR, pszUrl,
497 URLIS, UrlIs)
498{
499 dprintf(("not implemented."));
500
501 return TRUE;
502}
503
504
505/**
506 * @status stub
507 */
508ODINFUNCTION2(BOOL, UrlIsW,
509 LPCWSTR, pszUrl,
510 URLIS, UrlIs)
511{
512 dprintf(("not implemented."));
513
514 return TRUE;
515}
516
517/*****************************************************************************
518 * Name : UrlIsNoHistory
519 * Purpose : Returns whether or not a URL is a No History URL.
520 * Parameters: pszURL [in] NULL-terminated string with the URL.
521 * Variables :
522 * Result : Returns a non-zero value if the URL is a No History URL, or zero otherwise.
523 * Remark : SHLWAPI.
524 * A No History URL is a URL that browsers typically do not
525 * include in their navigation history.
526 * Status : STUB UNTESTED
527 *
528 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
529 *****************************************************************************/
530
531ODINFUNCTION1(BOOL, UrlIsNoHistoryA,
532 LPCSTR,pszURL)
533{
534 return UrlIsA(pszURL, URLIS_NOHISTORY);
535}
536
537
538/**
539 * @status stub
540 */
541ODINFUNCTION1(BOOL, UrlIsNoHistoryW,
542 LPCWSTR,pszURL)
543{
544 return UrlIsW(pszURL, URLIS_NOHISTORY);
545}
546
547
548/*****************************************************************************
549 * Name : UrlIsOpaque
550 * Purpose : Returns whether a URL is opaque.
551 * Parameters: pszURL [in] NULL-terminated string with the URL.
552 * Variables :
553 * Result : Returns a non-zero value if the URL is opaque, or zero
554 * otherwise.
555 * Remark : SHLWAPI.
556 * A URL that has a scheme that is not followed by two slashes (//)
557 * is opaque. For example, mailto:xyz@somecompany.com is an opaque
558 * URL. Opaque URLs cannot be separated into the standard
559 * URL heirarchy.
560 * Status : STUB UNTESTED
561 *
562 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
563 *****************************************************************************/
564
565ODINFUNCTION1(BOOL, UrlIsOpaqueA,
566 LPCSTR, pszURL)
567{
568 return UrlIsA(pszURL, URLIS_OPAQUE);
569}
570
571
572/**
573 * @status stub
574 */
575ODINFUNCTION1(BOOL, UrlIsOpaqueW,
576 LPCWSTR,pszURL)
577{
578 return UrlIsW(pszURL, URLIS_OPAQUE);
579}
580
581
Note: See TracBrowser for help on using the repository browser.