xref: /trunk/main/tools/inc/tools/urlobj.hxx (revision 8b851043)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _URLOBJ_HXX
24 #define _URLOBJ_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <tools/string.hxx>
28 #include "com/sun/star/uno/Reference.hxx"
29 #include "rtl/string.h"
30 #include "rtl/ustrbuf.hxx"
31 #include "rtl/textenc.h"
32 #include "sal/types.h"
33 
34 namespace com { namespace sun { namespace star { namespace util {
35     class XStringWidth;
36 } } } }
37 
38 //============================================================================
39 // Special tokens:
40 #define INET_PASS_TOKEN '@'
41 #define INET_DELIM_TOKEN ':'
42 #define INET_DELIM_IMAPID ';'
43 #define INET_ENC_DELIM_TOKEN '|'
44 #define INET_DELIM_HOST_TOKEN '.'
45 #define INET_PATH_TOKEN '/'
46 #define INET_DOSPATH_TOKEN '\\'
47 #define INET_MARK_TOKEN '#'
48 #define INET_PARAM_TOKEN '?'
49 #define INET_HEX_ESCAPE '%'
50 
51 //============================================================================
52 // Common URL prefixes for various schemes:
53 #define	INET_FTP_SCHEME "ftp://"
54 #define INET_HTTP_SCHEME "http://"
55 #define INET_HTTPS_SCHEME "https://"
56 #define INET_FILE_SCHEME "file://"
57 #define INET_GOPHER_SCHEME "gopher://"
58 #define INET_MAILTO_SCHEME "mailto:"
59 #define INET_CID_SCHEME "cid:"
60 #define INET_NEWS_SCHEME "news:"
61 #define INET_POP3_SCHEME "pop3://"
62 #define INET_LDAP_SCHEME "ldap://"
63 #define INET_PRIVATE_SCHEME "private:"
64 #define INET_BUGDOC_SCHEME "bugdoc:"
65 #define INET_SLOT_SCHEME "slot:"
66 #define INET_MACRO_SCHEME "macro:"
67 #define INET_JAVASCRIPT_SCHEME "javascript:"
68 #define INET_IMAP_SCHEME "imap://"
69 #define INET_DOWNPASS_SCHEME ".."
70 #define INET_DATA_SCHEME "data:"
71 #define INET_OUT_SCHEME "out://"
72 #define INET_FIF_SCHEME "fif://"
73 #define INET_CEPT_SCHEME "cept://"
74 #define INET_VIM_SCHEME "vim://"
75 #define INET_UNO_SCHEME ".uno:"
76 #define INET_COMPONENT_SCHEME ".component:"
77 #define INET_DB_SCHEME "db:"
78 #define INET_BUGID_SCHEME "bugid:"
79 #define INET_TELNET_SCHEME "telnet://"
80 #define INET_HID_SCHEME "hid:"
81 
82 #define URL_PREFIX_PRIV_SOFFICE "private:"
83 enum
84 {
85 	URL_PREFIX_PRIV_SOFFICE_LEN
86 	    = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_SOFFICE)
87 };
88 
89 #define URL_PREFIX_PRIV_OBSOLETE URL_PREFIX_PRIV_SOFFICE
90 enum
91 {
92 	URL_PREFIX_PRIV_OBSOLETE_LEN
93 	    = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_OBSOLETE)
94 };
95 
96 #define URL_PREFIX_PRIV_EXTERN "staroffice:"
97 enum
98 {
99 	URL_PREFIX_PRIV_EXTERN_LEN = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_EXTERN)
100 };
101 
102 //============================================================================
103 // Schemes:
104 enum INetProtocol
105 {
106 	INET_PROT_NOT_VALID = 0,
107 	INET_PROT_FTP = 1,
108 	INET_PROT_HTTP = 2,
109 	INET_PROT_FILE = 3,
110 	INET_PROT_MAILTO = 4,
111 	INET_PROT_VND_SUN_STAR_WEBDAV = 5,
112 	INET_PROT_NEWS = 6,
113 	INET_PROT_PRIV_SOFFICE = 7,
114 	INET_PROT_PRIVATE = INET_PROT_PRIV_SOFFICE, // obsolete
115 	INET_PROT_VND_SUN_STAR_HELP = 8,
116 	INET_PROT_HTTPS = 9,
117 	INET_PROT_SLOT = 10,
118 	INET_PROT_MACRO = 11,
119 	INET_PROT_JAVASCRIPT = 12,
120 	INET_PROT_IMAP = 13,
121 	INET_PROT_POP3 = 14,
122 	INET_PROT_DATA = 15,
123 	INET_PROT_CID = 16,
124 	INET_PROT_OUT = 17,
125 	INET_PROT_VND_SUN_STAR_HIER = 18,
126 	INET_PROT_VIM = 19,
127 	INET_PROT_UNO = 20,
128 	INET_PROT_COMPONENT = 21,
129 	INET_PROT_VND_SUN_STAR_PKG = 22,
130 	INET_PROT_LDAP = 23,
131 	INET_PROT_DB = 24,
132 	INET_PROT_VND_SUN_STAR_CMD = 25,
133 	INET_PROT_VND_SUN_STAR_ODMA = 26,
134     INET_PROT_TELNET = 27,
135     INET_PROT_VND_SUN_STAR_EXPAND = 28,
136     INET_PROT_VND_SUN_STAR_TDOC = 29,
137     INET_PROT_GENERIC = 30,
138     INET_PROT_SMB = 31,
139 	INET_PROT_HID = 32,
140 	INET_PROT_END = 33
141 };
142 
143 //============================================================================
144 class TOOLS_DLLPUBLIC INetURLObject
145 {
146 public:
147 	//========================================================================
148 	// Get- and Set-Methods:
149 
150 	/** The way input strings that represent (parts of) URIs are interpreted
151 		in set-methods.
152 
153 		@descr  Most set-methods accept either a ByteString or a rtl::OUString
154 		as input.  Using a ByteString, octets in the range 0x80--0xFF are
155 		replaced by single escape sequences.  Using a rtl::OUString , UTF-32
156 		characters in the range 0x80--0x10FFFF are replaced by sequences of
157 		escape sequences, representing the UTF-8 coded characters.
158 
159 		@descr  Along with an EncodeMechanism parameter, the set-methods all
160 		take an rtl_TextEncoding parameter, which is ignored unless the
161 		EncodeMechanism is WAS_ENCODED.
162 	 */
163 	enum EncodeMechanism
164 	{
165 		/** All escape sequences that are already present are ignored, and are
166 			interpreted as literal sequences of three characters.
167 		 */
168 		ENCODE_ALL,
169 
170 		/** Sequences of escape sequences, that represent characters from the
171 			specified character set and that can be converted to UTF-32
172 			characters, are first decoded.  If they have to be encoded, they
173 			are converted to UTF-8 characters and are than translated into
174 			(sequences of) escape sequences.  Other escape sequences are
175 			copied verbatim (but using upper case hex digits).
176 		 */
177 		WAS_ENCODED,
178 
179 		/** All escape sequences that are already present are copied verbatim
180 			(but using upper case hex digits).
181 		 */
182 		NOT_CANONIC
183 	};
184 
185 	/** The way strings that represent (parts of) URIs are returned from get-
186 		methods.
187 
188 		@descr  Along with a DecodeMechanism parameter, the get-methods all
189 		take an rtl_TextEncoding parameter, which is ignored unless the
190 		DecodeMechanism is DECODE_WITH_CHARSET or DECODE_UNAMBIGUOUS.
191 	 */
192 	enum DecodeMechanism
193 	{
194 		/** The (part of the) URI is returned unchanged.  Since URIs are
195 			written using a subset of US-ASCII, the returned string is
196 			guaranteed to contain only US-ASCII characters.
197 		 */
198 		NO_DECODE,
199 
200 		/** All sequences of escape sequences that represent UTF-8 coded
201 			UTF-32 characters with a numerical value greater than 0x7F, are
202 			replaced by the respective UTF-16 characters.  All other escape
203 			sequences are not decoded.
204 		 */
205 		DECODE_TO_IURI,
206 
207 		/** All (sequences of) escape sequences that represent characters from
208 			the specified character set, and that can be converted to UTF-32,
209 			are replaced by the respective UTF-16 characters.  All other
210 			escape sequences are not decoded.
211 		 */
212 		DECODE_WITH_CHARSET,
213 
214 		/** All (sequences of) escape sequences that represent characters from
215 			the specified character set, that can be converted to UTF-32, and
216 			that (in the case of ASCII characters) can safely be decoded
217 			without altering the meaning of the (part of the) URI, are
218 			replaced by the respective UTF-16 characters.  All other escape
219 			sequences are not decoded.
220 		 */
221 		DECODE_UNAMBIGUOUS
222 	};
223 
224 	//========================================================================
225 	// General Structure:
226 
INetURLObject()227 	inline INetURLObject():
228 		m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP) {}
229 
HasError() const230 	inline bool HasError() const { return m_eScheme == INET_PROT_NOT_VALID; }
231 
GetMainURL(DecodeMechanism eMechanism,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const232 	inline rtl::OUString GetMainURL(DecodeMechanism eMechanism,
233 								rtl_TextEncoding eCharset
234 								    = RTL_TEXTENCODING_UTF8) const
235 	{ return decode(m_aAbsURIRef, getEscapePrefix(), eMechanism, eCharset); }
236 
237 	rtl::OUString GetURLNoPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
238 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
239 		const;
240 
241 	rtl::OUString GetURLNoMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
242 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
243 		const;
244 
245     rtl::OUString
246     getAbbreviated(com::sun::star::uno::Reference<
247                            com::sun::star::util::XStringWidth > const &
248                        rStringWidth,
249                    sal_Int32 nWidth,
250                    DecodeMechanism eMechanism = DECODE_TO_IURI,
251                    rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
252 		const;
253 
254 	bool operator ==(INetURLObject const & rObject) const;
255 
operator !=(INetURLObject const & rObject) const256 	inline bool operator !=(INetURLObject const & rObject) const
257 	{ return !(*this == rObject); }
258 
259 	bool operator <(INetURLObject const & rObject) const;
260 
operator >(INetURLObject const & rObject) const261 	inline bool operator >(INetURLObject const & rObject) const
262 	{ return rObject < *this; }
263 
264 	//========================================================================
265 	// Strict Parsing:
266 
267 	inline INetURLObject(ByteString const & rTheAbsURIRef,
268 						 EncodeMechanism eMechanism = WAS_ENCODED,
269 						 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
270 
271 	inline INetURLObject(rtl::OUString const & rTheAbsURIRef,
272 						 EncodeMechanism eMechanism = WAS_ENCODED,
273 						 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
274 
275 	inline bool SetURL(ByteString const & rTheAbsURIRef,
276 					   EncodeMechanism eMechanism = WAS_ENCODED,
277 					   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
278 
279 	inline bool SetURL(rtl::OUString const & rTheAbsURIRef,
280 					   EncodeMechanism eMechanism = WAS_ENCODED,
281 					   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
282 
283 	bool ConcatData(INetProtocol eTheScheme, rtl::OUString const & rTheUser,
284 					rtl::OUString const & rThePassword,
285 					rtl::OUString const & rTheHost, sal_uInt32 nThePort,
286 					rtl::OUString const & rThePath,
287 					EncodeMechanism eMechanism = WAS_ENCODED,
288 					rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
289 
290 	//========================================================================
291 	// Smart Parsing:
292 
293 	/** The supported notations for file system paths.
294 	 */
295 	enum FSysStyle
296 	{
297 		/** VOS notation (e.g., "//server/dir/file").
298 		 */
299 		FSYS_VOS = 0x1,
300 
301 		/** Unix notation (e.g., "/dir/file").
302 		 */
303 		FSYS_UNX = 0x2,
304 
305 		/** DOS notation (e.g., "a:\dir\file" and "\\server\dir\file").
306 		 */
307 		FSYS_DOS = 0x4,
308 
309 		/** Mac notation (e.g., "dir:file").
310 		 */
311 		FSYS_MAC = 0x8,
312 
313 		/** Detect the used notation.
314 
315 			@descr  For the following descriptions, please note that
316 			whereas FSYS_DEFAULT includes all style bits, combinations of only
317 			a few style bits are also possible, and are also described.
318 
319 			@descr  When used to translate a file system path to a file URL,
320 			the subset of the following productions for which the appropriate
321 			style bit is set are checked in order (using the conventions of
322 			RFC 2234, RFC 2396, and RFC 2732; UCS4 stands for any UCS4
323 			character):
324 
325 			 Production T1 (VOS local; FSYS_VOS only):
326 			    "//." ["/" *UCS4]
327 			  becomes
328 			    "file:///" *UCS4
329 
330 			 Production T2 (VOS host; FSYS_VOS only):
331 			    "//" [host] ["/" *UCS4]
332 			  becomes
333 			    "file://" host "/" *UCS4
334 
335 			 Production T3 (UNC; FSYS_DOS only):
336 			    "\\" [host] ["\" *UCS4]
337 			  becomes
338 			    "file://" host "/" *UCS4
339 			  replacing "\" by "/" within <*UCS4>
340 
341 			 Production T4 (Unix-like DOS; FSYS_DOS only):
342 			    ALPHA ":" ["/" *UCS4]
343 			  becomes
344 			    "file:///" ALPHA ":/" *UCS4
345 			  replacing "\" by "/" within <*UCS4>
346 
347 			 Production T5 (DOS; FSYS_DOS only):
348 			    ALPHA ":" ["\" *UCS4]
349 			  becomes
350 			    "file:///" ALPHA ":/" *UCS4
351 			  replacing "\" by "/" within <*UCS4>
352 
353 			 Production T6 (any):
354 			    *UCS4
355 			  becomes
356 			    "file:///" *UCS4
357 			  replacing the delimiter by "/" within <*UCS4>.  The delimiter is
358 			  that character from the set { "/", "\", ":" } which appears most
359 			  often in <*UCS4> (if FSYS_UNX is not among the style bits, "/"
360 			  is removed from the set; if FSYS_DOS is not among the style
361 			  bits, "\" is removed from the set; if FSYS_MAC is not among the
362 			  style bits, ":" is removed from the set).  If two or more
363 			  characters appear the same number of times, the character
364 			  mentioned first in that set is chosen.  If the first character
365 			  of <*UCS4> is the delimiter, that character is not copied.
366 
367 			@descr  When used to translate a file URL to a file system path,
368 			the following productions are checked in order (using the
369 			conventions of RFC 2234, RFC 2396, and RFC 2732):
370 
371 			 Production F1 (VOS; FSYS_VOS):
372 			    "file://" host "/" fpath ["#" fragment]
373 			  becomes
374 			    "//" host "/" fpath
375 
376 			 Production F2 (DOS; FSYS_DOS):
377 			    "file:///" ALPHA ":" ["/" fpath] ["#" fragment]
378 			  becomes
379 			    ALPHA ":" ["\" fpath]
380 			  replacing "/" by "\" in <fpath>
381 
382 			 Production F3 (Unix; FSYS_UNX):
383 			    "file:///" fpath ["#" fragment]
384 			  becomes
385 			    "/" fpath
386 		 */
387 		FSYS_DETECT = FSYS_VOS | FSYS_UNX | FSYS_DOS
388 	};
389 
390 	inline INetURLObject(rtl::OUString const & rTheAbsURIRef,
391 						 INetProtocol eTheSmartScheme,
392 						 EncodeMechanism eMechanism = WAS_ENCODED,
393 						 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
394 						 FSysStyle eStyle = FSYS_DETECT);
395 
SetSmartProtocol(INetProtocol eTheSmartScheme)396 	inline void SetSmartProtocol(INetProtocol eTheSmartScheme)
397 	{ m_eSmartScheme = eTheSmartScheme; }
398 
399 	inline bool
400 	SetSmartURL(ByteString const & rTheAbsURIRef,
401 				EncodeMechanism eMechanism = WAS_ENCODED,
402 				rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
403 				FSysStyle eStyle = FSYS_DETECT);
404 
405 	inline bool
406 	SetSmartURL(rtl::OUString const & rTheAbsURIRef,
407 				EncodeMechanism eMechanism = WAS_ENCODED,
408 				rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
409 				FSysStyle eStyle = FSYS_DETECT);
410 
411 	inline INetURLObject
412 	smartRel2Abs(ByteString const & rTheRelURIRef,
413 				 bool & rWasAbsolute,
414 				 bool bIgnoreFragment = false,
415 				 EncodeMechanism eMechanism = WAS_ENCODED,
416 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
417 				 bool bRelativeNonURIs = false,
418 				 FSysStyle eStyle = FSYS_DETECT) const;
419 
420 	inline INetURLObject
421 	smartRel2Abs(rtl::OUString const & rTheRelURIRef,
422 				 bool & rWasAbsolute,
423 				 bool bIgnoreFragment = false,
424 				 EncodeMechanism eMechanism = WAS_ENCODED,
425 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
426 				 bool bRelativeNonURIs = false,
427 				 FSysStyle eStyle = FSYS_DETECT) const;
428 
429 	//========================================================================
430 	// Relative URLs:
431 
432 	inline bool
433 	GetNewAbsURL(ByteString const & rTheRelURIRef,
434 				 INetURLObject * pTheAbsURIRef,
435 				 EncodeMechanism eMechanism = WAS_ENCODED,
436 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
437 				 FSysStyle eStyle = FSYS_DETECT, bool bIgnoreFragment = false)
438         const;
439 
440 	inline bool
441 	GetNewAbsURL(rtl::OUString const & rTheRelURIRef,
442 				 INetURLObject * pTheAbsURIRef,
443 				 EncodeMechanism eMechanism = WAS_ENCODED,
444 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
445 				 FSysStyle eStyle = FSYS_DETECT, bool bIgnoreFragment = false)
446         const;
447 
448 	/** @descr  If rTheRelURIRef cannot be converted to an absolute URL
449 		(because of syntactic reasons), either rTheRelURIRef or an empty
450 		string is returned:  If all of the parameters eEncodeMechanism,
451 		eDecodeMechanism and eCharset have their respective default values,
452 		then rTheRelURIRef is returned unmodified; otherwise, an empty string
453 		is returned.
454 	 */
455     static rtl::OUString
456     GetAbsURL(rtl::OUString const & rTheBaseURIRef,
457               rtl::OUString const & rTheRelURIRef,
458               bool bIgnoreFragment = false,
459               EncodeMechanism eEncodeMechanism = WAS_ENCODED,
460               DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
461               rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
462               FSysStyle eStyle = FSYS_DETECT);
463 
464 	static inline rtl::OUString
465 	GetRelURL(ByteString const & rTheBaseURIRef,
466 			  ByteString const & rTheAbsURIRef,
467 			  EncodeMechanism eEncodeMechanism = WAS_ENCODED,
468 			  DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
469 			  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
470 			  FSysStyle eStyle = FSYS_DETECT);
471 
472 	static inline rtl::OUString
473 	GetRelURL(rtl::OUString const & rTheBaseURIRef,
474 			  rtl::OUString const & rTheAbsURIRef,
475 			  EncodeMechanism eEncodeMechanism = WAS_ENCODED,
476 			  DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
477 			  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
478 			  FSysStyle eStyle = FSYS_DETECT);
479 
480 	//========================================================================
481 	// External URLs:
482 
483 	rtl::OUString getExternalURL(DecodeMechanism eMechanism = DECODE_TO_IURI,
484 							 rtl_TextEncoding eCharset
485 							     = RTL_TEXTENCODING_UTF8) const;
486 
487 	static inline bool translateToExternal(ByteString const & rTheIntURIRef,
488 										   rtl::OUString & rTheExtURIRef,
489 										   DecodeMechanism eDecodeMechanism
490 										       = DECODE_TO_IURI,
491 										   rtl_TextEncoding eCharset
492 										       = RTL_TEXTENCODING_UTF8);
493 
494 	static inline bool translateToExternal(rtl::OUString const & rTheIntURIRef,
495 										   rtl::OUString & rTheExtURIRef,
496 										   DecodeMechanism eDecodeMechanism
497 										       = DECODE_TO_IURI,
498 										   rtl_TextEncoding eCharset
499 										       = RTL_TEXTENCODING_UTF8);
500 
501 	static inline bool translateToInternal(ByteString const & rTheExtURIRef,
502 										   rtl::OUString & rTheIntURIRef,
503 										   DecodeMechanism eDecodeMechanism
504 										       = DECODE_TO_IURI,
505 										   rtl_TextEncoding eCharset
506 										       = RTL_TEXTENCODING_UTF8);
507 
508     static inline bool translateToInternal(rtl::OUString const & rTheExtURIRef,
509                                            rtl::OUString & rTheIntURIRef,
510                                            DecodeMechanism eDecodeMechanism
511                                                = DECODE_TO_IURI,
512                                            rtl_TextEncoding eCharset
513                                                = RTL_TEXTENCODING_UTF8);
514 
515 	//========================================================================
516 	// Scheme:
517 
518 	struct SchemeInfo;
519 
GetProtocol() const520 	inline INetProtocol GetProtocol() const { return m_eScheme; }
521 
522 	/** Return the URL 'prefix' for a given scheme.
523 
524 		@param eTheScheme  One of the supported URL schemes.
525 
526 		@return  The 'prefix' of URLs of the given scheme.
527 	 */
528 	static rtl::OUString GetScheme(INetProtocol eTheScheme);
529 
CompareProtocolScheme(ByteString const & rTheAbsURIRef)530 	static inline INetProtocol CompareProtocolScheme(ByteString const &
531 													     rTheAbsURIRef)
532 	{ return CompareProtocolScheme(extend(rTheAbsURIRef)); }
533 
534 	static INetProtocol CompareProtocolScheme(rtl::OUString const &
535 											      rTheAbsURIRef);
536 
537 	//========================================================================
538 	// User Info:
539 
HasUserData() const540 	inline bool HasUserData() const { return m_aUser.isPresent(); }
541 
IsEmptyUser() const542 	inline bool IsEmptyUser() const
543 	{ return m_aUser.isPresent() && m_aUser.isEmpty(); }
544 
545 	bool hasPassword() const;
546 
IsEmptyPass() const547 	inline bool IsEmptyPass() const
548 	{ return hasPassword() && m_aAuth.isEmpty(); }
549 
GetUser(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const550 	inline rtl::OUString GetUser(DecodeMechanism eMechanism = DECODE_TO_IURI,
551 							 rtl_TextEncoding eCharset
552 							     = RTL_TEXTENCODING_UTF8) const
553 	{ return decode(m_aUser, getEscapePrefix(), eMechanism, eCharset); }
554 
GetPass(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const555 	inline rtl::OUString GetPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
556 							 rtl_TextEncoding eCharset
557 							     = RTL_TEXTENCODING_UTF8) const
558 	{ return decode(m_aAuth, getEscapePrefix(), eMechanism, eCharset); }
559 
SetUser(ByteString const & rTheUser,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)560 	inline bool SetUser(ByteString const & rTheUser,
561 						EncodeMechanism eMechanism = WAS_ENCODED,
562 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
563 	{ return setUser(extend(rTheUser), true, eMechanism, eCharset); }
564 
SetUser(rtl::OUString const & rTheUser,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)565 	inline bool SetUser(rtl::OUString const & rTheUser,
566 						EncodeMechanism eMechanism = WAS_ENCODED,
567 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
568 	{ return setUser(rTheUser, false, eMechanism, eCharset); }
569 
570 	void makeAuthCanonic();
571 
572 	inline bool SetPass(ByteString const & rThePassword,
573 						EncodeMechanism eMechanism = WAS_ENCODED,
574 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
575 
576 	inline bool SetPass(rtl::OUString const & rThePassword,
577 						EncodeMechanism eMechanism = WAS_ENCODED,
578 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
579 
580 	inline bool SetUserAndPass(ByteString const & rTheUser,
581 							   ByteString const & rThePassword,
582 							   EncodeMechanism eMechanism = WAS_ENCODED,
583 							   rtl_TextEncoding eCharset
584 							       = RTL_TEXTENCODING_UTF8);
585 
586 	inline bool SetUserAndPass(rtl::OUString const & rTheUser,
587 							   rtl::OUString const & rThePassword,
588 							   EncodeMechanism eMechanism = WAS_ENCODED,
589 							   rtl_TextEncoding eCharset
590 							       = RTL_TEXTENCODING_UTF8);
591 
592 	//========================================================================
593 	// Host and Port:
594 
HasPort() const595 	inline bool HasPort() const { return m_aPort.isPresent(); }
596 
GetHost(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const597 	inline rtl::OUString GetHost(DecodeMechanism eMechanism = DECODE_TO_IURI,
598 							 rtl_TextEncoding eCharset
599 							     = RTL_TEXTENCODING_UTF8) const
600 	{ return decode(m_aHost, getEscapePrefix(), eMechanism, eCharset); }
601 
602 	rtl::OUString GetHostPort(DecodeMechanism eMechanism = DECODE_TO_IURI,
603 						  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
604 
605 	sal_uInt32 GetPort() const;
606 
SetHost(ByteString const & rTheHost,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)607 	inline bool SetHost(ByteString const & rTheHost,
608 						EncodeMechanism eMechanism = WAS_ENCODED,
609 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
610 	{ return setHost(extend(rTheHost), true, eMechanism, eCharset); }
611 
SetHost(rtl::OUString const & rTheHost,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)612 	inline bool SetHost(rtl::OUString const & rTheHost,
613 						EncodeMechanism eMechanism = WAS_ENCODED,
614 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
615 	{ return setHost(rTheHost, false, eMechanism, eCharset); }
616 
617 	bool SetPort(sal_uInt32 nThePort);
618 
619 	void makePortCanonic();
620 
621 	/** Encode the <hostport> part of a URL.
622 
623 		@ATT  Obsolete, because at the moment the <hostport> part of a URL may
624 		not contain any escape sequences anyway, and because this method does
625 		not inform the caller whether the given <hostport> part is legal.
626 
627 		@param rTheHostPort  The <hostport> part of a URL (for its
628 		interpretation, see the general discussion for set-methods).
629 
630 		@param eMechanism  See the general discussion for set-methods.
631 
632 		@param eCharset  See the general discussion for set-methods.
633 
634 		@return  The <hostport> part, encoded according to the given mechanism
635 		and charset ('forbidden' characters replaced by escape sequences).
636 	 */
637 	static inline rtl::OUString encodeHostPort(ByteString const & rTheHostPort,
638 										   EncodeMechanism eMechanism,
639 										   rtl_TextEncoding eCharset
640 										       = RTL_TEXTENCODING_UTF8);
641 
642 	/** Encode the <hostport> part of a URL.
643 
644 		@ATT  Obsolete, because at the moment the <hostport> part of a URL may
645 		not contain any escape sequences anyway, and because this method does
646 		not inform the caller whether the given <hostport> part is legal.
647 
648 		@param rTheHostPort  The <hostport> part of a URL (for its
649 		interpretation, see the general discussion for set-methods).
650 
651 		@param eMechanism  See the general discussion for set-methods.
652 
653 		@param eCharset  See the general discussion for set-methods.
654 
655 		@return  The <hostport> part, encoded according to the given mechanism
656 		and charset ('forbidden' characters replaced by escape sequences).
657 	 */
encodeHostPort(rtl::OUString const & rTheHostPort,EncodeMechanism eMechanism,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)658 	static inline rtl::OUString encodeHostPort(rtl::OUString const & rTheHostPort,
659 										   EncodeMechanism eMechanism,
660 										   rtl_TextEncoding eCharset
661 										       = RTL_TEXTENCODING_UTF8)
662 	{ return encodeHostPort(rTheHostPort, false, eMechanism, eCharset); }
663 
664 	//========================================================================
665 	// Path:
666 
HasURLPath() const667 	inline bool HasURLPath() const { return !m_aPath.isEmpty(); }
668 
GetURLPath(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const669 	inline rtl::OUString GetURLPath(DecodeMechanism eMechanism = DECODE_TO_IURI,
670 								rtl_TextEncoding eCharset
671 								    = RTL_TEXTENCODING_UTF8) const
672 	{ return decode(m_aPath, getEscapePrefix(), eMechanism, eCharset); }
673 
SetURLPath(ByteString const & rThePath,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)674 	inline bool SetURLPath(ByteString const & rThePath,
675 						   EncodeMechanism eMechanism = WAS_ENCODED,
676 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
677 	{ return setPath(extend(rThePath), true, eMechanism, eCharset); }
678 
SetURLPath(rtl::OUString const & rThePath,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)679 	inline bool SetURLPath(rtl::OUString const & rThePath,
680 						   EncodeMechanism eMechanism = WAS_ENCODED,
681 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
682 	{ return setPath(rThePath, false, eMechanism, eCharset); }
683 
684 	//========================================================================
685 	// Hierarchical Path:
686 
687 	/** A constant to address the last segment in various methods dealing with
688 		hierarchical paths.
689 
690 		@descr  It is often more efficient to address the last segment using
691 		this constant, than to determine its ordinal value using
692 		getSegmentCount().
693 	 */
694 	enum { LAST_SEGMENT = -1 };
695 
696 	/** The number of segments in the hierarchical path.
697 
698 		@descr  Using RFC 2396 and RFC 2234, a hierarchical path is of the
699 		form
700 
701 		  hierarchical-path = 1*("/" segment)
702 
703 		  segment = name *(";" param)
704 
705 		  name = [base ["." extension]]
706 
707 		  base = 1*pchar
708 
709 		  extension = *<any pchar except ".">
710 
711 		  param = *pchar
712 
713 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
714 		hierarchical path does not denote an empty segment, but is ignored.
715 
716 		@return  The number of segments in the hierarchical path.  If the path
717 		is not hierarchical, 0 is returned.
718 	 */
719 	sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
720 
721 	/** Remove a segment from the hierarchical path.
722 
723 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
724 		if addressing the last segment.
725 
726 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
727 		hierarchical path does not denote an empty segment, but is ignored.
728 
729 		@return  True if the segment has successfully been removed (and the
730 		resulting URI is still valid).  If the path is not hierarchical, or
731 		the specified segment does not exist, false is returned.  If false is
732 		returned, the object is not modified.
733 	 */
734 	bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
735 					   bool bIgnoreFinalSlash = true);
736 
737 	/** Insert a new segment into the hierarchical path.
738 
739 		@param rTheName  The name part of the new segment.  The new segment
740 		will contain no parameters.
741 
742 		@param bAppendFinalSlash  If the new segment is appended at the end of
743 		the hierarchical path, this parameter specifies whether to add a final
744 		slash after it or not.
745 
746 		@param nIndex  The non-negative index of the segment before which
747 		to insert the new segment.  LAST_SEGMENT or an nIndex that equals
748 		getSegmentCount() inserts the new segment at the end of the
749 		hierarchical path.
750 
751 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
752 		hierarchical path does not denote an empty segment, but is ignored.
753 
754 		@param eMechanism  See the general discussion for set-methods.
755 
756 		@param eCharset  See the general discussion for set-methods.
757 
758 		@return  True if the segment has successfully been inserted (and the
759 		resulting URI is still valid).  If the path is not hierarchical, or
760 		the specified place to insert the new segment does not exist, false is
761 		returned.  If false is returned, the object is not modified.
762 	 */
763 	inline bool insertName(rtl::OUString const & rTheName,
764 						   bool bAppendFinalSlash = false,
765 						   sal_Int32 nIndex = LAST_SEGMENT,
766 						   bool bIgnoreFinalSlash = true,
767 						   EncodeMechanism eMechanism = WAS_ENCODED,
768 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
769 
770 	/** Get the name of a segment of the hierarchical path.
771 
772 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
773 		if addressing the last segment.
774 
775 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
776 		hierarchical path does not denote an empty segment, but is ignored.
777 
778 		@param eMechanism  See the general discussion for get-methods.
779 
780 		@param eCharset  See the general discussion for get-methods.
781 
782 		@return  The name part of the specified segment.  If the path is not
783 		hierarchical, or the specified segment does not exits, an empty string
784 		is returned.
785 	 */
786 	rtl::OUString getName(sal_Int32 nIndex = LAST_SEGMENT,
787 					  bool bIgnoreFinalSlash = true,
788 					  DecodeMechanism eMechanism = DECODE_TO_IURI,
789 					  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
790 		const;
791 
792 	/** Set the name of a segment (preserving any parameters and any query or
793 		fragment part).
794 
795 		@param rTheName  The new name.
796 
797 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
798 		if addressing the last segment.
799 
800 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
801 		hierarchical path does not denote an empty segment, but is ignored.
802 
803 		@param eMechanism  See the general discussion for set-methods.
804 
805 		@param eCharset  See the general discussion for set-methods.
806 
807 		@return  True if the name has successfully been modified (and the
808 		resulting URI is still valid).  If the path is not hierarchical, or
809 		the specified segment does not exist, false is returned.  If false is
810 		returned, the object is not modified.
811 	 */
812 	bool setName(rtl::OUString const & rTheName,
813 				 sal_Int32 nIndex = LAST_SEGMENT,
814 				 bool bIgnoreFinalSlash = true,
815 				 EncodeMechanism eMechanism = WAS_ENCODED,
816 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
817 
818 	/** Get the base of the name of a segment.
819 
820 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
821 		if addressing the last segment.
822 
823 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
824 		hierarchical path does not denote an empty segment, but is ignored.
825 
826 		@param eMechanism  See the general discussion for get-methods.
827 
828 		@param eCharset  See the general discussion for get-methods.
829 
830 		@return  The base part of the specified segment.  If the path is
831 		not hierarchical, or the specified segment does not exits, an empty
832 		string is returned.
833 	 */
834 	rtl::OUString getBase(sal_Int32 nIndex = LAST_SEGMENT,
835 					  bool bIgnoreFinalSlash = true,
836 					  DecodeMechanism eMechanism = DECODE_TO_IURI,
837 					  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
838 		const;
839 
840 	/** Set the base of the name of a segment (preserving the extension).
841 
842 		@param rTheBase  The new base.
843 
844 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
845 		if addressing the last segment.
846 
847 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
848 		hierarchical path does not denote an empty segment, but is ignored.
849 
850 		@param eMechanism  See the general discussion for set-methods.
851 
852 		@param eCharset  See the general discussion for set-methods.
853 
854 		@return  True if the base has successfully been modified (and the
855 		resulting URI is still valid).  If the path is not hierarchical, or
856 		the specified segment does not exist, false is returned.  If false is
857 		returned, the object is not modified.
858 	 */
859 	bool setBase(rtl::OUString const & rTheBase,
860 				 sal_Int32 nIndex = LAST_SEGMENT,
861 				 bool bIgnoreFinalSlash = true,
862 				 EncodeMechanism eMechanism = WAS_ENCODED,
863 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
864 
865 	/** Determine whether the name of a segment has an extension.
866 
867 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
868 		if addressing the last segment.
869 
870 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
871 		hierarchical path does not denote an empty segment, but is ignored.
872 
873 		@return  True if the name of the specified segment has an extension.
874 		If the path is not hierarchical, or the specified segment does not
875 		exist, false is returned.
876 	 */
877 	bool hasExtension(sal_Int32 nIndex = LAST_SEGMENT,
878 					  bool bIgnoreFinalSlash = true) const;
879 
880 	/** Get the extension of the name of a segment.
881 
882 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
883 		if addressing the last segment.
884 
885 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
886 		hierarchical path does not denote an empty segment, but is ignored.
887 
888 		@param eMechanism  See the general discussion for get-methods.
889 
890 		@param eCharset  See the general discussion for get-methods.
891 
892 		@return  The extension part of the specified segment.  If the path is
893 		not hierarchical, or the specified segment does not exits, an empty
894 		string is returned.
895 	 */
896 	rtl::OUString getExtension(sal_Int32 nIndex = LAST_SEGMENT,
897 						   bool bIgnoreFinalSlash = true,
898 						   DecodeMechanism eMechanism = DECODE_TO_IURI,
899 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
900 		const;
901 
902 	/** Set the extension of the name of a segment (replacing an already
903 		existing extension).
904 
905 		@param rTheExtension  The new extension.
906 
907 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
908 		if addressing the last segment.
909 
910 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
911 		hierarchical path does not denote an empty segment, but is ignored.
912 
913 		@param eMechanism  See the general discussion for set-methods.
914 
915 		@param eCharset  See the general discussion for set-methods.
916 
917 		@return  True if the extension has successfully been modified (and the
918 		resulting URI is still valid).  If the path is not hierarchical, or
919 		the specified segment does not exist, false is returned.  If false is
920 		returned, the object is not modified.
921 	 */
922 	bool setExtension(rtl::OUString const & rTheExtension,
923 					  sal_Int32 nIndex = LAST_SEGMENT,
924 					  bool bIgnoreFinalSlash = true,
925 					  EncodeMechanism eMechanism = WAS_ENCODED,
926 					  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
927 
928 	/** Remove the extension of the name of a segment.
929 
930 		@param nIndex  The non-negative index of the segment, or LAST_SEGMENT
931 		if addressing the last segment.
932 
933 		@param bIgnoreFinalSlash  If true, a final slash at the end of the
934 		hierarchical path does not denote an empty segment, but is ignored.
935 
936 		@return  True if the extension has successfully been removed (and the
937 		resulting URI is still valid), or if the name did not have an
938 		extension.  If the path is not hierarchical, or the specified segment
939 		does not exist, false is returned.  If false is returned, the object
940 		is not modified.
941 	 */
942 	bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
943 						 bool bIgnoreFinalSlash = true);
944 
945 	/** Determine whether the hierarchical path ends in a final slash.
946 
947 		@return  True if the hierarchical path ends in a final slash.  If the
948 		path is not hierarchical, false is returned.
949 	 */
950 	bool hasFinalSlash() const;
951 
952 	/** Make the hierarchical path end in a final slash (if it does not
953 		already do so).
954 
955 		@return  True if a final slash has successfully been appended (and the
956 		resulting URI is still valid), or if the hierarchical path already
957 		ended in a final slash.  If the path is not hierarchical, false is
958 		returned.  If false is returned, the object is not modified.
959 	 */
960 	bool setFinalSlash();
961 
962 	/** Remove a final slash from the hierarchical path.
963 
964 		@return  True if a final slash has successfully been removed (and the
965 		resulting URI is still valid), or if the hierarchical path already did
966 		not end in a final slash.  If the path is not hierarchical, false is
967 		returned.  If false is returned, the object is not modified.
968 	 */
969 	bool removeFinalSlash();
970 
971 	//========================================================================
972 	// Query:
973 
HasParam() const974 	inline bool HasParam() const { return m_aQuery.isPresent(); }
975 
GetParam(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const976 	inline rtl::OUString GetParam(DecodeMechanism eMechanism = DECODE_TO_IURI,
977 							  rtl_TextEncoding eCharset
978 							      = RTL_TEXTENCODING_UTF8) const
979 	{ return decode(m_aQuery, getEscapePrefix(), eMechanism, eCharset); }
980 
981 	inline bool SetParam(ByteString const & rTheQuery,
982 						 EncodeMechanism eMechanism = WAS_ENCODED,
983 						 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
984 
985 	inline bool SetParam(rtl::OUString const & rTheQuery,
986 						 EncodeMechanism eMechanism = WAS_ENCODED,
987 						 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
988 
989 	//========================================================================
990 	// Fragment:
991 
HasMark() const992 	inline bool HasMark() const { return m_aFragment.isPresent(); }
993 
GetMark(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const994 	inline rtl::OUString GetMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
995 							 rtl_TextEncoding eCharset
996 							     = RTL_TEXTENCODING_UTF8) const
997 	{ return decode(m_aFragment, getEscapePrefix(), eMechanism, eCharset); }
998 
999 	inline bool SetMark(ByteString const & rTheFragment,
1000 						EncodeMechanism eMechanism = WAS_ENCODED,
1001 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1002 
1003 	inline bool SetMark(rtl::OUString const & rTheFragment,
1004 						EncodeMechanism eMechanism = WAS_ENCODED,
1005 						rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1006 
1007 	static rtl::OUString createFragment(rtl::OUString const & rText);
1008 
1009 	//========================================================================
1010 	// File URLs:
1011 
1012 	/** Create an INetURLObject from a file system path.
1013 
1014 		@param rFSysPath  A file system path.  An URL is not allowed here!
1015 
1016 		@param eStyle  The notation of rFSysPath.
1017 	 */
1018 	inline INetURLObject(rtl::OUString const & rFSysPath, FSysStyle eStyle);
1019 
1020 	/** Set this INetURLObject to a file URL constructed from a file system
1021 		path.
1022 
1023 		@param rFSysPath  A file system path.  An URL is not allowed here!
1024 
1025 		@param eStyle  The notation of rFSysPath.
1026 
1027 		@return  True if this INetURLObject has successfully been changed.  If
1028 		false is returned, this INetURLObject has not been modified.
1029 	 */
1030 	bool setFSysPath(rtl::OUString const & rFSysPath, FSysStyle eStyle);
1031 
1032 	/** Return the file system path represented by a file URL (ignoring any
1033 		fragment part).
1034 
1035 		@param eStyle  The notation of the returned file system path.
1036 
1037 		@param pDelimiter  Upon successful return, this parameter can return
1038 		the character that is the 'main' delimiter within the returned file
1039 		system path (e.g., "/" for Unix, "\" for DOS, ":" for Mac).  This is
1040 		especially useful for routines that later try to shorten the returned
1041 		file system path at a 'good' position, e.g. to fit it into some
1042 		limited display space.
1043 
1044 		@return  The file system path represented by this file URL.  If this
1045 		file URL does not represent a file system path according to the
1046 		specified notation, or if this is not a file URL at all, an empty
1047 		string is returned.
1048 	 */
1049 	rtl::OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
1050 		const;
1051 
1052 	//========================================================================
1053 	// POP3 and URLs:
1054 
1055 	bool HasMsgId() const;
1056 
1057 	rtl::OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
1058 					   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1059 		const;
1060 
1061 	//========================================================================
1062 	// Coding:
1063 
1064 	enum Part
1065 	{
1066 		PART_OBSOLETE_NORMAL = 0x001, // Obsolete, do not use!
1067 		PART_OBSOLETE_FILE = 0x002, // Obsolete, do not use!
1068 		PART_OBSOLETE_PARAM = 0x004, // Obsolete, do not use!
1069 		PART_USER_PASSWORD = 0x008,
1070 		PART_IMAP_ACHAR = 0x010,
1071 		PART_VIM = 0x020,
1072 		PART_HOST_EXTRA = 0x040,
1073 		PART_FPATH = 0x080,
1074 		PART_AUTHORITY = 0x100,
1075 		PART_PATH_SEGMENTS_EXTRA = 0x200,
1076 		PART_REL_SEGMENT_EXTRA = 0x400,
1077 		PART_URIC = 0x800,
1078 		PART_HTTP_PATH = 0x1000,
1079 		PART_FILE_SEGMENT_EXTRA = 0x2000, // Obsolete, do not use!
1080 		PART_MESSAGE_ID = 0x4000,
1081 		PART_MESSAGE_ID_PATH = 0x8000,
1082 		PART_MAILTO = 0x10000,
1083 		PART_PATH_BEFORE_QUERY = 0x20000,
1084 		PART_PCHAR = 0x40000,
1085 		PART_FRAGMENT = 0x80000, // Obsolete, do not use!
1086 		PART_VISIBLE = 0x100000,
1087 		PART_VISIBLE_NONSPECIAL = 0x200000,
1088 		PART_CREATEFRAGMENT = 0x400000,
1089 		PART_UNO_PARAM_VALUE = 0x800000,
1090 		PART_UNAMBIGUOUS = 0x1000000,
1091 		PART_URIC_NO_SLASH = 0x2000000,
1092         PART_HTTP_QUERY = 0x4000000, //TODO! unused?
1093         PART_NEWS_ARTICLE_LOCALPART = 0x8000000,
1094 		max_part = 0x80000000
1095 			// Do not use!  Only there to allow compatible changes in the
1096 			// future.
1097 	};
1098 
1099 	enum EscapeType
1100 	{
1101 		ESCAPE_NO,
1102 		ESCAPE_OCTET,
1103 		ESCAPE_UTF32
1104 	};
1105 
1106 	/** Encode some text as part of a URI.
1107 
1108 		@param rText  Some text (for its interpretation, see the general
1109 		discussion for set-methods).
1110 
1111 		@param ePart  The part says which characters are 'forbidden' and must
1112 		be encoded (replaced by escape sequences).  Characters outside the US-
1113 		ASCII range are always 'forbidden.'
1114 
1115 		@param cEscapePrefix  The first character in an escape sequence
1116 		(normally '%').
1117 
1118 		@param eMechanism  See the general discussion for set-methods.
1119 
1120 		@param eCharset  See the general discussion for set-methods.
1121 
1122 		@return  The encoded representation of the text ('forbidden'
1123 		characters replaced by escape sequences).
1124 	 */
1125 	static inline rtl::OUString encode(ByteString const & rText, Part ePart,
1126 								   sal_Char cEscapePrefix,
1127 								   EncodeMechanism eMechanism,
1128 								   rtl_TextEncoding eCharset
1129 								       = RTL_TEXTENCODING_UTF8);
1130 
1131 	/** Encode some text as part of a URI.
1132 
1133 		@param rText  Some text (for its interpretation, see the general
1134 		discussion for set-methods).
1135 
1136 		@param ePart  The part says which characters are 'forbidden' and must
1137 		be encoded (replaced by escape sequences).  Characters outside the US-
1138 		ASCII range are always 'forbidden.'
1139 
1140 		@param cEscapePrefix  The first character in an escape sequence
1141 		(normally '%').
1142 
1143 		@param eMechanism  See the general discussion for set-methods.
1144 
1145 		@param eCharset  See the general discussion for set-methods.
1146 
1147 		@return  The text, encoded according to the given mechanism and
1148 		charset ('forbidden' characters replaced by escape sequences).
1149 	 */
1150 	static inline rtl::OUString encode(rtl::OUString const & rText, Part ePart,
1151 								   sal_Char cEscapePrefix,
1152 								   EncodeMechanism eMechanism,
1153 								   rtl_TextEncoding eCharset
1154 								       = RTL_TEXTENCODING_UTF8);
1155 
1156 	/** Decode some text.
1157 
1158 		@param rText  Some (encoded) text.
1159 
1160 		@param cEscapePrefix  The first character in an escape sequence
1161 		(normally '%').
1162 
1163 		@param eMechanism  See the general discussion for get-methods.
1164 
1165 		@param eCharset  See the general discussion for get-methods.
1166 
1167 		@return  The text, decoded according to the given mechanism and
1168 		charset (escape sequences replaced by 'raw' characters).
1169 	 */
1170 	static inline rtl::OUString decode(rtl::OUString const & rText,
1171 								   sal_Char cEscapePrefix,
1172 								   DecodeMechanism eMechanism,
1173 								   rtl_TextEncoding eCharset
1174 								       = RTL_TEXTENCODING_UTF8);
1175 
1176 	static inline rtl::OUString decode(rtl::OUStringBuffer const & rText,
1177 								   sal_Char cEscapePrefix,
1178 								   DecodeMechanism eMechanism,
1179 								   rtl_TextEncoding eCharset
1180 								       = RTL_TEXTENCODING_UTF8);
1181 
1182 	static void appendUCS4Escape(rtl::OUStringBuffer & rTheText,
1183 								 sal_Char cEscapePrefix,
1184 								 sal_uInt32 nUCS4);
1185 
1186 	static void appendUCS4(rtl::OUStringBuffer & rTheText, sal_uInt32 nUCS4,
1187 						   EscapeType eEscapeType, bool bOctets, Part ePart,
1188 						   sal_Char cEscapePrefix, rtl_TextEncoding eCharset,
1189 						   bool bKeepVisibleEscapes);
1190 
1191 	static sal_uInt32 getUTF32(sal_Unicode const *& rBegin,
1192 							   sal_Unicode const * pEnd, bool bOctets,
1193 							   sal_Char cEscapePrefix,
1194 							   EncodeMechanism eMechanism,
1195 							   rtl_TextEncoding eCharset,
1196 							   EscapeType & rEscapeType);
1197 
1198 	//========================================================================
1199 	// Specialized helpers:
1200 
1201 	static sal_uInt32 scanDomain(sal_Unicode const *& rBegin,
1202 								 sal_Unicode const * pEnd,
1203 								 bool bEager = true);
1204 
1205 	//========================================================================
1206 	// OBSOLETE Hierarchical Path:
1207 
1208 	rtl::OUString GetPartBeforeLastName(DecodeMechanism eMechanism
1209 									    = DECODE_TO_IURI,
1210 									rtl_TextEncoding eCharset
1211 									    = RTL_TEXTENCODING_UTF8) const;
1212 
1213 	/** Get the last segment in the path.
1214 
1215 		@param eMechanism  See the general discussion for get-methods.
1216 
1217 		@param eCharset  See the general discussion for get-methods.
1218 
1219 		@return  For a hierarchical URL, the last segment (everything after
1220 		the last unencoded '/').  Not that this last segment may be empty.  If
1221 		the URL is not hierarchical, an empty string is returned.
1222 	 */
1223 	rtl::OUString GetLastName(DecodeMechanism eMechanism = DECODE_TO_IURI,
1224 						  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1225 		const;
1226 
1227 	/** Get the 'extension' of the last segment in the path.
1228 
1229 		@param eMechanism  See the general discussion for get-methods.
1230 
1231 		@param eCharset  See the general discussion for get-methods.
1232 
1233 		@return  For a hierarchical URL, everything after the first unencoded
1234 		'.' in the last segment of the path.  Note that this 'extension' may
1235 		be empty.  If the URL is not hierarchical, or if the last segment does
1236 		not contain an unencoded '.', an empty string is returned.
1237 	 */
1238 	rtl::OUString GetFileExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
1239 							   rtl_TextEncoding eCharset
1240 							       = RTL_TEXTENCODING_UTF8) const;
1241 
Append(ByteString const & rTheSegment,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)1242 	inline bool Append(ByteString const & rTheSegment,
1243 					   EncodeMechanism eMechanism = WAS_ENCODED,
1244 					   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1245 	{ return appendSegment(extend(rTheSegment), true, eMechanism, eCharset); }
1246 
Append(rtl::OUString const & rTheSegment,EncodeMechanism eMechanism=WAS_ENCODED,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)1247 	inline bool Append(rtl::OUString const & rTheSegment,
1248 					   EncodeMechanism eMechanism = WAS_ENCODED,
1249 					   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
1250 	{ return appendSegment(rTheSegment, false, eMechanism, eCharset); }
1251 
1252 	bool CutLastName();
1253 
1254 	//========================================================================
1255 	// OBSOLETE File URLs:
1256 
1257 	rtl::OUString PathToFileName() const;
1258 
1259 	rtl::OUString GetFull() const;
1260 
1261 	rtl::OUString GetPath() const;
1262 
1263 	void SetBase(rtl::OUString const & rTheBase);
1264 
1265 	rtl::OUString GetBase() const;
1266 
1267 	void SetName(rtl::OUString const & rTheName,
1268 				 EncodeMechanism eMechanism = WAS_ENCODED,
1269 				 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1270 
GetName(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const1271 	inline rtl::OUString GetName(DecodeMechanism eMechanism = DECODE_TO_IURI,
1272 							 rtl_TextEncoding eCharset
1273 							     = RTL_TEXTENCODING_UTF8) const
1274 	{ return GetLastName(eMechanism, eCharset); }
1275 
1276 	rtl::OUString CutName(DecodeMechanism eMechanism = DECODE_TO_IURI,
1277 					  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1278 
1279 	void SetExtension(rtl::OUString const & rTheExtension,
1280 					  EncodeMechanism eMechanism = WAS_ENCODED,
1281 					  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1282 
GetExtension(DecodeMechanism eMechanism=DECODE_TO_IURI,rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const1283 	inline rtl::OUString GetExtension(
1284 								  DecodeMechanism eMechanism = DECODE_TO_IURI,
1285 								  rtl_TextEncoding eCharset
1286 								      = RTL_TEXTENCODING_UTF8) const
1287 	{ return GetFileExtension(eMechanism, eCharset); }
1288 
1289 	rtl::OUString CutExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
1290 						   rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
1291 
1292 	bool IsCaseSensitive() const;
1293 
1294 	//========================================================================
1295 
1296 private:
1297 	// General Structure:
1298 
1299 	class SubString
1300 	{
1301 		sal_Int32 m_nBegin;
1302 		sal_Int32 m_nLength;
1303 
1304 	public:
SubString(sal_Int32 nTheBegin=-1,sal_Int32 nTheLength=0)1305 		explicit inline SubString(sal_Int32 nTheBegin = -1,
1306 								  sal_Int32 nTheLength = 0):
1307 			m_nBegin(nTheBegin), m_nLength(nTheLength) {}
1308 
isPresent() const1309 		inline bool isPresent() const { return m_nBegin != -1; }
1310 
isEmpty() const1311 		inline bool isEmpty() const { return m_nLength == 0; }
1312 
getBegin() const1313 		inline sal_Int32 getBegin() const { return m_nBegin; }
1314 
getLength() const1315 		inline sal_Int32 getLength() const { return m_nLength; }
1316 
getEnd() const1317 		inline sal_Int32 getEnd() const { return m_nBegin + m_nLength; }
1318 
1319 		inline sal_Int32 clear();
1320 
1321 		inline sal_Int32 set(rtl::OUStringBuffer & rString,
1322 						     rtl::OUString const & rSubString,
1323 						     sal_Int32 nTheBegin);
1324 
1325 		inline sal_Int32 set(rtl::OUString & rString,
1326 						     rtl::OUString const & rSubString);
1327 
1328 		inline sal_Int32 set(rtl::OUStringBuffer & rString,
1329 						     rtl::OUString const & rSubString);
1330 
1331 		inline void operator +=(sal_Int32 nDelta);
1332 
1333 		int compare(SubString const & rOther,
1334 			rtl::OUStringBuffer const & rThisString,
1335 			rtl::OUStringBuffer const & rOtherString) const;
1336 	};
1337 
1338 	rtl::OUStringBuffer m_aAbsURIRef;
1339 	SubString m_aScheme;
1340 	SubString m_aUser;
1341 	SubString m_aAuth;
1342 	SubString m_aHost;
1343 	SubString m_aPort;
1344 	SubString m_aPath;
1345 	SubString m_aQuery;
1346 	SubString m_aFragment;
1347 	INetProtocol m_eScheme;
1348 	INetProtocol m_eSmartScheme;
1349 
1350     TOOLS_DLLPRIVATE void setInvalid();
1351 
1352     bool setAbsURIRef(
1353         rtl::OUString const & rTheAbsURIRef, bool bOctets,
1354         EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart,
1355         FSysStyle eStyle);
1356 
1357     // Relative URLs:
1358 
1359     bool convertRelToAbs(
1360         rtl::OUString const & rTheRelURIRef, bool bOctets,
1361         INetURLObject & rTheAbsURIRef, bool & rWasAbsolute,
1362         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1363         bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs,
1364         FSysStyle eStyle) const;
1365 
1366     bool convertAbsToRel(
1367         rtl::OUString const & rTheAbsURIRef, bool bOctets,
1368         rtl::OUString & rTheRelURIRef, EncodeMechanism eEncodeMechanism,
1369         DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset,
1370         FSysStyle eStyle) const;
1371 
1372     // External URLs:
1373 
1374     static bool convertIntToExt(
1375         rtl::OUString const & rTheIntURIRef, bool bOctets,
1376         rtl::OUString & rTheExtURIRef, DecodeMechanism eDecodeMechanism,
1377         rtl_TextEncoding eCharset);
1378 
1379     static bool convertExtToInt(
1380         rtl::OUString const & rTheExtURIRef, bool bOctets,
1381         rtl::OUString & rTheIntURIRef, DecodeMechanism eDecodeMechanism,
1382         rtl_TextEncoding eCharset);
1383 
1384     // Scheme:
1385 
1386     struct PrefixInfo;
1387 
1388     TOOLS_DLLPRIVATE static inline SchemeInfo const & getSchemeInfo(
1389         INetProtocol eTheScheme);
1390 
1391     TOOLS_DLLPRIVATE inline SchemeInfo const & getSchemeInfo() const;
1392 
1393     TOOLS_DLLPRIVATE static PrefixInfo const * getPrefix(
1394         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1395 
1396     // Authority:
1397 
1398     TOOLS_DLLPRIVATE sal_Int32 getAuthorityBegin() const;
1399 
1400     TOOLS_DLLPRIVATE SubString getAuthority() const;
1401 
1402     // User Info:
1403 
1404     bool setUser(
1405         rtl::OUString const & rTheUser, bool bOctets,
1406         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1407 
1408     bool clearPassword();
1409 
1410     bool setPassword(
1411         rtl::OUString const & rThePassword, bool bOctets,
1412         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1413 
1414     // Host and Port:
1415 
1416     TOOLS_DLLPRIVATE static bool parseHost(
1417         sal_Unicode const *& rBegin, sal_Unicode const * pEnd,
1418         rtl::OUString & rCanonic);
1419 
1420     TOOLS_DLLPRIVATE static bool parseHostOrNetBiosName(
1421         sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
1422         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
1423         bool bNetBiosName, rtl::OUStringBuffer* pCanonic);
1424 
1425     static rtl::OUString encodeHostPort(
1426         rtl::OUString const & rTheHostPort, bool bOctets,
1427         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1428 
1429     bool setHost(
1430         rtl::OUString const & rTheHost, bool bOctets,
1431         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1432 
1433     // Path:
1434 
1435     TOOLS_DLLPRIVATE static bool parsePath(
1436         INetProtocol eScheme, sal_Unicode const ** pBegin,
1437         sal_Unicode const * pEnd, bool bOctets, EncodeMechanism eMechanism,
1438         rtl_TextEncoding eCharset, bool bSkippedInitialSlash,
1439         sal_uInt32 nSegmentDelimiter, sal_uInt32 nAltSegmentDelimiter,
1440         sal_uInt32 nQueryDelimiter, sal_uInt32 nFragmentDelimiter,
1441         rtl::OUStringBuffer &rSynPath);
1442 
1443     bool setPath(
1444         rtl::OUString const & rThePath, bool bOctets,
1445         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1446 
1447     // Hierarchical Path:
1448 
1449     TOOLS_DLLPRIVATE bool checkHierarchical() const;
1450 
1451     bool appendSegment(
1452         rtl::OUString const & rTheSegment, bool bOctets,
1453         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1454 
1455     TOOLS_DLLPRIVATE SubString getSegment(
1456         sal_Int32 nIndex, bool bIgnoreFinalSlash) const;
1457 
1458     bool insertName(
1459         rtl::OUString const & rTheName, bool bOctets, bool bAppendFinalSlash,
1460         sal_Int32 nIndex, bool bIgnoreFinalSlash, EncodeMechanism eMechanism,
1461         rtl_TextEncoding eCharset);
1462 
1463     // Query:
1464 
1465     bool clearQuery();
1466 
1467     bool setQuery(
1468         rtl::OUString const & rTheQuery, bool bOctets,
1469         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1470 
1471     // Fragment:
1472 
1473     bool clearFragment();
1474 
1475     bool setFragment(
1476         rtl::OUString const & rTheMark, bool bOctets,
1477         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
1478 
1479     // FTP URLs:
1480 
1481     enum FTPType { FTP_TYPE_NONE, FTP_TYPE_A, FTP_TYPE_I, FTP_TYPE_D };
1482 
1483     TOOLS_DLLPRIVATE FTPType getFTPType() const;
1484 
1485     // FILE URLs:
1486 
1487     TOOLS_DLLPRIVATE bool hasDosVolume(FSysStyle eStyle) const;
1488 
1489     // IMAP URLs:
1490 
1491     TOOLS_DLLPRIVATE sal_uInt32 getIMAPUID() const;
1492 
1493     // Coding:
1494 
extend(ByteString const & rOctets)1495     static inline rtl::OUString extend(ByteString const & rOctets)
1496     {
1497         return rtl::OUString(rOctets.GetBuffer(), rOctets.Len(),
1498             RTL_TEXTENCODING_ISO_8859_1);
1499     }
1500 
getEscapePrefix(INetProtocol eTheScheme)1501     static inline sal_Char getEscapePrefix(INetProtocol eTheScheme)
1502     { return eTheScheme == INET_PROT_VIM ? '=' : '%'; }
1503 
getEscapePrefix() const1504     inline sal_Char getEscapePrefix() const
1505     { return getEscapePrefix(m_eScheme); }
1506 
1507     TOOLS_DLLPRIVATE static inline void appendEscape(
1508         rtl::OUStringBuffer & rTheText, sal_Char cEscapePrefix,
1509         sal_uInt32 nOctet);
1510 
1511     static rtl::OUString encodeText(
1512         sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
1513         Part ePart, sal_Char cEscapePrefix, EncodeMechanism eMechanism,
1514         rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
1515 
1516     static inline rtl::OUString encodeText(
1517         rtl::OUString const & rTheText, bool bOctets, Part ePart,
1518         sal_Char cEscapePrefix, EncodeMechanism eMechanism,
1519         rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
1520 
1521     static rtl::OUString decode(
1522         sal_Unicode const * pBegin, sal_Unicode const * pEnd,
1523         sal_Char cEscapePrefix, DecodeMechanism, rtl_TextEncoding eCharset);
1524 
1525     inline rtl::OUString decode(
1526         SubString const & rSubString, sal_Char cEscapePrefix,
1527         DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const;
1528 
1529     // Specialized helpers:
1530 
1531     TOOLS_DLLPRIVATE static bool scanIPv6reference(
1532         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
1533 };
1534 
1535 // static
encodeText(rtl::OUString const & rTheText,bool bOctets,Part ePart,sal_Char cEscapePrefix,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,bool bKeepVisibleEscapes)1536 inline rtl::OUString INetURLObject::encodeText(rtl::OUString const & rTheText,
1537 										   bool bOctets, Part ePart,
1538 										   sal_Char cEscapePrefix,
1539 										   EncodeMechanism eMechanism,
1540 										   rtl_TextEncoding eCharset,
1541 										   bool bKeepVisibleEscapes)
1542 {
1543 	return encodeText(rTheText.getStr(),
1544 					  rTheText.getStr() + rTheText.getLength(), bOctets, ePart,
1545 					  cEscapePrefix, eMechanism, eCharset,
1546 					  bKeepVisibleEscapes);
1547 }
1548 
decode(SubString const & rSubString,sal_Char cEscapePrefix,DecodeMechanism eMechanism,rtl_TextEncoding eCharset) const1549 inline rtl::OUString INetURLObject::decode(SubString const & rSubString,
1550 									   sal_Char cEscapePrefix,
1551 									   DecodeMechanism eMechanism,
1552 									   rtl_TextEncoding eCharset) const
1553 {
1554     return rSubString.isPresent() ?
1555                decode(m_aAbsURIRef.getStr() + rSubString.getBegin(),
1556                       m_aAbsURIRef.getStr() + rSubString.getEnd(),
1557                       cEscapePrefix, eMechanism, eCharset) :
1558                rtl::OUString();
1559 }
1560 
INetURLObject(ByteString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1561 inline INetURLObject::INetURLObject(ByteString const & rTheAbsURIRef,
1562 									EncodeMechanism eMechanism,
1563 									rtl_TextEncoding eCharset):
1564 	m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1565 {
1566 	setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset, false,
1567 				 FSysStyle(0));
1568 }
1569 
INetURLObject(rtl::OUString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1570 inline INetURLObject::INetURLObject(rtl::OUString const & rTheAbsURIRef,
1571 									EncodeMechanism eMechanism,
1572 									rtl_TextEncoding eCharset):
1573 	m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1574 {
1575 	setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
1576 				 FSysStyle(0));
1577 }
1578 
SetURL(ByteString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1579 inline bool INetURLObject::SetURL(ByteString const & rTheAbsURIRef,
1580 								  EncodeMechanism eMechanism,
1581 								  rtl_TextEncoding eCharset)
1582 {
1583 	return setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset,
1584 						false, FSysStyle(0));
1585 }
1586 
SetURL(rtl::OUString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1587 inline bool INetURLObject::SetURL(rtl::OUString const & rTheAbsURIRef,
1588 								  EncodeMechanism eMechanism,
1589 								  rtl_TextEncoding eCharset)
1590 {
1591 	return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
1592 						FSysStyle(0));
1593 }
1594 
INetURLObject(rtl::OUString const & rTheAbsURIRef,INetProtocol eTheSmartScheme,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle)1595 inline INetURLObject::INetURLObject(rtl::OUString const & rTheAbsURIRef,
1596 									INetProtocol eTheSmartScheme,
1597 									EncodeMechanism eMechanism,
1598 									rtl_TextEncoding eCharset,
1599 									FSysStyle eStyle):
1600 	m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(eTheSmartScheme)
1601 {
1602 	setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true, eStyle);
1603 }
1604 
SetSmartURL(ByteString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle)1605 inline bool INetURLObject::SetSmartURL(ByteString const & rTheAbsURIRef,
1606 									   EncodeMechanism eMechanism,
1607 									   rtl_TextEncoding eCharset,
1608 									   FSysStyle eStyle)
1609 {
1610 	return setAbsURIRef(extend(rTheAbsURIRef), true, eMechanism, eCharset,
1611 						true, eStyle);
1612 }
1613 
SetSmartURL(rtl::OUString const & rTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle)1614 inline bool INetURLObject::SetSmartURL(rtl::OUString const & rTheAbsURIRef,
1615 									   EncodeMechanism eMechanism,
1616 									   rtl_TextEncoding eCharset,
1617 									   FSysStyle eStyle)
1618 {
1619 	return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true,
1620 						eStyle);
1621 }
1622 
1623 inline INetURLObject
smartRel2Abs(ByteString const & rTheRelURIRef,bool & rWasAbsolute,bool bIgnoreFragment,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,bool bRelativeNonURIs,FSysStyle eStyle) const1624 INetURLObject::smartRel2Abs(ByteString const & rTheRelURIRef,
1625 							bool & rWasAbsolute,
1626 							bool bIgnoreFragment,
1627 							EncodeMechanism eMechanism,
1628 							rtl_TextEncoding eCharset,
1629 							bool bRelativeNonURIs,
1630 							FSysStyle eStyle) const
1631 {
1632 	INetURLObject aTheAbsURIRef;
1633 	convertRelToAbs(extend(rTheRelURIRef), true, aTheAbsURIRef, rWasAbsolute,
1634 					eMechanism, eCharset, bIgnoreFragment, true,
1635 					bRelativeNonURIs, eStyle);
1636 	return aTheAbsURIRef;
1637 }
1638 
1639 inline INetURLObject
smartRel2Abs(rtl::OUString const & rTheRelURIRef,bool & rWasAbsolute,bool bIgnoreFragment,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,bool bRelativeNonURIs,FSysStyle eStyle) const1640 INetURLObject::smartRel2Abs(rtl::OUString const & rTheRelURIRef,
1641 							bool & rWasAbsolute,
1642 							bool bIgnoreFragment,
1643 							EncodeMechanism eMechanism,
1644 							rtl_TextEncoding eCharset,
1645 							bool bRelativeNonURIs,
1646 							FSysStyle eStyle) const
1647 {
1648 	INetURLObject aTheAbsURIRef;
1649 	convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, rWasAbsolute,
1650 					eMechanism, eCharset, bIgnoreFragment, true,
1651 					bRelativeNonURIs, eStyle);
1652 	return aTheAbsURIRef;
1653 }
1654 
GetNewAbsURL(ByteString const & rTheRelURIRef,INetURLObject * pTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle,bool bIgnoreFragment) const1655 inline bool INetURLObject::GetNewAbsURL(ByteString const & rTheRelURIRef,
1656 										INetURLObject * pTheAbsURIRef,
1657 										EncodeMechanism eMechanism,
1658 										rtl_TextEncoding eCharset,
1659 										FSysStyle eStyle, bool bIgnoreFragment)
1660     const
1661 {
1662 	INetURLObject aTheAbsURIRef;
1663 	bool bWasAbsolute;
1664 	if (!convertRelToAbs(extend(rTheRelURIRef), true, aTheAbsURIRef,
1665 						 bWasAbsolute, eMechanism, eCharset, bIgnoreFragment,
1666                          false, false, eStyle))
1667 		return false;
1668 	if (pTheAbsURIRef)
1669 		*pTheAbsURIRef = aTheAbsURIRef;
1670 	return true;
1671 }
1672 
GetNewAbsURL(rtl::OUString const & rTheRelURIRef,INetURLObject * pTheAbsURIRef,EncodeMechanism eMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle,bool bIgnoreFragment) const1673 inline bool INetURLObject::GetNewAbsURL(rtl::OUString const & rTheRelURIRef,
1674 										INetURLObject * pTheAbsURIRef,
1675 										EncodeMechanism eMechanism,
1676 										rtl_TextEncoding eCharset,
1677 										FSysStyle eStyle, bool bIgnoreFragment)
1678     const
1679 {
1680 	INetURLObject aTheAbsURIRef;
1681 	bool bWasAbsolute;
1682 	if (!convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, bWasAbsolute,
1683 						 eMechanism, eCharset, bIgnoreFragment, false, false,
1684                          eStyle))
1685 		return false;
1686 	if (pTheAbsURIRef)
1687 		*pTheAbsURIRef = aTheAbsURIRef;
1688 	return true;
1689 }
1690 
1691 // static
GetRelURL(ByteString const & rTheBaseURIRef,ByteString const & rTheAbsURIRef,EncodeMechanism eEncodeMechanism,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle)1692 inline rtl::OUString INetURLObject::GetRelURL(ByteString const & rTheBaseURIRef,
1693 										  ByteString const & rTheAbsURIRef,
1694 										  EncodeMechanism eEncodeMechanism,
1695 										  DecodeMechanism eDecodeMechanism,
1696 										  rtl_TextEncoding eCharset,
1697 										  FSysStyle eStyle)
1698 {
1699 	rtl::OUString aTheRelURIRef;
1700 	INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1701 		convertAbsToRel(extend(rTheAbsURIRef), true, aTheRelURIRef,
1702 						eEncodeMechanism, eDecodeMechanism, eCharset, eStyle);
1703 	return aTheRelURIRef;
1704 }
1705 
1706 // static
GetRelURL(rtl::OUString const & rTheBaseURIRef,rtl::OUString const & rTheAbsURIRef,EncodeMechanism eEncodeMechanism,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset,FSysStyle eStyle)1707 inline rtl::OUString INetURLObject::GetRelURL(rtl::OUString const & rTheBaseURIRef,
1708 										  rtl::OUString const & rTheAbsURIRef,
1709 										  EncodeMechanism eEncodeMechanism,
1710 										  DecodeMechanism eDecodeMechanism,
1711 										  rtl_TextEncoding eCharset,
1712 										  FSysStyle eStyle)
1713 {
1714 	rtl::OUString aTheRelURIRef;
1715 	INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
1716 		convertAbsToRel(rTheAbsURIRef, false, aTheRelURIRef, eEncodeMechanism,
1717 						eDecodeMechanism, eCharset, eStyle);
1718 	return aTheRelURIRef;
1719 }
1720 
1721 // static
translateToExternal(ByteString const & rTheIntURIRef,rtl::OUString & rTheExtURIRef,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset)1722 inline bool INetURLObject::translateToExternal(ByteString const &
1723 											       rTheIntURIRef,
1724 											   rtl::OUString & rTheExtURIRef,
1725 											   DecodeMechanism
1726 											       eDecodeMechanism,
1727 											   rtl_TextEncoding eCharset)
1728 {
1729 	rtl::OUString aTheExtURIRef;
1730 	bool bRet = convertIntToExt(extend(rTheIntURIRef), true, aTheExtURIRef,
1731                                 eDecodeMechanism, eCharset);
1732 	rTheExtURIRef = aTheExtURIRef;
1733 	return bRet;
1734 }
1735 
1736 // static
translateToExternal(rtl::OUString const & rTheIntURIRef,rtl::OUString & rTheExtURIRef,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset)1737 inline bool INetURLObject::translateToExternal(rtl::OUString const &
1738 											       rTheIntURIRef,
1739 											   rtl::OUString & rTheExtURIRef,
1740 											   DecodeMechanism
1741 											       eDecodeMechanism,
1742 											   rtl_TextEncoding eCharset)
1743 {
1744 	return convertIntToExt(rTheIntURIRef, false, rTheExtURIRef,
1745 						   eDecodeMechanism, eCharset);
1746 }
1747 
1748 // static
translateToInternal(ByteString const & rTheExtURIRef,rtl::OUString & rTheIntURIRef,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset)1749 inline bool INetURLObject::translateToInternal(ByteString const &
1750 											       rTheExtURIRef,
1751 											   rtl::OUString & rTheIntURIRef,
1752 											   DecodeMechanism
1753 											       eDecodeMechanism,
1754 											   rtl_TextEncoding eCharset)
1755 {
1756 	rtl::OUString aTheIntURIRef;
1757 	bool bRet = convertExtToInt(extend(rTheExtURIRef), true, aTheIntURIRef,
1758 						   eDecodeMechanism, eCharset);
1759 	rTheIntURIRef = aTheIntURIRef;
1760 	return bRet;
1761 }
1762 
1763 // static
translateToInternal(rtl::OUString const & rTheExtURIRef,rtl::OUString & rTheIntURIRef,DecodeMechanism eDecodeMechanism,rtl_TextEncoding eCharset)1764 inline bool INetURLObject::translateToInternal(rtl::OUString const &
1765                                                    rTheExtURIRef,
1766                                                rtl::OUString & rTheIntURIRef,
1767                                                DecodeMechanism
1768                                                    eDecodeMechanism,
1769                                                rtl_TextEncoding eCharset)
1770 {
1771     return convertExtToInt(rTheExtURIRef, false, rTheIntURIRef,
1772                            eDecodeMechanism, eCharset);
1773 }
1774 
SetPass(ByteString const & rThePassword,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1775 inline bool INetURLObject::SetPass(ByteString const & rThePassword,
1776 								   EncodeMechanism eMechanism,
1777 								   rtl_TextEncoding eCharset)
1778 {
1779 	return rThePassword.Len() == 0 ?
1780 		       clearPassword() :
1781 		       setPassword(extend(rThePassword), true, eMechanism, eCharset);
1782 }
1783 
SetPass(rtl::OUString const & rThePassword,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1784 inline bool INetURLObject::SetPass(rtl::OUString const & rThePassword,
1785 								   EncodeMechanism eMechanism,
1786 								   rtl_TextEncoding eCharset)
1787 {
1788 	return rThePassword.getLength() == 0 ?
1789 		       clearPassword() :
1790 		       setPassword(rThePassword, false, eMechanism, eCharset);
1791 }
1792 
SetUserAndPass(ByteString const & rTheUser,ByteString const & rThePassword,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1793 inline bool INetURLObject::SetUserAndPass(ByteString const & rTheUser,
1794 										  ByteString const & rThePassword,
1795 										  EncodeMechanism eMechanism,
1796 										  rtl_TextEncoding eCharset)
1797 {
1798 	return setUser(extend(rTheUser), true, eMechanism, eCharset)
1799 		   && (rThePassword.Len() == 0 ?
1800 			       clearPassword() :
1801 			       setPassword(extend(rThePassword), true, eMechanism,
1802 							   eCharset));
1803 }
1804 
SetUserAndPass(rtl::OUString const & rTheUser,rtl::OUString const & rThePassword,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1805 inline bool INetURLObject::SetUserAndPass(rtl::OUString const & rTheUser,
1806 										  rtl::OUString const & rThePassword,
1807 										  EncodeMechanism eMechanism,
1808 										  rtl_TextEncoding eCharset)
1809 {
1810 	return setUser(rTheUser, false, eMechanism, eCharset)
1811 		   && (rThePassword.getLength() == 0 ?
1812 			       clearPassword() :
1813 			       setPassword(rThePassword, false, eMechanism, eCharset));
1814 }
1815 
1816 // static
encodeHostPort(ByteString const & rTheHostPort,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1817 inline rtl::OUString INetURLObject::encodeHostPort(ByteString const &
1818 											       rTheHostPort,
1819 											   EncodeMechanism eMechanism,
1820 											   rtl_TextEncoding eCharset)
1821 {
1822 	return encodeHostPort(extend(rTheHostPort), true, eMechanism, eCharset);
1823 }
1824 
insertName(rtl::OUString const & rTheName,bool bAppendFinalSlash,sal_Int32 nIndex,bool bIgnoreFinalSlash,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1825 inline bool INetURLObject::insertName(rtl::OUString const & rTheName,
1826 									  bool bAppendFinalSlash,
1827 									  sal_Int32 nIndex,
1828 									  bool bIgnoreFinalSlash,
1829 									  EncodeMechanism eMechanism,
1830 									  rtl_TextEncoding eCharset)
1831 {
1832 	return insertName(rTheName, false, bAppendFinalSlash, nIndex,
1833 					  bIgnoreFinalSlash, eMechanism, eCharset);
1834 }
1835 
SetParam(ByteString const & rTheQuery,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1836 inline bool INetURLObject::SetParam(ByteString const & rTheQuery,
1837 									EncodeMechanism eMechanism,
1838 									rtl_TextEncoding eCharset)
1839 {
1840 	return rTheQuery.Len() == 0 ?
1841 		       clearQuery() :
1842 		       setQuery(extend(rTheQuery), true, eMechanism, eCharset);
1843 }
1844 
SetParam(rtl::OUString const & rTheQuery,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1845 inline bool INetURLObject::SetParam(rtl::OUString const & rTheQuery,
1846 									EncodeMechanism eMechanism,
1847 									rtl_TextEncoding eCharset)
1848 {
1849 	return rTheQuery.getLength() == 0 ?
1850 		       clearQuery() :
1851 		       setQuery(rTheQuery, false, eMechanism, eCharset);
1852 }
1853 
SetMark(ByteString const & rTheFragment,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1854 inline bool INetURLObject::SetMark(ByteString const & rTheFragment,
1855 								   EncodeMechanism eMechanism,
1856 								   rtl_TextEncoding eCharset)
1857 {
1858 	return rTheFragment.Len() == 0 ?
1859 		       clearFragment() :
1860 		       setFragment(extend(rTheFragment), true, eMechanism, eCharset);
1861 }
1862 
SetMark(rtl::OUString const & rTheFragment,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1863 inline bool INetURLObject::SetMark(rtl::OUString const & rTheFragment,
1864 								   EncodeMechanism eMechanism,
1865 								   rtl_TextEncoding eCharset)
1866 {
1867 	return rTheFragment.getLength() == 0 ?
1868 		       clearFragment() :
1869 		       setFragment(rTheFragment, false, eMechanism, eCharset);
1870 }
1871 
INetURLObject(rtl::OUString const & rFSysPath,FSysStyle eStyle)1872 inline INetURLObject::INetURLObject(rtl::OUString const & rFSysPath,
1873 									FSysStyle eStyle):
1874 	m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
1875 {
1876 	setFSysPath(rFSysPath, eStyle);
1877 }
1878 
1879 // static
encode(ByteString const & rText,Part ePart,sal_Char cEscapePrefix,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1880 inline rtl::OUString INetURLObject::encode(ByteString const & rText, Part ePart,
1881 									   sal_Char cEscapePrefix,
1882 									   EncodeMechanism eMechanism,
1883 									   rtl_TextEncoding eCharset)
1884 {
1885 	return encodeText(extend(rText), true, ePart, cEscapePrefix, eMechanism,
1886 					  eCharset, false);
1887 }
1888 
1889 // static
encode(rtl::OUString const & rText,Part ePart,sal_Char cEscapePrefix,EncodeMechanism eMechanism,rtl_TextEncoding eCharset)1890 inline rtl::OUString INetURLObject::encode(rtl::OUString const & rText, Part ePart,
1891 									   sal_Char cEscapePrefix,
1892 									   EncodeMechanism eMechanism,
1893 									   rtl_TextEncoding eCharset)
1894 {
1895 	return encodeText(rText, false, ePart, cEscapePrefix, eMechanism,
1896 					  eCharset, false);
1897 }
1898 
1899 // static
decode(rtl::OUString const & rText,sal_Char cEscapePrefix,DecodeMechanism eMechanism,rtl_TextEncoding eCharset)1900 inline rtl::OUString INetURLObject::decode(rtl::OUString const & rText,
1901 									   sal_Char cEscapePrefix,
1902 									   DecodeMechanism eMechanism,
1903 									   rtl_TextEncoding eCharset)
1904 {
1905 	return decode(rText.getStr(), rText.getStr() + rText.getLength(),
1906 				  cEscapePrefix, eMechanism, eCharset);
1907 }
1908 
decode(rtl::OUStringBuffer const & rText,sal_Char cEscapePrefix,DecodeMechanism eMechanism,rtl_TextEncoding eCharset)1909 inline rtl::OUString INetURLObject::decode(rtl::OUStringBuffer const & rText,
1910 									   sal_Char cEscapePrefix,
1911 									   DecodeMechanism eMechanism,
1912 									   rtl_TextEncoding eCharset)
1913 {
1914 	return decode(rText.getStr(), rText.getStr() + rText.getLength(),
1915 				  cEscapePrefix, eMechanism, eCharset);
1916 }
1917 
1918 #endif // _URLOBJ_HXX
1919