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

Last change on this file since 6496 was 5618, checked in by sandervl, 24 years ago

resync with latest wine

File size: 22.0 KB
Line 
1/* $Id: url_odin.cpp,v 1.1 2001-04-28 13:32:38 sandervl 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 * @status partially
165 */
166ODINFUNCTION4(HRESULT, UrlApplySchemeW,
167 LPCWSTR, pszIn,
168 LPWSTR, pszOut,
169 LPDWORD, pcchOut,
170 DWORD, dwFlags)
171{
172 dprintf(("not implemented."));
173
174 wcsncpy((wchar_t*)pszOut,
175 (wchar_t*)pszIn,
176 *pcchOut);
177 *pcchOut = 0;
178
179 return S_OK;
180}
181
182
183
184
185
186/*****************************************************************************
187 * Name : UrlCombine
188 * Purpose : Takes a relative URL and its base and returns a URL in canonical form.
189 * Parameters: pszBase [in] Pointer to a string with the base URL.
190 * pszRelative [in] Pointer to a string with the relative URL.
191 * pszCombined [out] Pointer to a buffer to receive a
192 * NULL-terminated string containing the combined URL.
193 * pcchCombined [in/out] Pointer to a value set to the number of
194 * characters in the pszCombined buffer. When the
195 * function returns, the value depends on whether
196 * the function is successful or returns E_POINTER.
197 * For other return values, the value of this
198 * parameter is meaningless.
199 * dwFlags [in] Flags that specify how the URL will be converted
200 * to canonical form. The following flags can be combined.
201 * URL_DONT_SIMPLIFY
202 * Treat '/./' and '/../' in a URL string as literal
203 * characters, not as shorthand for
204 * navigation. See Remarks for further discussion.
205 * URL_ESCAPE_PERCENT
206 * Convert any occurrence of '%' to its escape sequence.
207 * URL_ESCAPE_SPACES_ONLY
208 * Replace only spaces with escape sequences. This flag
209 * takes precedence over
210 * URL_ESCAPE_UNSAFE, but does not apply to opaque URLs.
211 * URL_ESCAPE_UNSAFE
212 * Replace unsafe values with their escape sequences.
213 * This flag applies to all URLs,
214 * including opaque URLs.
215 * URL_PLUGGABLE_PROTOCOL
216 * Combine URLs with client-defined pluggable protocols,
217 * according to the W3C specification. This flag does not
218 * apply to standard protocols such as ftp, http,
219 * gopher, and so on. If this flag is set,
220 * UrlCombine will not simplify URLs, so there is
221 * no need to also set URL_DONT_SIMPLIFY.
222 * URL_UNESCAPE
223 * Unescape any escape sequences that the URLs contain,
224 * with two exceptions. The escape sequences
225 * for '?' and '#' will not be unescaped.
226 * If one of the URL_ESCAPE_XXX flags is also
227 * set, the two URLs will unescaped, then
228 * combined, then escaped.
229 * Variables :
230 * Result : S_OK pszCombined points to a string containing the
231 * combined URLs. The value of pcchCombined is set to
232 * the number of characters in the string, not counting
233 * the terminating NULL character.
234 * E_POINTER The buffer was too small. The value of pcchCombined
235 * is set to the minimum number of characters that the
236 * buffer must be able to contain, including the
237 * terminating NULL character.
238 * Other errors A standard OLE error value is returned.
239 * Remark : SHLWAPI.
240 * Status : STUB UNTESTED
241 *
242 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
243 *****************************************************************************/
244
245ODINFUNCTION5(HRESULT,UrlCombineA,
246 LPCSTR, pszBase,
247 LPCSTR, pszRelative,
248 LPSTR, pszCombined,
249 LPDWORD,pcchCombined,
250 DWORD, dwFlags)
251{
252 dprintf(("not implemented."));
253
254 return S_OK;
255}
256
257
258/**
259 * @status stub
260 */
261ODINFUNCTION5(HRESULT, UrlCombineW,
262 LPCWSTR, pszBase,
263 LPCWSTR, pszRelative,
264 LPWSTR, pszCombined,
265 LPDWORD, pcchCombined,
266 DWORD, dwFlags)
267{
268 dprintf(("not implemented."));
269
270 return S_OK;
271}
272
273
274/*****************************************************************************
275 * Name : UrlCompare
276 * Purpose : Does a case-sensitive comparison of two URL strings.
277 * Parameters: pszURL1 [in] NULL-terminated string with the first URL.
278 * pszURL2 [in] NULL-terminated string with the second URL.
279 * fIgnoreSlash [in] Value that is set to TRUE to have UrlCompare
280 * ignore a trailing '/' character on either or
281 * both URLs.
282 * Variables :
283 * Result : Returns zero if the two strings are equal, apart from a
284 * trailing '\' character if fIgnoreSlash is set to TRUE.
285 * Returns a negative integer if the string pointed to by pszURL1
286 * is less than the string pointed to by pszURL2. Otherwise, it
287 * returns a positive integer.
288 * Remark : SHLWAPI.
289 * For the best results, you should first canonicalize the URLs
290 * with UrlCanonicalize. Then, compare the canonicalized URLs with
291 * UrlCompare.
292 * Status : PARTIALLY IMPLEMENTED UNTESTED
293 *
294 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
295 *****************************************************************************/
296
297ODINFUNCTION3(int, UrlCompareA,
298 LPCSTR, pszURL1,
299 LPCSTR, pszURL2,
300 BOOL, fIgnoreSlash)
301{
302 dprintf(("not correctly implemented."));
303
304 return strcmp(pszURL1,
305 pszURL2);
306}
307
308/**
309 * @status stub
310 */
311ODINFUNCTION3(int, UrlCompareW,
312 LPCWSTR, pszURL1,
313 LPCWSTR, pszURL2,
314 BOOL, fIgnoreSlash)
315{
316 dprintf(("not correctly implemented."));
317
318 return wcscmp((const wchar_t *)pszURL1,
319 (const wchar_t *)pszURL2);
320}
321
322
323/*****************************************************************************
324 * Name : UrlCreateFromPath
325 * Purpose : Takes a DOS path and converts it to a canonicalized URL.
326 * Parameters: pszPath Pointer to the string with the DOS path.
327 * pszUrl Value used to return the URL.
328 * pcchPath Length of pszUrl.
329 * dwReserved Reserved. Set this parameter to NULL.
330 * Variables :
331 * Result : Returns S_FALSE if pszPath is already in URL format. In this
332 * case, pszPath will simply be copied to pszUrl. Otherwise, it
333 * returns S_OK if successful or a standard OLE error value if not.
334 * Remark : SHLWAPI.
335 * Status : STUB UNTESTED
336 *
337 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
338 *****************************************************************************/
339
340ODINFUNCTION4(HRESULT,UrlCreateFromPathA,
341 LPCSTR, pszPath,
342 LPSTR, pszUrl,
343 LPDWORD,pcchUrl,
344 DWORD, dwReserved)
345{
346 dprintf(("not implemented."));
347
348 return S_FALSE;
349}
350
351
352/**
353 * @status stub
354 */
355ODINFUNCTION4(HRESULT,UrlCreateFromPathW,
356 LPCWSTR,pszPath,
357 LPWSTR, pszUrl,
358 LPDWORD,pcchUrl,
359 DWORD, dwReserved)
360{
361 dprintf(("not implemented."));
362
363 return S_FALSE;
364}
365
366
367
368
369/*****************************************************************************
370 * Name : UrlGetLocation
371 * Purpose : Retrieves the location from a URL.
372 * Parameters: pszURL [in] Pointer to a NULL-terminated string that contains
373 * the location.
374 * Variables :
375 * Result : Returns a pointer to a NULL-terminated string with the
376 * location, or NULL otherwise.
377 * Remark : SHLWAPI.
378 * The location is the segment of the URL starting with a ? or #
379 * character. If a file URL has a query string, the returned
380 * string includes the query string.
381 * Status : STUB UNTESTED
382 *
383 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
384 *****************************************************************************/
385
386ODINFUNCTION1(LPCSTR, UrlGetLocationA,
387 LPCSTR, pszURL)
388{
389 dprintf(("not implemented."));
390
391 return pszURL;
392}
393
394
395/**
396 * @status stub
397 */
398ODINFUNCTION1(LPCWSTR, UrlGetLocationW,
399 LPCWSTR, pszURL)
400{
401 dprintf(("not implemented."));
402
403 return pszURL;
404}
405
406
407/*****************************************************************************
408 * Name : UrlGetPart
409 * Purpose : Takes a URL string and returns a specified part.
410 * Parameters: pszIn [in] NULL-terminated string that contains the URL.
411 * pszOut [out] A buffer that will receive a NULL-terminated
412 * string with the specified part.
413 * pcchOut [in/out] Address of a value set to the number of
414 * characters in the pszOut buffer. When the
415 * function returns, the value depends on whether
416 * the function is successful or returns E_POINTER.
417 * For other return values, the value of this
418 * parameter is meaningless.
419 * dwPart [in] Flags that specify which part of the URL to retrieve.
420 * It can have one of the following values.
421 * Flag Description
422 * URL_PART_HOSTNAME The host name.
423 * URL_PART_PASSWORD The password.
424 * URL_PART_PORT The port number.
425 * URL_PART_QUERY The query portion of the URL.
426 * URL_PART_SCHEME The URL scheme.
427 * URL_PART_USERNAME The username.
428 *
429 * dwFlags [in] Flag that can be set to keep the URL scheme,
430 * in addition to the part that is specified by dwPart.
431 * Flag Description
432 * URL_PARTFLAG_KEEPSCHEME Keep the URL scheme.
433 * Variables :
434 * Result :
435 * Remark : SHLWAPI.
436 * Returns an OLE success code if successful. The value pointed to
437 * by pcchOut will be set to the number of characters written to
438 * the output buffer, excluding the terminating NULL. If the buffer
439 * was too small, E_POINTER is returned, and the value pointed to
440 * by pcchOut will be set to the minimum number of characters that
441 * the buffer must be able to contain, including the terminating
442 * NULL character. Otherwise, an OLE error value is returned.
443 * Status : STUB UNTESTED
444 *
445 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
446 *****************************************************************************/
447
448ODINFUNCTION5(HRESULT, UrlGetPartA,
449 LPCSTR, pszIn,
450 LPSTR, pszOut,
451 LPDWORD, pcchOut,
452 DWORD, dwPart,
453 DWORD, dwFlags)
454{
455 dprintf(("not implemented."));
456
457 return S_OK;
458}
459
460
461/**
462 * @status stub
463 */
464ODINFUNCTION5(HRESULT, UrlGetPartW,
465 LPCWSTR, pszIn,
466 LPWSTR, pszOut,
467 LPDWORD, pcchOut,
468 DWORD, dwPart,
469 DWORD, dwFlags)
470{
471 dprintf(("not implemented."));
472
473 return S_OK;
474}
475
476
477
478
479/**
480 * @status stub
481 */
482ODINFUNCTION3(HRESULT,UrlHashW,
483 LPCWSTR,pszURL,
484 LPBYTE, pbHash,
485 DWORD, cbHash)
486{
487 dprintf(("not implemented."));
488
489 return S_OK;
490}
491
492
493/*****************************************************************************
494 * Name : UrlIs
495 * Purpose : Tests whether or not a URL is a specified type.
496 * Parameters: pszUrl [in] Pointer to a string containing the URL.
497 * UrlIs [in] Type of URL to be tested for.
498 * UrlIs can take one of the following values:
499 * URLIS_APPLIABLE Attempt to determine a valid scheme for the URL.
500 * URLIS_DIRECTORY Does the URL string end with a directory?
501 * URLIS_FILEURL Is the URL a file URL?
502 * URLIS_HASQUERY Does the URL have an appended query string?
503 * URLIS_NOHISTORY Is the URL a "No History" URL?
504 * URLIS_OPAQUE Is the URL opaque?
505 * URLIS_URL Is the URL valid?
506 * Variables :
507 * Result : For all but one of the URL types, UrlIs returns TRUE if the URL
508 * is the specified type, or FALSE if not. If UrlIs is set to
509 * URLIS_APPLIABLE, UrlIs will attempt to determine the URL scheme.
510 * If the function is able to determine a scheme, it returns TRUE,
511 * or FALSE otherwise.
512 * Remark : SHLWAPI.
513 * Status : STUB UNTESTED
514 *
515 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
516 *****************************************************************************/
517
518ODINFUNCTION2(BOOL, UrlIsA,
519 LPCSTR, pszUrl,
520 URLIS, UrlIs)
521{
522 dprintf(("not implemented."));
523
524 return TRUE;
525}
526
527
528/**
529 * @status stub
530 */
531ODINFUNCTION2(BOOL, UrlIsW,
532 LPCWSTR, pszUrl,
533 URLIS, UrlIs)
534{
535 dprintf(("not implemented."));
536
537 return TRUE;
538}
539
540/*****************************************************************************
541 * Name : UrlIsNoHistory
542 * Purpose : Returns whether or not a URL is a No History URL.
543 * Parameters: pszURL [in] NULL-terminated string with the URL.
544 * Variables :
545 * Result : Returns a non-zero value if the URL is a No History URL, or zero otherwise.
546 * Remark : SHLWAPI.
547 * A No History URL is a URL that browsers typically do not
548 * include in their navigation history.
549 * Status : STUB UNTESTED
550 *
551 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
552 *****************************************************************************/
553
554ODINFUNCTION1(BOOL, UrlIsNoHistoryA,
555 LPCSTR,pszURL)
556{
557 return UrlIsA(pszURL, URLIS_NOHISTORY);
558}
559
560
561/**
562 * @status stub
563 */
564ODINFUNCTION1(BOOL, UrlIsNoHistoryW,
565 LPCWSTR,pszURL)
566{
567 return UrlIsW(pszURL, URLIS_NOHISTORY);
568}
569
570
571/*****************************************************************************
572 * Name : UrlIsOpaque
573 * Purpose : Returns whether a URL is opaque.
574 * Parameters: pszURL [in] NULL-terminated string with the URL.
575 * Variables :
576 * Result : Returns a non-zero value if the URL is opaque, or zero
577 * otherwise.
578 * Remark : SHLWAPI.
579 * A URL that has a scheme that is not followed by two slashes (//)
580 * is opaque. For example, mailto:xyz@somecompany.com is an opaque
581 * URL. Opaque URLs cannot be separated into the standard
582 * URL heirarchy.
583 * Status : STUB UNTESTED
584 *
585 * Author : Patrick Haller [Tue, 2000/04/25 02:02]
586 *****************************************************************************/
587
588ODINFUNCTION1(BOOL, UrlIsOpaqueA,
589 LPCSTR, pszURL)
590{
591 return UrlIsA(pszURL, URLIS_OPAQUE);
592}
593
594
595/**
596 * @status stub
597 */
598ODINFUNCTION1(BOOL, UrlIsOpaqueW,
599 LPCWSTR,pszURL)
600{
601 return UrlIsW(pszURL, URLIS_OPAQUE);
602}
603
604
Note: See TracBrowser for help on using the repository browser.