update credits
[LibreOffice.git] / include / tools / urlobj.hxx
blob8905334e7e9f098a66386f43e29172356e3a47c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _URLOBJ_HXX
20 #define _URLOBJ_HXX
22 #include "tools/toolsdllapi.h"
23 #include "com/sun/star/uno/Reference.hxx"
24 #include "rtl/string.h"
25 #include "rtl/ustrbuf.hxx"
26 #include "rtl/textenc.h"
27 #include "sal/types.h"
29 namespace com { namespace sun { namespace star { namespace util {
30 class XStringWidth;
31 } } } }
33 // Special tokens:
34 #define INET_PATH_TOKEN '/'
35 #define INET_MARK_TOKEN '#'
36 #define INET_HEX_ESCAPE '%'
38 // Common URL prefixes for various schemes:
39 #define INET_FTP_SCHEME "ftp://"
40 #define INET_HTTP_SCHEME "http://"
41 #define INET_HTTPS_SCHEME "https://"
42 #define INET_FILE_SCHEME "file://"
43 #define INET_MAILTO_SCHEME "mailto:"
44 #define INET_NEWS_SCHEME "news:"
45 #define INET_HID_SCHEME "hid:"
47 #define URL_PREFIX_PRIV_SOFFICE "private:"
48 enum
50 URL_PREFIX_PRIV_SOFFICE_LEN
51 = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_SOFFICE)
54 #define URL_PREFIX_PRIV_OBSOLETE URL_PREFIX_PRIV_SOFFICE
55 enum
57 URL_PREFIX_PRIV_OBSOLETE_LEN
58 = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_OBSOLETE)
61 #define URL_PREFIX_PRIV_EXTERN "staroffice:"
62 enum
64 URL_PREFIX_PRIV_EXTERN_LEN = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_EXTERN)
67 // Schemes:
68 enum INetProtocol
70 INET_PROT_NOT_VALID = 0,
71 INET_PROT_FTP = 1,
72 INET_PROT_HTTP = 2,
73 INET_PROT_FILE = 3,
74 INET_PROT_MAILTO = 4,
75 INET_PROT_VND_SUN_STAR_WEBDAV = 5,
76 INET_PROT_NEWS = 6,
77 INET_PROT_PRIV_SOFFICE = 7,
78 INET_PROT_PRIVATE = INET_PROT_PRIV_SOFFICE, // obsolete
79 INET_PROT_VND_SUN_STAR_HELP = 8,
80 INET_PROT_HTTPS = 9,
81 INET_PROT_SLOT = 10,
82 INET_PROT_MACRO = 11,
83 INET_PROT_JAVASCRIPT = 12,
84 INET_PROT_IMAP = 13,
85 INET_PROT_POP3 = 14,
86 INET_PROT_DATA = 15,
87 INET_PROT_CID = 16,
88 INET_PROT_OUT = 17,
89 INET_PROT_VND_SUN_STAR_HIER = 18,
90 INET_PROT_VIM = 19,
91 INET_PROT_UNO = 20,
92 INET_PROT_COMPONENT = 21,
93 INET_PROT_VND_SUN_STAR_PKG = 22,
94 INET_PROT_LDAP = 23,
95 INET_PROT_DB = 24,
96 INET_PROT_VND_SUN_STAR_CMD = 25,
97 INET_PROT_TELNET = 27,
98 INET_PROT_VND_SUN_STAR_EXPAND = 28,
99 INET_PROT_VND_SUN_STAR_TDOC = 29,
100 INET_PROT_GENERIC = 30,
101 INET_PROT_SMB = 31,
102 INET_PROT_HID = 32,
103 INET_PROT_SFTP = 33,
104 INET_PROT_CMIS = 34,
105 INET_PROT_END = 35
108 class TOOLS_DLLPUBLIC INetURLObject
110 public:
111 // Get- and Set-Methods:
113 /** The way input strings that represent (parts of) URIs are interpreted
114 in set-methods.
116 @descr Most set-methods accept either a OString or a OUString
117 as input. Using a OString, octets in the range 0x80--0xFF are
118 replaced by single escape sequences. Using a OUString , UTF-32
119 characters in the range 0x80--0x10FFFF are replaced by sequences of
120 escape sequences, representing the UTF-8 coded characters.
122 @descr Along with an EncodeMechanism parameter, the set-methods all
123 take an rtl_TextEncoding parameter, which is ignored unless the
124 EncodeMechanism is WAS_ENCODED.
126 enum EncodeMechanism
128 /** All escape sequences that are already present are ignored, and are
129 interpreted as literal sequences of three characters.
131 ENCODE_ALL,
133 /** Sequences of escape sequences, that represent characters from the
134 specified character set and that can be converted to UTF-32
135 characters, are first decoded. If they have to be encoded, they
136 are converted to UTF-8 characters and are than translated into
137 (sequences of) escape sequences. Other escape sequences are
138 copied verbatim (but using upper case hex digits).
140 WAS_ENCODED,
142 /** All escape sequences that are already present are copied verbatim
143 (but using upper case hex digits).
145 NOT_CANONIC
148 /** The way strings that represent (parts of) URIs are returned from get-
149 methods.
151 @descr Along with a DecodeMechanism parameter, the get-methods all
152 take an rtl_TextEncoding parameter, which is ignored unless the
153 DecodeMechanism is DECODE_WITH_CHARSET or DECODE_UNAMBIGUOUS.
155 enum DecodeMechanism
157 /** The (part of the) URI is returned unchanged. Since URIs are
158 written using a subset of US-ASCII, the returned string is
159 guaranteed to contain only US-ASCII characters.
161 NO_DECODE,
163 /** All sequences of escape sequences that represent UTF-8 coded
164 UTF-32 characters with a numerical value greater than 0x7F, are
165 replaced by the respective UTF-16 characters. All other escape
166 sequences are not decoded.
168 DECODE_TO_IURI,
170 /** All (sequences of) escape sequences that represent characters from
171 the specified character set, and that can be converted to UTF-32,
172 are replaced by the respective UTF-16 characters. All other
173 escape sequences are not decoded.
175 DECODE_WITH_CHARSET,
177 /** All (sequences of) escape sequences that represent characters from
178 the specified character set, that can be converted to UTF-32, and
179 that (in the case of ASCII characters) can safely be decoded
180 without altering the meaning of the (part of the) URI, are
181 replaced by the respective UTF-16 characters. All other escape
182 sequences are not decoded.
184 DECODE_UNAMBIGUOUS
187 // General Structure:
189 inline INetURLObject():
190 m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP) {}
192 inline bool HasError() const { return m_eScheme == INET_PROT_NOT_VALID; }
194 inline OUString GetMainURL(DecodeMechanism eMechanism,
195 rtl_TextEncoding eCharset
196 = RTL_TEXTENCODING_UTF8) const
197 { return decode(m_aAbsURIRef, getEscapePrefix(), eMechanism, eCharset); }
199 OUString GetURLNoPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
200 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
201 const;
203 OUString GetURLNoMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
204 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
205 const;
207 OUString
208 getAbbreviated(com::sun::star::uno::Reference<
209 com::sun::star::util::XStringWidth > const &
210 rStringWidth,
211 sal_Int32 nWidth,
212 DecodeMechanism eMechanism = DECODE_TO_IURI,
213 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
214 const;
216 bool operator ==(INetURLObject const & rObject) const;
218 inline bool operator !=(INetURLObject const & rObject) const
219 { return !(*this == rObject); }
221 bool operator <(INetURLObject const & rObject) const;
223 inline bool operator >(INetURLObject const & rObject) const
224 { return rObject < *this; }
226 // Strict Parsing:
228 inline INetURLObject(const OString& rTheAbsURIRef,
229 EncodeMechanism eMechanism = WAS_ENCODED,
230 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
232 inline INetURLObject(OUString const & rTheAbsURIRef,
233 EncodeMechanism eMechanism = WAS_ENCODED,
234 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
236 inline bool SetURL(const OString& rTheAbsURIRef,
237 EncodeMechanism eMechanism = WAS_ENCODED,
238 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
240 inline bool SetURL(OUString const & rTheAbsURIRef,
241 EncodeMechanism eMechanism = WAS_ENCODED,
242 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
244 bool ConcatData(INetProtocol eTheScheme, OUString const & rTheUser,
245 OUString const & rThePassword,
246 OUString const & rTheHost, sal_uInt32 nThePort,
247 OUString const & rThePath,
248 EncodeMechanism eMechanism = WAS_ENCODED,
249 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
251 // Smart Parsing:
253 /** The supported notations for file system paths.
255 enum FSysStyle
257 /** VOS notation (e.g., "//server/dir/file").
259 FSYS_VOS = 0x1,
261 /** Unix notation (e.g., "/dir/file").
263 FSYS_UNX = 0x2,
265 /** DOS notation (e.g., "a:\dir\file" and "\\server\dir\file").
267 FSYS_DOS = 0x4,
269 /** Mac notation (e.g., "dir:file").
271 FSYS_MAC = 0x8,
273 /** Detect the used notation.
275 @descr For the following descriptions, please note that
276 whereas FSYS_DEFAULT includes all style bits, combinations of only
277 a few style bits are also possible, and are also described.
279 @descr When used to translate a file system path to a file URL,
280 the subset of the following productions for which the appropriate
281 style bit is set are checked in order (using the conventions of
282 RFC 2234, RFC 2396, and RFC 2732; UCS4 stands for any UCS4
283 character):
285 Production T1 (VOS local; FSYS_VOS only):
286 "//." ["/" *UCS4]
287 becomes
288 "file:///" *UCS4
290 Production T2 (VOS host; FSYS_VOS only):
291 "//" [host] ["/" *UCS4]
292 becomes
293 "file://" host "/" *UCS4
295 Production T3 (UNC; FSYS_DOS only):
296 "\\" [host] ["\" *UCS4]
297 becomes
298 "file://" host "/" *UCS4
299 replacing "\" by "/" within <*UCS4>
301 Production T4 (Unix-like DOS; FSYS_DOS only):
302 ALPHA ":" ["/" *UCS4]
303 becomes
304 "file:///" ALPHA ":/" *UCS4
305 replacing "\" by "/" within <*UCS4>
307 Production T5 (DOS; FSYS_DOS only):
308 ALPHA ":" ["\" *UCS4]
309 becomes
310 "file:///" ALPHA ":/" *UCS4
311 replacing "\" by "/" within <*UCS4>
313 Production T6 (any):
314 *UCS4
315 becomes
316 "file:///" *UCS4
317 replacing the delimiter by "/" within <*UCS4>. The delimiter is
318 that character from the set { "/", "\", ":" } which appears most
319 often in <*UCS4> (if FSYS_UNX is not among the style bits, "/"
320 is removed from the set; if FSYS_DOS is not among the style
321 bits, "\" is removed from the set; if FSYS_MAC is not among the
322 style bits, ":" is removed from the set). If two or more
323 characters appear the same number of times, the character
324 mentioned first in that set is chosen. If the first character
325 of <*UCS4> is the delimiter, that character is not copied.
327 @descr When used to translate a file URL to a file system path,
328 the following productions are checked in order (using the
329 conventions of RFC 2234, RFC 2396, and RFC 2732):
331 Production F1 (VOS; FSYS_VOS):
332 "file://" host "/" fpath ["#" fragment]
333 becomes
334 "//" host "/" fpath
336 Production F2 (DOS; FSYS_DOS):
337 "file:///" ALPHA ":" ["/" fpath] ["#" fragment]
338 becomes
339 ALPHA ":" ["\" fpath]
340 replacing "/" by "\" in <fpath>
342 Production F3 (Unix; FSYS_UNX):
343 "file:///" fpath ["#" fragment]
344 becomes
345 "/" fpath
347 FSYS_DETECT = FSYS_VOS | FSYS_UNX | FSYS_DOS
350 inline INetURLObject(OUString const & rTheAbsURIRef,
351 INetProtocol eTheSmartScheme,
352 EncodeMechanism eMechanism = WAS_ENCODED,
353 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
354 FSysStyle eStyle = FSYS_DETECT);
356 inline void SetSmartProtocol(INetProtocol eTheSmartScheme)
357 { m_eSmartScheme = eTheSmartScheme; }
359 inline bool
360 SetSmartURL(const OString& rTheAbsURIRef,
361 EncodeMechanism eMechanism = WAS_ENCODED,
362 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
363 FSysStyle eStyle = FSYS_DETECT);
365 inline bool
366 SetSmartURL(OUString const & rTheAbsURIRef,
367 EncodeMechanism eMechanism = WAS_ENCODED,
368 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
369 FSysStyle eStyle = FSYS_DETECT);
371 inline INetURLObject
372 smartRel2Abs(const OString& rTheRelURIRef,
373 bool & rWasAbsolute,
374 bool bIgnoreFragment = false,
375 EncodeMechanism eMechanism = WAS_ENCODED,
376 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
377 bool bRelativeNonURIs = false,
378 FSysStyle eStyle = FSYS_DETECT) const;
380 inline INetURLObject
381 smartRel2Abs(OUString const & rTheRelURIRef,
382 bool & rWasAbsolute,
383 bool bIgnoreFragment = false,
384 EncodeMechanism eMechanism = WAS_ENCODED,
385 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
386 bool bRelativeNonURIs = false,
387 FSysStyle eStyle = FSYS_DETECT) const;
389 // Relative URLs:
391 inline bool
392 GetNewAbsURL(const OString& rTheRelURIRef,
393 INetURLObject * pTheAbsURIRef,
394 EncodeMechanism eMechanism = WAS_ENCODED,
395 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
396 FSysStyle eStyle = FSYS_DETECT, bool bIgnoreFragment = false)
397 const;
399 inline bool
400 GetNewAbsURL(OUString const & rTheRelURIRef,
401 INetURLObject * pTheAbsURIRef,
402 EncodeMechanism eMechanism = WAS_ENCODED,
403 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
404 FSysStyle eStyle = FSYS_DETECT, bool bIgnoreFragment = false)
405 const;
407 /** @descr If rTheRelURIRef cannot be converted to an absolute URL
408 (because of syntactic reasons), either rTheRelURIRef or an empty
409 string is returned: If all of the parameters eEncodeMechanism,
410 eDecodeMechanism and eCharset have their respective default values,
411 then rTheRelURIRef is returned unmodified; otherwise, an empty string
412 is returned.
414 static OUString
415 GetAbsURL(OUString const & rTheBaseURIRef,
416 OUString const & rTheRelURIRef,
417 bool bIgnoreFragment = false,
418 EncodeMechanism eEncodeMechanism = WAS_ENCODED,
419 DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
420 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
421 FSysStyle eStyle = FSYS_DETECT);
423 static inline OUString
424 GetRelURL(const OString& rTheBaseURIRef,
425 const OString& rTheAbsURIRef,
426 EncodeMechanism eEncodeMechanism = WAS_ENCODED,
427 DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
428 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
429 FSysStyle eStyle = FSYS_DETECT);
431 static inline OUString
432 GetRelURL(OUString const & rTheBaseURIRef,
433 OUString const & rTheAbsURIRef,
434 EncodeMechanism eEncodeMechanism = WAS_ENCODED,
435 DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
436 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
437 FSysStyle eStyle = FSYS_DETECT);
439 // External URLs:
441 OUString getExternalURL(DecodeMechanism eMechanism = DECODE_TO_IURI,
442 rtl_TextEncoding eCharset
443 = RTL_TEXTENCODING_UTF8) const;
445 static inline bool translateToExternal(const OString& rTheIntURIRef,
446 OUString & rTheExtURIRef,
447 DecodeMechanism eDecodeMechanism
448 = DECODE_TO_IURI,
449 rtl_TextEncoding eCharset
450 = RTL_TEXTENCODING_UTF8);
452 static inline bool translateToExternal(OUString const & rTheIntURIRef,
453 OUString & rTheExtURIRef,
454 DecodeMechanism eDecodeMechanism
455 = DECODE_TO_IURI,
456 rtl_TextEncoding eCharset
457 = RTL_TEXTENCODING_UTF8);
459 static inline bool translateToInternal(const OString& rTheExtURIRef,
460 OUString & rTheIntURIRef,
461 DecodeMechanism eDecodeMechanism
462 = DECODE_TO_IURI,
463 rtl_TextEncoding eCharset
464 = RTL_TEXTENCODING_UTF8);
466 static inline bool translateToInternal(OUString const & rTheExtURIRef,
467 OUString & rTheIntURIRef,
468 DecodeMechanism eDecodeMechanism
469 = DECODE_TO_IURI,
470 rtl_TextEncoding eCharset
471 = RTL_TEXTENCODING_UTF8);
473 // Scheme:
475 struct SchemeInfo;
477 inline INetProtocol GetProtocol() const { return m_eScheme; }
479 /** Return the URL 'prefix' for a given scheme.
481 @param eTheScheme One of the supported URL schemes.
483 @return The 'prefix' of URLs of the given scheme.
485 static OUString GetScheme(INetProtocol eTheScheme);
487 /** Return the a human-readable name for a given scheme.
489 @param eTheScheme One of the supported URL schemes.
491 @return The protocol name of URLs of the given scheme.
493 static OUString GetSchemeName(INetProtocol eTheScheme);
495 static inline INetProtocol CompareProtocolScheme(const OString&
496 rTheAbsURIRef)
497 { return CompareProtocolScheme(extend(rTheAbsURIRef)); }
499 static INetProtocol CompareProtocolScheme(OUString const &
500 rTheAbsURIRef);
502 // User Info:
504 inline bool HasUserData() const { return m_aUser.isPresent(); }
506 inline bool IsEmptyUser() const
507 { return m_aUser.isPresent() && m_aUser.isEmpty(); }
509 inline OUString GetUser(DecodeMechanism eMechanism = DECODE_TO_IURI,
510 rtl_TextEncoding eCharset
511 = RTL_TEXTENCODING_UTF8) const
512 { return decode(m_aUser, getEscapePrefix(), eMechanism, eCharset); }
514 inline OUString GetPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
515 rtl_TextEncoding eCharset
516 = RTL_TEXTENCODING_UTF8) const
517 { return decode(m_aAuth, getEscapePrefix(), eMechanism, eCharset); }
519 inline bool SetUser(const OString& rTheUser,
520 EncodeMechanism eMechanism = WAS_ENCODED,
521 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
522 { return setUser(extend(rTheUser), true, eMechanism, eCharset); }
524 inline bool SetUser(OUString const & rTheUser,
525 EncodeMechanism eMechanism = WAS_ENCODED,
526 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
527 { return setUser(rTheUser, false, eMechanism, eCharset); }
529 inline bool SetPass(const OString& rThePassword,
530 EncodeMechanism eMechanism = WAS_ENCODED,
531 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
533 inline bool SetPass(OUString const & rThePassword,
534 EncodeMechanism eMechanism = WAS_ENCODED,
535 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
537 inline bool SetUserAndPass(const OString& rTheUser,
538 const OString& rThePassword,
539 EncodeMechanism eMechanism = WAS_ENCODED,
540 rtl_TextEncoding eCharset
541 = RTL_TEXTENCODING_UTF8);
543 inline bool SetUserAndPass(OUString const & rTheUser,
544 OUString const & rThePassword,
545 EncodeMechanism eMechanism = WAS_ENCODED,
546 rtl_TextEncoding eCharset
547 = RTL_TEXTENCODING_UTF8);
549 // Host and Port:
551 inline bool HasPort() const { return m_aPort.isPresent(); }
553 inline OUString GetHost(DecodeMechanism eMechanism = DECODE_TO_IURI,
554 rtl_TextEncoding eCharset
555 = RTL_TEXTENCODING_UTF8) const
556 { return decode(m_aHost, getEscapePrefix(), eMechanism, eCharset); }
558 OUString GetHostPort(DecodeMechanism eMechanism = DECODE_TO_IURI,
559 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
561 sal_uInt32 GetPort() const;
563 inline bool SetHost(const OString& rTheHost,
564 EncodeMechanism eMechanism = WAS_ENCODED,
565 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
566 { return setHost(extend(rTheHost), true, eMechanism, eCharset); }
568 inline bool SetHost(OUString const & rTheHost,
569 EncodeMechanism eMechanism = WAS_ENCODED,
570 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
571 { return setHost(rTheHost, false, eMechanism, eCharset); }
573 bool SetPort(sal_uInt32 nThePort);
575 // Path:
577 inline bool HasURLPath() const { return !m_aPath.isEmpty(); }
579 inline OUString GetURLPath(DecodeMechanism eMechanism = DECODE_TO_IURI,
580 rtl_TextEncoding eCharset
581 = RTL_TEXTENCODING_UTF8) const
582 { return decode(m_aPath, getEscapePrefix(), eMechanism, eCharset); }
584 inline bool SetURLPath(const OString& rThePath,
585 EncodeMechanism eMechanism = WAS_ENCODED,
586 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
587 { return setPath(extend(rThePath), true, eMechanism, eCharset); }
589 inline bool SetURLPath(OUString const & rThePath,
590 EncodeMechanism eMechanism = WAS_ENCODED,
591 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
592 { return setPath(rThePath, false, eMechanism, eCharset); }
594 // Hierarchical Path:
596 /** A constant to address the last segment in various methods dealing with
597 hierarchical paths.
599 @descr It is often more efficient to address the last segment using
600 this constant, than to determine its ordinal value using
601 getSegmentCount().
603 enum { LAST_SEGMENT = -1 };
605 /** The number of segments in the hierarchical path.
607 @descr Using RFC 2396 and RFC 2234, a hierarchical path is of the
608 form
610 hierarchical-path = 1*("/" segment)
612 segment = name *(";" param)
614 name = [base ["." extension]]
616 base = 1*pchar
618 extension = *<any pchar except ".">
620 param = *pchar
622 @param bIgnoreFinalSlash If true, a final slash at the end of the
623 hierarchical path does not denote an empty segment, but is ignored.
625 @return The number of segments in the hierarchical path. If the path
626 is not hierarchical, 0 is returned.
628 sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
630 /** Remove a segment from the hierarchical path.
632 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
633 if addressing the last segment.
635 @param bIgnoreFinalSlash If true, a final slash at the end of the
636 hierarchical path does not denote an empty segment, but is ignored.
638 @return True if the segment has successfully been removed (and the
639 resulting URI is still valid). If the path is not hierarchical, or
640 the specified segment does not exist, false is returned. If false is
641 returned, the object is not modified.
643 bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
644 bool bIgnoreFinalSlash = true);
646 /** Insert a new segment into the hierarchical path.
648 @param rTheName The name part of the new segment. The new segment
649 will contain no parameters.
651 @param bAppendFinalSlash If the new segment is appended at the end of
652 the hierarchical path, this parameter specifies whether to add a final
653 slash after it or not.
655 @param nIndex The non-negative index of the segment before which
656 to insert the new segment. LAST_SEGMENT or an nIndex that equals
657 getSegmentCount() inserts the new segment at the end of the
658 hierarchical path.
660 @param bIgnoreFinalSlash If true, a final slash at the end of the
661 hierarchical path does not denote an empty segment, but is ignored.
663 @param eMechanism See the general discussion for set-methods.
665 @param eCharset See the general discussion for set-methods.
667 @return True if the segment has successfully been inserted (and the
668 resulting URI is still valid). If the path is not hierarchical, or
669 the specified place to insert the new segment does not exist, false is
670 returned. If false is returned, the object is not modified.
672 inline bool insertName(OUString const & rTheName,
673 bool bAppendFinalSlash = false,
674 sal_Int32 nIndex = LAST_SEGMENT,
675 bool bIgnoreFinalSlash = true,
676 EncodeMechanism eMechanism = WAS_ENCODED,
677 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
679 /** Get the name of a segment of the hierarchical path.
681 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
682 if addressing the last segment.
684 @param bIgnoreFinalSlash If true, a final slash at the end of the
685 hierarchical path does not denote an empty segment, but is ignored.
687 @param eMechanism See the general discussion for get-methods.
689 @param eCharset See the general discussion for get-methods.
691 @return The name part of the specified segment. If the path is not
692 hierarchical, or the specified segment does not exits, an empty string
693 is returned.
695 OUString getName(sal_Int32 nIndex = LAST_SEGMENT,
696 bool bIgnoreFinalSlash = true,
697 DecodeMechanism eMechanism = DECODE_TO_IURI,
698 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
699 const;
701 /** Set the name of a segment (preserving any parameters and any query or
702 fragment part).
704 @param rTheName The new name.
706 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
707 if addressing the last segment.
709 @param bIgnoreFinalSlash If true, a final slash at the end of the
710 hierarchical path does not denote an empty segment, but is ignored.
712 @param eMechanism See the general discussion for set-methods.
714 @param eCharset See the general discussion for set-methods.
716 @return True if the name has successfully been modified (and the
717 resulting URI is still valid). If the path is not hierarchical, or
718 the specified segment does not exist, false is returned. If false is
719 returned, the object is not modified.
721 bool setName(OUString const & rTheName,
722 sal_Int32 nIndex = LAST_SEGMENT,
723 bool bIgnoreFinalSlash = true,
724 EncodeMechanism eMechanism = WAS_ENCODED,
725 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
727 /** Get the base of the name of a segment.
729 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
730 if addressing the last segment.
732 @param bIgnoreFinalSlash If true, a final slash at the end of the
733 hierarchical path does not denote an empty segment, but is ignored.
735 @param eMechanism See the general discussion for get-methods.
737 @param eCharset See the general discussion for get-methods.
739 @return The base part of the specified segment. If the path is
740 not hierarchical, or the specified segment does not exits, an empty
741 string is returned.
743 OUString getBase(sal_Int32 nIndex = LAST_SEGMENT,
744 bool bIgnoreFinalSlash = true,
745 DecodeMechanism eMechanism = DECODE_TO_IURI,
746 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
747 const;
749 /** Set the base of the name of a segment (preserving the extension).
751 @param rTheBase The new base.
753 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
754 if addressing the last segment.
756 @param bIgnoreFinalSlash If true, a final slash at the end of the
757 hierarchical path does not denote an empty segment, but is ignored.
759 @param eMechanism See the general discussion for set-methods.
761 @param eCharset See the general discussion for set-methods.
763 @return True if the base has successfully been modified (and the
764 resulting URI is still valid). If the path is not hierarchical, or
765 the specified segment does not exist, false is returned. If false is
766 returned, the object is not modified.
768 bool setBase(OUString const & rTheBase,
769 sal_Int32 nIndex = LAST_SEGMENT,
770 bool bIgnoreFinalSlash = true,
771 EncodeMechanism eMechanism = WAS_ENCODED,
772 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
774 /** Determine whether the name of a segment has an extension.
776 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
777 if addressing the last segment.
779 @param bIgnoreFinalSlash If true, a final slash at the end of the
780 hierarchical path does not denote an empty segment, but is ignored.
782 @return True if the name of the specified segment has an extension.
783 If the path is not hierarchical, or the specified segment does not
784 exist, false is returned.
786 bool hasExtension(sal_Int32 nIndex = LAST_SEGMENT,
787 bool bIgnoreFinalSlash = true) const;
789 /** Get the extension of the name of a segment.
791 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
792 if addressing the last segment.
794 @param bIgnoreFinalSlash If true, a final slash at the end of the
795 hierarchical path does not denote an empty segment, but is ignored.
797 @param eMechanism See the general discussion for get-methods.
799 @param eCharset See the general discussion for get-methods.
801 @return The extension part of the specified segment. If the path is
802 not hierarchical, or the specified segment does not exits, an empty
803 string is returned.
805 OUString getExtension(sal_Int32 nIndex = LAST_SEGMENT,
806 bool bIgnoreFinalSlash = true,
807 DecodeMechanism eMechanism = DECODE_TO_IURI,
808 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
809 const;
811 /** Set the extension of the name of a segment (replacing an already
812 existing extension).
814 @param rTheExtension The new extension.
816 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
817 if addressing the last segment.
819 @param bIgnoreFinalSlash If true, a final slash at the end of the
820 hierarchical path does not denote an empty segment, but is ignored.
822 @param eMechanism See the general discussion for set-methods.
824 @param eCharset See the general discussion for set-methods.
826 @return True if the extension has successfully been modified (and the
827 resulting URI is still valid). If the path is not hierarchical, or
828 the specified segment does not exist, false is returned. If false is
829 returned, the object is not modified.
831 bool setExtension(OUString const & rTheExtension,
832 sal_Int32 nIndex = LAST_SEGMENT,
833 bool bIgnoreFinalSlash = true,
834 EncodeMechanism eMechanism = WAS_ENCODED,
835 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
837 /** Remove the extension of the name of a segment.
839 @param nIndex The non-negative index of the segment, or LAST_SEGMENT
840 if addressing the last segment.
842 @param bIgnoreFinalSlash If true, a final slash at the end of the
843 hierarchical path does not denote an empty segment, but is ignored.
845 @return True if the extension has successfully been removed (and the
846 resulting URI is still valid), or if the name did not have an
847 extension. If the path is not hierarchical, or the specified segment
848 does not exist, false is returned. If false is returned, the object
849 is not modified.
851 bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
852 bool bIgnoreFinalSlash = true);
854 /** Determine whether the hierarchical path ends in a final slash.
856 @return True if the hierarchical path ends in a final slash. If the
857 path is not hierarchical, false is returned.
859 bool hasFinalSlash() const;
861 /** Make the hierarchical path end in a final slash (if it does not
862 already do so).
864 @return True if a final slash has successfully been appended (and the
865 resulting URI is still valid), or if the hierarchical path already
866 ended in a final slash. If the path is not hierarchical, false is
867 returned. If false is returned, the object is not modified.
869 bool setFinalSlash();
871 /** Remove a final slash from the hierarchical path.
873 @return True if a final slash has successfully been removed (and the
874 resulting URI is still valid), or if the hierarchical path already did
875 not end in a final slash. If the path is not hierarchical, false is
876 returned. If false is returned, the object is not modified.
878 bool removeFinalSlash();
880 // Query:
882 inline bool HasParam() const { return m_aQuery.isPresent(); }
884 inline OUString GetParam(DecodeMechanism eMechanism = DECODE_TO_IURI,
885 rtl_TextEncoding eCharset
886 = RTL_TEXTENCODING_UTF8) const
887 { return decode(m_aQuery, getEscapePrefix(), eMechanism, eCharset); }
889 inline bool SetParam(const OString& rTheQuery,
890 EncodeMechanism eMechanism = WAS_ENCODED,
891 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
893 inline bool SetParam(OUString const & rTheQuery,
894 EncodeMechanism eMechanism = WAS_ENCODED,
895 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
897 // Fragment:
899 inline bool HasMark() const { return m_aFragment.isPresent(); }
901 inline OUString GetMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
902 rtl_TextEncoding eCharset
903 = RTL_TEXTENCODING_UTF8) const
904 { return decode(m_aFragment, getEscapePrefix(), eMechanism, eCharset); }
906 inline bool SetMark(const OString& rTheFragment,
907 EncodeMechanism eMechanism = WAS_ENCODED,
908 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
910 inline bool SetMark(OUString const & rTheFragment,
911 EncodeMechanism eMechanism = WAS_ENCODED,
912 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
914 // File URLs:
916 /** Create an INetURLObject from a file system path.
918 @param rFSysPath A file system path. An URL is not allowed here!
920 @param eStyle The notation of rFSysPath.
922 inline INetURLObject(OUString const & rFSysPath, FSysStyle eStyle);
924 /** Set this INetURLObject to a file URL constructed from a file system
925 path.
927 @param rFSysPath A file system path. An URL is not allowed here!
929 @param eStyle The notation of rFSysPath.
931 @return True if this INetURLObject has successfully been changed. If
932 false is returned, this INetURLObject has not been modified.
934 bool setFSysPath(OUString const & rFSysPath, FSysStyle eStyle);
936 /** Return the file system path represented by a file URL (ignoring any
937 fragment part).
939 @param eStyle The notation of the returned file system path.
941 @param pDelimiter Upon successful return, this parameter can return
942 the character that is the 'main' delimiter within the returned file
943 system path (e.g., "/" for Unix, "\" for DOS, ":" for Mac). This is
944 especially useful for routines that later try to shorten the returned
945 file system path at a 'good' position, e.g. to fit it into some
946 limited display space.
948 @return The file system path represented by this file URL. If this
949 file URL does not represent a file system path according to the
950 specified notation, or if this is not a file URL at all, an empty
951 string is returned.
953 OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
954 const;
956 // POP3 and URLs:
958 OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
959 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
960 const;
962 // Coding:
964 enum Part
966 PART_OBSOLETE_NORMAL = 0x001, // Obsolete, do not use!
967 PART_OBSOLETE_FILE = 0x002, // Obsolete, do not use!
968 PART_OBSOLETE_PARAM = 0x004, // Obsolete, do not use!
969 PART_USER_PASSWORD = 0x008,
970 PART_IMAP_ACHAR = 0x010,
971 PART_VIM = 0x020,
972 PART_HOST_EXTRA = 0x040,
973 PART_FPATH = 0x080,
974 PART_AUTHORITY = 0x100,
975 PART_PATH_SEGMENTS_EXTRA = 0x200,
976 PART_REL_SEGMENT_EXTRA = 0x400,
977 PART_URIC = 0x800,
978 PART_HTTP_PATH = 0x1000,
979 PART_FILE_SEGMENT_EXTRA = 0x2000, // Obsolete, do not use!
980 PART_MESSAGE_ID = 0x4000,
981 PART_MESSAGE_ID_PATH = 0x8000,
982 PART_MAILTO = 0x10000,
983 PART_PATH_BEFORE_QUERY = 0x20000,
984 PART_PCHAR = 0x40000,
985 PART_FRAGMENT = 0x80000, // Obsolete, do not use!
986 PART_VISIBLE = 0x100000,
987 PART_VISIBLE_NONSPECIAL = 0x200000,
988 PART_CREATEFRAGMENT = 0x400000,
989 PART_UNO_PARAM_VALUE = 0x800000,
990 PART_UNAMBIGUOUS = 0x1000000,
991 PART_URIC_NO_SLASH = 0x2000000,
992 PART_HTTP_QUERY = 0x4000000, //TODO! unused?
993 PART_NEWS_ARTICLE_LOCALPART = 0x8000000,
994 max_part = 0x80000000
995 // Do not use! Only there to allow compatible changes in the
996 // future.
999 enum EscapeType
1001 ESCAPE_NO,
1002 ESCAPE_OCTET,
1003 ESCAPE_UTF32
1006 /** Encode some text as part of a URI.
1008 @param rText Some text (for its interpretation, see the general
1009 discussion for set-methods).
1011 @param ePart The part says which characters are 'forbidden' and must
1012 be encoded (replaced by escape sequences). Characters outside the US-
1013 ASCII range are always 'forbidden.'
1015 @param cEscapePrefix The first character in an escape sequence
1016 (normally '%').
1018 @param eMechanism See the general discussion for set-methods.
1020 @param eCharset See the general discussion for set-methods.
1022 @return The encoded representation of the text ('forbidden'
1023 characters replaced by escape sequences).
1025 static inline OUString encode(const OString& rText, Part ePart,
1026 sal_Char cEscapePrefix,
1027 EncodeMechanism eMechanism,
1028 rtl_TextEncoding eCharset
1029 = RTL_TEXTENCODING_UTF8);
1031 /** Encode some text as part of a URI.
1033 @param rText Some text (for its interpretation, see the general
1034 discussion for set-methods).
1036 @param ePart The part says which characters are 'forbidden' and must
1037 be encoded (replaced by escape sequences). Characters outside the US-
1038 ASCII range are always 'forbidden.'
1040 @param cEscapePrefix The first character in an escape sequence
1041 (normally '%').
1043 @param eMechanism See the general discussion for set-methods.
1045 @param eCharset See the general discussion for set-methods.
1047 @return The text, encoded according to the given mechanism and
1048 charset ('forbidden' characters replaced by escape sequences).
1050 static inline OUString encode(OUString const & rText, Part ePart,
1051 sal_Char cEscapePrefix,
1052 EncodeMechanism eMechanism,
1053 rtl_TextEncoding eCharset
1054 = RTL_TEXTENCODING_UTF8);
1056 /** Decode some text.
1058 @param rText Some (encoded) text.
1060 @param cEscapePrefix The first character in an escape sequence
1061 (normally '%').
1063 @param eMechanism See the general discussion for get-methods.
1065 @param eCharset See the general discussion for get-methods.
1067 @return The text, decoded according to the given mechanism and
1068 charset (escape sequences replaced by 'raw' characters).
1070 static inline OUString decode(OUString const & rText,
1071 sal_Char cEscapePrefix,
1072 DecodeMechanism eMechanism,
1073 rtl_TextEncoding eCharset
1074 = RTL_TEXTENCODING_UTF8);
1076 static inline OUString decode(OUStringBuffer const & rText,
1077 sal_Char cEscapePrefix,
1078 DecodeMechanism eMechanism,
1079 rtl_TextEncoding eCharset
1080 = RTL_TEXTENCODING_UTF8);
1082 static void appendUCS4Escape(OUStringBuffer & rTheText,
1083 sal_Char cEscapePrefix,
1084 sal_uInt32 nUCS4);
1086 static void appendUCS4(OUStringBuffer & rTheText, sal_uInt32 nUCS4,
1087 EscapeType eEscapeType, bool bOctets, Part ePart,
1088 sal_Char cEscapePrefix, rtl_TextEncoding eCharset,
1089 bool bKeepVisibleEscapes);
1091 static sal_uInt32 getUTF32(sal_Unicode const *& rBegin,
1092 sal_Unicode const * pEnd, bool bOctets,
1093 sal_Char cEscapePrefix,
1094 EncodeMechanism eMechanism,
1095 rtl_TextEncoding eCharset,
1096 EscapeType & rEscapeType);
1098 // Specialized helpers:
1100 static sal_uInt32 scanDomain(sal_Unicode const *& rBegin,
1101 sal_Unicode const * pEnd,
1102 bool bEager = true);
1104 // OBSOLETE Hierarchical Path:
1106 OUString GetPartBeforeLastName(DecodeMechanism eMechanism
1107 = DECODE_TO_IURI,
1108 rtl_TextEncoding eCharset
1109 = RTL_TEXTENCODING_UTF8) const;
1111 /** Get the last segment in the path.
1113 @param eMechanism See the general discussion for get-methods.
1115 @param eCharset See the general discussion for get-methods.
1117 @return For a hierarchical URL, the last segment (everything after
1118 the last unencoded '/'). Not that this last segment may be empty. If
1119 the URL is not hierarchical, an empty string is returned.
1121 OUString GetLastName(DecodeMechanism eMechanism = DECODE_TO_IURI,
1122 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1123 const;
1125 /** Get the 'extension' of the last segment in the path.
1127 @param eMechanism See the general discussion for get-methods.
1129 @param eCharset See the general discussion for get-methods.
1131 @return For a hierarchical URL, everything after the first unencoded
1132 '.' in the last segment of the path. Note that this 'extension' may
1133 be empty. If the URL is not hierarchical, or if the last segment does
1134 not contain an unencoded '.', an empty string is returned.
1136 OUString GetFileExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
1137 rtl_TextEncoding eCharset
1138 = RTL_TEXTENCODING_UTF8) const;
1140 inline bool Append(const OString& rTheSegment,
1141 EncodeMechanism eMechanism = WAS_ENCODED,
1142 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1143 { return appendSegment(extend(rTheSegment), true, eMechanism, eCharset); }
1145 inline bool Append(OUString const & rTheSegment,
1146 EncodeMechanism eMechanism = WAS_ENCODED,
1147 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1148 { return appendSegment(rTheSegment, false, eMechanism, eCharset); }
1150 bool CutLastName();
1152 // OBSOLETE File URLs:
1154 OUString PathToFileName() const;
1156 OUString GetFull() const;
1158 OUString GetPath() const;
1160 void SetBase(OUString const & rTheBase);
1162 OUString GetBase() const;
1164 void SetName(OUString const & rTheName,
1165 EncodeMechanism eMechanism = WAS_ENCODED,
1166 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1168 inline OUString GetName(DecodeMechanism eMechanism = DECODE_TO_IURI,
1169 rtl_TextEncoding eCharset
1170 = RTL_TEXTENCODING_UTF8) const
1171 { return GetLastName(eMechanism, eCharset); }
1173 void SetExtension(OUString const & rTheExtension,
1174 EncodeMechanism eMechanism = WAS_ENCODED,
1175 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1177 inline OUString GetExtension(
1178 DecodeMechanism eMechanism = DECODE_TO_IURI,
1179 rtl_TextEncoding eCharset
1180 = RTL_TEXTENCODING_UTF8) const
1181 { return GetFileExtension(eMechanism, eCharset); }
1183 OUString CutExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
1184 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1186 bool IsCaseSensitive() const;
1189 private:
1190 // General Structure:
1192 class SubString
1194 sal_Int32 m_nBegin;
1195 sal_Int32 m_nLength;
1197 public:
1198 explicit inline SubString(sal_Int32 nTheBegin = -1,
1199 sal_Int32 nTheLength = 0):
1200 m_nBegin(nTheBegin), m_nLength(nTheLength) {}
1202 inline bool isPresent() const { return m_nBegin != -1; }
1204 inline bool isEmpty() const { return m_nLength == 0; }
1206 inline sal_Int32 getBegin() const { return m_nBegin; }
1208 inline sal_Int32 getLength() const { return m_nLength; }
1210 inline sal_Int32 getEnd() const { return m_nBegin + m_nLength; }
1212 inline sal_Int32 clear();
1214 inline sal_Int32 set(OUStringBuffer & rString,
1215 OUString const & rSubString,
1216 sal_Int32 nTheBegin);
1218 inline sal_Int32 set(OUString & rString,
1219 OUString const & rSubString);
1221 inline sal_Int32 set(OUStringBuffer & rString,
1222 OUString const & rSubString);
1224 inline void operator +=(sal_Int32 nDelta);
1226 int compare(SubString const & rOther,
1227 OUStringBuffer const & rThisString,
1228 OUStringBuffer const & rOtherString) const;
1231 OUStringBuffer m_aAbsURIRef;
1232 SubString m_aScheme;
1233 SubString m_aUser;
1234 SubString m_aAuth;
1235 SubString m_aHost;
1236 SubString m_aPort;
1237 SubString m_aPath;
1238 SubString m_aQuery;
1239 SubString m_aFragment;
1240 INetProtocol m_eScheme;
1241 INetProtocol m_eSmartScheme;
1243 TOOLS_DLLPRIVATE void setInvalid();
1245 bool setAbsURIRef(
1246 OUString const & rTheAbsURIRef, bool bOctets,
1247 EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart,
1248 FSysStyle eStyle);
1250 // Relative URLs:
1252 bool convertRelToAbs(
1253 OUString const & rTheRelURIRef, bool bOctets,
1254 INetURLObject & rTheAbsURIRef, bool & rWasAbsolute,
1255 EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1256 bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs,
1257 FSysStyle eStyle) const;
1259 bool convertAbsToRel(
1260 OUString const & rTheAbsURIRef, bool bOctets,
1261 OUString & rTheRelURIRef, EncodeMechanism eEncodeMechanism,
1262 DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset,
1263 FSysStyle eStyle) const;
1265 // External URLs:
1267 static bool convertIntToExt(
1268 OUString const & rTheIntURIRef, bool bOctets,
1269 OUString & rTheExtURIRef, DecodeMechanism eDecodeMechanism,
1270 rtl_TextEncoding eCharset);
1272 static bool convertExtToInt(
1273 OUString const & rTheExtURIRef, bool bOctets,
1274 OUString & rTheIntURIRef, DecodeMechanism eDecodeMechanism,
1275 rtl_TextEncoding eCharset);
1277 // Scheme:
1279 struct PrefixInfo;
1281 TOOLS_DLLPRIVATE static inline SchemeInfo const & getSchemeInfo(
1282 INetProtocol eTheScheme);
1284 TOOLS_DLLPRIVATE inline SchemeInfo const & getSchemeInfo() const;
1286 TOOLS_DLLPRIVATE static PrefixInfo const * getPrefix(
1287 sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1289 // Authority:
1291 TOOLS_DLLPRIVATE sal_Int32 getAuthorityBegin() const;
1293 TOOLS_DLLPRIVATE SubString getAuthority() const;
1295 // User Info:
1297 bool setUser(
1298 OUString const & rTheUser, bool bOctets,
1299 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1301 bool clearPassword();
1303 bool setPassword(
1304 OUString const & rThePassword, bool bOctets,
1305 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1307 // Host and Port:
1309 TOOLS_DLLPRIVATE static bool parseHost(
1310 sal_Unicode const *& rBegin, sal_Unicode const * pEnd,
1311 OUString & rCanonic);
1313 TOOLS_DLLPRIVATE static bool parseHostOrNetBiosName(
1314 sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
1315 EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1316 bool bNetBiosName, OUStringBuffer* pCanonic);
1318 bool setHost(
1319 OUString const & rTheHost, bool bOctets,
1320 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1322 // Path:
1324 TOOLS_DLLPRIVATE static bool parsePath(
1325 INetProtocol eScheme, sal_Unicode const ** pBegin,
1326 sal_Unicode const * pEnd, bool bOctets, EncodeMechanism eMechanism,
1327 rtl_TextEncoding eCharset, bool bSkippedInitialSlash,
1328 sal_uInt32 nSegmentDelimiter, sal_uInt32 nAltSegmentDelimiter,
1329 sal_uInt32 nQueryDelimiter, sal_uInt32 nFragmentDelimiter,
1330 OUStringBuffer &rSynPath);
1332 bool setPath(
1333 OUString const & rThePath, bool bOctets,
1334 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1336 // Hierarchical Path:
1338 TOOLS_DLLPRIVATE bool checkHierarchical() const;
1340 bool appendSegment(
1341 OUString const & rTheSegment, bool bOctets,
1342 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1344 TOOLS_DLLPRIVATE SubString getSegment(
1345 sal_Int32 nIndex, bool bIgnoreFinalSlash) const;
1347 bool insertName(
1348 OUString const & rTheName, bool bOctets, bool bAppendFinalSlash,
1349 sal_Int32 nIndex, bool bIgnoreFinalSlash, EncodeMechanism eMechanism,
1350 rtl_TextEncoding eCharset);
1352 // Query:
1354 bool clearQuery();
1356 bool setQuery(
1357 OUString const & rTheQuery, bool bOctets,
1358 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1360 // Fragment:
1362 bool clearFragment();
1364 bool setFragment(
1365 OUString const & rTheMark, bool bOctets,
1366 EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1368 // FILE URLs:
1370 TOOLS_DLLPRIVATE bool hasDosVolume(FSysStyle eStyle) const;
1372 // Coding:
1374 static inline OUString extend(const OString& rOctets)
1376 return OStringToOUString(rOctets, RTL_TEXTENCODING_ISO_8859_1);
1379 static inline sal_Char getEscapePrefix(INetProtocol eTheScheme)
1380 { return eTheScheme == INET_PROT_VIM ? '=' : '%'; }
1382 inline sal_Char getEscapePrefix() const
1383 { return getEscapePrefix(m_eScheme); }
1385 TOOLS_DLLPRIVATE static inline void appendEscape(
1386 OUStringBuffer & rTheText, sal_Char cEscapePrefix,
1387 sal_uInt32 nOctet);
1389 static OUString encodeText(
1390 sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
1391 Part ePart, sal_Char cEscapePrefix, EncodeMechanism eMechanism,
1392 rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
1394 static inline OUString encodeText(
1395 OUString const & rTheText, bool bOctets, Part ePart,
1396 sal_Char cEscapePrefix, EncodeMechanism eMechanism,
1397 rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
1399 static OUString decode(
1400 sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1401 sal_Char cEscapePrefix, DecodeMechanism, rtl_TextEncoding eCharset);
1403 inline OUString decode(
1404 SubString const & rSubString, sal_Char cEscapePrefix,
1405 DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const;
1407 // Specialized helpers:
1409 TOOLS_DLLPRIVATE static bool scanIPv6reference(
1410 sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1412 private:
1413 void changeScheme(INetProtocol eTargetScheme);
1416 // static
1417 inline OUString INetURLObject::encodeText(OUString const & rTheText,
1418 bool bOctets, Part ePart,
1419 sal_Char cEscapePrefix,
1420 EncodeMechanism eMechanism,
1421 rtl_TextEncoding eCharset,
1422 bool bKeepVisibleEscapes)
1424 return encodeText(rTheText.getStr(),
1425 rTheText.getStr() + rTheText.getLength(), bOctets, ePart,
1426 cEscapePrefix, eMechanism, eCharset,
1427 bKeepVisibleEscapes);
1430 inline OUString INetURLObject::decode(SubString const & rSubString,
1431 sal_Char cEscapePrefix,
1432 DecodeMechanism eMechanism,
1433 rtl_TextEncoding eCharset) const
1435 return rSubString.isPresent() ?
1436 decode(m_aAbsURIRef.getStr() + rSubString.getBegin(),
1437 m_aAbsURIRef.getStr() + rSubString.getEnd(),
1438 cEscapePrefix, eMechanism, eCharset) :
1439 OUString();
1442 inline INetURLObject::INetURLObject(const OString& rTheAbsURIRef,
1443 EncodeMechanism eMechanism,
1444 rtl_TextEncoding eCharset):
1445 m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1447 setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset, false,
1448 FSysStyle(0));
1451 inline INetURLObject::INetURLObject(OUString const & rTheAbsURIRef,
1452 EncodeMechanism eMechanism,
1453 rtl_TextEncoding eCharset):
1454 m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1456 setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
1457 FSysStyle(0));
1460 inline bool INetURLObject::SetURL(const OString& rTheAbsURIRef,
1461 EncodeMechanism eMechanism,
1462 rtl_TextEncoding eCharset)
1464 return setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset,
1465 false, FSysStyle(0));
1468 inline bool INetURLObject::SetURL(OUString const & rTheAbsURIRef,
1469 EncodeMechanism eMechanism,
1470 rtl_TextEncoding eCharset)
1472 return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
1473 FSysStyle(0));
1476 inline INetURLObject::INetURLObject(OUString const & rTheAbsURIRef,
1477 INetProtocol eTheSmartScheme,
1478 EncodeMechanism eMechanism,
1479 rtl_TextEncoding eCharset,
1480 FSysStyle eStyle):
1481 m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(eTheSmartScheme)
1483 setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true, eStyle);
1486 inline bool INetURLObject::SetSmartURL(const OString& rTheAbsURIRef,
1487 EncodeMechanism eMechanism,
1488 rtl_TextEncoding eCharset,
1489 FSysStyle eStyle)
1491 return setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset,
1492 true, eStyle);
1495 inline bool INetURLObject::SetSmartURL(OUString const & rTheAbsURIRef,
1496 EncodeMechanism eMechanism,
1497 rtl_TextEncoding eCharset,
1498 FSysStyle eStyle)
1500 return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true,
1501 eStyle);
1504 inline INetURLObject
1505 INetURLObject::smartRel2Abs(const OString& rTheRelURIRef,
1506 bool & rWasAbsolute,
1507 bool bIgnoreFragment,
1508 EncodeMechanism eMechanism,
1509 rtl_TextEncoding eCharset,
1510 bool bRelativeNonURIs,
1511 FSysStyle eStyle) const
1513 INetURLObject aTheAbsURIRef;
1514 convertRelToAbs(extend(rTheRelURIRef), true, aTheAbsURIRef, rWasAbsolute,
1515 eMechanism, eCharset, bIgnoreFragment, true,
1516 bRelativeNonURIs, eStyle);
1517 return aTheAbsURIRef;
1520 inline INetURLObject
1521 INetURLObject::smartRel2Abs(OUString const & rTheRelURIRef,
1522 bool & rWasAbsolute,
1523 bool bIgnoreFragment,
1524 EncodeMechanism eMechanism,
1525 rtl_TextEncoding eCharset,
1526 bool bRelativeNonURIs,
1527 FSysStyle eStyle) const
1529 INetURLObject aTheAbsURIRef;
1530 convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, rWasAbsolute,
1531 eMechanism, eCharset, bIgnoreFragment, true,
1532 bRelativeNonURIs, eStyle);
1533 return aTheAbsURIRef;
1536 inline bool INetURLObject::GetNewAbsURL(const OString& rTheRelURIRef,
1537 INetURLObject * pTheAbsURIRef,
1538 EncodeMechanism eMechanism,
1539 rtl_TextEncoding eCharset,
1540 FSysStyle eStyle, bool bIgnoreFragment)
1541 const
1543 INetURLObject aTheAbsURIRef;
1544 bool bWasAbsolute;
1545 if (!convertRelToAbs(extend(rTheRelURIRef), true, aTheAbsURIRef,
1546 bWasAbsolute, eMechanism, eCharset, bIgnoreFragment,
1547 false, false, eStyle))
1548 return false;
1549 if (pTheAbsURIRef)
1550 *pTheAbsURIRef = aTheAbsURIRef;
1551 return true;
1554 inline bool INetURLObject::GetNewAbsURL(OUString const & rTheRelURIRef,
1555 INetURLObject * pTheAbsURIRef,
1556 EncodeMechanism eMechanism,
1557 rtl_TextEncoding eCharset,
1558 FSysStyle eStyle, bool bIgnoreFragment)
1559 const
1561 INetURLObject aTheAbsURIRef;
1562 bool bWasAbsolute;
1563 if (!convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, bWasAbsolute,
1564 eMechanism, eCharset, bIgnoreFragment, false, false,
1565 eStyle))
1566 return false;
1567 if (pTheAbsURIRef)
1568 *pTheAbsURIRef = aTheAbsURIRef;
1569 return true;
1572 // static
1573 inline OUString INetURLObject::GetRelURL(const OString& rTheBaseURIRef,
1574 const OString& rTheAbsURIRef,
1575 EncodeMechanism eEncodeMechanism,
1576 DecodeMechanism eDecodeMechanism,
1577 rtl_TextEncoding eCharset,
1578 FSysStyle eStyle)
1580 OUString aTheRelURIRef;
1581 INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1582 convertAbsToRel(extend(rTheAbsURIRef), true, aTheRelURIRef,
1583 eEncodeMechanism, eDecodeMechanism, eCharset, eStyle);
1584 return aTheRelURIRef;
1587 // static
1588 inline OUString INetURLObject::GetRelURL(OUString const & rTheBaseURIRef,
1589 OUString const & rTheAbsURIRef,
1590 EncodeMechanism eEncodeMechanism,
1591 DecodeMechanism eDecodeMechanism,
1592 rtl_TextEncoding eCharset,
1593 FSysStyle eStyle)
1595 OUString aTheRelURIRef;
1596 INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1597 convertAbsToRel(rTheAbsURIRef, false, aTheRelURIRef, eEncodeMechanism,
1598 eDecodeMechanism, eCharset, eStyle);
1599 return aTheRelURIRef;
1602 // static
1603 inline bool INetURLObject::translateToExternal(const OString& rTheIntURIRef,
1604 OUString & rTheExtURIRef,
1605 DecodeMechanism
1606 eDecodeMechanism,
1607 rtl_TextEncoding eCharset)
1609 OUString aTheExtURIRef;
1610 bool bRet = convertIntToExt(extend(rTheIntURIRef), true, aTheExtURIRef,
1611 eDecodeMechanism, eCharset);
1612 rTheExtURIRef = aTheExtURIRef;
1613 return bRet;
1616 // static
1617 inline bool INetURLObject::translateToExternal(OUString const &
1618 rTheIntURIRef,
1619 OUString & rTheExtURIRef,
1620 DecodeMechanism
1621 eDecodeMechanism,
1622 rtl_TextEncoding eCharset)
1624 return convertIntToExt(rTheIntURIRef, false, rTheExtURIRef,
1625 eDecodeMechanism, eCharset);
1628 // static
1629 inline bool INetURLObject::translateToInternal(const OString&
1630 rTheExtURIRef,
1631 OUString & rTheIntURIRef,
1632 DecodeMechanism
1633 eDecodeMechanism,
1634 rtl_TextEncoding eCharset)
1636 OUString aTheIntURIRef;
1637 bool bRet = convertExtToInt(extend(rTheExtURIRef), true, aTheIntURIRef,
1638 eDecodeMechanism, eCharset);
1639 rTheIntURIRef = aTheIntURIRef;
1640 return bRet;
1643 // static
1644 inline bool INetURLObject::translateToInternal(OUString const &
1645 rTheExtURIRef,
1646 OUString & rTheIntURIRef,
1647 DecodeMechanism
1648 eDecodeMechanism,
1649 rtl_TextEncoding eCharset)
1651 return convertExtToInt(rTheExtURIRef, false, rTheIntURIRef,
1652 eDecodeMechanism, eCharset);
1655 inline bool INetURLObject::SetPass(const OString& rThePassword,
1656 EncodeMechanism eMechanism,
1657 rtl_TextEncoding eCharset)
1659 return rThePassword.isEmpty() ?
1660 clearPassword() :
1661 setPassword(extend(rThePassword), true, eMechanism, eCharset);
1664 inline bool INetURLObject::SetPass(OUString const & rThePassword,
1665 EncodeMechanism eMechanism,
1666 rtl_TextEncoding eCharset)
1668 return rThePassword.isEmpty() ?
1669 clearPassword() :
1670 setPassword(rThePassword, false, eMechanism, eCharset);
1673 inline bool INetURLObject::SetUserAndPass(const OString& rTheUser,
1674 const OString& rThePassword,
1675 EncodeMechanism eMechanism,
1676 rtl_TextEncoding eCharset)
1678 return setUser(extend(rTheUser), true, eMechanism, eCharset)
1679 && (rThePassword.isEmpty() ?
1680 clearPassword() :
1681 setPassword(extend(rThePassword), true, eMechanism,
1682 eCharset));
1685 inline bool INetURLObject::SetUserAndPass(OUString const & rTheUser,
1686 OUString const & rThePassword,
1687 EncodeMechanism eMechanism,
1688 rtl_TextEncoding eCharset)
1690 return setUser(rTheUser, false, eMechanism, eCharset)
1691 && (rThePassword.isEmpty() ?
1692 clearPassword() :
1693 setPassword(rThePassword, false, eMechanism, eCharset));
1696 inline bool INetURLObject::insertName(OUString const & rTheName,
1697 bool bAppendFinalSlash,
1698 sal_Int32 nIndex,
1699 bool bIgnoreFinalSlash,
1700 EncodeMechanism eMechanism,
1701 rtl_TextEncoding eCharset)
1703 return insertName(rTheName, false, bAppendFinalSlash, nIndex,
1704 bIgnoreFinalSlash, eMechanism, eCharset);
1707 inline bool INetURLObject::SetParam(const OString& rTheQuery,
1708 EncodeMechanism eMechanism,
1709 rtl_TextEncoding eCharset)
1711 return rTheQuery.isEmpty() ?
1712 clearQuery() :
1713 setQuery(extend(rTheQuery), true, eMechanism, eCharset);
1716 inline bool INetURLObject::SetParam(OUString const & rTheQuery,
1717 EncodeMechanism eMechanism,
1718 rtl_TextEncoding eCharset)
1720 return rTheQuery.isEmpty() ?
1721 clearQuery() :
1722 setQuery(rTheQuery, false, eMechanism, eCharset);
1725 inline bool INetURLObject::SetMark(const OString& rTheFragment,
1726 EncodeMechanism eMechanism,
1727 rtl_TextEncoding eCharset)
1729 return rTheFragment.isEmpty() ?
1730 clearFragment() :
1731 setFragment(extend(rTheFragment), true, eMechanism, eCharset);
1734 inline bool INetURLObject::SetMark(OUString const & rTheFragment,
1735 EncodeMechanism eMechanism,
1736 rtl_TextEncoding eCharset)
1738 return rTheFragment.isEmpty() ?
1739 clearFragment() :
1740 setFragment(rTheFragment, false, eMechanism, eCharset);
1743 inline INetURLObject::INetURLObject(OUString const & rFSysPath,
1744 FSysStyle eStyle):
1745 m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1747 setFSysPath(rFSysPath, eStyle);
1750 // static
1751 inline OUString INetURLObject::encode(const OString& rText, Part ePart,
1752 sal_Char cEscapePrefix,
1753 EncodeMechanism eMechanism,
1754 rtl_TextEncoding eCharset)
1756 return encodeText(extend(rText), true, ePart, cEscapePrefix, eMechanism,
1757 eCharset, false);
1760 // static
1761 inline OUString INetURLObject::encode(OUString const & rText, Part ePart,
1762 sal_Char cEscapePrefix,
1763 EncodeMechanism eMechanism,
1764 rtl_TextEncoding eCharset)
1766 return encodeText(rText, false, ePart, cEscapePrefix, eMechanism,
1767 eCharset, false);
1770 // static
1771 inline OUString INetURLObject::decode(OUString const & rText,
1772 sal_Char cEscapePrefix,
1773 DecodeMechanism eMechanism,
1774 rtl_TextEncoding eCharset)
1776 return decode(rText.getStr(), rText.getStr() + rText.getLength(),
1777 cEscapePrefix, eMechanism, eCharset);
1780 inline OUString INetURLObject::decode(OUStringBuffer const & rText,
1781 sal_Char cEscapePrefix,
1782 DecodeMechanism eMechanism,
1783 rtl_TextEncoding eCharset)
1785 return decode(rText.getStr(), rText.getStr() + rText.getLength(),
1786 cEscapePrefix, eMechanism, eCharset);
1789 #endif
1791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */