LCOV - code coverage report
Current view: top level - include/tools - urlobj.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 98 119 82.4 %
Date: 2014-11-03 Functions: 49 56 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef INCLUDED_TOOLS_URLOBJ_HXX
      20             : #define INCLUDED_TOOLS_URLOBJ_HXX
      21             : 
      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>
      28             : 
      29             : #include <memory>
      30             : 
      31             : class SvMemoryStream;
      32             : 
      33             : namespace com { namespace sun { namespace star { namespace util {
      34             :     class XStringWidth;
      35             : } } } }
      36             : 
      37             : // Common URL prefixes for various schemes:
      38             : #define INET_FTP_SCHEME "ftp://"
      39             : #define INET_HTTP_SCHEME "http://"
      40             : #define INET_HTTPS_SCHEME "https://"
      41             : #define INET_FILE_SCHEME "file://"
      42             : #define INET_MAILTO_SCHEME "mailto:"
      43             : #define INET_NEWS_SCHEME "news:"
      44             : #define INET_HID_SCHEME "hid:"
      45             : 
      46             : #define URL_PREFIX_PRIV_SOFFICE "private:"
      47             : enum
      48             : {
      49             :     URL_PREFIX_PRIV_SOFFICE_LEN
      50             :         = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_SOFFICE)
      51             : };
      52             : 
      53             : #define URL_PREFIX_PRIV_OBSOLETE URL_PREFIX_PRIV_SOFFICE
      54             : enum
      55             : {
      56             :     URL_PREFIX_PRIV_OBSOLETE_LEN
      57             :         = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_OBSOLETE)
      58             : };
      59             : 
      60             : #define URL_PREFIX_PRIV_EXTERN "staroffice:"
      61             : enum
      62             : {
      63             :     URL_PREFIX_PRIV_EXTERN_LEN = RTL_CONSTASCII_LENGTH(URL_PREFIX_PRIV_EXTERN)
      64             : };
      65             : 
      66             : // Schemes:
      67             : enum INetProtocol
      68             : {
      69             :     INET_PROT_NOT_VALID = 0,
      70             :     INET_PROT_FTP = 1,
      71             :     INET_PROT_HTTP = 2,
      72             :     INET_PROT_FILE = 3,
      73             :     INET_PROT_MAILTO = 4,
      74             :     INET_PROT_VND_SUN_STAR_WEBDAV = 5,
      75             :     INET_PROT_NEWS = 6,
      76             :     INET_PROT_PRIV_SOFFICE = 7,
      77             :     INET_PROT_PRIVATE = INET_PROT_PRIV_SOFFICE, // obsolete
      78             :     INET_PROT_VND_SUN_STAR_HELP = 8,
      79             :     INET_PROT_HTTPS = 9,
      80             :     INET_PROT_SLOT = 10,
      81             :     INET_PROT_MACRO = 11,
      82             :     INET_PROT_JAVASCRIPT = 12,
      83             :     INET_PROT_IMAP = 13,
      84             :     INET_PROT_POP3 = 14,
      85             :     INET_PROT_DATA = 15,
      86             :     INET_PROT_CID = 16,
      87             :     INET_PROT_OUT = 17,
      88             :     INET_PROT_VND_SUN_STAR_HIER = 18,
      89             :     INET_PROT_VIM = 19,
      90             :     INET_PROT_UNO = 20,
      91             :     INET_PROT_COMPONENT = 21,
      92             :     INET_PROT_VND_SUN_STAR_PKG = 22,
      93             :     INET_PROT_LDAP = 23,
      94             :     INET_PROT_DB = 24,
      95             :     INET_PROT_VND_SUN_STAR_CMD = 25,
      96             :     INET_PROT_TELNET = 27,
      97             :     INET_PROT_VND_SUN_STAR_EXPAND = 28,
      98             :     INET_PROT_VND_SUN_STAR_TDOC = 29,
      99             :     INET_PROT_GENERIC = 30,
     100             :     INET_PROT_SMB = 31,
     101             :     INET_PROT_HID = 32,
     102             :     INET_PROT_SFTP = 33,
     103             :     INET_PROT_CMIS = 34,
     104             :     INET_PROT_END = 35
     105             : };
     106             : 
     107     1961559 : class TOOLS_DLLPUBLIC SAL_WARN_UNUSED INetURLObject
     108             : {
     109             : public:
     110             :     // Get- and Set-Methods:
     111             : 
     112             :     /** The way input strings that represent (parts of) URIs are interpreted
     113             :         in set-methods.
     114             : 
     115             :         @descr  UTF-32 characters in the range 0x80--0x10FFFF are replaced by
     116             :         sequences of escape sequences, representing the UTF-8 coded characters.
     117             : 
     118             :         @descr  Along with an EncodeMechanism parameter, the set-methods all
     119             :         take an rtl_TextEncoding parameter, which is ignored unless the
     120             :         EncodeMechanism is WAS_ENCODED.
     121             :      */
     122             :     enum EncodeMechanism
     123             :     {
     124             :         /** All escape sequences that are already present are ignored, and are
     125             :             interpreted as literal sequences of three characters.
     126             :          */
     127             :         ENCODE_ALL,
     128             : 
     129             :         /** Sequences of escape sequences, that represent characters from the
     130             :             specified character set and that can be converted to UTF-32
     131             :             characters, are first decoded.  If they have to be encoded, they
     132             :             are converted to UTF-8 characters and are than translated into
     133             :             (sequences of) escape sequences.  Other escape sequences are
     134             :             copied verbatim (but using upper case hex digits).
     135             :          */
     136             :         WAS_ENCODED,
     137             : 
     138             :         /** All escape sequences that are already present are copied verbatim
     139             :             (but using upper case hex digits).
     140             :          */
     141             :         NOT_CANONIC
     142             :     };
     143             : 
     144             :     /** The way strings that represent (parts of) URIs are returned from get-
     145             :         methods.
     146             : 
     147             :         @descr  Along with a DecodeMechanism parameter, the get-methods all
     148             :         take an rtl_TextEncoding parameter, which is ignored unless the
     149             :         DecodeMechanism is DECODE_WITH_CHARSET or DECODE_UNAMBIGUOUS.
     150             :      */
     151             :     enum DecodeMechanism
     152             :     {
     153             :         /** The (part of the) URI is returned unchanged.  Since URIs are
     154             :             written using a subset of US-ASCII, the returned string is
     155             :             guaranteed to contain only US-ASCII characters.
     156             :          */
     157             :         NO_DECODE,
     158             : 
     159             :         /** All sequences of escape sequences that represent UTF-8 coded
     160             :             UTF-32 characters with a numerical value greater than 0x7F, are
     161             :             replaced by the respective UTF-16 characters.  All other escape
     162             :             sequences are not decoded.
     163             :          */
     164             :         DECODE_TO_IURI,
     165             : 
     166             :         /** All (sequences of) escape sequences that represent characters from
     167             :             the specified character set, and that can be converted to UTF-32,
     168             :             are replaced by the respective UTF-16 characters.  All other
     169             :             escape sequences are not decoded.
     170             :          */
     171             :         DECODE_WITH_CHARSET,
     172             : 
     173             :         /** All (sequences of) escape sequences that represent characters from
     174             :             the specified character set, that can be converted to UTF-32, and
     175             :             that (in the case of ASCII characters) can safely be decoded
     176             :             without altering the meaning of the (part of the) URI, are
     177             :             replaced by the respective UTF-16 characters.  All other escape
     178             :             sequences are not decoded.
     179             :          */
     180             :         DECODE_UNAMBIGUOUS
     181             :     };
     182             : 
     183             :     // General Structure:
     184             : 
     185       22854 :     inline INetURLObject():
     186       22854 :         m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP) {}
     187             : 
     188     1995252 :     inline bool HasError() const { return m_eScheme == INET_PROT_NOT_VALID; }
     189             : 
     190     1639700 :     inline OUString GetMainURL(DecodeMechanism eMechanism,
     191             :                                 rtl_TextEncoding eCharset
     192             :                                     = RTL_TEXTENCODING_UTF8) const
     193     1639700 :     { return decode(m_aAbsURIRef, getEscapePrefix(), eMechanism, eCharset); }
     194             : 
     195             :     OUString GetURLNoPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
     196             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     197             :         const;
     198             : 
     199             :     OUString GetURLNoMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
     200             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     201             :         const;
     202             : 
     203             :     OUString
     204             :     getAbbreviated(com::sun::star::uno::Reference<
     205             :                            com::sun::star::util::XStringWidth > const &
     206             :                        rStringWidth,
     207             :                    sal_Int32 nWidth,
     208             :                    DecodeMechanism eMechanism = DECODE_TO_IURI,
     209             :                    rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     210             :         const;
     211             : 
     212             :     bool operator ==(INetURLObject const & rObject) const;
     213             : 
     214        1114 :     inline bool operator !=(INetURLObject const & rObject) const
     215        1114 :     { return !(*this == rObject); }
     216             : 
     217             :     bool operator <(INetURLObject const & rObject) const;
     218             : 
     219             :     inline bool operator >(INetURLObject const & rObject) const
     220             :     { return rObject < *this; }
     221             : 
     222             :     // Strict Parsing:
     223             : 
     224             :     inline explicit INetURLObject(
     225             :         OUString const & rTheAbsURIRef,
     226             :         EncodeMechanism eMechanism = WAS_ENCODED,
     227             :         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     228             : 
     229             :     inline bool SetURL(OUString const & rTheAbsURIRef,
     230             :                        EncodeMechanism eMechanism = WAS_ENCODED,
     231             :                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     232             : 
     233             :     bool ConcatData(INetProtocol eTheScheme, OUString const & rTheUser,
     234             :                     OUString const & rThePassword,
     235             :                     OUString const & rTheHost, sal_uInt32 nThePort,
     236             :                     OUString const & rThePath,
     237             :                     EncodeMechanism eMechanism = WAS_ENCODED,
     238             :                     rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     239             : 
     240             :     // Smart Parsing:
     241             : 
     242             :     /** The supported notations for file system paths.
     243             :      */
     244             :     enum FSysStyle
     245             :     {
     246             :         /** VOS notation (e.g., "//server/dir/file").
     247             :          */
     248             :         FSYS_VOS = 0x1,
     249             : 
     250             :         /** Unix notation (e.g., "/dir/file").
     251             :          */
     252             :         FSYS_UNX = 0x2,
     253             : 
     254             :         /** DOS notation (e.g., "a:\dir\file" and "\\server\dir\file").
     255             :          */
     256             :         FSYS_DOS = 0x4,
     257             : 
     258             :         /** Detect the used notation.
     259             : 
     260             :             @descr  For the following descriptions, please note that
     261             :             whereas FSYS_DEFAULT includes all style bits, combinations of only
     262             :             a few style bits are also possible, and are also described.
     263             : 
     264             :             @descr  When used to translate a file system path to a file URL,
     265             :             the subset of the following productions for which the appropriate
     266             :             style bit is set are checked in order (using the conventions of
     267             :             RFC 2234, RFC 2396, and RFC 2732; UCS4 stands for any UCS4
     268             :             character):
     269             : 
     270             :              Production T1 (VOS local; FSYS_VOS only):
     271             :                 "//." ["/" *UCS4]
     272             :               becomes
     273             :                 "file:///" *UCS4
     274             : 
     275             :              Production T2 (VOS host; FSYS_VOS only):
     276             :                 "//" [host] ["/" *UCS4]
     277             :               becomes
     278             :                 "file://" host "/" *UCS4
     279             : 
     280             :              Production T3 (UNC; FSYS_DOS only):
     281             :                 "\\" [host] ["\" *UCS4]
     282             :               becomes
     283             :                 "file://" host "/" *UCS4
     284             :               replacing "\" by "/" within <*UCS4>
     285             : 
     286             :              Production T4 (Unix-like DOS; FSYS_DOS only):
     287             :                 ALPHA ":" ["/" *UCS4]
     288             :               becomes
     289             :                 "file:///" ALPHA ":/" *UCS4
     290             :               replacing "\" by "/" within <*UCS4>
     291             : 
     292             :              Production T5 (DOS; FSYS_DOS only):
     293             :                 ALPHA ":" ["\" *UCS4]
     294             :               becomes
     295             :                 "file:///" ALPHA ":/" *UCS4
     296             :               replacing "\" by "/" within <*UCS4>
     297             : 
     298             :              Production T6 (any):
     299             :                 *UCS4
     300             :               becomes
     301             :                 "file:///" *UCS4
     302             :               replacing the delimiter by "/" within <*UCS4>.  The delimiter is
     303             :               that character from the set { "/", "\" } which appears most
     304             :               often in <*UCS4> (if FSYS_UNX is not among the style bits, "/"
     305             :               is removed from the set; if FSYS_DOS is not among the style
     306             :               bits, "\" is removed from the set).  If two or more
     307             :               characters appear the same number of times, the character
     308             :               mentioned first in that set is chosen.  If the first character
     309             :               of <*UCS4> is the delimiter, that character is not copied.
     310             : 
     311             :             @descr  When used to translate a file URL to a file system path,
     312             :             the following productions are checked in order (using the
     313             :             conventions of RFC 2234, RFC 2396, and RFC 2732):
     314             : 
     315             :              Production F1 (VOS; FSYS_VOS):
     316             :                 "file://" host "/" fpath ["#" fragment]
     317             :               becomes
     318             :                 "//" host "/" fpath
     319             : 
     320             :              Production F2 (DOS; FSYS_DOS):
     321             :                 "file:///" ALPHA ":" ["/" fpath] ["#" fragment]
     322             :               becomes
     323             :                 ALPHA ":" ["\" fpath]
     324             :               replacing "/" by "\" in <fpath>
     325             : 
     326             :              Production F3 (Unix; FSYS_UNX):
     327             :                 "file:///" fpath ["#" fragment]
     328             :               becomes
     329             :                 "/" fpath
     330             :          */
     331             :         FSYS_DETECT = FSYS_VOS | FSYS_UNX | FSYS_DOS
     332             :     };
     333             : 
     334             :     inline INetURLObject(OUString const & rTheAbsURIRef,
     335             :                          INetProtocol eTheSmartScheme,
     336             :                          EncodeMechanism eMechanism = WAS_ENCODED,
     337             :                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     338             :                          FSysStyle eStyle = FSYS_DETECT);
     339             : 
     340         705 :     inline void SetSmartProtocol(INetProtocol eTheSmartScheme)
     341         705 :     { m_eSmartScheme = eTheSmartScheme; }
     342             : 
     343             :     inline bool
     344             :     SetSmartURL(OUString const & rTheAbsURIRef,
     345             :                 EncodeMechanism eMechanism = WAS_ENCODED,
     346             :                 rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     347             :                 FSysStyle eStyle = FSYS_DETECT);
     348             : 
     349             :     inline INetURLObject
     350             :     smartRel2Abs(OUString const & rTheRelURIRef,
     351             :                  bool & rWasAbsolute,
     352             :                  bool bIgnoreFragment = false,
     353             :                  EncodeMechanism eMechanism = WAS_ENCODED,
     354             :                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     355             :                  bool bRelativeNonURIs = false,
     356             :                  FSysStyle eStyle = FSYS_DETECT) const;
     357             : 
     358             :     // Relative URLs:
     359             : 
     360             :     inline bool
     361             :     GetNewAbsURL(OUString const & rTheRelURIRef,
     362             :                  INetURLObject * pTheAbsURIRef,
     363             :                  EncodeMechanism eMechanism = WAS_ENCODED,
     364             :                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     365             :                  FSysStyle eStyle = FSYS_DETECT, bool bIgnoreFragment = false)
     366             :         const;
     367             : 
     368             :     /** @descr  If rTheRelURIRef cannot be converted to an absolute URL
     369             :         (because of syntactic reasons), either rTheRelURIRef or an empty
     370             :         string is returned:  If all of the parameters eEncodeMechanism,
     371             :         eDecodeMechanism and eCharset have their respective default values,
     372             :         then rTheRelURIRef is returned unmodified; otherwise, an empty string
     373             :         is returned.
     374             :      */
     375             :     static OUString
     376             :     GetAbsURL(OUString const & rTheBaseURIRef,
     377             :               OUString const & rTheRelURIRef,
     378             :               bool bIgnoreFragment = false,
     379             :               EncodeMechanism eEncodeMechanism = WAS_ENCODED,
     380             :               DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
     381             :               rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     382             :               FSysStyle eStyle = FSYS_DETECT);
     383             : 
     384             :     static inline OUString
     385             :     GetRelURL(OUString const & rTheBaseURIRef,
     386             :               OUString const & rTheAbsURIRef,
     387             :               EncodeMechanism eEncodeMechanism = WAS_ENCODED,
     388             :               DecodeMechanism eDecodeMechanism = DECODE_TO_IURI,
     389             :               rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8,
     390             :               FSysStyle eStyle = FSYS_DETECT);
     391             : 
     392             :     // External URLs:
     393             : 
     394             :     OUString getExternalURL(DecodeMechanism eMechanism = DECODE_TO_IURI,
     395             :                              rtl_TextEncoding eCharset
     396             :                                  = RTL_TEXTENCODING_UTF8) const;
     397             : 
     398             :     static inline bool translateToExternal(OUString const & rTheIntURIRef,
     399             :                                            OUString & rTheExtURIRef,
     400             :                                            DecodeMechanism eDecodeMechanism
     401             :                                                = DECODE_TO_IURI,
     402             :                                            rtl_TextEncoding eCharset
     403             :                                                = RTL_TEXTENCODING_UTF8);
     404             : 
     405             :     static inline bool translateToInternal(OUString const & rTheExtURIRef,
     406             :                                            OUString & rTheIntURIRef,
     407             :                                            DecodeMechanism eDecodeMechanism
     408             :                                                = DECODE_TO_IURI,
     409             :                                            rtl_TextEncoding eCharset
     410             :                                                = RTL_TEXTENCODING_UTF8);
     411             : 
     412             :     // Scheme:
     413             : 
     414             :     struct SchemeInfo;
     415             : 
     416     1821016 :     inline INetProtocol GetProtocol() const { return m_eScheme; }
     417             : 
     418             :     /** Return the URL 'prefix' for a given scheme.
     419             : 
     420             :         @param eTheScheme  One of the supported URL schemes.
     421             : 
     422             :         @return  The 'prefix' of URLs of the given scheme.
     423             :      */
     424             :     static OUString GetScheme(INetProtocol eTheScheme);
     425             : 
     426             :     /** Return the a human-readable name for a given scheme.
     427             : 
     428             :         @param eTheScheme  One of the supported URL schemes.
     429             : 
     430             :         @return  The protocol name of URLs of the given scheme.
     431             :      */
     432             :     static OUString GetSchemeName(INetProtocol eTheScheme);
     433             : 
     434             :     static INetProtocol CompareProtocolScheme(OUString const &
     435             :                                                   rTheAbsURIRef);
     436             : 
     437             :     // User Info:
     438             : 
     439           2 :     inline bool HasUserData() const { return m_aUser.isPresent(); }
     440             : 
     441             :     inline bool IsEmptyUser() const
     442             :     { return m_aUser.isPresent() && m_aUser.isEmpty(); }
     443             : 
     444      693931 :     inline OUString GetUser(DecodeMechanism eMechanism = DECODE_TO_IURI,
     445             :                              rtl_TextEncoding eCharset
     446             :                                  = RTL_TEXTENCODING_UTF8) const
     447      693931 :     { return decode(m_aUser, getEscapePrefix(), eMechanism, eCharset); }
     448             : 
     449      693929 :     inline OUString GetPass(DecodeMechanism eMechanism = DECODE_TO_IURI,
     450             :                              rtl_TextEncoding eCharset
     451             :                                  = RTL_TEXTENCODING_UTF8) const
     452      693929 :     { return decode(m_aAuth, getEscapePrefix(), eMechanism, eCharset); }
     453             : 
     454           0 :     inline bool SetUser(OUString const & rTheUser,
     455             :                         EncodeMechanism eMechanism = WAS_ENCODED,
     456             :                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     457           0 :     { return setUser(rTheUser, false, eMechanism, eCharset); }
     458             : 
     459             :     inline bool SetPass(OUString const & rThePassword,
     460             :                         EncodeMechanism eMechanism = WAS_ENCODED,
     461             :                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     462             : 
     463             :     inline bool SetUserAndPass(OUString const & rTheUser,
     464             :                                OUString const & rThePassword,
     465             :                                EncodeMechanism eMechanism = WAS_ENCODED,
     466             :                                rtl_TextEncoding eCharset
     467             :                                    = RTL_TEXTENCODING_UTF8);
     468             : 
     469             :     // Host and Port:
     470             : 
     471         786 :     inline bool HasPort() const { return m_aPort.isPresent(); }
     472             : 
     473      693949 :     inline OUString GetHost(DecodeMechanism eMechanism = DECODE_TO_IURI,
     474             :                              rtl_TextEncoding eCharset
     475             :                                  = RTL_TEXTENCODING_UTF8) const
     476      693949 :     { return decode(m_aHost, getEscapePrefix(), eMechanism, eCharset); }
     477             : 
     478             :     OUString GetHostPort(DecodeMechanism eMechanism = DECODE_TO_IURI,
     479             :                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     480             : 
     481             :     sal_uInt32 GetPort() const;
     482             : 
     483           0 :     inline bool SetHost(OUString const & rTheHost,
     484             :                         EncodeMechanism eMechanism = WAS_ENCODED,
     485             :                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     486           0 :     { return setHost(rTheHost, false, eMechanism, eCharset); }
     487             : 
     488             :     bool SetPort(sal_uInt32 nThePort);
     489             : 
     490             :     // Path:
     491             : 
     492         786 :     inline bool HasURLPath() const { return !m_aPath.isEmpty(); }
     493             : 
     494      886820 :     inline OUString GetURLPath(DecodeMechanism eMechanism = DECODE_TO_IURI,
     495             :                                 rtl_TextEncoding eCharset
     496             :                                     = RTL_TEXTENCODING_UTF8) const
     497      886820 :     { return decode(m_aPath, getEscapePrefix(), eMechanism, eCharset); }
     498             : 
     499         252 :     inline bool SetURLPath(OUString const & rThePath,
     500             :                            EncodeMechanism eMechanism = WAS_ENCODED,
     501             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     502         252 :     { return setPath(rThePath, false, eMechanism, eCharset); }
     503             : 
     504             :     // Hierarchical Path:
     505             : 
     506             :     /** A constant to address the last segment in various methods dealing with
     507             :         hierarchical paths.
     508             : 
     509             :         @descr  It is often more efficient to address the last segment using
     510             :         this constant, than to determine its ordinal value using
     511             :         getSegmentCount().
     512             :      */
     513             :     enum { LAST_SEGMENT = -1 };
     514             : 
     515             :     /** The number of segments in the hierarchical path.
     516             : 
     517             :         @descr  Using RFC 2396 and RFC 2234, a hierarchical path is of the
     518             :         form
     519             : 
     520             :           hierarchical-path = 1*("/" segment)
     521             : 
     522             :           segment = name *(";" param)
     523             : 
     524             :           name = [base ["." extension]]
     525             : 
     526             :           base = 1*pchar
     527             : 
     528             :           extension = *<any pchar except ".">
     529             : 
     530             :           param = *pchar
     531             : 
     532             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     533             :         hierarchical path does not denote an empty segment, but is ignored.
     534             : 
     535             :         @return  The number of segments in the hierarchical path.  If the path
     536             :         is not hierarchical, 0 is returned.
     537             :      */
     538             :     sal_Int32 getSegmentCount(bool bIgnoreFinalSlash = true) const;
     539             : 
     540             :     /** Remove a segment from the hierarchical path.
     541             : 
     542             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     543             :         if addressing the last segment.
     544             : 
     545             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     546             :         hierarchical path does not denote an empty segment, but is ignored.
     547             : 
     548             :         @return  True if the segment has successfully been removed (and the
     549             :         resulting URI is still valid).  If the path is not hierarchical, or
     550             :         the specified segment does not exist, false is returned.  If false is
     551             :         returned, the object is not modified.
     552             :      */
     553             :     bool removeSegment(sal_Int32 nIndex = LAST_SEGMENT,
     554             :                        bool bIgnoreFinalSlash = true);
     555             : 
     556             :     /** Insert a new segment into the hierarchical path.
     557             : 
     558             :         @param rTheName  The name part of the new segment.  The new segment
     559             :         will contain no parameters.
     560             : 
     561             :         @param bAppendFinalSlash  If the new segment is appended at the end of
     562             :         the hierarchical path, this parameter specifies whether to add a final
     563             :         slash after it or not.
     564             : 
     565             :         @param nIndex  The non-negative index of the segment before which
     566             :         to insert the new segment.  LAST_SEGMENT or an nIndex that equals
     567             :         getSegmentCount() inserts the new segment at the end of the
     568             :         hierarchical path.
     569             : 
     570             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     571             :         hierarchical path does not denote an empty segment, but is ignored.
     572             : 
     573             :         @param eMechanism  See the general discussion for set-methods.
     574             : 
     575             :         @param eCharset  See the general discussion for set-methods.
     576             : 
     577             :         @return  True if the segment has successfully been inserted (and the
     578             :         resulting URI is still valid).  If the path is not hierarchical, or
     579             :         the specified place to insert the new segment does not exist, false is
     580             :         returned.  If false is returned, the object is not modified.
     581             :      */
     582             :     inline bool insertName(OUString const & rTheName,
     583             :                            bool bAppendFinalSlash = false,
     584             :                            sal_Int32 nIndex = LAST_SEGMENT,
     585             :                            bool bIgnoreFinalSlash = true,
     586             :                            EncodeMechanism eMechanism = WAS_ENCODED,
     587             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     588             : 
     589             :     /** Get the name of a segment of the hierarchical path.
     590             : 
     591             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     592             :         if addressing the last segment.
     593             : 
     594             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     595             :         hierarchical path does not denote an empty segment, but is ignored.
     596             : 
     597             :         @param eMechanism  See the general discussion for get-methods.
     598             : 
     599             :         @param eCharset  See the general discussion for get-methods.
     600             : 
     601             :         @return  The name part of the specified segment.  If the path is not
     602             :         hierarchical, or the specified segment does not exits, an empty string
     603             :         is returned.
     604             :      */
     605             :     OUString getName(sal_Int32 nIndex = LAST_SEGMENT,
     606             :                       bool bIgnoreFinalSlash = true,
     607             :                       DecodeMechanism eMechanism = DECODE_TO_IURI,
     608             :                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     609             :         const;
     610             : 
     611             :     /** Set the name of a segment (preserving any parameters and any query or
     612             :         fragment part).
     613             : 
     614             :         @param rTheName  The new name.
     615             : 
     616             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     617             :         if addressing the last segment.
     618             : 
     619             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     620             :         hierarchical path does not denote an empty segment, but is ignored.
     621             : 
     622             :         @param eMechanism  See the general discussion for set-methods.
     623             : 
     624             :         @param eCharset  See the general discussion for set-methods.
     625             : 
     626             :         @return  True if the name has successfully been modified (and the
     627             :         resulting URI is still valid).  If the path is not hierarchical, or
     628             :         the specified segment does not exist, false is returned.  If false is
     629             :         returned, the object is not modified.
     630             :      */
     631             :     bool setName(OUString const & rTheName,
     632             :                  sal_Int32 nIndex = LAST_SEGMENT,
     633             :                  bool bIgnoreFinalSlash = true,
     634             :                  EncodeMechanism eMechanism = WAS_ENCODED,
     635             :                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     636             : 
     637             :     /** Get the base of the name of a segment.
     638             : 
     639             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     640             :         if addressing the last segment.
     641             : 
     642             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     643             :         hierarchical path does not denote an empty segment, but is ignored.
     644             : 
     645             :         @param eMechanism  See the general discussion for get-methods.
     646             : 
     647             :         @param eCharset  See the general discussion for get-methods.
     648             : 
     649             :         @return  The base part of the specified segment.  If the path is
     650             :         not hierarchical, or the specified segment does not exits, an empty
     651             :         string is returned.
     652             :      */
     653             :     OUString getBase(sal_Int32 nIndex = LAST_SEGMENT,
     654             :                       bool bIgnoreFinalSlash = true,
     655             :                       DecodeMechanism eMechanism = DECODE_TO_IURI,
     656             :                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     657             :         const;
     658             : 
     659             :     /** Set the base of the name of a segment (preserving the extension).
     660             : 
     661             :         @param rTheBase  The new base.
     662             : 
     663             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     664             :         if addressing the last segment.
     665             : 
     666             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     667             :         hierarchical path does not denote an empty segment, but is ignored.
     668             : 
     669             :         @param eMechanism  See the general discussion for set-methods.
     670             : 
     671             :         @param eCharset  See the general discussion for set-methods.
     672             : 
     673             :         @return  True if the base has successfully been modified (and the
     674             :         resulting URI is still valid).  If the path is not hierarchical, or
     675             :         the specified segment does not exist, false is returned.  If false is
     676             :         returned, the object is not modified.
     677             :      */
     678             :     bool setBase(OUString const & rTheBase,
     679             :                  sal_Int32 nIndex = LAST_SEGMENT,
     680             :                  bool bIgnoreFinalSlash = true,
     681             :                  EncodeMechanism eMechanism = WAS_ENCODED,
     682             :                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     683             : 
     684             :     /** Determine whether the name of a segment has an extension.
     685             : 
     686             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     687             :         if addressing the last segment.
     688             : 
     689             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     690             :         hierarchical path does not denote an empty segment, but is ignored.
     691             : 
     692             :         @return  True if the name of the specified segment has an extension.
     693             :         If the path is not hierarchical, or the specified segment does not
     694             :         exist, false is returned.
     695             :      */
     696             :     bool hasExtension(sal_Int32 nIndex = LAST_SEGMENT,
     697             :                       bool bIgnoreFinalSlash = true) const;
     698             : 
     699             :     /** Get the extension of the name of a segment.
     700             : 
     701             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     702             :         if addressing the last segment.
     703             : 
     704             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     705             :         hierarchical path does not denote an empty segment, but is ignored.
     706             : 
     707             :         @param eMechanism  See the general discussion for get-methods.
     708             : 
     709             :         @param eCharset  See the general discussion for get-methods.
     710             : 
     711             :         @return  The extension part of the specified segment.  If the path is
     712             :         not hierarchical, or the specified segment does not exits, an empty
     713             :         string is returned.
     714             :      */
     715             :     OUString getExtension(sal_Int32 nIndex = LAST_SEGMENT,
     716             :                            bool bIgnoreFinalSlash = true,
     717             :                            DecodeMechanism eMechanism = DECODE_TO_IURI,
     718             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     719             :         const;
     720             : 
     721             :     /** Set the extension of the name of a segment (replacing an already
     722             :         existing extension).
     723             : 
     724             :         @param rTheExtension  The new extension.
     725             : 
     726             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     727             :         if addressing the last segment.
     728             : 
     729             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     730             :         hierarchical path does not denote an empty segment, but is ignored.
     731             : 
     732             :         @param eMechanism  See the general discussion for set-methods.
     733             : 
     734             :         @param eCharset  See the general discussion for set-methods.
     735             : 
     736             :         @return  True if the extension has successfully been modified (and the
     737             :         resulting URI is still valid).  If the path is not hierarchical, or
     738             :         the specified segment does not exist, false is returned.  If false is
     739             :         returned, the object is not modified.
     740             :      */
     741             :     bool setExtension(OUString const & rTheExtension,
     742             :                       sal_Int32 nIndex = LAST_SEGMENT,
     743             :                       bool bIgnoreFinalSlash = true,
     744             :                       EncodeMechanism eMechanism = WAS_ENCODED,
     745             :                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     746             : 
     747             :     /** Remove the extension of the name of a segment.
     748             : 
     749             :         @param nIndex  The non-negative index of the segment, or LAST_SEGMENT
     750             :         if addressing the last segment.
     751             : 
     752             :         @param bIgnoreFinalSlash  If true, a final slash at the end of the
     753             :         hierarchical path does not denote an empty segment, but is ignored.
     754             : 
     755             :         @return  True if the extension has successfully been removed (and the
     756             :         resulting URI is still valid), or if the name did not have an
     757             :         extension.  If the path is not hierarchical, or the specified segment
     758             :         does not exist, false is returned.  If false is returned, the object
     759             :         is not modified.
     760             :      */
     761             :     bool removeExtension(sal_Int32 nIndex = LAST_SEGMENT,
     762             :                          bool bIgnoreFinalSlash = true);
     763             : 
     764             :     /** Determine whether the hierarchical path ends in a final slash.
     765             : 
     766             :         @return  True if the hierarchical path ends in a final slash.  If the
     767             :         path is not hierarchical, false is returned.
     768             :      */
     769             :     bool hasFinalSlash() const;
     770             : 
     771             :     /** Make the hierarchical path end in a final slash (if it does not
     772             :         already do so).
     773             : 
     774             :         @return  True if a final slash has successfully been appended (and the
     775             :         resulting URI is still valid), or if the hierarchical path already
     776             :         ended in a final slash.  If the path is not hierarchical, false is
     777             :         returned.  If false is returned, the object is not modified.
     778             :      */
     779             :     bool setFinalSlash();
     780             : 
     781             :     /** Remove a final slash from the hierarchical path.
     782             : 
     783             :         @return  True if a final slash has successfully been removed (and the
     784             :         resulting URI is still valid), or if the hierarchical path already did
     785             :         not end in a final slash.  If the path is not hierarchical, false is
     786             :         returned.  If false is returned, the object is not modified.
     787             :      */
     788             :     bool removeFinalSlash();
     789             : 
     790             :     // Query:
     791             : 
     792       34850 :     inline bool HasParam() const { return m_aQuery.isPresent(); }
     793             : 
     794      693929 :     inline OUString GetParam(DecodeMechanism eMechanism = DECODE_TO_IURI,
     795             :                               rtl_TextEncoding eCharset
     796             :                                   = RTL_TEXTENCODING_UTF8) const
     797      693929 :     { return decode(m_aQuery, getEscapePrefix(), eMechanism, eCharset); }
     798             : 
     799             :     inline bool SetParam(OUString const & rTheQuery,
     800             :                          EncodeMechanism eMechanism = WAS_ENCODED,
     801             :                          rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     802             : 
     803             :     // Fragment:
     804             : 
     805       38878 :     inline bool HasMark() const { return m_aFragment.isPresent(); }
     806             : 
     807      659891 :     inline OUString GetMark(DecodeMechanism eMechanism = DECODE_TO_IURI,
     808             :                              rtl_TextEncoding eCharset
     809             :                                  = RTL_TEXTENCODING_UTF8) const
     810      659891 :     { return decode(m_aFragment, getEscapePrefix(), eMechanism, eCharset); }
     811             : 
     812             :     inline bool SetMark(OUString const & rTheFragment,
     813             :                         EncodeMechanism eMechanism = WAS_ENCODED,
     814             :                         rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
     815             : 
     816             :     // File URLs:
     817             : 
     818             :     /** Create an INetURLObject from a file system path.
     819             : 
     820             :         @param rFSysPath  A file system path.  An URL is not allowed here!
     821             : 
     822             :         @param eStyle  The notation of rFSysPath.
     823             :      */
     824             :     inline INetURLObject(OUString const & rFSysPath, FSysStyle eStyle);
     825             : 
     826             :     /** Set this INetURLObject to a file URL constructed from a file system
     827             :         path.
     828             : 
     829             :         @param rFSysPath  A file system path.  An URL is not allowed here!
     830             : 
     831             :         @param eStyle  The notation of rFSysPath.
     832             : 
     833             :         @return  True if this INetURLObject has successfully been changed.  If
     834             :         false is returned, this INetURLObject has not been modified.
     835             :      */
     836             :     bool setFSysPath(OUString const & rFSysPath, FSysStyle eStyle);
     837             : 
     838             :     /** Return the file system path represented by a file URL (ignoring any
     839             :         fragment part).
     840             : 
     841             :         @param eStyle  The notation of the returned file system path.
     842             : 
     843             :         @param pDelimiter  Upon successful return, this parameter can return
     844             :         the character that is the 'main' delimiter within the returned file
     845             :         system path (e.g., "/" for Unix, "\" for DOS).  This is
     846             :         especially useful for routines that later try to shorten the returned
     847             :         file system path at a 'good' position, e.g. to fit it into some
     848             :         limited display space.
     849             : 
     850             :         @return  The file system path represented by this file URL.  If this
     851             :         file URL does not represent a file system path according to the
     852             :         specified notation, or if this is not a file URL at all, an empty
     853             :         string is returned.
     854             :      */
     855             :     OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
     856             :         const;
     857             : 
     858             :     // Data URLs:
     859             :     std::unique_ptr<SvMemoryStream> getData();
     860             : 
     861             :     // POP3 and URLs:
     862             : 
     863             :     OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
     864             :                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     865             :         const;
     866             : 
     867             :     // Coding:
     868             : 
     869             :     enum Part
     870             :     {
     871             :         PART_USER_PASSWORD          = 0x00001,
     872             :         PART_IMAP_ACHAR             = 0x00002,
     873             :         PART_VIM                    = 0x00004,
     874             :         PART_FPATH                  = 0x00008,
     875             :         PART_AUTHORITY              = 0x00010,
     876             :         PART_REL_SEGMENT_EXTRA      = 0x00020,
     877             :         PART_URIC                   = 0x00040,
     878             :         PART_HTTP_PATH              = 0x00080,
     879             :         PART_MESSAGE_ID_PATH        = 0x00100,
     880             :         PART_MAILTO                 = 0x00200,
     881             :         PART_PATH_BEFORE_QUERY      = 0x00400,
     882             :         PART_PCHAR                  = 0x00800,
     883             :         PART_VISIBLE                = 0x01000,
     884             :         PART_VISIBLE_NONSPECIAL     = 0x02000,
     885             :         PART_UNO_PARAM_VALUE        = 0x04000,
     886             :         PART_UNAMBIGUOUS            = 0x08000,
     887             :         PART_URIC_NO_SLASH          = 0x10000,
     888             :         PART_HTTP_QUERY             = 0x20000, //TODO! unused?
     889             :         PART_NEWS_ARTICLE_LOCALPART = 0x40000
     890             :     };
     891             : 
     892             :     enum EscapeType
     893             :     {
     894             :         ESCAPE_NO,
     895             :         ESCAPE_OCTET,
     896             :         ESCAPE_UTF32
     897             :     };
     898             : 
     899             :     /** Encode some text as part of a URI.
     900             : 
     901             :         @param rText  Some text (for its interpretation, see the general
     902             :         discussion for set-methods).
     903             : 
     904             :         @param ePart  The part says which characters are 'forbidden' and must
     905             :         be encoded (replaced by escape sequences).  Characters outside the US-
     906             :         ASCII range are always 'forbidden.'
     907             : 
     908             :         @param cEscapePrefix  The first character in an escape sequence
     909             :         (normally '%').
     910             : 
     911             :         @param eMechanism  See the general discussion for set-methods.
     912             : 
     913             :         @param eCharset  See the general discussion for set-methods.
     914             : 
     915             :         @return  The text, encoded according to the given mechanism and
     916             :         charset ('forbidden' characters replaced by escape sequences).
     917             :      */
     918             :     static inline OUString encode(OUString const & rText, Part ePart,
     919             :                                    sal_Char cEscapePrefix,
     920             :                                    EncodeMechanism eMechanism,
     921             :                                    rtl_TextEncoding eCharset
     922             :                                        = RTL_TEXTENCODING_UTF8);
     923             : 
     924             :     /** Decode some text.
     925             : 
     926             :         @param rText  Some (encoded) text.
     927             : 
     928             :         @param cEscapePrefix  The first character in an escape sequence
     929             :         (normally '%').
     930             : 
     931             :         @param eMechanism  See the general discussion for get-methods.
     932             : 
     933             :         @param eCharset  See the general discussion for get-methods.
     934             : 
     935             :         @return  The text, decoded according to the given mechanism and
     936             :         charset (escape sequences replaced by 'raw' characters).
     937             :      */
     938             :     static inline OUString decode(OUString const & rText,
     939             :                                    sal_Char cEscapePrefix,
     940             :                                    DecodeMechanism eMechanism,
     941             :                                    rtl_TextEncoding eCharset
     942             :                                        = RTL_TEXTENCODING_UTF8);
     943             : 
     944             :     static inline OUString decode(OUStringBuffer const & rText,
     945             :                                    sal_Char cEscapePrefix,
     946             :                                    DecodeMechanism eMechanism,
     947             :                                    rtl_TextEncoding eCharset
     948             :                                        = RTL_TEXTENCODING_UTF8);
     949             : 
     950             :     static void appendUCS4Escape(OUStringBuffer & rTheText,
     951             :                                  sal_Char cEscapePrefix,
     952             :                                  sal_uInt32 nUCS4);
     953             : 
     954             :     static void appendUCS4(OUStringBuffer & rTheText, sal_uInt32 nUCS4,
     955             :                            EscapeType eEscapeType, bool bOctets, Part ePart,
     956             :                            sal_Char cEscapePrefix, rtl_TextEncoding eCharset,
     957             :                            bool bKeepVisibleEscapes);
     958             : 
     959             :     static sal_uInt32 getUTF32(sal_Unicode const *& rBegin,
     960             :                                sal_Unicode const * pEnd, bool bOctets,
     961             :                                sal_Char cEscapePrefix,
     962             :                                EncodeMechanism eMechanism,
     963             :                                rtl_TextEncoding eCharset,
     964             :                                EscapeType & rEscapeType);
     965             : 
     966             :     // Specialized helpers:
     967             : 
     968             :     static sal_uInt32 scanDomain(sal_Unicode const *& rBegin,
     969             :                                  sal_Unicode const * pEnd,
     970             :                                  bool bEager = true);
     971             : 
     972             :     // OBSOLETE Hierarchical Path:
     973             : 
     974             :     OUString GetPartBeforeLastName(DecodeMechanism eMechanism
     975             :                                         = DECODE_TO_IURI,
     976             :                                     rtl_TextEncoding eCharset
     977             :                                         = RTL_TEXTENCODING_UTF8) const;
     978             : 
     979             :     /** Get the last segment in the path.
     980             : 
     981             :         @param eMechanism  See the general discussion for get-methods.
     982             : 
     983             :         @param eCharset  See the general discussion for get-methods.
     984             : 
     985             :         @return  For a hierarchical URL, the last segment (everything after
     986             :         the last unencoded '/').  Not that this last segment may be empty.  If
     987             :         the URL is not hierarchical, an empty string is returned.
     988             :      */
     989             :     OUString GetLastName(DecodeMechanism eMechanism = DECODE_TO_IURI,
     990             :                           rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
     991             :         const;
     992             : 
     993             :     /** Get the 'extension' of the last segment in the path.
     994             : 
     995             :         @param eMechanism  See the general discussion for get-methods.
     996             : 
     997             :         @param eCharset  See the general discussion for get-methods.
     998             : 
     999             :         @return  For a hierarchical URL, everything after the first unencoded
    1000             :         '.' in the last segment of the path.  Note that this 'extension' may
    1001             :         be empty.  If the URL is not hierarchical, or if the last segment does
    1002             :         not contain an unencoded '.', an empty string is returned.
    1003             :      */
    1004             :     OUString GetFileExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
    1005             :                                rtl_TextEncoding eCharset
    1006             :                                    = RTL_TEXTENCODING_UTF8) const;
    1007             : 
    1008       29202 :     inline bool Append(OUString const & rTheSegment,
    1009             :                        EncodeMechanism eMechanism = WAS_ENCODED,
    1010             :                        rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8)
    1011       29202 :     { return appendSegment(rTheSegment, false, eMechanism, eCharset); }
    1012             : 
    1013             :     bool CutLastName();
    1014             : 
    1015             :     // OBSOLETE File URLs:
    1016             : 
    1017             :     OUString PathToFileName() const;
    1018             : 
    1019             :     OUString GetFull() const;
    1020             : 
    1021             :     OUString GetPath() const;
    1022             : 
    1023             :     void SetBase(OUString const & rTheBase);
    1024             : 
    1025             :     OUString GetBase() const;
    1026             : 
    1027             :     void SetName(OUString const & rTheName,
    1028             :                  EncodeMechanism eMechanism = WAS_ENCODED,
    1029             :                  rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
    1030             : 
    1031      648039 :     inline OUString GetName(DecodeMechanism eMechanism = DECODE_TO_IURI,
    1032             :                              rtl_TextEncoding eCharset
    1033             :                                  = RTL_TEXTENCODING_UTF8) const
    1034      648039 :     { return GetLastName(eMechanism, eCharset); }
    1035             : 
    1036             :     void SetExtension(OUString const & rTheExtension,
    1037             :                       EncodeMechanism eMechanism = WAS_ENCODED,
    1038             :                       rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
    1039             : 
    1040          89 :     inline OUString GetExtension(
    1041             :                                   DecodeMechanism eMechanism = DECODE_TO_IURI,
    1042             :                                   rtl_TextEncoding eCharset
    1043             :                                       = RTL_TEXTENCODING_UTF8) const
    1044          89 :     { return GetFileExtension(eMechanism, eCharset); }
    1045             : 
    1046             :     OUString CutExtension(DecodeMechanism eMechanism = DECODE_TO_IURI,
    1047             :                            rtl_TextEncoding eCharset = RTL_TEXTENCODING_UTF8);
    1048             : 
    1049             :     bool IsCaseSensitive() const;
    1050             : 
    1051             : 
    1052             : private:
    1053             :     // General Structure:
    1054             : 
    1055             :     class SubString
    1056             :     {
    1057             :         sal_Int32 m_nBegin;
    1058             :         sal_Int32 m_nLength;
    1059             : 
    1060             :     public:
    1061    17333549 :         explicit inline SubString(sal_Int32 nTheBegin = -1,
    1062             :                                   sal_Int32 nTheLength = 0):
    1063    17333549 :             m_nBegin(nTheBegin), m_nLength(nTheLength) {}
    1064             : 
    1065     7680542 :         inline bool isPresent() const { return m_nBegin != -1; }
    1066             : 
    1067      764511 :         inline bool isEmpty() const { return m_nLength == 0; }
    1068             : 
    1069     2003524 :         inline sal_Int32 getBegin() const { return m_nBegin; }
    1070             : 
    1071     1007969 :         inline sal_Int32 getLength() const { return m_nLength; }
    1072             : 
    1073     1003310 :         inline sal_Int32 getEnd() const { return m_nBegin + m_nLength; }
    1074             : 
    1075             :         inline sal_Int32 clear();
    1076             : 
    1077             :         inline sal_Int32 set(OUStringBuffer & rString,
    1078             :                              OUString const & rSubString,
    1079             :                              sal_Int32 nTheBegin);
    1080             : 
    1081             :         inline sal_Int32 set(OUString & rString,
    1082             :                              OUString const & rSubString);
    1083             : 
    1084             :         inline sal_Int32 set(OUStringBuffer & rString,
    1085             :                              OUString const & rSubString);
    1086             : 
    1087             :         inline void operator +=(sal_Int32 nDelta);
    1088             : 
    1089             :         int compare(SubString const & rOther,
    1090             :             OUStringBuffer const & rThisString,
    1091             :             OUStringBuffer const & rOtherString) const;
    1092             :     };
    1093             : 
    1094             :     OUStringBuffer m_aAbsURIRef;
    1095             :     SubString m_aScheme;
    1096             :     SubString m_aUser;
    1097             :     SubString m_aAuth;
    1098             :     SubString m_aHost;
    1099             :     SubString m_aPort;
    1100             :     SubString m_aPath;
    1101             :     SubString m_aQuery;
    1102             :     SubString m_aFragment;
    1103             :     INetProtocol m_eScheme;
    1104             :     INetProtocol m_eSmartScheme;
    1105             : 
    1106             :     TOOLS_DLLPRIVATE void setInvalid();
    1107             : 
    1108             :     bool setAbsURIRef(
    1109             :         OUString const & rTheAbsURIRef, bool bOctets,
    1110             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bSmart,
    1111             :         FSysStyle eStyle);
    1112             : 
    1113             :     // Relative URLs:
    1114             : 
    1115             :     bool convertRelToAbs(
    1116             :         OUString const & rTheRelURIRef, bool bOctets,
    1117             :         INetURLObject & rTheAbsURIRef, bool & rWasAbsolute,
    1118             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
    1119             :         bool bIgnoreFragment, bool bSmart, bool bRelativeNonURIs,
    1120             :         FSysStyle eStyle) const;
    1121             : 
    1122             :     bool convertAbsToRel(
    1123             :         OUString const & rTheAbsURIRef, bool bOctets,
    1124             :         OUString & rTheRelURIRef, EncodeMechanism eEncodeMechanism,
    1125             :         DecodeMechanism eDecodeMechanism, rtl_TextEncoding eCharset,
    1126             :         FSysStyle eStyle) const;
    1127             : 
    1128             :     // External URLs:
    1129             : 
    1130             :     static bool convertIntToExt(
    1131             :         OUString const & rTheIntURIRef, bool bOctets,
    1132             :         OUString & rTheExtURIRef, DecodeMechanism eDecodeMechanism,
    1133             :         rtl_TextEncoding eCharset);
    1134             : 
    1135             :     static bool convertExtToInt(
    1136             :         OUString const & rTheExtURIRef, bool bOctets,
    1137             :         OUString & rTheIntURIRef, DecodeMechanism eDecodeMechanism,
    1138             :         rtl_TextEncoding eCharset);
    1139             : 
    1140             :     // Scheme:
    1141             : 
    1142             :     struct PrefixInfo;
    1143             : 
    1144             :     TOOLS_DLLPRIVATE static inline SchemeInfo const & getSchemeInfo(
    1145             :         INetProtocol eTheScheme);
    1146             : 
    1147             :     TOOLS_DLLPRIVATE inline SchemeInfo const & getSchemeInfo() const;
    1148             : 
    1149             :     TOOLS_DLLPRIVATE static PrefixInfo const * getPrefix(
    1150             :         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
    1151             : 
    1152             :     // Authority:
    1153             : 
    1154             :     TOOLS_DLLPRIVATE sal_Int32 getAuthorityBegin() const;
    1155             : 
    1156             :     TOOLS_DLLPRIVATE SubString getAuthority() const;
    1157             : 
    1158             :     // User Info:
    1159             : 
    1160             :     bool setUser(
    1161             :         OUString const & rTheUser, bool bOctets,
    1162             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1163             : 
    1164             :     bool clearPassword();
    1165             : 
    1166             :     bool setPassword(
    1167             :         OUString const & rThePassword, bool bOctets,
    1168             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1169             : 
    1170             :     // Host and Port:
    1171             : 
    1172             :     TOOLS_DLLPRIVATE static bool parseHost(
    1173             :         sal_Unicode const *& rBegin, sal_Unicode const * pEnd,
    1174             :         OUString & rCanonic);
    1175             : 
    1176             :     TOOLS_DLLPRIVATE static bool parseHostOrNetBiosName(
    1177             :         sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
    1178             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
    1179             :         bool bNetBiosName, OUStringBuffer* pCanonic);
    1180             : 
    1181             :     bool setHost(
    1182             :         OUString const & rTheHost, bool bOctets,
    1183             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1184             : 
    1185             :     // Path:
    1186             : 
    1187             :     TOOLS_DLLPRIVATE static bool parsePath(
    1188             :         INetProtocol eScheme, sal_Unicode const ** pBegin,
    1189             :         sal_Unicode const * pEnd, bool bOctets, EncodeMechanism eMechanism,
    1190             :         rtl_TextEncoding eCharset, bool bSkippedInitialSlash,
    1191             :         sal_uInt32 nSegmentDelimiter, sal_uInt32 nAltSegmentDelimiter,
    1192             :         sal_uInt32 nQueryDelimiter, sal_uInt32 nFragmentDelimiter,
    1193             :         OUStringBuffer &rSynPath);
    1194             : 
    1195             :     bool setPath(
    1196             :         OUString const & rThePath, bool bOctets,
    1197             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1198             : 
    1199             :     // Hierarchical Path:
    1200             : 
    1201             :     TOOLS_DLLPRIVATE bool checkHierarchical() const;
    1202             : 
    1203             :     bool appendSegment(
    1204             :         OUString const & rTheSegment, bool bOctets,
    1205             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1206             : 
    1207             :     TOOLS_DLLPRIVATE SubString getSegment(
    1208             :         sal_Int32 nIndex, bool bIgnoreFinalSlash) const;
    1209             : 
    1210             :     bool insertName(
    1211             :         OUString const & rTheName, bool bOctets, bool bAppendFinalSlash,
    1212             :         sal_Int32 nIndex, bool bIgnoreFinalSlash, EncodeMechanism eMechanism,
    1213             :         rtl_TextEncoding eCharset);
    1214             : 
    1215             :     // Query:
    1216             : 
    1217             :     bool clearQuery();
    1218             : 
    1219             :     bool setQuery(
    1220             :         OUString const & rTheQuery, bool bOctets,
    1221             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1222             : 
    1223             :     // Fragment:
    1224             : 
    1225             :     bool clearFragment();
    1226             : 
    1227             :     bool setFragment(
    1228             :         OUString const & rTheMark, bool bOctets,
    1229             :         EncodeMechanism eMechanism, rtl_TextEncoding eCharset);
    1230             : 
    1231             :     // FILE URLs:
    1232             : 
    1233             :     TOOLS_DLLPRIVATE bool hasDosVolume(FSysStyle eStyle) const;
    1234             : 
    1235             :     // Coding:
    1236             : 
    1237     8240571 :     static inline sal_Char getEscapePrefix(INetProtocol eTheScheme)
    1238     8240571 :     { return eTheScheme == INET_PROT_VIM ? '=' : '%'; }
    1239             : 
    1240     8240571 :     inline sal_Char getEscapePrefix() const
    1241     8240571 :     { return getEscapePrefix(m_eScheme); }
    1242             : 
    1243             :     TOOLS_DLLPRIVATE static inline void appendEscape(
    1244             :         OUStringBuffer & rTheText, sal_Char cEscapePrefix,
    1245             :         sal_uInt32 nOctet);
    1246             : 
    1247             :     static OUString encodeText(
    1248             :         sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets,
    1249             :         Part ePart, sal_Char cEscapePrefix, EncodeMechanism eMechanism,
    1250             :         rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
    1251             : 
    1252             :     static inline OUString encodeText(
    1253             :         OUString const & rTheText, bool bOctets, Part ePart,
    1254             :         sal_Char cEscapePrefix, EncodeMechanism eMechanism,
    1255             :         rtl_TextEncoding eCharset, bool bKeepVisibleEscapes);
    1256             : 
    1257             :     static OUString decode(
    1258             :         sal_Unicode const * pBegin, sal_Unicode const * pEnd,
    1259             :         sal_Char cEscapePrefix, DecodeMechanism, rtl_TextEncoding eCharset);
    1260             : 
    1261             :     inline OUString decode(
    1262             :         SubString const & rSubString, sal_Char cEscapePrefix,
    1263             :         DecodeMechanism eMechanism, rtl_TextEncoding eCharset) const;
    1264             : 
    1265             :     // Specialized helpers:
    1266             : 
    1267             :     TOOLS_DLLPRIVATE static bool scanIPv6reference(
    1268             :         sal_Unicode const *& rBegin, sal_Unicode const * pEnd);
    1269             : 
    1270             : private:
    1271             :     void changeScheme(INetProtocol eTargetScheme);
    1272             : };
    1273             : 
    1274             : // static
    1275       42270 : inline OUString INetURLObject::encodeText(OUString const & rTheText,
    1276             :                                            bool bOctets, Part ePart,
    1277             :                                            sal_Char cEscapePrefix,
    1278             :                                            EncodeMechanism eMechanism,
    1279             :                                            rtl_TextEncoding eCharset,
    1280             :                                            bool bKeepVisibleEscapes)
    1281             : {
    1282             :     return encodeText(rTheText.getStr(),
    1283       42270 :                       rTheText.getStr() + rTheText.getLength(), bOctets, ePart,
    1284             :                       cEscapePrefix, eMechanism, eCharset,
    1285       84540 :                       bKeepVisibleEscapes);
    1286             : }
    1287             : 
    1288     4322479 : inline OUString INetURLObject::decode(SubString const & rSubString,
    1289             :                                        sal_Char cEscapePrefix,
    1290             :                                        DecodeMechanism eMechanism,
    1291             :                                        rtl_TextEncoding eCharset) const
    1292             : {
    1293     4322479 :     return rSubString.isPresent() ?
    1294      933730 :                decode(m_aAbsURIRef.getStr() + rSubString.getBegin(),
    1295      933730 :                       m_aAbsURIRef.getStr() + rSubString.getEnd(),
    1296             :                       cEscapePrefix, eMechanism, eCharset) :
    1297     6189939 :                OUString();
    1298             : }
    1299             : 
    1300     1754998 : inline INetURLObject::INetURLObject(OUString const & rTheAbsURIRef,
    1301             :                                     EncodeMechanism eMechanism,
    1302             :                                     rtl_TextEncoding eCharset):
    1303     1754998 :     m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
    1304             : {
    1305             :     setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
    1306     1754998 :                  FSysStyle(0));
    1307     1754998 : }
    1308             : 
    1309        6788 : inline bool INetURLObject::SetURL(OUString const & rTheAbsURIRef,
    1310             :                                   EncodeMechanism eMechanism,
    1311             :                                   rtl_TextEncoding eCharset)
    1312             : {
    1313             :     return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, false,
    1314        6788 :                         FSysStyle(0));
    1315             : }
    1316             : 
    1317       42520 : inline INetURLObject::INetURLObject(OUString const & rTheAbsURIRef,
    1318             :                                     INetProtocol eTheSmartScheme,
    1319             :                                     EncodeMechanism eMechanism,
    1320             :                                     rtl_TextEncoding eCharset,
    1321             :                                     FSysStyle eStyle):
    1322       42520 :     m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(eTheSmartScheme)
    1323             : {
    1324       42520 :     setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true, eStyle);
    1325       42520 : }
    1326             : 
    1327        1548 : inline bool INetURLObject::SetSmartURL(OUString const & rTheAbsURIRef,
    1328             :                                        EncodeMechanism eMechanism,
    1329             :                                        rtl_TextEncoding eCharset,
    1330             :                                        FSysStyle eStyle)
    1331             : {
    1332             :     return setAbsURIRef(rTheAbsURIRef, false, eMechanism, eCharset, true,
    1333        1548 :                         eStyle);
    1334             : }
    1335             : 
    1336             : inline INetURLObject
    1337         218 : INetURLObject::smartRel2Abs(OUString const & rTheRelURIRef,
    1338             :                             bool & rWasAbsolute,
    1339             :                             bool bIgnoreFragment,
    1340             :                             EncodeMechanism eMechanism,
    1341             :                             rtl_TextEncoding eCharset,
    1342             :                             bool bRelativeNonURIs,
    1343             :                             FSysStyle eStyle) const
    1344             : {
    1345         218 :     INetURLObject aTheAbsURIRef;
    1346             :     convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, rWasAbsolute,
    1347             :                     eMechanism, eCharset, bIgnoreFragment, true,
    1348         218 :                     bRelativeNonURIs, eStyle);
    1349         218 :     return aTheAbsURIRef;
    1350             : }
    1351             : 
    1352         214 : inline bool INetURLObject::GetNewAbsURL(OUString const & rTheRelURIRef,
    1353             :                                         INetURLObject * pTheAbsURIRef,
    1354             :                                         EncodeMechanism eMechanism,
    1355             :                                         rtl_TextEncoding eCharset,
    1356             :                                         FSysStyle eStyle, bool bIgnoreFragment)
    1357             :     const
    1358             : {
    1359         214 :     INetURLObject aTheAbsURIRef;
    1360             :     bool bWasAbsolute;
    1361         214 :     if (!convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, bWasAbsolute,
    1362             :                          eMechanism, eCharset, bIgnoreFragment, false, false,
    1363         214 :                          eStyle))
    1364           0 :         return false;
    1365         214 :     if (pTheAbsURIRef)
    1366         214 :         *pTheAbsURIRef = aTheAbsURIRef;
    1367         214 :     return true;
    1368             : }
    1369             : 
    1370             : // static
    1371         180 : inline OUString INetURLObject::GetRelURL(OUString const & rTheBaseURIRef,
    1372             :                                           OUString const & rTheAbsURIRef,
    1373             :                                           EncodeMechanism eEncodeMechanism,
    1374             :                                           DecodeMechanism eDecodeMechanism,
    1375             :                                           rtl_TextEncoding eCharset,
    1376             :                                           FSysStyle eStyle)
    1377             : {
    1378         180 :     OUString aTheRelURIRef;
    1379             :     INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset).
    1380             :         convertAbsToRel(rTheAbsURIRef, false, aTheRelURIRef, eEncodeMechanism,
    1381         180 :                         eDecodeMechanism, eCharset, eStyle);
    1382         180 :     return aTheRelURIRef;
    1383             : }
    1384             : 
    1385             : // static
    1386           0 : inline bool INetURLObject::translateToExternal(OUString const &
    1387             :                                                    rTheIntURIRef,
    1388             :                                                OUString & rTheExtURIRef,
    1389             :                                                DecodeMechanism
    1390             :                                                    eDecodeMechanism,
    1391             :                                                rtl_TextEncoding eCharset)
    1392             : {
    1393             :     return convertIntToExt(rTheIntURIRef, false, rTheExtURIRef,
    1394           0 :                            eDecodeMechanism, eCharset);
    1395             : }
    1396             : 
    1397             : // static
    1398           0 : inline bool INetURLObject::translateToInternal(OUString const &
    1399             :                                                    rTheExtURIRef,
    1400             :                                                OUString & rTheIntURIRef,
    1401             :                                                DecodeMechanism
    1402             :                                                    eDecodeMechanism,
    1403             :                                                rtl_TextEncoding eCharset)
    1404             : {
    1405             :     return convertExtToInt(rTheExtURIRef, false, rTheIntURIRef,
    1406           0 :                            eDecodeMechanism, eCharset);
    1407             : }
    1408             : 
    1409           0 : inline bool INetURLObject::SetPass(OUString const & rThePassword,
    1410             :                                    EncodeMechanism eMechanism,
    1411             :                                    rtl_TextEncoding eCharset)
    1412             : {
    1413           0 :     return rThePassword.isEmpty() ?
    1414             :                clearPassword() :
    1415           0 :                setPassword(rThePassword, false, eMechanism, eCharset);
    1416             : }
    1417             : 
    1418           0 : inline bool INetURLObject::SetUserAndPass(OUString const & rTheUser,
    1419             :                                           OUString const & rThePassword,
    1420             :                                           EncodeMechanism eMechanism,
    1421             :                                           rtl_TextEncoding eCharset)
    1422             : {
    1423           0 :     return setUser(rTheUser, false, eMechanism, eCharset)
    1424           0 :            && (rThePassword.isEmpty() ?
    1425           0 :                    clearPassword() :
    1426           0 :                    setPassword(rThePassword, false, eMechanism, eCharset));
    1427             : }
    1428             : 
    1429        5491 : inline bool INetURLObject::insertName(OUString const & rTheName,
    1430             :                                       bool bAppendFinalSlash,
    1431             :                                       sal_Int32 nIndex,
    1432             :                                       bool bIgnoreFinalSlash,
    1433             :                                       EncodeMechanism eMechanism,
    1434             :                                       rtl_TextEncoding eCharset)
    1435             : {
    1436             :     return insertName(rTheName, false, bAppendFinalSlash, nIndex,
    1437        5491 :                       bIgnoreFinalSlash, eMechanism, eCharset);
    1438             : }
    1439             : 
    1440      659377 : inline bool INetURLObject::SetParam(OUString const & rTheQuery,
    1441             :                                     EncodeMechanism eMechanism,
    1442             :                                     rtl_TextEncoding eCharset)
    1443             : {
    1444      659377 :     return rTheQuery.isEmpty() ?
    1445             :                clearQuery() :
    1446      659377 :                setQuery(rTheQuery, false, eMechanism, eCharset);
    1447             : }
    1448             : 
    1449      671701 : inline bool INetURLObject::SetMark(OUString const & rTheFragment,
    1450             :                                    EncodeMechanism eMechanism,
    1451             :                                    rtl_TextEncoding eCharset)
    1452             : {
    1453      671701 :     return rTheFragment.isEmpty() ?
    1454             :                clearFragment() :
    1455      671701 :                setFragment(rTheFragment, false, eMechanism, eCharset);
    1456             : }
    1457             : 
    1458           0 : inline INetURLObject::INetURLObject(OUString const & rFSysPath,
    1459             :                                     FSysStyle eStyle):
    1460           0 :     m_eScheme(INET_PROT_NOT_VALID), m_eSmartScheme(INET_PROT_HTTP)
    1461             : {
    1462           0 :     setFSysPath(rFSysPath, eStyle);
    1463           0 : }
    1464             : 
    1465             : // static
    1466        3732 : inline OUString INetURLObject::encode(OUString const & rText, Part ePart,
    1467             :                                        sal_Char cEscapePrefix,
    1468             :                                        EncodeMechanism eMechanism,
    1469             :                                        rtl_TextEncoding eCharset)
    1470             : {
    1471             :     return encodeText(rText, false, ePart, cEscapePrefix, eMechanism,
    1472        3732 :                       eCharset, false);
    1473             : }
    1474             : 
    1475             : // static
    1476         504 : inline OUString INetURLObject::decode(OUString const & rText,
    1477             :                                        sal_Char cEscapePrefix,
    1478             :                                        DecodeMechanism eMechanism,
    1479             :                                        rtl_TextEncoding eCharset)
    1480             : {
    1481         504 :     return decode(rText.getStr(), rText.getStr() + rText.getLength(),
    1482        1008 :                   cEscapePrefix, eMechanism, eCharset);
    1483             : }
    1484             : 
    1485     1639700 : inline OUString INetURLObject::decode(OUStringBuffer const & rText,
    1486             :                                        sal_Char cEscapePrefix,
    1487             :                                        DecodeMechanism eMechanism,
    1488             :                                        rtl_TextEncoding eCharset)
    1489             : {
    1490     1639700 :     return decode(rText.getStr(), rText.getStr() + rText.getLength(),
    1491     3279400 :                   cEscapePrefix, eMechanism, eCharset);
    1492             : }
    1493             : 
    1494             : #endif
    1495             : 
    1496             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10