reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
FileSystem.cxx
Go to the documentation of this file.
2#include "rutil/Logger.hxx"
3
4#include <sys/stat.h>
5
6#include "rutil/ResipAssert.h"
7using namespace resip;
8
9#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
10
11
13
14
16 : mPath(path)
17{
18}
19
20
21#ifndef WIN32
22// !jf! added this constructor since it was missing - don't know if it is correct
24{
25}
26
27
29{
30 resip_assert(!dir.getPath().empty());
31 //InfoLog(<< "FileSystem::Directory::iterator::iterator: " << dir.getPath());
32 mPath = dir.getPath();
33 if ((mNixDir = opendir( dir.getPath().c_str() )))
34 {
35 errno = 0;
36 mDirent = readdir(mNixDir);
37 if(errno != 0)
38 {
39 throw Exception("Failed readdir", __FILE__, __LINE__);
40 }
41 if (mDirent)
42 {
43 //InfoLog(<< "FileSystem::Directory::iterator::iterator, first file " << mFile);
44 mFile = mDirent->d_name;
45 mFullFilename = mPath + '/' + mFile;
46 }
47 }
48 else
49 {
50 mDirent = 0;
51 }
52}
53
54
56{
57 if (mNixDir)
58 {
59 closedir(mNixDir);
60 }
61}
62
63
66{
67 if (mDirent)
68 {
69 errno = 0;
70 mDirent = readdir(mNixDir);
71 if(errno != 0)
72 {
73 throw Exception("Failed readdir", __FILE__, __LINE__);
74 }
75 if (mDirent)
76 {
77 mFile = mDirent->d_name;
78 mFullFilename = mPath + '/' + mFile;
79 //InfoLog(<< "FileSystem::Directory::iterator::iterator, next file " << mFile);
80 }
81 }
82 return *this;
83}
84
85
86bool
88{
89 return !(*this == rhs);
90}
91
92
93bool
95{
96 if (mDirent && rhs.mDirent)
97 {
98 return **this == *rhs;
99 }
100
101 return mDirent == rhs.mDirent;
102}
103
104
105const Data&
107{
108 return mFile;
109}
110
111
112const Data*
114{
115 return &mFile;
116}
117
118bool
120{
121#if HAVE_STRUCT_DIRENT_D_TYPE
122 return mDirent->d_type == DT_DIR;
123#else
124 struct stat s;
125 StackLog(<<"calling stat() for " << mDirent->d_name);
126 if(stat(mFullFilename.c_str(), &s) < 0)
127 {
128 ErrLog(<<"Error calling stat() for " << mFullFilename.c_str() << ": " << strError(errno));
129 throw Exception("stat() failed", __FILE__, __LINE__);
130 }
131 return S_ISDIR(s.st_mode);
132#endif
133}
134
135int
137{
138 if(mkdir(mPath.c_str(), 0777) == -1)
139 {
140 return errno;
141 }
142 return 0;
143}
144
145#else
146
148 mWinSearch(0),
149 mIsDirectory(false)
150{
151}
152
153
155{
156 Data searchPath;
157 if (dir.getPath().empty() || dir.getPath().postfix("/") || dir.getPath().postfix("\\"))
158 {
159 searchPath = dir.getPath() + Data("*");
160 }
161 else
162 {
163 searchPath = dir.getPath() + Data("/*");
164 }
165 WIN32_FIND_DATAA fileData;
166 mWinSearch = FindFirstFileA( searchPath.c_str(), &fileData);
167
168 if (mWinSearch == INVALID_HANDLE_VALUE)
169 {
170 mWinSearch = 0;
171 }
172 else
173 {
174 mFile = fileData.cFileName;
175 mFullFilename = mPath + '/' + mFile;
176 mIsDirectory = (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
177 }
178}
179
180
182{
183 if (mWinSearch)
184 {
185 FindClose(mWinSearch);
186 }
187}
188
189
192{
193 WIN32_FIND_DATAA fileData;
194
195 if (!FindNextFileA(mWinSearch, &fileData))
196 {
197 if (GetLastError() == ERROR_NO_MORE_FILES)
198 {
199 FindClose(mWinSearch);
200 mWinSearch = 0;
201 }
202 }
203 else
204 {
205 mFile = fileData.cFileName;
206 mFullFilename = mPath + '/' + mFile;
207 mIsDirectory = (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
208 }
209 return *this;
210}
211
212
213bool
214FileSystem::Directory::iterator::operator!=(const iterator& rhs) const
215{
216 return !(*this == rhs);
217}
218
219
220bool
221FileSystem::Directory::iterator::operator==(const iterator& rhs) const
222{
223 if (mWinSearch && rhs.mWinSearch)
224 {
225 return **this == *rhs;
226 }
227 else
228 {
229 return mWinSearch == rhs.mWinSearch;
230 }
231}
232
233
234const Data&
236{
237 return mFile;
238}
239
240
241const Data*
243{
244 return &mFile;
245}
246
247bool
249{
250 return mIsDirectory;
251}
252
253int
255{
256 if(_mkdir(mPath.c_str()) == -1)
257 {
258 return (int)GetLastError();
259 }
260 return 0;
261}
262
263#endif
264
265
270
271
276
277/* ====================================================================
278 * The Vovida Software License, Version 1.0
279 *
280 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
281 *
282 * Redistribution and use in source and binary forms, with or without
283 * modification, are permitted provided that the following conditions
284 * are met:
285 *
286 * 1. Redistributions of source code must retain the above copyright
287 * notice, this list of conditions and the following disclaimer.
288 *
289 * 2. Redistributions in binary form must reproduce the above copyright
290 * notice, this list of conditions and the following disclaimer in
291 * the documentation and/or other materials provided with the
292 * distribution.
293 *
294 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
295 * and "Vovida Open Communication Application Library (VOCAL)" must
296 * not be used to endorse or promote products derived from this
297 * software without prior written permission. For written
298 * permission, please contact vocal@vovida.org.
299 *
300 * 4. Products derived from this software may not be called "VOCAL", nor
301 * may "VOCAL" appear in their name, without prior written
302 * permission of Vovida Networks, Inc.
303 *
304 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
305 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
306 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
307 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
308 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
309 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
310 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
311 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
312 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
313 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
314 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
315 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
316 * DAMAGE.
317 *
318 * ====================================================================
319 *
320 * This software consists of voluntary contributions made by Vovida
321 * Networks, Inc. and many individuals on behalf of Vovida Networks,
322 * Inc. For more information on Vovida Networks, Inc., please see
323 * <http://www.vovida.org/>.
324 *
325 */
static FileSystem::Directory::iterator staticEnd
#define StackLog(args_)
Definition Logger.hxx:125
#define ErrLog(args_)
Definition Logger.hxx:137
#define resip_assert(x)
This file needs to work for both C and C++ code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * c_str() const
Returns a null-terminated string representing.
Definition Data.cxx:1097
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
bool operator==(const iterator &rhs) const
bool operator!=(const iterator &rhs) const
const Data & getPath() const
Directory(const Data &path)
dcm! – add UnusedChecking(_enum) below;
std::string strError(int err)
Definition compat.hxx:274