1*89b56da7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*89b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*89b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*89b56da7SAndrew Rist * distributed with this work for additional information 6*89b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*89b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*89b56da7SAndrew Rist * "License"); you may not use this file except in compliance 9*89b56da7SAndrew Rist * with the License. You may obtain a copy of the License at 10*89b56da7SAndrew Rist * 11*89b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*89b56da7SAndrew Rist * 13*89b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*89b56da7SAndrew Rist * software distributed under the License is distributed on an 15*89b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*89b56da7SAndrew Rist * KIND, either express or implied. See the License for the 17*89b56da7SAndrew Rist * specific language governing permissions and limitations 18*89b56da7SAndrew Rist * under the License. 19*89b56da7SAndrew Rist * 20*89b56da7SAndrew Rist *************************************************************/ 21*89b56da7SAndrew Rist 22*89b56da7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_tools.hxx" 26cdf0e10cSrcweir #include <tools/urlobj.hxx> 27cdf0e10cSrcweir #include <tools/debug.hxx> 28cdf0e10cSrcweir #include <tools/inetmime.hxx> 29cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 30cdf0e10cSrcweir #include "com/sun/star/util/XStringWidth.hpp" 31cdf0e10cSrcweir #include "osl/diagnose.h" 32cdf0e10cSrcweir #include "osl/file.hxx" 33cdf0e10cSrcweir #include "rtl/string.h" 34cdf0e10cSrcweir #include "rtl/textenc.h" 35cdf0e10cSrcweir #include "rtl/ustring.hxx" 36cdf0e10cSrcweir #include "sal/types.h" 37cdf0e10cSrcweir 38cdf0e10cSrcweir #ifndef INCLUDED_ALGORITHM 39cdf0e10cSrcweir #include <algorithm> 40cdf0e10cSrcweir #define INCLUDED_ALGORITHM 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #ifndef INCLUDED_LIMITS 43cdf0e10cSrcweir #include <limits> 44cdf0e10cSrcweir #define INCLUDED_LIMITS 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include <string.h> 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace unnamed_tools_urlobj {} using namespace unnamed_tools_urlobj; 50cdf0e10cSrcweir // unnamed namespaces don't work well yet... 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace com::sun; 53cdf0e10cSrcweir 54cdf0e10cSrcweir //============================================================================ 55cdf0e10cSrcweir // 56cdf0e10cSrcweir // INetURLObject 57cdf0e10cSrcweir // 58cdf0e10cSrcweir //============================================================================ 59cdf0e10cSrcweir 60cdf0e10cSrcweir /* The URI grammar (using RFC 2234 conventions). 61cdf0e10cSrcweir 62cdf0e10cSrcweir Constructs of the form 63cdf0e10cSrcweir {reference <rule1> using rule2} 64cdf0e10cSrcweir stand for a rule matching the given rule1 specified in the given reference, 65cdf0e10cSrcweir encoded to URI syntax using rule2 (as specified in this URI grammar). 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir ; RFC 1738, RFC 2396, RFC 2732, private 69cdf0e10cSrcweir login = [user [":" password] "@"] hostport 70cdf0e10cSrcweir user = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ";" / "=" / "_" / "~") 71cdf0e10cSrcweir password = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ";" / "=" / "_" / "~") 72cdf0e10cSrcweir hostport = host [":" port] 73cdf0e10cSrcweir host = incomplete-hostname / hostname / IPv4address / IPv6reference 74cdf0e10cSrcweir incomplete-hostname = *(domainlabel ".") domainlabel 75cdf0e10cSrcweir hostname = *(domainlabel ".") toplabel ["."] 76cdf0e10cSrcweir domainlabel = alphanum [*(alphanum / "-") alphanum] 77cdf0e10cSrcweir toplabel = ALPHA [*(alphanum / "-") alphanum] 78cdf0e10cSrcweir IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT 79cdf0e10cSrcweir IPv6reference = "[" hexpart [":" IPv4address] "]" 80cdf0e10cSrcweir hexpart = (hexseq ["::" [hexseq]]) / ("::" [hexseq]) 81cdf0e10cSrcweir hexseq = hex4 *(":" hex4) 82cdf0e10cSrcweir hex4 = 1*4HEXDIG 83cdf0e10cSrcweir port = *DIGIT 84cdf0e10cSrcweir escaped = "%" HEXDIG HEXDIG 85cdf0e10cSrcweir reserved = "$" / "&" / "+" / "," / "/" / ":" / ";" / "=" / "?" / "@" / "[" / "]" 86cdf0e10cSrcweir mark = "!" / "'" / "(" / ")" / "*" / "-" / "." / "_" / "~" 87cdf0e10cSrcweir alphanum = ALPHA / DIGIT 88cdf0e10cSrcweir unreserved = alphanum / mark 89cdf0e10cSrcweir uric = escaped / reserved / unreserved 90cdf0e10cSrcweir pchar = escaped / unreserved / "$" / "&" / "+" / "," / ":" / "=" / "@" 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir ; RFC 1738, RFC 2396 94cdf0e10cSrcweir ftp-url = "FTP://" login ["/" segment *("/" segment) [";TYPE=" ("A" / "D" / "I")]] 95cdf0e10cSrcweir segment = *pchar 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir ; RFC 1738, RFC 2396 99cdf0e10cSrcweir http-url = "HTTP://" hostport ["/" segment *("/" segment) ["?" *uric]] 100cdf0e10cSrcweir segment = *(pchar / ";") 101cdf0e10cSrcweir 102cdf0e10cSrcweir 103cdf0e10cSrcweir ; RFC 1738, RFC 2396, <http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q188997&> 104cdf0e10cSrcweir file-url = "FILE://" [host / "LOCALHOST" / netbios-name] ["/" segment *("/" segment)] 105cdf0e10cSrcweir segment = *pchar 106cdf0e10cSrcweir netbios-name = 1*{<alphanum / "!" / "#" / "$" / "%" / "&" / "'" / "(" / ")" / "-" / "." / "@" / "^" / "_" / "{" / "}" / "~"> using (escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "-" / "." / "@" / "_" / "~")} 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir ; RFC 2368, RFC 2396 110cdf0e10cSrcweir mailto-url = "MAILTO:" [to] [headers] 111cdf0e10cSrcweir to = {RFC 822 <#mailbox> using *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "@" / "_" / "~")} 112cdf0e10cSrcweir headers = "?" header *("&" header) 113cdf0e10cSrcweir header = hname "=" hvalue 114cdf0e10cSrcweir hname = {RFC 822 <field-name> using *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "@" / "_" / "~")} / "BODY" 115cdf0e10cSrcweir hvalue = {RFC 822 <field-body> using *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "@" / "_" / "~")} 116cdf0e10cSrcweir 117cdf0e10cSrcweir 118cdf0e10cSrcweir ; private (see RFC 1738, RFC 2396) 119cdf0e10cSrcweir vnd-sun-star-webdav-url = "VND.SUN.STAR.WEBDAV://" hostport ["/" segment *("/" segment) ["?" *uric]] 120cdf0e10cSrcweir segment = *(pchar / ";") 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir ; RFC 1738, RFC 2396, RFC 2732 124cdf0e10cSrcweir news-url = "NEWS:" grouppart 125cdf0e10cSrcweir grouppart = "*" / group / article 126cdf0e10cSrcweir group = alpha *(alphanum / "+" / "-" / "." / "_") 127cdf0e10cSrcweir article = 1*(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "?" / "_" / "~") "@" host 128cdf0e10cSrcweir 129cdf0e10cSrcweir 130cdf0e10cSrcweir ; private 131cdf0e10cSrcweir private-url = "PRIVATE:" path ["?" *uric] 132cdf0e10cSrcweir path = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~") 133cdf0e10cSrcweir 134cdf0e10cSrcweir 135cdf0e10cSrcweir ; private 136cdf0e10cSrcweir vnd-sun-star-help-url = "VND.SUN.STAR.HELP://" name *("/" segment) ["?" *uric] 137cdf0e10cSrcweir name = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") 138cdf0e10cSrcweir segment = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir ; private 142cdf0e10cSrcweir https-url = "HTTPS://" hostport ["/" segment *("/" segment) ["?" *uric]] 143cdf0e10cSrcweir segment = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir ; private 147cdf0e10cSrcweir slot-url = "SLOT:" path ["?" *uric] 148cdf0e10cSrcweir path = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~") 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir ; private 152cdf0e10cSrcweir macro-url = "MACRO:" path ["?" *uric] 153cdf0e10cSrcweir path = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~") 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir ; private 157cdf0e10cSrcweir javascript-url = "JAVASCRIPT:" *uric 158cdf0e10cSrcweir 159cdf0e10cSrcweir 160cdf0e10cSrcweir ; private (see RFC 2192) 161cdf0e10cSrcweir imap-url = "IMAP://" user [";AUTH=" auth] "@" hostport "/" segment *("/" segment) ["/;UID=" nz_number] 162cdf0e10cSrcweir user = 1*{RFC 2060 <CHAR8> using (escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "=" / "_" / "~")} 163cdf0e10cSrcweir auth = {RFC 2060 <atom> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "+" / "," / "-" / "." / "=" / "_" / "~")} 164cdf0e10cSrcweir segment = *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / "=" / "@" / "_" / "~") 165cdf0e10cSrcweir nz_number = {RFC 2060 <nz_number> using *DIGIT} 166cdf0e10cSrcweir 167cdf0e10cSrcweir 168cdf0e10cSrcweir ; private 169cdf0e10cSrcweir pop3-url = "POP3://" login ["/" ["<" *uric ">"]] 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir ; RFC 2397 173cdf0e10cSrcweir data-url = "DATA:" [mediatype] [";BASE64"] "," *uric 174cdf0e10cSrcweir mediatype = [type "/" subtype] *(";" attribute "=" value) 175cdf0e10cSrcweir type = {RFC 2045 <type> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / ":" / "?" / "@" / "_" / "~")} 176cdf0e10cSrcweir subtype = {RFC 2045 <subtype> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / ":" / "?" / "@" / "_" / "~")} 177cdf0e10cSrcweir attribute = {RFC 2045 <subtype> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / ":" / "?" / "@" / "_" / "~")} 178cdf0e10cSrcweir value = {RFC 2045 <subtype> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / ":" / "?" / "@" / "_" / "~")} 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir ; RFC 2392, RFC 2396 182cdf0e10cSrcweir cid-url = "CID:" {RFC 822 <addr-spec> using *uric} 183cdf0e10cSrcweir 184cdf0e10cSrcweir 185cdf0e10cSrcweir ; private 186cdf0e10cSrcweir out-url = "OUT:///~" name ["/" *uric] 187cdf0e10cSrcweir name = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "?" / "@" / "_" / "~" 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweir ; private 191cdf0e10cSrcweir vnd-sun-star-hier-url = "VND.SUN.STAR.HIER:" ["//"reg_name] *("/" *pchar) 192cdf0e10cSrcweir reg_name = 1*(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") 193cdf0e10cSrcweir 194cdf0e10cSrcweir ; private 195cdf0e10cSrcweir vim-url = "VIM://" +vimc [":" *vimc] ["/" [("INBOX" message) / ("NEWSGROUPS" ["/" [+vimc message]])]] 196cdf0e10cSrcweir message = ["/" [+vimc [":" +DIGIT "." +DIGIT "." +DIGIT]]] 197cdf0e10cSrcweir vimc = ("=" HEXDIG HEXDIG) / alphanum 198cdf0e10cSrcweir 199cdf0e10cSrcweir 200cdf0e10cSrcweir ; private 201cdf0e10cSrcweir uno-url = ".UNO:" path ["?" *uric] 202cdf0e10cSrcweir path = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~") 203cdf0e10cSrcweir 204cdf0e10cSrcweir 205cdf0e10cSrcweir ; private 206cdf0e10cSrcweir component-url = ".COMPONENT:" path ["?" *uric] 207cdf0e10cSrcweir path = *(escaped / alphanum / "!" / "$" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~") 208cdf0e10cSrcweir 209cdf0e10cSrcweir 210cdf0e10cSrcweir ; private 211cdf0e10cSrcweir vnd-sun-star-pkg-url = "VND.SUN.STAR.PKG://" reg_name *("/" *pchar) ["?" *uric] 212cdf0e10cSrcweir reg_name = 1*(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / ":" / ";" / "=" / "@" / "_" / "~") 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweir ; RFC 2255 216cdf0e10cSrcweir ldap-url = "LDAP://" [hostport] ["/" [dn ["?" [attrdesct *("," attrdesc)] ["?" ["base" / "one" / "sub"] ["?" [filter] ["?" extension *("," extension)]]]]]] 217cdf0e10cSrcweir dn = {RFC 2253 <distinguishedName> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~")} 218cdf0e10cSrcweir attrdesc = {RFC 2251 <AttributeDescription> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~")} 219cdf0e10cSrcweir filter = {RFC 2254 <filter> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~")} 220cdf0e10cSrcweir extension = ["!"] ["X-"] extoken ["=" exvalue] 221cdf0e10cSrcweir extoken = {RFC 2252 <oid> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / "/" / ":" / ";" / "@" / "_" / "~")} 222cdf0e10cSrcweir exvalue = {RFC 2251 <LDAPString> using *(escaped / alphanum / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "-" / "." / "/" / ":" / ";" / "=" / "@" / "_" / "~")} 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir ; private 226cdf0e10cSrcweir db-url = "DB:" *uric 227cdf0e10cSrcweir 228cdf0e10cSrcweir 229cdf0e10cSrcweir ; private 230cdf0e10cSrcweir vnd-sun-star-cmd-url = "VND.SUN.STAR.CMD:" opaque_part 231cdf0e10cSrcweir opaque_part = uric_no_slash *uric 232cdf0e10cSrcweir uric_no_slash = unreserved / escaped / ";" / "?" / ":" / "@" / "&" / "=" / "+" / "$" / "," 233cdf0e10cSrcweir 234cdf0e10cSrcweir 235cdf0e10cSrcweir ; private 236cdf0e10cSrcweir vnd-sun-star-url = "VND.SUN.STAR.ODMA:" ["/" *uric_no_slash] 237cdf0e10cSrcweir uric_no_slash = unreserved / escaped / ";" / "?" / ":" / "@" / "&" / "=" / "+" / "$" / "," 238cdf0e10cSrcweir 239cdf0e10cSrcweir 240cdf0e10cSrcweir ; RFC 1738 241cdf0e10cSrcweir telnet-url = "TELNET://" login ["/"] 242cdf0e10cSrcweir 243cdf0e10cSrcweir 244cdf0e10cSrcweir ; private 245cdf0e10cSrcweir vnd-sun-star-expand-url = "VND.SUN.STAR.EXPAND:" opaque_part 246cdf0e10cSrcweir opaque_part = uric_no_slash *uric 247cdf0e10cSrcweir uric_no_slash = unreserved / escaped / ";" / "?" / ":" / "@" / "&" / "=" / "+" / "$" / "," 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250cdf0e10cSrcweir ; private 251cdf0e10cSrcweir vnd-sun-star-tdoc-url = "VND.SUN.STAR.TDOC:/" segment *("/" segment) 252cdf0e10cSrcweir segment = *pchar 253cdf0e10cSrcweir 254cdf0e10cSrcweir 255cdf0e10cSrcweir ; private 256cdf0e10cSrcweir unknown-url = scheme ":" 1*uric 257cdf0e10cSrcweir scheme = ALPHA *(alphanum / "+" / "-" / ".") 258cdf0e10cSrcweir 259cdf0e10cSrcweir 260cdf0e10cSrcweir ; private (http://ubiqx.org/cifs/Appendix-D.html): 261cdf0e10cSrcweir smb-url = "SMB://" login ["/" segment *("/" segment) ["?" *uric]] 262cdf0e10cSrcweir segment = *(pchar / ";") 263cdf0e10cSrcweir */ 264cdf0e10cSrcweir 265cdf0e10cSrcweir //============================================================================ 266cdf0e10cSrcweir inline sal_Int32 INetURLObject::SubString::clear() 267cdf0e10cSrcweir { 268cdf0e10cSrcweir sal_Int32 nDelta = -m_nLength; 269cdf0e10cSrcweir m_nBegin = -1; 270cdf0e10cSrcweir m_nLength = 0; 271cdf0e10cSrcweir return nDelta; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir inline sal_Int32 INetURLObject::SubString::set(rtl::OUStringBuffer & rString, 275cdf0e10cSrcweir rtl::OUString const & rSubString) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir rtl::OUString sTemp(rString.makeStringAndClear()); 278cdf0e10cSrcweir sal_Int32 nDelta = set(sTemp, rSubString); 279cdf0e10cSrcweir rString.append(sTemp); 280cdf0e10cSrcweir return nDelta; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir inline sal_Int32 INetURLObject::SubString::set(rtl::OUString & rString, 284cdf0e10cSrcweir rtl::OUString const & rSubString) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir sal_Int32 nDelta = rSubString.getLength() - m_nLength; 287cdf0e10cSrcweir 288cdf0e10cSrcweir rString = rString.replaceAt(m_nBegin, m_nLength, rSubString); 289cdf0e10cSrcweir 290cdf0e10cSrcweir m_nLength = rSubString.getLength(); 291cdf0e10cSrcweir return nDelta; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir inline sal_Int32 INetURLObject::SubString::set(rtl::OUStringBuffer & rString, 295cdf0e10cSrcweir rtl::OUString const & rSubString, 296cdf0e10cSrcweir sal_Int32 nTheBegin) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir m_nBegin = nTheBegin; 299cdf0e10cSrcweir return set(rString, rSubString); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir //============================================================================ 303cdf0e10cSrcweir inline void INetURLObject::SubString::operator +=(sal_Int32 nDelta) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir if (isPresent()) 306cdf0e10cSrcweir m_nBegin = m_nBegin + nDelta; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir //============================================================================ 310cdf0e10cSrcweir int INetURLObject::SubString::compare(SubString const & rOther, 311cdf0e10cSrcweir rtl::OUStringBuffer const & rThisString, 312cdf0e10cSrcweir rtl::OUStringBuffer const & rOtherString) const 313cdf0e10cSrcweir { 314cdf0e10cSrcweir sal_Int32 len = std::min(m_nLength, rOther.m_nLength); 315cdf0e10cSrcweir sal_Unicode const * p1 = rThisString.getStr() + m_nBegin; 316cdf0e10cSrcweir sal_Unicode const * end = p1 + len; 317cdf0e10cSrcweir sal_Unicode const * p2 = rOtherString.getStr() + rOther.m_nBegin; 318cdf0e10cSrcweir while (p1 != end) { 319cdf0e10cSrcweir if (*p1 < *p2) { 320cdf0e10cSrcweir return -1; 321cdf0e10cSrcweir } else if (*p1 > *p2) { 322cdf0e10cSrcweir return 1; 323cdf0e10cSrcweir } 324cdf0e10cSrcweir ++p1; 325cdf0e10cSrcweir ++p2; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir return m_nLength < rOther.m_nLength ? -1 328cdf0e10cSrcweir : m_nLength > rOther.m_nLength ? 1 329cdf0e10cSrcweir : 0; 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir //============================================================================ 333cdf0e10cSrcweir struct INetURLObject::SchemeInfo 334cdf0e10cSrcweir { 335cdf0e10cSrcweir sal_Char const * m_pScheme; 336cdf0e10cSrcweir sal_Char const * m_pPrefix; 337cdf0e10cSrcweir sal_uInt16 m_nDefaultPort; 338cdf0e10cSrcweir bool m_bAuthority; 339cdf0e10cSrcweir bool m_bUser; 340cdf0e10cSrcweir bool m_bAuth; 341cdf0e10cSrcweir bool m_bPassword; 342cdf0e10cSrcweir bool m_bHost; 343cdf0e10cSrcweir bool m_bPort; 344cdf0e10cSrcweir bool m_bHierarchical; 345cdf0e10cSrcweir bool m_bQuery; 346cdf0e10cSrcweir }; 347cdf0e10cSrcweir 348cdf0e10cSrcweir //============================================================================ 349cdf0e10cSrcweir struct INetURLObject::PrefixInfo 350cdf0e10cSrcweir { 351cdf0e10cSrcweir enum Kind { OFFICIAL, INTERNAL, EXTERNAL, ALIAS }; // order is important! 352cdf0e10cSrcweir 353cdf0e10cSrcweir sal_Char const * m_pPrefix; 354cdf0e10cSrcweir sal_Char const * m_pTranslatedPrefix; 355cdf0e10cSrcweir INetProtocol m_eScheme; 356cdf0e10cSrcweir Kind m_eKind; 357cdf0e10cSrcweir }; 358cdf0e10cSrcweir 359cdf0e10cSrcweir //============================================================================ 360cdf0e10cSrcweir static INetURLObject::SchemeInfo const aSchemeInfoMap[INET_PROT_END] 361cdf0e10cSrcweir = { { "", "", 0, false, false, false, false, false, false, false, 362cdf0e10cSrcweir false }, 363cdf0e10cSrcweir { "ftp", "ftp://", 21, true, true, false, true, true, true, true, 364cdf0e10cSrcweir false }, 365cdf0e10cSrcweir { "http", "http://", 80, true, false, false, false, true, true, 366cdf0e10cSrcweir true, true }, 367cdf0e10cSrcweir { "file", "file://", 0, true, false, false, false, true, false, 368cdf0e10cSrcweir true, false }, 369cdf0e10cSrcweir { "mailto", "mailto:", 0, false, false, false, false, false, 370cdf0e10cSrcweir false, false, true }, 371cdf0e10cSrcweir { "vnd.sun.star.webdav", "vnd.sun.star.webdav://", 80, true, false, 372cdf0e10cSrcweir false, false, true, true, true, true }, 373cdf0e10cSrcweir { "news", "news:", 0, false, false, false, false, false, false, false, 374cdf0e10cSrcweir false }, 375cdf0e10cSrcweir { "private", "private:", 0, false, false, false, false, false, 376cdf0e10cSrcweir false, false, true }, 377cdf0e10cSrcweir { "vnd.sun.star.help", "vnd.sun.star.help://", 0, true, false, false, 378cdf0e10cSrcweir false, false, false, true, true }, 379cdf0e10cSrcweir { "https", "https://", 443, true, false, false, false, true, true, 380cdf0e10cSrcweir true, true }, 381cdf0e10cSrcweir { "slot", "slot:", 0, false, false, false, false, false, false, 382cdf0e10cSrcweir false, true }, 383cdf0e10cSrcweir { "macro", "macro:", 0, false, false, false, false, false, false, 384cdf0e10cSrcweir false, true }, 385cdf0e10cSrcweir { "javascript", "javascript:", 0, false, false, false, false, 386cdf0e10cSrcweir false, false, false, false }, 387cdf0e10cSrcweir { "imap", "imap://", 143, true, true, true, false, true, true, 388cdf0e10cSrcweir true, false }, 389cdf0e10cSrcweir { "pop3", "pop3://", 110, true, true, false, true, true, true, 390cdf0e10cSrcweir false, false }, 391cdf0e10cSrcweir { "data", "data:", 0, false, false, false, false, false, false, 392cdf0e10cSrcweir false, false }, 393cdf0e10cSrcweir { "cid", "cid:", 0, false, false, false, false, false, false, 394cdf0e10cSrcweir false, false }, 395cdf0e10cSrcweir { "out", "out://", 0, true, false, false, false, false, false, 396cdf0e10cSrcweir false, false }, 397cdf0e10cSrcweir { "vnd.sun.star.hier", "vnd.sun.star.hier:", 0, true, false, false, 398cdf0e10cSrcweir false, false, false, true, false }, 399cdf0e10cSrcweir { "vim", "vim://", 0, true, true, false, true, false, false, true, 400cdf0e10cSrcweir false }, 401cdf0e10cSrcweir { ".uno", ".uno:", 0, false, false, false, false, false, false, 402cdf0e10cSrcweir false, true }, 403cdf0e10cSrcweir { ".component", ".component:", 0, false, false, false, false, 404cdf0e10cSrcweir false, false, false, true }, 405cdf0e10cSrcweir { "vnd.sun.star.pkg", "vnd.sun.star.pkg://", 0, true, false, false, 406cdf0e10cSrcweir false, false, false, true, true }, 407cdf0e10cSrcweir { "ldap", "ldap://", 389, true, false, false, false, true, true, 408cdf0e10cSrcweir false, true }, 409cdf0e10cSrcweir { "db", "db:", 0, false, false, false, false, false, false, false, 410cdf0e10cSrcweir false }, 411cdf0e10cSrcweir { "vnd.sun.star.cmd", "vnd.sun.star.cmd:", 0, false, false, false, 412cdf0e10cSrcweir false, false, false, false, false }, 413cdf0e10cSrcweir { "vnd.sun.star.odma", "vnd.sun.star.odma:", 0, false, false, false, 414cdf0e10cSrcweir false, false, false, true, false }, 415cdf0e10cSrcweir { "telnet", "telnet://", 23, true, true, false, true, true, true, true, 416cdf0e10cSrcweir false }, 417cdf0e10cSrcweir { "vnd.sun.star.expand", "vnd.sun.star.expand:", 0, false, false, false, 418cdf0e10cSrcweir false, false, false, false, false }, 419cdf0e10cSrcweir { "vnd.sun.star.tdoc", "vnd.sun.star.tdoc:", 0, false, false, false, 420cdf0e10cSrcweir false, false, false, true, false }, 421cdf0e10cSrcweir { "", "", 0, false, false, false, false, true, true, true, false }, 422cdf0e10cSrcweir { "smb", "smb://", 139, true, true, false, true, true, true, true, 423cdf0e10cSrcweir true }, 424cdf0e10cSrcweir { "hid", "hid:", 0, false, false, false, false, false, false, 425cdf0e10cSrcweir false, true } }; 426cdf0e10cSrcweir 427cdf0e10cSrcweir // static 428cdf0e10cSrcweir inline INetURLObject::SchemeInfo const & 429cdf0e10cSrcweir INetURLObject::getSchemeInfo(INetProtocol eTheScheme) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir return aSchemeInfoMap[eTheScheme]; 432cdf0e10cSrcweir }; 433cdf0e10cSrcweir 434cdf0e10cSrcweir //============================================================================ 435cdf0e10cSrcweir inline INetURLObject::SchemeInfo const & INetURLObject::getSchemeInfo() const 436cdf0e10cSrcweir { 437cdf0e10cSrcweir return getSchemeInfo(m_eScheme); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir //============================================================================ 441cdf0e10cSrcweir // static 442cdf0e10cSrcweir inline void INetURLObject::appendEscape(rtl::OUStringBuffer & rTheText, 443cdf0e10cSrcweir sal_Char cEscapePrefix, 444cdf0e10cSrcweir sal_uInt32 nOctet) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir rTheText.append(sal_Unicode(cEscapePrefix)); 447cdf0e10cSrcweir rTheText.append(sal_Unicode(INetMIME::getHexDigit(int(nOctet >> 4)))); 448cdf0e10cSrcweir rTheText.append(sal_Unicode(INetMIME::getHexDigit(int(nOctet & 15)))); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir //============================================================================ 452cdf0e10cSrcweir namespace unnamed_tools_urlobj { 453cdf0e10cSrcweir 454cdf0e10cSrcweir enum 455cdf0e10cSrcweir { 456cdf0e10cSrcweir PA = INetURLObject::PART_OBSOLETE_NORMAL, 457cdf0e10cSrcweir PB = INetURLObject::PART_OBSOLETE_FILE, 458cdf0e10cSrcweir PC = INetURLObject::PART_OBSOLETE_PARAM, 459cdf0e10cSrcweir PD = INetURLObject::PART_USER_PASSWORD, 460cdf0e10cSrcweir PE = INetURLObject::PART_IMAP_ACHAR, 461cdf0e10cSrcweir PF = INetURLObject::PART_VIM, 462cdf0e10cSrcweir PG = INetURLObject::PART_HOST_EXTRA, 463cdf0e10cSrcweir PH = INetURLObject::PART_FPATH, 464cdf0e10cSrcweir PI = INetURLObject::PART_AUTHORITY, 465cdf0e10cSrcweir PJ = INetURLObject::PART_PATH_SEGMENTS_EXTRA, 466cdf0e10cSrcweir PK = INetURLObject::PART_REL_SEGMENT_EXTRA, 467cdf0e10cSrcweir PL = INetURLObject::PART_URIC, 468cdf0e10cSrcweir PM = INetURLObject::PART_HTTP_PATH, 469cdf0e10cSrcweir PN = INetURLObject::PART_FILE_SEGMENT_EXTRA, 470cdf0e10cSrcweir PO = INetURLObject::PART_MESSAGE_ID, 471cdf0e10cSrcweir PP = INetURLObject::PART_MESSAGE_ID_PATH, 472cdf0e10cSrcweir PQ = INetURLObject::PART_MAILTO, 473cdf0e10cSrcweir PR = INetURLObject::PART_PATH_BEFORE_QUERY, 474cdf0e10cSrcweir PS = INetURLObject::PART_PCHAR, 475cdf0e10cSrcweir PT = INetURLObject::PART_FRAGMENT, 476cdf0e10cSrcweir PU = INetURLObject::PART_VISIBLE, 477cdf0e10cSrcweir PV = INetURLObject::PART_VISIBLE_NONSPECIAL, 478cdf0e10cSrcweir PW = INetURLObject::PART_CREATEFRAGMENT, 479cdf0e10cSrcweir PX = INetURLObject::PART_UNO_PARAM_VALUE, 480cdf0e10cSrcweir PY = INetURLObject::PART_UNAMBIGUOUS, 481cdf0e10cSrcweir PZ = INetURLObject::PART_URIC_NO_SLASH, 482cdf0e10cSrcweir P1 = INetURLObject::PART_HTTP_QUERY, 483cdf0e10cSrcweir P2 = INetURLObject::PART_NEWS_ARTICLE_LOCALPART 484cdf0e10cSrcweir }; 485cdf0e10cSrcweir 486cdf0e10cSrcweir static sal_uInt32 const aMustEncodeMap[128] 487cdf0e10cSrcweir = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 488cdf0e10cSrcweir 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 489cdf0e10cSrcweir /* */ PY, 490cdf0e10cSrcweir /* ! */ PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 491cdf0e10cSrcweir /* " */ PU+PV +PY, 492cdf0e10cSrcweir /* # */ PU, 493cdf0e10cSrcweir /* $ */ PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 494cdf0e10cSrcweir /* % */ PU, 495cdf0e10cSrcweir /* & */ PA+PB+PC+PD+PE +PH+PI+PJ+PK+PL+PM+PN+PO+PP +PR+PS+PT+PU+PV+PW+PX +PZ+P1+P2, 496cdf0e10cSrcweir /* ' */ PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 497cdf0e10cSrcweir /* ( */ PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 498cdf0e10cSrcweir /* ) */ PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 499cdf0e10cSrcweir /* * */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 500cdf0e10cSrcweir /* + */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX +PZ+P1+P2, 501cdf0e10cSrcweir /* , */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW +PZ+P1+P2, 502cdf0e10cSrcweir /* - */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 503cdf0e10cSrcweir /* . */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 504cdf0e10cSrcweir /* / */ PA+PB+PC +PH +PJ +PL+PM +PP+PQ+PR +PT+PU+PV +PX +P2, 505cdf0e10cSrcweir /* 0 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 506cdf0e10cSrcweir /* 1 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 507cdf0e10cSrcweir /* 2 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 508cdf0e10cSrcweir /* 3 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 509cdf0e10cSrcweir /* 4 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 510cdf0e10cSrcweir /* 5 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 511cdf0e10cSrcweir /* 6 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 512cdf0e10cSrcweir /* 7 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 513cdf0e10cSrcweir /* 8 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 514cdf0e10cSrcweir /* 9 */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 515cdf0e10cSrcweir /* : */ PB+PC +PH+PI+PJ +PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX +PZ+P1+P2, 516cdf0e10cSrcweir /* ; */ PC+PD +PI+PJ+PK+PL+PM +PO+PP+PQ+PR +PT+PU +PW +PZ+P1+P2, 517cdf0e10cSrcweir /* < */ PC +PO+PP +PU+PV +PY, 518cdf0e10cSrcweir /* = */ PA+PB+PC+PD+PE +PH+PI+PJ+PK+PL+PM+PN +PR+PS+PT+PU+PV+PW +PZ+P1+P2, 519cdf0e10cSrcweir /* > */ PC +PO+PP +PU+PV +PY, 520cdf0e10cSrcweir /* ? */ PC +PL +PT+PU +PW+PX +PZ +P2, 521cdf0e10cSrcweir /* @ */ PC +PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1, 522cdf0e10cSrcweir /* A */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 523cdf0e10cSrcweir /* B */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 524cdf0e10cSrcweir /* C */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 525cdf0e10cSrcweir /* D */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 526cdf0e10cSrcweir /* E */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 527cdf0e10cSrcweir /* F */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 528cdf0e10cSrcweir /* G */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 529cdf0e10cSrcweir /* H */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 530cdf0e10cSrcweir /* I */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 531cdf0e10cSrcweir /* J */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 532cdf0e10cSrcweir /* K */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 533cdf0e10cSrcweir /* L */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 534cdf0e10cSrcweir /* M */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 535cdf0e10cSrcweir /* N */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 536cdf0e10cSrcweir /* O */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 537cdf0e10cSrcweir /* P */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 538cdf0e10cSrcweir /* Q */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 539cdf0e10cSrcweir /* R */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 540cdf0e10cSrcweir /* S */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 541cdf0e10cSrcweir /* T */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 542cdf0e10cSrcweir /* U */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 543cdf0e10cSrcweir /* V */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 544cdf0e10cSrcweir /* W */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 545cdf0e10cSrcweir /* X */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 546cdf0e10cSrcweir /* Y */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 547cdf0e10cSrcweir /* Z */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 548cdf0e10cSrcweir /* [ */ PL +PU+PV +PX, 549cdf0e10cSrcweir /* \ */ PB +PU+PV +PY, 550cdf0e10cSrcweir /* ] */ PL +PU+PV +PX, 551cdf0e10cSrcweir /* ^ */ PU+PV +PY, 552cdf0e10cSrcweir /* _ */ PA+PB+PC+PD+PE +PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 553cdf0e10cSrcweir /* ` */ PU+PV +PY, 554cdf0e10cSrcweir /* a */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 555cdf0e10cSrcweir /* b */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 556cdf0e10cSrcweir /* c */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 557cdf0e10cSrcweir /* d */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 558cdf0e10cSrcweir /* e */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 559cdf0e10cSrcweir /* f */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 560cdf0e10cSrcweir /* g */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 561cdf0e10cSrcweir /* h */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 562cdf0e10cSrcweir /* i */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 563cdf0e10cSrcweir /* j */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 564cdf0e10cSrcweir /* k */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 565cdf0e10cSrcweir /* l */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 566cdf0e10cSrcweir /* m */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 567cdf0e10cSrcweir /* n */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 568cdf0e10cSrcweir /* o */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 569cdf0e10cSrcweir /* p */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 570cdf0e10cSrcweir /* q */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 571cdf0e10cSrcweir /* r */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 572cdf0e10cSrcweir /* s */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 573cdf0e10cSrcweir /* t */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 574cdf0e10cSrcweir /* u */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 575cdf0e10cSrcweir /* v */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 576cdf0e10cSrcweir /* w */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 577cdf0e10cSrcweir /* x */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 578cdf0e10cSrcweir /* y */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 579cdf0e10cSrcweir /* z */ PA+PB+PC+PD+PE+PF+PG+PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ+P1+P2, 580cdf0e10cSrcweir /* { */ PU+PV +PY, 581cdf0e10cSrcweir /* | */ PB+PC +PN +PT+PU+PV +PY, 582cdf0e10cSrcweir /* } */ PU+PV +PY, 583cdf0e10cSrcweir /* ~ */ PA+PB+PC+PD+PE +PH+PI+PJ+PK+PL+PM+PN+PO+PP+PQ+PR+PS+PT+PU+PV+PW+PX+PY+PZ +P2, 584cdf0e10cSrcweir 0 }; 585cdf0e10cSrcweir 586cdf0e10cSrcweir inline bool mustEncode(sal_uInt32 nUTF32, INetURLObject::Part ePart) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir return !INetMIME::isUSASCII(nUTF32) || !(aMustEncodeMap[nUTF32] & ePart); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir //============================================================================ 594cdf0e10cSrcweir void INetURLObject::setInvalid() 595cdf0e10cSrcweir { 596cdf0e10cSrcweir m_aAbsURIRef.setLength(0); 597cdf0e10cSrcweir m_eScheme = INET_PROT_NOT_VALID; 598cdf0e10cSrcweir m_aScheme.clear(); 599cdf0e10cSrcweir m_aUser.clear(); 600cdf0e10cSrcweir m_aAuth.clear(); 601cdf0e10cSrcweir m_aHost.clear(); 602cdf0e10cSrcweir m_aPort.clear(); 603cdf0e10cSrcweir m_aPath.clear(); 604cdf0e10cSrcweir m_aQuery.clear(); 605cdf0e10cSrcweir m_aFragment.clear(); 606cdf0e10cSrcweir } 607cdf0e10cSrcweir 608cdf0e10cSrcweir //============================================================================ 609cdf0e10cSrcweir 610cdf0e10cSrcweir namespace unnamed_tools_urlobj { 611cdf0e10cSrcweir 612cdf0e10cSrcweir INetURLObject::FSysStyle 613cdf0e10cSrcweir guessFSysStyleByCounting(sal_Unicode const * pBegin, 614cdf0e10cSrcweir sal_Unicode const * pEnd, 615cdf0e10cSrcweir INetURLObject::FSysStyle eStyle) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir DBG_ASSERT(eStyle 618cdf0e10cSrcweir & (INetURLObject::FSYS_UNX 619cdf0e10cSrcweir | INetURLObject::FSYS_DOS 620cdf0e10cSrcweir | INetURLObject::FSYS_MAC), 621cdf0e10cSrcweir "guessFSysStyleByCounting(): Bad style"); 622cdf0e10cSrcweir DBG_ASSERT(std::numeric_limits< sal_Int32 >::min() < pBegin - pEnd 623cdf0e10cSrcweir && pEnd - pBegin <= std::numeric_limits< sal_Int32 >::max(), 624cdf0e10cSrcweir "guessFSysStyleByCounting(): Too big"); 625cdf0e10cSrcweir sal_Int32 nSlashCount 626cdf0e10cSrcweir = eStyle & INetURLObject::FSYS_UNX ? 627cdf0e10cSrcweir 0 : std::numeric_limits< sal_Int32 >::min(); 628cdf0e10cSrcweir sal_Int32 nBackslashCount 629cdf0e10cSrcweir = eStyle & INetURLObject::FSYS_DOS ? 630cdf0e10cSrcweir 0 : std::numeric_limits< sal_Int32 >::min(); 631cdf0e10cSrcweir sal_Int32 nColonCount 632cdf0e10cSrcweir = eStyle & INetURLObject::FSYS_MAC ? 633cdf0e10cSrcweir 0 : std::numeric_limits< sal_Int32 >::min(); 634cdf0e10cSrcweir while (pBegin != pEnd) 635cdf0e10cSrcweir switch (*pBegin++) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir case '/': 638cdf0e10cSrcweir ++nSlashCount; 639cdf0e10cSrcweir break; 640cdf0e10cSrcweir 641cdf0e10cSrcweir case '\\': 642cdf0e10cSrcweir ++nBackslashCount; 643cdf0e10cSrcweir break; 644cdf0e10cSrcweir 645cdf0e10cSrcweir case ':': 646cdf0e10cSrcweir ++nColonCount; 647cdf0e10cSrcweir break; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir return nSlashCount >= nBackslashCount ? 650cdf0e10cSrcweir nSlashCount >= nColonCount ? 651cdf0e10cSrcweir INetURLObject::FSYS_UNX : INetURLObject::FSYS_MAC : 652cdf0e10cSrcweir nBackslashCount >= nColonCount ? 653cdf0e10cSrcweir INetURLObject::FSYS_DOS : INetURLObject::FSYS_MAC; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir rtl::OUString parseScheme( 657cdf0e10cSrcweir sal_Unicode const ** begin, sal_Unicode const * end, 658cdf0e10cSrcweir sal_uInt32 fragmentDelimiter) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir sal_Unicode const * p = *begin; 661cdf0e10cSrcweir if (p != end && INetMIME::isAlpha(*p)) { 662cdf0e10cSrcweir do { 663cdf0e10cSrcweir ++p; 664cdf0e10cSrcweir } while (p != end 665cdf0e10cSrcweir && (INetMIME::isAlphanumeric(*p) || *p == '+' || *p == '-' 666cdf0e10cSrcweir || *p == '.')); 667cdf0e10cSrcweir // #i34835# To avoid problems with Windows file paths like "C:\foo", 668cdf0e10cSrcweir // do not accept generic schemes that are only one character long: 669cdf0e10cSrcweir if (end - p > 1 && p[0] == ':' && p[1] != fragmentDelimiter 670cdf0e10cSrcweir && p - *begin >= 2) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir rtl::OUString scheme( 673cdf0e10cSrcweir rtl::OUString(*begin, p - *begin).toAsciiLowerCase()); 674cdf0e10cSrcweir *begin = p + 1; 675cdf0e10cSrcweir return scheme; 676cdf0e10cSrcweir } 677cdf0e10cSrcweir } 678cdf0e10cSrcweir return rtl::OUString(); 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir } 682cdf0e10cSrcweir 683cdf0e10cSrcweir bool INetURLObject::setAbsURIRef(rtl::OUString const & rTheAbsURIRef, 684cdf0e10cSrcweir bool bOctets, 685cdf0e10cSrcweir EncodeMechanism eMechanism, 686cdf0e10cSrcweir rtl_TextEncoding eCharset, 687cdf0e10cSrcweir bool bSmart, 688cdf0e10cSrcweir FSysStyle eStyle) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir sal_Unicode const * pPos = rTheAbsURIRef.getStr(); 691cdf0e10cSrcweir sal_Unicode const * pEnd = pPos + rTheAbsURIRef.getLength(); 692cdf0e10cSrcweir 693cdf0e10cSrcweir setInvalid(); 694cdf0e10cSrcweir 695cdf0e10cSrcweir sal_uInt32 nFragmentDelimiter = '#'; 696cdf0e10cSrcweir 697cdf0e10cSrcweir rtl::OUStringBuffer aSynAbsURIRef; 698cdf0e10cSrcweir 699cdf0e10cSrcweir // Parse <scheme>: 700cdf0e10cSrcweir sal_Unicode const * p = pPos; 701cdf0e10cSrcweir PrefixInfo const * pPrefix = getPrefix(p, pEnd); 702cdf0e10cSrcweir if (pPrefix) 703cdf0e10cSrcweir { 704cdf0e10cSrcweir pPos = p; 705cdf0e10cSrcweir m_eScheme = pPrefix->m_eScheme; 706cdf0e10cSrcweir 707cdf0e10cSrcweir rtl::OUString sTemp(rtl::OUString::createFromAscii(pPrefix->m_eKind 708cdf0e10cSrcweir >= PrefixInfo::EXTERNAL ? 709cdf0e10cSrcweir pPrefix->m_pTranslatedPrefix : 710cdf0e10cSrcweir pPrefix->m_pPrefix)); 711cdf0e10cSrcweir aSynAbsURIRef.append(sTemp); 712cdf0e10cSrcweir m_aScheme = SubString( 0, sTemp.indexOf(static_cast< sal_Unicode >(':')) ); 713cdf0e10cSrcweir } 714cdf0e10cSrcweir else 715cdf0e10cSrcweir { 716cdf0e10cSrcweir if (bSmart) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir // For scheme detection, the first (if any) of the following 719cdf0e10cSrcweir // productions that matches the input string (and for which the 720cdf0e10cSrcweir // appropriate style bit is set in eStyle, if applicable) 721cdf0e10cSrcweir // determines the scheme. The productions use the auxiliary rules 722cdf0e10cSrcweir // 723cdf0e10cSrcweir // domain = label *("." label) 724cdf0e10cSrcweir // label = alphanum [*(alphanum / "-") alphanum] 725cdf0e10cSrcweir // alphanum = ALPHA / DIGIT 726cdf0e10cSrcweir // IPv6reference = "[" IPv6address "]" 727cdf0e10cSrcweir // IPv6address = hexpart [":" IPv4address] 728cdf0e10cSrcweir // IPv4address = 1*3DIGIT 3("." 1*3DIGIT) 729cdf0e10cSrcweir // hexpart = (hexseq ["::" [hexseq]]) / ("::" [hexseq]) 730cdf0e10cSrcweir // hexseq = hex4 *(":" hex4) 731cdf0e10cSrcweir // hex4 = 1*4HEXDIG 732cdf0e10cSrcweir // UCS4 = <any UCS4 character> 733cdf0e10cSrcweir // 734cdf0e10cSrcweir // 1st Production (known scheme): 735cdf0e10cSrcweir // <one of the known schemes, ignoring case> ":" *UCS4 736cdf0e10cSrcweir // 737cdf0e10cSrcweir // 2nd Production (mailto): 738cdf0e10cSrcweir // domain "@" domain 739cdf0e10cSrcweir // 740cdf0e10cSrcweir // 3rd Production (ftp): 741cdf0e10cSrcweir // "FTP" 2*("." label) ["/" *UCS4] 742cdf0e10cSrcweir // 743cdf0e10cSrcweir // 4th Production (http): 744cdf0e10cSrcweir // label 2*("." label) ["/" *UCS4] 745cdf0e10cSrcweir // 746cdf0e10cSrcweir // 5th Production (file): 747cdf0e10cSrcweir // "//" (domain / IPv6reference) ["/" *UCS4] 748cdf0e10cSrcweir // 749cdf0e10cSrcweir // 6th Production (Unix file): 750cdf0e10cSrcweir // "/" *UCS4 751cdf0e10cSrcweir // 752cdf0e10cSrcweir // 7th Production (UNC file; FSYS_DOS only): 753cdf0e10cSrcweir // "\\" domain ["\" *UCS4] 754cdf0e10cSrcweir // 755cdf0e10cSrcweir // 8th Production (Unix-like DOS file; FSYS_DOS only): 756cdf0e10cSrcweir // ALPHA ":" ["/" *UCS4] 757cdf0e10cSrcweir // 758cdf0e10cSrcweir // 9th Production (DOS file; FSYS_DOS only): 759cdf0e10cSrcweir // ALPHA ":" ["\" *UCS4] 760cdf0e10cSrcweir // 761cdf0e10cSrcweir // For the 'non URL' file productions 6--9, the interpretation of 762cdf0e10cSrcweir // the input as a (degenerate) URI is turned off, i.e., escape 763cdf0e10cSrcweir // sequences and fragments are never detected as such, but are 764cdf0e10cSrcweir // taken as literal characters. 765cdf0e10cSrcweir 766cdf0e10cSrcweir sal_Unicode const * p1 = pPos; 767cdf0e10cSrcweir if (eStyle & FSYS_DOS 768cdf0e10cSrcweir && pEnd - p1 >= 2 769cdf0e10cSrcweir && INetMIME::isAlpha(p1[0]) 770cdf0e10cSrcweir && p1[1] == ':' 771cdf0e10cSrcweir && (pEnd - p1 == 2 || p1[2] == '/' || p1[2] == '\\')) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir m_eScheme = INET_PROT_FILE; // 8th, 9th 774cdf0e10cSrcweir eMechanism = ENCODE_ALL; 775cdf0e10cSrcweir nFragmentDelimiter = 0x80000000; 776cdf0e10cSrcweir } 777cdf0e10cSrcweir else if (pEnd - p1 >= 2 && p1[0] == '/' && p1[1] == '/') 778cdf0e10cSrcweir { 779cdf0e10cSrcweir p1 += 2; 780cdf0e10cSrcweir if ((scanDomain(p1, pEnd) > 0 || scanIPv6reference(p1, pEnd)) 781cdf0e10cSrcweir && (p1 == pEnd || *p1 == '/')) 782cdf0e10cSrcweir m_eScheme = INET_PROT_FILE; // 5th 783cdf0e10cSrcweir } 784cdf0e10cSrcweir else if (p1 != pEnd && *p1 == '/') 785cdf0e10cSrcweir { 786cdf0e10cSrcweir m_eScheme = INET_PROT_FILE; // 6th 787cdf0e10cSrcweir eMechanism = ENCODE_ALL; 788cdf0e10cSrcweir nFragmentDelimiter = 0x80000000; 789cdf0e10cSrcweir } 790cdf0e10cSrcweir else if (eStyle & FSYS_DOS 791cdf0e10cSrcweir && pEnd - p1 >= 2 792cdf0e10cSrcweir && p1[0] == '\\' 793cdf0e10cSrcweir && p1[1] == '\\') 794cdf0e10cSrcweir { 795cdf0e10cSrcweir p1 += 2; 796cdf0e10cSrcweir sal_Int32 n = rtl_ustr_indexOfChar_WithLength( 797cdf0e10cSrcweir p1, pEnd - p1, '\\'); 798cdf0e10cSrcweir sal_Unicode const * pe = n == -1 ? pEnd : p1 + n; 799cdf0e10cSrcweir if ( 800cdf0e10cSrcweir parseHostOrNetBiosName( 801cdf0e10cSrcweir p1, pe, bOctets, ENCODE_ALL, RTL_TEXTENCODING_DONTKNOW, 802cdf0e10cSrcweir true, NULL) || 803cdf0e10cSrcweir (scanDomain(p1, pe) > 0 && p1 == pe) 804cdf0e10cSrcweir ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir m_eScheme = INET_PROT_FILE; // 7th 807cdf0e10cSrcweir eMechanism = ENCODE_ALL; 808cdf0e10cSrcweir nFragmentDelimiter = 0x80000000; 809cdf0e10cSrcweir } 810cdf0e10cSrcweir } 811cdf0e10cSrcweir else 812cdf0e10cSrcweir { 813cdf0e10cSrcweir sal_Unicode const * pDomainEnd = p1; 814cdf0e10cSrcweir sal_uInt32 nLabels = scanDomain(pDomainEnd, pEnd); 815cdf0e10cSrcweir if (nLabels > 0 && pDomainEnd != pEnd && *pDomainEnd == '@') 816cdf0e10cSrcweir { 817cdf0e10cSrcweir ++pDomainEnd; 818cdf0e10cSrcweir if (scanDomain(pDomainEnd, pEnd) > 0 819cdf0e10cSrcweir && pDomainEnd == pEnd) 820cdf0e10cSrcweir m_eScheme = INET_PROT_MAILTO; // 2nd 821cdf0e10cSrcweir } 822cdf0e10cSrcweir else if (nLabels >= 3 823cdf0e10cSrcweir && (pDomainEnd == pEnd || *pDomainEnd == '/')) 824cdf0e10cSrcweir m_eScheme 825cdf0e10cSrcweir = pDomainEnd - p1 >= 4 826cdf0e10cSrcweir && (p1[0] == 'f' || p1[0] == 'F') 827cdf0e10cSrcweir && (p1[1] == 't' || p1[1] == 'T') 828cdf0e10cSrcweir && (p1[2] == 'p' || p1[2] == 'P') 829cdf0e10cSrcweir && p1[3] == '.' ? 830cdf0e10cSrcweir INET_PROT_FTP : INET_PROT_HTTP; // 3rd, 4th 831cdf0e10cSrcweir } 832cdf0e10cSrcweir } 833cdf0e10cSrcweir 834cdf0e10cSrcweir rtl::OUString aSynScheme; 835cdf0e10cSrcweir if (m_eScheme == INET_PROT_NOT_VALID) { 836cdf0e10cSrcweir sal_Unicode const * p1 = pPos; 837cdf0e10cSrcweir aSynScheme = parseScheme(&p1, pEnd, nFragmentDelimiter); 838cdf0e10cSrcweir if (aSynScheme.getLength() > 0) 839cdf0e10cSrcweir { 840cdf0e10cSrcweir m_eScheme = INET_PROT_GENERIC; 841cdf0e10cSrcweir pPos = p1; 842cdf0e10cSrcweir } 843cdf0e10cSrcweir } 844cdf0e10cSrcweir 845cdf0e10cSrcweir if (bSmart && m_eScheme == INET_PROT_NOT_VALID && pPos != pEnd 846cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir m_eScheme = m_eSmartScheme; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir 851cdf0e10cSrcweir if (m_eScheme == INET_PROT_NOT_VALID) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir setInvalid(); 854cdf0e10cSrcweir return false; 855cdf0e10cSrcweir } 856cdf0e10cSrcweir 857cdf0e10cSrcweir if (m_eScheme != INET_PROT_GENERIC) { 858cdf0e10cSrcweir aSynScheme = rtl::OUString::createFromAscii(getSchemeInfo().m_pScheme); 859cdf0e10cSrcweir } 860cdf0e10cSrcweir m_aScheme.set(aSynAbsURIRef, aSynScheme, aSynAbsURIRef.getLength()); 861cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode(':')); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir sal_Char cEscapePrefix = getEscapePrefix(); 865cdf0e10cSrcweir sal_uInt32 nSegmentDelimiter = '/'; 866cdf0e10cSrcweir sal_uInt32 nAltSegmentDelimiter = 0x80000000; 867cdf0e10cSrcweir bool bSkippedInitialSlash = false; 868cdf0e10cSrcweir 869cdf0e10cSrcweir // Parse //<user>;AUTH=<auth>@<host>:<port> or 870cdf0e10cSrcweir // //<user>:<password>@<host>:<port> or 871cdf0e10cSrcweir // //<reg_name> 872cdf0e10cSrcweir if (getSchemeInfo().m_bAuthority) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir sal_Unicode const * pUserInfoBegin = 0; 875cdf0e10cSrcweir sal_Unicode const * pUserInfoEnd = 0; 876cdf0e10cSrcweir sal_Unicode const * pHostPortBegin = 0; 877cdf0e10cSrcweir sal_Unicode const * pHostPortEnd = 0; 878cdf0e10cSrcweir 879cdf0e10cSrcweir switch (m_eScheme) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_HELP: 882cdf0e10cSrcweir { 883cdf0e10cSrcweir if (pEnd - pPos < 2 || *pPos++ != '/' || *pPos++ != '/') 884cdf0e10cSrcweir { 885cdf0e10cSrcweir setInvalid(); 886cdf0e10cSrcweir return false; 887cdf0e10cSrcweir } 888cdf0e10cSrcweir aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 889cdf0e10cSrcweir rtl::OUStringBuffer aSynAuthority; 890cdf0e10cSrcweir while (pPos < pEnd 891cdf0e10cSrcweir && *pPos != '/' && *pPos != '?' 892cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir EscapeType eEscapeType; 895cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 896cdf0e10cSrcweir cEscapePrefix, eMechanism, 897cdf0e10cSrcweir eCharset, eEscapeType); 898cdf0e10cSrcweir appendUCS4(aSynAuthority, nUTF32, eEscapeType, bOctets, 899cdf0e10cSrcweir PART_AUTHORITY, cEscapePrefix, eCharset, 900cdf0e10cSrcweir false); 901cdf0e10cSrcweir } 902cdf0e10cSrcweir m_aHost.set(aSynAbsURIRef, 903cdf0e10cSrcweir aSynAuthority.makeStringAndClear(), 904cdf0e10cSrcweir aSynAbsURIRef.getLength()); 905cdf0e10cSrcweir // misusing m_aHost to store the authority 906cdf0e10cSrcweir break; 907cdf0e10cSrcweir } 908cdf0e10cSrcweir 909cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_HIER: 910cdf0e10cSrcweir { 911cdf0e10cSrcweir if (pEnd - pPos >= 2 && pPos[0] == '/' && pPos[1] == '/') 912cdf0e10cSrcweir { 913cdf0e10cSrcweir pPos += 2; 914cdf0e10cSrcweir aSynAbsURIRef. 915cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 916cdf0e10cSrcweir rtl::OUStringBuffer aSynAuthority; 917cdf0e10cSrcweir while (pPos < pEnd 918cdf0e10cSrcweir && *pPos != '/' && *pPos != '?' 919cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 920cdf0e10cSrcweir { 921cdf0e10cSrcweir EscapeType eEscapeType; 922cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, 923cdf0e10cSrcweir pEnd, 924cdf0e10cSrcweir bOctets, 925cdf0e10cSrcweir cEscapePrefix, 926cdf0e10cSrcweir eMechanism, 927cdf0e10cSrcweir eCharset, 928cdf0e10cSrcweir eEscapeType); 929cdf0e10cSrcweir appendUCS4(aSynAuthority, 930cdf0e10cSrcweir nUTF32, 931cdf0e10cSrcweir eEscapeType, 932cdf0e10cSrcweir bOctets, 933cdf0e10cSrcweir PART_AUTHORITY, 934cdf0e10cSrcweir cEscapePrefix, 935cdf0e10cSrcweir eCharset, 936cdf0e10cSrcweir false); 937cdf0e10cSrcweir } 938cdf0e10cSrcweir if (aSynAuthority.getLength() == 0) 939cdf0e10cSrcweir { 940cdf0e10cSrcweir setInvalid(); 941cdf0e10cSrcweir return false; 942cdf0e10cSrcweir } 943cdf0e10cSrcweir m_aHost.set(aSynAbsURIRef, 944cdf0e10cSrcweir aSynAuthority.makeStringAndClear(), 945cdf0e10cSrcweir aSynAbsURIRef.getLength()); 946cdf0e10cSrcweir // misusing m_aHost to store the authority 947cdf0e10cSrcweir } 948cdf0e10cSrcweir break; 949cdf0e10cSrcweir } 950cdf0e10cSrcweir 951cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_PKG: 952cdf0e10cSrcweir { 953cdf0e10cSrcweir if (pEnd - pPos < 2 || *pPos++ != '/' || *pPos++ != '/') 954cdf0e10cSrcweir { 955cdf0e10cSrcweir setInvalid(); 956cdf0e10cSrcweir return false; 957cdf0e10cSrcweir } 958cdf0e10cSrcweir aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 959cdf0e10cSrcweir rtl::OUStringBuffer aSynAuthority; 960cdf0e10cSrcweir while (pPos < pEnd 961cdf0e10cSrcweir && *pPos != '/' && *pPos != '?' 962cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 963cdf0e10cSrcweir { 964cdf0e10cSrcweir EscapeType eEscapeType; 965cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 966cdf0e10cSrcweir cEscapePrefix, eMechanism, 967cdf0e10cSrcweir eCharset, eEscapeType); 968cdf0e10cSrcweir appendUCS4(aSynAuthority, nUTF32, eEscapeType, bOctets, 969cdf0e10cSrcweir PART_AUTHORITY, cEscapePrefix, eCharset, 970cdf0e10cSrcweir false); 971cdf0e10cSrcweir } 972cdf0e10cSrcweir if (aSynAuthority.getLength() == 0) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir setInvalid(); 975cdf0e10cSrcweir return false; 976cdf0e10cSrcweir } 977cdf0e10cSrcweir m_aHost.set(aSynAbsURIRef, 978cdf0e10cSrcweir aSynAuthority.makeStringAndClear(), 979cdf0e10cSrcweir aSynAbsURIRef.getLength()); 980cdf0e10cSrcweir // misusing m_aHost to store the authority 981cdf0e10cSrcweir break; 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir case INET_PROT_FILE: 985cdf0e10cSrcweir if (bSmart) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir // The first of the following seven productions that 988cdf0e10cSrcweir // matches the rest of the input string (and for which the 989cdf0e10cSrcweir // appropriate style bit is set in eStyle, if applicable) 990cdf0e10cSrcweir // determines the used notation. The productions use the 991cdf0e10cSrcweir // auxiliary rules 992cdf0e10cSrcweir // 993cdf0e10cSrcweir // domain = label *("." label) 994cdf0e10cSrcweir // label = alphanum [*(alphanum / "-") alphanum] 995cdf0e10cSrcweir // alphanum = ALPHA / DIGIT 996cdf0e10cSrcweir // IPv6reference = "[" IPv6address "]" 997cdf0e10cSrcweir // IPv6address = hexpart [":" IPv4address] 998cdf0e10cSrcweir // IPv4address = 1*3DIGIT 3("." 1*3DIGIT) 999cdf0e10cSrcweir // hexpart = (hexseq ["::" [hexseq]]) / ("::" [hexseq]) 1000cdf0e10cSrcweir // hexseq = hex4 *(":" hex4) 1001cdf0e10cSrcweir // hex4 = 1*4HEXDIG 1002cdf0e10cSrcweir // path = <any UCS4 character except "#"> 1003cdf0e10cSrcweir // UCS4 = <any UCS4 character> 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir // 1st Production (URL): 1006cdf0e10cSrcweir // "//" [domain / IPv6reference] ["/" *path] 1007cdf0e10cSrcweir // ["#" *UCS4] 1008cdf0e10cSrcweir // becomes 1009cdf0e10cSrcweir // "file://" domain "/" *path ["#" *UCS4] 1010cdf0e10cSrcweir if (pEnd - pPos >= 2 && pPos[0] == '/' && pPos[1] == '/') 1011cdf0e10cSrcweir { 1012cdf0e10cSrcweir sal_Unicode const * p1 = pPos + 2; 1013cdf0e10cSrcweir while (p1 != pEnd && *p1 != '/' && 1014cdf0e10cSrcweir *p1 != nFragmentDelimiter) 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir ++p1; 1017cdf0e10cSrcweir } 1018cdf0e10cSrcweir if (parseHostOrNetBiosName( 1019cdf0e10cSrcweir pPos + 2, p1, bOctets, ENCODE_ALL, 1020cdf0e10cSrcweir RTL_TEXTENCODING_DONTKNOW, true, NULL)) 1021cdf0e10cSrcweir { 1022cdf0e10cSrcweir aSynAbsURIRef. 1023cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1024cdf0e10cSrcweir pHostPortBegin = pPos + 2; 1025cdf0e10cSrcweir pHostPortEnd = p1; 1026cdf0e10cSrcweir pPos = p1; 1027cdf0e10cSrcweir break; 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir // 2nd Production (MS IE generated 1; FSYS_DOS only): 1032cdf0e10cSrcweir // "//" ALPHA ":" ["/" *path] ["#" *UCS4] 1033cdf0e10cSrcweir // becomes 1034cdf0e10cSrcweir // "file:///" ALPHA ":" ["/" *path] ["#" *UCS4] 1035cdf0e10cSrcweir // replacing "\" by "/" within <*path> 1036cdf0e10cSrcweir // 1037cdf0e10cSrcweir // 3rd Production (MS IE generated 2; FSYS_DOS only): 1038cdf0e10cSrcweir // "//" ALPHA ":" ["\" *path] ["#" *UCS4] 1039cdf0e10cSrcweir // becomes 1040cdf0e10cSrcweir // "file:///" ALPHA ":" ["/" *path] ["#" *UCS4] 1041cdf0e10cSrcweir // replacing "\" by "/" within <*path> 1042cdf0e10cSrcweir // 1043cdf0e10cSrcweir // 4th Production (misscounted slashes): 1044cdf0e10cSrcweir // "//" *path ["#" *UCS4] 1045cdf0e10cSrcweir // becomes 1046cdf0e10cSrcweir // "file:///" *path ["#" *UCS4] 1047cdf0e10cSrcweir if (pEnd - pPos >= 2 && pPos[0] == '/' && pPos[1] == '/') 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir aSynAbsURIRef. 1050cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1051cdf0e10cSrcweir pPos += 2; 1052cdf0e10cSrcweir bSkippedInitialSlash = true; 1053cdf0e10cSrcweir if ((eStyle & FSYS_DOS) != 0 1054cdf0e10cSrcweir && pEnd - pPos >= 2 1055cdf0e10cSrcweir && INetMIME::isAlpha(pPos[0]) 1056cdf0e10cSrcweir && pPos[1] == ':' 1057cdf0e10cSrcweir && (pEnd - pPos == 2 1058cdf0e10cSrcweir || pPos[2] == '/' || pPos[2] == '\\')) 1059cdf0e10cSrcweir nAltSegmentDelimiter = '\\'; 1060cdf0e10cSrcweir break; 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir // 5th Production (Unix): 1064cdf0e10cSrcweir // "/" *path ["#" *UCS4] 1065cdf0e10cSrcweir // becomes 1066cdf0e10cSrcweir // "file:///" *path ["#" *UCS4] 1067cdf0e10cSrcweir if (pPos < pEnd && *pPos == '/') 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir aSynAbsURIRef. 1070cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1071cdf0e10cSrcweir break; 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir // 6th Production (UNC; FSYS_DOS only): 1075cdf0e10cSrcweir // "\\" domain ["\" *path] ["#" *UCS4] 1076cdf0e10cSrcweir // becomes 1077cdf0e10cSrcweir // "file://" domain "/" *path ["#" *UCS4] 1078cdf0e10cSrcweir // replacing "\" by "/" within <*path> 1079cdf0e10cSrcweir if (eStyle & FSYS_DOS 1080cdf0e10cSrcweir && pEnd - pPos >= 2 1081cdf0e10cSrcweir && pPos[0] == '\\' 1082cdf0e10cSrcweir && pPos[1] == '\\') 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir sal_Unicode const * p1 = pPos + 2; 1085cdf0e10cSrcweir sal_Unicode const * pe = p1; 1086cdf0e10cSrcweir while (pe < pEnd && *pe != '\\' && 1087cdf0e10cSrcweir *pe != nFragmentDelimiter) 1088cdf0e10cSrcweir { 1089cdf0e10cSrcweir ++pe; 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir if ( 1092cdf0e10cSrcweir parseHostOrNetBiosName( 1093cdf0e10cSrcweir p1, pe, bOctets, ENCODE_ALL, 1094cdf0e10cSrcweir RTL_TEXTENCODING_DONTKNOW, true, NULL) || 1095cdf0e10cSrcweir (scanDomain(p1, pe) > 0 && p1 == pe) 1096cdf0e10cSrcweir ) 1097cdf0e10cSrcweir { 1098cdf0e10cSrcweir aSynAbsURIRef. 1099cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1100cdf0e10cSrcweir pHostPortBegin = pPos + 2; 1101cdf0e10cSrcweir pHostPortEnd = pe; 1102cdf0e10cSrcweir pPos = pe; 1103cdf0e10cSrcweir nSegmentDelimiter = '\\'; 1104cdf0e10cSrcweir break; 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir // 7th Production (Unix-like DOS; FSYS_DOS only): 1109cdf0e10cSrcweir // ALPHA ":" ["/" *path] ["#" *UCS4] 1110cdf0e10cSrcweir // becomes 1111cdf0e10cSrcweir // "file:///" ALPHA ":" ["/" *path] ["#" *UCS4] 1112cdf0e10cSrcweir // replacing "\" by "/" within <*path> 1113cdf0e10cSrcweir // 1114cdf0e10cSrcweir // 8th Production (DOS; FSYS_DOS only): 1115cdf0e10cSrcweir // ALPHA ":" ["\" *path] ["#" *UCS4] 1116cdf0e10cSrcweir // becomes 1117cdf0e10cSrcweir // "file:///" ALPHA ":" ["/" *path] ["#" *UCS4] 1118cdf0e10cSrcweir // replacing "\" by "/" within <*path> 1119cdf0e10cSrcweir if (eStyle & FSYS_DOS 1120cdf0e10cSrcweir && pEnd - pPos >= 2 1121cdf0e10cSrcweir && INetMIME::isAlpha(pPos[0]) 1122cdf0e10cSrcweir && pPos[1] == ':' 1123cdf0e10cSrcweir && (pEnd - pPos == 2 1124cdf0e10cSrcweir || pPos[2] == '/' 1125cdf0e10cSrcweir || pPos[2] == '\\')) 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir aSynAbsURIRef. 1128cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1129cdf0e10cSrcweir nAltSegmentDelimiter = '\\'; 1130cdf0e10cSrcweir bSkippedInitialSlash = true; 1131cdf0e10cSrcweir break; 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir // 9th Production (any): 1135cdf0e10cSrcweir // *path ["#" *UCS4] 1136cdf0e10cSrcweir // becomes 1137cdf0e10cSrcweir // "file:///" *path ["#" *UCS4] 1138cdf0e10cSrcweir // replacing the delimiter by "/" within <*path>. The 1139cdf0e10cSrcweir // delimiter is that character from the set { "/", "\", 1140cdf0e10cSrcweir // ":" } which appears most often in <*path> (if FSYS_UNX 1141cdf0e10cSrcweir // is not among the style bits, "/" is removed from the 1142cdf0e10cSrcweir // set; if FSYS_DOS is not among the style bits, "\" is 1143cdf0e10cSrcweir // removed from the set; if FSYS_MAC is not among the 1144cdf0e10cSrcweir // style bits, ":" is removed from the set). If two or 1145cdf0e10cSrcweir // more characters appear the same number of times, the 1146cdf0e10cSrcweir // character mentioned first in that set is chosen. If 1147cdf0e10cSrcweir // the first character of <*path> is the delimiter, that 1148cdf0e10cSrcweir // character is not copied. 1149cdf0e10cSrcweir if (eStyle & (FSYS_UNX | FSYS_DOS | FSYS_MAC)) 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir aSynAbsURIRef. 1152cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1153cdf0e10cSrcweir switch (guessFSysStyleByCounting(pPos, pEnd, eStyle)) 1154cdf0e10cSrcweir { 1155cdf0e10cSrcweir case FSYS_UNX: 1156cdf0e10cSrcweir nSegmentDelimiter = '/'; 1157cdf0e10cSrcweir break; 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir case FSYS_DOS: 1160cdf0e10cSrcweir nSegmentDelimiter = '\\'; 1161cdf0e10cSrcweir break; 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir case FSYS_MAC: 1164cdf0e10cSrcweir nSegmentDelimiter = ':'; 1165cdf0e10cSrcweir break; 1166cdf0e10cSrcweir 1167cdf0e10cSrcweir default: 1168cdf0e10cSrcweir DBG_ERROR( 1169cdf0e10cSrcweir "INetURLObject::setAbsURIRef():" 1170cdf0e10cSrcweir " Bad guessFSysStyleByCounting"); 1171cdf0e10cSrcweir break; 1172cdf0e10cSrcweir } 1173cdf0e10cSrcweir bSkippedInitialSlash 1174cdf0e10cSrcweir = pPos != pEnd && *pPos != nSegmentDelimiter; 1175cdf0e10cSrcweir break; 1176cdf0e10cSrcweir } 1177cdf0e10cSrcweir } 1178cdf0e10cSrcweir default: 1179cdf0e10cSrcweir { 1180cdf0e10cSrcweir // For INET_PROT_FILE, allow an empty authority ("//") to be 1181cdf0e10cSrcweir // missing if the following path starts with an explicit "/" 1182cdf0e10cSrcweir // (Java is notorious in generating such file URLs, so be 1183cdf0e10cSrcweir // liberal here): 1184cdf0e10cSrcweir if (pEnd - pPos >= 2 && pPos[0] == '/' && pPos[1] == '/') 1185cdf0e10cSrcweir pPos += 2; 1186cdf0e10cSrcweir else if (!bSmart 1187cdf0e10cSrcweir && !(m_eScheme == INET_PROT_FILE 1188cdf0e10cSrcweir && pPos != pEnd && *pPos == '/')) 1189cdf0e10cSrcweir { 1190cdf0e10cSrcweir setInvalid(); 1191cdf0e10cSrcweir return false; 1192cdf0e10cSrcweir } 1193cdf0e10cSrcweir aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir sal_Unicode const * pAuthority = pPos; 1196cdf0e10cSrcweir sal_uInt32 c = getSchemeInfo().m_bQuery ? '?' : 0x80000000; 1197cdf0e10cSrcweir while (pPos < pEnd && *pPos != '/' && *pPos != c 1198cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 1199cdf0e10cSrcweir ++pPos; 1200cdf0e10cSrcweir if (getSchemeInfo().m_bUser) 1201cdf0e10cSrcweir if (getSchemeInfo().m_bHost) 1202cdf0e10cSrcweir { 1203cdf0e10cSrcweir sal_Unicode const * p1 = pAuthority; 1204cdf0e10cSrcweir while (p1 < pPos && *p1 != '@') 1205cdf0e10cSrcweir ++p1; 1206cdf0e10cSrcweir if (p1 == pPos) 1207cdf0e10cSrcweir { 1208cdf0e10cSrcweir pHostPortBegin = pAuthority; 1209cdf0e10cSrcweir pHostPortEnd = pPos; 1210cdf0e10cSrcweir } 1211cdf0e10cSrcweir else 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir pUserInfoBegin = pAuthority; 1214cdf0e10cSrcweir pUserInfoEnd = p1; 1215cdf0e10cSrcweir pHostPortBegin = p1 + 1; 1216cdf0e10cSrcweir pHostPortEnd = pPos; 1217cdf0e10cSrcweir } 1218cdf0e10cSrcweir } 1219cdf0e10cSrcweir else 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir pUserInfoBegin = pAuthority; 1222cdf0e10cSrcweir pUserInfoEnd = pPos; 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir else if (getSchemeInfo().m_bHost) 1225cdf0e10cSrcweir { 1226cdf0e10cSrcweir pHostPortBegin = pAuthority; 1227cdf0e10cSrcweir pHostPortEnd = pPos; 1228cdf0e10cSrcweir } 1229cdf0e10cSrcweir else if (pPos != pAuthority) 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir setInvalid(); 1232cdf0e10cSrcweir return false; 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir break; 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir } 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir if (pUserInfoBegin) 1239cdf0e10cSrcweir { 1240cdf0e10cSrcweir Part ePart = m_eScheme == INET_PROT_IMAP ? 1241cdf0e10cSrcweir PART_IMAP_ACHAR : 1242cdf0e10cSrcweir m_eScheme == INET_PROT_VIM ? 1243cdf0e10cSrcweir PART_VIM : 1244cdf0e10cSrcweir PART_USER_PASSWORD; 1245cdf0e10cSrcweir bool bSupportsPassword = getSchemeInfo().m_bPassword; 1246cdf0e10cSrcweir bool bSupportsAuth 1247cdf0e10cSrcweir = !bSupportsPassword && getSchemeInfo().m_bAuth; 1248cdf0e10cSrcweir bool bHasAuth = false; 1249cdf0e10cSrcweir rtl::OUStringBuffer aSynUser; 1250cdf0e10cSrcweir sal_Unicode const * p1 = pUserInfoBegin; 1251cdf0e10cSrcweir while (p1 < pUserInfoEnd) 1252cdf0e10cSrcweir { 1253cdf0e10cSrcweir EscapeType eEscapeType; 1254cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(p1, pUserInfoEnd, bOctets, 1255cdf0e10cSrcweir cEscapePrefix, eMechanism, 1256cdf0e10cSrcweir eCharset, eEscapeType); 1257cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO) 1258cdf0e10cSrcweir { 1259cdf0e10cSrcweir if (nUTF32 == ':' && bSupportsPassword) 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir bHasAuth = true; 1262cdf0e10cSrcweir break; 1263cdf0e10cSrcweir } 1264cdf0e10cSrcweir else if (nUTF32 == ';' && bSupportsAuth 1265cdf0e10cSrcweir && pUserInfoEnd - p1 1266cdf0e10cSrcweir > RTL_CONSTASCII_LENGTH("auth=") 1267cdf0e10cSrcweir && INetMIME::equalIgnoreCase( 1268cdf0e10cSrcweir p1, 1269cdf0e10cSrcweir p1 + RTL_CONSTASCII_LENGTH("auth="), 1270cdf0e10cSrcweir "auth=")) 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir p1 += RTL_CONSTASCII_LENGTH("auth="); 1273cdf0e10cSrcweir bHasAuth = true; 1274cdf0e10cSrcweir break; 1275cdf0e10cSrcweir } 1276cdf0e10cSrcweir } 1277cdf0e10cSrcweir appendUCS4(aSynUser, nUTF32, eEscapeType, bOctets, ePart, 1278cdf0e10cSrcweir cEscapePrefix, eCharset, false); 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir m_aUser.set(aSynAbsURIRef, aSynUser.makeStringAndClear(), 1281cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1282cdf0e10cSrcweir if (bHasAuth) 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir if (bSupportsPassword) 1285cdf0e10cSrcweir { 1286cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode(':')); 1287cdf0e10cSrcweir rtl::OUStringBuffer aSynAuth; 1288cdf0e10cSrcweir while (p1 < pUserInfoEnd) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir EscapeType eEscapeType; 1291cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(p1, pUserInfoEnd, bOctets, 1292cdf0e10cSrcweir cEscapePrefix, 1293cdf0e10cSrcweir eMechanism, eCharset, 1294cdf0e10cSrcweir eEscapeType); 1295cdf0e10cSrcweir appendUCS4(aSynAuth, nUTF32, eEscapeType, bOctets, 1296cdf0e10cSrcweir ePart, cEscapePrefix, eCharset, false); 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir m_aAuth.set(aSynAbsURIRef, aSynAuth.makeStringAndClear(), 1299cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir else 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir aSynAbsURIRef. 1304cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM(";AUTH=")); 1305cdf0e10cSrcweir rtl::OUStringBuffer aSynAuth; 1306cdf0e10cSrcweir while (p1 < pUserInfoEnd) 1307cdf0e10cSrcweir { 1308cdf0e10cSrcweir EscapeType eEscapeType; 1309cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(p1, pUserInfoEnd, bOctets, 1310cdf0e10cSrcweir cEscapePrefix, 1311cdf0e10cSrcweir eMechanism, eCharset, 1312cdf0e10cSrcweir eEscapeType); 1313cdf0e10cSrcweir if (!INetMIME::isIMAPAtomChar(nUTF32)) 1314cdf0e10cSrcweir { 1315cdf0e10cSrcweir setInvalid(); 1316cdf0e10cSrcweir return false; 1317cdf0e10cSrcweir } 1318cdf0e10cSrcweir appendUCS4(aSynAuth, nUTF32, eEscapeType, bOctets, 1319cdf0e10cSrcweir ePart, cEscapePrefix, eCharset, false); 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir m_aAuth.set(aSynAbsURIRef, aSynAuth.makeStringAndClear(), 1322cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1323cdf0e10cSrcweir } 1324cdf0e10cSrcweir } 1325cdf0e10cSrcweir if (pHostPortBegin) 1326cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('@')); 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir if (pHostPortBegin) 1330cdf0e10cSrcweir { 1331cdf0e10cSrcweir sal_Unicode const * pPort = pHostPortEnd; 1332cdf0e10cSrcweir if ( getSchemeInfo().m_bPort && pHostPortBegin < pHostPortEnd ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir sal_Unicode const * p1 = pHostPortEnd - 1; 1335cdf0e10cSrcweir while (p1 > pHostPortBegin && INetMIME::isDigit(*p1)) 1336cdf0e10cSrcweir --p1; 1337cdf0e10cSrcweir if (*p1 == ':') 1338cdf0e10cSrcweir pPort = p1; 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir bool bNetBiosName = false; 1341cdf0e10cSrcweir switch (m_eScheme) 1342cdf0e10cSrcweir { 1343cdf0e10cSrcweir case INET_PROT_FILE: 1344cdf0e10cSrcweir // If the host equals "LOCALHOST" (unencoded and ignoring 1345cdf0e10cSrcweir // case), turn it into an empty host: 1346cdf0e10cSrcweir if (INetMIME::equalIgnoreCase(pHostPortBegin, pPort, 1347cdf0e10cSrcweir "localhost")) 1348cdf0e10cSrcweir pHostPortBegin = pPort; 1349cdf0e10cSrcweir bNetBiosName = true; 1350cdf0e10cSrcweir break; 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir case INET_PROT_LDAP: 1353cdf0e10cSrcweir case INET_PROT_SMB: 1354cdf0e10cSrcweir if (pHostPortBegin == pPort && pPort != pHostPortEnd) 1355cdf0e10cSrcweir { 1356cdf0e10cSrcweir setInvalid(); 1357cdf0e10cSrcweir return false; 1358cdf0e10cSrcweir } 1359cdf0e10cSrcweir break; 1360cdf0e10cSrcweir default: 1361cdf0e10cSrcweir if (pHostPortBegin == pPort) 1362cdf0e10cSrcweir { 1363cdf0e10cSrcweir setInvalid(); 1364cdf0e10cSrcweir return false; 1365cdf0e10cSrcweir } 1366cdf0e10cSrcweir break; 1367cdf0e10cSrcweir } 1368cdf0e10cSrcweir rtl::OUStringBuffer aSynHost; 1369cdf0e10cSrcweir if (!parseHostOrNetBiosName( 1370cdf0e10cSrcweir pHostPortBegin, pPort, bOctets, eMechanism, eCharset, 1371cdf0e10cSrcweir bNetBiosName, &aSynHost)) 1372cdf0e10cSrcweir { 1373cdf0e10cSrcweir setInvalid(); 1374cdf0e10cSrcweir return false; 1375cdf0e10cSrcweir } 1376cdf0e10cSrcweir m_aHost.set(aSynAbsURIRef, aSynHost.makeStringAndClear(), 1377cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1378cdf0e10cSrcweir if (pPort != pHostPortEnd) 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode(':')); 1381cdf0e10cSrcweir m_aPort.set(aSynAbsURIRef, 1382cdf0e10cSrcweir rtl::OUString(pPort + 1, pHostPortEnd - (pPort + 1)), 1383cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1384cdf0e10cSrcweir } 1385cdf0e10cSrcweir } 1386cdf0e10cSrcweir } 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir // Parse <path> 1389cdf0e10cSrcweir rtl::OUStringBuffer aSynPath; 1390cdf0e10cSrcweir if (!parsePath(m_eScheme, &pPos, pEnd, bOctets, eMechanism, eCharset, 1391cdf0e10cSrcweir bSkippedInitialSlash, nSegmentDelimiter, 1392cdf0e10cSrcweir nAltSegmentDelimiter, 1393cdf0e10cSrcweir getSchemeInfo().m_bQuery ? '?' : 0x80000000, 1394cdf0e10cSrcweir nFragmentDelimiter, aSynPath)) 1395cdf0e10cSrcweir { 1396cdf0e10cSrcweir setInvalid(); 1397cdf0e10cSrcweir return false; 1398cdf0e10cSrcweir } 1399cdf0e10cSrcweir m_aPath.set(aSynAbsURIRef, aSynPath.makeStringAndClear(), 1400cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1401cdf0e10cSrcweir 1402cdf0e10cSrcweir // Parse ?<query> 1403cdf0e10cSrcweir if (getSchemeInfo().m_bQuery && pPos < pEnd && *pPos == '?') 1404cdf0e10cSrcweir { 1405cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('?')); 1406cdf0e10cSrcweir rtl::OUStringBuffer aSynQuery; 1407cdf0e10cSrcweir for (++pPos; pPos < pEnd && *pPos != nFragmentDelimiter;) 1408cdf0e10cSrcweir { 1409cdf0e10cSrcweir EscapeType eEscapeType; 1410cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, cEscapePrefix, 1411cdf0e10cSrcweir eMechanism, eCharset, eEscapeType); 1412cdf0e10cSrcweir appendUCS4(aSynQuery, nUTF32, eEscapeType, bOctets, 1413cdf0e10cSrcweir PART_URIC, cEscapePrefix, eCharset, true); 1414cdf0e10cSrcweir } 1415cdf0e10cSrcweir m_aQuery.set(aSynAbsURIRef, aSynQuery.makeStringAndClear(), 1416cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir 1419cdf0e10cSrcweir // Parse #<fragment> 1420cdf0e10cSrcweir if (pPos < pEnd && *pPos == nFragmentDelimiter) 1421cdf0e10cSrcweir { 1422cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode(nFragmentDelimiter)); 1423cdf0e10cSrcweir rtl::OUStringBuffer aSynFragment; 1424cdf0e10cSrcweir for (++pPos; pPos < pEnd;) 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir EscapeType eEscapeType; 1427cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, cEscapePrefix, 1428cdf0e10cSrcweir eMechanism, eCharset, eEscapeType); 1429cdf0e10cSrcweir appendUCS4(aSynFragment, nUTF32, eEscapeType, bOctets, PART_URIC, 1430cdf0e10cSrcweir cEscapePrefix, eCharset, true); 1431cdf0e10cSrcweir } 1432cdf0e10cSrcweir m_aFragment.set(aSynAbsURIRef, aSynFragment.makeStringAndClear(), 1433cdf0e10cSrcweir aSynAbsURIRef.getLength()); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir if (pPos != pEnd) 1437cdf0e10cSrcweir { 1438cdf0e10cSrcweir setInvalid(); 1439cdf0e10cSrcweir return false; 1440cdf0e10cSrcweir } 1441cdf0e10cSrcweir 1442cdf0e10cSrcweir m_aAbsURIRef = aSynAbsURIRef; 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir return true; 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir //============================================================================ 1448cdf0e10cSrcweir bool INetURLObject::convertRelToAbs(rtl::OUString const & rTheRelURIRef, 1449cdf0e10cSrcweir bool bOctets, 1450cdf0e10cSrcweir INetURLObject & rTheAbsURIRef, 1451cdf0e10cSrcweir bool & rWasAbsolute, 1452cdf0e10cSrcweir EncodeMechanism eMechanism, 1453cdf0e10cSrcweir rtl_TextEncoding eCharset, 1454cdf0e10cSrcweir bool bIgnoreFragment, bool bSmart, 1455cdf0e10cSrcweir bool bRelativeNonURIs, FSysStyle eStyle) 1456cdf0e10cSrcweir const 1457cdf0e10cSrcweir { 1458cdf0e10cSrcweir sal_Unicode const * p = rTheRelURIRef.getStr(); 1459cdf0e10cSrcweir sal_Unicode const * pEnd = p + rTheRelURIRef.getLength(); 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir sal_Unicode const * pPrefixBegin = p; 1462cdf0e10cSrcweir PrefixInfo const * pPrefix = getPrefix(pPrefixBegin, pEnd); 1463cdf0e10cSrcweir bool hasScheme = pPrefix != 0; 1464cdf0e10cSrcweir if (!hasScheme) { 1465cdf0e10cSrcweir pPrefixBegin = p; 1466cdf0e10cSrcweir hasScheme = parseScheme(&pPrefixBegin, pEnd, '#').getLength() > 0; 1467cdf0e10cSrcweir } 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir sal_uInt32 nSegmentDelimiter = '/'; 1470cdf0e10cSrcweir sal_uInt32 nQueryDelimiter 1471cdf0e10cSrcweir = !bSmart || getSchemeInfo().m_bQuery ? '?' : 0x80000000; 1472cdf0e10cSrcweir sal_uInt32 nFragmentDelimiter = '#'; 1473cdf0e10cSrcweir Part ePart = PART_VISIBLE; 1474cdf0e10cSrcweir 1475cdf0e10cSrcweir if (!hasScheme && bSmart) 1476cdf0e10cSrcweir { 1477cdf0e10cSrcweir // If the input matches any of the following productions (for which 1478cdf0e10cSrcweir // the appropriate style bit is set in eStyle), it is assumed to be an 1479cdf0e10cSrcweir // absolute file system path, rather than a relative URI reference. 1480cdf0e10cSrcweir // (This is only a subset of the productions used for scheme detection 1481cdf0e10cSrcweir // in INetURLObject::setAbsURIRef(), because most of those productions 1482cdf0e10cSrcweir // interfere with the syntax of relative URI references.) The 1483cdf0e10cSrcweir // productions use the auxiliary rules 1484cdf0e10cSrcweir // 1485cdf0e10cSrcweir // domain = label *("." label) 1486cdf0e10cSrcweir // label = alphanum [*(alphanum / "-") alphanum] 1487cdf0e10cSrcweir // alphanum = ALPHA / DIGIT 1488cdf0e10cSrcweir // UCS4 = <any UCS4 character> 1489cdf0e10cSrcweir // 1490cdf0e10cSrcweir // 1st Production (UNC file; FSYS_DOS only): 1491cdf0e10cSrcweir // "\\" domain ["\" *UCS4] 1492cdf0e10cSrcweir // 1493cdf0e10cSrcweir // 2nd Production (Unix-like DOS file; FSYS_DOS only): 1494cdf0e10cSrcweir // ALPHA ":" ["/" *UCS4] 1495cdf0e10cSrcweir // 1496cdf0e10cSrcweir // 3rd Production (DOS file; FSYS_DOS only): 1497cdf0e10cSrcweir // ALPHA ":" ["\" *UCS4] 1498cdf0e10cSrcweir if (eStyle & FSYS_DOS) 1499cdf0e10cSrcweir { 1500cdf0e10cSrcweir bool bFSys = false; 1501cdf0e10cSrcweir sal_Unicode const * q = p; 1502cdf0e10cSrcweir if (pEnd - q >= 2 1503cdf0e10cSrcweir && INetMIME::isAlpha(q[0]) 1504cdf0e10cSrcweir && q[1] == ':' 1505cdf0e10cSrcweir && (pEnd - q == 2 || q[2] == '/' || q[2] == '\\')) 1506cdf0e10cSrcweir bFSys = true; // 2nd, 3rd 1507cdf0e10cSrcweir else if (pEnd - q >= 2 && q[0] == '\\' && q[1] == '\\') 1508cdf0e10cSrcweir { 1509cdf0e10cSrcweir q += 2; 1510cdf0e10cSrcweir sal_Int32 n = rtl_ustr_indexOfChar_WithLength( 1511cdf0e10cSrcweir q, pEnd - q, '\\'); 1512cdf0e10cSrcweir sal_Unicode const * qe = n == -1 ? pEnd : q + n; 1513cdf0e10cSrcweir if (parseHostOrNetBiosName( 1514cdf0e10cSrcweir q, qe, bOctets, ENCODE_ALL, RTL_TEXTENCODING_DONTKNOW, 1515cdf0e10cSrcweir true, NULL)) 1516cdf0e10cSrcweir { 1517cdf0e10cSrcweir bFSys = true; // 1st 1518cdf0e10cSrcweir } 1519cdf0e10cSrcweir } 1520cdf0e10cSrcweir if (bFSys) 1521cdf0e10cSrcweir { 1522cdf0e10cSrcweir INetURLObject aNewURI; 1523cdf0e10cSrcweir aNewURI.setAbsURIRef(rTheRelURIRef, bOctets, eMechanism, 1524cdf0e10cSrcweir eCharset, true, eStyle); 1525cdf0e10cSrcweir if (!aNewURI.HasError()) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir rTheAbsURIRef = aNewURI; 1528cdf0e10cSrcweir rWasAbsolute = true; 1529cdf0e10cSrcweir return true; 1530cdf0e10cSrcweir } 1531cdf0e10cSrcweir } 1532cdf0e10cSrcweir } 1533cdf0e10cSrcweir 1534cdf0e10cSrcweir // When the base URL is a file URL, accept relative file system paths 1535cdf0e10cSrcweir // using "\" or ":" as delimiter (and ignoring URI conventions for "%" 1536cdf0e10cSrcweir // and "#"), as well as relative URIs using "/" as delimiter: 1537cdf0e10cSrcweir if (m_eScheme == INET_PROT_FILE) 1538cdf0e10cSrcweir switch (guessFSysStyleByCounting(p, pEnd, eStyle)) 1539cdf0e10cSrcweir { 1540cdf0e10cSrcweir case FSYS_UNX: 1541cdf0e10cSrcweir nSegmentDelimiter = '/'; 1542cdf0e10cSrcweir break; 1543cdf0e10cSrcweir 1544cdf0e10cSrcweir case FSYS_DOS: 1545cdf0e10cSrcweir nSegmentDelimiter = '\\'; 1546cdf0e10cSrcweir bRelativeNonURIs = true; 1547cdf0e10cSrcweir break; 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir case FSYS_MAC: 1550cdf0e10cSrcweir nSegmentDelimiter = ':'; 1551cdf0e10cSrcweir bRelativeNonURIs = true; 1552cdf0e10cSrcweir break; 1553cdf0e10cSrcweir 1554cdf0e10cSrcweir default: 1555cdf0e10cSrcweir DBG_ERROR("INetURLObject::convertRelToAbs():" 1556cdf0e10cSrcweir " Bad guessFSysStyleByCounting"); 1557cdf0e10cSrcweir break; 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir 1560cdf0e10cSrcweir if (bRelativeNonURIs) 1561cdf0e10cSrcweir { 1562cdf0e10cSrcweir eMechanism = ENCODE_ALL; 1563cdf0e10cSrcweir nQueryDelimiter = 0x80000000; 1564cdf0e10cSrcweir nFragmentDelimiter = 0x80000000; 1565cdf0e10cSrcweir ePart = PART_VISIBLE_NONSPECIAL; 1566cdf0e10cSrcweir } 1567cdf0e10cSrcweir } 1568cdf0e10cSrcweir 1569cdf0e10cSrcweir // If the relative URI has the same scheme as the base URI, and that 1570cdf0e10cSrcweir // scheme is hierarchical, then ignore its presence in the relative 1571cdf0e10cSrcweir // URI in order to be backward compatible (cf. RFC 2396 section 5.2 1572cdf0e10cSrcweir // step 3): 1573cdf0e10cSrcweir if (pPrefix && pPrefix->m_eScheme == m_eScheme 1574cdf0e10cSrcweir && getSchemeInfo().m_bHierarchical) 1575cdf0e10cSrcweir { 1576cdf0e10cSrcweir hasScheme = false; 1577cdf0e10cSrcweir while (p != pEnd && *p++ != ':') ; 1578cdf0e10cSrcweir } 1579cdf0e10cSrcweir rWasAbsolute = hasScheme; 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir // Fast solution for non-relative URIs: 1582cdf0e10cSrcweir if (hasScheme) 1583cdf0e10cSrcweir { 1584cdf0e10cSrcweir INetURLObject aNewURI(rTheRelURIRef, eMechanism, eCharset); 1585cdf0e10cSrcweir if (aNewURI.HasError()) 1586cdf0e10cSrcweir { 1587cdf0e10cSrcweir rWasAbsolute = false; 1588cdf0e10cSrcweir return false; 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir if (bIgnoreFragment) 1592cdf0e10cSrcweir aNewURI.clearFragment(); 1593cdf0e10cSrcweir rTheAbsURIRef = aNewURI; 1594cdf0e10cSrcweir return true; 1595cdf0e10cSrcweir } 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir enum State { STATE_AUTH, STATE_ABS_PATH, STATE_REL_PATH, STATE_FRAGMENT, 1598cdf0e10cSrcweir STATE_DONE }; 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir rtl::OUStringBuffer aSynAbsURIRef; 1601cdf0e10cSrcweir // make sure that the scheme is copied for generic schemes: getSchemeInfo().m_pScheme 1602cdf0e10cSrcweir // is empty ("") in that case, so take the scheme from m_aAbsURIRef 1603cdf0e10cSrcweir if (m_eScheme != INET_PROT_GENERIC) 1604cdf0e10cSrcweir { 1605cdf0e10cSrcweir aSynAbsURIRef.appendAscii(getSchemeInfo().m_pScheme); 1606cdf0e10cSrcweir } 1607cdf0e10cSrcweir else 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir sal_Unicode const * pSchemeBegin 1610cdf0e10cSrcweir = m_aAbsURIRef.getStr(); 1611cdf0e10cSrcweir sal_Unicode const * pSchemeEnd = pSchemeBegin; 1612cdf0e10cSrcweir while (pSchemeEnd[0] != ':') 1613cdf0e10cSrcweir { 1614cdf0e10cSrcweir ++pSchemeEnd; 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir aSynAbsURIRef.append(pSchemeBegin, pSchemeEnd - pSchemeBegin); 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode(':')); 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir sal_Char cEscapePrefix = getEscapePrefix(); 1621cdf0e10cSrcweir 1622cdf0e10cSrcweir State eState = STATE_AUTH; 1623cdf0e10cSrcweir bool bSameDoc = true; 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir if (getSchemeInfo().m_bAuthority) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir if (pEnd - p >= 2 && p[0] == '/' && p[1] == '/') 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir aSynAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 1630cdf0e10cSrcweir p += 2; 1631cdf0e10cSrcweir eState = STATE_ABS_PATH; 1632cdf0e10cSrcweir bSameDoc = false; 1633cdf0e10cSrcweir while (p != pEnd) 1634cdf0e10cSrcweir { 1635cdf0e10cSrcweir EscapeType eEscapeType; 1636cdf0e10cSrcweir sal_uInt32 nUTF32 1637cdf0e10cSrcweir = getUTF32(p, pEnd, bOctets, cEscapePrefix, eMechanism, 1638cdf0e10cSrcweir eCharset, eEscapeType); 1639cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO) 1640cdf0e10cSrcweir { 1641cdf0e10cSrcweir if (nUTF32 == nSegmentDelimiter) 1642cdf0e10cSrcweir break; 1643cdf0e10cSrcweir else if (nUTF32 == nFragmentDelimiter) 1644cdf0e10cSrcweir { 1645cdf0e10cSrcweir eState = STATE_FRAGMENT; 1646cdf0e10cSrcweir break; 1647cdf0e10cSrcweir } 1648cdf0e10cSrcweir } 1649cdf0e10cSrcweir appendUCS4(aSynAbsURIRef, nUTF32, eEscapeType, bOctets, 1650cdf0e10cSrcweir PART_VISIBLE, cEscapePrefix, eCharset, true); 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir else 1654cdf0e10cSrcweir { 1655cdf0e10cSrcweir SubString aAuthority(getAuthority()); 1656cdf0e10cSrcweir aSynAbsURIRef.append(m_aAbsURIRef.getStr() 1657cdf0e10cSrcweir + aAuthority.getBegin(), 1658cdf0e10cSrcweir aAuthority.getLength()); 1659cdf0e10cSrcweir } 1660cdf0e10cSrcweir } 1661cdf0e10cSrcweir 1662cdf0e10cSrcweir if (eState == STATE_AUTH) 1663cdf0e10cSrcweir { 1664cdf0e10cSrcweir if (p == pEnd) 1665cdf0e10cSrcweir eState = STATE_DONE; 1666cdf0e10cSrcweir else if (*p == nFragmentDelimiter) 1667cdf0e10cSrcweir { 1668cdf0e10cSrcweir ++p; 1669cdf0e10cSrcweir eState = STATE_FRAGMENT; 1670cdf0e10cSrcweir } 1671cdf0e10cSrcweir else if (*p == nSegmentDelimiter) 1672cdf0e10cSrcweir { 1673cdf0e10cSrcweir ++p; 1674cdf0e10cSrcweir eState = STATE_ABS_PATH; 1675cdf0e10cSrcweir bSameDoc = false; 1676cdf0e10cSrcweir } 1677cdf0e10cSrcweir else 1678cdf0e10cSrcweir { 1679cdf0e10cSrcweir eState = STATE_REL_PATH; 1680cdf0e10cSrcweir bSameDoc = false; 1681cdf0e10cSrcweir } 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir 1684cdf0e10cSrcweir if (eState == STATE_ABS_PATH) 1685cdf0e10cSrcweir { 1686cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 1687cdf0e10cSrcweir eState = STATE_DONE; 1688cdf0e10cSrcweir while (p != pEnd) 1689cdf0e10cSrcweir { 1690cdf0e10cSrcweir EscapeType eEscapeType; 1691cdf0e10cSrcweir sal_uInt32 nUTF32 1692cdf0e10cSrcweir = getUTF32(p, pEnd, bOctets, cEscapePrefix, eMechanism, 1693cdf0e10cSrcweir eCharset, eEscapeType); 1694cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO) 1695cdf0e10cSrcweir { 1696cdf0e10cSrcweir if (nUTF32 == nFragmentDelimiter) 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir eState = STATE_FRAGMENT; 1699cdf0e10cSrcweir break; 1700cdf0e10cSrcweir } 1701cdf0e10cSrcweir else if (nUTF32 == nSegmentDelimiter) 1702cdf0e10cSrcweir nUTF32 = '/'; 1703cdf0e10cSrcweir } 1704cdf0e10cSrcweir appendUCS4(aSynAbsURIRef, nUTF32, eEscapeType, bOctets, ePart, 1705cdf0e10cSrcweir cEscapePrefix, eCharset, true); 1706cdf0e10cSrcweir } 1707cdf0e10cSrcweir } 1708cdf0e10cSrcweir else if (eState == STATE_REL_PATH) 1709cdf0e10cSrcweir { 1710cdf0e10cSrcweir if (!getSchemeInfo().m_bHierarchical) 1711cdf0e10cSrcweir { 1712cdf0e10cSrcweir // Detect cases where a relative input could not be made absolute 1713cdf0e10cSrcweir // because the given base URL is broken (most probably because it is 1714cdf0e10cSrcweir // empty): 1715cdf0e10cSrcweir OSL_ASSERT(!HasError()); 1716cdf0e10cSrcweir rWasAbsolute = false; 1717cdf0e10cSrcweir return false; 1718cdf0e10cSrcweir } 1719cdf0e10cSrcweir 1720cdf0e10cSrcweir sal_Unicode const * pBasePathBegin 1721cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 1722cdf0e10cSrcweir sal_Unicode const * pBasePathEnd 1723cdf0e10cSrcweir = pBasePathBegin + m_aPath.getLength(); 1724cdf0e10cSrcweir while (pBasePathEnd != pBasePathBegin) 1725cdf0e10cSrcweir if (*(--pBasePathEnd) == '/') 1726cdf0e10cSrcweir { 1727cdf0e10cSrcweir ++pBasePathEnd; 1728cdf0e10cSrcweir break; 1729cdf0e10cSrcweir } 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir sal_Int32 nPathBegin = aSynAbsURIRef.getLength(); 1732cdf0e10cSrcweir aSynAbsURIRef.append(pBasePathBegin, pBasePathEnd - pBasePathBegin); 1733cdf0e10cSrcweir DBG_ASSERT(aSynAbsURIRef.getLength() > nPathBegin 1734cdf0e10cSrcweir && aSynAbsURIRef.charAt(aSynAbsURIRef.getLength() - 1) == '/', 1735cdf0e10cSrcweir "INetURLObject::convertRelToAbs(): Bad base path"); 1736cdf0e10cSrcweir 1737cdf0e10cSrcweir while (p != pEnd && *p != nQueryDelimiter && *p != nFragmentDelimiter) 1738cdf0e10cSrcweir { 1739cdf0e10cSrcweir if (*p == '.') 1740cdf0e10cSrcweir { 1741cdf0e10cSrcweir if (pEnd - p == 1 1742cdf0e10cSrcweir || p[1] == nSegmentDelimiter 1743cdf0e10cSrcweir || p[1] == nQueryDelimiter 1744cdf0e10cSrcweir || p[1] == nFragmentDelimiter) 1745cdf0e10cSrcweir { 1746cdf0e10cSrcweir ++p; 1747cdf0e10cSrcweir if (p != pEnd && *p == nSegmentDelimiter) 1748cdf0e10cSrcweir ++p; 1749cdf0e10cSrcweir continue; 1750cdf0e10cSrcweir } 1751cdf0e10cSrcweir else if (pEnd - p >= 2 1752cdf0e10cSrcweir && p[1] == '.' 1753cdf0e10cSrcweir && (pEnd - p == 2 1754cdf0e10cSrcweir || p[2] == nSegmentDelimiter 1755cdf0e10cSrcweir || p[2] == nQueryDelimiter 1756cdf0e10cSrcweir || p[2] == nFragmentDelimiter) 1757cdf0e10cSrcweir && aSynAbsURIRef.getLength() - nPathBegin > 1) 1758cdf0e10cSrcweir { 1759cdf0e10cSrcweir p += 2; 1760cdf0e10cSrcweir if (p != pEnd && *p == nSegmentDelimiter) 1761cdf0e10cSrcweir ++p; 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir sal_Int32 i = aSynAbsURIRef.getLength() - 2; 1764cdf0e10cSrcweir while (i > nPathBegin && aSynAbsURIRef.charAt(i) != '/') 1765cdf0e10cSrcweir --i; 1766cdf0e10cSrcweir aSynAbsURIRef.setLength(i + 1); 1767cdf0e10cSrcweir DBG_ASSERT( 1768cdf0e10cSrcweir aSynAbsURIRef.getLength() > nPathBegin 1769cdf0e10cSrcweir && aSynAbsURIRef.charAt(aSynAbsURIRef.getLength() - 1) 1770cdf0e10cSrcweir == '/', 1771cdf0e10cSrcweir "INetURLObject::convertRelToAbs(): Bad base path"); 1772cdf0e10cSrcweir continue; 1773cdf0e10cSrcweir } 1774cdf0e10cSrcweir } 1775cdf0e10cSrcweir 1776cdf0e10cSrcweir while (p != pEnd 1777cdf0e10cSrcweir && *p != nSegmentDelimiter 1778cdf0e10cSrcweir && *p != nQueryDelimiter 1779cdf0e10cSrcweir && *p != nFragmentDelimiter) 1780cdf0e10cSrcweir { 1781cdf0e10cSrcweir EscapeType eEscapeType; 1782cdf0e10cSrcweir sal_uInt32 nUTF32 1783cdf0e10cSrcweir = getUTF32(p, pEnd, bOctets, cEscapePrefix, eMechanism, 1784cdf0e10cSrcweir eCharset, eEscapeType); 1785cdf0e10cSrcweir appendUCS4(aSynAbsURIRef, nUTF32, eEscapeType, bOctets, ePart, 1786cdf0e10cSrcweir cEscapePrefix, eCharset, true); 1787cdf0e10cSrcweir } 1788cdf0e10cSrcweir if (p != pEnd && *p == nSegmentDelimiter) 1789cdf0e10cSrcweir { 1790cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 1791cdf0e10cSrcweir ++p; 1792cdf0e10cSrcweir } 1793cdf0e10cSrcweir } 1794cdf0e10cSrcweir 1795cdf0e10cSrcweir while (p != pEnd && *p != nFragmentDelimiter) 1796cdf0e10cSrcweir { 1797cdf0e10cSrcweir EscapeType eEscapeType; 1798cdf0e10cSrcweir sal_uInt32 nUTF32 1799cdf0e10cSrcweir = getUTF32(p, pEnd, bOctets, cEscapePrefix, eMechanism, 1800cdf0e10cSrcweir eCharset, eEscapeType); 1801cdf0e10cSrcweir appendUCS4(aSynAbsURIRef, nUTF32, eEscapeType, bOctets, ePart, 1802cdf0e10cSrcweir cEscapePrefix, eCharset, true); 1803cdf0e10cSrcweir } 1804cdf0e10cSrcweir 1805cdf0e10cSrcweir if (p == pEnd) 1806cdf0e10cSrcweir eState = STATE_DONE; 1807cdf0e10cSrcweir else 1808cdf0e10cSrcweir { 1809cdf0e10cSrcweir ++p; 1810cdf0e10cSrcweir eState = STATE_FRAGMENT; 1811cdf0e10cSrcweir } 1812cdf0e10cSrcweir } 1813cdf0e10cSrcweir else if (bSameDoc) 1814cdf0e10cSrcweir { 1815cdf0e10cSrcweir aSynAbsURIRef.append(m_aAbsURIRef.getStr() + m_aPath.getBegin(), 1816cdf0e10cSrcweir m_aPath.getLength()); 1817cdf0e10cSrcweir if (m_aQuery.isPresent()) 1818cdf0e10cSrcweir aSynAbsURIRef.append(m_aAbsURIRef.getStr() 1819cdf0e10cSrcweir + m_aQuery.getBegin() - 1, 1820cdf0e10cSrcweir m_aQuery.getLength() + 1); 1821cdf0e10cSrcweir } 1822cdf0e10cSrcweir 1823cdf0e10cSrcweir if (eState == STATE_FRAGMENT && !bIgnoreFragment) 1824cdf0e10cSrcweir { 1825cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('#')); 1826cdf0e10cSrcweir while (p != pEnd) 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir EscapeType eEscapeType; 1829cdf0e10cSrcweir sal_uInt32 nUTF32 1830cdf0e10cSrcweir = getUTF32(p, pEnd, bOctets, cEscapePrefix, eMechanism, 1831cdf0e10cSrcweir eCharset, eEscapeType); 1832cdf0e10cSrcweir appendUCS4(aSynAbsURIRef, nUTF32, eEscapeType, bOctets, 1833cdf0e10cSrcweir PART_VISIBLE, cEscapePrefix, eCharset, true); 1834cdf0e10cSrcweir } 1835cdf0e10cSrcweir } 1836cdf0e10cSrcweir 1837cdf0e10cSrcweir INetURLObject aNewURI(aSynAbsURIRef.makeStringAndClear()); 1838cdf0e10cSrcweir if (aNewURI.HasError()) 1839cdf0e10cSrcweir { 1840cdf0e10cSrcweir // Detect cases where a relative input could not be made absolute 1841cdf0e10cSrcweir // because the given base URL is broken (most probably because it is 1842cdf0e10cSrcweir // empty): 1843cdf0e10cSrcweir OSL_ASSERT(!HasError()); 1844cdf0e10cSrcweir rWasAbsolute = false; 1845cdf0e10cSrcweir return false; 1846cdf0e10cSrcweir } 1847cdf0e10cSrcweir 1848cdf0e10cSrcweir rTheAbsURIRef = aNewURI; 1849cdf0e10cSrcweir return true; 1850cdf0e10cSrcweir } 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir //============================================================================ 1853cdf0e10cSrcweir bool INetURLObject::convertAbsToRel(rtl::OUString const & rTheAbsURIRef, 1854cdf0e10cSrcweir bool bOctets, rtl::OUString & rTheRelURIRef, 1855cdf0e10cSrcweir EncodeMechanism eEncodeMechanism, 1856cdf0e10cSrcweir DecodeMechanism eDecodeMechanism, 1857cdf0e10cSrcweir rtl_TextEncoding eCharset, 1858cdf0e10cSrcweir FSysStyle eStyle) const 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir // Check for hierarchical base URL: 1861cdf0e10cSrcweir if (!getSchemeInfo().m_bHierarchical) 1862cdf0e10cSrcweir { 1863cdf0e10cSrcweir rTheRelURIRef 1864cdf0e10cSrcweir = decode(rTheAbsURIRef, 1865cdf0e10cSrcweir getEscapePrefix(CompareProtocolScheme(rTheAbsURIRef)), 1866cdf0e10cSrcweir eDecodeMechanism, eCharset); 1867cdf0e10cSrcweir return false; 1868cdf0e10cSrcweir } 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir // Convert the input (absolute or relative URI ref) to an absolute URI 1871cdf0e10cSrcweir // ref: 1872cdf0e10cSrcweir INetURLObject aSubject; 1873cdf0e10cSrcweir bool bWasAbsolute; 1874cdf0e10cSrcweir if (!convertRelToAbs(rTheAbsURIRef, bOctets, aSubject, bWasAbsolute, 1875cdf0e10cSrcweir eEncodeMechanism, eCharset, false, false, false, 1876cdf0e10cSrcweir eStyle)) 1877cdf0e10cSrcweir { 1878cdf0e10cSrcweir rTheRelURIRef 1879cdf0e10cSrcweir = decode(rTheAbsURIRef, 1880cdf0e10cSrcweir getEscapePrefix(CompareProtocolScheme(rTheAbsURIRef)), 1881cdf0e10cSrcweir eDecodeMechanism, eCharset); 1882cdf0e10cSrcweir return false; 1883cdf0e10cSrcweir } 1884cdf0e10cSrcweir 1885cdf0e10cSrcweir // Check for differing scheme or authority parts: 1886cdf0e10cSrcweir if ((m_aScheme.compare( 1887cdf0e10cSrcweir aSubject.m_aScheme, m_aAbsURIRef, aSubject.m_aAbsURIRef) 1888cdf0e10cSrcweir != 0) 1889cdf0e10cSrcweir || (m_aUser.compare( 1890cdf0e10cSrcweir aSubject.m_aUser, m_aAbsURIRef, aSubject.m_aAbsURIRef) 1891cdf0e10cSrcweir != 0) 1892cdf0e10cSrcweir || (m_aAuth.compare( 1893cdf0e10cSrcweir aSubject.m_aAuth, m_aAbsURIRef, aSubject.m_aAbsURIRef) 1894cdf0e10cSrcweir != 0) 1895cdf0e10cSrcweir || (m_aHost.compare( 1896cdf0e10cSrcweir aSubject.m_aHost, m_aAbsURIRef, aSubject.m_aAbsURIRef) 1897cdf0e10cSrcweir != 0) 1898cdf0e10cSrcweir || (m_aPort.compare( 1899cdf0e10cSrcweir aSubject.m_aPort, m_aAbsURIRef, aSubject.m_aAbsURIRef) 1900cdf0e10cSrcweir != 0)) 1901cdf0e10cSrcweir { 1902cdf0e10cSrcweir rTheRelURIRef = aSubject.GetMainURL(eDecodeMechanism, eCharset); 1903cdf0e10cSrcweir return false; 1904cdf0e10cSrcweir } 1905cdf0e10cSrcweir 1906cdf0e10cSrcweir sal_Unicode const * pBasePathBegin 1907cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 1908cdf0e10cSrcweir sal_Unicode const * pBasePathEnd = pBasePathBegin + m_aPath.getLength(); 1909cdf0e10cSrcweir sal_Unicode const * pSubjectPathBegin 1910cdf0e10cSrcweir = aSubject.m_aAbsURIRef.getStr() + aSubject.m_aPath.getBegin(); 1911cdf0e10cSrcweir sal_Unicode const * pSubjectPathEnd 1912cdf0e10cSrcweir = pSubjectPathBegin + aSubject.m_aPath.getLength(); 1913cdf0e10cSrcweir 1914cdf0e10cSrcweir // Make nMatch point past the last matching slash, or past the end of the 1915cdf0e10cSrcweir // paths, in case they are equal: 1916cdf0e10cSrcweir sal_Unicode const * pSlash = 0; 1917cdf0e10cSrcweir sal_Unicode const * p1 = pBasePathBegin; 1918cdf0e10cSrcweir sal_Unicode const * p2 = pSubjectPathBegin; 1919cdf0e10cSrcweir for (;;) 1920cdf0e10cSrcweir { 1921cdf0e10cSrcweir if (p1 == pBasePathEnd || p2 == pSubjectPathEnd) 1922cdf0e10cSrcweir { 1923cdf0e10cSrcweir if (p1 == pBasePathEnd && p2 == pSubjectPathEnd) 1924cdf0e10cSrcweir pSlash = p1; 1925cdf0e10cSrcweir break; 1926cdf0e10cSrcweir } 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir sal_Unicode c = *p1++; 1929cdf0e10cSrcweir if (c != *p2++) 1930cdf0e10cSrcweir break; 1931cdf0e10cSrcweir if (c == '/') 1932cdf0e10cSrcweir pSlash = p1; 1933cdf0e10cSrcweir } 1934cdf0e10cSrcweir if (!pSlash) 1935cdf0e10cSrcweir { 1936cdf0e10cSrcweir // One of the paths does not start with '/': 1937cdf0e10cSrcweir rTheRelURIRef = aSubject.GetMainURL(eDecodeMechanism, eCharset); 1938cdf0e10cSrcweir return false; 1939cdf0e10cSrcweir } 1940cdf0e10cSrcweir sal_Int32 nMatch = pSlash - pBasePathBegin; 1941cdf0e10cSrcweir 1942cdf0e10cSrcweir // If the two URLs are DOS file URLs starting with different volumes 1943cdf0e10cSrcweir // (e.g., file:///a:/... and file:///b:/...), the subject is not made 1944cdf0e10cSrcweir // relative (it could be, but some people do not like that): 1945cdf0e10cSrcweir if (m_eScheme == INET_PROT_FILE 1946cdf0e10cSrcweir && nMatch <= 1 1947cdf0e10cSrcweir && hasDosVolume(eStyle) 1948cdf0e10cSrcweir && aSubject.hasDosVolume(eStyle)) //TODO! ok to use eStyle for these? 1949cdf0e10cSrcweir { 1950cdf0e10cSrcweir rTheRelURIRef = aSubject.GetMainURL(eDecodeMechanism, eCharset); 1951cdf0e10cSrcweir return false; 1952cdf0e10cSrcweir } 1953cdf0e10cSrcweir 1954cdf0e10cSrcweir // For every slash in the base path after nMatch, a prefix of "../" is 1955cdf0e10cSrcweir // added to the new relative URL (if the common prefix of the two paths is 1956cdf0e10cSrcweir // only "/"---but see handling of file URLs above---, the complete subject 1957cdf0e10cSrcweir // path could go into the new relative URL instead, but some people don't 1958cdf0e10cSrcweir // like that): 1959cdf0e10cSrcweir rtl::OUStringBuffer aSynRelURIRef; 1960cdf0e10cSrcweir // if (nMatch <= 1) nMatch = 0; else // see comment above 1961cdf0e10cSrcweir for (sal_Unicode const * p = pBasePathBegin + nMatch; p != pBasePathEnd; 1962cdf0e10cSrcweir ++p) 1963cdf0e10cSrcweir { 1964cdf0e10cSrcweir if (*p == '/') 1965cdf0e10cSrcweir aSynRelURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("../")); 1966cdf0e10cSrcweir } 1967cdf0e10cSrcweir 1968cdf0e10cSrcweir // If the new relative URL would start with "//" (i.e., it would be 1969cdf0e10cSrcweir // mistaken for a relative URL starting with an authority part), or if the 1970cdf0e10cSrcweir // new relative URL would neither be empty nor start with <"/"> nor start 1971cdf0e10cSrcweir // with <1*rseg> (i.e., it could be mistaken for an absolute URL starting 1972cdf0e10cSrcweir // with a scheme part), then the new relative URL is prefixed with "./": 1973cdf0e10cSrcweir if (aSynRelURIRef.getLength() == 0) 1974cdf0e10cSrcweir { 1975cdf0e10cSrcweir if (pSubjectPathEnd - pSubjectPathBegin >= nMatch + 2 1976cdf0e10cSrcweir && pSubjectPathBegin[nMatch] == '/' 1977cdf0e10cSrcweir && pSubjectPathBegin[nMatch + 1] == '/') 1978cdf0e10cSrcweir { 1979cdf0e10cSrcweir aSynRelURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("./")); 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir else 1982cdf0e10cSrcweir { 1983cdf0e10cSrcweir for (sal_Unicode const * p = pSubjectPathBegin + nMatch; 1984cdf0e10cSrcweir p != pSubjectPathEnd && *p != '/'; ++p) 1985cdf0e10cSrcweir { 1986cdf0e10cSrcweir if (mustEncode(*p, PART_REL_SEGMENT_EXTRA)) 1987cdf0e10cSrcweir { 1988cdf0e10cSrcweir aSynRelURIRef. 1989cdf0e10cSrcweir appendAscii(RTL_CONSTASCII_STRINGPARAM("./")); 1990cdf0e10cSrcweir break; 1991cdf0e10cSrcweir } 1992cdf0e10cSrcweir } 1993cdf0e10cSrcweir } 1994cdf0e10cSrcweir } 1995cdf0e10cSrcweir 1996cdf0e10cSrcweir // The remainder of the subject path, starting at nMatch, is appended to 1997cdf0e10cSrcweir // the new relative URL: 1998cdf0e10cSrcweir sal_Char cEscapePrefix = getEscapePrefix(); 1999cdf0e10cSrcweir aSynRelURIRef.append(decode(pSubjectPathBegin + nMatch, pSubjectPathEnd, 2000cdf0e10cSrcweir cEscapePrefix, eDecodeMechanism, eCharset)); 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir // If the subject has defined query or fragment parts, they are appended 2003cdf0e10cSrcweir // to the new relative URL: 2004cdf0e10cSrcweir if (aSubject.m_aQuery.isPresent()) 2005cdf0e10cSrcweir { 2006cdf0e10cSrcweir aSynRelURIRef.append(sal_Unicode('?')); 2007cdf0e10cSrcweir aSynRelURIRef.append(aSubject.decode(aSubject.m_aQuery, cEscapePrefix, 2008cdf0e10cSrcweir eDecodeMechanism, eCharset)); 2009cdf0e10cSrcweir } 2010cdf0e10cSrcweir if (aSubject.m_aFragment.isPresent()) 2011cdf0e10cSrcweir { 2012cdf0e10cSrcweir aSynRelURIRef.append(sal_Unicode('#')); 2013cdf0e10cSrcweir aSynRelURIRef.append(aSubject.decode(aSubject.m_aFragment, 2014cdf0e10cSrcweir cEscapePrefix, eDecodeMechanism, eCharset)); 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir 2017cdf0e10cSrcweir rTheRelURIRef = aSynRelURIRef.makeStringAndClear(); 2018cdf0e10cSrcweir return true; 2019cdf0e10cSrcweir } 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir //============================================================================ 2022cdf0e10cSrcweir // static 2023cdf0e10cSrcweir bool INetURLObject::convertIntToExt(rtl::OUString const & rTheIntURIRef, 2024cdf0e10cSrcweir bool bOctets, rtl::OUString & rTheExtURIRef, 2025cdf0e10cSrcweir DecodeMechanism eDecodeMechanism, 2026cdf0e10cSrcweir rtl_TextEncoding eCharset) 2027cdf0e10cSrcweir { 2028cdf0e10cSrcweir sal_Char cEscapePrefix 2029cdf0e10cSrcweir = getEscapePrefix(CompareProtocolScheme(rTheIntURIRef)); 2030cdf0e10cSrcweir rtl::OUString aSynExtURIRef(encodeText(rTheIntURIRef, bOctets, PART_VISIBLE, 2031cdf0e10cSrcweir cEscapePrefix, NOT_CANONIC, eCharset, 2032cdf0e10cSrcweir true)); 2033cdf0e10cSrcweir sal_Unicode const * pBegin = aSynExtURIRef.getStr(); 2034cdf0e10cSrcweir sal_Unicode const * pEnd = pBegin + aSynExtURIRef.getLength(); 2035cdf0e10cSrcweir sal_Unicode const * p = pBegin; 2036cdf0e10cSrcweir PrefixInfo const * pPrefix = getPrefix(p, pEnd); 2037cdf0e10cSrcweir bool bConvert = pPrefix && pPrefix->m_eKind == PrefixInfo::INTERNAL; 2038cdf0e10cSrcweir if (bConvert) 2039cdf0e10cSrcweir { 2040cdf0e10cSrcweir aSynExtURIRef = 2041cdf0e10cSrcweir aSynExtURIRef.replaceAt(0, p - pBegin, 2042cdf0e10cSrcweir rtl::OUString::createFromAscii(pPrefix->m_pTranslatedPrefix)); 2043cdf0e10cSrcweir } 2044cdf0e10cSrcweir rTheExtURIRef = decode(aSynExtURIRef, cEscapePrefix, eDecodeMechanism, 2045cdf0e10cSrcweir eCharset); 2046cdf0e10cSrcweir return bConvert; 2047cdf0e10cSrcweir } 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir //============================================================================ 2050cdf0e10cSrcweir // static 2051cdf0e10cSrcweir bool INetURLObject::convertExtToInt(rtl::OUString const & rTheExtURIRef, 2052cdf0e10cSrcweir bool bOctets, rtl::OUString & rTheIntURIRef, 2053cdf0e10cSrcweir DecodeMechanism eDecodeMechanism, 2054cdf0e10cSrcweir rtl_TextEncoding eCharset) 2055cdf0e10cSrcweir { 2056cdf0e10cSrcweir sal_Char cEscapePrefix 2057cdf0e10cSrcweir = getEscapePrefix(CompareProtocolScheme(rTheExtURIRef)); 2058cdf0e10cSrcweir rtl::OUString aSynIntURIRef(encodeText(rTheExtURIRef, bOctets, PART_VISIBLE, 2059cdf0e10cSrcweir cEscapePrefix, NOT_CANONIC, eCharset, 2060cdf0e10cSrcweir true)); 2061cdf0e10cSrcweir sal_Unicode const * pBegin = aSynIntURIRef.getStr(); 2062cdf0e10cSrcweir sal_Unicode const * pEnd = pBegin + aSynIntURIRef.getLength(); 2063cdf0e10cSrcweir sal_Unicode const * p = pBegin; 2064cdf0e10cSrcweir PrefixInfo const * pPrefix = getPrefix(p, pEnd); 2065cdf0e10cSrcweir bool bConvert = pPrefix && pPrefix->m_eKind == PrefixInfo::EXTERNAL; 2066cdf0e10cSrcweir if (bConvert) 2067cdf0e10cSrcweir { 2068cdf0e10cSrcweir aSynIntURIRef = 2069cdf0e10cSrcweir aSynIntURIRef.replaceAt(0, p - pBegin, 2070cdf0e10cSrcweir rtl::OUString::createFromAscii(pPrefix->m_pTranslatedPrefix)); 2071cdf0e10cSrcweir } 2072cdf0e10cSrcweir rTheIntURIRef = decode(aSynIntURIRef, cEscapePrefix, eDecodeMechanism, 2073cdf0e10cSrcweir eCharset); 2074cdf0e10cSrcweir return bConvert; 2075cdf0e10cSrcweir } 2076cdf0e10cSrcweir 2077cdf0e10cSrcweir //============================================================================ 2078cdf0e10cSrcweir // static 2079cdf0e10cSrcweir INetURLObject::PrefixInfo const * 2080cdf0e10cSrcweir INetURLObject::getPrefix(sal_Unicode const *& rBegin, 2081cdf0e10cSrcweir sal_Unicode const * pEnd) 2082cdf0e10cSrcweir { 2083cdf0e10cSrcweir static PrefixInfo const aMap[] 2084cdf0e10cSrcweir = { // dummy entry at front needed, because pLast may point here: 2085cdf0e10cSrcweir { 0, 0, INET_PROT_NOT_VALID, PrefixInfo::INTERNAL }, 2086cdf0e10cSrcweir { ".component:", "staroffice.component:", INET_PROT_COMPONENT, 2087cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2088cdf0e10cSrcweir { ".uno:", "staroffice.uno:", INET_PROT_UNO, 2089cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2090cdf0e10cSrcweir { "cid:", 0, INET_PROT_CID, PrefixInfo::OFFICIAL }, 2091cdf0e10cSrcweir { "data:", 0, INET_PROT_DATA, PrefixInfo::OFFICIAL }, 2092cdf0e10cSrcweir { "db:", "staroffice.db:", INET_PROT_DB, PrefixInfo::INTERNAL }, 2093cdf0e10cSrcweir { "file:", 0, INET_PROT_FILE, PrefixInfo::OFFICIAL }, 2094cdf0e10cSrcweir { "ftp:", 0, INET_PROT_FTP, PrefixInfo::OFFICIAL }, 2095cdf0e10cSrcweir { "hid:", "staroffice.hid:", INET_PROT_HID, 2096cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2097cdf0e10cSrcweir { "http:", 0, INET_PROT_HTTP, PrefixInfo::OFFICIAL }, 2098cdf0e10cSrcweir { "https:", 0, INET_PROT_HTTPS, PrefixInfo::OFFICIAL }, 2099cdf0e10cSrcweir { "imap:", 0, INET_PROT_IMAP, PrefixInfo::OFFICIAL }, 2100cdf0e10cSrcweir { "javascript:", 0, INET_PROT_JAVASCRIPT, PrefixInfo::OFFICIAL }, 2101cdf0e10cSrcweir { "ldap:", 0, INET_PROT_LDAP, PrefixInfo::OFFICIAL }, 2102cdf0e10cSrcweir { "macro:", "staroffice.macro:", INET_PROT_MACRO, 2103cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2104cdf0e10cSrcweir { "mailto:", 0, INET_PROT_MAILTO, PrefixInfo::OFFICIAL }, 2105cdf0e10cSrcweir { "news:", 0, INET_PROT_NEWS, PrefixInfo::OFFICIAL }, 2106cdf0e10cSrcweir { "out:", "staroffice.out:", INET_PROT_OUT, 2107cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2108cdf0e10cSrcweir { "pop3:", "staroffice.pop3:", INET_PROT_POP3, 2109cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2110cdf0e10cSrcweir { "private:", "staroffice.private:", INET_PROT_PRIV_SOFFICE, 2111cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2112cdf0e10cSrcweir { "private:factory/", "staroffice.factory:", 2113cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::INTERNAL }, 2114cdf0e10cSrcweir { "private:helpid/", "staroffice.helpid:", INET_PROT_PRIV_SOFFICE, 2115cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2116cdf0e10cSrcweir { "private:java/", "staroffice.java:", INET_PROT_PRIV_SOFFICE, 2117cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2118cdf0e10cSrcweir { "private:searchfolder:", "staroffice.searchfolder:", 2119cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::INTERNAL }, 2120cdf0e10cSrcweir { "private:trashcan:", "staroffice.trashcan:", 2121cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::INTERNAL }, 2122cdf0e10cSrcweir { "slot:", "staroffice.slot:", INET_PROT_SLOT, 2123cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2124cdf0e10cSrcweir { "smb:", 0, INET_PROT_SMB, PrefixInfo::OFFICIAL }, 2125cdf0e10cSrcweir { "staroffice.component:", ".component:", INET_PROT_COMPONENT, 2126cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2127cdf0e10cSrcweir { "staroffice.db:", "db:", INET_PROT_DB, PrefixInfo::EXTERNAL }, 2128cdf0e10cSrcweir { "staroffice.factory:", "private:factory/", 2129cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::EXTERNAL }, 2130cdf0e10cSrcweir { "staroffice.helpid:", "private:helpid/", INET_PROT_PRIV_SOFFICE, 2131cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2132cdf0e10cSrcweir { "staroffice.hid:", "hid:", INET_PROT_HID, 2133cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2134cdf0e10cSrcweir { "staroffice.java:", "private:java/", INET_PROT_PRIV_SOFFICE, 2135cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2136cdf0e10cSrcweir { "staroffice.macro:", "macro:", INET_PROT_MACRO, 2137cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2138cdf0e10cSrcweir { "staroffice.out:", "out:", INET_PROT_OUT, 2139cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2140cdf0e10cSrcweir { "staroffice.pop3:", "pop3:", INET_PROT_POP3, 2141cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2142cdf0e10cSrcweir { "staroffice.private:", "private:", INET_PROT_PRIV_SOFFICE, 2143cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2144cdf0e10cSrcweir { "staroffice.searchfolder:", "private:searchfolder:", 2145cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::EXTERNAL }, 2146cdf0e10cSrcweir { "staroffice.slot:", "slot:", INET_PROT_SLOT, 2147cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2148cdf0e10cSrcweir { "staroffice.trashcan:", "private:trashcan:", 2149cdf0e10cSrcweir INET_PROT_PRIV_SOFFICE, PrefixInfo::EXTERNAL }, 2150cdf0e10cSrcweir { "staroffice.uno:", ".uno:", INET_PROT_UNO, 2151cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2152cdf0e10cSrcweir { "staroffice.vim:", "vim:", INET_PROT_VIM, 2153cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2154cdf0e10cSrcweir { "staroffice:", "private:", INET_PROT_PRIV_SOFFICE, 2155cdf0e10cSrcweir PrefixInfo::EXTERNAL }, 2156cdf0e10cSrcweir { "telnet:", 0, INET_PROT_TELNET, PrefixInfo::OFFICIAL }, 2157cdf0e10cSrcweir { "vim:", "staroffice.vim:", INET_PROT_VIM, 2158cdf0e10cSrcweir PrefixInfo::INTERNAL }, 2159cdf0e10cSrcweir { "vnd.sun.star.cmd:", 0, INET_PROT_VND_SUN_STAR_CMD, 2160cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2161cdf0e10cSrcweir { "vnd.sun.star.expand:", 0, INET_PROT_VND_SUN_STAR_EXPAND, 2162cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2163cdf0e10cSrcweir { "vnd.sun.star.help:", 0, INET_PROT_VND_SUN_STAR_HELP, 2164cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2165cdf0e10cSrcweir { "vnd.sun.star.hier:", 0, INET_PROT_VND_SUN_STAR_HIER, 2166cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2167cdf0e10cSrcweir { "vnd.sun.star.odma:", 0, INET_PROT_VND_SUN_STAR_ODMA, 2168cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2169cdf0e10cSrcweir { "vnd.sun.star.pkg:", 0, INET_PROT_VND_SUN_STAR_PKG, 2170cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2171cdf0e10cSrcweir { "vnd.sun.star.tdoc:", 0, INET_PROT_VND_SUN_STAR_TDOC, 2172cdf0e10cSrcweir PrefixInfo::OFFICIAL }, 2173cdf0e10cSrcweir { "vnd.sun.star.webdav:", 0, INET_PROT_VND_SUN_STAR_WEBDAV, 2174cdf0e10cSrcweir PrefixInfo::OFFICIAL } }; 2175cdf0e10cSrcweir PrefixInfo const * pFirst = aMap + 1; 2176cdf0e10cSrcweir PrefixInfo const * pLast = aMap + sizeof aMap / sizeof (PrefixInfo) - 1; 2177cdf0e10cSrcweir PrefixInfo const * pMatch = 0; 2178cdf0e10cSrcweir sal_Unicode const * pMatched = rBegin; 2179cdf0e10cSrcweir sal_Unicode const * p = rBegin; 2180cdf0e10cSrcweir sal_Int32 i = 0; 2181cdf0e10cSrcweir for (; pFirst < pLast; ++i) 2182cdf0e10cSrcweir { 2183cdf0e10cSrcweir if (pFirst->m_pPrefix[i] == '\0') 2184cdf0e10cSrcweir { 2185cdf0e10cSrcweir pMatch = pFirst++; 2186cdf0e10cSrcweir pMatched = p; 2187cdf0e10cSrcweir } 2188cdf0e10cSrcweir if (p >= pEnd) 2189cdf0e10cSrcweir break; 2190cdf0e10cSrcweir sal_uInt32 nChar = INetMIME::toLowerCase(*p++); 2191cdf0e10cSrcweir while (pFirst <= pLast && sal_uChar(pFirst->m_pPrefix[i]) < nChar) 2192cdf0e10cSrcweir ++pFirst; 2193cdf0e10cSrcweir while (pFirst <= pLast && sal_uChar(pLast->m_pPrefix[i]) > nChar) 2194cdf0e10cSrcweir --pLast; 2195cdf0e10cSrcweir } 2196cdf0e10cSrcweir if (pFirst == pLast) 2197cdf0e10cSrcweir { 2198cdf0e10cSrcweir sal_Char const * q = pFirst->m_pPrefix + i; 2199cdf0e10cSrcweir while (p < pEnd && *q != '\0' 2200cdf0e10cSrcweir && INetMIME::toLowerCase(*p) == sal_uChar(*q)) 2201cdf0e10cSrcweir { 2202cdf0e10cSrcweir ++p; 2203cdf0e10cSrcweir ++q; 2204cdf0e10cSrcweir } 2205cdf0e10cSrcweir if (*q == '\0') 2206cdf0e10cSrcweir { 2207cdf0e10cSrcweir rBegin = p; 2208cdf0e10cSrcweir return pFirst; 2209cdf0e10cSrcweir } 2210cdf0e10cSrcweir } 2211cdf0e10cSrcweir rBegin = pMatched; 2212cdf0e10cSrcweir return pMatch; 2213cdf0e10cSrcweir } 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir //============================================================================ 2216cdf0e10cSrcweir sal_Int32 INetURLObject::getAuthorityBegin() const 2217cdf0e10cSrcweir { 2218cdf0e10cSrcweir DBG_ASSERT(getSchemeInfo().m_bAuthority, 2219cdf0e10cSrcweir "INetURLObject::getAuthority(): Bad scheme"); 2220cdf0e10cSrcweir sal_Int32 nBegin; 2221cdf0e10cSrcweir if (m_aUser.isPresent()) 2222cdf0e10cSrcweir nBegin = m_aUser.getBegin(); 2223cdf0e10cSrcweir else if (m_aHost.isPresent()) 2224cdf0e10cSrcweir nBegin = m_aHost.getBegin(); 2225cdf0e10cSrcweir else 2226cdf0e10cSrcweir nBegin = m_aPath.getBegin(); 2227cdf0e10cSrcweir nBegin -= RTL_CONSTASCII_LENGTH("//"); 2228cdf0e10cSrcweir DBG_ASSERT(m_aAbsURIRef.charAt(nBegin) == '/' 2229cdf0e10cSrcweir && m_aAbsURIRef.charAt(nBegin + 1) == '/', 2230cdf0e10cSrcweir "INetURLObject::getAuthority(): Bad authority"); 2231cdf0e10cSrcweir return nBegin; 2232cdf0e10cSrcweir } 2233cdf0e10cSrcweir 2234cdf0e10cSrcweir //============================================================================ 2235cdf0e10cSrcweir INetURLObject::SubString INetURLObject::getAuthority() const 2236cdf0e10cSrcweir { 2237cdf0e10cSrcweir sal_Int32 nBegin = getAuthorityBegin(); 2238cdf0e10cSrcweir sal_Int32 nEnd = m_aPort.isPresent() ? m_aPort.getEnd() : 2239cdf0e10cSrcweir m_aHost.isPresent() ? m_aHost.getEnd() : 2240cdf0e10cSrcweir m_aAuth.isPresent() ? m_aAuth.getEnd() : 2241cdf0e10cSrcweir m_aUser.isPresent() ? m_aUser.getEnd() : 2242cdf0e10cSrcweir nBegin + RTL_CONSTASCII_LENGTH("//"); 2243cdf0e10cSrcweir return SubString(nBegin, nEnd - nBegin); 2244cdf0e10cSrcweir } 2245cdf0e10cSrcweir 2246cdf0e10cSrcweir //============================================================================ 2247cdf0e10cSrcweir bool INetURLObject::setUser(rtl::OUString const & rTheUser, 2248cdf0e10cSrcweir bool bOctets, EncodeMechanism eMechanism, 2249cdf0e10cSrcweir rtl_TextEncoding eCharset) 2250cdf0e10cSrcweir { 2251cdf0e10cSrcweir if ( 2252cdf0e10cSrcweir !getSchemeInfo().m_bUser || 2253cdf0e10cSrcweir (m_eScheme == INET_PROT_IMAP && rTheUser.getLength() == 0) 2254cdf0e10cSrcweir ) 2255cdf0e10cSrcweir { 2256cdf0e10cSrcweir return false; 2257cdf0e10cSrcweir } 2258cdf0e10cSrcweir 2259cdf0e10cSrcweir rtl::OUString aNewUser(encodeText(rTheUser, bOctets, 2260cdf0e10cSrcweir m_eScheme == INET_PROT_IMAP ? 2261cdf0e10cSrcweir PART_IMAP_ACHAR : 2262cdf0e10cSrcweir m_eScheme == INET_PROT_VIM ? 2263cdf0e10cSrcweir PART_VIM : 2264cdf0e10cSrcweir PART_USER_PASSWORD, 2265cdf0e10cSrcweir getEscapePrefix(), eMechanism, eCharset, 2266cdf0e10cSrcweir false)); 2267cdf0e10cSrcweir sal_Int32 nDelta; 2268cdf0e10cSrcweir if (m_aUser.isPresent()) 2269cdf0e10cSrcweir nDelta = m_aUser.set(m_aAbsURIRef, aNewUser); 2270cdf0e10cSrcweir else if (m_aHost.isPresent()) 2271cdf0e10cSrcweir { 2272cdf0e10cSrcweir m_aAbsURIRef.insert(m_aHost.getBegin(), sal_Unicode('@')); 2273cdf0e10cSrcweir nDelta = m_aUser.set(m_aAbsURIRef, aNewUser, m_aHost.getBegin()) + 1; 2274cdf0e10cSrcweir } 2275cdf0e10cSrcweir else if (getSchemeInfo().m_bHost) 2276cdf0e10cSrcweir return false; 2277cdf0e10cSrcweir else 2278cdf0e10cSrcweir nDelta = m_aUser.set(m_aAbsURIRef, aNewUser, m_aPath.getBegin()); 2279cdf0e10cSrcweir m_aAuth += nDelta; 2280cdf0e10cSrcweir m_aHost += nDelta; 2281cdf0e10cSrcweir m_aPort += nDelta; 2282cdf0e10cSrcweir m_aPath += nDelta; 2283cdf0e10cSrcweir m_aQuery += nDelta; 2284cdf0e10cSrcweir m_aFragment += nDelta; 2285cdf0e10cSrcweir return true; 2286cdf0e10cSrcweir } 2287cdf0e10cSrcweir 2288cdf0e10cSrcweir namespace 2289cdf0e10cSrcweir { 2290cdf0e10cSrcweir void lcl_Erase(rtl::OUStringBuffer &rBuf, sal_Int32 index, sal_Int32 count) 2291cdf0e10cSrcweir { 2292cdf0e10cSrcweir rtl::OUString sTemp(rBuf.makeStringAndClear()); 2293cdf0e10cSrcweir rBuf.append(sTemp.replaceAt(index, count, rtl::OUString())); 2294cdf0e10cSrcweir } 2295cdf0e10cSrcweir } 2296cdf0e10cSrcweir 2297cdf0e10cSrcweir //============================================================================ 2298cdf0e10cSrcweir bool INetURLObject::clearPassword() 2299cdf0e10cSrcweir { 2300cdf0e10cSrcweir if (!getSchemeInfo().m_bPassword) 2301cdf0e10cSrcweir return false; 2302cdf0e10cSrcweir if (m_aAuth.isPresent()) 2303cdf0e10cSrcweir { 2304cdf0e10cSrcweir lcl_Erase(m_aAbsURIRef, m_aAuth.getBegin() - 1, 2305cdf0e10cSrcweir m_aAuth.getLength() + 1); 2306cdf0e10cSrcweir sal_Int32 nDelta = m_aAuth.clear() - 1; 2307cdf0e10cSrcweir m_aHost += nDelta; 2308cdf0e10cSrcweir m_aPort += nDelta; 2309cdf0e10cSrcweir m_aPath += nDelta; 2310cdf0e10cSrcweir m_aQuery += nDelta; 2311cdf0e10cSrcweir m_aFragment += nDelta; 2312cdf0e10cSrcweir } 2313cdf0e10cSrcweir return true; 2314cdf0e10cSrcweir } 2315cdf0e10cSrcweir 2316cdf0e10cSrcweir //============================================================================ 2317cdf0e10cSrcweir bool INetURLObject::setPassword(rtl::OUString const & rThePassword, 2318cdf0e10cSrcweir bool bOctets, EncodeMechanism eMechanism, 2319cdf0e10cSrcweir rtl_TextEncoding eCharset) 2320cdf0e10cSrcweir { 2321cdf0e10cSrcweir if (!getSchemeInfo().m_bPassword) 2322cdf0e10cSrcweir return false; 2323cdf0e10cSrcweir rtl::OUString aNewAuth(encodeText(rThePassword, bOctets, 2324cdf0e10cSrcweir m_eScheme == INET_PROT_VIM ? 2325cdf0e10cSrcweir PART_VIM : PART_USER_PASSWORD, 2326cdf0e10cSrcweir getEscapePrefix(), eMechanism, eCharset, 2327cdf0e10cSrcweir false)); 2328cdf0e10cSrcweir sal_Int32 nDelta; 2329cdf0e10cSrcweir if (m_aAuth.isPresent()) 2330cdf0e10cSrcweir nDelta = m_aAuth.set(m_aAbsURIRef, aNewAuth); 2331cdf0e10cSrcweir else if (m_aUser.isPresent()) 2332cdf0e10cSrcweir { 2333cdf0e10cSrcweir m_aAbsURIRef.insert(m_aUser.getEnd(), sal_Unicode(':')); 2334cdf0e10cSrcweir nDelta 2335cdf0e10cSrcweir = m_aAuth.set(m_aAbsURIRef, aNewAuth, m_aUser.getEnd() + 1) + 1; 2336cdf0e10cSrcweir } 2337cdf0e10cSrcweir else if (m_aHost.isPresent()) 2338cdf0e10cSrcweir { 2339cdf0e10cSrcweir m_aAbsURIRef.insert(m_aHost.getBegin(), 2340cdf0e10cSrcweir rtl::OUString::createFromAscii(":@")); 2341cdf0e10cSrcweir m_aUser.set(m_aAbsURIRef, rtl::OUString(), m_aHost.getBegin()); 2342cdf0e10cSrcweir nDelta 2343cdf0e10cSrcweir = m_aAuth.set(m_aAbsURIRef, aNewAuth, m_aHost.getBegin() + 1) + 2; 2344cdf0e10cSrcweir } 2345cdf0e10cSrcweir else if (getSchemeInfo().m_bHost) 2346cdf0e10cSrcweir return false; 2347cdf0e10cSrcweir else 2348cdf0e10cSrcweir { 2349cdf0e10cSrcweir m_aAbsURIRef.insert(m_aPath.getBegin(), sal_Unicode(':')); 2350cdf0e10cSrcweir m_aUser.set(m_aAbsURIRef, rtl::OUString(), m_aPath.getBegin()); 2351cdf0e10cSrcweir nDelta 2352cdf0e10cSrcweir = m_aAuth.set(m_aAbsURIRef, aNewAuth, m_aPath.getBegin() + 1) + 1; 2353cdf0e10cSrcweir } 2354cdf0e10cSrcweir m_aHost += nDelta; 2355cdf0e10cSrcweir m_aPort += nDelta; 2356cdf0e10cSrcweir m_aPath += nDelta; 2357cdf0e10cSrcweir m_aQuery += nDelta; 2358cdf0e10cSrcweir m_aFragment += nDelta; 2359cdf0e10cSrcweir return true; 2360cdf0e10cSrcweir } 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir //============================================================================ 2363cdf0e10cSrcweir // static 2364cdf0e10cSrcweir bool INetURLObject::parseHost( 2365cdf0e10cSrcweir sal_Unicode const *& rBegin, sal_Unicode const * pEnd, 2366cdf0e10cSrcweir rtl::OUString & rCanonic) 2367cdf0e10cSrcweir { 2368cdf0e10cSrcweir // RFC 2373 is inconsistent about how to write an IPv6 address in which an 2369cdf0e10cSrcweir // IPv4 address directly follows the abbreviating "::". The ABNF in 2370cdf0e10cSrcweir // Appendix B suggests ":::13.1.68.3", while an example in 2.2/3 explicitly 2371cdf0e10cSrcweir // mentions "::13:1.68.3". This algorithm accepts both variants: 2372cdf0e10cSrcweir enum State { STATE_INITIAL, STATE_LABEL, STATE_LABEL_HYPHEN, 2373cdf0e10cSrcweir STATE_LABEL_DOT, STATE_TOPLABEL, STATE_TOPLABEL_HYPHEN, 2374cdf0e10cSrcweir STATE_TOPLABEL_DOT, STATE_IP4, STATE_IP4_DOT, STATE_IP6, 2375cdf0e10cSrcweir STATE_IP6_COLON, STATE_IP6_2COLON, STATE_IP6_3COLON, 2376cdf0e10cSrcweir STATE_IP6_HEXSEQ1, STATE_IP6_HEXSEQ1_COLON, 2377cdf0e10cSrcweir STATE_IP6_HEXSEQ1_MAYBE_IP4, STATE_IP6_HEXSEQ2, 2378cdf0e10cSrcweir STATE_IP6_HEXSEQ2_COLON, STATE_IP6_HEXSEQ2_MAYBE_IP4, 2379cdf0e10cSrcweir STATE_IP6_IP4, STATE_IP6_IP4_DOT, STATE_IP6_DONE }; 2380cdf0e10cSrcweir rtl::OUStringBuffer aTheCanonic; 2381cdf0e10cSrcweir sal_uInt32 nNumber = 0; 2382cdf0e10cSrcweir int nDigits = 0; 2383cdf0e10cSrcweir int nOctets = 0; 2384cdf0e10cSrcweir State eState = STATE_INITIAL; 2385cdf0e10cSrcweir sal_Unicode const * p = rBegin; 2386cdf0e10cSrcweir for (; p != pEnd; ++p) 2387cdf0e10cSrcweir switch (eState) 2388cdf0e10cSrcweir { 2389cdf0e10cSrcweir case STATE_INITIAL: 2390cdf0e10cSrcweir if (*p == '[') 2391cdf0e10cSrcweir { 2392cdf0e10cSrcweir aTheCanonic.append(sal_Unicode('[')); 2393cdf0e10cSrcweir eState = STATE_IP6; 2394cdf0e10cSrcweir } 2395cdf0e10cSrcweir else if (INetMIME::isAlpha(*p)) 2396cdf0e10cSrcweir eState = STATE_TOPLABEL; 2397cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2398cdf0e10cSrcweir { 2399cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2400cdf0e10cSrcweir nDigits = 1; 2401cdf0e10cSrcweir nOctets = 1; 2402cdf0e10cSrcweir eState = STATE_IP4; 2403cdf0e10cSrcweir } 2404cdf0e10cSrcweir else 2405cdf0e10cSrcweir goto done; 2406cdf0e10cSrcweir break; 2407cdf0e10cSrcweir 2408cdf0e10cSrcweir case STATE_LABEL: 2409cdf0e10cSrcweir if (*p == '.') 2410cdf0e10cSrcweir eState = STATE_LABEL_DOT; 2411cdf0e10cSrcweir else if (*p == '-') 2412cdf0e10cSrcweir eState = STATE_LABEL_HYPHEN; 2413cdf0e10cSrcweir else if (!INetMIME::isAlphanumeric(*p)) 2414cdf0e10cSrcweir goto done; 2415cdf0e10cSrcweir break; 2416cdf0e10cSrcweir 2417cdf0e10cSrcweir case STATE_LABEL_HYPHEN: 2418cdf0e10cSrcweir if (INetMIME::isAlphanumeric(*p)) 2419cdf0e10cSrcweir eState = STATE_LABEL; 2420cdf0e10cSrcweir else if (*p != '-') 2421cdf0e10cSrcweir goto done; 2422cdf0e10cSrcweir break; 2423cdf0e10cSrcweir 2424cdf0e10cSrcweir case STATE_LABEL_DOT: 2425cdf0e10cSrcweir if (INetMIME::isAlpha(*p)) 2426cdf0e10cSrcweir eState = STATE_TOPLABEL; 2427cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2428cdf0e10cSrcweir eState = STATE_LABEL; 2429cdf0e10cSrcweir else 2430cdf0e10cSrcweir goto done; 2431cdf0e10cSrcweir break; 2432cdf0e10cSrcweir 2433cdf0e10cSrcweir case STATE_TOPLABEL: 2434cdf0e10cSrcweir if (*p == '.') 2435cdf0e10cSrcweir eState = STATE_TOPLABEL_DOT; 2436cdf0e10cSrcweir else if (*p == '-') 2437cdf0e10cSrcweir eState = STATE_TOPLABEL_HYPHEN; 2438cdf0e10cSrcweir else if (!INetMIME::isAlphanumeric(*p)) 2439cdf0e10cSrcweir goto done; 2440cdf0e10cSrcweir break; 2441cdf0e10cSrcweir 2442cdf0e10cSrcweir case STATE_TOPLABEL_HYPHEN: 2443cdf0e10cSrcweir if (INetMIME::isAlphanumeric(*p)) 2444cdf0e10cSrcweir eState = STATE_TOPLABEL; 2445cdf0e10cSrcweir else if (*p != '-') 2446cdf0e10cSrcweir goto done; 2447cdf0e10cSrcweir break; 2448cdf0e10cSrcweir 2449cdf0e10cSrcweir case STATE_TOPLABEL_DOT: 2450cdf0e10cSrcweir if (INetMIME::isAlpha(*p)) 2451cdf0e10cSrcweir eState = STATE_TOPLABEL; 2452cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2453cdf0e10cSrcweir eState = STATE_LABEL; 2454cdf0e10cSrcweir else 2455cdf0e10cSrcweir goto done; 2456cdf0e10cSrcweir break; 2457cdf0e10cSrcweir 2458cdf0e10cSrcweir case STATE_IP4: 2459cdf0e10cSrcweir if (*p == '.') 2460cdf0e10cSrcweir if (nOctets < 4) 2461cdf0e10cSrcweir { 2462cdf0e10cSrcweir aTheCanonic.append( 2463cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2464cdf0e10cSrcweir aTheCanonic.append(sal_Unicode('.')); 2465cdf0e10cSrcweir ++nOctets; 2466cdf0e10cSrcweir eState = STATE_IP4_DOT; 2467cdf0e10cSrcweir } 2468cdf0e10cSrcweir else 2469cdf0e10cSrcweir eState = STATE_LABEL_DOT; 2470cdf0e10cSrcweir else if (*p == '-') 2471cdf0e10cSrcweir eState = STATE_LABEL_HYPHEN; 2472cdf0e10cSrcweir else if (INetMIME::isAlpha(*p)) 2473cdf0e10cSrcweir eState = STATE_LABEL; 2474cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2475cdf0e10cSrcweir if (nDigits < 3) 2476cdf0e10cSrcweir { 2477cdf0e10cSrcweir nNumber = 10 * nNumber + INetMIME::getWeight(*p); 2478cdf0e10cSrcweir ++nDigits; 2479cdf0e10cSrcweir } 2480cdf0e10cSrcweir else 2481cdf0e10cSrcweir eState = STATE_LABEL; 2482cdf0e10cSrcweir else 2483cdf0e10cSrcweir goto done; 2484cdf0e10cSrcweir break; 2485cdf0e10cSrcweir 2486cdf0e10cSrcweir case STATE_IP4_DOT: 2487cdf0e10cSrcweir if (INetMIME::isAlpha(*p)) 2488cdf0e10cSrcweir eState = STATE_TOPLABEL; 2489cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2490cdf0e10cSrcweir { 2491cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2492cdf0e10cSrcweir nDigits = 1; 2493cdf0e10cSrcweir eState = STATE_IP4; 2494cdf0e10cSrcweir } 2495cdf0e10cSrcweir else 2496cdf0e10cSrcweir goto done; 2497cdf0e10cSrcweir break; 2498cdf0e10cSrcweir 2499cdf0e10cSrcweir case STATE_IP6: 2500cdf0e10cSrcweir if (*p == ':') 2501cdf0e10cSrcweir eState = STATE_IP6_COLON; 2502cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p)) 2503cdf0e10cSrcweir { 2504cdf0e10cSrcweir nNumber = INetMIME::getHexWeight(*p); 2505cdf0e10cSrcweir nDigits = 1; 2506cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1; 2507cdf0e10cSrcweir } 2508cdf0e10cSrcweir else 2509cdf0e10cSrcweir goto done; 2510cdf0e10cSrcweir break; 2511cdf0e10cSrcweir 2512cdf0e10cSrcweir case STATE_IP6_COLON: 2513cdf0e10cSrcweir if (*p == ':') 2514cdf0e10cSrcweir { 2515cdf0e10cSrcweir aTheCanonic.appendAscii(RTL_CONSTASCII_STRINGPARAM("::")); 2516cdf0e10cSrcweir eState = STATE_IP6_2COLON; 2517cdf0e10cSrcweir } 2518cdf0e10cSrcweir else 2519cdf0e10cSrcweir goto done; 2520cdf0e10cSrcweir break; 2521cdf0e10cSrcweir 2522cdf0e10cSrcweir case STATE_IP6_2COLON: 2523cdf0e10cSrcweir if (*p == ']') 2524cdf0e10cSrcweir eState = STATE_IP6_DONE; 2525cdf0e10cSrcweir else if (*p == ':') 2526cdf0e10cSrcweir { 2527cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2528cdf0e10cSrcweir eState = STATE_IP6_3COLON; 2529cdf0e10cSrcweir } 2530cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2531cdf0e10cSrcweir { 2532cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2533cdf0e10cSrcweir nDigits = 1; 2534cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2_MAYBE_IP4; 2535cdf0e10cSrcweir } 2536cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p)) 2537cdf0e10cSrcweir { 2538cdf0e10cSrcweir nNumber = INetMIME::getHexWeight(*p); 2539cdf0e10cSrcweir nDigits = 1; 2540cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2; 2541cdf0e10cSrcweir } 2542cdf0e10cSrcweir else 2543cdf0e10cSrcweir goto done; 2544cdf0e10cSrcweir break; 2545cdf0e10cSrcweir 2546cdf0e10cSrcweir case STATE_IP6_3COLON: 2547cdf0e10cSrcweir if (INetMIME::isDigit(*p)) 2548cdf0e10cSrcweir { 2549cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2550cdf0e10cSrcweir nDigits = 1; 2551cdf0e10cSrcweir nOctets = 1; 2552cdf0e10cSrcweir eState = STATE_IP6_IP4; 2553cdf0e10cSrcweir } 2554cdf0e10cSrcweir else 2555cdf0e10cSrcweir goto done; 2556cdf0e10cSrcweir break; 2557cdf0e10cSrcweir 2558cdf0e10cSrcweir case STATE_IP6_HEXSEQ1: 2559cdf0e10cSrcweir if (*p == ']') 2560cdf0e10cSrcweir { 2561cdf0e10cSrcweir aTheCanonic.append( 2562cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2563cdf0e10cSrcweir eState = STATE_IP6_DONE; 2564cdf0e10cSrcweir } 2565cdf0e10cSrcweir else if (*p == ':') 2566cdf0e10cSrcweir { 2567cdf0e10cSrcweir aTheCanonic.append( 2568cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2569cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2570cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1_COLON; 2571cdf0e10cSrcweir } 2572cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p) && nDigits < 4) 2573cdf0e10cSrcweir { 2574cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getHexWeight(*p); 2575cdf0e10cSrcweir ++nDigits; 2576cdf0e10cSrcweir } 2577cdf0e10cSrcweir else 2578cdf0e10cSrcweir goto done; 2579cdf0e10cSrcweir break; 2580cdf0e10cSrcweir 2581cdf0e10cSrcweir case STATE_IP6_HEXSEQ1_COLON: 2582cdf0e10cSrcweir if (*p == ':') 2583cdf0e10cSrcweir { 2584cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2585cdf0e10cSrcweir eState = STATE_IP6_2COLON; 2586cdf0e10cSrcweir } 2587cdf0e10cSrcweir else if (INetMIME::isDigit(*p)) 2588cdf0e10cSrcweir { 2589cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2590cdf0e10cSrcweir nDigits = 1; 2591cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1_MAYBE_IP4; 2592cdf0e10cSrcweir } 2593cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p)) 2594cdf0e10cSrcweir { 2595cdf0e10cSrcweir nNumber = INetMIME::getHexWeight(*p); 2596cdf0e10cSrcweir nDigits = 1; 2597cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1; 2598cdf0e10cSrcweir } 2599cdf0e10cSrcweir else 2600cdf0e10cSrcweir goto done; 2601cdf0e10cSrcweir break; 2602cdf0e10cSrcweir 2603cdf0e10cSrcweir case STATE_IP6_HEXSEQ1_MAYBE_IP4: 2604cdf0e10cSrcweir if (*p == ']') 2605cdf0e10cSrcweir { 2606cdf0e10cSrcweir aTheCanonic.append( 2607cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2608cdf0e10cSrcweir eState = STATE_IP6_DONE; 2609cdf0e10cSrcweir } 2610cdf0e10cSrcweir else if (*p == ':') 2611cdf0e10cSrcweir { 2612cdf0e10cSrcweir aTheCanonic.append( 2613cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2614cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2615cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1_COLON; 2616cdf0e10cSrcweir } 2617cdf0e10cSrcweir else if (*p == '.') 2618cdf0e10cSrcweir { 2619cdf0e10cSrcweir nNumber = 100 * (nNumber >> 8) + 10 * (nNumber >> 4 & 15) 2620cdf0e10cSrcweir + (nNumber & 15); 2621cdf0e10cSrcweir aTheCanonic.append( 2622cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2623cdf0e10cSrcweir aTheCanonic.append(sal_Unicode('.')); 2624cdf0e10cSrcweir nOctets = 2; 2625cdf0e10cSrcweir eState = STATE_IP6_IP4_DOT; 2626cdf0e10cSrcweir } 2627cdf0e10cSrcweir else if (INetMIME::isDigit(*p) && nDigits < 3) 2628cdf0e10cSrcweir { 2629cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getWeight(*p); 2630cdf0e10cSrcweir ++nDigits; 2631cdf0e10cSrcweir } 2632cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p) && nDigits < 4) 2633cdf0e10cSrcweir { 2634cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getHexWeight(*p); 2635cdf0e10cSrcweir ++nDigits; 2636cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ1; 2637cdf0e10cSrcweir } 2638cdf0e10cSrcweir else 2639cdf0e10cSrcweir goto done; 2640cdf0e10cSrcweir break; 2641cdf0e10cSrcweir 2642cdf0e10cSrcweir case STATE_IP6_HEXSEQ2: 2643cdf0e10cSrcweir if (*p == ']') 2644cdf0e10cSrcweir { 2645cdf0e10cSrcweir aTheCanonic.append( 2646cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2647cdf0e10cSrcweir eState = STATE_IP6_DONE; 2648cdf0e10cSrcweir } 2649cdf0e10cSrcweir else if (*p == ':') 2650cdf0e10cSrcweir { 2651cdf0e10cSrcweir aTheCanonic.append( 2652cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2653cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2654cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2_COLON; 2655cdf0e10cSrcweir } 2656cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p) && nDigits < 4) 2657cdf0e10cSrcweir { 2658cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getHexWeight(*p); 2659cdf0e10cSrcweir ++nDigits; 2660cdf0e10cSrcweir } 2661cdf0e10cSrcweir else 2662cdf0e10cSrcweir goto done; 2663cdf0e10cSrcweir break; 2664cdf0e10cSrcweir 2665cdf0e10cSrcweir case STATE_IP6_HEXSEQ2_COLON: 2666cdf0e10cSrcweir if (INetMIME::isDigit(*p)) 2667cdf0e10cSrcweir { 2668cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2669cdf0e10cSrcweir nDigits = 1; 2670cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2_MAYBE_IP4; 2671cdf0e10cSrcweir } 2672cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p)) 2673cdf0e10cSrcweir { 2674cdf0e10cSrcweir nNumber = INetMIME::getHexWeight(*p); 2675cdf0e10cSrcweir nDigits = 1; 2676cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2; 2677cdf0e10cSrcweir } 2678cdf0e10cSrcweir else 2679cdf0e10cSrcweir goto done; 2680cdf0e10cSrcweir break; 2681cdf0e10cSrcweir 2682cdf0e10cSrcweir case STATE_IP6_HEXSEQ2_MAYBE_IP4: 2683cdf0e10cSrcweir if (*p == ']') 2684cdf0e10cSrcweir { 2685cdf0e10cSrcweir aTheCanonic.append( 2686cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2687cdf0e10cSrcweir eState = STATE_IP6_DONE; 2688cdf0e10cSrcweir } 2689cdf0e10cSrcweir else if (*p == ':') 2690cdf0e10cSrcweir { 2691cdf0e10cSrcweir aTheCanonic.append( 2692cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber), 16)); 2693cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(':')); 2694cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2_COLON; 2695cdf0e10cSrcweir } 2696cdf0e10cSrcweir else if (*p == '.') 2697cdf0e10cSrcweir { 2698cdf0e10cSrcweir nNumber = 100 * (nNumber >> 8) + 10 * (nNumber >> 4 & 15) 2699cdf0e10cSrcweir + (nNumber & 15); 2700cdf0e10cSrcweir aTheCanonic.append( 2701cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2702cdf0e10cSrcweir aTheCanonic.append(sal_Unicode('.')); 2703cdf0e10cSrcweir nOctets = 2; 2704cdf0e10cSrcweir eState = STATE_IP6_IP4_DOT; 2705cdf0e10cSrcweir } 2706cdf0e10cSrcweir else if (INetMIME::isDigit(*p) && nDigits < 3) 2707cdf0e10cSrcweir { 2708cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getWeight(*p); 2709cdf0e10cSrcweir ++nDigits; 2710cdf0e10cSrcweir } 2711cdf0e10cSrcweir else if (INetMIME::isHexDigit(*p) && nDigits < 4) 2712cdf0e10cSrcweir { 2713cdf0e10cSrcweir nNumber = 16 * nNumber + INetMIME::getHexWeight(*p); 2714cdf0e10cSrcweir ++nDigits; 2715cdf0e10cSrcweir eState = STATE_IP6_HEXSEQ2; 2716cdf0e10cSrcweir } 2717cdf0e10cSrcweir else 2718cdf0e10cSrcweir goto done; 2719cdf0e10cSrcweir break; 2720cdf0e10cSrcweir 2721cdf0e10cSrcweir case STATE_IP6_IP4: 2722cdf0e10cSrcweir if (*p == ']') 2723cdf0e10cSrcweir if (nOctets == 4) 2724cdf0e10cSrcweir { 2725cdf0e10cSrcweir aTheCanonic.append( 2726cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2727cdf0e10cSrcweir eState = STATE_IP6_DONE; 2728cdf0e10cSrcweir } 2729cdf0e10cSrcweir else 2730cdf0e10cSrcweir goto done; 2731cdf0e10cSrcweir else if (*p == '.') 2732cdf0e10cSrcweir if (nOctets < 4) 2733cdf0e10cSrcweir { 2734cdf0e10cSrcweir aTheCanonic.append( 2735cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2736cdf0e10cSrcweir aTheCanonic.append(sal_Unicode('.')); 2737cdf0e10cSrcweir ++nOctets; 2738cdf0e10cSrcweir eState = STATE_IP6_IP4_DOT; 2739cdf0e10cSrcweir } 2740cdf0e10cSrcweir else 2741cdf0e10cSrcweir goto done; 2742cdf0e10cSrcweir else if (INetMIME::isDigit(*p) && nDigits < 3) 2743cdf0e10cSrcweir { 2744cdf0e10cSrcweir nNumber = 10 * nNumber + INetMIME::getWeight(*p); 2745cdf0e10cSrcweir ++nDigits; 2746cdf0e10cSrcweir } 2747cdf0e10cSrcweir else 2748cdf0e10cSrcweir goto done; 2749cdf0e10cSrcweir break; 2750cdf0e10cSrcweir 2751cdf0e10cSrcweir case STATE_IP6_IP4_DOT: 2752cdf0e10cSrcweir if (INetMIME::isDigit(*p)) 2753cdf0e10cSrcweir { 2754cdf0e10cSrcweir nNumber = INetMIME::getWeight(*p); 2755cdf0e10cSrcweir nDigits = 1; 2756cdf0e10cSrcweir eState = STATE_IP6_IP4; 2757cdf0e10cSrcweir } 2758cdf0e10cSrcweir else 2759cdf0e10cSrcweir goto done; 2760cdf0e10cSrcweir break; 2761cdf0e10cSrcweir 2762cdf0e10cSrcweir case STATE_IP6_DONE: 2763cdf0e10cSrcweir goto done; 2764cdf0e10cSrcweir } 2765cdf0e10cSrcweir done: 2766cdf0e10cSrcweir switch (eState) 2767cdf0e10cSrcweir { 2768cdf0e10cSrcweir case STATE_LABEL: 2769cdf0e10cSrcweir case STATE_TOPLABEL: 2770cdf0e10cSrcweir case STATE_TOPLABEL_DOT: 2771cdf0e10cSrcweir aTheCanonic.setLength(0); 2772cdf0e10cSrcweir aTheCanonic.append(rBegin, p - rBegin); 2773cdf0e10cSrcweir rBegin = p; 2774cdf0e10cSrcweir rCanonic = aTheCanonic.makeStringAndClear(); 2775cdf0e10cSrcweir return true; 2776cdf0e10cSrcweir 2777cdf0e10cSrcweir case STATE_IP4: 2778cdf0e10cSrcweir if (nOctets == 4) 2779cdf0e10cSrcweir { 2780cdf0e10cSrcweir aTheCanonic.append( 2781cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int32(nNumber))); 2782cdf0e10cSrcweir rBegin = p; 2783cdf0e10cSrcweir rCanonic = aTheCanonic.makeStringAndClear(); 2784cdf0e10cSrcweir return true; 2785cdf0e10cSrcweir } 2786cdf0e10cSrcweir return false; 2787cdf0e10cSrcweir 2788cdf0e10cSrcweir case STATE_IP6_DONE: 2789cdf0e10cSrcweir aTheCanonic.append(sal_Unicode(']')); 2790cdf0e10cSrcweir rBegin = p; 2791cdf0e10cSrcweir rCanonic = aTheCanonic.makeStringAndClear(); 2792cdf0e10cSrcweir return true; 2793cdf0e10cSrcweir 2794cdf0e10cSrcweir default: 2795cdf0e10cSrcweir return false; 2796cdf0e10cSrcweir } 2797cdf0e10cSrcweir } 2798cdf0e10cSrcweir 2799cdf0e10cSrcweir //============================================================================ 2800cdf0e10cSrcweir // static 2801cdf0e10cSrcweir bool INetURLObject::parseHostOrNetBiosName( 2802cdf0e10cSrcweir sal_Unicode const * pBegin, sal_Unicode const * pEnd, bool bOctets, 2803cdf0e10cSrcweir EncodeMechanism eMechanism, rtl_TextEncoding eCharset, bool bNetBiosName, 2804cdf0e10cSrcweir rtl::OUStringBuffer* pCanonic) 2805cdf0e10cSrcweir { 2806cdf0e10cSrcweir rtl::OUString aTheCanonic; 2807cdf0e10cSrcweir if (pBegin < pEnd) 2808cdf0e10cSrcweir { 2809cdf0e10cSrcweir sal_Unicode const * p = pBegin; 2810cdf0e10cSrcweir if (!parseHost(p, pEnd, aTheCanonic) || p != pEnd) 2811cdf0e10cSrcweir { 2812cdf0e10cSrcweir if (bNetBiosName) 2813cdf0e10cSrcweir { 2814cdf0e10cSrcweir rtl::OUStringBuffer buf; 2815cdf0e10cSrcweir while (pBegin < pEnd) 2816cdf0e10cSrcweir { 2817cdf0e10cSrcweir EscapeType eEscapeType; 2818cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pBegin, pEnd, bOctets, '%', 2819cdf0e10cSrcweir eMechanism, eCharset, 2820cdf0e10cSrcweir eEscapeType); 2821cdf0e10cSrcweir if (!INetMIME::isVisible(nUTF32)) 2822cdf0e10cSrcweir return false; 2823cdf0e10cSrcweir if (!INetMIME::isAlphanumeric(nUTF32)) 2824cdf0e10cSrcweir switch (nUTF32) 2825cdf0e10cSrcweir { 2826cdf0e10cSrcweir case '"': 2827cdf0e10cSrcweir case '*': 2828cdf0e10cSrcweir case '+': 2829cdf0e10cSrcweir case ',': 2830cdf0e10cSrcweir case '/': 2831cdf0e10cSrcweir case ':': 2832cdf0e10cSrcweir case ';': 2833cdf0e10cSrcweir case '<': 2834cdf0e10cSrcweir case '=': 2835cdf0e10cSrcweir case '>': 2836cdf0e10cSrcweir case '?': 2837cdf0e10cSrcweir case '[': 2838cdf0e10cSrcweir case '\\': 2839cdf0e10cSrcweir case ']': 2840cdf0e10cSrcweir case '`': 2841cdf0e10cSrcweir case '|': 2842cdf0e10cSrcweir return false;; 2843cdf0e10cSrcweir } 2844cdf0e10cSrcweir if (pCanonic != NULL) { 2845cdf0e10cSrcweir appendUCS4( 2846cdf0e10cSrcweir buf, nUTF32, eEscapeType, bOctets, PART_URIC, '%', 2847cdf0e10cSrcweir eCharset, true); 2848cdf0e10cSrcweir } 2849cdf0e10cSrcweir } 2850cdf0e10cSrcweir aTheCanonic = buf.makeStringAndClear(); 2851cdf0e10cSrcweir } 2852cdf0e10cSrcweir else 2853cdf0e10cSrcweir return false; 2854cdf0e10cSrcweir } 2855cdf0e10cSrcweir } 2856cdf0e10cSrcweir if (pCanonic != NULL) { 2857cdf0e10cSrcweir *pCanonic = aTheCanonic; 2858cdf0e10cSrcweir } 2859cdf0e10cSrcweir return true; 2860cdf0e10cSrcweir } 2861cdf0e10cSrcweir 2862cdf0e10cSrcweir //============================================================================ 2863cdf0e10cSrcweir // static 2864cdf0e10cSrcweir rtl::OUString INetURLObject::encodeHostPort(rtl::OUString const & rTheHostPort, 2865cdf0e10cSrcweir bool bOctets, 2866cdf0e10cSrcweir EncodeMechanism eMechanism, 2867cdf0e10cSrcweir rtl_TextEncoding eCharset) 2868cdf0e10cSrcweir { 2869cdf0e10cSrcweir sal_Int32 nPort = rTheHostPort.getLength(); 2870cdf0e10cSrcweir if (nPort != 0) 2871cdf0e10cSrcweir { 2872cdf0e10cSrcweir sal_Int32 i = nPort - 1; 2873cdf0e10cSrcweir while (i != 0 && INetMIME::isDigit(rTheHostPort.getStr()[i])) 2874cdf0e10cSrcweir --i; 2875cdf0e10cSrcweir if (rTheHostPort.getStr()[i] == ':') 2876cdf0e10cSrcweir nPort = i; 2877cdf0e10cSrcweir } 2878cdf0e10cSrcweir rtl::OUString aResult(encodeText(rTheHostPort.copy(0, nPort), bOctets, 2879cdf0e10cSrcweir PART_HOST_EXTRA, '%', eMechanism, eCharset, 2880cdf0e10cSrcweir true)); 2881cdf0e10cSrcweir aResult += rTheHostPort.copy(nPort); 2882cdf0e10cSrcweir return aResult; 2883cdf0e10cSrcweir } 2884cdf0e10cSrcweir 2885cdf0e10cSrcweir //============================================================================ 2886cdf0e10cSrcweir bool INetURLObject::setHost(rtl::OUString const & rTheHost, bool bOctets, 2887cdf0e10cSrcweir EncodeMechanism eMechanism, 2888cdf0e10cSrcweir rtl_TextEncoding eCharset) 2889cdf0e10cSrcweir { 2890cdf0e10cSrcweir if (!getSchemeInfo().m_bHost) 2891cdf0e10cSrcweir return false; 2892cdf0e10cSrcweir rtl::OUStringBuffer aSynHost(rTheHost); 2893cdf0e10cSrcweir bool bNetBiosName = false; 2894cdf0e10cSrcweir switch (m_eScheme) 2895cdf0e10cSrcweir { 2896cdf0e10cSrcweir case INET_PROT_FILE: 2897cdf0e10cSrcweir { 2898cdf0e10cSrcweir rtl::OUString sTemp(aSynHost); 2899cdf0e10cSrcweir if (sTemp.equalsIgnoreAsciiCaseAsciiL( 2900cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("localhost"))) 2901cdf0e10cSrcweir { 2902cdf0e10cSrcweir aSynHost.setLength(0); 2903cdf0e10cSrcweir } 2904cdf0e10cSrcweir bNetBiosName = true; 2905cdf0e10cSrcweir } 2906cdf0e10cSrcweir break; 2907cdf0e10cSrcweir case INET_PROT_LDAP: 2908cdf0e10cSrcweir if (aSynHost.getLength() == 0 && m_aPort.isPresent()) 2909cdf0e10cSrcweir return false; 2910cdf0e10cSrcweir break; 2911cdf0e10cSrcweir 2912cdf0e10cSrcweir default: 2913cdf0e10cSrcweir if (aSynHost.getLength() == 0) 2914cdf0e10cSrcweir return false; 2915cdf0e10cSrcweir break; 2916cdf0e10cSrcweir } 2917cdf0e10cSrcweir if (!parseHostOrNetBiosName( 2918cdf0e10cSrcweir aSynHost.getStr(), aSynHost.getStr() + aSynHost.getLength(), 2919cdf0e10cSrcweir bOctets, eMechanism, eCharset, bNetBiosName, &aSynHost)) 2920cdf0e10cSrcweir return false; 2921cdf0e10cSrcweir sal_Int32 nDelta = m_aHost.set(m_aAbsURIRef, aSynHost.makeStringAndClear()); 2922cdf0e10cSrcweir m_aPort += nDelta; 2923cdf0e10cSrcweir m_aPath += nDelta; 2924cdf0e10cSrcweir m_aQuery += nDelta; 2925cdf0e10cSrcweir m_aFragment += nDelta; 2926cdf0e10cSrcweir return true; 2927cdf0e10cSrcweir } 2928cdf0e10cSrcweir 2929cdf0e10cSrcweir //============================================================================ 2930cdf0e10cSrcweir // static 2931cdf0e10cSrcweir bool INetURLObject::parsePath(INetProtocol eScheme, 2932cdf0e10cSrcweir sal_Unicode const ** pBegin, 2933cdf0e10cSrcweir sal_Unicode const * pEnd, 2934cdf0e10cSrcweir bool bOctets, 2935cdf0e10cSrcweir EncodeMechanism eMechanism, 2936cdf0e10cSrcweir rtl_TextEncoding eCharset, 2937cdf0e10cSrcweir bool bSkippedInitialSlash, 2938cdf0e10cSrcweir sal_uInt32 nSegmentDelimiter, 2939cdf0e10cSrcweir sal_uInt32 nAltSegmentDelimiter, 2940cdf0e10cSrcweir sal_uInt32 nQueryDelimiter, 2941cdf0e10cSrcweir sal_uInt32 nFragmentDelimiter, 2942cdf0e10cSrcweir rtl::OUStringBuffer &rSynPath) 2943cdf0e10cSrcweir { 2944cdf0e10cSrcweir DBG_ASSERT(pBegin, "INetURLObject::parsePath(): Null output param"); 2945cdf0e10cSrcweir 2946cdf0e10cSrcweir sal_Unicode const * pPos = *pBegin; 2947cdf0e10cSrcweir rtl::OUStringBuffer aTheSynPath; 2948cdf0e10cSrcweir 2949cdf0e10cSrcweir switch (eScheme) 2950cdf0e10cSrcweir { 2951cdf0e10cSrcweir case INET_PROT_NOT_VALID: 2952cdf0e10cSrcweir return false; 2953cdf0e10cSrcweir 2954cdf0e10cSrcweir case INET_PROT_FTP: 2955cdf0e10cSrcweir case INET_PROT_IMAP: 2956cdf0e10cSrcweir if (pPos < pEnd && *pPos != '/') 2957cdf0e10cSrcweir return false; 2958cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 2959cdf0e10cSrcweir { 2960cdf0e10cSrcweir EscapeType eEscapeType; 2961cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 2962cdf0e10cSrcweir '%', eMechanism, 2963cdf0e10cSrcweir eCharset, eEscapeType); 2964cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 2965cdf0e10cSrcweir PART_HTTP_PATH, '%', eCharset, true); 2966cdf0e10cSrcweir } 2967cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 2968cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 2969cdf0e10cSrcweir break; 2970cdf0e10cSrcweir 2971cdf0e10cSrcweir case INET_PROT_HTTP: 2972cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_WEBDAV: 2973cdf0e10cSrcweir case INET_PROT_HTTPS: 2974cdf0e10cSrcweir case INET_PROT_SMB: 2975cdf0e10cSrcweir if (pPos < pEnd && *pPos != '/') 2976cdf0e10cSrcweir return false; 2977cdf0e10cSrcweir while (pPos < pEnd && *pPos != nQueryDelimiter 2978cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 2979cdf0e10cSrcweir { 2980cdf0e10cSrcweir EscapeType eEscapeType; 2981cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 2982cdf0e10cSrcweir '%', eMechanism, 2983cdf0e10cSrcweir eCharset, eEscapeType); 2984cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 2985cdf0e10cSrcweir PART_HTTP_PATH, '%', eCharset, true); 2986cdf0e10cSrcweir } 2987cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 2988cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 2989cdf0e10cSrcweir break; 2990cdf0e10cSrcweir 2991cdf0e10cSrcweir case INET_PROT_FILE: 2992cdf0e10cSrcweir { 2993cdf0e10cSrcweir if (bSkippedInitialSlash) 2994cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 2995cdf0e10cSrcweir else if (pPos < pEnd 2996cdf0e10cSrcweir && *pPos != nSegmentDelimiter 2997cdf0e10cSrcweir && *pPos != nAltSegmentDelimiter) 2998cdf0e10cSrcweir return false; 2999cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3000cdf0e10cSrcweir { 3001cdf0e10cSrcweir EscapeType eEscapeType; 3002cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3003cdf0e10cSrcweir '%', eMechanism, 3004cdf0e10cSrcweir eCharset, eEscapeType); 3005cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO) 3006cdf0e10cSrcweir { 3007cdf0e10cSrcweir if (nUTF32 == nSegmentDelimiter 3008cdf0e10cSrcweir || nUTF32 == nAltSegmentDelimiter) 3009cdf0e10cSrcweir { 3010cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3011cdf0e10cSrcweir continue; 3012cdf0e10cSrcweir } 3013cdf0e10cSrcweir else if (nUTF32 == '|' 3014cdf0e10cSrcweir && (pPos == pEnd 3015cdf0e10cSrcweir || *pPos == nFragmentDelimiter 3016cdf0e10cSrcweir || *pPos == nSegmentDelimiter 3017cdf0e10cSrcweir || *pPos == nAltSegmentDelimiter) 3018cdf0e10cSrcweir && aTheSynPath.getLength() == 2 3019cdf0e10cSrcweir && INetMIME::isAlpha(aTheSynPath.charAt(1))) 3020cdf0e10cSrcweir { 3021cdf0e10cSrcweir // A first segment of <ALPHA "|"> is translated to 3022cdf0e10cSrcweir // <ALPHA ":">: 3023cdf0e10cSrcweir aTheSynPath.append(sal_Unicode(':')); 3024cdf0e10cSrcweir continue; 3025cdf0e10cSrcweir } 3026cdf0e10cSrcweir } 3027cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3028cdf0e10cSrcweir PART_PCHAR, '%', eCharset, true); 3029cdf0e10cSrcweir } 3030cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 3031cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3032cdf0e10cSrcweir break; 3033cdf0e10cSrcweir } 3034cdf0e10cSrcweir 3035cdf0e10cSrcweir case INET_PROT_MAILTO: 3036cdf0e10cSrcweir while (pPos < pEnd && *pPos != nQueryDelimiter 3037cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 3038cdf0e10cSrcweir { 3039cdf0e10cSrcweir EscapeType eEscapeType; 3040cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3041cdf0e10cSrcweir '%', eMechanism, 3042cdf0e10cSrcweir eCharset, eEscapeType); 3043cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3044cdf0e10cSrcweir PART_MAILTO, '%', eCharset, true); 3045cdf0e10cSrcweir } 3046cdf0e10cSrcweir break; 3047cdf0e10cSrcweir 3048cdf0e10cSrcweir case INET_PROT_NEWS: 3049cdf0e10cSrcweir if (pPos == pEnd || *pPos == nQueryDelimiter 3050cdf0e10cSrcweir || *pPos == nFragmentDelimiter) 3051cdf0e10cSrcweir return false; 3052cdf0e10cSrcweir 3053cdf0e10cSrcweir // Match <"*">: 3054cdf0e10cSrcweir if (*pPos == '*' 3055cdf0e10cSrcweir && (pEnd - pPos == 1 || pPos[1] == nQueryDelimiter 3056cdf0e10cSrcweir || pPos[1] == nFragmentDelimiter)) 3057cdf0e10cSrcweir { 3058cdf0e10cSrcweir ++pPos; 3059cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('*')); 3060cdf0e10cSrcweir break; 3061cdf0e10cSrcweir } 3062cdf0e10cSrcweir 3063cdf0e10cSrcweir // Match <group>: 3064cdf0e10cSrcweir if (INetMIME::isAlpha(*pPos)) 3065cdf0e10cSrcweir for (sal_Unicode const * p = pPos + 1;; ++p) 3066cdf0e10cSrcweir if (p == pEnd || *p == nQueryDelimiter 3067cdf0e10cSrcweir || *p == nFragmentDelimiter) 3068cdf0e10cSrcweir { 3069cdf0e10cSrcweir aTheSynPath.setLength(0); 3070cdf0e10cSrcweir aTheSynPath.append(pPos, p - pPos); 3071cdf0e10cSrcweir pPos = p; 3072cdf0e10cSrcweir goto done; 3073cdf0e10cSrcweir } 3074cdf0e10cSrcweir else if (!INetMIME::isAlphanumeric(*p) && *p != '+' 3075cdf0e10cSrcweir && *p != '-' && *p != '.' && *p != '_') 3076cdf0e10cSrcweir break; 3077cdf0e10cSrcweir 3078cdf0e10cSrcweir // Match <article>: 3079cdf0e10cSrcweir for (;;) 3080cdf0e10cSrcweir { 3081cdf0e10cSrcweir if (pPos == pEnd || *pPos == nQueryDelimiter 3082cdf0e10cSrcweir || *pPos == nFragmentDelimiter) 3083cdf0e10cSrcweir return false; 3084cdf0e10cSrcweir if (*pPos == '@') 3085cdf0e10cSrcweir break; 3086cdf0e10cSrcweir EscapeType eEscapeType; 3087cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, '%', 3088cdf0e10cSrcweir eMechanism, eCharset, eEscapeType); 3089cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3090cdf0e10cSrcweir PART_NEWS_ARTICLE_LOCALPART, '%', eCharset, true); 3091cdf0e10cSrcweir } 3092cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 3093cdf0e10cSrcweir return false; 3094cdf0e10cSrcweir ++pPos; 3095cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('@')); 3096cdf0e10cSrcweir { 3097cdf0e10cSrcweir sal_Unicode const * p = pPos; 3098cdf0e10cSrcweir while (p < pEnd && *pPos != nQueryDelimiter 3099cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 3100cdf0e10cSrcweir ++p; 3101cdf0e10cSrcweir rtl::OUString aCanonic; 3102cdf0e10cSrcweir if (!parseHost(pPos, p, aCanonic)) 3103cdf0e10cSrcweir return false; 3104cdf0e10cSrcweir aTheSynPath.append(aCanonic); 3105cdf0e10cSrcweir } 3106cdf0e10cSrcweir 3107cdf0e10cSrcweir done: 3108cdf0e10cSrcweir break; 3109cdf0e10cSrcweir 3110cdf0e10cSrcweir case INET_PROT_POP3: 3111cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3112cdf0e10cSrcweir { 3113cdf0e10cSrcweir EscapeType eEscapeType; 3114cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3115cdf0e10cSrcweir '%', eMechanism, 3116cdf0e10cSrcweir eCharset, eEscapeType); 3117cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3118cdf0e10cSrcweir PART_MESSAGE_ID_PATH, '%', eCharset, 3119cdf0e10cSrcweir true); 3120cdf0e10cSrcweir } 3121cdf0e10cSrcweir break; 3122cdf0e10cSrcweir 3123cdf0e10cSrcweir case INET_PROT_PRIV_SOFFICE: 3124cdf0e10cSrcweir case INET_PROT_SLOT: 3125cdf0e10cSrcweir case INET_PROT_HID: 3126cdf0e10cSrcweir case INET_PROT_MACRO: 3127cdf0e10cSrcweir case INET_PROT_UNO: 3128cdf0e10cSrcweir case INET_PROT_COMPONENT: 3129cdf0e10cSrcweir case INET_PROT_LDAP: 3130cdf0e10cSrcweir while (pPos < pEnd && *pPos != nQueryDelimiter 3131cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 3132cdf0e10cSrcweir { 3133cdf0e10cSrcweir EscapeType eEscapeType; 3134cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3135cdf0e10cSrcweir '%', eMechanism, 3136cdf0e10cSrcweir eCharset, eEscapeType); 3137cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3138cdf0e10cSrcweir PART_PATH_BEFORE_QUERY, '%', eCharset, 3139cdf0e10cSrcweir true); 3140cdf0e10cSrcweir } 3141cdf0e10cSrcweir break; 3142cdf0e10cSrcweir 3143cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_HELP: 3144cdf0e10cSrcweir if (pPos == pEnd 3145cdf0e10cSrcweir || *pPos == nQueryDelimiter 3146cdf0e10cSrcweir || *pPos == nFragmentDelimiter) 3147cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3148cdf0e10cSrcweir else 3149cdf0e10cSrcweir { 3150cdf0e10cSrcweir if (*pPos != '/') 3151cdf0e10cSrcweir return false; 3152cdf0e10cSrcweir while (pPos < pEnd && *pPos != nQueryDelimiter 3153cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 3154cdf0e10cSrcweir { 3155cdf0e10cSrcweir EscapeType eEscapeType; 3156cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3157cdf0e10cSrcweir '%', eMechanism, 3158cdf0e10cSrcweir eCharset, eEscapeType); 3159cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3160cdf0e10cSrcweir PART_HTTP_PATH, '%', eCharset, true); 3161cdf0e10cSrcweir } 3162cdf0e10cSrcweir } 3163cdf0e10cSrcweir break; 3164cdf0e10cSrcweir 3165cdf0e10cSrcweir case INET_PROT_JAVASCRIPT: 3166cdf0e10cSrcweir case INET_PROT_DATA: 3167cdf0e10cSrcweir case INET_PROT_CID: 3168cdf0e10cSrcweir case INET_PROT_DB: 3169cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3170cdf0e10cSrcweir { 3171cdf0e10cSrcweir EscapeType eEscapeType; 3172cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3173cdf0e10cSrcweir '%', eMechanism, 3174cdf0e10cSrcweir eCharset, eEscapeType); 3175cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3176cdf0e10cSrcweir PART_URIC, '%', eCharset, true); 3177cdf0e10cSrcweir } 3178cdf0e10cSrcweir break; 3179cdf0e10cSrcweir 3180cdf0e10cSrcweir case INET_PROT_OUT: 3181cdf0e10cSrcweir if (pEnd - pPos < 2 || *pPos++ != '/' || *pPos++ != '~') 3182cdf0e10cSrcweir return false; 3183cdf0e10cSrcweir aTheSynPath.appendAscii(RTL_CONSTASCII_STRINGPARAM("/~")); 3184cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3185cdf0e10cSrcweir { 3186cdf0e10cSrcweir EscapeType eEscapeType; 3187cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3188cdf0e10cSrcweir '%', eMechanism, 3189cdf0e10cSrcweir eCharset, eEscapeType); 3190cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3191cdf0e10cSrcweir PART_URIC, '%', eCharset, true); 3192cdf0e10cSrcweir } 3193cdf0e10cSrcweir break; 3194cdf0e10cSrcweir 3195cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_HIER: 3196cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_PKG: 3197cdf0e10cSrcweir if (pPos < pEnd && *pPos != '/' 3198cdf0e10cSrcweir && *pPos != nQueryDelimiter && *pPos != nFragmentDelimiter) 3199cdf0e10cSrcweir return false; 3200cdf0e10cSrcweir while (pPos < pEnd && *pPos != nQueryDelimiter 3201cdf0e10cSrcweir && *pPos != nFragmentDelimiter) 3202cdf0e10cSrcweir { 3203cdf0e10cSrcweir EscapeType eEscapeType; 3204cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3205cdf0e10cSrcweir '%', eMechanism, 3206cdf0e10cSrcweir eCharset, eEscapeType); 3207cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO && nUTF32 == '/') 3208cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3209cdf0e10cSrcweir else 3210cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3211cdf0e10cSrcweir PART_PCHAR, '%', eCharset, false); 3212cdf0e10cSrcweir } 3213cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 3214cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3215cdf0e10cSrcweir break; 3216cdf0e10cSrcweir 3217cdf0e10cSrcweir case INET_PROT_VIM: 3218cdf0e10cSrcweir { 3219cdf0e10cSrcweir /* test had to be taken out to make parsePath static; ok since INET_PROT_VIM is 3220cdf0e10cSrcweir obsolete, anyway 3221cdf0e10cSrcweir if (m_aUser.isEmpty()) 3222cdf0e10cSrcweir return false; 3223cdf0e10cSrcweir */ 3224cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPos; 3225cdf0e10cSrcweir while (pPathEnd < pEnd && *pPathEnd != nFragmentDelimiter) 3226cdf0e10cSrcweir ++pPathEnd; 3227cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3228cdf0e10cSrcweir if (pPos == pPathEnd) 3229cdf0e10cSrcweir break; 3230cdf0e10cSrcweir else if (*pPos++ != '/') 3231cdf0e10cSrcweir return false; 3232cdf0e10cSrcweir if (pPos == pPathEnd) 3233cdf0e10cSrcweir break; 3234cdf0e10cSrcweir while (pPos < pPathEnd && *pPos != '/') 3235cdf0e10cSrcweir { 3236cdf0e10cSrcweir EscapeType eEscapeType; 3237cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, 3238cdf0e10cSrcweir '=', eMechanism, 3239cdf0e10cSrcweir eCharset, eEscapeType); 3240cdf0e10cSrcweir appendUCS4(aTheSynPath, 3241cdf0e10cSrcweir eEscapeType == ESCAPE_NO ? 3242cdf0e10cSrcweir INetMIME::toLowerCase(nUTF32) : nUTF32, 3243cdf0e10cSrcweir eEscapeType, bOctets, PART_VIM, '=', 3244cdf0e10cSrcweir eCharset, false); 3245cdf0e10cSrcweir } 3246cdf0e10cSrcweir bool bInbox; 3247cdf0e10cSrcweir rtl::OUString sCompare(aTheSynPath); 3248cdf0e10cSrcweir if (sCompare.equalsAscii("/inbox")) 3249cdf0e10cSrcweir bInbox = true; 3250cdf0e10cSrcweir else if (sCompare.equalsAscii("/newsgroups")) 3251cdf0e10cSrcweir bInbox = false; 3252cdf0e10cSrcweir else 3253cdf0e10cSrcweir return false; 3254cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3255cdf0e10cSrcweir if (pPos == pPathEnd) 3256cdf0e10cSrcweir break; 3257cdf0e10cSrcweir else if (*pPos++ != '/') 3258cdf0e10cSrcweir return false; 3259cdf0e10cSrcweir if (!bInbox) 3260cdf0e10cSrcweir { 3261cdf0e10cSrcweir bool bEmpty = true; 3262cdf0e10cSrcweir while (pPos < pPathEnd && *pPos != '/') 3263cdf0e10cSrcweir { 3264cdf0e10cSrcweir EscapeType eEscapeType; 3265cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, 3266cdf0e10cSrcweir '=', eMechanism, 3267cdf0e10cSrcweir eCharset, eEscapeType); 3268cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3269cdf0e10cSrcweir PART_VIM, '=', eCharset, false); 3270cdf0e10cSrcweir bEmpty = false; 3271cdf0e10cSrcweir } 3272cdf0e10cSrcweir if (bEmpty) 3273cdf0e10cSrcweir return false; 3274cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3275cdf0e10cSrcweir if (pPos == pPathEnd) 3276cdf0e10cSrcweir break; 3277cdf0e10cSrcweir else if (*pPos++ != '/') 3278cdf0e10cSrcweir return false; 3279cdf0e10cSrcweir } 3280cdf0e10cSrcweir bool bEmpty = true; 3281cdf0e10cSrcweir while (pPos < pPathEnd && *pPos != ':') 3282cdf0e10cSrcweir { 3283cdf0e10cSrcweir EscapeType eEscapeType; 3284cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, 3285cdf0e10cSrcweir '=', eMechanism, 3286cdf0e10cSrcweir eCharset, eEscapeType); 3287cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3288cdf0e10cSrcweir PART_VIM, '=', eCharset, false); 3289cdf0e10cSrcweir bEmpty = false; 3290cdf0e10cSrcweir } 3291cdf0e10cSrcweir if (bEmpty) 3292cdf0e10cSrcweir return false; 3293cdf0e10cSrcweir if (pPos == pPathEnd) 3294cdf0e10cSrcweir break; 3295cdf0e10cSrcweir else if (*pPos++ != ':') 3296cdf0e10cSrcweir return false; 3297cdf0e10cSrcweir aTheSynPath.append(sal_Unicode(':')); 3298cdf0e10cSrcweir for (int i = 0; i < 3; ++i) 3299cdf0e10cSrcweir { 3300cdf0e10cSrcweir if (i != 0) 3301cdf0e10cSrcweir { 3302cdf0e10cSrcweir if (pPos == pPathEnd || *pPos++ != '.') 3303cdf0e10cSrcweir return false; 3304cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('.')); 3305cdf0e10cSrcweir } 3306cdf0e10cSrcweir bEmpty = true; 3307cdf0e10cSrcweir while (pPos < pPathEnd && *pPos != '.') 3308cdf0e10cSrcweir { 3309cdf0e10cSrcweir EscapeType eEscapeType; 3310cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pPathEnd, bOctets, 3311cdf0e10cSrcweir '=', eMechanism, 3312cdf0e10cSrcweir eCharset, eEscapeType); 3313cdf0e10cSrcweir if (!INetMIME::isDigit(nUTF32)) 3314cdf0e10cSrcweir return false; 3315cdf0e10cSrcweir aTheSynPath.append(sal_Unicode(nUTF32)); 3316cdf0e10cSrcweir bEmpty = false; 3317cdf0e10cSrcweir } 3318cdf0e10cSrcweir if (bEmpty) 3319cdf0e10cSrcweir return false; 3320cdf0e10cSrcweir } 3321cdf0e10cSrcweir if (pPos != pPathEnd) 3322cdf0e10cSrcweir return false; 3323cdf0e10cSrcweir break; 3324cdf0e10cSrcweir } 3325cdf0e10cSrcweir 3326cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_CMD: 3327cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_EXPAND: 3328cdf0e10cSrcweir { 3329cdf0e10cSrcweir if (pPos == pEnd || *pPos == nFragmentDelimiter) 3330cdf0e10cSrcweir return false; 3331cdf0e10cSrcweir Part ePart = PART_URIC_NO_SLASH; 3332cdf0e10cSrcweir while (pPos != pEnd && *pPos != nFragmentDelimiter) 3333cdf0e10cSrcweir { 3334cdf0e10cSrcweir EscapeType eEscapeType; 3335cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3336cdf0e10cSrcweir '%', eMechanism, 3337cdf0e10cSrcweir eCharset, eEscapeType); 3338cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, ePart, 3339cdf0e10cSrcweir '%', eCharset, true); 3340cdf0e10cSrcweir ePart = PART_URIC; 3341cdf0e10cSrcweir } 3342cdf0e10cSrcweir break; 3343cdf0e10cSrcweir } 3344cdf0e10cSrcweir 3345cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_ODMA: 3346cdf0e10cSrcweir if (pPos < pEnd) 3347cdf0e10cSrcweir { 3348cdf0e10cSrcweir if (*pPos == '/') 3349cdf0e10cSrcweir ++pPos; 3350cdf0e10cSrcweir else 3351cdf0e10cSrcweir return false; 3352cdf0e10cSrcweir } 3353cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3354cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3355cdf0e10cSrcweir { 3356cdf0e10cSrcweir EscapeType eEscapeType; 3357cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3358cdf0e10cSrcweir '%', eMechanism, 3359cdf0e10cSrcweir eCharset, eEscapeType); 3360cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3361cdf0e10cSrcweir PART_URIC_NO_SLASH, '%', eCharset, true); 3362cdf0e10cSrcweir } 3363cdf0e10cSrcweir break; 3364cdf0e10cSrcweir 3365cdf0e10cSrcweir case INET_PROT_TELNET: 3366cdf0e10cSrcweir if (pPos < pEnd) 3367cdf0e10cSrcweir { 3368cdf0e10cSrcweir if (*pPos != '/' || pEnd - pPos > 1) 3369cdf0e10cSrcweir return false; 3370cdf0e10cSrcweir ++pPos; 3371cdf0e10cSrcweir } 3372cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3373cdf0e10cSrcweir break; 3374cdf0e10cSrcweir 3375cdf0e10cSrcweir case INET_PROT_VND_SUN_STAR_TDOC: 3376cdf0e10cSrcweir if (pPos == pEnd || *pPos != '/') 3377cdf0e10cSrcweir return false; 3378cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3379cdf0e10cSrcweir { 3380cdf0e10cSrcweir EscapeType eEscapeType; 3381cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3382cdf0e10cSrcweir '%', eMechanism, 3383cdf0e10cSrcweir eCharset, eEscapeType); 3384cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO && nUTF32 == '/') 3385cdf0e10cSrcweir aTheSynPath.append(sal_Unicode('/')); 3386cdf0e10cSrcweir else 3387cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3388cdf0e10cSrcweir PART_PCHAR, '%', eCharset, false); 3389cdf0e10cSrcweir } 3390cdf0e10cSrcweir break; 3391cdf0e10cSrcweir 3392cdf0e10cSrcweir case INET_PROT_GENERIC: 3393cdf0e10cSrcweir while (pPos < pEnd && *pPos != nFragmentDelimiter) 3394cdf0e10cSrcweir { 3395cdf0e10cSrcweir EscapeType eEscapeType; 3396cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pPos, pEnd, bOctets, 3397cdf0e10cSrcweir '%', eMechanism, 3398cdf0e10cSrcweir eCharset, eEscapeType); 3399cdf0e10cSrcweir appendUCS4(aTheSynPath, nUTF32, eEscapeType, bOctets, 3400cdf0e10cSrcweir PART_URIC, '%', eCharset, true); 3401cdf0e10cSrcweir } 3402cdf0e10cSrcweir if (aTheSynPath.getLength() == 0) 3403cdf0e10cSrcweir return false; 3404cdf0e10cSrcweir break; 3405cdf0e10cSrcweir default: 3406cdf0e10cSrcweir OSL_ASSERT(false); 3407cdf0e10cSrcweir break; 3408cdf0e10cSrcweir } 3409cdf0e10cSrcweir 3410cdf0e10cSrcweir *pBegin = pPos; 3411cdf0e10cSrcweir rSynPath = aTheSynPath; 3412cdf0e10cSrcweir return true; 3413cdf0e10cSrcweir } 3414cdf0e10cSrcweir 3415cdf0e10cSrcweir //============================================================================ 3416cdf0e10cSrcweir bool INetURLObject::setPath(rtl::OUString const & rThePath, bool bOctets, 3417cdf0e10cSrcweir EncodeMechanism eMechanism, 3418cdf0e10cSrcweir rtl_TextEncoding eCharset) 3419cdf0e10cSrcweir { 3420cdf0e10cSrcweir rtl::OUStringBuffer aSynPath; 3421cdf0e10cSrcweir sal_Unicode const * p = rThePath.getStr(); 3422cdf0e10cSrcweir sal_Unicode const * pEnd = p + rThePath.getLength(); 3423cdf0e10cSrcweir if (!parsePath(m_eScheme, &p, pEnd, bOctets, eMechanism, eCharset, false, 3424cdf0e10cSrcweir '/', 0x80000000, 0x80000000, 0x80000000, aSynPath) 3425cdf0e10cSrcweir || p != pEnd) 3426cdf0e10cSrcweir return false; 3427cdf0e10cSrcweir sal_Int32 nDelta = m_aPath.set(m_aAbsURIRef, aSynPath.makeStringAndClear()); 3428cdf0e10cSrcweir m_aQuery += nDelta; 3429cdf0e10cSrcweir m_aFragment += nDelta; 3430cdf0e10cSrcweir return true; 3431cdf0e10cSrcweir } 3432cdf0e10cSrcweir 3433cdf0e10cSrcweir //============================================================================ 3434cdf0e10cSrcweir bool INetURLObject::checkHierarchical() const { 3435cdf0e10cSrcweir if (m_eScheme == INET_PROT_VND_SUN_STAR_EXPAND) { 3436cdf0e10cSrcweir OSL_ENSURE( 3437cdf0e10cSrcweir false, "INetURLObject::checkHierarchical vnd.sun.star.expand"); 3438cdf0e10cSrcweir return true; 3439cdf0e10cSrcweir } else { 3440cdf0e10cSrcweir return getSchemeInfo().m_bHierarchical; 3441cdf0e10cSrcweir } 3442cdf0e10cSrcweir } 3443cdf0e10cSrcweir 3444cdf0e10cSrcweir //============================================================================ 3445cdf0e10cSrcweir bool INetURLObject::appendSegment(rtl::OUString const & rTheSegment, 3446cdf0e10cSrcweir bool bOctets, EncodeMechanism eMechanism, 3447cdf0e10cSrcweir rtl_TextEncoding eCharset) 3448cdf0e10cSrcweir { 3449cdf0e10cSrcweir return insertName(rTheSegment, bOctets, false, LAST_SEGMENT, true, 3450cdf0e10cSrcweir eMechanism, eCharset); 3451cdf0e10cSrcweir } 3452cdf0e10cSrcweir 3453cdf0e10cSrcweir //============================================================================ 3454cdf0e10cSrcweir INetURLObject::SubString INetURLObject::getSegment(sal_Int32 nIndex, 3455cdf0e10cSrcweir bool bIgnoreFinalSlash) 3456cdf0e10cSrcweir const 3457cdf0e10cSrcweir { 3458cdf0e10cSrcweir DBG_ASSERT(nIndex >= 0 || nIndex == LAST_SEGMENT, 3459cdf0e10cSrcweir "INetURLObject::getSegment(): Bad index"); 3460cdf0e10cSrcweir 3461cdf0e10cSrcweir if (!checkHierarchical()) 3462cdf0e10cSrcweir return SubString(); 3463cdf0e10cSrcweir 3464cdf0e10cSrcweir sal_Unicode const * pPathBegin 3465cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 3466cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 3467cdf0e10cSrcweir sal_Unicode const * pSegBegin; 3468cdf0e10cSrcweir sal_Unicode const * pSegEnd; 3469cdf0e10cSrcweir if (nIndex == LAST_SEGMENT) 3470cdf0e10cSrcweir { 3471cdf0e10cSrcweir pSegEnd = pPathEnd; 3472cdf0e10cSrcweir if (bIgnoreFinalSlash && pSegEnd > pPathBegin && pSegEnd[-1] == '/') 3473cdf0e10cSrcweir --pSegEnd; 3474cdf0e10cSrcweir if (pSegEnd <= pPathBegin) 3475cdf0e10cSrcweir return SubString(); 3476cdf0e10cSrcweir pSegBegin = pSegEnd - 1; 3477cdf0e10cSrcweir while (pSegBegin > pPathBegin && *pSegBegin != '/') 3478cdf0e10cSrcweir --pSegBegin; 3479cdf0e10cSrcweir } 3480cdf0e10cSrcweir else 3481cdf0e10cSrcweir { 3482cdf0e10cSrcweir pSegBegin = pPathBegin; 3483cdf0e10cSrcweir while (nIndex-- > 0) 3484cdf0e10cSrcweir do 3485cdf0e10cSrcweir { 3486cdf0e10cSrcweir ++pSegBegin; 3487cdf0e10cSrcweir if (pSegBegin >= pPathEnd) 3488cdf0e10cSrcweir return SubString(); 3489cdf0e10cSrcweir } 3490cdf0e10cSrcweir while (*pSegBegin != '/'); 3491cdf0e10cSrcweir pSegEnd = pSegBegin + 1; 3492cdf0e10cSrcweir while (pSegEnd < pPathEnd && *pSegEnd != '/') 3493cdf0e10cSrcweir ++pSegEnd; 3494cdf0e10cSrcweir } 3495cdf0e10cSrcweir 3496cdf0e10cSrcweir return SubString(pSegBegin - m_aAbsURIRef.getStr(), 3497cdf0e10cSrcweir pSegEnd - pSegBegin); 3498cdf0e10cSrcweir } 3499cdf0e10cSrcweir 3500cdf0e10cSrcweir //============================================================================ 3501cdf0e10cSrcweir bool INetURLObject::insertName(rtl::OUString const & rTheName, bool bOctets, 3502cdf0e10cSrcweir bool bAppendFinalSlash, sal_Int32 nIndex, 3503cdf0e10cSrcweir bool bIgnoreFinalSlash, 3504cdf0e10cSrcweir EncodeMechanism eMechanism, 3505cdf0e10cSrcweir rtl_TextEncoding eCharset) 3506cdf0e10cSrcweir { 3507cdf0e10cSrcweir DBG_ASSERT(nIndex >= 0 || nIndex == LAST_SEGMENT, 3508cdf0e10cSrcweir "INetURLObject::insertName(): Bad index"); 3509cdf0e10cSrcweir 3510cdf0e10cSrcweir if (!checkHierarchical()) 3511cdf0e10cSrcweir return false; 3512cdf0e10cSrcweir 3513cdf0e10cSrcweir sal_Unicode const * pPathBegin 3514cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 3515cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 3516cdf0e10cSrcweir sal_Unicode const * pPrefixEnd; 3517cdf0e10cSrcweir bool bInsertSlash; 3518cdf0e10cSrcweir sal_Unicode const * pSuffixBegin; 3519cdf0e10cSrcweir if (nIndex == LAST_SEGMENT) 3520cdf0e10cSrcweir { 3521cdf0e10cSrcweir pPrefixEnd = pPathEnd; 3522cdf0e10cSrcweir if (bIgnoreFinalSlash && pPrefixEnd > pPathBegin && 3523cdf0e10cSrcweir pPrefixEnd[-1] == '/') 3524cdf0e10cSrcweir { 3525cdf0e10cSrcweir --pPrefixEnd; 3526cdf0e10cSrcweir } 3527cdf0e10cSrcweir bInsertSlash = bAppendFinalSlash; 3528cdf0e10cSrcweir pSuffixBegin = pPathEnd; 3529cdf0e10cSrcweir } 3530cdf0e10cSrcweir else if (nIndex == 0) 3531cdf0e10cSrcweir { 3532cdf0e10cSrcweir pPrefixEnd = pPathBegin; 3533cdf0e10cSrcweir bInsertSlash = 3534cdf0e10cSrcweir (pPathBegin < pPathEnd && *pPathBegin != '/') || 3535cdf0e10cSrcweir (pPathBegin == pPathEnd && bAppendFinalSlash); 3536cdf0e10cSrcweir pSuffixBegin = 3537cdf0e10cSrcweir (pPathEnd - pPathBegin == 1 && *pPathBegin == '/' && 3538cdf0e10cSrcweir !bAppendFinalSlash && bIgnoreFinalSlash) 3539cdf0e10cSrcweir ? pPathEnd : pPathBegin; 3540cdf0e10cSrcweir } 3541cdf0e10cSrcweir else 3542cdf0e10cSrcweir { 3543cdf0e10cSrcweir pPrefixEnd = pPathBegin; 3544cdf0e10cSrcweir sal_Unicode const * pEnd = pPathEnd; 3545cdf0e10cSrcweir if (bIgnoreFinalSlash && pEnd > pPathBegin && pEnd[-1] == '/') 3546cdf0e10cSrcweir --pEnd; 3547cdf0e10cSrcweir bool bSkip = pPrefixEnd < pEnd && *pPrefixEnd == '/'; 3548cdf0e10cSrcweir bInsertSlash = false; 3549cdf0e10cSrcweir pSuffixBegin = pPathEnd; 3550cdf0e10cSrcweir while (nIndex-- > 0) 3551cdf0e10cSrcweir for (;;) 3552cdf0e10cSrcweir { 3553cdf0e10cSrcweir if (bSkip) 3554cdf0e10cSrcweir ++pPrefixEnd; 3555cdf0e10cSrcweir bSkip = true; 3556cdf0e10cSrcweir if (pPrefixEnd >= pEnd) 3557cdf0e10cSrcweir { 3558cdf0e10cSrcweir if (nIndex == 0) 3559cdf0e10cSrcweir { 3560cdf0e10cSrcweir bInsertSlash = bAppendFinalSlash; 3561cdf0e10cSrcweir break; 3562cdf0e10cSrcweir } 3563cdf0e10cSrcweir else 3564cdf0e10cSrcweir return false; 3565cdf0e10cSrcweir } 3566cdf0e10cSrcweir if (*pPrefixEnd == '/') 3567cdf0e10cSrcweir { 3568cdf0e10cSrcweir pSuffixBegin = pPrefixEnd; 3569cdf0e10cSrcweir break; 3570cdf0e10cSrcweir } 3571cdf0e10cSrcweir } 3572cdf0e10cSrcweir } 3573cdf0e10cSrcweir 3574cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 3575cdf0e10cSrcweir aNewPath.append(pPathBegin, pPrefixEnd - pPathBegin); 3576cdf0e10cSrcweir aNewPath.append(sal_Unicode('/')); 3577cdf0e10cSrcweir aNewPath.append(encodeText(rTheName, bOctets, PART_PCHAR, getEscapePrefix(), 3578cdf0e10cSrcweir eMechanism, eCharset, true)); 3579cdf0e10cSrcweir if (bInsertSlash) { 3580cdf0e10cSrcweir aNewPath.append(sal_Unicode('/')); 3581cdf0e10cSrcweir } 3582cdf0e10cSrcweir aNewPath.append(pSuffixBegin, pPathEnd - pSuffixBegin); 3583cdf0e10cSrcweir 3584cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 3585cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 3586cdf0e10cSrcweir } 3587cdf0e10cSrcweir 3588cdf0e10cSrcweir //============================================================================ 3589cdf0e10cSrcweir bool INetURLObject::clearQuery() 3590cdf0e10cSrcweir { 3591cdf0e10cSrcweir if (HasError()) 3592cdf0e10cSrcweir return false; 3593cdf0e10cSrcweir if (m_aQuery.isPresent()) 3594cdf0e10cSrcweir { 3595cdf0e10cSrcweir lcl_Erase(m_aAbsURIRef, m_aQuery.getBegin() - 1, 3596cdf0e10cSrcweir m_aQuery.getLength() + 1); 3597cdf0e10cSrcweir m_aFragment += m_aQuery.clear() - 1; 3598cdf0e10cSrcweir } 3599cdf0e10cSrcweir return false; 3600cdf0e10cSrcweir } 3601cdf0e10cSrcweir 3602cdf0e10cSrcweir //============================================================================ 3603cdf0e10cSrcweir bool INetURLObject::setQuery(rtl::OUString const & rTheQuery, bool bOctets, 3604cdf0e10cSrcweir EncodeMechanism eMechanism, 3605cdf0e10cSrcweir rtl_TextEncoding eCharset) 3606cdf0e10cSrcweir { 3607cdf0e10cSrcweir if (!getSchemeInfo().m_bQuery) 3608cdf0e10cSrcweir return false; 3609cdf0e10cSrcweir rtl::OUString aNewQuery(encodeText(rTheQuery, bOctets, PART_URIC, 3610cdf0e10cSrcweir getEscapePrefix(), eMechanism, eCharset, 3611cdf0e10cSrcweir true)); 3612cdf0e10cSrcweir sal_Int32 nDelta; 3613cdf0e10cSrcweir if (m_aQuery.isPresent()) 3614cdf0e10cSrcweir nDelta = m_aQuery.set(m_aAbsURIRef, aNewQuery); 3615cdf0e10cSrcweir else 3616cdf0e10cSrcweir { 3617cdf0e10cSrcweir m_aAbsURIRef.insert(m_aPath.getEnd(), sal_Unicode('?')); 3618cdf0e10cSrcweir nDelta = m_aQuery.set(m_aAbsURIRef, aNewQuery, m_aPath.getEnd() + 1) 3619cdf0e10cSrcweir + 1; 3620cdf0e10cSrcweir } 3621cdf0e10cSrcweir m_aFragment += nDelta; 3622cdf0e10cSrcweir return true; 3623cdf0e10cSrcweir } 3624cdf0e10cSrcweir 3625cdf0e10cSrcweir //============================================================================ 3626cdf0e10cSrcweir bool INetURLObject::clearFragment() 3627cdf0e10cSrcweir { 3628cdf0e10cSrcweir if (HasError()) 3629cdf0e10cSrcweir return false; 3630cdf0e10cSrcweir if (m_aFragment.isPresent()) 3631cdf0e10cSrcweir { 3632cdf0e10cSrcweir m_aAbsURIRef.setLength(m_aFragment.getBegin() - 1); 3633cdf0e10cSrcweir m_aFragment.clear(); 3634cdf0e10cSrcweir } 3635cdf0e10cSrcweir return true; 3636cdf0e10cSrcweir } 3637cdf0e10cSrcweir 3638cdf0e10cSrcweir //============================================================================ 3639cdf0e10cSrcweir bool INetURLObject::setFragment(rtl::OUString const & rTheFragment, 3640cdf0e10cSrcweir bool bOctets, EncodeMechanism eMechanism, 3641cdf0e10cSrcweir rtl_TextEncoding eCharset) 3642cdf0e10cSrcweir { 3643cdf0e10cSrcweir if (HasError()) 3644cdf0e10cSrcweir return false; 3645cdf0e10cSrcweir rtl::OUString aNewFragment(encodeText(rTheFragment, bOctets, PART_URIC, 3646cdf0e10cSrcweir getEscapePrefix(), eMechanism, 3647cdf0e10cSrcweir eCharset, true)); 3648cdf0e10cSrcweir if (m_aFragment.isPresent()) 3649cdf0e10cSrcweir m_aFragment.set(m_aAbsURIRef, aNewFragment); 3650cdf0e10cSrcweir else 3651cdf0e10cSrcweir { 3652cdf0e10cSrcweir m_aAbsURIRef.append(sal_Unicode('#')); 3653cdf0e10cSrcweir m_aFragment.set(m_aAbsURIRef, aNewFragment, m_aAbsURIRef.getLength()); 3654cdf0e10cSrcweir } 3655cdf0e10cSrcweir return true; 3656cdf0e10cSrcweir } 3657cdf0e10cSrcweir 3658cdf0e10cSrcweir //============================================================================ 3659cdf0e10cSrcweir INetURLObject::FTPType INetURLObject::getFTPType() const 3660cdf0e10cSrcweir { 3661cdf0e10cSrcweir if (m_eScheme == INET_PROT_FTP 3662cdf0e10cSrcweir && m_aPath.getLength() >= RTL_CONSTASCII_LENGTH(";type=") + 1 3663cdf0e10cSrcweir && rtl::OUString(m_aAbsURIRef).copy( 3664cdf0e10cSrcweir m_aPath.getEnd() - (RTL_CONSTASCII_LENGTH(";type=") + 1), 3665cdf0e10cSrcweir RTL_CONSTASCII_LENGTH(";type=")).equalsIgnoreAsciiCaseAscii(";type=")) 3666cdf0e10cSrcweir switch (m_aAbsURIRef.charAt(m_aPath.getEnd())) 3667cdf0e10cSrcweir { 3668cdf0e10cSrcweir case 'A': 3669cdf0e10cSrcweir case 'a': 3670cdf0e10cSrcweir return FTP_TYPE_A; 3671cdf0e10cSrcweir 3672cdf0e10cSrcweir case 'D': 3673cdf0e10cSrcweir case 'd': 3674cdf0e10cSrcweir return FTP_TYPE_D; 3675cdf0e10cSrcweir 3676cdf0e10cSrcweir case 'I': 3677cdf0e10cSrcweir case 'i': 3678cdf0e10cSrcweir return FTP_TYPE_I; 3679cdf0e10cSrcweir } 3680cdf0e10cSrcweir return FTP_TYPE_NONE; 3681cdf0e10cSrcweir } 3682cdf0e10cSrcweir 3683cdf0e10cSrcweir //============================================================================ 3684cdf0e10cSrcweir bool INetURLObject::hasDosVolume(FSysStyle eStyle) const 3685cdf0e10cSrcweir { 3686cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 3687cdf0e10cSrcweir return (eStyle & FSYS_DOS) != 0 3688cdf0e10cSrcweir && m_aPath.getLength() >= 3 3689cdf0e10cSrcweir && p[0] == '/' 3690cdf0e10cSrcweir && INetMIME::isAlpha(p[1]) 3691cdf0e10cSrcweir && p[2] == ':' 3692cdf0e10cSrcweir && (m_aPath.getLength() == 3 || p[3] == '/'); 3693cdf0e10cSrcweir } 3694cdf0e10cSrcweir 3695cdf0e10cSrcweir //============================================================================ 3696cdf0e10cSrcweir sal_uInt32 INetURLObject::getIMAPUID() const 3697cdf0e10cSrcweir { 3698cdf0e10cSrcweir if (m_eScheme == INET_PROT_IMAP 3699cdf0e10cSrcweir && m_aPath.getLength() >= RTL_CONSTASCII_LENGTH("/;uid=") + 1) 3700cdf0e10cSrcweir { 3701cdf0e10cSrcweir sal_Unicode const * pBegin = m_aAbsURIRef.getStr() 3702cdf0e10cSrcweir + m_aPath.getBegin() 3703cdf0e10cSrcweir + RTL_CONSTASCII_LENGTH("/;uid="); 3704cdf0e10cSrcweir sal_Unicode const * pEnd = pBegin + m_aPath.getLength(); 3705cdf0e10cSrcweir sal_Unicode const * p = pEnd; 3706cdf0e10cSrcweir while (p > pBegin && INetMIME::isDigit(p[-1])) 3707cdf0e10cSrcweir --p; 3708cdf0e10cSrcweir if (p < pEnd && *--p != '0' 3709cdf0e10cSrcweir && rtl::OUString(m_aAbsURIRef).copy( 3710cdf0e10cSrcweir p - RTL_CONSTASCII_LENGTH("/;uid=") - m_aAbsURIRef.getStr(), 3711cdf0e10cSrcweir RTL_CONSTASCII_LENGTH("/;uid=")).equalsIgnoreAsciiCaseAscii("/;uid=") 3712cdf0e10cSrcweir ) 3713cdf0e10cSrcweir { 3714cdf0e10cSrcweir sal_uInt32 nUID; 3715cdf0e10cSrcweir if (INetMIME::scanUnsigned(p, pEnd, false, nUID)) 3716cdf0e10cSrcweir return nUID; 3717cdf0e10cSrcweir } 3718cdf0e10cSrcweir } 3719cdf0e10cSrcweir return 0; 3720cdf0e10cSrcweir } 3721cdf0e10cSrcweir 3722cdf0e10cSrcweir //============================================================================ 3723cdf0e10cSrcweir // static 3724cdf0e10cSrcweir rtl::OUString INetURLObject::encodeText(sal_Unicode const * pBegin, 3725cdf0e10cSrcweir sal_Unicode const * pEnd, bool bOctets, 3726cdf0e10cSrcweir Part ePart, sal_Char cEscapePrefix, 3727cdf0e10cSrcweir EncodeMechanism eMechanism, 3728cdf0e10cSrcweir rtl_TextEncoding eCharset, 3729cdf0e10cSrcweir bool bKeepVisibleEscapes) 3730cdf0e10cSrcweir { 3731cdf0e10cSrcweir rtl::OUStringBuffer aResult; 3732cdf0e10cSrcweir while (pBegin < pEnd) 3733cdf0e10cSrcweir { 3734cdf0e10cSrcweir EscapeType eEscapeType; 3735cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pBegin, pEnd, bOctets, cEscapePrefix, 3736cdf0e10cSrcweir eMechanism, eCharset, eEscapeType); 3737cdf0e10cSrcweir appendUCS4(aResult, nUTF32, eEscapeType, bOctets, ePart, 3738cdf0e10cSrcweir cEscapePrefix, eCharset, bKeepVisibleEscapes); 3739cdf0e10cSrcweir } 3740cdf0e10cSrcweir return aResult.makeStringAndClear(); 3741cdf0e10cSrcweir } 3742cdf0e10cSrcweir 3743cdf0e10cSrcweir //============================================================================ 3744cdf0e10cSrcweir // static 3745cdf0e10cSrcweir rtl::OUString INetURLObject::decode(sal_Unicode const * pBegin, 3746cdf0e10cSrcweir sal_Unicode const * pEnd, 3747cdf0e10cSrcweir sal_Char cEscapePrefix, 3748cdf0e10cSrcweir DecodeMechanism eMechanism, 3749cdf0e10cSrcweir rtl_TextEncoding eCharset) 3750cdf0e10cSrcweir { 3751cdf0e10cSrcweir switch (eMechanism) 3752cdf0e10cSrcweir { 3753cdf0e10cSrcweir case NO_DECODE: 3754cdf0e10cSrcweir return rtl::OUString(pBegin, pEnd - pBegin); 3755cdf0e10cSrcweir 3756cdf0e10cSrcweir case DECODE_TO_IURI: 3757cdf0e10cSrcweir eCharset = RTL_TEXTENCODING_UTF8; 3758cdf0e10cSrcweir break; 3759cdf0e10cSrcweir 3760cdf0e10cSrcweir default: 3761cdf0e10cSrcweir break; 3762cdf0e10cSrcweir } 3763cdf0e10cSrcweir rtl::OUStringBuffer aResult; 3764cdf0e10cSrcweir while (pBegin < pEnd) 3765cdf0e10cSrcweir { 3766cdf0e10cSrcweir EscapeType eEscapeType; 3767cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(pBegin, pEnd, false, cEscapePrefix, 3768cdf0e10cSrcweir WAS_ENCODED, eCharset, eEscapeType); 3769cdf0e10cSrcweir switch (eEscapeType) 3770cdf0e10cSrcweir { 3771cdf0e10cSrcweir case ESCAPE_NO: 3772cdf0e10cSrcweir aResult.append(sal_Unicode(nUTF32)); 3773cdf0e10cSrcweir break; 3774cdf0e10cSrcweir 3775cdf0e10cSrcweir case ESCAPE_OCTET: 3776cdf0e10cSrcweir appendEscape(aResult, cEscapePrefix, nUTF32); 3777cdf0e10cSrcweir break; 3778cdf0e10cSrcweir 3779cdf0e10cSrcweir case ESCAPE_UTF32: 3780cdf0e10cSrcweir if ( 3781cdf0e10cSrcweir INetMIME::isUSASCII(nUTF32) && 3782cdf0e10cSrcweir ( 3783cdf0e10cSrcweir eMechanism == DECODE_TO_IURI || 3784cdf0e10cSrcweir ( 3785cdf0e10cSrcweir eMechanism == DECODE_UNAMBIGUOUS && 3786cdf0e10cSrcweir mustEncode(nUTF32, PART_UNAMBIGUOUS) 3787cdf0e10cSrcweir ) 3788cdf0e10cSrcweir ) 3789cdf0e10cSrcweir ) 3790cdf0e10cSrcweir { 3791cdf0e10cSrcweir appendEscape(aResult, cEscapePrefix, nUTF32); 3792cdf0e10cSrcweir } 3793cdf0e10cSrcweir else 3794cdf0e10cSrcweir aResult.append(sal_Unicode(nUTF32)); 3795cdf0e10cSrcweir break; 3796cdf0e10cSrcweir } 3797cdf0e10cSrcweir } 3798cdf0e10cSrcweir return aResult.makeStringAndClear(); 3799cdf0e10cSrcweir } 3800cdf0e10cSrcweir 3801cdf0e10cSrcweir //============================================================================ 3802cdf0e10cSrcweir rtl::OUString INetURLObject::GetURLNoPass(DecodeMechanism eMechanism, 3803cdf0e10cSrcweir rtl_TextEncoding eCharset) const 3804cdf0e10cSrcweir { 3805cdf0e10cSrcweir INetURLObject aTemp(*this); 3806cdf0e10cSrcweir aTemp.clearPassword(); 3807cdf0e10cSrcweir return aTemp.GetMainURL(eMechanism, eCharset); 3808cdf0e10cSrcweir } 3809cdf0e10cSrcweir 3810cdf0e10cSrcweir //============================================================================ 3811cdf0e10cSrcweir rtl::OUString INetURLObject::GetURLNoMark(DecodeMechanism eMechanism, 3812cdf0e10cSrcweir rtl_TextEncoding eCharset) const 3813cdf0e10cSrcweir { 3814cdf0e10cSrcweir INetURLObject aTemp(*this); 3815cdf0e10cSrcweir aTemp.clearFragment(); 3816cdf0e10cSrcweir return aTemp.GetMainURL(eMechanism, eCharset); 3817cdf0e10cSrcweir } 3818cdf0e10cSrcweir 3819cdf0e10cSrcweir //============================================================================ 3820cdf0e10cSrcweir rtl::OUString 3821cdf0e10cSrcweir INetURLObject::getAbbreviated( 3822cdf0e10cSrcweir star::uno::Reference< star::util::XStringWidth > const & rStringWidth, 3823cdf0e10cSrcweir sal_Int32 nWidth, 3824cdf0e10cSrcweir DecodeMechanism eMechanism, 3825cdf0e10cSrcweir rtl_TextEncoding eCharset) 3826cdf0e10cSrcweir const 3827cdf0e10cSrcweir { 3828cdf0e10cSrcweir OSL_ENSURE(rStringWidth.is(), "specification violation"); 3829cdf0e10cSrcweir sal_Char cEscapePrefix = getEscapePrefix(); 3830cdf0e10cSrcweir rtl::OUStringBuffer aBuffer; 3831cdf0e10cSrcweir // make sure that the scheme is copied for generic schemes: getSchemeInfo().m_pScheme 3832cdf0e10cSrcweir // is empty ("") in that case, so take the scheme from m_aAbsURIRef 3833cdf0e10cSrcweir if (m_eScheme != INET_PROT_GENERIC) 3834cdf0e10cSrcweir { 3835cdf0e10cSrcweir aBuffer.appendAscii(getSchemeInfo().m_pScheme); 3836cdf0e10cSrcweir } 3837cdf0e10cSrcweir else 3838cdf0e10cSrcweir { 3839cdf0e10cSrcweir if (m_aAbsURIRef) 3840cdf0e10cSrcweir { 3841cdf0e10cSrcweir sal_Unicode const * pSchemeBegin 3842cdf0e10cSrcweir = m_aAbsURIRef.getStr(); 3843cdf0e10cSrcweir sal_Unicode const * pSchemeEnd = pSchemeBegin; 3844cdf0e10cSrcweir 3845cdf0e10cSrcweir while (pSchemeEnd[0] != ':') 3846cdf0e10cSrcweir { 3847cdf0e10cSrcweir ++pSchemeEnd; 3848cdf0e10cSrcweir } 3849cdf0e10cSrcweir aBuffer.append(pSchemeBegin, pSchemeEnd - pSchemeBegin); 3850cdf0e10cSrcweir } 3851cdf0e10cSrcweir } 3852cdf0e10cSrcweir aBuffer.append(static_cast< sal_Unicode >(':')); 3853cdf0e10cSrcweir bool bAuthority = getSchemeInfo().m_bAuthority; 3854cdf0e10cSrcweir sal_Unicode const * pCoreBegin 3855cdf0e10cSrcweir = m_aAbsURIRef.getStr() + (bAuthority ? getAuthorityBegin() : 3856cdf0e10cSrcweir m_aPath.getBegin()); 3857cdf0e10cSrcweir sal_Unicode const * pCoreEnd 3858cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin() + m_aPath.getLength(); 3859cdf0e10cSrcweir bool bSegment = false; 3860cdf0e10cSrcweir if (getSchemeInfo().m_bHierarchical) 3861cdf0e10cSrcweir { 3862cdf0e10cSrcweir rtl::OUString aRest; 3863cdf0e10cSrcweir if (m_aQuery.isPresent()) 3864cdf0e10cSrcweir aRest = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?...")); 3865cdf0e10cSrcweir else if (m_aFragment.isPresent()) 3866cdf0e10cSrcweir aRest = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#...")); 3867cdf0e10cSrcweir rtl::OUStringBuffer aTrailer; 3868cdf0e10cSrcweir sal_Unicode const * pBegin = pCoreBegin; 3869cdf0e10cSrcweir sal_Unicode const * pEnd = pCoreEnd; 3870cdf0e10cSrcweir sal_Unicode const * pPrefixBegin = pBegin; 3871cdf0e10cSrcweir sal_Unicode const * pSuffixEnd = pEnd; 3872cdf0e10cSrcweir bool bPrefix = true; 3873cdf0e10cSrcweir bool bSuffix = true; 3874cdf0e10cSrcweir do 3875cdf0e10cSrcweir { 3876cdf0e10cSrcweir if (bSuffix) 3877cdf0e10cSrcweir { 3878cdf0e10cSrcweir sal_Unicode const * p = pSuffixEnd - 1; 3879cdf0e10cSrcweir if (pSuffixEnd == pCoreEnd && *p == '/') 3880cdf0e10cSrcweir --p; 3881cdf0e10cSrcweir while (*p != '/') 3882cdf0e10cSrcweir --p; 3883cdf0e10cSrcweir if (bAuthority && p == pCoreBegin + 1) 3884cdf0e10cSrcweir --p; 3885cdf0e10cSrcweir rtl::OUString 3886cdf0e10cSrcweir aSegment(decode(p + (p == pBegin && pBegin != pCoreBegin ? 3887cdf0e10cSrcweir 1 : 0), 3888cdf0e10cSrcweir pSuffixEnd, 3889cdf0e10cSrcweir cEscapePrefix, 3890cdf0e10cSrcweir eMechanism, 3891cdf0e10cSrcweir eCharset)); 3892cdf0e10cSrcweir pSuffixEnd = p; 3893cdf0e10cSrcweir rtl::OUStringBuffer aResult(aBuffer); 3894cdf0e10cSrcweir if (pSuffixEnd != pBegin) 3895cdf0e10cSrcweir aResult.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); 3896cdf0e10cSrcweir aResult.append(aSegment); 3897cdf0e10cSrcweir aResult.append(aTrailer); 3898cdf0e10cSrcweir aResult.append(aRest); 3899cdf0e10cSrcweir if (rStringWidth-> 3900cdf0e10cSrcweir queryStringWidth(aResult.makeStringAndClear()) 3901cdf0e10cSrcweir <= nWidth) 3902cdf0e10cSrcweir { 3903cdf0e10cSrcweir aTrailer.insert(0, aSegment); 3904cdf0e10cSrcweir bSegment = true; 3905cdf0e10cSrcweir pEnd = pSuffixEnd; 3906cdf0e10cSrcweir } 3907cdf0e10cSrcweir else 3908cdf0e10cSrcweir bSuffix = false; 3909cdf0e10cSrcweir if (pPrefixBegin > pSuffixEnd) 3910cdf0e10cSrcweir pPrefixBegin = pSuffixEnd; 3911cdf0e10cSrcweir if (pBegin == pEnd) 3912cdf0e10cSrcweir break; 3913cdf0e10cSrcweir } 3914cdf0e10cSrcweir if (bPrefix) 3915cdf0e10cSrcweir { 3916cdf0e10cSrcweir sal_Unicode const * p 3917cdf0e10cSrcweir = pPrefixBegin 3918cdf0e10cSrcweir + (bAuthority && pPrefixBegin == pCoreBegin ? 2 : 3919cdf0e10cSrcweir 1); 3920cdf0e10cSrcweir OSL_ASSERT(p <= pEnd); 3921cdf0e10cSrcweir while (p < pEnd && *p != '/') 3922cdf0e10cSrcweir ++p; 3923cdf0e10cSrcweir if (p == pCoreEnd - 1 && *p == '/') 3924cdf0e10cSrcweir ++p; 3925cdf0e10cSrcweir rtl::OUString 3926cdf0e10cSrcweir aSegment(decode(pPrefixBegin 3927cdf0e10cSrcweir + (pPrefixBegin == pCoreBegin ? 0 : 3928cdf0e10cSrcweir 1), 3929cdf0e10cSrcweir p == pEnd ? p : p + 1, 3930cdf0e10cSrcweir cEscapePrefix, 3931cdf0e10cSrcweir eMechanism, 3932cdf0e10cSrcweir eCharset)); 3933cdf0e10cSrcweir pPrefixBegin = p; 3934cdf0e10cSrcweir rtl::OUStringBuffer aResult(aBuffer); 3935cdf0e10cSrcweir aResult.append(aSegment); 3936cdf0e10cSrcweir if (pPrefixBegin != pEnd) 3937cdf0e10cSrcweir aResult.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); 3938cdf0e10cSrcweir aResult.append(aTrailer); 3939cdf0e10cSrcweir aResult.append(aRest); 3940cdf0e10cSrcweir if (rStringWidth-> 3941cdf0e10cSrcweir queryStringWidth(aResult.makeStringAndClear()) 3942cdf0e10cSrcweir <= nWidth) 3943cdf0e10cSrcweir { 3944cdf0e10cSrcweir aBuffer.append(aSegment); 3945cdf0e10cSrcweir bSegment = true; 3946cdf0e10cSrcweir pBegin = pPrefixBegin; 3947cdf0e10cSrcweir } 3948cdf0e10cSrcweir else 3949cdf0e10cSrcweir bPrefix = false; 3950cdf0e10cSrcweir if (pPrefixBegin > pSuffixEnd) 3951cdf0e10cSrcweir pSuffixEnd = pPrefixBegin; 3952cdf0e10cSrcweir if (pBegin == pEnd) 3953cdf0e10cSrcweir break; 3954cdf0e10cSrcweir } 3955cdf0e10cSrcweir } 3956cdf0e10cSrcweir while (bPrefix || bSuffix); 3957cdf0e10cSrcweir if (bSegment) 3958cdf0e10cSrcweir { 3959cdf0e10cSrcweir if (pPrefixBegin != pBegin || pSuffixEnd != pEnd) 3960cdf0e10cSrcweir aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); 3961cdf0e10cSrcweir aBuffer.append(aTrailer); 3962cdf0e10cSrcweir } 3963cdf0e10cSrcweir } 3964cdf0e10cSrcweir if (!bSegment) 3965cdf0e10cSrcweir aBuffer.append(decode(pCoreBegin, 3966cdf0e10cSrcweir pCoreEnd, 3967cdf0e10cSrcweir cEscapePrefix, 3968cdf0e10cSrcweir eMechanism, 3969cdf0e10cSrcweir eCharset)); 3970cdf0e10cSrcweir if (m_aQuery.isPresent()) 3971cdf0e10cSrcweir { 3972cdf0e10cSrcweir aBuffer.append(static_cast< sal_Unicode >('?')); 3973cdf0e10cSrcweir aBuffer.append(decode(m_aQuery, cEscapePrefix, eMechanism, eCharset)); 3974cdf0e10cSrcweir } 3975cdf0e10cSrcweir if (m_aFragment.isPresent()) 3976cdf0e10cSrcweir { 3977cdf0e10cSrcweir aBuffer.append(static_cast< sal_Unicode >('#')); 3978cdf0e10cSrcweir aBuffer. 3979cdf0e10cSrcweir append(decode(m_aFragment, cEscapePrefix, eMechanism, eCharset)); 3980cdf0e10cSrcweir } 3981cdf0e10cSrcweir if (aBuffer.getLength() != 0) 3982cdf0e10cSrcweir { 3983cdf0e10cSrcweir rtl::OUStringBuffer aResult(aBuffer); 3984cdf0e10cSrcweir if (rStringWidth->queryStringWidth(aResult.makeStringAndClear()) 3985cdf0e10cSrcweir > nWidth) 3986cdf0e10cSrcweir for (sal_Int32 i = aBuffer.getLength();;) 3987cdf0e10cSrcweir { 3988cdf0e10cSrcweir if (i == 0) 3989cdf0e10cSrcweir { 3990cdf0e10cSrcweir aBuffer.setLength(aBuffer.getLength() - 1); 3991cdf0e10cSrcweir if (aBuffer.getLength() == 0) 3992cdf0e10cSrcweir break; 3993cdf0e10cSrcweir } 3994cdf0e10cSrcweir else 3995cdf0e10cSrcweir { 3996cdf0e10cSrcweir aBuffer.setLength(--i); 3997cdf0e10cSrcweir aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("...")); 3998cdf0e10cSrcweir } 3999cdf0e10cSrcweir aResult = aBuffer; 4000cdf0e10cSrcweir if (rStringWidth-> 4001cdf0e10cSrcweir queryStringWidth(aResult.makeStringAndClear()) 4002cdf0e10cSrcweir <= nWidth) 4003cdf0e10cSrcweir break; 4004cdf0e10cSrcweir } 4005cdf0e10cSrcweir } 4006cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 4007cdf0e10cSrcweir } 4008cdf0e10cSrcweir 4009cdf0e10cSrcweir //============================================================================ 4010cdf0e10cSrcweir bool INetURLObject::operator ==(INetURLObject const & rObject) const 4011cdf0e10cSrcweir { 4012cdf0e10cSrcweir if (m_eScheme != rObject.m_eScheme) 4013cdf0e10cSrcweir return false; 4014cdf0e10cSrcweir if (m_eScheme == INET_PROT_NOT_VALID) 4015cdf0e10cSrcweir return (m_aAbsURIRef == rObject.m_aAbsURIRef) != false; 4016cdf0e10cSrcweir if ((m_aScheme.compare( 4017cdf0e10cSrcweir rObject.m_aScheme, m_aAbsURIRef, rObject.m_aAbsURIRef) 4018cdf0e10cSrcweir != 0) 4019cdf0e10cSrcweir || GetUser(NO_DECODE) != rObject.GetUser(NO_DECODE) 4020cdf0e10cSrcweir || GetPass(NO_DECODE) != rObject.GetPass(NO_DECODE) 4021cdf0e10cSrcweir || !GetHost(NO_DECODE).equalsIgnoreAsciiCase( 4022cdf0e10cSrcweir rObject.GetHost(NO_DECODE)) 4023cdf0e10cSrcweir || GetPort() != rObject.GetPort() 4024cdf0e10cSrcweir || HasParam() != rObject.HasParam() 4025cdf0e10cSrcweir || GetParam(NO_DECODE) != rObject.GetParam(NO_DECODE) 4026cdf0e10cSrcweir || GetMsgId(NO_DECODE) != rObject.GetMsgId(NO_DECODE)) 4027cdf0e10cSrcweir return false; 4028cdf0e10cSrcweir rtl::OUString aPath1(GetURLPath(NO_DECODE)); 4029cdf0e10cSrcweir rtl::OUString aPath2(rObject.GetURLPath(NO_DECODE)); 4030cdf0e10cSrcweir switch (m_eScheme) 4031cdf0e10cSrcweir { 4032cdf0e10cSrcweir case INET_PROT_FILE: 4033cdf0e10cSrcweir { 4034cdf0e10cSrcweir // If the URL paths of two file URLs only differ in that one has a 4035cdf0e10cSrcweir // final '/' and the other has not, take the two paths as 4036cdf0e10cSrcweir // equivalent (this could be usefull for other schemes, too): 4037cdf0e10cSrcweir sal_Int32 nLength = aPath1.getLength(); 4038cdf0e10cSrcweir switch (nLength - aPath2.getLength()) 4039cdf0e10cSrcweir { 4040cdf0e10cSrcweir case -1: 4041cdf0e10cSrcweir if (aPath2.getStr()[nLength] != '/') 4042cdf0e10cSrcweir return false; 4043cdf0e10cSrcweir break; 4044cdf0e10cSrcweir 4045cdf0e10cSrcweir case 0: 4046cdf0e10cSrcweir break; 4047cdf0e10cSrcweir 4048cdf0e10cSrcweir case 1: 4049cdf0e10cSrcweir if (aPath1.getStr()[--nLength] != '/') 4050cdf0e10cSrcweir return false; 4051cdf0e10cSrcweir break; 4052cdf0e10cSrcweir 4053cdf0e10cSrcweir default: 4054cdf0e10cSrcweir return false; 4055cdf0e10cSrcweir } 4056cdf0e10cSrcweir return aPath1.compareTo(aPath2, nLength) == 0; 4057cdf0e10cSrcweir } 4058cdf0e10cSrcweir 4059cdf0e10cSrcweir default: 4060cdf0e10cSrcweir return (aPath1 == aPath2) != false; 4061cdf0e10cSrcweir } 4062cdf0e10cSrcweir } 4063cdf0e10cSrcweir 4064cdf0e10cSrcweir //============================================================================ 4065cdf0e10cSrcweir bool INetURLObject::operator <(INetURLObject const & rObject) const 4066cdf0e10cSrcweir { 4067cdf0e10cSrcweir sal_Int32 nCompare = m_aScheme.compare( 4068cdf0e10cSrcweir rObject.m_aScheme, m_aAbsURIRef, rObject.m_aAbsURIRef); 4069cdf0e10cSrcweir if (nCompare < 0) { 4070cdf0e10cSrcweir return true; 4071cdf0e10cSrcweir } else if (nCompare > 0) { 4072cdf0e10cSrcweir return false; 4073cdf0e10cSrcweir } 4074cdf0e10cSrcweir sal_uInt32 nPort1 = GetPort(); 4075cdf0e10cSrcweir sal_uInt32 nPort2 = rObject.GetPort(); 4076cdf0e10cSrcweir if (nPort1 < nPort2) 4077cdf0e10cSrcweir return true; 4078cdf0e10cSrcweir else if (nPort1 > nPort2) 4079cdf0e10cSrcweir return false; 4080cdf0e10cSrcweir nCompare = GetUser(NO_DECODE).compareTo(rObject.GetUser(NO_DECODE)); 4081cdf0e10cSrcweir if (nCompare < 0) 4082cdf0e10cSrcweir return true; 4083cdf0e10cSrcweir else if (nCompare > 0) 4084cdf0e10cSrcweir return false; 4085cdf0e10cSrcweir nCompare = GetPass(NO_DECODE).compareTo(rObject.GetPass(NO_DECODE)); 4086cdf0e10cSrcweir if (nCompare < 0) 4087cdf0e10cSrcweir return true; 4088cdf0e10cSrcweir else if (nCompare > 0) 4089cdf0e10cSrcweir return false; 4090cdf0e10cSrcweir nCompare = GetHost(NO_DECODE).compareTo(rObject.GetHost(NO_DECODE)); 4091cdf0e10cSrcweir if (nCompare < 0) 4092cdf0e10cSrcweir return true; 4093cdf0e10cSrcweir else if (nCompare > 0) 4094cdf0e10cSrcweir return false; 4095cdf0e10cSrcweir const rtl::OUString &rPath1(GetURLPath(NO_DECODE)); 4096cdf0e10cSrcweir const rtl::OUString &rPath2(rObject.GetURLPath(NO_DECODE)); 4097cdf0e10cSrcweir nCompare = rPath1.compareTo(rPath2); 4098cdf0e10cSrcweir if (nCompare < 0) 4099cdf0e10cSrcweir return true; 4100cdf0e10cSrcweir else if (nCompare > 0) 4101cdf0e10cSrcweir return false; 4102cdf0e10cSrcweir nCompare = GetParam(NO_DECODE).compareTo(rObject.GetParam(NO_DECODE)); 4103cdf0e10cSrcweir if (nCompare < 0) 4104cdf0e10cSrcweir return true; 4105cdf0e10cSrcweir else if (nCompare > 0) 4106cdf0e10cSrcweir return false; 4107cdf0e10cSrcweir return GetMsgId(NO_DECODE).compareTo(rObject.GetMsgId(NO_DECODE)) < 0; 4108cdf0e10cSrcweir } 4109cdf0e10cSrcweir 4110cdf0e10cSrcweir //============================================================================ 4111cdf0e10cSrcweir bool INetURLObject::ConcatData(INetProtocol eTheScheme, 4112cdf0e10cSrcweir rtl::OUString const & rTheUser, 4113cdf0e10cSrcweir rtl::OUString const & rThePassword, 4114cdf0e10cSrcweir rtl::OUString const & rTheHost, 4115cdf0e10cSrcweir sal_uInt32 nThePort, 4116cdf0e10cSrcweir rtl::OUString const & rThePath, 4117cdf0e10cSrcweir EncodeMechanism eMechanism, 4118cdf0e10cSrcweir rtl_TextEncoding eCharset) 4119cdf0e10cSrcweir { 4120cdf0e10cSrcweir setInvalid(); 4121cdf0e10cSrcweir m_eScheme = eTheScheme; 4122cdf0e10cSrcweir if (HasError() || m_eScheme == INET_PROT_GENERIC) 4123cdf0e10cSrcweir return false; 4124cdf0e10cSrcweir m_aAbsURIRef.setLength(0); 4125cdf0e10cSrcweir m_aAbsURIRef.appendAscii(getSchemeInfo().m_pScheme); 4126cdf0e10cSrcweir m_aAbsURIRef.append(sal_Unicode(':')); 4127cdf0e10cSrcweir if (getSchemeInfo().m_bAuthority) 4128cdf0e10cSrcweir { 4129cdf0e10cSrcweir m_aAbsURIRef.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 4130cdf0e10cSrcweir bool bUserInfo = false; 4131cdf0e10cSrcweir if (getSchemeInfo().m_bUser) 4132cdf0e10cSrcweir { 4133cdf0e10cSrcweir if (m_eScheme == INET_PROT_IMAP && rTheUser.getLength() == 0) 4134cdf0e10cSrcweir { 4135cdf0e10cSrcweir setInvalid(); 4136cdf0e10cSrcweir return false; 4137cdf0e10cSrcweir } 4138cdf0e10cSrcweir if (rTheUser.getLength() != 0) 4139cdf0e10cSrcweir { 4140cdf0e10cSrcweir m_aUser.set(m_aAbsURIRef, 4141cdf0e10cSrcweir encodeText(rTheUser, false, 4142cdf0e10cSrcweir m_eScheme == INET_PROT_IMAP ? 4143cdf0e10cSrcweir PART_IMAP_ACHAR : 4144cdf0e10cSrcweir m_eScheme == INET_PROT_VIM ? 4145cdf0e10cSrcweir PART_VIM : 4146cdf0e10cSrcweir PART_USER_PASSWORD, 4147cdf0e10cSrcweir getEscapePrefix(), eMechanism, 4148cdf0e10cSrcweir eCharset, false), 4149cdf0e10cSrcweir m_aAbsURIRef.getLength()); 4150cdf0e10cSrcweir bUserInfo = true; 4151cdf0e10cSrcweir } 4152cdf0e10cSrcweir } 4153cdf0e10cSrcweir else if (rTheUser.getLength() != 0) 4154cdf0e10cSrcweir { 4155cdf0e10cSrcweir setInvalid(); 4156cdf0e10cSrcweir return false; 4157cdf0e10cSrcweir } 4158cdf0e10cSrcweir if (rThePassword.getLength() != 0) 4159cdf0e10cSrcweir { 4160cdf0e10cSrcweir if (getSchemeInfo().m_bPassword) 4161cdf0e10cSrcweir { 4162cdf0e10cSrcweir m_aAbsURIRef.append(sal_Unicode(':')); 4163cdf0e10cSrcweir m_aAuth.set(m_aAbsURIRef, 4164cdf0e10cSrcweir encodeText(rThePassword, false, 4165cdf0e10cSrcweir m_eScheme == INET_PROT_VIM ? 4166cdf0e10cSrcweir PART_VIM : PART_USER_PASSWORD, 4167cdf0e10cSrcweir getEscapePrefix(), eMechanism, 4168cdf0e10cSrcweir eCharset, false), 4169cdf0e10cSrcweir m_aAbsURIRef.getLength()); 4170cdf0e10cSrcweir bUserInfo = true; 4171cdf0e10cSrcweir } 4172cdf0e10cSrcweir else 4173cdf0e10cSrcweir { 4174cdf0e10cSrcweir setInvalid(); 4175cdf0e10cSrcweir return false; 4176cdf0e10cSrcweir } 4177cdf0e10cSrcweir } 4178cdf0e10cSrcweir if (bUserInfo && getSchemeInfo().m_bHost) 4179cdf0e10cSrcweir m_aAbsURIRef.append(sal_Unicode('@')); 4180cdf0e10cSrcweir if (getSchemeInfo().m_bHost) 4181cdf0e10cSrcweir { 4182cdf0e10cSrcweir rtl::OUStringBuffer aSynHost(rTheHost); 4183cdf0e10cSrcweir bool bNetBiosName = false; 4184cdf0e10cSrcweir switch (m_eScheme) 4185cdf0e10cSrcweir { 4186cdf0e10cSrcweir case INET_PROT_FILE: 4187cdf0e10cSrcweir { 4188cdf0e10cSrcweir rtl::OUString sTemp(aSynHost); 4189cdf0e10cSrcweir if (sTemp.equalsIgnoreAsciiCaseAsciiL( 4190cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("localhost"))) 4191cdf0e10cSrcweir { 4192cdf0e10cSrcweir aSynHost.setLength(0); 4193cdf0e10cSrcweir } 4194cdf0e10cSrcweir bNetBiosName = true; 4195cdf0e10cSrcweir } 4196cdf0e10cSrcweir break; 4197cdf0e10cSrcweir 4198cdf0e10cSrcweir case INET_PROT_LDAP: 4199cdf0e10cSrcweir if (aSynHost.getLength() == 0 && nThePort != 0) 4200cdf0e10cSrcweir { 4201cdf0e10cSrcweir setInvalid(); 4202cdf0e10cSrcweir return false; 4203cdf0e10cSrcweir } 4204cdf0e10cSrcweir break; 4205cdf0e10cSrcweir 4206cdf0e10cSrcweir default: 4207cdf0e10cSrcweir if (aSynHost.getLength() == 0) 4208cdf0e10cSrcweir { 4209cdf0e10cSrcweir setInvalid(); 4210cdf0e10cSrcweir return false; 4211cdf0e10cSrcweir } 4212cdf0e10cSrcweir break; 4213cdf0e10cSrcweir } 4214cdf0e10cSrcweir if (!parseHostOrNetBiosName( 4215cdf0e10cSrcweir aSynHost.getStr(), aSynHost.getStr() + aSynHost.getLength(), 4216cdf0e10cSrcweir false, eMechanism, eCharset, bNetBiosName, &aSynHost)) 4217cdf0e10cSrcweir { 4218cdf0e10cSrcweir setInvalid(); 4219cdf0e10cSrcweir return false; 4220cdf0e10cSrcweir } 4221cdf0e10cSrcweir m_aHost.set(m_aAbsURIRef, aSynHost.makeStringAndClear(), 4222cdf0e10cSrcweir m_aAbsURIRef.getLength()); 4223cdf0e10cSrcweir if (nThePort != 0) 4224cdf0e10cSrcweir { 4225cdf0e10cSrcweir if (getSchemeInfo().m_bPort) 4226cdf0e10cSrcweir { 4227cdf0e10cSrcweir m_aAbsURIRef.append(sal_Unicode(':')); 4228cdf0e10cSrcweir m_aPort.set(m_aAbsURIRef, 4229cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int64(nThePort)), 4230cdf0e10cSrcweir m_aAbsURIRef.getLength()); 4231cdf0e10cSrcweir } 4232cdf0e10cSrcweir else 4233cdf0e10cSrcweir { 4234cdf0e10cSrcweir setInvalid(); 4235cdf0e10cSrcweir return false; 4236cdf0e10cSrcweir } 4237cdf0e10cSrcweir } 4238cdf0e10cSrcweir } 4239cdf0e10cSrcweir else if (rTheHost.getLength() != 0 || nThePort != 0) 4240cdf0e10cSrcweir { 4241cdf0e10cSrcweir setInvalid(); 4242cdf0e10cSrcweir return false; 4243cdf0e10cSrcweir } 4244cdf0e10cSrcweir } 4245cdf0e10cSrcweir rtl::OUStringBuffer aSynPath; 4246cdf0e10cSrcweir sal_Unicode const * p = rThePath.getStr(); 4247cdf0e10cSrcweir sal_Unicode const * pEnd = p + rThePath.getLength(); 4248cdf0e10cSrcweir if (!parsePath(m_eScheme, &p, pEnd, false, eMechanism, eCharset, false, '/', 4249cdf0e10cSrcweir 0x80000000, 0x80000000, 0x80000000, aSynPath) 4250cdf0e10cSrcweir || p != pEnd) 4251cdf0e10cSrcweir { 4252cdf0e10cSrcweir setInvalid(); 4253cdf0e10cSrcweir return false; 4254cdf0e10cSrcweir } 4255cdf0e10cSrcweir m_aPath.set(m_aAbsURIRef, aSynPath.makeStringAndClear(), 4256cdf0e10cSrcweir m_aAbsURIRef.getLength()); 4257cdf0e10cSrcweir return true; 4258cdf0e10cSrcweir } 4259cdf0e10cSrcweir 4260cdf0e10cSrcweir //============================================================================ 4261cdf0e10cSrcweir // static 4262cdf0e10cSrcweir rtl::OUString INetURLObject::GetAbsURL(rtl::OUString const & rTheBaseURIRef, 4263cdf0e10cSrcweir rtl::OUString const & rTheRelURIRef, 4264cdf0e10cSrcweir bool bIgnoreFragment, 4265cdf0e10cSrcweir EncodeMechanism eEncodeMechanism, 4266cdf0e10cSrcweir DecodeMechanism eDecodeMechanism, 4267cdf0e10cSrcweir rtl_TextEncoding eCharset, 4268cdf0e10cSrcweir FSysStyle eStyle) 4269cdf0e10cSrcweir { 4270cdf0e10cSrcweir // Backwards compatibility: 4271cdf0e10cSrcweir if (rTheRelURIRef.getLength() == 0 || rTheRelURIRef[0] == '#') 4272cdf0e10cSrcweir return rTheRelURIRef; 4273cdf0e10cSrcweir 4274cdf0e10cSrcweir INetURLObject aTheAbsURIRef; 4275cdf0e10cSrcweir bool bWasAbsolute; 4276cdf0e10cSrcweir return INetURLObject(rTheBaseURIRef, eEncodeMechanism, eCharset). 4277cdf0e10cSrcweir convertRelToAbs(rTheRelURIRef, false, aTheAbsURIRef, 4278cdf0e10cSrcweir bWasAbsolute, eEncodeMechanism, 4279cdf0e10cSrcweir eCharset, bIgnoreFragment, false, 4280cdf0e10cSrcweir false, eStyle) 4281cdf0e10cSrcweir || eEncodeMechanism != WAS_ENCODED 4282cdf0e10cSrcweir || eDecodeMechanism != DECODE_TO_IURI 4283cdf0e10cSrcweir || eCharset != RTL_TEXTENCODING_UTF8 ? 4284cdf0e10cSrcweir aTheAbsURIRef.GetMainURL(eDecodeMechanism, eCharset) : 4285cdf0e10cSrcweir rTheRelURIRef; 4286cdf0e10cSrcweir } 4287cdf0e10cSrcweir 4288cdf0e10cSrcweir //============================================================================ 4289cdf0e10cSrcweir rtl::OUString INetURLObject::getExternalURL(DecodeMechanism eMechanism, 4290cdf0e10cSrcweir rtl_TextEncoding eCharset) const 4291cdf0e10cSrcweir { 4292cdf0e10cSrcweir rtl::OUString aTheExtURIRef; 4293cdf0e10cSrcweir translateToExternal( 4294cdf0e10cSrcweir rtl::OUString(m_aAbsURIRef), aTheExtURIRef, eMechanism, eCharset); 4295cdf0e10cSrcweir return aTheExtURIRef; 4296cdf0e10cSrcweir } 4297cdf0e10cSrcweir 4298cdf0e10cSrcweir //============================================================================ 4299cdf0e10cSrcweir // static 4300cdf0e10cSrcweir rtl::OUString INetURLObject::GetScheme(INetProtocol eTheScheme) 4301cdf0e10cSrcweir { 4302cdf0e10cSrcweir return rtl::OUString::createFromAscii(getSchemeInfo(eTheScheme).m_pPrefix); 4303cdf0e10cSrcweir } 4304cdf0e10cSrcweir 4305cdf0e10cSrcweir //============================================================================ 4306cdf0e10cSrcweir // static 4307cdf0e10cSrcweir INetProtocol INetURLObject::CompareProtocolScheme(rtl::OUString const & 4308cdf0e10cSrcweir rTheAbsURIRef) 4309cdf0e10cSrcweir { 4310cdf0e10cSrcweir sal_Unicode const * p = rTheAbsURIRef.getStr(); 4311cdf0e10cSrcweir PrefixInfo const * pPrefix = getPrefix(p, p + rTheAbsURIRef.getLength()); 4312cdf0e10cSrcweir return pPrefix ? pPrefix->m_eScheme : INET_PROT_NOT_VALID; 4313cdf0e10cSrcweir } 4314cdf0e10cSrcweir 4315cdf0e10cSrcweir //============================================================================ 4316cdf0e10cSrcweir bool INetURLObject::hasPassword() const 4317cdf0e10cSrcweir { 4318cdf0e10cSrcweir return m_aAuth.isPresent() && getSchemeInfo().m_bPassword; 4319cdf0e10cSrcweir } 4320cdf0e10cSrcweir 4321cdf0e10cSrcweir //============================================================================ 4322cdf0e10cSrcweir void INetURLObject::makeAuthCanonic() 4323cdf0e10cSrcweir { 4324cdf0e10cSrcweir if (m_eScheme == INET_PROT_IMAP && m_aAuth.getLength() == 1 4325cdf0e10cSrcweir && m_aAbsURIRef.charAt(m_aAuth.getBegin()) == '*') 4326cdf0e10cSrcweir { 4327cdf0e10cSrcweir lcl_Erase(m_aAbsURIRef, m_aAuth.getBegin() 4328cdf0e10cSrcweir - RTL_CONSTASCII_LENGTH(";AUTH="), 4329cdf0e10cSrcweir RTL_CONSTASCII_LENGTH(";AUTH=*")); 4330cdf0e10cSrcweir sal_Int32 nDelta = m_aAuth.clear() - RTL_CONSTASCII_LENGTH(";AUTH="); 4331cdf0e10cSrcweir m_aPath += nDelta; 4332cdf0e10cSrcweir m_aQuery += nDelta; 4333cdf0e10cSrcweir m_aFragment += nDelta; 4334cdf0e10cSrcweir } 4335cdf0e10cSrcweir } 4336cdf0e10cSrcweir 4337cdf0e10cSrcweir //============================================================================ 4338cdf0e10cSrcweir rtl::OUString INetURLObject::GetHostPort(DecodeMechanism eMechanism, 4339cdf0e10cSrcweir rtl_TextEncoding eCharset) 4340cdf0e10cSrcweir { 4341cdf0e10cSrcweir // Check because PROT_VND_SUN_STAR_HELP, PROT_VND_SUN_STAR_HIER, and 4342cdf0e10cSrcweir // PROT_VND_SUN_STAR_PKG misuse m_aHost: 4343cdf0e10cSrcweir if (!getSchemeInfo().m_bHost) 4344cdf0e10cSrcweir return rtl::OUString(); 4345cdf0e10cSrcweir rtl::OUStringBuffer aHostPort(decode(m_aHost, getEscapePrefix(), 4346cdf0e10cSrcweir eMechanism, eCharset)); 4347cdf0e10cSrcweir if (m_aPort.isPresent()) 4348cdf0e10cSrcweir { 4349cdf0e10cSrcweir aHostPort.append(sal_Unicode(':')); 4350cdf0e10cSrcweir aHostPort.append(decode(m_aPort, getEscapePrefix(), 4351cdf0e10cSrcweir eMechanism, eCharset)); 4352cdf0e10cSrcweir } 4353cdf0e10cSrcweir return aHostPort.makeStringAndClear(); 4354cdf0e10cSrcweir } 4355cdf0e10cSrcweir 4356cdf0e10cSrcweir //============================================================================ 4357cdf0e10cSrcweir sal_uInt32 INetURLObject::GetPort() const 4358cdf0e10cSrcweir { 4359cdf0e10cSrcweir if (m_aPort.isPresent()) 4360cdf0e10cSrcweir { 4361cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPort.getBegin(); 4362cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPort.getLength(); 4363cdf0e10cSrcweir sal_uInt32 nThePort; 4364cdf0e10cSrcweir if (INetMIME::scanUnsigned(p, pEnd, true, nThePort) && p == pEnd) 4365cdf0e10cSrcweir return nThePort; 4366cdf0e10cSrcweir } 4367cdf0e10cSrcweir return 0; 4368cdf0e10cSrcweir } 4369cdf0e10cSrcweir 4370cdf0e10cSrcweir //============================================================================ 4371cdf0e10cSrcweir bool INetURLObject::SetPort(sal_uInt32 nThePort) 4372cdf0e10cSrcweir { 4373cdf0e10cSrcweir if (getSchemeInfo().m_bPort && m_aHost.isPresent()) 4374cdf0e10cSrcweir { 4375cdf0e10cSrcweir rtl::OUString aNewPort(rtl::OUString::valueOf(sal_Int64(nThePort))); 4376cdf0e10cSrcweir sal_Int32 nDelta; 4377cdf0e10cSrcweir if (m_aPort.isPresent()) 4378cdf0e10cSrcweir nDelta = m_aPort.set(m_aAbsURIRef, aNewPort); 4379cdf0e10cSrcweir else 4380cdf0e10cSrcweir { 4381cdf0e10cSrcweir m_aAbsURIRef.insert(m_aHost.getEnd(), sal_Unicode(':')); 4382cdf0e10cSrcweir nDelta = m_aPort.set(m_aAbsURIRef, aNewPort, m_aHost.getEnd() + 1) 4383cdf0e10cSrcweir + 1; 4384cdf0e10cSrcweir } 4385cdf0e10cSrcweir m_aPath += nDelta; 4386cdf0e10cSrcweir m_aQuery += nDelta; 4387cdf0e10cSrcweir m_aFragment += nDelta; 4388cdf0e10cSrcweir return true; 4389cdf0e10cSrcweir } 4390cdf0e10cSrcweir return false; 4391cdf0e10cSrcweir } 4392cdf0e10cSrcweir 4393cdf0e10cSrcweir //============================================================================ 4394cdf0e10cSrcweir void INetURLObject::makePortCanonic() 4395cdf0e10cSrcweir { 4396cdf0e10cSrcweir if (m_aPort.isPresent()) 4397cdf0e10cSrcweir { 4398cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPort.getBegin(); 4399cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPort.getLength(); 4400cdf0e10cSrcweir sal_uInt32 nThePort; 4401cdf0e10cSrcweir if (INetMIME::scanUnsigned(p, pEnd, true, nThePort) && p == pEnd) 4402cdf0e10cSrcweir { 4403cdf0e10cSrcweir sal_Int32 nDelta; 4404cdf0e10cSrcweir if (nThePort != 0 && nThePort == getSchemeInfo().m_nDefaultPort) 4405cdf0e10cSrcweir { 4406cdf0e10cSrcweir lcl_Erase(m_aAbsURIRef, m_aPort.getBegin() - 1, 4407cdf0e10cSrcweir m_aPort.getLength() + 1); 4408cdf0e10cSrcweir nDelta = m_aPort.clear() - 1; 4409cdf0e10cSrcweir } 4410cdf0e10cSrcweir else 4411cdf0e10cSrcweir nDelta = m_aPort.set(m_aAbsURIRef, 4412cdf0e10cSrcweir rtl::OUString::valueOf(sal_Int64(nThePort))); 4413cdf0e10cSrcweir m_aPath += nDelta; 4414cdf0e10cSrcweir m_aQuery += nDelta; 4415cdf0e10cSrcweir m_aFragment += nDelta; 4416cdf0e10cSrcweir } 4417cdf0e10cSrcweir } 4418cdf0e10cSrcweir } 4419cdf0e10cSrcweir 4420cdf0e10cSrcweir //============================================================================ 4421cdf0e10cSrcweir sal_Int32 INetURLObject::getSegmentCount(bool bIgnoreFinalSlash) const 4422cdf0e10cSrcweir { 4423cdf0e10cSrcweir if (!checkHierarchical()) 4424cdf0e10cSrcweir return 0; 4425cdf0e10cSrcweir 4426cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4427cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPath.getLength(); 4428cdf0e10cSrcweir if (bIgnoreFinalSlash && pEnd > p && pEnd[-1] == '/') 4429cdf0e10cSrcweir --pEnd; 4430cdf0e10cSrcweir sal_Int32 n = p == pEnd || *p == '/' ? 0 : 1; 4431cdf0e10cSrcweir while (p != pEnd) 4432cdf0e10cSrcweir if (*p++ == '/') 4433cdf0e10cSrcweir ++n; 4434cdf0e10cSrcweir return n; 4435cdf0e10cSrcweir } 4436cdf0e10cSrcweir 4437cdf0e10cSrcweir //============================================================================ 4438cdf0e10cSrcweir bool INetURLObject::removeSegment(sal_Int32 nIndex, bool bIgnoreFinalSlash) 4439cdf0e10cSrcweir { 4440cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4441cdf0e10cSrcweir if (!aSegment.isPresent()) 4442cdf0e10cSrcweir return false; 4443cdf0e10cSrcweir 4444cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4445cdf0e10cSrcweir aNewPath.append(m_aAbsURIRef.getStr() + m_aPath.getBegin(), 4446cdf0e10cSrcweir aSegment.getBegin() - m_aPath.getBegin()); 4447cdf0e10cSrcweir if (bIgnoreFinalSlash && aSegment.getEnd() == m_aPath.getEnd()) 4448cdf0e10cSrcweir aNewPath.append(sal_Unicode('/')); 4449cdf0e10cSrcweir else 4450cdf0e10cSrcweir aNewPath.append(m_aAbsURIRef.getStr() + aSegment.getEnd(), 4451cdf0e10cSrcweir m_aPath.getEnd() - aSegment.getEnd()); 4452cdf0e10cSrcweir if (aNewPath.getLength() == 0 && !aSegment.isEmpty() && 4453cdf0e10cSrcweir m_aAbsURIRef[aSegment.getBegin()] == '/') 4454cdf0e10cSrcweir { 4455cdf0e10cSrcweir aNewPath.append(sal_Unicode('/')); 4456cdf0e10cSrcweir } 4457cdf0e10cSrcweir 4458cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4459cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4460cdf0e10cSrcweir } 4461cdf0e10cSrcweir 4462cdf0e10cSrcweir //============================================================================ 4463cdf0e10cSrcweir rtl::OUString INetURLObject::getName(sal_Int32 nIndex, bool bIgnoreFinalSlash, 4464cdf0e10cSrcweir DecodeMechanism eMechanism, 4465cdf0e10cSrcweir rtl_TextEncoding eCharset) const 4466cdf0e10cSrcweir { 4467cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4468cdf0e10cSrcweir if (!aSegment.isPresent()) 4469cdf0e10cSrcweir return rtl::OUString(); 4470cdf0e10cSrcweir 4471cdf0e10cSrcweir sal_Unicode const * pSegBegin 4472cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4473cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4474cdf0e10cSrcweir 4475cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4476cdf0e10cSrcweir ++pSegBegin; 4477cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4478cdf0e10cSrcweir while (p != pSegEnd && *p != ';') 4479cdf0e10cSrcweir ++p; 4480cdf0e10cSrcweir 4481cdf0e10cSrcweir return decode(pSegBegin, p, getEscapePrefix(), eMechanism, eCharset); 4482cdf0e10cSrcweir } 4483cdf0e10cSrcweir 4484cdf0e10cSrcweir //============================================================================ 4485cdf0e10cSrcweir bool INetURLObject::setName(rtl::OUString const & rTheName, sal_Int32 nIndex, 4486cdf0e10cSrcweir bool bIgnoreFinalSlash, 4487cdf0e10cSrcweir EncodeMechanism eMechanism, 4488cdf0e10cSrcweir rtl_TextEncoding eCharset) 4489cdf0e10cSrcweir { 4490cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4491cdf0e10cSrcweir if (!aSegment.isPresent()) 4492cdf0e10cSrcweir return false; 4493cdf0e10cSrcweir 4494cdf0e10cSrcweir sal_Unicode const * pPathBegin 4495cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4496cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4497cdf0e10cSrcweir sal_Unicode const * pSegBegin 4498cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4499cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4500cdf0e10cSrcweir 4501cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4502cdf0e10cSrcweir ++pSegBegin; 4503cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4504cdf0e10cSrcweir while (p != pSegEnd && *p != ';') 4505cdf0e10cSrcweir ++p; 4506cdf0e10cSrcweir 4507cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4508cdf0e10cSrcweir aNewPath.append(pPathBegin, pSegBegin - pPathBegin); 4509cdf0e10cSrcweir aNewPath.append(encodeText(rTheName, false, PART_PCHAR, getEscapePrefix(), 4510cdf0e10cSrcweir eMechanism, eCharset, true)); 4511cdf0e10cSrcweir aNewPath.append(p, pPathEnd - p); 4512cdf0e10cSrcweir 4513cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4514cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4515cdf0e10cSrcweir } 4516cdf0e10cSrcweir 4517cdf0e10cSrcweir //============================================================================ 4518cdf0e10cSrcweir bool INetURLObject::hasExtension(sal_Int32 nIndex, bool bIgnoreFinalSlash) 4519cdf0e10cSrcweir const 4520cdf0e10cSrcweir { 4521cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4522cdf0e10cSrcweir if (!aSegment.isPresent()) 4523cdf0e10cSrcweir return false; 4524cdf0e10cSrcweir 4525cdf0e10cSrcweir sal_Unicode const * pSegBegin 4526cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4527cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4528cdf0e10cSrcweir 4529cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4530cdf0e10cSrcweir ++pSegBegin; 4531cdf0e10cSrcweir for (sal_Unicode const * p = pSegBegin; p != pSegEnd && *p != ';'; ++p) 4532cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4533cdf0e10cSrcweir return true; 4534cdf0e10cSrcweir return false; 4535cdf0e10cSrcweir } 4536cdf0e10cSrcweir 4537cdf0e10cSrcweir //============================================================================ 4538cdf0e10cSrcweir rtl::OUString INetURLObject::getBase(sal_Int32 nIndex, bool bIgnoreFinalSlash, 4539cdf0e10cSrcweir DecodeMechanism eMechanism, 4540cdf0e10cSrcweir rtl_TextEncoding eCharset) const 4541cdf0e10cSrcweir { 4542cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4543cdf0e10cSrcweir if (!aSegment.isPresent()) 4544cdf0e10cSrcweir return rtl::OUString(); 4545cdf0e10cSrcweir 4546cdf0e10cSrcweir sal_Unicode const * pSegBegin 4547cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4548cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4549cdf0e10cSrcweir 4550cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4551cdf0e10cSrcweir ++pSegBegin; 4552cdf0e10cSrcweir sal_Unicode const * pExtension = 0; 4553cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4554cdf0e10cSrcweir for (; p != pSegEnd && *p != ';'; ++p) 4555cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4556cdf0e10cSrcweir pExtension = p; 4557cdf0e10cSrcweir if (!pExtension) 4558cdf0e10cSrcweir pExtension = p; 4559cdf0e10cSrcweir 4560cdf0e10cSrcweir return decode(pSegBegin, pExtension, getEscapePrefix(), eMechanism, 4561cdf0e10cSrcweir eCharset); 4562cdf0e10cSrcweir } 4563cdf0e10cSrcweir 4564cdf0e10cSrcweir //============================================================================ 4565cdf0e10cSrcweir bool INetURLObject::setBase(rtl::OUString const & rTheBase, sal_Int32 nIndex, 4566cdf0e10cSrcweir bool bIgnoreFinalSlash, 4567cdf0e10cSrcweir EncodeMechanism eMechanism, 4568cdf0e10cSrcweir rtl_TextEncoding eCharset) 4569cdf0e10cSrcweir { 4570cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4571cdf0e10cSrcweir if (!aSegment.isPresent()) 4572cdf0e10cSrcweir return false; 4573cdf0e10cSrcweir 4574cdf0e10cSrcweir sal_Unicode const * pPathBegin 4575cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4576cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4577cdf0e10cSrcweir sal_Unicode const * pSegBegin 4578cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4579cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4580cdf0e10cSrcweir 4581cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4582cdf0e10cSrcweir ++pSegBegin; 4583cdf0e10cSrcweir sal_Unicode const * pExtension = 0; 4584cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4585cdf0e10cSrcweir for (; p != pSegEnd && *p != ';'; ++p) 4586cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4587cdf0e10cSrcweir pExtension = p; 4588cdf0e10cSrcweir if (!pExtension) 4589cdf0e10cSrcweir pExtension = p; 4590cdf0e10cSrcweir 4591cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4592cdf0e10cSrcweir aNewPath.append(pPathBegin, pSegBegin - pPathBegin); 4593cdf0e10cSrcweir aNewPath.append(encodeText(rTheBase, false, PART_PCHAR, getEscapePrefix(), 4594cdf0e10cSrcweir eMechanism, eCharset, true)); 4595cdf0e10cSrcweir aNewPath.append(pExtension, pPathEnd - pExtension); 4596cdf0e10cSrcweir 4597cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4598cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4599cdf0e10cSrcweir } 4600cdf0e10cSrcweir 4601cdf0e10cSrcweir //============================================================================ 4602cdf0e10cSrcweir rtl::OUString INetURLObject::getExtension(sal_Int32 nIndex, 4603cdf0e10cSrcweir bool bIgnoreFinalSlash, 4604cdf0e10cSrcweir DecodeMechanism eMechanism, 4605cdf0e10cSrcweir rtl_TextEncoding eCharset) const 4606cdf0e10cSrcweir { 4607cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4608cdf0e10cSrcweir if (!aSegment.isPresent()) 4609cdf0e10cSrcweir return rtl::OUString(); 4610cdf0e10cSrcweir 4611cdf0e10cSrcweir sal_Unicode const * pSegBegin 4612cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4613cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4614cdf0e10cSrcweir 4615cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4616cdf0e10cSrcweir ++pSegBegin; 4617cdf0e10cSrcweir sal_Unicode const * pExtension = 0; 4618cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4619cdf0e10cSrcweir for (; p != pSegEnd && *p != ';'; ++p) 4620cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4621cdf0e10cSrcweir pExtension = p; 4622cdf0e10cSrcweir 4623cdf0e10cSrcweir if (!pExtension) 4624cdf0e10cSrcweir return rtl::OUString(); 4625cdf0e10cSrcweir 4626cdf0e10cSrcweir return decode(pExtension + 1, p, getEscapePrefix(), eMechanism, eCharset); 4627cdf0e10cSrcweir } 4628cdf0e10cSrcweir 4629cdf0e10cSrcweir //============================================================================ 4630cdf0e10cSrcweir bool INetURLObject::setExtension(rtl::OUString const & rTheExtension, 4631cdf0e10cSrcweir sal_Int32 nIndex, bool bIgnoreFinalSlash, 4632cdf0e10cSrcweir EncodeMechanism eMechanism, 4633cdf0e10cSrcweir rtl_TextEncoding eCharset) 4634cdf0e10cSrcweir { 4635cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4636cdf0e10cSrcweir if (!aSegment.isPresent()) 4637cdf0e10cSrcweir return false; 4638cdf0e10cSrcweir 4639cdf0e10cSrcweir sal_Unicode const * pPathBegin 4640cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4641cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4642cdf0e10cSrcweir sal_Unicode const * pSegBegin 4643cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4644cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4645cdf0e10cSrcweir 4646cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4647cdf0e10cSrcweir ++pSegBegin; 4648cdf0e10cSrcweir sal_Unicode const * pExtension = 0; 4649cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4650cdf0e10cSrcweir for (; p != pSegEnd && *p != ';'; ++p) 4651cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4652cdf0e10cSrcweir pExtension = p; 4653cdf0e10cSrcweir if (!pExtension) 4654cdf0e10cSrcweir pExtension = p; 4655cdf0e10cSrcweir 4656cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4657cdf0e10cSrcweir aNewPath.append(pPathBegin, pExtension - pPathBegin); 4658cdf0e10cSrcweir aNewPath.append(sal_Unicode('.')); 4659cdf0e10cSrcweir aNewPath.append(encodeText(rTheExtension, false, PART_PCHAR, 4660cdf0e10cSrcweir getEscapePrefix(), eMechanism, eCharset, true)); 4661cdf0e10cSrcweir aNewPath.append(p, pPathEnd - p); 4662cdf0e10cSrcweir 4663cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4664cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4665cdf0e10cSrcweir } 4666cdf0e10cSrcweir 4667cdf0e10cSrcweir //============================================================================ 4668cdf0e10cSrcweir bool INetURLObject::removeExtension(sal_Int32 nIndex, bool bIgnoreFinalSlash) 4669cdf0e10cSrcweir { 4670cdf0e10cSrcweir SubString aSegment(getSegment(nIndex, bIgnoreFinalSlash)); 4671cdf0e10cSrcweir if (!aSegment.isPresent()) 4672cdf0e10cSrcweir return false; 4673cdf0e10cSrcweir 4674cdf0e10cSrcweir sal_Unicode const * pPathBegin 4675cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4676cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4677cdf0e10cSrcweir sal_Unicode const * pSegBegin 4678cdf0e10cSrcweir = m_aAbsURIRef.getStr() + aSegment.getBegin(); 4679cdf0e10cSrcweir sal_Unicode const * pSegEnd = pSegBegin + aSegment.getLength(); 4680cdf0e10cSrcweir 4681cdf0e10cSrcweir if (pSegBegin < pSegEnd && *pSegBegin == '/') 4682cdf0e10cSrcweir ++pSegBegin; 4683cdf0e10cSrcweir sal_Unicode const * pExtension = 0; 4684cdf0e10cSrcweir sal_Unicode const * p = pSegBegin; 4685cdf0e10cSrcweir for (; p != pSegEnd && *p != ';'; ++p) 4686cdf0e10cSrcweir if (*p == '.' && p != pSegBegin) 4687cdf0e10cSrcweir pExtension = p; 4688cdf0e10cSrcweir if (!pExtension) 4689cdf0e10cSrcweir return true; 4690cdf0e10cSrcweir 4691cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4692cdf0e10cSrcweir aNewPath.append(pPathBegin, pExtension - pPathBegin); 4693cdf0e10cSrcweir aNewPath.append(p, pPathEnd - p); 4694cdf0e10cSrcweir 4695cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4696cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4697cdf0e10cSrcweir } 4698cdf0e10cSrcweir 4699cdf0e10cSrcweir //============================================================================ 4700cdf0e10cSrcweir bool INetURLObject::hasFinalSlash() const 4701cdf0e10cSrcweir { 4702cdf0e10cSrcweir if (!checkHierarchical()) 4703cdf0e10cSrcweir return false; 4704cdf0e10cSrcweir 4705cdf0e10cSrcweir sal_Unicode const * pPathBegin 4706cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4707cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4708cdf0e10cSrcweir return pPathEnd > pPathBegin && pPathEnd[-1] == '/'; 4709cdf0e10cSrcweir } 4710cdf0e10cSrcweir 4711cdf0e10cSrcweir //============================================================================ 4712cdf0e10cSrcweir bool INetURLObject::setFinalSlash() 4713cdf0e10cSrcweir { 4714cdf0e10cSrcweir if (!checkHierarchical()) 4715cdf0e10cSrcweir return false; 4716cdf0e10cSrcweir 4717cdf0e10cSrcweir sal_Unicode const * pPathBegin 4718cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4719cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4720cdf0e10cSrcweir if (pPathEnd > pPathBegin && pPathEnd[-1] == '/') 4721cdf0e10cSrcweir return true; 4722cdf0e10cSrcweir 4723cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 4724cdf0e10cSrcweir aNewPath.append(pPathBegin, pPathEnd - pPathBegin); 4725cdf0e10cSrcweir aNewPath.append(sal_Unicode('/')); 4726cdf0e10cSrcweir 4727cdf0e10cSrcweir return setPath(aNewPath.makeStringAndClear(), false, NOT_CANONIC, 4728cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4729cdf0e10cSrcweir } 4730cdf0e10cSrcweir 4731cdf0e10cSrcweir //============================================================================ 4732cdf0e10cSrcweir bool INetURLObject::removeFinalSlash() 4733cdf0e10cSrcweir { 4734cdf0e10cSrcweir if (!checkHierarchical()) 4735cdf0e10cSrcweir return false; 4736cdf0e10cSrcweir 4737cdf0e10cSrcweir sal_Unicode const * pPathBegin 4738cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 4739cdf0e10cSrcweir sal_Unicode const * pPathEnd = pPathBegin + m_aPath.getLength(); 4740cdf0e10cSrcweir if (pPathEnd <= pPathBegin || pPathEnd[-1] != '/') 4741cdf0e10cSrcweir return true; 4742cdf0e10cSrcweir 4743cdf0e10cSrcweir --pPathEnd; 4744cdf0e10cSrcweir if (pPathEnd == pPathBegin && *pPathBegin == '/') 4745cdf0e10cSrcweir return false; 4746cdf0e10cSrcweir rtl::OUString aNewPath(pPathBegin, pPathEnd - pPathBegin); 4747cdf0e10cSrcweir 4748cdf0e10cSrcweir return setPath(aNewPath, false, NOT_CANONIC, RTL_TEXTENCODING_UTF8); 4749cdf0e10cSrcweir } 4750cdf0e10cSrcweir 4751cdf0e10cSrcweir //============================================================================ 4752cdf0e10cSrcweir // static 4753cdf0e10cSrcweir rtl::OUString INetURLObject::createFragment(rtl::OUString const & rText) 4754cdf0e10cSrcweir { 4755cdf0e10cSrcweir rtl::OUString aFragment(rText); 4756cdf0e10cSrcweir for (sal_Int32 i = 0; i < aFragment.getLength();) 4757cdf0e10cSrcweir { 4758cdf0e10cSrcweir sal_Unicode c = aFragment.getStr()[i]; 4759cdf0e10cSrcweir if (mustEncode(c, PART_CREATEFRAGMENT)) 4760cdf0e10cSrcweir aFragment = aFragment.replaceAt(i, 1, rtl::OUString()); 4761cdf0e10cSrcweir else 4762cdf0e10cSrcweir ++i; 4763cdf0e10cSrcweir } 4764cdf0e10cSrcweir return aFragment; 4765cdf0e10cSrcweir } 4766cdf0e10cSrcweir 4767cdf0e10cSrcweir //============================================================================ 4768cdf0e10cSrcweir bool INetURLObject::setFSysPath(rtl::OUString const & rFSysPath, 4769cdf0e10cSrcweir FSysStyle eStyle) 4770cdf0e10cSrcweir { 4771cdf0e10cSrcweir sal_Unicode const * pFSysBegin = rFSysPath.getStr(); 4772cdf0e10cSrcweir sal_Unicode const * pFSysEnd = pFSysBegin + rFSysPath.getLength(); 4773cdf0e10cSrcweir 4774cdf0e10cSrcweir switch ((eStyle & FSYS_VOS ? 1 : 0) 4775cdf0e10cSrcweir + (eStyle & FSYS_UNX ? 1 : 0) 4776cdf0e10cSrcweir + (eStyle & FSYS_DOS ? 1 : 0) 4777cdf0e10cSrcweir + (eStyle & FSYS_MAC ? 1 : 0)) 4778cdf0e10cSrcweir { 4779cdf0e10cSrcweir case 0: 4780cdf0e10cSrcweir return false; 4781cdf0e10cSrcweir 4782cdf0e10cSrcweir case 1: 4783cdf0e10cSrcweir break; 4784cdf0e10cSrcweir 4785cdf0e10cSrcweir default: 4786cdf0e10cSrcweir if (eStyle & FSYS_VOS 4787cdf0e10cSrcweir && pFSysEnd - pFSysBegin >= 2 4788cdf0e10cSrcweir && pFSysBegin[0] == '/' 4789cdf0e10cSrcweir && pFSysBegin[1] == '/') 4790cdf0e10cSrcweir { 4791cdf0e10cSrcweir if (pFSysEnd - pFSysBegin >= 3 4792cdf0e10cSrcweir && pFSysBegin[2] == '.' 4793cdf0e10cSrcweir && (pFSysEnd - pFSysBegin == 3 || pFSysBegin[3] == '/')) 4794cdf0e10cSrcweir { 4795cdf0e10cSrcweir eStyle = FSYS_VOS; // Production T1 4796cdf0e10cSrcweir break; 4797cdf0e10cSrcweir } 4798cdf0e10cSrcweir 4799cdf0e10cSrcweir sal_Unicode const * p = pFSysBegin + 2; 4800cdf0e10cSrcweir rtl::OUString aHost; 4801cdf0e10cSrcweir if (parseHost(p, pFSysEnd, aHost) 4802cdf0e10cSrcweir && (p == pFSysEnd || *p == '/')) 4803cdf0e10cSrcweir { 4804cdf0e10cSrcweir eStyle = FSYS_VOS; // Production T2 4805cdf0e10cSrcweir break; 4806cdf0e10cSrcweir } 4807cdf0e10cSrcweir } 4808cdf0e10cSrcweir 4809cdf0e10cSrcweir if (eStyle & FSYS_DOS 4810cdf0e10cSrcweir && pFSysEnd - pFSysBegin >= 2 4811cdf0e10cSrcweir && pFSysBegin[0] == '\\' 4812cdf0e10cSrcweir && pFSysBegin[1] == '\\') 4813cdf0e10cSrcweir { 4814cdf0e10cSrcweir sal_Unicode const * p = pFSysBegin + 2; 4815cdf0e10cSrcweir rtl::OUString aHost; 4816cdf0e10cSrcweir if (parseHost(p, pFSysEnd, aHost) 4817cdf0e10cSrcweir && (p == pFSysEnd || *p == '\\')) 4818cdf0e10cSrcweir { 4819cdf0e10cSrcweir eStyle = FSYS_DOS; // Production T3 4820cdf0e10cSrcweir break; 4821cdf0e10cSrcweir } 4822cdf0e10cSrcweir } 4823cdf0e10cSrcweir 4824cdf0e10cSrcweir if (eStyle & FSYS_DOS 4825cdf0e10cSrcweir && pFSysEnd - pFSysBegin >= 2 4826cdf0e10cSrcweir && INetMIME::isAlpha(pFSysBegin[0]) 4827cdf0e10cSrcweir && pFSysBegin[1] == ':' 4828cdf0e10cSrcweir && (pFSysEnd - pFSysBegin == 2 4829cdf0e10cSrcweir || pFSysBegin[2] == '/' 4830cdf0e10cSrcweir || pFSysBegin[2] == '\\')) 4831cdf0e10cSrcweir { 4832cdf0e10cSrcweir eStyle = FSYS_DOS; // Productions T4, T5 4833cdf0e10cSrcweir break; 4834cdf0e10cSrcweir } 4835cdf0e10cSrcweir 4836cdf0e10cSrcweir if (!(eStyle & (FSYS_UNX | FSYS_DOS | FSYS_MAC))) 4837cdf0e10cSrcweir return false; 4838cdf0e10cSrcweir 4839cdf0e10cSrcweir eStyle = guessFSysStyleByCounting(pFSysBegin, pFSysEnd, eStyle); 4840cdf0e10cSrcweir // Production T6 4841cdf0e10cSrcweir break; 4842cdf0e10cSrcweir } 4843cdf0e10cSrcweir 4844cdf0e10cSrcweir rtl::OUStringBuffer aSynAbsURIRef(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file://"))); 4845cdf0e10cSrcweir 4846cdf0e10cSrcweir switch (eStyle) 4847cdf0e10cSrcweir { 4848cdf0e10cSrcweir case FSYS_VOS: 4849cdf0e10cSrcweir { 4850cdf0e10cSrcweir sal_Unicode const * p = pFSysBegin; 4851cdf0e10cSrcweir if (pFSysEnd - p < 2 || *p++ != '/' || *p++ != '/') 4852cdf0e10cSrcweir return false; 4853cdf0e10cSrcweir if (p != pFSysEnd && *p == '.' 4854cdf0e10cSrcweir && (pFSysEnd - p == 1 || p[1] == '/')) 4855cdf0e10cSrcweir ++p; 4856cdf0e10cSrcweir for (; p != pFSysEnd; ++p) 4857cdf0e10cSrcweir switch (*p) 4858cdf0e10cSrcweir { 4859cdf0e10cSrcweir case '#': 4860cdf0e10cSrcweir case '%': 4861cdf0e10cSrcweir appendEscape(aSynAbsURIRef, '%', *p); 4862cdf0e10cSrcweir break; 4863cdf0e10cSrcweir 4864cdf0e10cSrcweir default: 4865cdf0e10cSrcweir aSynAbsURIRef.append(*p); 4866cdf0e10cSrcweir break; 4867cdf0e10cSrcweir } 4868cdf0e10cSrcweir break; 4869cdf0e10cSrcweir } 4870cdf0e10cSrcweir 4871cdf0e10cSrcweir case FSYS_UNX: 4872cdf0e10cSrcweir { 4873cdf0e10cSrcweir sal_Unicode const * p = pFSysBegin; 4874cdf0e10cSrcweir if (p != pFSysEnd && *p != '/') 4875cdf0e10cSrcweir return false; 4876cdf0e10cSrcweir for (; p != pFSysEnd; ++p) 4877cdf0e10cSrcweir switch (*p) 4878cdf0e10cSrcweir { 4879cdf0e10cSrcweir case '|': 4880cdf0e10cSrcweir case '#': 4881cdf0e10cSrcweir case '%': 4882cdf0e10cSrcweir appendEscape(aSynAbsURIRef, '%', *p); 4883cdf0e10cSrcweir break; 4884cdf0e10cSrcweir 4885cdf0e10cSrcweir default: 4886cdf0e10cSrcweir aSynAbsURIRef.append(*p); 4887cdf0e10cSrcweir break; 4888cdf0e10cSrcweir } 4889cdf0e10cSrcweir break; 4890cdf0e10cSrcweir } 4891cdf0e10cSrcweir 4892cdf0e10cSrcweir case FSYS_DOS: 4893cdf0e10cSrcweir { 4894cdf0e10cSrcweir sal_uInt32 nAltDelimiter = 0x80000000; 4895cdf0e10cSrcweir sal_Unicode const * p = pFSysBegin; 4896cdf0e10cSrcweir if (pFSysEnd - p >= 3 && p[0] == '\\' && p[1] == '\\') 4897cdf0e10cSrcweir p += 2; 4898cdf0e10cSrcweir else 4899cdf0e10cSrcweir { 4900cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 4901cdf0e10cSrcweir if (pFSysEnd - p >= 2 4902cdf0e10cSrcweir && INetMIME::isAlpha(p[0]) 4903cdf0e10cSrcweir && p[1] == ':' 4904cdf0e10cSrcweir && (pFSysEnd - p == 2 || p[2] == '\\' || p[2] == '/')) 4905cdf0e10cSrcweir nAltDelimiter = '/'; 4906cdf0e10cSrcweir } 4907cdf0e10cSrcweir for (; p != pFSysEnd; ++p) 4908cdf0e10cSrcweir if (*p == '\\' || *p == nAltDelimiter) 4909cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 4910cdf0e10cSrcweir else 4911cdf0e10cSrcweir switch (*p) 4912cdf0e10cSrcweir { 4913cdf0e10cSrcweir case '/': 4914cdf0e10cSrcweir case '#': 4915cdf0e10cSrcweir case '%': 4916cdf0e10cSrcweir appendEscape(aSynAbsURIRef, '%', *p); 4917cdf0e10cSrcweir break; 4918cdf0e10cSrcweir 4919cdf0e10cSrcweir default: 4920cdf0e10cSrcweir aSynAbsURIRef.append(*p); 4921cdf0e10cSrcweir break; 4922cdf0e10cSrcweir } 4923cdf0e10cSrcweir break; 4924cdf0e10cSrcweir } 4925cdf0e10cSrcweir 4926cdf0e10cSrcweir case FSYS_MAC: 4927cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 4928cdf0e10cSrcweir {for (sal_Unicode const * p = pFSysBegin; p != pFSysEnd; ++p) 4929cdf0e10cSrcweir switch (*p) 4930cdf0e10cSrcweir { 4931cdf0e10cSrcweir case ':': 4932cdf0e10cSrcweir aSynAbsURIRef.append(sal_Unicode('/')); 4933cdf0e10cSrcweir break; 4934cdf0e10cSrcweir 4935cdf0e10cSrcweir case '/': 4936cdf0e10cSrcweir case '|': 4937cdf0e10cSrcweir case '#': 4938cdf0e10cSrcweir case '%': 4939cdf0e10cSrcweir appendEscape(aSynAbsURIRef, '%', *p); 4940cdf0e10cSrcweir break; 4941cdf0e10cSrcweir 4942cdf0e10cSrcweir default: 4943cdf0e10cSrcweir aSynAbsURIRef.append(*p); 4944cdf0e10cSrcweir break; 4945cdf0e10cSrcweir } 4946cdf0e10cSrcweir } 4947cdf0e10cSrcweir break; 4948cdf0e10cSrcweir 4949cdf0e10cSrcweir default: 4950cdf0e10cSrcweir OSL_ASSERT(false); 4951cdf0e10cSrcweir break; 4952cdf0e10cSrcweir } 4953cdf0e10cSrcweir 4954cdf0e10cSrcweir INetURLObject aTemp(aSynAbsURIRef.makeStringAndClear(), WAS_ENCODED, 4955cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 4956cdf0e10cSrcweir if (aTemp.HasError()) 4957cdf0e10cSrcweir return false; 4958cdf0e10cSrcweir 4959cdf0e10cSrcweir *this = aTemp; 4960cdf0e10cSrcweir return true; 4961cdf0e10cSrcweir } 4962cdf0e10cSrcweir 4963cdf0e10cSrcweir //============================================================================ 4964cdf0e10cSrcweir rtl::OUString INetURLObject::getFSysPath(FSysStyle eStyle, 4965cdf0e10cSrcweir sal_Unicode * pDelimiter) const 4966cdf0e10cSrcweir { 4967cdf0e10cSrcweir if (m_eScheme != INET_PROT_FILE) 4968cdf0e10cSrcweir return rtl::OUString(); 4969cdf0e10cSrcweir 4970cdf0e10cSrcweir if ((eStyle & FSYS_VOS ? 1 : 0) 4971cdf0e10cSrcweir + (eStyle & FSYS_UNX ? 1 : 0) 4972cdf0e10cSrcweir + (eStyle & FSYS_DOS ? 1 : 0) 4973cdf0e10cSrcweir + (eStyle & FSYS_MAC ? 1 : 0) 4974cdf0e10cSrcweir > 1) 4975cdf0e10cSrcweir { 4976cdf0e10cSrcweir eStyle = eStyle & FSYS_VOS 4977cdf0e10cSrcweir && m_aHost.isPresent() 4978cdf0e10cSrcweir && m_aHost.getLength() > 0 ? 4979cdf0e10cSrcweir FSYS_VOS : 4980cdf0e10cSrcweir hasDosVolume(eStyle) 4981cdf0e10cSrcweir || ((eStyle & FSYS_DOS) != 0 4982cdf0e10cSrcweir && m_aHost.isPresent() 4983cdf0e10cSrcweir && m_aHost.getLength() > 0) ? 4984cdf0e10cSrcweir FSYS_DOS : 4985cdf0e10cSrcweir eStyle & FSYS_UNX 4986cdf0e10cSrcweir && (!m_aHost.isPresent() || m_aHost.getLength() == 0) ? 4987cdf0e10cSrcweir FSYS_UNX : 4988cdf0e10cSrcweir FSysStyle(0); 4989cdf0e10cSrcweir } 4990cdf0e10cSrcweir 4991cdf0e10cSrcweir switch (eStyle) 4992cdf0e10cSrcweir { 4993cdf0e10cSrcweir case FSYS_VOS: 4994cdf0e10cSrcweir { 4995cdf0e10cSrcweir if (pDelimiter) 4996cdf0e10cSrcweir *pDelimiter = '/'; 4997cdf0e10cSrcweir 4998cdf0e10cSrcweir rtl::OUStringBuffer aSynFSysPath; 4999cdf0e10cSrcweir aSynFSysPath.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); 5000cdf0e10cSrcweir if (m_aHost.isPresent() && m_aHost.getLength() > 0) 5001cdf0e10cSrcweir aSynFSysPath.append(decode(m_aHost, '%', DECODE_WITH_CHARSET, 5002cdf0e10cSrcweir RTL_TEXTENCODING_UTF8)); 5003cdf0e10cSrcweir else 5004cdf0e10cSrcweir aSynFSysPath.append(sal_Unicode('.')); 5005cdf0e10cSrcweir aSynFSysPath.append(decode(m_aPath, '%', DECODE_WITH_CHARSET, 5006cdf0e10cSrcweir RTL_TEXTENCODING_UTF8)); 5007cdf0e10cSrcweir return aSynFSysPath.makeStringAndClear(); 5008cdf0e10cSrcweir } 5009cdf0e10cSrcweir 5010cdf0e10cSrcweir case FSYS_UNX: 5011cdf0e10cSrcweir { 5012cdf0e10cSrcweir if (m_aHost.isPresent() && m_aHost.getLength() > 0) 5013cdf0e10cSrcweir return rtl::OUString(); 5014cdf0e10cSrcweir 5015cdf0e10cSrcweir if (pDelimiter) 5016cdf0e10cSrcweir *pDelimiter = '/'; 5017cdf0e10cSrcweir 5018cdf0e10cSrcweir return decode(m_aPath, '%', DECODE_WITH_CHARSET, 5019cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 5020cdf0e10cSrcweir } 5021cdf0e10cSrcweir 5022cdf0e10cSrcweir case FSYS_DOS: 5023cdf0e10cSrcweir { 5024cdf0e10cSrcweir if (pDelimiter) 5025cdf0e10cSrcweir *pDelimiter = '\\'; 5026cdf0e10cSrcweir 5027cdf0e10cSrcweir rtl::OUStringBuffer aSynFSysPath; 5028cdf0e10cSrcweir if (m_aHost.isPresent() && m_aHost.getLength() > 0) 5029cdf0e10cSrcweir { 5030cdf0e10cSrcweir aSynFSysPath.appendAscii(RTL_CONSTASCII_STRINGPARAM("\\\\")); 5031cdf0e10cSrcweir aSynFSysPath.append(decode(m_aHost, '%', DECODE_WITH_CHARSET, 5032cdf0e10cSrcweir RTL_TEXTENCODING_UTF8)); 5033cdf0e10cSrcweir aSynFSysPath.append(sal_Unicode('\\')); 5034cdf0e10cSrcweir } 5035cdf0e10cSrcweir sal_Unicode const * p 5036cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 5037cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPath.getLength(); 5038cdf0e10cSrcweir DBG_ASSERT(p < pEnd && *p == '/', 5039cdf0e10cSrcweir "INetURLObject::getFSysPath(): Bad path"); 5040cdf0e10cSrcweir ++p; 5041cdf0e10cSrcweir while (p < pEnd) 5042cdf0e10cSrcweir { 5043cdf0e10cSrcweir EscapeType eEscapeType; 5044cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(p, pEnd, false, '%', WAS_ENCODED, 5045cdf0e10cSrcweir RTL_TEXTENCODING_UTF8, 5046cdf0e10cSrcweir eEscapeType); 5047cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO && nUTF32 == '/') 5048cdf0e10cSrcweir aSynFSysPath.append(sal_Unicode('\\')); 5049cdf0e10cSrcweir else 5050cdf0e10cSrcweir aSynFSysPath.appendUtf32(nUTF32); 5051cdf0e10cSrcweir } 5052cdf0e10cSrcweir return aSynFSysPath.makeStringAndClear(); 5053cdf0e10cSrcweir } 5054cdf0e10cSrcweir 5055cdf0e10cSrcweir case FSYS_MAC: 5056cdf0e10cSrcweir { 5057cdf0e10cSrcweir if (m_aHost.isPresent() && m_aHost.getLength() > 0) 5058cdf0e10cSrcweir return rtl::OUString(); 5059cdf0e10cSrcweir 5060cdf0e10cSrcweir if (pDelimiter) 5061cdf0e10cSrcweir *pDelimiter = ':'; 5062cdf0e10cSrcweir 5063cdf0e10cSrcweir rtl::OUStringBuffer aSynFSysPath; 5064cdf0e10cSrcweir sal_Unicode const * p 5065cdf0e10cSrcweir = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 5066cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPath.getLength(); 5067cdf0e10cSrcweir DBG_ASSERT(p < pEnd && *p == '/', 5068cdf0e10cSrcweir "INetURLObject::getFSysPath(): Bad path"); 5069cdf0e10cSrcweir ++p; 5070cdf0e10cSrcweir while (p < pEnd) 5071cdf0e10cSrcweir { 5072cdf0e10cSrcweir EscapeType eEscapeType; 5073cdf0e10cSrcweir sal_uInt32 nUTF32 = getUTF32(p, pEnd, false, '%', WAS_ENCODED, 5074cdf0e10cSrcweir RTL_TEXTENCODING_UTF8, 5075cdf0e10cSrcweir eEscapeType); 5076cdf0e10cSrcweir if (eEscapeType == ESCAPE_NO && nUTF32 == '/') 5077cdf0e10cSrcweir aSynFSysPath.append(sal_Unicode(':')); 5078cdf0e10cSrcweir else 5079cdf0e10cSrcweir aSynFSysPath.appendUtf32(nUTF32); 5080cdf0e10cSrcweir } 5081cdf0e10cSrcweir return aSynFSysPath.makeStringAndClear(); 5082cdf0e10cSrcweir } 5083cdf0e10cSrcweir 5084cdf0e10cSrcweir default: 5085cdf0e10cSrcweir return rtl::OUString(); 5086cdf0e10cSrcweir } 5087cdf0e10cSrcweir } 5088cdf0e10cSrcweir 5089cdf0e10cSrcweir //============================================================================ 5090cdf0e10cSrcweir bool INetURLObject::HasMsgId() const 5091cdf0e10cSrcweir { 5092cdf0e10cSrcweir if (m_eScheme != INET_PROT_POP3) 5093cdf0e10cSrcweir return false; 5094cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 5095cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPath.getLength(); 5096cdf0e10cSrcweir for (; p < pEnd; ++p) 5097cdf0e10cSrcweir if (*p == '<') 5098cdf0e10cSrcweir return true; 5099cdf0e10cSrcweir return false; 5100cdf0e10cSrcweir } 5101cdf0e10cSrcweir 5102cdf0e10cSrcweir //============================================================================ 5103cdf0e10cSrcweir rtl::OUString INetURLObject::GetMsgId(DecodeMechanism eMechanism, 5104cdf0e10cSrcweir rtl_TextEncoding eCharset) const 5105cdf0e10cSrcweir { 5106cdf0e10cSrcweir if (m_eScheme != INET_PROT_POP3) 5107cdf0e10cSrcweir return rtl::OUString(); 5108cdf0e10cSrcweir sal_Unicode const * p = m_aAbsURIRef.getStr() + m_aPath.getBegin(); 5109cdf0e10cSrcweir sal_Unicode const * pEnd = p + m_aPath.getLength(); 5110cdf0e10cSrcweir for (; p < pEnd; ++p) 5111cdf0e10cSrcweir if (*p == '<') 5112cdf0e10cSrcweir return decode(p, pEnd, getEscapePrefix(), eMechanism, eCharset); 5113cdf0e10cSrcweir return rtl::OUString(); 5114cdf0e10cSrcweir } 5115cdf0e10cSrcweir 5116cdf0e10cSrcweir //============================================================================ 5117cdf0e10cSrcweir // static 5118cdf0e10cSrcweir void INetURLObject::appendUCS4Escape(rtl::OUStringBuffer & rTheText, 5119cdf0e10cSrcweir sal_Char cEscapePrefix, sal_uInt32 nUCS4) 5120cdf0e10cSrcweir { 5121cdf0e10cSrcweir DBG_ASSERT(nUCS4 < 0x80000000, 5122cdf0e10cSrcweir "INetURLObject::appendUCS4Escape(): Bad char"); 5123cdf0e10cSrcweir if (nUCS4 < 0x80) 5124cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4); 5125cdf0e10cSrcweir else if (nUCS4 < 0x800) 5126cdf0e10cSrcweir { 5127cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4 >> 6 | 0xC0); 5128cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 & 0x3F) | 0x80); 5129cdf0e10cSrcweir } 5130cdf0e10cSrcweir else if (nUCS4 < 0x10000) 5131cdf0e10cSrcweir { 5132cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4 >> 12 | 0xE0); 5133cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 6 & 0x3F) | 0x80); 5134cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 & 0x3F) | 0x80); 5135cdf0e10cSrcweir } 5136cdf0e10cSrcweir else if (nUCS4 < 0x200000) 5137cdf0e10cSrcweir { 5138cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4 >> 18 | 0xF0); 5139cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 12 & 0x3F) | 0x80); 5140cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 6 & 0x3F) | 0x80); 5141cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 & 0x3F) | 0x80); 5142cdf0e10cSrcweir } 5143cdf0e10cSrcweir else if (nUCS4 < 0x4000000) 5144cdf0e10cSrcweir { 5145cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4 >> 24 | 0xF8); 5146cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 18 & 0x3F) | 0x80); 5147cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 12 & 0x3F) | 0x80); 5148cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 6 & 0x3F) | 0x80); 5149cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 & 0x3F) | 0x80); 5150cdf0e10cSrcweir } 5151cdf0e10cSrcweir else 5152cdf0e10cSrcweir { 5153cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4 >> 30 | 0xFC); 5154cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 24 & 0x3F) | 0x80); 5155cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 18 & 0x3F) | 0x80); 5156cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 12 & 0x3F) | 0x80); 5157cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 >> 6 & 0x3F) | 0x80); 5158cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, (nUCS4 & 0x3F) | 0x80); 5159cdf0e10cSrcweir } 5160cdf0e10cSrcweir } 5161cdf0e10cSrcweir 5162cdf0e10cSrcweir //============================================================================ 5163cdf0e10cSrcweir // static 5164cdf0e10cSrcweir void INetURLObject::appendUCS4(rtl::OUStringBuffer& rTheText, sal_uInt32 nUCS4, 5165cdf0e10cSrcweir EscapeType eEscapeType, bool bOctets, 5166cdf0e10cSrcweir Part ePart, sal_Char cEscapePrefix, 5167cdf0e10cSrcweir rtl_TextEncoding eCharset, 5168cdf0e10cSrcweir bool bKeepVisibleEscapes) 5169cdf0e10cSrcweir { 5170cdf0e10cSrcweir bool bEscape; 5171cdf0e10cSrcweir rtl_TextEncoding eTargetCharset = RTL_TEXTENCODING_DONTKNOW; 5172cdf0e10cSrcweir switch (eEscapeType) 5173cdf0e10cSrcweir { 5174cdf0e10cSrcweir case ESCAPE_NO: 5175cdf0e10cSrcweir if (mustEncode(nUCS4, ePart)) 5176cdf0e10cSrcweir { 5177cdf0e10cSrcweir bEscape = true; 5178cdf0e10cSrcweir eTargetCharset = bOctets ? RTL_TEXTENCODING_ISO_8859_1 : 5179cdf0e10cSrcweir RTL_TEXTENCODING_UTF8; 5180cdf0e10cSrcweir } 5181cdf0e10cSrcweir else 5182cdf0e10cSrcweir bEscape = false; 5183cdf0e10cSrcweir break; 5184cdf0e10cSrcweir 5185cdf0e10cSrcweir case ESCAPE_OCTET: 5186cdf0e10cSrcweir bEscape = true; 5187cdf0e10cSrcweir eTargetCharset = RTL_TEXTENCODING_ISO_8859_1; 5188cdf0e10cSrcweir break; 5189cdf0e10cSrcweir 5190cdf0e10cSrcweir case ESCAPE_UTF32: 5191cdf0e10cSrcweir if (mustEncode(nUCS4, ePart)) 5192cdf0e10cSrcweir { 5193cdf0e10cSrcweir bEscape = true; 5194cdf0e10cSrcweir eTargetCharset = eCharset; 5195cdf0e10cSrcweir } 5196cdf0e10cSrcweir else if (bKeepVisibleEscapes && INetMIME::isVisible(nUCS4)) 5197cdf0e10cSrcweir { 5198cdf0e10cSrcweir bEscape = true; 5199cdf0e10cSrcweir eTargetCharset = RTL_TEXTENCODING_ASCII_US; 5200cdf0e10cSrcweir } 5201cdf0e10cSrcweir else 5202cdf0e10cSrcweir bEscape = false; 5203cdf0e10cSrcweir break; 5204cdf0e10cSrcweir default: 5205cdf0e10cSrcweir bEscape = false; 5206cdf0e10cSrcweir } 5207cdf0e10cSrcweir 5208cdf0e10cSrcweir if (bEscape) 5209cdf0e10cSrcweir { 5210cdf0e10cSrcweir switch (eTargetCharset) 5211cdf0e10cSrcweir { 5212cdf0e10cSrcweir default: 5213cdf0e10cSrcweir DBG_ERROR("INetURLObject::appendUCS4(): Unsupported charset"); 5214cdf0e10cSrcweir case RTL_TEXTENCODING_ASCII_US: 5215cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_1: 5216cdf0e10cSrcweir appendEscape(rTheText, cEscapePrefix, nUCS4); 5217cdf0e10cSrcweir break; 5218cdf0e10cSrcweir 5219cdf0e10cSrcweir case RTL_TEXTENCODING_UTF8: 5220cdf0e10cSrcweir appendUCS4Escape(rTheText, cEscapePrefix, nUCS4); 5221cdf0e10cSrcweir break; 5222cdf0e10cSrcweir } 5223cdf0e10cSrcweir } 5224cdf0e10cSrcweir else 5225cdf0e10cSrcweir rTheText.append(sal_Unicode(nUCS4)); 5226cdf0e10cSrcweir } 5227cdf0e10cSrcweir 5228cdf0e10cSrcweir //============================================================================ 5229cdf0e10cSrcweir // static 5230cdf0e10cSrcweir sal_uInt32 INetURLObject::getUTF32(sal_Unicode const *& rBegin, 5231cdf0e10cSrcweir sal_Unicode const * pEnd, bool bOctets, 5232cdf0e10cSrcweir sal_Char cEscapePrefix, 5233cdf0e10cSrcweir EncodeMechanism eMechanism, 5234cdf0e10cSrcweir rtl_TextEncoding eCharset, 5235cdf0e10cSrcweir EscapeType & rEscapeType) 5236cdf0e10cSrcweir { 5237cdf0e10cSrcweir DBG_ASSERT(rBegin < pEnd, "INetURLObject::getUTF32(): Bad sequence"); 5238cdf0e10cSrcweir sal_uInt32 nUTF32 = bOctets ? *rBegin++ : 5239cdf0e10cSrcweir INetMIME::getUTF32Character(rBegin, pEnd); 5240cdf0e10cSrcweir switch (eMechanism) 5241cdf0e10cSrcweir { 5242cdf0e10cSrcweir case ENCODE_ALL: 5243cdf0e10cSrcweir rEscapeType = ESCAPE_NO; 5244cdf0e10cSrcweir break; 5245cdf0e10cSrcweir 5246cdf0e10cSrcweir case WAS_ENCODED: 5247cdf0e10cSrcweir { 5248cdf0e10cSrcweir int nWeight1; 5249cdf0e10cSrcweir int nWeight2; 5250cdf0e10cSrcweir if (nUTF32 == sal_uChar(cEscapePrefix) && rBegin + 1 < pEnd 5251cdf0e10cSrcweir && (nWeight1 = INetMIME::getHexWeight(rBegin[0])) >= 0 5252cdf0e10cSrcweir && (nWeight2 = INetMIME::getHexWeight(rBegin[1])) >= 0) 5253cdf0e10cSrcweir { 5254cdf0e10cSrcweir rBegin += 2; 5255cdf0e10cSrcweir nUTF32 = nWeight1 << 4 | nWeight2; 5256cdf0e10cSrcweir switch (eCharset) 5257cdf0e10cSrcweir { 5258cdf0e10cSrcweir default: 5259cdf0e10cSrcweir DBG_ERROR( 5260cdf0e10cSrcweir "INetURLObject::getUTF32(): Unsupported charset"); 5261cdf0e10cSrcweir case RTL_TEXTENCODING_ASCII_US: 5262cdf0e10cSrcweir rEscapeType = INetMIME::isUSASCII(nUTF32) ? 5263cdf0e10cSrcweir ESCAPE_UTF32 : ESCAPE_OCTET; 5264cdf0e10cSrcweir break; 5265cdf0e10cSrcweir 5266cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_1: 5267cdf0e10cSrcweir rEscapeType = ESCAPE_UTF32; 5268cdf0e10cSrcweir break; 5269cdf0e10cSrcweir 5270cdf0e10cSrcweir case RTL_TEXTENCODING_UTF8: 5271cdf0e10cSrcweir if (INetMIME::isUSASCII(nUTF32)) 5272cdf0e10cSrcweir rEscapeType = ESCAPE_UTF32; 5273cdf0e10cSrcweir else 5274cdf0e10cSrcweir { 5275cdf0e10cSrcweir if (nUTF32 >= 0xC0 && nUTF32 <= 0xF4) 5276cdf0e10cSrcweir { 5277cdf0e10cSrcweir sal_uInt32 nEncoded; 5278cdf0e10cSrcweir int nShift; 5279cdf0e10cSrcweir sal_uInt32 nMin; 5280cdf0e10cSrcweir if (nUTF32 <= 0xDF) 5281cdf0e10cSrcweir { 5282cdf0e10cSrcweir nEncoded = (nUTF32 & 0x1F) << 6; 5283cdf0e10cSrcweir nShift = 0; 5284cdf0e10cSrcweir nMin = 0x80; 5285cdf0e10cSrcweir } 5286cdf0e10cSrcweir else if (nUTF32 <= 0xEF) 5287cdf0e10cSrcweir { 5288cdf0e10cSrcweir nEncoded = (nUTF32 & 0x0F) << 12; 5289cdf0e10cSrcweir nShift = 6; 5290cdf0e10cSrcweir nMin = 0x800; 5291cdf0e10cSrcweir } 5292cdf0e10cSrcweir else 5293cdf0e10cSrcweir { 5294cdf0e10cSrcweir nEncoded = (nUTF32 & 0x07) << 18; 5295cdf0e10cSrcweir nShift = 12; 5296cdf0e10cSrcweir nMin = 0x10000; 5297cdf0e10cSrcweir } 5298cdf0e10cSrcweir sal_Unicode const * p = rBegin; 5299cdf0e10cSrcweir bool bUTF8 = true; 5300cdf0e10cSrcweir for (;;) 5301cdf0e10cSrcweir { 5302cdf0e10cSrcweir if (pEnd - p < 3 5303cdf0e10cSrcweir || p[0] != cEscapePrefix 5304cdf0e10cSrcweir || (nWeight1 5305cdf0e10cSrcweir = INetMIME::getHexWeight(p[1])) 5306cdf0e10cSrcweir < 8 5307cdf0e10cSrcweir || nWeight1 > 11 5308cdf0e10cSrcweir || (nWeight2 5309cdf0e10cSrcweir = INetMIME::getHexWeight(p[2])) 5310cdf0e10cSrcweir < 0) 5311cdf0e10cSrcweir { 5312cdf0e10cSrcweir bUTF8 = false; 5313cdf0e10cSrcweir break; 5314cdf0e10cSrcweir } 5315cdf0e10cSrcweir p += 3; 5316cdf0e10cSrcweir nEncoded 5317cdf0e10cSrcweir |= ((nWeight1 & 3) << 4 | nWeight2) 5318cdf0e10cSrcweir << nShift; 5319cdf0e10cSrcweir if (nShift == 0) 5320cdf0e10cSrcweir break; 5321cdf0e10cSrcweir nShift -= 6; 5322cdf0e10cSrcweir } 5323cdf0e10cSrcweir if (bUTF8 && nEncoded >= nMin 5324cdf0e10cSrcweir && !INetMIME::isHighSurrogate(nEncoded) 5325cdf0e10cSrcweir && !INetMIME::isLowSurrogate(nEncoded) 5326cdf0e10cSrcweir && nEncoded <= 0x10FFFF) 5327cdf0e10cSrcweir { 5328cdf0e10cSrcweir rBegin = p; 5329cdf0e10cSrcweir nUTF32 = nEncoded; 5330cdf0e10cSrcweir rEscapeType = ESCAPE_UTF32; 5331cdf0e10cSrcweir break; 5332cdf0e10cSrcweir } 5333cdf0e10cSrcweir } 5334cdf0e10cSrcweir rEscapeType = ESCAPE_OCTET; 5335cdf0e10cSrcweir } 5336cdf0e10cSrcweir break; 5337cdf0e10cSrcweir } 5338cdf0e10cSrcweir } 5339cdf0e10cSrcweir else 5340cdf0e10cSrcweir rEscapeType = ESCAPE_NO; 5341cdf0e10cSrcweir break; 5342cdf0e10cSrcweir } 5343cdf0e10cSrcweir 5344cdf0e10cSrcweir case NOT_CANONIC: 5345cdf0e10cSrcweir { 5346cdf0e10cSrcweir int nWeight1; 5347cdf0e10cSrcweir int nWeight2; 5348cdf0e10cSrcweir if (nUTF32 == sal_uChar(cEscapePrefix) && rBegin + 1 < pEnd 5349cdf0e10cSrcweir && ((nWeight1 = INetMIME::getHexWeight(rBegin[0])) >= 0) 5350cdf0e10cSrcweir && ((nWeight2 = INetMIME::getHexWeight(rBegin[1])) >= 0)) 5351cdf0e10cSrcweir { 5352cdf0e10cSrcweir rBegin += 2; 5353cdf0e10cSrcweir nUTF32 = nWeight1 << 4 | nWeight2; 5354cdf0e10cSrcweir rEscapeType = ESCAPE_OCTET; 5355cdf0e10cSrcweir } 5356cdf0e10cSrcweir else 5357cdf0e10cSrcweir rEscapeType = ESCAPE_NO; 5358cdf0e10cSrcweir break; 5359cdf0e10cSrcweir } 5360cdf0e10cSrcweir } 5361cdf0e10cSrcweir return nUTF32; 5362cdf0e10cSrcweir } 5363cdf0e10cSrcweir 5364cdf0e10cSrcweir //============================================================================ 5365cdf0e10cSrcweir // static 5366cdf0e10cSrcweir sal_uInt32 INetURLObject::scanDomain(sal_Unicode const *& rBegin, 5367cdf0e10cSrcweir sal_Unicode const * pEnd, 5368cdf0e10cSrcweir bool bEager) 5369cdf0e10cSrcweir { 5370cdf0e10cSrcweir enum State { STATE_DOT, STATE_LABEL, STATE_HYPHEN }; 5371cdf0e10cSrcweir State eState = STATE_DOT; 5372cdf0e10cSrcweir sal_Int32 nLabels = 0; 5373cdf0e10cSrcweir sal_Unicode const * pLastAlphanumeric = 0; 5374cdf0e10cSrcweir for (sal_Unicode const * p = rBegin;; ++p) 5375cdf0e10cSrcweir switch (eState) 5376cdf0e10cSrcweir { 5377cdf0e10cSrcweir case STATE_DOT: 5378cdf0e10cSrcweir if (p != pEnd && INetMIME::isAlphanumeric(*p)) 5379cdf0e10cSrcweir { 5380cdf0e10cSrcweir ++nLabels; 5381cdf0e10cSrcweir eState = STATE_LABEL; 5382cdf0e10cSrcweir break; 5383cdf0e10cSrcweir } 5384cdf0e10cSrcweir if (bEager || nLabels == 0) 5385cdf0e10cSrcweir return 0; 5386cdf0e10cSrcweir rBegin = p - 1; 5387cdf0e10cSrcweir return nLabels; 5388cdf0e10cSrcweir 5389cdf0e10cSrcweir case STATE_LABEL: 5390cdf0e10cSrcweir if (p != pEnd) 5391cdf0e10cSrcweir { 5392cdf0e10cSrcweir if (INetMIME::isAlphanumeric(*p)) 5393cdf0e10cSrcweir break; 5394cdf0e10cSrcweir else if (*p == '.') 5395cdf0e10cSrcweir { 5396cdf0e10cSrcweir eState = STATE_DOT; 5397cdf0e10cSrcweir break; 5398cdf0e10cSrcweir } 5399cdf0e10cSrcweir else if (*p == '-') 5400cdf0e10cSrcweir { 5401cdf0e10cSrcweir pLastAlphanumeric = p; 5402cdf0e10cSrcweir eState = STATE_HYPHEN; 5403cdf0e10cSrcweir break; 5404cdf0e10cSrcweir } 5405cdf0e10cSrcweir } 5406cdf0e10cSrcweir rBegin = p; 5407cdf0e10cSrcweir return nLabels; 5408cdf0e10cSrcweir 5409cdf0e10cSrcweir case STATE_HYPHEN: 5410cdf0e10cSrcweir if (p != pEnd) 5411cdf0e10cSrcweir { 5412cdf0e10cSrcweir if (INetMIME::isAlphanumeric(*p)) 5413cdf0e10cSrcweir { 5414cdf0e10cSrcweir eState = STATE_LABEL; 5415cdf0e10cSrcweir break; 5416cdf0e10cSrcweir } 5417cdf0e10cSrcweir else if (*p == '-') 5418cdf0e10cSrcweir break; 5419cdf0e10cSrcweir } 5420cdf0e10cSrcweir if (bEager) 5421cdf0e10cSrcweir return 0; 5422cdf0e10cSrcweir rBegin = pLastAlphanumeric; 5423cdf0e10cSrcweir return nLabels; 5424cdf0e10cSrcweir } 5425cdf0e10cSrcweir } 5426cdf0e10cSrcweir 5427cdf0e10cSrcweir //============================================================================ 5428cdf0e10cSrcweir // static 5429cdf0e10cSrcweir bool INetURLObject::scanIPv6reference(sal_Unicode const *& rBegin, 5430cdf0e10cSrcweir sal_Unicode const * pEnd) 5431cdf0e10cSrcweir { 5432cdf0e10cSrcweir if (rBegin != pEnd && *rBegin == '[') { 5433cdf0e10cSrcweir sal_Unicode const * p = rBegin + 1; 5434cdf0e10cSrcweir //TODO: check for valid IPv6address (RFC 2373): 5435cdf0e10cSrcweir while (p != pEnd && (INetMIME::isHexDigit(*p) || *p == ':' || *p == '.')) 5436cdf0e10cSrcweir { 5437cdf0e10cSrcweir ++p; 5438cdf0e10cSrcweir } 5439cdf0e10cSrcweir if (p != pEnd && *p == ']') { 5440cdf0e10cSrcweir rBegin = p + 1; 5441cdf0e10cSrcweir return true; 5442cdf0e10cSrcweir } 5443cdf0e10cSrcweir } 5444cdf0e10cSrcweir return false; 5445cdf0e10cSrcweir } 5446cdf0e10cSrcweir 5447cdf0e10cSrcweir //============================================================================ 5448cdf0e10cSrcweir rtl::OUString INetURLObject::GetPartBeforeLastName(DecodeMechanism eMechanism, 5449cdf0e10cSrcweir rtl_TextEncoding eCharset) 5450cdf0e10cSrcweir const 5451cdf0e10cSrcweir { 5452cdf0e10cSrcweir if (!checkHierarchical()) 5453cdf0e10cSrcweir return rtl::OUString(); 5454cdf0e10cSrcweir INetURLObject aTemp(*this); 5455cdf0e10cSrcweir aTemp.clearFragment(); 5456cdf0e10cSrcweir aTemp.clearQuery(); 5457cdf0e10cSrcweir aTemp.removeSegment(LAST_SEGMENT, false); 5458cdf0e10cSrcweir aTemp.setFinalSlash(); 5459cdf0e10cSrcweir return aTemp.GetMainURL(eMechanism, eCharset); 5460cdf0e10cSrcweir } 5461cdf0e10cSrcweir 5462cdf0e10cSrcweir //============================================================================ 5463cdf0e10cSrcweir rtl::OUString INetURLObject::GetLastName(DecodeMechanism eMechanism, 5464cdf0e10cSrcweir rtl_TextEncoding eCharset) const 5465cdf0e10cSrcweir { 5466cdf0e10cSrcweir return getName(LAST_SEGMENT, true, eMechanism, eCharset); 5467cdf0e10cSrcweir } 5468cdf0e10cSrcweir 5469cdf0e10cSrcweir //============================================================================ 5470cdf0e10cSrcweir rtl::OUString INetURLObject::GetFileExtension(DecodeMechanism eMechanism, 5471cdf0e10cSrcweir rtl_TextEncoding eCharset) const 5472cdf0e10cSrcweir { 5473cdf0e10cSrcweir return getExtension(LAST_SEGMENT, false, eMechanism, eCharset); 5474cdf0e10cSrcweir } 5475cdf0e10cSrcweir 5476cdf0e10cSrcweir //============================================================================ 5477cdf0e10cSrcweir bool INetURLObject::CutLastName() 5478cdf0e10cSrcweir { 5479cdf0e10cSrcweir INetURLObject aTemp(*this); 5480cdf0e10cSrcweir aTemp.clearFragment(); 5481cdf0e10cSrcweir aTemp.clearQuery(); 5482cdf0e10cSrcweir if (!aTemp.removeSegment(LAST_SEGMENT, false)) 5483cdf0e10cSrcweir return false; 5484cdf0e10cSrcweir *this = aTemp; 5485cdf0e10cSrcweir return true; 5486cdf0e10cSrcweir } 5487cdf0e10cSrcweir 5488cdf0e10cSrcweir //============================================================================ 5489cdf0e10cSrcweir rtl::OUString INetURLObject::PathToFileName() const 5490cdf0e10cSrcweir { 5491cdf0e10cSrcweir if (m_eScheme != INET_PROT_FILE) 5492cdf0e10cSrcweir return rtl::OUString(); 5493cdf0e10cSrcweir rtl::OUString aSystemPath; 5494cdf0e10cSrcweir if (osl::FileBase::getSystemPathFromFileURL( 5495cdf0e10cSrcweir decode(m_aAbsURIRef.getStr(), 5496cdf0e10cSrcweir m_aAbsURIRef.getStr() + m_aPath.getEnd(), 5497cdf0e10cSrcweir getEscapePrefix(), NO_DECODE, RTL_TEXTENCODING_UTF8), 5498cdf0e10cSrcweir aSystemPath) 5499cdf0e10cSrcweir != osl::FileBase::E_None) 5500cdf0e10cSrcweir return rtl::OUString(); 5501cdf0e10cSrcweir return aSystemPath; 5502cdf0e10cSrcweir } 5503cdf0e10cSrcweir 5504cdf0e10cSrcweir //============================================================================ 5505cdf0e10cSrcweir rtl::OUString INetURLObject::GetFull() const 5506cdf0e10cSrcweir { 5507cdf0e10cSrcweir INetURLObject aTemp(*this); 5508cdf0e10cSrcweir aTemp.removeFinalSlash(); 5509cdf0e10cSrcweir return aTemp.PathToFileName(); 5510cdf0e10cSrcweir } 5511cdf0e10cSrcweir 5512cdf0e10cSrcweir //============================================================================ 5513cdf0e10cSrcweir rtl::OUString INetURLObject::GetPath() const 5514cdf0e10cSrcweir { 5515cdf0e10cSrcweir INetURLObject aTemp(*this); 5516cdf0e10cSrcweir aTemp.removeSegment(LAST_SEGMENT, true); 5517cdf0e10cSrcweir aTemp.removeFinalSlash(); 5518cdf0e10cSrcweir return aTemp.PathToFileName(); 5519cdf0e10cSrcweir } 5520cdf0e10cSrcweir 5521cdf0e10cSrcweir //============================================================================ 5522cdf0e10cSrcweir void INetURLObject::SetBase(rtl::OUString const & rTheBase) 5523cdf0e10cSrcweir { 5524cdf0e10cSrcweir setBase(rTheBase, LAST_SEGMENT, true, ENCODE_ALL); 5525cdf0e10cSrcweir } 5526cdf0e10cSrcweir 5527cdf0e10cSrcweir //============================================================================ 5528cdf0e10cSrcweir rtl::OUString INetURLObject::GetBase() const 5529cdf0e10cSrcweir { 5530cdf0e10cSrcweir return getBase(LAST_SEGMENT, true, DECODE_WITH_CHARSET); 5531cdf0e10cSrcweir } 5532cdf0e10cSrcweir 5533cdf0e10cSrcweir //============================================================================ 5534cdf0e10cSrcweir void INetURLObject::SetName(rtl::OUString const & rTheName, 5535cdf0e10cSrcweir EncodeMechanism eMechanism, 5536cdf0e10cSrcweir rtl_TextEncoding eCharset) 5537cdf0e10cSrcweir { 5538cdf0e10cSrcweir INetURLObject aTemp(*this); 5539cdf0e10cSrcweir if (aTemp.removeSegment(LAST_SEGMENT, true) 5540cdf0e10cSrcweir && aTemp.insertName(rTheName, false, LAST_SEGMENT, true, eMechanism, 5541cdf0e10cSrcweir eCharset)) 5542cdf0e10cSrcweir *this = aTemp; 5543cdf0e10cSrcweir } 5544cdf0e10cSrcweir 5545cdf0e10cSrcweir //============================================================================ 5546cdf0e10cSrcweir rtl::OUString INetURLObject::CutName(DecodeMechanism eMechanism, 5547cdf0e10cSrcweir rtl_TextEncoding eCharset) 5548cdf0e10cSrcweir { 5549cdf0e10cSrcweir rtl::OUString aTheName(getName(LAST_SEGMENT, true, eMechanism, eCharset)); 5550cdf0e10cSrcweir return removeSegment(LAST_SEGMENT, true) ? aTheName : rtl::OUString(); 5551cdf0e10cSrcweir } 5552cdf0e10cSrcweir 5553cdf0e10cSrcweir //============================================================================ 5554cdf0e10cSrcweir void INetURLObject::SetExtension(rtl::OUString const & rTheExtension, 5555cdf0e10cSrcweir EncodeMechanism eMechanism, 5556cdf0e10cSrcweir rtl_TextEncoding eCharset) 5557cdf0e10cSrcweir { 5558cdf0e10cSrcweir setExtension(rTheExtension, LAST_SEGMENT, false, eMechanism, eCharset); 5559cdf0e10cSrcweir } 5560cdf0e10cSrcweir 5561cdf0e10cSrcweir //============================================================================ 5562cdf0e10cSrcweir rtl::OUString INetURLObject::CutExtension(DecodeMechanism eMechanism, 5563cdf0e10cSrcweir rtl_TextEncoding eCharset) 5564cdf0e10cSrcweir { 5565cdf0e10cSrcweir rtl::OUString aTheExtension(getExtension(LAST_SEGMENT, false, eMechanism, 5566cdf0e10cSrcweir eCharset)); 5567cdf0e10cSrcweir return removeExtension(LAST_SEGMENT, false) 5568cdf0e10cSrcweir ? aTheExtension : rtl::OUString(); 5569cdf0e10cSrcweir } 5570cdf0e10cSrcweir 5571cdf0e10cSrcweir //============================================================================ 5572cdf0e10cSrcweir bool INetURLObject::IsCaseSensitive() const 5573cdf0e10cSrcweir { 5574cdf0e10cSrcweir return true; 5575cdf0e10cSrcweir } 5576