1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
21 #pragma once
22 
23 #include <apr_uri.h>
24 #include <rtl/ustring.hxx>
25 #include "DAVException.hxx"
26 
27 namespace http_dav_ucp
28 {
29 
30 #define DEFAULT_HTTP_PORT       80
31 #define DEFAULT_HTTPS_PORT      443
32 
33 
34 // SerfUri
35 // A URI implementation for use with the neon/expat library
36 
37 class SerfUri
38 {
39     private:
40         apr_uri_t mAprUri;
41         OUString mURI;
42         OUString mScheme;
43         OUString mUserInfo;
44         OUString mHostName;
45         sal_Int32       mPort;
46         OUString mPath;
47 
48         void init( const apr_uri_t * pUri );
49         void calculateURI ();
50 
51     public:
52         /// @throws DAVException
53         explicit SerfUri( const OUString & inUri );
54         /// @throws DAVException
55         explicit SerfUri( const apr_uri_t * inUri );
56 
57         bool operator== ( const SerfUri & rOther ) const;
operator !=(const SerfUri & rOther) const58         bool operator!= ( const SerfUri & rOther ) const
59         { return !operator==( rOther ); }
60 
getAprUri()61         apr_uri_t& getAprUri()
62         {
63             return mAprUri;
64         }
GetURI() const65         const OUString & GetURI() const
66                                             { return mURI; };
GetScheme() const67         const OUString & GetScheme() const
68                                             { return mScheme; };
GetUserInfo() const69         const OUString & GetUserInfo() const
70                                             { return mUserInfo; };
GetHost() const71         const OUString & GetHost() const
72                                             { return mHostName; };
GetPort() const73         sal_Int32       GetPort()     const
74                                             { return mPort; };
GetPath() const75         const OUString &     GetPath() const
76                                             { return mPath; };
77 
78         OUString GetPathBaseName() const;
79 
80         OUString GetPathBaseNameUnescaped() const;
81 
SetScheme(const OUString & scheme)82         void SetScheme (const OUString& scheme)
83             { mScheme = scheme; calculateURI (); };
84 
85         void AppendPath (const OUString& rPath);
86 
87         static OUString escapeSegment( const OUString& segment );
88         static OUString unescape( const OUString& string );
89 
90         // "host:port", omit ":port" for port 80 and 443
91         static OUString makeConnectionEndPointString(
92                                         const OUString & rHostName,
93                                         int nPort );
makeConnectionEndPointString() const94         OUString makeConnectionEndPointString() const
95         { return makeConnectionEndPointString( GetHost(), GetPort() ); }
96 };
97 
98 } // namespace http_dav_ucp
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
101