xref: /trunk/main/ucb/source/ucp/ftp/ftpurl.hxx (revision 72cd26dd)
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 
66         curl_exception(sal_Int32 err)
67             : n_err(err) { }
68 
69         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             throw(
95                 malformed_exception
96             );
97 
98         FTPURL(const FTPURL& r);
99 
100         ~FTPURL();
101 
102         rtl::OUString host() const { return m_aHost; }
103 
104         rtl::OUString port() const { return m_aPort; }
105 
106         rtl::OUString username() const { return m_aUsername; }
107 
108         /** This returns the URL, but cleaned from
109          *  unnessary ellipses.
110          */
111 
112         rtl::OUString ident(bool withslash,bool internal) const;
113 
114         /** returns the parent url.
115          */
116 
117         rtl::OUString parent(bool internal = false) const;
118 
119         /** sets the unencoded title */
120         void child(const rtl::OUString& title);
121 
122         /** returns the unencoded title */
123         rtl::OUString child(void) const;
124 
125         std::vector<FTPDirentry> list(sal_Int16 nMode) const
126             throw(curl_exception);
127 
128         // returns a pointer to an open tempfile,
129         // seeked to the beginning of.
130         oslFileHandle open() throw(curl_exception);
131 
132         FTPDirentry direntry() const throw(curl_exception);
133 
134         void insert(bool ReplaceExisting,void* stream) const
135             throw(curl_exception);
136 
137         void mkdir(bool ReplaceExisting) const
138             throw(curl_exception);
139 
140         rtl::OUString ren(const rtl::OUString& NewTitle)
141             throw(curl_exception);
142 
143         void del() const
144             throw(curl_exception);
145 
146 
147     private:
148 
149         osl::Mutex m_mutex;
150 
151         FTPHandleProvider *m_pFCP;
152 
153         mutable rtl::OUString m_aUsername;
154         bool m_bShowPassword;
155         mutable rtl::OUString m_aHost;
156         mutable rtl::OUString m_aPort;
157         mutable rtl::OUString m_aType;
158 
159         /** Contains the encoded pathsegments of the url.
160          */
161         std::vector<rtl::OUString> m_aPathSegmentVec;
162 
163         void parse(const rtl::OUString& url)
164             throw(
165                 malformed_exception
166             );
167 
168         rtl::OUString net_title() const throw(curl_exception);
169     };
170 
171 }
172 
173 
174 #endif
175