xref: /trunk/main/ucb/source/ucp/ftp/ftpurl.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
24 /**************************************************************************
25                                 TODO
26  **************************************************************************
27 
28  *************************************************************************/
29 
30 #ifndef _FTP_FTPURL_HXX_
31 #define _FTP_FTPURL_HXX_
32 
33 #include "curl.hxx"
34 #include <curl/easy.h>
35 #include <com/sun/star/io/XOutputStream.hpp>
36 
37 #include <rtl/ustring.hxx>
38 #include <osl/mutex.hxx>
39 #include <osl/file.h>
40 #include <vector>
41 
42 #include "ftpdirp.hxx"
43 #include "ftpcfunc.hxx"
44 
45 namespace ftp {
46 
47     /** Forward declarations.
48      */
49 
50     class FTPHandleProvider;
51 
52 
53     enum FTPErrors { FILE_EXIST_DURING_INSERT = CURL_LAST +1,
54                      FOLDER_EXIST_DURING_INSERT,
55                      FOLDER_MIGHT_EXIST_DURING_INSERT,
56                      FILE_MIGHT_EXIST_DURING_INSERT };
57 
58 
59     class malformed_exception { };
60 
61 
62     class curl_exception
63     {
64     public:
65 
curl_exception(sal_Int32 err)66         curl_exception(sal_Int32 err)
67             : n_err(err) { }
68 
code() const69         sal_Int32 code() const { return n_err; }
70 
71 
72     private:
73 
74         sal_Int32 n_err;
75     };
76 
77     class CurlInput {
78 
79     public:
80 
81         // returns the number of bytes actually read
82         virtual sal_Int32 read(sal_Int8 *dest,sal_Int32 nBytesRequested) = 0;
83     };
84 
85 
86     class FTPURL
87     {
88     public:
89 
90         FTPURL(
91             const rtl::OUString& aIdent,
92             FTPHandleProvider* pFCP = 0
93         );
94 
95         FTPURL(const FTPURL& r);
96 
97         ~FTPURL();
98 
host() const99         rtl::OUString host() const { return m_aHost; }
100 
port() const101         rtl::OUString port() const { return m_aPort; }
102 
username() const103         rtl::OUString username() const { return m_aUsername; }
104 
105         /** This returns the URL, but cleaned from
106          *  unnecessary ellipses.
107          */
108 
109         rtl::OUString ident(bool withslash,bool internal) const;
110 
111         /** returns the parent url.
112          */
113 
114         rtl::OUString parent(bool internal = false) const;
115 
116         /** sets the unencoded title */
117         void child(const rtl::OUString& title);
118 
119         /** returns the unencoded title */
120         rtl::OUString child(void) const;
121 
122         std::vector<FTPDirentry> list(sal_Int16 nMode) const;
123 
124         // returns a pointer to an open tempfile,
125         // sought to the beginning of.
126         oslFileHandle open();
127 
128         FTPDirentry direntry() const;
129 
130         void insert(bool ReplaceExisting,void* stream) const;
131 
132         void mkdir(bool ReplaceExisting) const;
133 
134         rtl::OUString ren(const rtl::OUString& NewTitle);
135 
136         void del() const;
137 
138 
139     private:
140 
141         osl::Mutex m_mutex;
142 
143         FTPHandleProvider *m_pFCP;
144 
145         mutable rtl::OUString m_aUsername;
146         bool m_bShowPassword;
147         mutable rtl::OUString m_aHost;
148         mutable rtl::OUString m_aPort;
149         mutable rtl::OUString m_aType;
150 
151         /** Contains the encoded pathsegments of the url.
152          */
153         std::vector<rtl::OUString> m_aPathSegmentVec;
154 
155         void parse(const rtl::OUString& url);
156 
157         rtl::OUString net_title() const;
158     };
159 
160 }
161 
162 
163 #endif
164