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