31 #include <rtl/uri.hxx>
32 #include <rtl/ustring.hxx>
33 #include <rtl/ustrbuf.hxx>
38 #include "../inc/urihelper.hxx"
46 #pragma GCC diagnostic ignored "-Wwrite-strings"
51 const ne_uri g_sUriDefaultsHTTP = {
const_cast<char *
>(
"http"),
52 const_cast<char *>(
""),
53 const_cast<char *
>(
""),
55 const_cast<char *>(
""),
58 const ne_uri g_sUriDefaultsHTTPS = {
const_cast<char *
>(
"https"),
59 const_cast<char *>(
""),
60 const_cast<char *
>(
""),
62 const_cast<char *>(
""),
65 const ne_uri g_sUriDefaultsFTP = {
const_cast<char *
>(
"ftp"),
66 const_cast<char *>(
""),
67 const_cast<char *
>(
""),
69 const_cast<char *>(
""),
76 if ( inUri ==
nullptr )
79 char *
uri = ne_uri_unparse( inUri );
84 init( OString( uri ), inUri );
92 if ( inUri.isEmpty() )
99 aEscapedUri.getStr(), aEscapedUri.getLength(), RTL_TEXTENCODING_UTF8 );
102 if ( ne_uri_parse( theInputUri.getStr(), &theUri ) != 0 )
104 ne_uri_free( &theUri );
108 init( theInputUri, &theUri );
109 ne_uri_free( &theUri );
117 const ne_uri * pUriDefs
118 = rUri.matchIgnoreAsciiCase(
"ftp:" ) ?
120 rUri.matchIgnoreAsciiCase(
"https:" ) ?
121 &g_sUriDefaultsHTTPS :
125 pUri->scheme ? pUri->scheme : pUriDefs->scheme,
126 RTL_TEXTENCODING_UTF8 );
128 pUri->userinfo ? pUri->userinfo : pUriDefs->userinfo,
129 RTL_TEXTENCODING_UTF8 );
131 pUri->host ? pUri->host : pUriDefs->host,
132 RTL_TEXTENCODING_UTF8 );
133 mPort = pUri->port > 0 ? pUri->port : pUriDefs->port;
134 mPath = OStringToOUString(
135 pUri->path ? pUri->path : pUriDefs->path,
136 RTL_TEXTENCODING_UTF8 );
140 mPath +=
"?" + OStringToOUString( pUri->query, RTL_TEXTENCODING_UTF8 );
143 if ( pUri->fragment )
145 mPath +=
"#" + OStringToOUString( pUri->fragment, RTL_TEXTENCODING_UTF8 );
151 OUStringBuffer
aBuf( 256 );
153 aBuf.append(
"://" );
161 if ( (
mHostName.indexOf(
':' ) != -1 ) &&
174 bool bAppendPort =
true;
178 bAppendPort =
mScheme !=
"http";
182 bAppendPort =
mScheme !=
"https";
186 bAppendPort =
mScheme !=
"ftp";
192 aBuf.append( OUString::number(
mPort ) );
194 aBuf.append(
mPath );
196 mURI = aBuf.makeStringAndClear();
201 sal_Int32
nPos =
mPath.lastIndexOf (
'/');
202 sal_Int32 nTrail = 0;
203 if (nPos ==
mPath.getLength () - 1)
207 nPos =
mPath.lastIndexOf (
'/', nPos);
212 mPath.copy (nPos + 1,
mPath.getLength () - nPos - 1 - nTrail) );
215 nPos = aTemp.indexOf(
'?' );
217 nPos = aTemp.indexOf(
'#' );
220 aTemp = aTemp.copy( 0, nPos );
240 if (
mPath.lastIndexOf (
'/') !=
mPath.getLength () - 1)
250 return rtl::Uri::encode( segment,
251 rtl_UriCharClassPchar,
252 rtl_UriEncodeIgnoreEscapes,
253 RTL_TEXTENCODING_UTF8 );
259 return rtl::Uri::decode( segment,
260 rtl_UriDecodeWithCharset,
261 RTL_TEXTENCODING_UTF8 );
266 const OUString & rHostName,
int nPort )
271 if ( ( rHostName.indexOf(
':' ) != -1 ) &&
272 ( rHostName[ 0 ] !=
'[' ) )
275 aBuf.append( rHostName );
280 aBuf.append( rHostName );
286 aBuf.append( OUString::number( nPort ) );
288 return aBuf.makeStringAndClear();
static OUString unescape(const OUString &string)
OUString GetPathBaseNameUnescaped() const
#define DEFAULT_HTTPS_PORT
OUString encodeURI(const OUString &rURI)
bool operator==(const NeonUri &rOther) const
OUString GetPathBaseName() const
NeonUri(const OUString &inUri)
void init(const OString &rUri, const ne_uri *pUri)
#define DEFAULT_HTTP_PORT
void AppendPath(std::u16string_view rPath)
static OUString escapeSegment(const OUString &segment)
exports com.sun.star. uri
static OUString makeConnectionEndPointString(const OUString &rHostName, int nPort)