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