xref: /trunk/main/ucb/source/ucp/ftp/ftpurl.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 /**************************************************************************
29                                 TODO
30  **************************************************************************
31 
32  *************************************************************************/
33 
34 #ifndef _FTP_FTPURL_HXX_
35 #define _FTP_FTPURL_HXX_
36 
37 #include "curl.hxx"
38 #include <curl/easy.h>
39 #include <com/sun/star/io/XOutputStream.hpp>
40 
41 #include <stdio.h>
42 #include <rtl/ustring.hxx>
43 #include <osl/mutex.hxx>
44 #include <vector>
45 
46 #include "ftpdirp.hxx"
47 #include "ftpcfunc.hxx"
48 
49 namespace ftp {
50 
51     /** Forward declarations.
52      */
53 
54     class FTPHandleProvider;
55 
56 
57     enum FTPErrors { FILE_EXIST_DURING_INSERT = CURL_LAST +1,
58                      FOLDER_EXIST_DURING_INSERT,
59                      FOLDER_MIGHT_EXIST_DURING_INSERT,
60                      FILE_MIGHT_EXIST_DURING_INSERT };
61 
62 
63     class malformed_exception { };
64 
65 
66     class curl_exception
67     {
68     public:
69 
70         curl_exception(sal_Int32 err)
71             : n_err(err) { }
72 
73         sal_Int32 code() const { return n_err; }
74 
75 
76     private:
77 
78         sal_Int32 n_err;
79     };
80 
81     class CurlInput {
82 
83     public:
84 
85         // returns the number of bytes actually read
86         virtual sal_Int32 read(sal_Int8 *dest,sal_Int32 nBytesRequested) = 0;
87     };
88 
89 
90     class FTPURL
91     {
92     public:
93 
94         FTPURL(
95             const rtl::OUString& aIdent,
96             FTPHandleProvider* pFCP = 0
97         )
98             throw(
99                 malformed_exception
100             );
101 
102         FTPURL(const FTPURL& r);
103 
104         ~FTPURL();
105 
106         rtl::OUString host() const { return m_aHost; }
107 
108         rtl::OUString port() const { return m_aPort; }
109 
110         rtl::OUString username() const { return m_aUsername; }
111 
112         /** This returns the URL, but cleaned from
113          *  unnessary ellipses.
114          */
115 
116         rtl::OUString ident(bool withslash,bool internal) const;
117 
118         /** returns the parent url.
119          */
120 
121         rtl::OUString parent(bool internal = false) const;
122 
123         /** sets the unencoded title */
124         void child(const rtl::OUString& title);
125 
126         /** returns the unencoded title */
127         rtl::OUString child(void) const;
128 
129         std::vector<FTPDirentry> list(sal_Int16 nMode) const
130             throw(curl_exception);
131 
132         // returns a pointer to an open tempfile,
133         // seeked to the beginning of.
134         FILE* open() throw(curl_exception);
135 
136         FTPDirentry direntry() const throw(curl_exception);
137 
138         void insert(bool ReplaceExisting,void* stream) const
139             throw(curl_exception);
140 
141         void mkdir(bool ReplaceExisting) const
142             throw(curl_exception);
143 
144         rtl::OUString ren(const rtl::OUString& NewTitle)
145             throw(curl_exception);
146 
147         void del() const
148             throw(curl_exception);
149 
150 
151     private:
152 
153         osl::Mutex m_mutex;
154 
155         FTPHandleProvider *m_pFCP;
156 
157         mutable rtl::OUString m_aUsername;
158         bool m_bShowPassword;
159         mutable rtl::OUString m_aHost;
160         mutable rtl::OUString m_aPort;
161         mutable rtl::OUString m_aType;
162 
163         /** Contains the encoded pathsegments of the url.
164          */
165         std::vector<rtl::OUString> m_aPathSegmentVec;
166 
167         void parse(const rtl::OUString& url)
168             throw(
169                 malformed_exception
170             );
171 
172         rtl::OUString net_title() const throw(curl_exception);
173     };
174 
175 }
176 
177 
178 #endif
179