xref: /AOO41X/main/ucb/source/ucp/webdav/SerfUri.hxx (revision 4023fbb75b8bfa2fc9125aeeead040b06e4d3840)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef INCLUDED_SERFURI_HXX
24 #define INCLUDED_SERFURI_HXX
25 
26 #ifdef OS2 // use system apr headers
27 #include <apr_uri.h>
28 #else
29 #include <apr-util/apr_uri.h>
30 #endif
31 #include <rtl/ustring.hxx>
32 #include <DAVException.hxx>
33 
34 namespace http_dav_ucp
35 {
36 
37 #define DEFAULT_HTTP_PORT       80
38 #define DEFAULT_HTTPS_PORT      443
39 
40 // -------------------------------------------------------------------
41 // SerfUri
42 // A URI implementation for use with the neon/expat library
43 // -------------------------------------------------------------------
44 class SerfUri
45 {
46 	private:
47         apr_uri_t mAprUri;
48 		::rtl::OUString	mURI;
49 		::rtl::OUString	mScheme;
50 		::rtl::OUString	mUserInfo;
51 		::rtl::OUString	mHostName;
52 		sal_Int32		mPort;
53 		::rtl::OUString	mPath;
54 
55         void init( const apr_uri_t * pUri );
56 		void calculateURI ();
57 
58 	public:
59         SerfUri( const ::rtl::OUString & inUri ) throw ( DAVException );
60         SerfUri( const apr_uri_t * inUri ) throw ( DAVException );
61 		~SerfUri( );
62 
63         bool operator== ( const SerfUri & rOther ) const;
64         bool operator!= ( const SerfUri & rOther ) const
65         { return !operator==( rOther ); }
66 
67         apr_uri_t* getAprUri()
68         {
69             return &mAprUri;
70         }
71 		const ::rtl::OUString & GetURI( void ) const
72 											{ return mURI; };
73 		const ::rtl::OUString & GetScheme( void ) const
74 											{ return mScheme; };
75 		const ::rtl::OUString & GetUserInfo( void ) const
76 											{ return mUserInfo; };
77 		const ::rtl::OUString & GetHost( void ) const
78 											{ return mHostName; };
79 		sal_Int32		GetPort( void )		const
80 											{ return mPort; };
81 		const ::rtl::OUString &		GetPath( void )	const
82 											{ return mPath; };
83 
84 		::rtl::OUString GetPathBaseName ( void ) const;
85 
86 		::rtl::OUString GetPathBaseNameUnescaped ( void ) const;
87 
88 		void SetScheme (const ::rtl::OUString& scheme)
89 			{ mScheme = scheme; calculateURI (); };
90 
91 		void AppendPath (const ::rtl::OUString& rPath);
92 
93 		static ::rtl::OUString escapeSegment( const ::rtl::OUString& segment );
94 		static ::rtl::OUString unescape( const ::rtl::OUString& string );
95 
96         // "host:port", omit ":port" for port 80 and 443
97         static rtl::OUString makeConnectionEndPointString(
98                                         const rtl::OUString & rHostName,
99                                         int nPort );
100         rtl::OUString makeConnectionEndPointString() const
101         { return makeConnectionEndPointString( GetHost(), GetPort() ); }
102 };
103 
104 } // namespace http_dav_ucp
105 
106 #endif // INCLUDED_SERFURI_HXX
107