xref: /aoo42x/main/ucb/source/ucp/ftp/ftpdirp.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 #ifndef _FTP_FTPDIRP_HXX_
34 #define _FTP_FTPDIRP_HXX_
35 
36 #include <osl/time.h>
37 #include <rtl/ustring.hxx>
38 #include <com/sun/star/util/DateTime.hpp>
39 
40 
41 namespace ftp {
42 
43     /*========================================================================
44      *
45      * the DateTime structure
46      *
47      *======================================================================*/
48 
49     struct DateTime
50         : public com::sun::star::util::DateTime
51     {
52         DateTime(const sal_uInt16& hundredthSeconds,
53                  const sal_uInt16& seconds,
54                  const sal_uInt16& minutes,
55                  const sal_uInt16& hours,
56                  const sal_uInt16& day,
57                  const sal_uInt16& month,
58                  const sal_uInt16& year) SAL_THROW( () )
59                      : com::sun::star::util::DateTime(hundredthSeconds,
60                                                       seconds,
61                                                       minutes,
62                                                       hours,
63                                                       day,
64                                                       month,
65                                                       year) { }
66 
67         void SetYear(sal_uInt16 year) { Year = year; }
68         void SetMonth(sal_uInt16 month) { Month = month; }
69         void SetDay(sal_uInt16 day) { Day = day; }
70         // Only zero allowed and used for time-argument
71         void SetTime(sal_uInt16) { Hours = Minutes = Seconds = HundredthSeconds = 0; }
72         void SetHour(sal_uInt16 hours) { Hours = hours; }
73         void SetMin(sal_uInt16 minutes) { Minutes = minutes; }
74         void SetSec(sal_uInt16 seconds) { Seconds = seconds; }
75         void Set100Sec(sal_uInt16 hundredthSec) { HundredthSeconds = hundredthSec; }
76 
77         sal_uInt16 GetMonth(void) { return Month; }
78     };
79 
80 
81 
82 /*========================================================================
83  *
84  * the directory information structure
85  *
86  *======================================================================*/
87 
88     enum FTPDirentryMode { INETCOREFTP_FILEMODE_UNKNOWN = 0x00,
89                            INETCOREFTP_FILEMODE_READ = 0x01,
90                            INETCOREFTP_FILEMODE_WRITE = 0x02,
91                            INETCOREFTP_FILEMODE_ISDIR = 0x04,
92                            INETCOREFTP_FILEMODE_ISLINK = 0x08 };
93 
94     struct FTPDirentry
95     {
96         rtl::OUString                       m_aURL;
97         rtl::OUString                       m_aName;
98         DateTime                            m_aDate;
99         sal_uInt32                          m_nMode;
100         sal_uInt32                          m_nSize;
101 
102         FTPDirentry(void)
103             : m_aDate(0,0,0,0,0,0,0),
104               m_nMode(INETCOREFTP_FILEMODE_UNKNOWN),
105               m_nSize((sal_uInt32)(-1)) { }
106 
107         void clear() {
108             m_aURL = m_aName = rtl::OUString();
109             m_aDate = DateTime(0,0,0,0,0,0,0);
110             m_nMode = INETCOREFTP_FILEMODE_UNKNOWN;
111             m_nSize = sal_uInt32(-1);
112         }
113 
114         bool isDir() const {
115             return bool(m_nMode && INETCOREFTP_FILEMODE_ISDIR);
116         }
117 
118         bool isFile() const {
119             return ! bool(m_nMode && INETCOREFTP_FILEMODE_ISDIR);
120         }
121     };
122 
123 
124 /*========================================================================
125  *
126  * the directory parser
127  *
128  *======================================================================*/
129 
130 
131     class FTPDirectoryParser
132     {
133     public:
134         static sal_Bool parseDOS (
135             FTPDirentry &rEntry,
136             const sal_Char  *pBuffer );
137 
138         static sal_Bool parseVMS (
139             FTPDirentry &rEntry,
140             const sal_Char  *pBuffer );
141 
142         static sal_Bool parseUNIX (
143             FTPDirentry &rEntry,
144             const sal_Char  *pBuffer );
145 
146 
147     private:
148 
149         static sal_Bool parseUNIX_isSizeField (
150             const sal_Char *pStart,
151             const sal_Char *pEnd,
152             sal_uInt32     &rSize);
153 
154         static sal_Bool parseUNIX_isMonthField (
155             const sal_Char *pStart,
156             const sal_Char *pEnd,
157             DateTime& rDateTime);
158 
159         static sal_Bool parseUNIX_isDayField (
160             const sal_Char *pStart,
161             const sal_Char *pEnd,
162             DateTime& rDateTime);
163 
164         static sal_Bool parseUNIX_isYearTimeField (
165             const sal_Char *pStart,
166             const sal_Char *pEnd,
167             DateTime& rDateTime);
168 
169         static sal_Bool parseUNIX_isTime (
170             const sal_Char *pStart,
171             const sal_Char *pEnd,
172             sal_uInt16      nHour,
173             DateTime& rDateTime);
174 
175         static sal_Bool setYear (
176             DateTime& rDateTime,
177             sal_uInt16  nYear);
178 
179         static sal_Bool setPath (
180             rtl::OUString& rPath,
181             const sal_Char *value,
182             sal_Int32       length = -1);
183     };
184 
185 
186 }
187 
188 
189 #endif
190