mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 09:12:28 +02:00
removing old trunk files
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
//
|
||||
// ASCIIEncoding.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ASCIIEncoding.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: ASCIIEncoding
|
||||
//
|
||||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ASCIIEncoding.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const char* ASCIIEncoding::_names[] =
|
||||
{
|
||||
"ASCII",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap ASCIIEncoding::_charMap =
|
||||
{
|
||||
/* 00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
/* 10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
/* 20 */ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
/* 30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
/* 40 */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
/* 50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
/* 60 */ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
/* 70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
/* 80 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* 90 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* a0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* b0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* c0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* d0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* e0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* f0 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
};
|
||||
|
||||
|
||||
ASCIIEncoding::ASCIIEncoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ASCIIEncoding::~ASCIIEncoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char* ASCIIEncoding::canonicalName() const
|
||||
{
|
||||
return _names[0];
|
||||
}
|
||||
|
||||
|
||||
bool ASCIIEncoding::isA(const std::string& encodingName) const
|
||||
{
|
||||
for (const char** name = _names; *name; ++name)
|
||||
{
|
||||
if (Poco::icompare(encodingName, *name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap& ASCIIEncoding::characterMap() const
|
||||
{
|
||||
return _charMap;
|
||||
}
|
||||
|
||||
|
||||
int ASCIIEncoding::convert(const unsigned char* bytes) const
|
||||
{
|
||||
return _charMap[*bytes];
|
||||
}
|
||||
|
||||
|
||||
int ASCIIEncoding::convert(int ch, unsigned char* bytes, int length) const
|
||||
{
|
||||
if (ch >= 0 && ch <= 127)
|
||||
{
|
||||
if (bytes && length >= 1)
|
||||
*bytes = (unsigned char) ch;
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
int ASCIIEncoding::queryConvert(const unsigned char* bytes, int length) const
|
||||
{
|
||||
if (1 <= length)
|
||||
return _charMap [*bytes];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int ASCIIEncoding::sequenceLength(const unsigned char* bytes, int length) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// AbstractObserver.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/AbstractObserver.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Notifications
|
||||
// Module: NotificationCenter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AbstractObserver.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
AbstractObserver::AbstractObserver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractObserver::AbstractObserver(const AbstractObserver& observer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractObserver::~AbstractObserver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AbstractObserver& AbstractObserver::operator = (const AbstractObserver& observer)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,133 +0,0 @@
|
||||
//
|
||||
// ActiveDispatcher.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ActiveDispatcher.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: ActiveObjects
|
||||
//
|
||||
// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ActiveDispatcher.h"
|
||||
#include "Poco/Notification.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class MethodNotification: public Notification
|
||||
{
|
||||
public:
|
||||
MethodNotification(ActiveRunnableBase::Ptr pRunnable):
|
||||
_pRunnable(pRunnable)
|
||||
{
|
||||
}
|
||||
|
||||
ActiveRunnableBase::Ptr runnable() const
|
||||
{
|
||||
return _pRunnable;
|
||||
}
|
||||
|
||||
private:
|
||||
ActiveRunnableBase::Ptr _pRunnable;
|
||||
};
|
||||
|
||||
class StopNotification: public Notification
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
ActiveDispatcher::ActiveDispatcher()
|
||||
{
|
||||
_thread.start(*this);
|
||||
}
|
||||
|
||||
|
||||
ActiveDispatcher::ActiveDispatcher(Thread::Priority prio)
|
||||
{
|
||||
_thread.setPriority(prio);
|
||||
_thread.start(*this);
|
||||
}
|
||||
|
||||
|
||||
ActiveDispatcher::~ActiveDispatcher()
|
||||
{
|
||||
try
|
||||
{
|
||||
stop();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcher::start(ActiveRunnableBase::Ptr pRunnable)
|
||||
{
|
||||
poco_check_ptr (pRunnable);
|
||||
|
||||
_queue.enqueueNotification(new MethodNotification(pRunnable));
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcher::cancel()
|
||||
{
|
||||
_queue.clear();
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcher::run()
|
||||
{
|
||||
AutoPtr<Notification> pNf = _queue.waitDequeueNotification();
|
||||
while (pNf && !dynamic_cast<StopNotification*>(pNf.get()))
|
||||
{
|
||||
MethodNotification* pMethodNf = dynamic_cast<MethodNotification*>(pNf.get());
|
||||
poco_check_ptr (pMethodNf);
|
||||
ActiveRunnableBase::Ptr pRunnable = pMethodNf->runnable();
|
||||
pRunnable->duplicate(); // run will release
|
||||
pRunnable->run();
|
||||
pNf = _queue.waitDequeueNotification();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ActiveDispatcher::stop()
|
||||
{
|
||||
_queue.clear();
|
||||
_queue.wakeUpAll();
|
||||
_queue.enqueueNotification(new StopNotification);
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,211 +0,0 @@
|
||||
//
|
||||
// ArchiveStrategy.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ArchiveStrategy.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: FileChannel
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ArchiveStrategy.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/DeflatingStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/ActiveDispatcher.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/Void.h"
|
||||
#include "Poco/FileStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
//
|
||||
// ArchiveCompressor
|
||||
//
|
||||
|
||||
|
||||
class ArchiveCompressor: public ActiveDispatcher
|
||||
{
|
||||
public:
|
||||
ArchiveCompressor():
|
||||
compress(this, &ArchiveCompressor::compressImpl)
|
||||
{
|
||||
}
|
||||
|
||||
~ArchiveCompressor()
|
||||
{
|
||||
}
|
||||
|
||||
ActiveMethod<Void, std::string, ArchiveCompressor, ActiveStarter<ActiveDispatcher> > compress;
|
||||
|
||||
protected:
|
||||
Void compressImpl(const std::string& path)
|
||||
{
|
||||
std::string gzPath(path);
|
||||
gzPath.append(".gz");
|
||||
FileInputStream istr(path, std::ios::binary | std::ios::in);
|
||||
if (!istr.good()) throw OpenFileException(path);
|
||||
FileOutputStream ostr(gzPath, std::ios::binary | std::ios::out);
|
||||
if (ostr.good())
|
||||
{
|
||||
DeflatingOutputStream deflater(ostr, DeflatingStreamBuf::STREAM_GZIP);
|
||||
StreamCopier::copyStream(istr, deflater);
|
||||
deflater.close();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
File f(path);
|
||||
f.remove();
|
||||
}
|
||||
else throw CreateFileException(gzPath);
|
||||
return Void();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ArchiveStrategy
|
||||
//
|
||||
|
||||
|
||||
ArchiveStrategy::ArchiveStrategy():
|
||||
_compress(false),
|
||||
_pCompressor(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ArchiveStrategy::~ArchiveStrategy()
|
||||
{
|
||||
delete _pCompressor;
|
||||
}
|
||||
|
||||
|
||||
void ArchiveStrategy::compress(bool flag)
|
||||
{
|
||||
_compress = flag;
|
||||
}
|
||||
|
||||
|
||||
void ArchiveStrategy::moveFile(const std::string& oldPath, const std::string& newPath)
|
||||
{
|
||||
bool compressed = false;
|
||||
Path p(oldPath);
|
||||
File f(oldPath);
|
||||
if (!f.exists())
|
||||
{
|
||||
f = oldPath + ".gz";
|
||||
compressed = true;
|
||||
}
|
||||
std::string mvPath(newPath);
|
||||
if (_compress || compressed)
|
||||
mvPath.append(".gz");
|
||||
if (!_compress || compressed)
|
||||
{
|
||||
f.renameTo(mvPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
f.renameTo(newPath);
|
||||
if (!_pCompressor) _pCompressor = new ArchiveCompressor;
|
||||
_pCompressor->compress(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ArchiveStrategy::exists(const std::string& name)
|
||||
{
|
||||
File f(name);
|
||||
if (f.exists())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (_compress)
|
||||
{
|
||||
std::string gzName(name);
|
||||
gzName.append(".gz");
|
||||
File gzf(gzName);
|
||||
return gzf.exists();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ArchiveByNumberStrategy
|
||||
//
|
||||
|
||||
|
||||
ArchiveByNumberStrategy::ArchiveByNumberStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ArchiveByNumberStrategy::~ArchiveByNumberStrategy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogFile* ArchiveByNumberStrategy::archive(LogFile* pFile)
|
||||
{
|
||||
std::string basePath = pFile->path();
|
||||
delete pFile;
|
||||
int n = -1;
|
||||
std::string path;
|
||||
do
|
||||
{
|
||||
path = basePath;
|
||||
path.append(".");
|
||||
NumberFormatter::append(path, ++n);
|
||||
}
|
||||
while (exists(path));
|
||||
|
||||
while (n >= 0)
|
||||
{
|
||||
std::string oldPath = basePath;
|
||||
if (n > 0)
|
||||
{
|
||||
oldPath.append(".");
|
||||
NumberFormatter::append(oldPath, n - 1);
|
||||
}
|
||||
std::string newPath = basePath;
|
||||
newPath.append(".");
|
||||
NumberFormatter::append(newPath, n);
|
||||
moveFile(oldPath, newPath);
|
||||
--n;
|
||||
}
|
||||
return new LogFile(basePath);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,176 +0,0 @@
|
||||
//
|
||||
// Ascii.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Ascii.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Ascii
|
||||
//
|
||||
// Copyright (c) 2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Ascii.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const int Ascii::CHARACTER_PROPERTIES[128] =
|
||||
{
|
||||
/* 00 . */ ACP_CONTROL,
|
||||
/* 01 . */ ACP_CONTROL,
|
||||
/* 02 . */ ACP_CONTROL,
|
||||
/* 03 . */ ACP_CONTROL,
|
||||
/* 04 . */ ACP_CONTROL,
|
||||
/* 05 . */ ACP_CONTROL,
|
||||
/* 06 . */ ACP_CONTROL,
|
||||
/* 07 . */ ACP_CONTROL,
|
||||
/* 08 . */ ACP_CONTROL,
|
||||
/* 09 . */ ACP_CONTROL | ACP_SPACE,
|
||||
/* 0a . */ ACP_CONTROL | ACP_SPACE,
|
||||
/* 0b . */ ACP_CONTROL | ACP_SPACE,
|
||||
/* 0c . */ ACP_CONTROL | ACP_SPACE,
|
||||
/* 0d . */ ACP_CONTROL | ACP_SPACE,
|
||||
/* 0e . */ ACP_CONTROL,
|
||||
/* 0f . */ ACP_CONTROL,
|
||||
/* 10 . */ ACP_CONTROL,
|
||||
/* 11 . */ ACP_CONTROL,
|
||||
/* 12 . */ ACP_CONTROL,
|
||||
/* 13 . */ ACP_CONTROL,
|
||||
/* 14 . */ ACP_CONTROL,
|
||||
/* 15 . */ ACP_CONTROL,
|
||||
/* 16 . */ ACP_CONTROL,
|
||||
/* 17 . */ ACP_CONTROL,
|
||||
/* 18 . */ ACP_CONTROL,
|
||||
/* 19 . */ ACP_CONTROL,
|
||||
/* 1a . */ ACP_CONTROL,
|
||||
/* 1b . */ ACP_CONTROL,
|
||||
/* 1c . */ ACP_CONTROL,
|
||||
/* 1d . */ ACP_CONTROL,
|
||||
/* 1e . */ ACP_CONTROL,
|
||||
/* 1f . */ ACP_CONTROL,
|
||||
/* 20 */ ACP_SPACE | ACP_PRINT,
|
||||
/* 21 ! */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 22 " */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 23 # */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 24 $ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 25 % */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 26 & */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 27 ' */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 28 ( */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 29 ) */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2a * */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2b + */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2c , */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2d - */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2e . */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 2f / */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 30 0 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 31 1 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 32 2 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 33 3 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 34 4 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 35 5 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 36 6 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 37 7 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 38 8 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 39 9 */ ACP_DIGIT | ACP_HEXDIGIT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3a : */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3b ; */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3c < */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3d = */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3e > */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 3f ? */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 40 @ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 41 A */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 42 B */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 43 C */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 44 D */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 45 E */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 46 F */ ACP_HEXDIGIT | ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 47 G */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 48 H */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 49 I */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4a J */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4b K */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4c L */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4d M */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4e N */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 4f O */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 50 P */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 51 Q */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 52 R */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 53 S */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 54 T */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 55 U */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 56 V */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 57 W */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 58 X */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 59 Y */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5a Z */ ACP_ALPHA | ACP_UPPER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5b [ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5c \ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5d ] */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5e ^ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 5f _ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 60 ` */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 61 a */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 62 b */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 63 c */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 64 d */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 65 e */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 66 f */ ACP_HEXDIGIT | ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 67 g */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 68 h */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 69 i */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6a j */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6b k */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6c l */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6d m */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6e n */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 6f o */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 70 p */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 71 q */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 72 r */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 73 s */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 74 t */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 75 u */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 76 v */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 77 w */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 78 x */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 79 y */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7a z */ ACP_ALPHA | ACP_LOWER | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7b { */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7c | */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7d } */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7e ~ */ ACP_PUNCT | ACP_GRAPH | ACP_PRINT,
|
||||
/* 7f . */ ACP_CONTROL
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,183 +0,0 @@
|
||||
//
|
||||
// AsyncChannel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/AsyncChannel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: AsyncChannel
|
||||
//
|
||||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AsyncChannel.h"
|
||||
#include "Poco/Notification.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/LoggingRegistry.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class MessageNotification: public Notification
|
||||
{
|
||||
public:
|
||||
MessageNotification(const Message& msg)
|
||||
{
|
||||
_msg = msg;
|
||||
}
|
||||
|
||||
~MessageNotification()
|
||||
{
|
||||
}
|
||||
|
||||
const Message& message() const
|
||||
{
|
||||
return _msg;
|
||||
}
|
||||
|
||||
private:
|
||||
Message _msg;
|
||||
};
|
||||
|
||||
|
||||
AsyncChannel::AsyncChannel(Channel* pChannel, Thread::Priority prio):
|
||||
_pChannel(pChannel),
|
||||
_thread("AsyncChannel")
|
||||
{
|
||||
if (_pChannel) _pChannel->duplicate();
|
||||
_thread.setPriority(prio);
|
||||
}
|
||||
|
||||
|
||||
AsyncChannel::~AsyncChannel()
|
||||
{
|
||||
close();
|
||||
if (_pChannel) _pChannel->release();
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::setChannel(Channel* pChannel)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_channelMutex);
|
||||
|
||||
if (_pChannel) _pChannel->release();
|
||||
_pChannel = pChannel;
|
||||
if (_pChannel) _pChannel->duplicate();
|
||||
}
|
||||
|
||||
|
||||
Channel* AsyncChannel::getChannel() const
|
||||
{
|
||||
return _pChannel;
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::open()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_threadMutex);
|
||||
|
||||
if (!_thread.isRunning())
|
||||
_thread.start(*this);
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::close()
|
||||
{
|
||||
if (_thread.isRunning())
|
||||
{
|
||||
while (!_queue.empty()) Thread::sleep(100);
|
||||
|
||||
do
|
||||
{
|
||||
_queue.wakeUpAll();
|
||||
}
|
||||
while (!_thread.tryJoin(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::log(const Message& msg)
|
||||
{
|
||||
open();
|
||||
|
||||
_queue.enqueueNotification(new MessageNotification(msg));
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (name == "channel")
|
||||
setChannel(LoggingRegistry::defaultRegistry().channelForName(value));
|
||||
else if (name == "priority")
|
||||
setPriority(value);
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::run()
|
||||
{
|
||||
AutoPtr<Notification> nf = _queue.waitDequeueNotification();
|
||||
while (nf)
|
||||
{
|
||||
MessageNotification* pNf = dynamic_cast<MessageNotification*>(nf.get());
|
||||
{
|
||||
FastMutex::ScopedLock lock(_channelMutex);
|
||||
|
||||
if (pNf && _pChannel) _pChannel->log(pNf->message());
|
||||
}
|
||||
nf = _queue.waitDequeueNotification();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AsyncChannel::setPriority(const std::string& value)
|
||||
{
|
||||
Thread::Priority prio = Thread::PRIO_NORMAL;
|
||||
|
||||
if (value == "lowest")
|
||||
prio = Thread::PRIO_LOWEST;
|
||||
else if (value == "low")
|
||||
prio = Thread::PRIO_LOW;
|
||||
else if (value == "normal")
|
||||
prio = Thread::PRIO_NORMAL;
|
||||
else if (value == "high")
|
||||
prio = Thread::PRIO_HIGH;
|
||||
else if (value == "highest")
|
||||
prio = Thread::PRIO_HIGHEST;
|
||||
else
|
||||
throw InvalidArgumentException("thread priority", value);
|
||||
|
||||
_thread.setPriority(prio);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,212 +0,0 @@
|
||||
//
|
||||
// AtomicCounter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/AtomicCounter.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: AtomicCounter
|
||||
//
|
||||
// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/AtomicCounter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
#if POCO_OS == POCO_OS_WINDOWS_NT
|
||||
//
|
||||
// Windows
|
||||
//
|
||||
AtomicCounter::AtomicCounter():
|
||||
_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
|
||||
_counter(initialValue)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
|
||||
_counter(counter.value())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::~AtomicCounter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
|
||||
{
|
||||
InterlockedExchange(&_counter, counter.value());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
{
|
||||
InterlockedExchange(&_counter, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
//
|
||||
// Mac OS X
|
||||
//
|
||||
AtomicCounter::AtomicCounter():
|
||||
_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
|
||||
_counter(initialValue)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
|
||||
_counter(counter.value())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::~AtomicCounter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
|
||||
{
|
||||
_counter = counter.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
{
|
||||
_counter = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#elif defined(POCO_HAVE_GCC_ATOMICS)
|
||||
//
|
||||
// GCC 4.1+ atomic builtins.
|
||||
//
|
||||
AtomicCounter::AtomicCounter():
|
||||
_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue):
|
||||
_counter(initialValue)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(const AtomicCounter& counter):
|
||||
_counter(counter.value())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::~AtomicCounter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
|
||||
{
|
||||
__sync_lock_test_and_set(&_counter, counter.value());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
{
|
||||
__sync_lock_test_and_set(&_counter, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
//
|
||||
// Generic implementation based on FastMutex
|
||||
//
|
||||
AtomicCounter::AtomicCounter()
|
||||
{
|
||||
_counter.value = 0;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(AtomicCounter::ValueType initialValue)
|
||||
{
|
||||
_counter.value = initialValue;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::AtomicCounter(const AtomicCounter& counter)
|
||||
{
|
||||
_counter.value = counter.value();
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter::~AtomicCounter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_counter.mutex);
|
||||
_counter.value = counter.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_counter.mutex);
|
||||
_counter.value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_OS
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,158 +0,0 @@
|
||||
//
|
||||
// Base64Decoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Base64Decoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base64
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Base64Decoder.h"
|
||||
#include "Poco/Base64Encoder.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
unsigned char Base64DecoderBuf::IN_ENCODING[256];
|
||||
bool Base64DecoderBuf::IN_ENCODING_INIT = false;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static FastMutex mutex;
|
||||
}
|
||||
|
||||
|
||||
Base64DecoderBuf::Base64DecoderBuf(std::istream& istr):
|
||||
_groupLength(0),
|
||||
_groupIndex(0),
|
||||
_buf(*istr.rdbuf())
|
||||
{
|
||||
FastMutex::ScopedLock lock(mutex);
|
||||
if (!IN_ENCODING_INIT)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(IN_ENCODING); i++)
|
||||
{
|
||||
IN_ENCODING[i] = 0xFF;
|
||||
}
|
||||
for (unsigned i = 0; i < sizeof(Base64EncoderBuf::OUT_ENCODING); i++)
|
||||
{
|
||||
IN_ENCODING[Base64EncoderBuf::OUT_ENCODING[i]] = i;
|
||||
}
|
||||
IN_ENCODING[static_cast<unsigned char>('=')] = '\0';
|
||||
IN_ENCODING_INIT = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Base64DecoderBuf::~Base64DecoderBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Base64DecoderBuf::readFromDevice()
|
||||
{
|
||||
if (_groupIndex < _groupLength)
|
||||
{
|
||||
return _group[_groupIndex++];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char buffer[4];
|
||||
int c;
|
||||
if ((c = readOne()) == -1) return -1;
|
||||
buffer[0] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[0]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[1] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[1]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[2] = c;
|
||||
if (IN_ENCODING[buffer[2]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[3] = c;
|
||||
if (IN_ENCODING[buffer[3]] == 0xFF) throw DataFormatException();
|
||||
|
||||
_group[0] = (IN_ENCODING[buffer[0]] << 2) | (IN_ENCODING[buffer[1]] >> 4);
|
||||
_group[1] = ((IN_ENCODING[buffer[1]] & 0x0F) << 4) | (IN_ENCODING[buffer[2]] >> 2);
|
||||
_group[2] = (IN_ENCODING[buffer[2]] << 6) | IN_ENCODING[buffer[3]];
|
||||
|
||||
if (buffer[2] == '=')
|
||||
_groupLength = 1;
|
||||
else if (buffer[3] == '=')
|
||||
_groupLength = 2;
|
||||
else
|
||||
_groupLength = 3;
|
||||
_groupIndex = 1;
|
||||
return _group[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Base64DecoderBuf::readOne()
|
||||
{
|
||||
int ch = _buf.sbumpc();
|
||||
while (ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n')
|
||||
ch = _buf.sbumpc();
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
Base64DecoderIOS::Base64DecoderIOS(std::istream& istr): _buf(istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
Base64DecoderIOS::~Base64DecoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base64DecoderBuf* Base64DecoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
Base64Decoder::Base64Decoder(std::istream& istr): Base64DecoderIOS(istr), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base64Decoder::~Base64Decoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,184 +0,0 @@
|
||||
//
|
||||
// Base64Encoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Base64Encoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base64
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Base64Encoder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const unsigned char Base64EncoderBuf::OUT_ENCODING[64] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
|
||||
Base64EncoderBuf::Base64EncoderBuf(std::ostream& ostr):
|
||||
_groupLength(0),
|
||||
_pos(0),
|
||||
_lineLength(72),
|
||||
_buf(*ostr.rdbuf())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base64EncoderBuf::~Base64EncoderBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Base64EncoderBuf::setLineLength(int lineLength)
|
||||
{
|
||||
_lineLength = lineLength;
|
||||
}
|
||||
|
||||
|
||||
int Base64EncoderBuf::getLineLength() const
|
||||
{
|
||||
return _lineLength;
|
||||
}
|
||||
|
||||
|
||||
int Base64EncoderBuf::writeToDevice(char c)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
_group[_groupLength++] = (unsigned char) c;
|
||||
if (_groupLength == 3)
|
||||
{
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 2;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x03) << 4) | (_group[1] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x0F) << 2) | (_group[2] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = _group[2] & 0x3F;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
_pos += 4;
|
||||
if (_lineLength > 0 && _pos >= _lineLength)
|
||||
{
|
||||
if (_buf.sputc('\r') == eof) return eof;
|
||||
if (_buf.sputc('\n') == eof) return eof;
|
||||
_pos = 0;
|
||||
}
|
||||
_groupLength = 0;
|
||||
}
|
||||
return charToInt(c);
|
||||
}
|
||||
|
||||
|
||||
int Base64EncoderBuf::close()
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
if (sync() == eof) return eof;
|
||||
if (_groupLength == 1)
|
||||
{
|
||||
_group[1] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 2;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x03) << 4) | (_group[1] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
}
|
||||
else if (_groupLength == 2)
|
||||
{
|
||||
_group[2] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 2;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x03) << 4) | (_group[1] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x0F) << 2) | (_group[2] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
}
|
||||
_groupLength = 0;
|
||||
return _buf.pubsync();
|
||||
}
|
||||
|
||||
|
||||
Base64EncoderIOS::Base64EncoderIOS(std::ostream& ostr): _buf(ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
Base64EncoderIOS::~Base64EncoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Base64EncoderIOS::close()
|
||||
{
|
||||
return _buf.close();
|
||||
}
|
||||
|
||||
|
||||
Base64EncoderBuf* Base64EncoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
Base64Encoder::Base64Encoder(std::ostream& ostr): Base64EncoderIOS(ostr), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base64Encoder::~Base64Encoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,309 +0,0 @@
|
||||
//
|
||||
// BinaryReader.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/BinaryReader.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: BinaryReaderWriter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/BinaryReader.h"
|
||||
#include "Poco/ByteOrder.h"
|
||||
#include "Poco/TextEncoding.h"
|
||||
#include "Poco/TextConverter.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
BinaryReader::BinaryReader(std::istream& istr, StreamByteOrder byteOrder):
|
||||
_istr(istr),
|
||||
_pTextConverter(0)
|
||||
{
|
||||
#if defined(POCO_ARCH_BIG_ENDIAN)
|
||||
_flipBytes = (byteOrder == LITTLE_ENDIAN_BYTE_ORDER);
|
||||
#else
|
||||
_flipBytes = (byteOrder == BIG_ENDIAN_BYTE_ORDER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BinaryReader::BinaryReader(std::istream& istr, TextEncoding& encoding, StreamByteOrder byteOrder):
|
||||
_istr(istr),
|
||||
_pTextConverter(new TextConverter(encoding, Poco::TextEncoding::global()))
|
||||
{
|
||||
#if defined(POCO_ARCH_BIG_ENDIAN)
|
||||
_flipBytes = (byteOrder == LITTLE_ENDIAN_BYTE_ORDER);
|
||||
#else
|
||||
_flipBytes = (byteOrder == BIG_ENDIAN_BYTE_ORDER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BinaryReader::~BinaryReader()
|
||||
{
|
||||
delete _pTextConverter;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (bool& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (char& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (unsigned char& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (signed char& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (short& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (unsigned short& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (int& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (unsigned int& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (long& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
#if defined(POCO_LONG_IS_64_BIT)
|
||||
if (_flipBytes) value = ByteOrder::flipBytes((Int64) value);
|
||||
#else
|
||||
if (_flipBytes) value = ByteOrder::flipBytes((Int32) value);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (unsigned long& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
#if defined(POCO_LONG_IS_64_BIT)
|
||||
if (_flipBytes) value = ByteOrder::flipBytes((UInt64) value);
|
||||
#else
|
||||
if (_flipBytes) value = ByteOrder::flipBytes((UInt32) value);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (float& value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
char* ptr = (char*) &value;
|
||||
ptr += sizeof(value);
|
||||
for (unsigned i = 0; i < sizeof(value); ++i)
|
||||
_istr.read(--ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (double& value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
char* ptr = (char*) &value;
|
||||
ptr += sizeof(value);
|
||||
for (unsigned i = 0; i < sizeof(value); ++i)
|
||||
_istr.read(--ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64) && !defined(POCO_LONG_IS_64_BIT)
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (Int64& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (UInt64& value)
|
||||
{
|
||||
_istr.read((char*) &value, sizeof(value));
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
BinaryReader& BinaryReader::operator >> (std::string& value)
|
||||
{
|
||||
UInt32 size = 0;
|
||||
read7BitEncoded(size);
|
||||
value.clear();
|
||||
if (!_istr.good()) return *this;
|
||||
value.reserve(size);
|
||||
while (size--)
|
||||
{
|
||||
char c;
|
||||
if (!_istr.read(&c, 1).good()) break;
|
||||
value += c;
|
||||
}
|
||||
if (_pTextConverter)
|
||||
{
|
||||
std::string converted;
|
||||
_pTextConverter->convert(value, converted);
|
||||
std::swap(value, converted);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void BinaryReader::read7BitEncoded(UInt32& value)
|
||||
{
|
||||
char c;
|
||||
value = 0;
|
||||
int s = 0;
|
||||
do
|
||||
{
|
||||
c = 0;
|
||||
_istr.read(&c, 1);
|
||||
UInt32 x = (c & 0x7F);
|
||||
x <<= s;
|
||||
value += x;
|
||||
s += 7;
|
||||
}
|
||||
while (c & 0x80);
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
|
||||
void BinaryReader::read7BitEncoded(UInt64& value)
|
||||
{
|
||||
char c;
|
||||
value = 0;
|
||||
int s = 0;
|
||||
do
|
||||
{
|
||||
c = 0;
|
||||
_istr.read(&c, 1);
|
||||
UInt64 x = (c & 0x7F);
|
||||
x <<= s;
|
||||
value += x;
|
||||
s += 7;
|
||||
}
|
||||
while (c & 0x80);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void BinaryReader::readRaw(std::streamsize length, std::string& value)
|
||||
{
|
||||
value.clear();
|
||||
value.reserve(static_cast<std::string::size_type>(length));
|
||||
while (length--)
|
||||
{
|
||||
char c;
|
||||
if (!_istr.read(&c, 1).good()) break;
|
||||
value += c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BinaryReader::readRaw(char* buffer, std::streamsize length)
|
||||
{
|
||||
_istr.read(buffer, length);
|
||||
}
|
||||
|
||||
|
||||
void BinaryReader::readBOM()
|
||||
{
|
||||
UInt16 bom;
|
||||
_istr.read((char*) &bom, sizeof(bom));
|
||||
_flipBytes = bom != 0xFEFF;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,373 +0,0 @@
|
||||
//
|
||||
// BinaryWriter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/BinaryWriter.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: BinaryReaderWriter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/BinaryWriter.h"
|
||||
#include "Poco/ByteOrder.h"
|
||||
#include "Poco/TextEncoding.h"
|
||||
#include "Poco/TextConverter.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
BinaryWriter::BinaryWriter(std::ostream& ostr, StreamByteOrder byteOrder):
|
||||
_ostr(ostr),
|
||||
_pTextConverter(0)
|
||||
{
|
||||
#if defined(POCO_ARCH_BIG_ENDIAN)
|
||||
_flipBytes = (byteOrder == LITTLE_ENDIAN_BYTE_ORDER);
|
||||
#else
|
||||
_flipBytes = (byteOrder == BIG_ENDIAN_BYTE_ORDER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter::BinaryWriter(std::ostream& ostr, TextEncoding& encoding, StreamByteOrder byteOrder):
|
||||
_ostr(ostr),
|
||||
_pTextConverter(new TextConverter(Poco::TextEncoding::global(), encoding))
|
||||
{
|
||||
#if defined(POCO_ARCH_BIG_ENDIAN)
|
||||
_flipBytes = (byteOrder == LITTLE_ENDIAN_BYTE_ORDER);
|
||||
#else
|
||||
_flipBytes = (byteOrder == BIG_ENDIAN_BYTE_ORDER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter::~BinaryWriter()
|
||||
{
|
||||
delete _pTextConverter;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (bool value)
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (char value)
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (unsigned char value)
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (signed char value)
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (short value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
short fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (unsigned short value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
unsigned short fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (int value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
int fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (unsigned int value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
unsigned int fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (long value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
#if defined(POCO_LONG_IS_64_BIT)
|
||||
long fValue = ByteOrder::flipBytes((Int64) value);
|
||||
#else
|
||||
long fValue = ByteOrder::flipBytes((Int32) value);
|
||||
#endif
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (unsigned long value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
#if defined(POCO_LONG_IS_64_BIT)
|
||||
long fValue = ByteOrder::flipBytes((UInt64) value);
|
||||
#else
|
||||
long fValue = ByteOrder::flipBytes((UInt32) value);
|
||||
#endif
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (float value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
const char* ptr = (const char*) &value;
|
||||
ptr += sizeof(value);
|
||||
for (unsigned i = 0; i < sizeof(value); ++i)
|
||||
_ostr.write(--ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (double value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
const char* ptr = (const char*) &value;
|
||||
ptr += sizeof(value);
|
||||
for (unsigned i = 0; i < sizeof(value); ++i)
|
||||
_ostr.write(--ptr, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64) && !defined(POCO_LONG_IS_64_BIT)
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (Int64 value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
Int64 fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (UInt64 value)
|
||||
{
|
||||
if (_flipBytes)
|
||||
{
|
||||
UInt64 fValue = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &fValue, sizeof(fValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (const std::string& value)
|
||||
{
|
||||
if (_pTextConverter)
|
||||
{
|
||||
std::string converted;
|
||||
_pTextConverter->convert(value, converted);
|
||||
UInt32 length = (UInt32) converted.size();
|
||||
write7BitEncoded(length);
|
||||
_ostr.write(converted.data(), length);
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 length = (UInt32) value.size();
|
||||
write7BitEncoded(length);
|
||||
_ostr.write(value.data(), length);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
BinaryWriter& BinaryWriter::operator << (const char* value)
|
||||
{
|
||||
poco_check_ptr (value);
|
||||
|
||||
if (_pTextConverter)
|
||||
{
|
||||
std::string converted;
|
||||
_pTextConverter->convert(value, static_cast<int>(std::strlen(value)), converted);
|
||||
UInt32 length = (UInt32) converted.size();
|
||||
write7BitEncoded(length);
|
||||
_ostr.write(converted.data(), length);
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 length = static_cast<UInt32>(std::strlen(value));
|
||||
write7BitEncoded(length);
|
||||
_ostr.write(value, length);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void BinaryWriter::write7BitEncoded(UInt32 value)
|
||||
{
|
||||
do
|
||||
{
|
||||
unsigned char c = (unsigned char) (value & 0x7F);
|
||||
value >>= 7;
|
||||
if (value) c |= 0x80;
|
||||
_ostr.write((const char*) &c, 1);
|
||||
}
|
||||
while (value);
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
|
||||
|
||||
void BinaryWriter::write7BitEncoded(UInt64 value)
|
||||
{
|
||||
do
|
||||
{
|
||||
unsigned char c = (unsigned char) (value & 0x7F);
|
||||
value >>= 7;
|
||||
if (value) c |= 0x80;
|
||||
_ostr.write((const char*) &c, 1);
|
||||
}
|
||||
while (value);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void BinaryWriter::writeRaw(const std::string& rawData)
|
||||
{
|
||||
_ostr.write(rawData.data(), (std::streamsize) rawData.length());
|
||||
}
|
||||
|
||||
|
||||
void BinaryWriter::writeRaw(const char* buffer, std::streamsize length)
|
||||
{
|
||||
_ostr.write(buffer, length);
|
||||
}
|
||||
|
||||
|
||||
void BinaryWriter::writeBOM()
|
||||
{
|
||||
UInt16 value = 0xFEFF;
|
||||
if (_flipBytes) value = ByteOrder::flipBytes(value);
|
||||
_ostr.write((const char*) &value, sizeof(value));
|
||||
}
|
||||
|
||||
|
||||
void BinaryWriter::flush()
|
||||
{
|
||||
_ostr.flush();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,103 +0,0 @@
|
||||
//
|
||||
// Bugcheck.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Bugcheck.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Bugcheck
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Debugger.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void Bugcheck::assertion(const char* cond, const char* file, int line)
|
||||
{
|
||||
Debugger::enter(std::string("Assertion violation: ") + cond, file, line);
|
||||
throw AssertionViolationException(what(cond, file, line));
|
||||
}
|
||||
|
||||
|
||||
void Bugcheck::nullPointer(const char* ptr, const char* file, int line)
|
||||
{
|
||||
Debugger::enter(std::string("NULL pointer: ") + ptr, file, line);
|
||||
throw NullPointerException(what(ptr, file, line));
|
||||
}
|
||||
|
||||
|
||||
void Bugcheck::bugcheck(const char* file, int line)
|
||||
{
|
||||
Debugger::enter("Bugcheck", file, line);
|
||||
throw BugcheckException(what(0, file, line));
|
||||
}
|
||||
|
||||
|
||||
void Bugcheck::bugcheck(const char* msg, const char* file, int line)
|
||||
{
|
||||
std::string m("Bugcheck");
|
||||
if (msg)
|
||||
{
|
||||
m.append(": ");
|
||||
m.append(msg);
|
||||
}
|
||||
Debugger::enter(m, file, line);
|
||||
throw BugcheckException(what(msg, file, line));
|
||||
}
|
||||
|
||||
|
||||
void Bugcheck::debugger(const char* file, int line)
|
||||
{
|
||||
Debugger::enter(file, line);
|
||||
}
|
||||
|
||||
|
||||
void Bugcheck::debugger(const char* msg, const char* file, int line)
|
||||
{
|
||||
Debugger::enter(msg, file, line);
|
||||
}
|
||||
|
||||
|
||||
std::string Bugcheck::what(const char* msg, const char* file, int line)
|
||||
{
|
||||
std::ostringstream str;
|
||||
if (msg) str << msg << " ";
|
||||
str << "in file \"" << file << "\", line " << line;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// ByteOrder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ByteOrder.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: ByteOrder
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ByteOrder.h"
|
||||
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// Channel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Channel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Channel
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Channel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Channel::Channel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Channel::~Channel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Channel::open()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Channel::close()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Channel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
throw PropertyNotSupportedException(name);
|
||||
}
|
||||
|
||||
|
||||
std::string Channel::getProperty(const std::string& name) const
|
||||
{
|
||||
throw PropertyNotSupportedException(name);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,80 +0,0 @@
|
||||
//
|
||||
// Checksum.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Checksum.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Checksum
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Checksum.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <zlib.h>
|
||||
#else
|
||||
#include "Poco/zlib.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Checksum::Checksum():
|
||||
_type(TYPE_CRC32),
|
||||
_value(crc32(0L, Z_NULL, 0))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Checksum::Checksum(Type t):
|
||||
_type(t),
|
||||
_value(0)
|
||||
{
|
||||
if (t == TYPE_CRC32)
|
||||
_value = crc32(0L, Z_NULL, 0);
|
||||
else
|
||||
_value = adler32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
Checksum::~Checksum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Checksum::update(const char* data, unsigned length)
|
||||
{
|
||||
if (_type == TYPE_ADLER32)
|
||||
_value = adler32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
else
|
||||
_value = crc32(_value, reinterpret_cast<const Bytef*>(data), length);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,101 +0,0 @@
|
||||
//
|
||||
// Condition.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Condition.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Condition
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Condition.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Condition::Condition()
|
||||
{
|
||||
}
|
||||
|
||||
Condition::~Condition()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Condition::signal()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_waitQueue.empty())
|
||||
{
|
||||
_waitQueue.front()->set();
|
||||
dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Condition::broadcast()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
(*it)->set();
|
||||
}
|
||||
_waitQueue.clear();
|
||||
}
|
||||
|
||||
|
||||
void Condition::enqueue(Event& event)
|
||||
{
|
||||
_waitQueue.push_back(&event);
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue()
|
||||
{
|
||||
_waitQueue.pop_front();
|
||||
}
|
||||
|
||||
|
||||
void Condition::dequeue(Event& event)
|
||||
{
|
||||
for (WaitQueue::iterator it = _waitQueue.begin(); it != _waitQueue.end(); ++it)
|
||||
{
|
||||
if (*it == &event)
|
||||
{
|
||||
_waitQueue.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// Configurable.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Configurable.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Configurable
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Configurable.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Configurable::Configurable()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Configurable::~Configurable()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// ConsoleChannel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ConsoleChannel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: ConsoleChannel
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ConsoleChannel.h"
|
||||
#include "Poco/Message.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FastMutex ConsoleChannel::_mutex;
|
||||
|
||||
|
||||
ConsoleChannel::ConsoleChannel(): _str(std::clog)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConsoleChannel::ConsoleChannel(std::ostream& str): _str(str)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConsoleChannel::~ConsoleChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ConsoleChannel::log(const Message& msg)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_str << msg.getText() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,185 +0,0 @@
|
||||
//
|
||||
// CountingStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/CountingStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: CountingStream
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/CountingStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
CountingStreamBuf::CountingStreamBuf():
|
||||
_pIstr(0),
|
||||
_pOstr(0),
|
||||
_chars(0),
|
||||
_lines(0),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingStreamBuf::CountingStreamBuf(std::istream& istr):
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_chars(0),
|
||||
_lines(0),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingStreamBuf::CountingStreamBuf(std::ostream& ostr):
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_chars(0),
|
||||
_lines(0),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingStreamBuf::~CountingStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CountingStreamBuf::readFromDevice()
|
||||
{
|
||||
if (_pIstr)
|
||||
{
|
||||
int c = _pIstr->get();
|
||||
if (c != -1)
|
||||
{
|
||||
++_chars;
|
||||
if (_pos++ == 0) ++_lines;
|
||||
if (c == '\n') _pos = 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int CountingStreamBuf::writeToDevice(char c)
|
||||
{
|
||||
++_chars;
|
||||
if (_pos++ == 0) ++_lines;
|
||||
if (c == '\n') _pos = 0;
|
||||
if (_pOstr) _pOstr->put(c);
|
||||
return charToInt(c);
|
||||
}
|
||||
|
||||
|
||||
void CountingStreamBuf::reset()
|
||||
{
|
||||
_chars = 0;
|
||||
_lines = 0;
|
||||
_pos = 0;
|
||||
}
|
||||
|
||||
|
||||
void CountingStreamBuf::setCurrentLineNumber(int line)
|
||||
{
|
||||
_lines = line;
|
||||
}
|
||||
|
||||
|
||||
CountingIOS::CountingIOS()
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
CountingIOS::CountingIOS(std::istream& istr): _buf(istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
CountingIOS::CountingIOS(std::ostream& ostr): _buf(ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
CountingIOS::~CountingIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CountingIOS::reset()
|
||||
{
|
||||
_buf.reset();
|
||||
}
|
||||
|
||||
|
||||
void CountingIOS::setCurrentLineNumber(int line)
|
||||
{
|
||||
_buf.setCurrentLineNumber(line);
|
||||
}
|
||||
|
||||
|
||||
CountingStreamBuf* CountingIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
CountingInputStream::CountingInputStream(std::istream& istr): CountingIOS(istr), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingInputStream::~CountingInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingOutputStream::CountingOutputStream(): std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingOutputStream::CountingOutputStream(std::ostream& ostr): CountingIOS(ostr), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CountingOutputStream::~CountingOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,423 +0,0 @@
|
||||
//
|
||||
// DateTime.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DateTime.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: DateTime
|
||||
// Module: DateTime
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
inline double DateTime::toJulianDay(Timestamp::UtcTimeVal utcTime)
|
||||
{
|
||||
double utcDays = double(utcTime)/864000000000.0;
|
||||
return utcDays + 2299160.5; // first day of Gregorian reform (Oct 15 1582)
|
||||
}
|
||||
|
||||
|
||||
inline Timestamp::UtcTimeVal DateTime::toUtcTime(double julianDay)
|
||||
{
|
||||
return Timestamp::UtcTimeVal((julianDay - 2299160.5)*864000000000.0);
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime()
|
||||
{
|
||||
Timestamp now;
|
||||
_utcTime = now.utcTime();
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime(const Timestamp& timestamp):
|
||||
_utcTime(timestamp.utcTime())
|
||||
{
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond):
|
||||
_year(year),
|
||||
_month(month),
|
||||
_day(day),
|
||||
_hour(hour),
|
||||
_minute(minute),
|
||||
_second(second),
|
||||
_millisecond(millisecond),
|
||||
_microsecond(microsecond)
|
||||
{
|
||||
poco_assert (year >= 0 && year <= 9999);
|
||||
poco_assert (month >= 1 && month <= 12);
|
||||
poco_assert (day >= 1 && day <= daysOfMonth(year, month));
|
||||
poco_assert (hour >= 0 && hour <= 23);
|
||||
poco_assert (minute >= 0 && minute <= 59);
|
||||
poco_assert (second >= 0 && second <= 59);
|
||||
poco_assert (millisecond >= 0 && millisecond <= 999);
|
||||
poco_assert (microsecond >= 0 && microsecond <= 999);
|
||||
|
||||
_utcTime = toUtcTime(toJulianDay(year, month, day)) + 10*(hour*Timespan::HOURS + minute*Timespan::MINUTES + second*Timespan::SECONDS + millisecond*Timespan::MILLISECONDS + microsecond);
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime(double julianDay):
|
||||
_utcTime(toUtcTime(julianDay))
|
||||
{
|
||||
computeGregorian(julianDay);
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff):
|
||||
_utcTime(utcTime + diff*10)
|
||||
{
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
}
|
||||
|
||||
|
||||
DateTime::DateTime(const DateTime& dateTime):
|
||||
_utcTime(dateTime._utcTime),
|
||||
_year(dateTime._year),
|
||||
_month(dateTime._month),
|
||||
_day(dateTime._day),
|
||||
_hour(dateTime._hour),
|
||||
_minute(dateTime._minute),
|
||||
_second(dateTime._second),
|
||||
_millisecond(dateTime._millisecond),
|
||||
_microsecond(dateTime._microsecond)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DateTime::~DateTime()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::operator = (const DateTime& dateTime)
|
||||
{
|
||||
if (&dateTime != this)
|
||||
{
|
||||
_utcTime = dateTime._utcTime;
|
||||
_year = dateTime._year;
|
||||
_month = dateTime._month;
|
||||
_day = dateTime._day;
|
||||
_hour = dateTime._hour;
|
||||
_minute = dateTime._minute;
|
||||
_second = dateTime._second;
|
||||
_millisecond = dateTime._millisecond;
|
||||
_microsecond = dateTime._microsecond;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::operator = (const Timestamp& timestamp)
|
||||
{
|
||||
_utcTime = timestamp.utcTime();
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::operator = (double julianDay)
|
||||
{
|
||||
_utcTime = toUtcTime(julianDay);
|
||||
computeGregorian(julianDay);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::assign(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond)
|
||||
{
|
||||
poco_assert (year >= 0 && year <= 9999);
|
||||
poco_assert (month >= 1 && month <= 12);
|
||||
poco_assert (day >= 1 && day <= daysOfMonth(year, month));
|
||||
poco_assert (hour >= 0 && hour <= 23);
|
||||
poco_assert (minute >= 0 && minute <= 59);
|
||||
poco_assert (second >= 0 && second <= 59);
|
||||
poco_assert (millisecond >= 0 && millisecond <= 999);
|
||||
poco_assert (microsecond >= 0 && microsecond <= 999);
|
||||
|
||||
_utcTime = toUtcTime(toJulianDay(year, month, day)) + 10*(hour*Timespan::HOURS + minute*Timespan::MINUTES + second*Timespan::SECONDS + millisecond*Timespan::MILLISECONDS + microsecond);
|
||||
_year = year;
|
||||
_month = month;
|
||||
_day = day;
|
||||
_hour = hour;
|
||||
_minute = minute;
|
||||
_second = second;
|
||||
_millisecond = millisecond;
|
||||
_microsecond = microsecond;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void DateTime::swap(DateTime& dateTime)
|
||||
{
|
||||
std::swap(_utcTime, dateTime._utcTime);
|
||||
std::swap(_year, dateTime._year);
|
||||
std::swap(_month, dateTime._month);
|
||||
std::swap(_day, dateTime._day);
|
||||
std::swap(_hour, dateTime._hour);
|
||||
std::swap(_minute, dateTime._minute);
|
||||
std::swap(_second, dateTime._second);
|
||||
std::swap(_millisecond, dateTime._millisecond);
|
||||
std::swap(_microsecond, dateTime._microsecond);
|
||||
}
|
||||
|
||||
|
||||
int DateTime::dayOfWeek() const
|
||||
{
|
||||
return int((std::floor(julianDay() + 1.5))) % 7;
|
||||
}
|
||||
|
||||
|
||||
int DateTime::dayOfYear() const
|
||||
{
|
||||
int doy = 0;
|
||||
for (int month = 1; month < _month; ++month)
|
||||
doy += daysOfMonth(_year, month);
|
||||
doy += _day;
|
||||
return doy;
|
||||
}
|
||||
|
||||
|
||||
int DateTime::daysOfMonth(int year, int month)
|
||||
{
|
||||
poco_assert (month >= 1 && month <= 12);
|
||||
|
||||
static int daysOfMonthTable[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
if (month == 2 && isLeapYear(year))
|
||||
return 29;
|
||||
else
|
||||
return daysOfMonthTable[month];
|
||||
}
|
||||
|
||||
|
||||
bool DateTime::isValid(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond)
|
||||
{
|
||||
return
|
||||
(year >= 0 && year <= 9999) &&
|
||||
(month >= 1 && month <= 12) &&
|
||||
(day >= 1 && day <= daysOfMonth(year, month)) &&
|
||||
(hour >= 0 && hour <= 23) &&
|
||||
(minute >= 0 && minute <= 59) &&
|
||||
(second >= 0 && second <= 59) &&
|
||||
(millisecond >= 0 && millisecond <= 999) &&
|
||||
(microsecond >= 0 && microsecond <= 999);
|
||||
}
|
||||
|
||||
|
||||
int DateTime::week(int firstDayOfWeek) const
|
||||
{
|
||||
poco_assert (firstDayOfWeek >= 0 && firstDayOfWeek <= 6);
|
||||
|
||||
/// find the first firstDayOfWeek.
|
||||
int baseDay = 1;
|
||||
while (DateTime(_year, 1, baseDay).dayOfWeek() != firstDayOfWeek) ++baseDay;
|
||||
|
||||
int doy = dayOfYear();
|
||||
int offs = baseDay <= 4 ? 0 : 1;
|
||||
if (doy < baseDay)
|
||||
return offs;
|
||||
else
|
||||
return (doy - baseDay)/7 + 1 + offs;
|
||||
}
|
||||
|
||||
|
||||
double DateTime::julianDay() const
|
||||
{
|
||||
return toJulianDay(_utcTime);
|
||||
}
|
||||
|
||||
|
||||
DateTime DateTime::operator + (const Timespan& span) const
|
||||
{
|
||||
return DateTime(_utcTime, span.totalMicroseconds());
|
||||
}
|
||||
|
||||
|
||||
DateTime DateTime::operator - (const Timespan& span) const
|
||||
{
|
||||
return DateTime(_utcTime, -span.totalMicroseconds());
|
||||
}
|
||||
|
||||
|
||||
Timespan DateTime::operator - (const DateTime& dateTime) const
|
||||
{
|
||||
return Timespan((_utcTime - dateTime._utcTime)/10);
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::operator += (const Timespan& span)
|
||||
{
|
||||
_utcTime += span.totalMicroseconds()*10;
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DateTime& DateTime::operator -= (const Timespan& span)
|
||||
{
|
||||
_utcTime -= span.totalMicroseconds()*10;
|
||||
computeGregorian(julianDay());
|
||||
computeDaytime();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void DateTime::makeUTC(int tzd)
|
||||
{
|
||||
operator -= (Timespan(((Timestamp::TimeDiff) tzd)*Timespan::SECONDS));
|
||||
}
|
||||
|
||||
|
||||
void DateTime::makeLocal(int tzd)
|
||||
{
|
||||
operator += (Timespan(((Timestamp::TimeDiff) tzd)*Timespan::SECONDS));
|
||||
}
|
||||
|
||||
|
||||
double DateTime::toJulianDay(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond)
|
||||
{
|
||||
// lookup table for (153*month - 457)/5 - note that 3 <= month <= 14.
|
||||
static int lookup[] = {-91, -60, -30, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337};
|
||||
|
||||
// day to double
|
||||
double dday = double(day) + ((double((hour*60 + minute)*60 + second)*1000 + millisecond)*1000 + microsecond)/86400000000.0;
|
||||
if (month < 3)
|
||||
{
|
||||
month += 12;
|
||||
--year;
|
||||
}
|
||||
double dyear = double(year);
|
||||
return dday + lookup[month] + 365*year + std::floor(dyear/4) - std::floor(dyear/100) + std::floor(dyear/400) + 1721118.5;
|
||||
}
|
||||
|
||||
|
||||
void DateTime::checkLimit(short& lower, short& higher, short limit)
|
||||
{
|
||||
if (lower >= limit)
|
||||
{
|
||||
higher += short(lower / limit);
|
||||
lower = short(lower % limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DateTime::normalize()
|
||||
{
|
||||
checkLimit(_microsecond, _millisecond, 1000);
|
||||
checkLimit(_millisecond, _second, 1000);
|
||||
checkLimit(_second, _minute, 60);
|
||||
checkLimit(_minute, _hour, 60);
|
||||
checkLimit(_hour, _day, 24);
|
||||
|
||||
if (_day > daysOfMonth(_year, _month))
|
||||
{
|
||||
_day -= daysOfMonth(_year, _month);
|
||||
if (++_month > 12)
|
||||
{
|
||||
++_year;
|
||||
_month -= 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DateTime::computeGregorian(double julianDay)
|
||||
{
|
||||
double z = std::floor(julianDay - 1721118.5);
|
||||
double r = julianDay - 1721118.5 - z;
|
||||
double g = z - 0.25;
|
||||
double a = std::floor(g / 36524.25);
|
||||
double b = a - std::floor(a/4);
|
||||
_year = short(std::floor((b + g)/365.25));
|
||||
double c = b + z - std::floor(365.25*_year);
|
||||
_month = short(std::floor((5*c + 456)/153));
|
||||
double dday = c - std::floor((153.0*_month - 457)/5) + r;
|
||||
_day = short(dday);
|
||||
if (_month > 12)
|
||||
{
|
||||
++_year;
|
||||
_month -= 12;
|
||||
}
|
||||
r *= 24;
|
||||
_hour = short(std::floor(r));
|
||||
r -= std::floor(r);
|
||||
r *= 60;
|
||||
_minute = short(std::floor(r));
|
||||
r -= std::floor(r);
|
||||
r *= 60;
|
||||
_second = short(std::floor(r));
|
||||
r -= std::floor(r);
|
||||
r *= 1000;
|
||||
_millisecond = short(std::floor(r));
|
||||
r -= std::floor(r);
|
||||
r *= 1000;
|
||||
_microsecond = short(r + 0.5);
|
||||
|
||||
normalize();
|
||||
|
||||
poco_assert_dbg (_month >= 1 && _month <= 12);
|
||||
poco_assert_dbg (_day >= 1 && _day <= daysOfMonth(_year, _month));
|
||||
poco_assert_dbg (_hour >= 0 && _hour <= 23);
|
||||
poco_assert_dbg (_minute >= 0 && _minute <= 59);
|
||||
poco_assert_dbg (_second >= 0 && _second <= 59);
|
||||
poco_assert_dbg (_millisecond >= 0 && _millisecond <= 999);
|
||||
poco_assert_dbg (_microsecond >= 0 && _microsecond <= 999);
|
||||
}
|
||||
|
||||
|
||||
void DateTime::computeDaytime()
|
||||
{
|
||||
Timespan span(_utcTime/10);
|
||||
_hour = span.hours();
|
||||
_minute = span.minutes();
|
||||
_second = span.seconds();
|
||||
_millisecond = span.milliseconds();
|
||||
_microsecond = span.microseconds();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,83 +0,0 @@
|
||||
//
|
||||
// DateTimeFormat.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DateTimeFormat.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: DateTime
|
||||
// Module: DateTimeFormat
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const std::string DateTimeFormat::ISO8601_FORMAT("%Y-%m-%dT%H:%M:%S%z");
|
||||
const std::string DateTimeFormat::ISO8601_FRAC_FORMAT("%Y-%m-%dT%H:%M:%s%z");
|
||||
const std::string DateTimeFormat::RFC822_FORMAT("%w, %e %b %y %H:%M:%S %Z");
|
||||
const std::string DateTimeFormat::RFC1123_FORMAT("%w, %e %b %Y %H:%M:%S %Z");
|
||||
const std::string DateTimeFormat::HTTP_FORMAT("%w, %d %b %Y %H:%M:%S %Z");
|
||||
const std::string DateTimeFormat::RFC850_FORMAT("%W, %e-%b-%y %H:%M:%S %Z");
|
||||
const std::string DateTimeFormat::RFC1036_FORMAT("%W, %e %b %y %H:%M:%S %Z");
|
||||
const std::string DateTimeFormat::ASCTIME_FORMAT("%w %b %f %H:%M:%S %Y");
|
||||
const std::string DateTimeFormat::SORTABLE_FORMAT("%Y-%m-%d %H:%M:%S");
|
||||
|
||||
|
||||
const std::string DateTimeFormat::WEEKDAY_NAMES[] =
|
||||
{
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
};
|
||||
|
||||
|
||||
const std::string DateTimeFormat::MONTH_NAMES[] =
|
||||
{
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,177 +0,0 @@
|
||||
//
|
||||
// DateTimeFormatter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DateTimeFormatter.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: DateTime
|
||||
// Module: DateTimeFormatter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void DateTimeFormatter::append(std::string& str, const LocalDateTime& dateTime, const std::string& fmt)
|
||||
{
|
||||
DateTimeFormatter::append(str, dateTime.utc(), fmt, dateTime.tzd());
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatter::append(std::string& str, const DateTime& dateTime, const std::string& fmt, int timeZoneDifferential)
|
||||
{
|
||||
std::string::const_iterator it = fmt.begin();
|
||||
std::string::const_iterator end = fmt.end();
|
||||
while (it != end)
|
||||
{
|
||||
if (*it == '%')
|
||||
{
|
||||
if (++it != end)
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
case 'w': str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3); break;
|
||||
case 'W': str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]); break;
|
||||
case 'b': str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3); break;
|
||||
case 'B': str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]); break;
|
||||
case 'd': NumberFormatter::append0(str, dateTime.day(), 2); break;
|
||||
case 'e': NumberFormatter::append(str, dateTime.day()); break;
|
||||
case 'f': NumberFormatter::append(str, dateTime.day(), 2); break;
|
||||
case 'm': NumberFormatter::append0(str, dateTime.month(), 2); break;
|
||||
case 'n': NumberFormatter::append(str, dateTime.month()); break;
|
||||
case 'o': NumberFormatter::append(str, dateTime.month(), 2); break;
|
||||
case 'y': NumberFormatter::append0(str, dateTime.year() % 100, 2); break;
|
||||
case 'Y': NumberFormatter::append0(str, dateTime.year(), 4); break;
|
||||
case 'H': NumberFormatter::append0(str, dateTime.hour(), 2); break;
|
||||
case 'h': NumberFormatter::append0(str, dateTime.hourAMPM(), 2); break;
|
||||
case 'a': str.append(dateTime.isAM() ? "am" : "pm"); break;
|
||||
case 'A': str.append(dateTime.isAM() ? "AM" : "PM"); break;
|
||||
case 'M': NumberFormatter::append0(str, dateTime.minute(), 2); break;
|
||||
case 'S': NumberFormatter::append0(str, dateTime.second(), 2); break;
|
||||
case 's': NumberFormatter::append0(str, dateTime.second(), 2);
|
||||
str += '.';
|
||||
NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6);
|
||||
break;
|
||||
case 'i': NumberFormatter::append0(str, dateTime.millisecond(), 3); break;
|
||||
case 'c': NumberFormatter::append(str, dateTime.millisecond()/100); break;
|
||||
case 'F': NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); break;
|
||||
case 'z': tzdISO(str, timeZoneDifferential); break;
|
||||
case 'Z': tzdRFC(str, timeZoneDifferential); break;
|
||||
default: str += *it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
else str += *it++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatter::append(std::string& str, const Timespan& timespan, const std::string& fmt)
|
||||
{
|
||||
std::string::const_iterator it = fmt.begin();
|
||||
std::string::const_iterator end = fmt.end();
|
||||
while (it != end)
|
||||
{
|
||||
if (*it == '%')
|
||||
{
|
||||
if (++it != end)
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
case 'd': NumberFormatter::append(str, timespan.days()); break;
|
||||
case 'H': NumberFormatter::append0(str, timespan.hours(), 2); break;
|
||||
case 'h': NumberFormatter::append(str, timespan.totalHours()); break;
|
||||
case 'M': NumberFormatter::append0(str, timespan.minutes(), 2); break;
|
||||
case 'm': NumberFormatter::append(str, timespan.totalMinutes()); break;
|
||||
case 'S': NumberFormatter::append0(str, timespan.seconds(), 2); break;
|
||||
case 's': NumberFormatter::append(str, timespan.totalSeconds()); break;
|
||||
case 'i': NumberFormatter::append0(str, timespan.milliseconds(), 3); break;
|
||||
case 'c': NumberFormatter::append(str, timespan.milliseconds()/100); break;
|
||||
case 'F': NumberFormatter::append0(str, timespan.milliseconds()*1000 + timespan.microseconds(), 6); break;
|
||||
default: str += *it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
else str += *it++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatter::tzdISO(std::string& str, int timeZoneDifferential)
|
||||
{
|
||||
if (timeZoneDifferential != UTC)
|
||||
{
|
||||
if (timeZoneDifferential >= 0)
|
||||
{
|
||||
str += '+';
|
||||
NumberFormatter::append0(str, timeZoneDifferential/3600, 2);
|
||||
str += ':';
|
||||
NumberFormatter::append0(str, (timeZoneDifferential%3600)/60, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
str += '-';
|
||||
NumberFormatter::append0(str, -timeZoneDifferential/3600, 2);
|
||||
str += ':';
|
||||
NumberFormatter::append0(str, (-timeZoneDifferential%3600)/60, 2);
|
||||
}
|
||||
}
|
||||
else str += 'Z';
|
||||
}
|
||||
|
||||
|
||||
void DateTimeFormatter::tzdRFC(std::string& str, int timeZoneDifferential)
|
||||
{
|
||||
if (timeZoneDifferential != UTC)
|
||||
{
|
||||
if (timeZoneDifferential >= 0)
|
||||
{
|
||||
str += '+';
|
||||
NumberFormatter::append0(str, timeZoneDifferential/3600, 2);
|
||||
NumberFormatter::append0(str, (timeZoneDifferential%3600)/60, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
str += '-';
|
||||
NumberFormatter::append0(str, -timeZoneDifferential/3600, 2);
|
||||
NumberFormatter::append0(str, (-timeZoneDifferential%3600)/60, 2);
|
||||
}
|
||||
}
|
||||
else str += "GMT";
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,399 +0,0 @@
|
||||
//
|
||||
// DateTimeParser.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DateTimeParser.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: DateTime
|
||||
// Module: DateTimeParser
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Ascii.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
#define SKIP_JUNK() \
|
||||
while (it != end && !Ascii::isDigit(*it)) ++it
|
||||
|
||||
|
||||
#define PARSE_NUMBER(var) \
|
||||
while (it != end && Ascii::isDigit(*it)) var = var*10 + ((*it++) - '0')
|
||||
|
||||
|
||||
#define PARSE_NUMBER_N(var, n) \
|
||||
{ int i = 0; while (i++ < n && it != end && Ascii::isDigit(*it)) var = var*10 + ((*it++) - '0'); }
|
||||
|
||||
#define PARSE_FRACTIONAL_N(var, n) \
|
||||
{ int i = 0; while (i < n && it != end && Ascii::isDigit(*it)) { var = var*10 + ((*it++) - '0'); i++; } while (i++ < n) var *= 10; }
|
||||
|
||||
|
||||
void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateTime& dateTime, int& timeZoneDifferential)
|
||||
{
|
||||
int year = 0;
|
||||
int month = 0;
|
||||
int day = 0;
|
||||
int hour = 0;
|
||||
int minute = 0;
|
||||
int second = 0;
|
||||
int millis = 0;
|
||||
int micros = 0;
|
||||
int tzd = 0;
|
||||
|
||||
std::string::const_iterator it = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
std::string::const_iterator itf = fmt.begin();
|
||||
std::string::const_iterator endf = fmt.end();
|
||||
|
||||
while (itf != endf && it != end)
|
||||
{
|
||||
if (*itf == '%')
|
||||
{
|
||||
if (++itf != endf)
|
||||
{
|
||||
switch (*itf)
|
||||
{
|
||||
case 'w':
|
||||
case 'W':
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
while (it != end && Ascii::isAlpha(*it)) ++it;
|
||||
break;
|
||||
case 'b':
|
||||
case 'B':
|
||||
month = parseMonth(it, end);
|
||||
break;
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(day, 2);
|
||||
break;
|
||||
case 'm':
|
||||
case 'n':
|
||||
case 'o':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(month, 2);
|
||||
break;
|
||||
case 'y':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(year, 2);
|
||||
if (year >= 69)
|
||||
year += 1900;
|
||||
else
|
||||
year += 2000;
|
||||
break;
|
||||
case 'Y':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(year, 4);
|
||||
break;
|
||||
case 'r':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER(year);
|
||||
if (year < 1000)
|
||||
{
|
||||
if (year >= 69)
|
||||
year += 1900;
|
||||
else
|
||||
year += 2000;
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
case 'h':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(hour, 2);
|
||||
break;
|
||||
case 'a':
|
||||
case 'A':
|
||||
hour = parseAMPM(it, end, hour);
|
||||
break;
|
||||
case 'M':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(minute, 2);
|
||||
break;
|
||||
case 'S':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(second, 2);
|
||||
break;
|
||||
case 's':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(second, 2);
|
||||
if (it != end && *it == '.')
|
||||
{
|
||||
++it;
|
||||
PARSE_FRACTIONAL_N(millis, 3);
|
||||
PARSE_FRACTIONAL_N(micros, 3);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(millis, 3);
|
||||
break;
|
||||
case 'c':
|
||||
SKIP_JUNK();
|
||||
PARSE_NUMBER_N(millis, 1);
|
||||
millis *= 100;
|
||||
break;
|
||||
case 'F':
|
||||
SKIP_JUNK();
|
||||
PARSE_FRACTIONAL_N(millis, 3);
|
||||
PARSE_FRACTIONAL_N(micros, 3);
|
||||
break;
|
||||
case 'z':
|
||||
case 'Z':
|
||||
tzd = parseTZD(it, end);
|
||||
break;
|
||||
}
|
||||
++itf;
|
||||
}
|
||||
}
|
||||
else ++itf;
|
||||
}
|
||||
if (month == 0) month = 1;
|
||||
if (day == 0) day = 1;
|
||||
if (DateTime::isValid(year, month, day, hour, minute, second, millis, micros))
|
||||
dateTime.assign(year, month, day, hour, minute, second, millis, micros);
|
||||
else
|
||||
throw SyntaxException("date/time component out of range");
|
||||
timeZoneDifferential = tzd;
|
||||
}
|
||||
|
||||
|
||||
DateTime DateTimeParser::parse(const std::string& fmt, const std::string& str, int& timeZoneDifferential)
|
||||
{
|
||||
DateTime result;
|
||||
parse(fmt, str, result, timeZoneDifferential);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool DateTimeParser::tryParse(const std::string& fmt, const std::string& str, DateTime& dateTime, int& timeZoneDifferential)
|
||||
{
|
||||
try
|
||||
{
|
||||
parse(fmt, str, dateTime, timeZoneDifferential);
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void DateTimeParser::parse(const std::string& str, DateTime& dateTime, int& timeZoneDifferential)
|
||||
{
|
||||
if (!tryParse(str, dateTime, timeZoneDifferential))
|
||||
throw SyntaxException("Unsupported or invalid date/time format");
|
||||
}
|
||||
|
||||
|
||||
DateTime DateTimeParser::parse(const std::string& str, int& timeZoneDifferential)
|
||||
{
|
||||
DateTime result;
|
||||
if (tryParse(str, result, timeZoneDifferential))
|
||||
return result;
|
||||
else
|
||||
throw SyntaxException("Unsupported or invalid date/time format");
|
||||
}
|
||||
|
||||
|
||||
bool DateTimeParser::tryParse(const std::string& str, DateTime& dateTime, int& timeZoneDifferential)
|
||||
{
|
||||
if (str.length() < 4) return false;
|
||||
|
||||
if (str[3] == ',')
|
||||
return tryParse("%w, %e %b %r %H:%M:%S %Z", str, dateTime, timeZoneDifferential);
|
||||
else if (str[3] == ' ')
|
||||
return tryParse(DateTimeFormat::ASCTIME_FORMAT, str, dateTime, timeZoneDifferential);
|
||||
else if (str.find(',') != std::string::npos)
|
||||
return tryParse("%W, %e %b %r %H:%M:%S %Z", str, dateTime, timeZoneDifferential);
|
||||
else if (Ascii::isDigit(str[0]))
|
||||
{
|
||||
if (str.find(' ') != std::string::npos || str.length() == 10)
|
||||
return tryParse(DateTimeFormat::SORTABLE_FORMAT, str, dateTime, timeZoneDifferential);
|
||||
else
|
||||
return tryParse(DateTimeFormat::ISO8601_FORMAT, str, dateTime, timeZoneDifferential);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
int DateTimeParser::parseTZD(std::string::const_iterator& it, const std::string::const_iterator& end)
|
||||
{
|
||||
struct Zone
|
||||
{
|
||||
const char* designator;
|
||||
int timeZoneDifferential;
|
||||
};
|
||||
|
||||
static Zone zones[] =
|
||||
{
|
||||
{"Z", 0},
|
||||
{"UT", 0},
|
||||
{"GMT", 0},
|
||||
{"BST", 1*3600},
|
||||
{"IST", 1*3600},
|
||||
{"WET", 0},
|
||||
{"WEST", 1*3600},
|
||||
{"CET", 1*3600},
|
||||
{"CEST", 2*3600},
|
||||
{"EET", 2*3600},
|
||||
{"EEST", 3*3600},
|
||||
{"MSK", 3*3600},
|
||||
{"MSD", 4*3600},
|
||||
{"NST", -3*3600-1800},
|
||||
{"NDT", -2*3600-1800},
|
||||
{"AST", -4*3600},
|
||||
{"ADT", -3*3600},
|
||||
{"EST", -5*3600},
|
||||
{"EDT", -4*3600},
|
||||
{"CST", -6*3600},
|
||||
{"CDT", -5*3600},
|
||||
{"MST", -7*3600},
|
||||
{"MDT", -6*3600},
|
||||
{"PST", -8*3600},
|
||||
{"PDT", -7*3600},
|
||||
{"AKST", -9*3600},
|
||||
{"AKDT", -8*3600},
|
||||
{"HST", -10*3600},
|
||||
{"AEST", 10*3600},
|
||||
{"AEDT", 11*3600},
|
||||
{"ACST", 9*3600+1800},
|
||||
{"ACDT", 10*3600+1800},
|
||||
{"AWST", 8*3600},
|
||||
{"AWDT", 9*3600}
|
||||
};
|
||||
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
if (it != end)
|
||||
{
|
||||
if (Ascii::isAlpha(*it))
|
||||
{
|
||||
std::string designator;
|
||||
designator += *it++;
|
||||
if (it != end && Ascii::isAlpha(*it)) designator += *it++;
|
||||
if (it != end && Ascii::isAlpha(*it)) designator += *it++;
|
||||
if (it != end && Ascii::isAlpha(*it)) designator += *it++;
|
||||
for (unsigned i = 0; i < sizeof(zones)/sizeof(Zone); ++i)
|
||||
{
|
||||
if (designator == zones[i].designator)
|
||||
return zones[i].timeZoneDifferential;
|
||||
}
|
||||
}
|
||||
else if (*it == '+' || *it == '-')
|
||||
{
|
||||
int sign = *it == '+' ? 1 : -1;
|
||||
++it;
|
||||
int hours = 0;
|
||||
PARSE_NUMBER_N(hours, 2);
|
||||
if (it != end && *it == ':') ++it;
|
||||
int minutes = 0;
|
||||
PARSE_NUMBER_N(minutes, 2);
|
||||
return sign*(hours*3600 + minutes*60);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DateTimeParser::parseMonth(std::string::const_iterator& it, const std::string::const_iterator& end)
|
||||
{
|
||||
std::string month;
|
||||
while (it != end && (Ascii::isSpace(*it) || Ascii::isPunct(*it))) ++it;
|
||||
bool isFirst = true;
|
||||
while (it != end && Ascii::isAlpha(*it))
|
||||
{
|
||||
char ch = (*it++);
|
||||
if (isFirst) { month += Ascii::toUpper(ch); isFirst = false; }
|
||||
else month += Ascii::toLower(ch);
|
||||
}
|
||||
if (month.length() < 3) throw SyntaxException("Month name must be at least three characters long", month);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
if (DateTimeFormat::MONTH_NAMES[i].find(month) == 0)
|
||||
return i + 1;
|
||||
}
|
||||
throw SyntaxException("Not a valid month name", month);
|
||||
}
|
||||
|
||||
|
||||
int DateTimeParser::parseDayOfWeek(std::string::const_iterator& it, const std::string::const_iterator& end)
|
||||
{
|
||||
std::string dow;
|
||||
while (it != end && (Ascii::isSpace(*it) || Ascii::isPunct(*it))) ++it;
|
||||
bool isFirst = true;
|
||||
while (it != end && Ascii::isAlpha(*it))
|
||||
{
|
||||
char ch = (*it++);
|
||||
if (isFirst) { dow += Ascii::toUpper(ch); isFirst = false; }
|
||||
else dow += Ascii::toLower(ch);
|
||||
}
|
||||
if (dow.length() < 3) throw SyntaxException("Weekday name must be at least three characters long", dow);
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
if (DateTimeFormat::WEEKDAY_NAMES[i].find(dow) == 0)
|
||||
return i;
|
||||
}
|
||||
throw SyntaxException("Not a valid weekday name", dow);
|
||||
}
|
||||
|
||||
|
||||
int DateTimeParser::parseAMPM(std::string::const_iterator& it, const std::string::const_iterator& end, int hour)
|
||||
{
|
||||
std::string ampm;
|
||||
while (it != end && (Ascii::isSpace(*it) || Ascii::isPunct(*it))) ++it;
|
||||
while (it != end && Ascii::isAlpha(*it))
|
||||
{
|
||||
char ch = (*it++);
|
||||
ampm += Ascii::toUpper(ch);
|
||||
}
|
||||
if (ampm == "AM")
|
||||
{
|
||||
if (hour == 12)
|
||||
return 0;
|
||||
else
|
||||
return hour;
|
||||
}
|
||||
else if (ampm == "PM")
|
||||
{
|
||||
if (hour < 12)
|
||||
return hour + 12;
|
||||
else
|
||||
return hour;
|
||||
}
|
||||
else throw SyntaxException("Not a valid AM/PM designator", ampm);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,184 +0,0 @@
|
||||
//
|
||||
// Debugger.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Debugger.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Debugger
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Debugger.h"
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Poco/UnWindows.h"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_VXWORKS)
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#elif defined(POCO_OS_FAMILY_VMS)
|
||||
#include <lib$routines.h>
|
||||
#include <ssdef.h>
|
||||
#endif
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
// NOTE: In this module, we use the C library functions (fputs) for,
|
||||
// output since, at the time we're called, the C++ iostream objects std::cout, etc.
|
||||
// might not have been initialized yet.
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
bool Debugger::isAvailable()
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if defined(_WIN32_WCE)
|
||||
#if (_WIN32_WCE >= 0x600)
|
||||
BOOL isDebuggerPresent;
|
||||
if (CheckRemoteDebuggerPresent(GetCurrentProcess(), &isDebuggerPresent))
|
||||
{
|
||||
return isDebuggerPresent ? true : false;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
#else
|
||||
return IsDebuggerPresent() ? true : false;
|
||||
#endif
|
||||
#elif defined(POCO_VXWORKS)
|
||||
return false;
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
return std::getenv("POCO_ENABLE_DEBUGGER") ? true : false;
|
||||
#elif defined(POCO_OS_FAMILY_VMS)
|
||||
return true;
|
||||
#endif
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::message(const std::string& msg)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
std::fputs("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stderr);
|
||||
std::fputs(msg.c_str(), stderr);
|
||||
std::fputs("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", stderr);
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
if (isAvailable())
|
||||
{
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
std::wstring umsg;
|
||||
UnicodeConverter::toUTF16(msg, umsg);
|
||||
umsg += '\n';
|
||||
OutputDebugStringW(umsg.c_str());
|
||||
#else
|
||||
OutputDebugStringA(msg.c_str());
|
||||
OutputDebugStringA("\n");
|
||||
#endif
|
||||
}
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#elif defined(POCO_OS_FAMILY_VMS)
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::message(const std::string& msg, const char* file, int line)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
std::ostringstream str;
|
||||
str << msg << " [in file \"" << file << "\", line " << line << "]";
|
||||
message(str.str());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::enter()
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
if (isAvailable())
|
||||
{
|
||||
DebugBreak();
|
||||
}
|
||||
#elif defined(POCO_VXWORKS)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
if (isAvailable())
|
||||
{
|
||||
kill(getpid(), SIGINT);
|
||||
}
|
||||
#elif defined(POCO_OS_FAMILY_VMS)
|
||||
{
|
||||
const char* cmd = "\012SHOW CALLS";
|
||||
lib$signal(SS$_DEBUG, 1, cmd);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::enter(const std::string& msg)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
message(msg);
|
||||
enter();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::enter(const std::string& msg, const char* file, int line)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
message(msg, file, line);
|
||||
enter();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Debugger::enter(const char* file, int line)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
message("BREAK", file, line);
|
||||
enter();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,399 +0,0 @@
|
||||
//
|
||||
// DeflatingStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DeflatingStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: ZLibStream
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DeflatingStream.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DeflatingStreamBuf::DeflatingStreamBuf(std::istream& istr, StreamType type, int level):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_eof(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[DEFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = deflateInit2(&_zstr, level, Z_DEFLATED, 15 + (type == STREAM_GZIP ? 16 : 0), 8, Z_DEFAULT_STRATEGY);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeflatingStreamBuf::DeflatingStreamBuf(std::istream& istr, int windowBits, int level):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_eof(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[DEFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = deflateInit2(&_zstr, level, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeflatingStreamBuf::DeflatingStreamBuf(std::ostream& ostr, StreamType type, int level):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_eof(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[DEFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = deflateInit2(&_zstr, level, Z_DEFLATED, 15 + (type == STREAM_GZIP ? 16 : 0), 8, Z_DEFAULT_STRATEGY);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeflatingStreamBuf::DeflatingStreamBuf(std::ostream& ostr, int windowBits, int level):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_eof(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[DEFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = deflateInit2(&_zstr, level, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeflatingStreamBuf::~DeflatingStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
delete [] _buffer;
|
||||
deflateEnd(&_zstr);
|
||||
}
|
||||
|
||||
|
||||
int DeflatingStreamBuf::close()
|
||||
{
|
||||
BufferedStreamBuf::sync();
|
||||
_pIstr = 0;
|
||||
if (_pOstr)
|
||||
{
|
||||
if (_zstr.next_out)
|
||||
{
|
||||
int rc = deflate(&_zstr, Z_FINISH);
|
||||
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
while (rc != Z_STREAM_END)
|
||||
{
|
||||
rc = deflate(&_zstr, Z_FINISH);
|
||||
if (rc != Z_OK && rc != Z_STREAM_END) throw IOException(zError(rc));
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
_pOstr = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DeflatingStreamBuf::sync()
|
||||
{
|
||||
if (BufferedStreamBuf::sync())
|
||||
return -1;
|
||||
|
||||
if (_pOstr && _zstr.next_out)
|
||||
{
|
||||
int rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
while (_zstr.avail_out == 0)
|
||||
{
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
rc = deflate(&_zstr, Z_SYNC_FLUSH);
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
};
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int DeflatingStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_pIstr) return 0;
|
||||
if (_zstr.avail_in == 0 && !_eof)
|
||||
{
|
||||
int n = 0;
|
||||
if (_pIstr->good())
|
||||
{
|
||||
_pIstr->read(_buffer, DEFLATE_BUFFER_SIZE);
|
||||
n = static_cast<int>(_pIstr->gcount());
|
||||
}
|
||||
if (n > 0)
|
||||
{
|
||||
_zstr.next_in = (unsigned char*) _buffer;
|
||||
_zstr.avail_in = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_eof = true;
|
||||
}
|
||||
}
|
||||
_zstr.next_out = (unsigned char*) buffer;
|
||||
_zstr.avail_out = static_cast<unsigned>(length);
|
||||
for (;;)
|
||||
{
|
||||
int rc = deflate(&_zstr, _eof ? Z_FINISH : Z_NO_FLUSH);
|
||||
if (_eof && rc == Z_STREAM_END)
|
||||
{
|
||||
_pIstr = 0;
|
||||
return static_cast<int>(length) - _zstr.avail_out;
|
||||
}
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
if (_zstr.avail_out == 0)
|
||||
{
|
||||
return static_cast<int>(length);
|
||||
}
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
int n = 0;
|
||||
if (_pIstr->good())
|
||||
{
|
||||
_pIstr->read(_buffer, DEFLATE_BUFFER_SIZE);
|
||||
n = static_cast<int>(_pIstr->gcount());
|
||||
}
|
||||
if (n > 0)
|
||||
{
|
||||
_zstr.next_in = (unsigned char*) _buffer;
|
||||
_zstr.avail_in = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_eof = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int DeflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (length == 0 || !_pOstr) return 0;
|
||||
|
||||
_zstr.next_in = (unsigned char*) buffer;
|
||||
_zstr.avail_in = static_cast<unsigned>(length);
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
for (;;)
|
||||
{
|
||||
int rc = deflate(&_zstr, Z_NO_FLUSH);
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
if (_zstr.avail_out == 0)
|
||||
{
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
}
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
_pOstr->write(_buffer, DEFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = DEFLATE_BUFFER_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return static_cast<int>(length);
|
||||
}
|
||||
|
||||
|
||||
DeflatingIOS::DeflatingIOS(std::ostream& ostr, DeflatingStreamBuf::StreamType type, int level):
|
||||
_buf(ostr, type, level)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DeflatingIOS::DeflatingIOS(std::ostream& ostr, int windowBits, int level):
|
||||
_buf(ostr, windowBits, level)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DeflatingIOS::DeflatingIOS(std::istream& istr, DeflatingStreamBuf::StreamType type, int level):
|
||||
_buf(istr, type, level)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DeflatingIOS::DeflatingIOS(std::istream& istr, int windowBits, int level):
|
||||
_buf(istr, windowBits, level)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DeflatingIOS::~DeflatingIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DeflatingStreamBuf* DeflatingIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
DeflatingOutputStream::DeflatingOutputStream(std::ostream& ostr, DeflatingStreamBuf::StreamType type, int level):
|
||||
DeflatingIOS(ostr, type, level),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DeflatingOutputStream::DeflatingOutputStream(std::ostream& ostr, int windowBits, int level):
|
||||
DeflatingIOS(ostr, windowBits, level),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DeflatingOutputStream::~DeflatingOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int DeflatingOutputStream::close()
|
||||
{
|
||||
return _buf.close();
|
||||
}
|
||||
|
||||
|
||||
int DeflatingOutputStream::sync()
|
||||
{
|
||||
return _buf.pubsync();
|
||||
}
|
||||
|
||||
|
||||
DeflatingInputStream::DeflatingInputStream(std::istream& istr, DeflatingStreamBuf::StreamType type, int level):
|
||||
DeflatingIOS(istr, type, level),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DeflatingInputStream::DeflatingInputStream(std::istream& istr, int windowBits, int level):
|
||||
DeflatingIOS(istr, windowBits, level),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DeflatingInputStream::~DeflatingInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,104 +0,0 @@
|
||||
//
|
||||
// DigestEngine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DigestEngine.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Crypt
|
||||
// Module: DigestEngine
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DigestEngine.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DigestEngine::DigestEngine()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestEngine::~DigestEngine()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string DigestEngine::digestToHex(const Digest& bytes)
|
||||
{
|
||||
static const char digits[] = "0123456789abcdef";
|
||||
std::string result;
|
||||
result.reserve(bytes.size()*2);
|
||||
for (Digest::const_iterator it = bytes.begin(); it != bytes.end(); ++it)
|
||||
{
|
||||
unsigned char c = *it;
|
||||
result += digits[(c >> 4) & 0xF];
|
||||
result += digits[c & 0xF];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
DigestEngine::Digest DigestEngine::digestFromHex(const std::string& digest)
|
||||
{
|
||||
if (digest.size() % 2 != 0)
|
||||
throw DataFormatException();
|
||||
Digest result;
|
||||
result.reserve(digest.size()/2);
|
||||
for (std::size_t i = 0; i < digest.size(); ++i)
|
||||
{
|
||||
int c = 0;
|
||||
// first upper 4 bits
|
||||
if (digest[i] >= '0' && digest[i] <= '9')
|
||||
c = digest[i] - '0';
|
||||
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
||||
c = digest[i] - 'a'+10;
|
||||
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
||||
c = digest[i] - 'A'+10;
|
||||
else
|
||||
throw DataFormatException();
|
||||
c <<= 4;
|
||||
++i;
|
||||
if (digest[i] >= '0' && digest[i] <= '9')
|
||||
c += digest[i] - '0';
|
||||
else if (digest[i] >= 'a' && digest[i] <= 'f')
|
||||
c += digest[i] - 'a'+10;
|
||||
else if (digest[i] >= 'A' && digest[i] <= 'F')
|
||||
c += digest[i] - 'A'+10;
|
||||
else
|
||||
throw DataFormatException();
|
||||
|
||||
result.push_back(static_cast<unsigned char>(c));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,172 +0,0 @@
|
||||
//
|
||||
// DigestStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DigestStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Crypt
|
||||
// Module: DigestStream
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DigestStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const int DigestBuf::BUFFER_SIZE = 256;
|
||||
|
||||
|
||||
DigestBuf::DigestBuf(DigestEngine& eng):
|
||||
BufferedStreamBuf(BUFFER_SIZE, std::ios::out),
|
||||
_eng(eng),
|
||||
_pIstr(0),
|
||||
_pOstr(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestBuf::DigestBuf(DigestEngine& eng, std::istream& istr):
|
||||
BufferedStreamBuf(BUFFER_SIZE, std::ios::in),
|
||||
_eng(eng),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestBuf::DigestBuf(DigestEngine& eng, std::ostream& ostr):
|
||||
BufferedStreamBuf(BUFFER_SIZE, std::ios::out),
|
||||
_eng(eng),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestBuf::~DigestBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int DigestBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_pIstr && _pIstr->good())
|
||||
{
|
||||
_pIstr->read(buffer, length);
|
||||
std::streamsize n = _pIstr->gcount();
|
||||
if (n > 0) _eng.update(buffer, static_cast<unsigned>(n));
|
||||
return static_cast<int>(n);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int DigestBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
_eng.update(buffer, (unsigned) length);
|
||||
if (_pOstr) _pOstr->write(buffer, length);
|
||||
return static_cast<int>(length);
|
||||
}
|
||||
|
||||
|
||||
void DigestBuf::close()
|
||||
{
|
||||
sync();
|
||||
if (_pOstr) _pOstr->flush();
|
||||
}
|
||||
|
||||
|
||||
DigestIOS::DigestIOS(DigestEngine& eng): _buf(eng)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DigestIOS::DigestIOS(DigestEngine& eng, std::istream& istr): _buf(eng, istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DigestIOS::DigestIOS(DigestEngine& eng, std::ostream& ostr): _buf(eng, ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
DigestIOS::~DigestIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestBuf* DigestIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
DigestInputStream::DigestInputStream(DigestEngine& eng, std::istream& istr):
|
||||
DigestIOS(eng, istr),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestInputStream::~DigestInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestOutputStream::DigestOutputStream(DigestEngine& eng):
|
||||
DigestIOS(eng),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestOutputStream::DigestOutputStream(DigestEngine& eng, std::ostream& ostr):
|
||||
DigestIOS(eng, ostr),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestOutputStream::~DigestOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DigestOutputStream::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,169 +0,0 @@
|
||||
//
|
||||
// DirectoryIterator.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DirectoryIterator.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: DirectoryIterator
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DirectoryIterator.h"
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#include "DirectoryIterator_WIN32U.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "DirectoryIterator_WIN32.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "DirectoryIterator_UNIX.cpp"
|
||||
#else
|
||||
#include "DirectoryIterator_VMS.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DirectoryIterator::DirectoryIterator(): _pImpl(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator::DirectoryIterator(const std::string& path): _path(path), _pImpl(new DirectoryIteratorImpl(path))
|
||||
{
|
||||
_path.makeDirectory();
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator::DirectoryIterator(const DirectoryIterator& iterator): _path(iterator._path), _pImpl(iterator._pImpl)
|
||||
{
|
||||
if (_pImpl)
|
||||
{
|
||||
_pImpl->duplicate();
|
||||
_file = _path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator::DirectoryIterator(const File& file): _path(file.path()), _pImpl(new DirectoryIteratorImpl(file.path()))
|
||||
{
|
||||
_path.makeDirectory();
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator::DirectoryIterator(const Path& path): _path(path), _pImpl(new DirectoryIteratorImpl(path.toString()))
|
||||
{
|
||||
_path.makeDirectory();
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator::~DirectoryIterator()
|
||||
{
|
||||
if (_pImpl) _pImpl->release();
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it)
|
||||
{
|
||||
if (_pImpl) _pImpl->release();
|
||||
_pImpl = it._pImpl;
|
||||
if (_pImpl)
|
||||
{
|
||||
_pImpl->duplicate();
|
||||
_path = it._path;
|
||||
_file = _path;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator& DirectoryIterator::operator = (const File& file)
|
||||
{
|
||||
if (_pImpl) _pImpl->release();
|
||||
_pImpl = new DirectoryIteratorImpl(file.path());
|
||||
_path.parseDirectory(file.path());
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator& DirectoryIterator::operator = (const Path& path)
|
||||
{
|
||||
if (_pImpl) _pImpl->release();
|
||||
_pImpl = new DirectoryIteratorImpl(path.toString());
|
||||
_path = path;
|
||||
_path.makeDirectory();
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator& DirectoryIterator::operator = (const std::string& path)
|
||||
{
|
||||
if (_pImpl) _pImpl->release();
|
||||
_pImpl = new DirectoryIteratorImpl(path);
|
||||
_path.parseDirectory(path);
|
||||
_path.setFileName(_pImpl->get());
|
||||
_file = _path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator& DirectoryIterator::operator ++ ()
|
||||
{
|
||||
if (_pImpl)
|
||||
{
|
||||
_path.setFileName(_pImpl->next());
|
||||
_file = _path;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
DirectoryIterator DirectoryIterator::operator ++ (int dummy)
|
||||
{
|
||||
if (_pImpl)
|
||||
{
|
||||
_path.setFileName(_pImpl->next());
|
||||
_file = _path;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// DirectoryIterator_UNIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DirectoryIterator_UNIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: DirectoryIterator
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DirectoryIterator_UNIX.h"
|
||||
#if defined(POCO_VXWORKS)
|
||||
#include "Poco/File_VX.h"
|
||||
#else
|
||||
#include "Poco/File_UNIX.h"
|
||||
#endif
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _pDir(0), _rc(1)
|
||||
{
|
||||
Path p(path);
|
||||
p.makeFile();
|
||||
|
||||
#if defined(POCO_VXWORKS)
|
||||
_pDir = opendir(const_cast<char*>(p.toString().c_str()));
|
||||
#else
|
||||
_pDir = opendir(p.toString().c_str());
|
||||
#endif
|
||||
if (!_pDir) File::handleLastError(path);
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
|
||||
DirectoryIteratorImpl::~DirectoryIteratorImpl()
|
||||
{
|
||||
if (_pDir) closedir(_pDir);
|
||||
}
|
||||
|
||||
|
||||
const std::string& DirectoryIteratorImpl::next()
|
||||
{
|
||||
do
|
||||
{
|
||||
struct dirent* pEntry = readdir(_pDir);
|
||||
if (pEntry)
|
||||
_current = pEntry->d_name;
|
||||
else
|
||||
_current.clear();
|
||||
}
|
||||
while (_current == "." || _current == "..");
|
||||
return _current;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,87 +0,0 @@
|
||||
//
|
||||
// DirectoryIterator_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DirectoryIterator_VMS.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: DirectoryIterator
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DirectoryIterator_VMS.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <iodef.h>
|
||||
#include <atrdef.h>
|
||||
#include <fibdef.h>
|
||||
#include <starlet.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _rc(1)
|
||||
{
|
||||
Path p(path);
|
||||
p.makeDirectory();
|
||||
_search = p.toString();
|
||||
_search.append("*.*;*");
|
||||
|
||||
_fab = cc$rms_fab;
|
||||
_fab.fab$l_fna = (char*) _search.c_str();
|
||||
_fab.fab$b_fns = _search.size();
|
||||
_fab.fab$l_nam = &_nam;
|
||||
|
||||
_nam = cc$rms_nam;
|
||||
_nam.nam$l_esa = _spec;
|
||||
_nam.nam$b_ess = sizeof(_spec);
|
||||
|
||||
if (sys$parse(&_fab) & 1)
|
||||
throw OpenFileException(path);
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
|
||||
DirectoryIteratorImpl::~DirectoryIteratorImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const std::string& DirectoryIteratorImpl::next()
|
||||
{
|
||||
if (sys$search(&_fab) & 1)
|
||||
_current.clear();
|
||||
else
|
||||
_current.assign(_fab.fab$l_nam->nam$l_name, _fab.fab$l_nam->nam$b_name + _fab.fab$l_nam->nam$b_type);
|
||||
return _current;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,88 +0,0 @@
|
||||
//
|
||||
// DirectoryIterator_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DirectoryIterator_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: DirectoryIterator
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DirectoryIterator_WIN32.h"
|
||||
#include "Poco/File_WIN32.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _fh(INVALID_HANDLE_VALUE), _rc(1)
|
||||
{
|
||||
Path p(path);
|
||||
p.makeDirectory();
|
||||
std::string findPath = p.toString();
|
||||
findPath.append("*");
|
||||
|
||||
_fh = FindFirstFile(findPath.c_str(), &_fd);
|
||||
if (_fh == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES)
|
||||
File::handleLastError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
_current = _fd.cFileName;
|
||||
if (_current == "." || _current == "..")
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DirectoryIteratorImpl::~DirectoryIteratorImpl()
|
||||
{
|
||||
if (_fh != INVALID_HANDLE_VALUE)
|
||||
FindClose(_fh);
|
||||
}
|
||||
|
||||
|
||||
const std::string& DirectoryIteratorImpl::next()
|
||||
{
|
||||
do
|
||||
{
|
||||
if (FindNextFile(_fh, &_fd) != 0)
|
||||
_current = _fd.cFileName;
|
||||
else
|
||||
_current.clear();
|
||||
}
|
||||
while (_current == "." || _current == "..");
|
||||
return _current;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,97 +0,0 @@
|
||||
//
|
||||
// DirectoryIterator_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/DirectoryIterator_WIN32U.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: DirectoryIterator
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/DirectoryIterator_WIN32U.h"
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "Poco/File_WINCE.h"
|
||||
#else
|
||||
#include "Poco/File_WIN32U.h"
|
||||
#endif
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _fh(INVALID_HANDLE_VALUE), _rc(1)
|
||||
{
|
||||
Path p(path);
|
||||
p.makeDirectory();
|
||||
std::string findPath = p.toString();
|
||||
findPath.append("*");
|
||||
std::wstring uFindPath;
|
||||
UnicodeConverter::toUTF16(findPath, uFindPath);
|
||||
|
||||
_fh = FindFirstFileW(uFindPath.c_str(), &_fd);
|
||||
if (_fh == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES)
|
||||
File::handleLastError(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnicodeConverter::toUTF8(_fd.cFileName, _current);
|
||||
if (_current == "." || _current == "..")
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DirectoryIteratorImpl::~DirectoryIteratorImpl()
|
||||
{
|
||||
if (_fh != INVALID_HANDLE_VALUE)
|
||||
FindClose(_fh);
|
||||
}
|
||||
|
||||
|
||||
const std::string& DirectoryIteratorImpl::next()
|
||||
{
|
||||
do
|
||||
{
|
||||
_current.clear();
|
||||
if (FindNextFileW(_fh, &_fd) != 0)
|
||||
{
|
||||
UnicodeConverter::toUTF8(_fd.cFileName, _current);
|
||||
}
|
||||
}
|
||||
while (_current == "." || _current == "..");
|
||||
return _current;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,154 +0,0 @@
|
||||
//
|
||||
// Environment.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment.h"
|
||||
#include "Poco/Version.h"
|
||||
#include <cstdlib>
|
||||
#include <cstdio> // sprintf()
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_VMS)
|
||||
#include "Environment_VMS.cpp"
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include "Environment_VX.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "Environment_UNIX.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "Environment_WINCE.cpp"
|
||||
#else
|
||||
#include "Environment_WIN32U.cpp"
|
||||
#endif
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Environment_WIN32.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::string Environment::get(const std::string& name)
|
||||
{
|
||||
return EnvironmentImpl::getImpl(name);
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::get(const std::string& name, const std::string& defaultValue)
|
||||
{
|
||||
if (has(name))
|
||||
return get(name);
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
bool Environment::has(const std::string& name)
|
||||
{
|
||||
return EnvironmentImpl::hasImpl(name);
|
||||
}
|
||||
|
||||
|
||||
void Environment::set(const std::string& name, const std::string& value)
|
||||
{
|
||||
EnvironmentImpl::setImpl(name, value);
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::osName()
|
||||
{
|
||||
return EnvironmentImpl::osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::osDisplayName()
|
||||
{
|
||||
return EnvironmentImpl::osDisplayNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::osVersion()
|
||||
{
|
||||
return EnvironmentImpl::osVersionImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::osArchitecture()
|
||||
{
|
||||
return EnvironmentImpl::osArchitectureImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::nodeName()
|
||||
{
|
||||
return EnvironmentImpl::nodeNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::nodeId()
|
||||
{
|
||||
NodeId id;
|
||||
nodeId(id);
|
||||
char result[18];
|
||||
std::sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
id[0],
|
||||
id[1],
|
||||
id[2],
|
||||
id[3],
|
||||
id[4],
|
||||
id[5]);
|
||||
return std::string(result);
|
||||
}
|
||||
|
||||
|
||||
void Environment::nodeId(NodeId& id)
|
||||
{
|
||||
return EnvironmentImpl::nodeIdImpl(id);
|
||||
}
|
||||
|
||||
|
||||
unsigned Environment::processorCount()
|
||||
{
|
||||
return EnvironmentImpl::processorCountImpl();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt32 Environment::libraryVersion()
|
||||
{
|
||||
return POCO_VERSION;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,331 +0,0 @@
|
||||
|
||||
// Environment_UNIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_UNIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_UNIX.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/param.h>
|
||||
#include <cstring>
|
||||
#if defined(POCO_OS_FAMILY_BSD)
|
||||
#include <sys/sysctl.h>
|
||||
#elif POCO_OS == POCO_OS_HPUX
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EnvironmentImpl::StringMap EnvironmentImpl::_map;
|
||||
FastMutex EnvironmentImpl::_mutex;
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
const char* val = getenv(name.c_str());
|
||||
if (val)
|
||||
return std::string(val);
|
||||
else
|
||||
throw NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return getenv(name.c_str()) != 0;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string var = name;
|
||||
var.append("=");
|
||||
var.append(value);
|
||||
_map[name] = var;
|
||||
if (putenv((char*) _map[name].c_str()))
|
||||
{
|
||||
std::string msg = "cannot set environment variable: ";
|
||||
msg.append(name);
|
||||
throw SystemException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
return uts.sysname;
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
return uts.release;
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
return uts.machine;
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
return uts.nodename;
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_BSD)
|
||||
unsigned count;
|
||||
std::size_t size = sizeof(count);
|
||||
if (sysctlbyname("hw.ncpu", &count, &size, 0, 0))
|
||||
return 1;
|
||||
else
|
||||
return count;
|
||||
#elif POCO_OS == POCO_OS_HPUX
|
||||
return pthread_num_processors_np();
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
int count = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (count <= 0) count = 1;
|
||||
return static_cast<int>(count);
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
//
|
||||
// nodeIdImpl
|
||||
//
|
||||
#if defined(POCO_OS_FAMILY_BSD) || POCO_OS == POCO_OS_QNX
|
||||
//
|
||||
// BSD variants
|
||||
//
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if_dl.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
struct ifaddrs* ifaphead;
|
||||
int rc = getifaddrs(&ifaphead);
|
||||
if (rc) return;
|
||||
|
||||
for (struct ifaddrs* ifap = ifaphead; ifap; ifap = ifap->ifa_next)
|
||||
{
|
||||
if (ifap->ifa_addr && ifap->ifa_addr->sa_family == AF_LINK)
|
||||
{
|
||||
struct sockaddr_dl* sdl = reinterpret_cast<struct sockaddr_dl*>(ifap->ifa_addr);
|
||||
caddr_t ap = (caddr_t) (sdl->sdl_data + sdl->sdl_nlen);
|
||||
int alen = sdl->sdl_alen;
|
||||
if (ap && alen > 0)
|
||||
{
|
||||
std::memcpy(&id, ap, sizeof(id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
freeifaddrs(ifaphead);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#elif defined(__CYGWIN__) || POCO_OS == POCO_OS_LINUX
|
||||
//
|
||||
// Linux, Cygwin
|
||||
//
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#ifndef __CYGWIN__
|
||||
#include <net/if_arp.h>
|
||||
#else // workaround for Cygwin, which does not have if_arp.h
|
||||
#define ARPHRD_ETHER 1 /* Ethernet 10Mbps */
|
||||
#endif
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
int sock = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (sock == -1) return;
|
||||
|
||||
// the following code is loosely based
|
||||
// on W. Richard Stevens, UNIX Network Programming, pp 434ff.
|
||||
int lastlen = 0;
|
||||
int len = 100*sizeof(struct ifreq);
|
||||
struct ifconf ifc;
|
||||
char* buf = 0;
|
||||
for (;;)
|
||||
{
|
||||
buf = new char[len];
|
||||
ifc.ifc_len = len;
|
||||
ifc.ifc_buf = buf;
|
||||
if (::ioctl(sock, SIOCGIFCONF, &ifc) < 0)
|
||||
{
|
||||
if (errno != EINVAL || lastlen != 0)
|
||||
{
|
||||
close(sock);
|
||||
delete [] buf;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ifc.ifc_len == lastlen)
|
||||
break;
|
||||
lastlen = ifc.ifc_len;
|
||||
}
|
||||
len += 10*sizeof(struct ifreq);
|
||||
delete [] buf;
|
||||
}
|
||||
for (const char* ptr = buf; ptr < buf + ifc.ifc_len;)
|
||||
{
|
||||
const struct ifreq* ifr = reinterpret_cast<const struct ifreq*>(ptr);
|
||||
int rc = ioctl(sock, SIOCGIFHWADDR, ifr);
|
||||
if (rc != -1)
|
||||
{
|
||||
const struct sockaddr* sa = reinterpret_cast<const struct sockaddr*>(&ifr->ifr_hwaddr);
|
||||
if (sa->sa_family == ARPHRD_ETHER)
|
||||
{
|
||||
std::memcpy(&id, sa->sa_data, sizeof(id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
ptr += sizeof(struct ifreq);
|
||||
}
|
||||
close(sock);
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
//
|
||||
// General Unix
|
||||
//
|
||||
#include <sys/ioctl.h>
|
||||
#if defined(sun) || defined(__sun)
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
char name[MAXHOSTNAMELEN];
|
||||
if (gethostname(name, sizeof(name)))
|
||||
return;
|
||||
|
||||
struct hostent* pHost = gethostbyname(name);
|
||||
if (!pHost) return;
|
||||
|
||||
int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s == -1) return;
|
||||
|
||||
struct arpreq ar;
|
||||
std::memset(&ar, 0, sizeof(ar));
|
||||
struct sockaddr_in* pAddr = reinterpret_cast<struct sockaddr_in*>(&ar.arp_pa);
|
||||
pAddr->sin_family = AF_INET;
|
||||
std::memcpy(&pAddr->sin_addr, *pHost->h_addr_list, sizeof(struct in_addr));
|
||||
int rc = ioctl(s, SIOCGARP, &ar);
|
||||
close(s);
|
||||
if (rc < 0) return;
|
||||
std::memcpy(&id, ar.arp_ha.sa_data, sizeof(id));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,240 +0,0 @@
|
||||
//
|
||||
// Environment_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_VMS.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_VMS.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <stdlib.h>
|
||||
#include <starlet.h>
|
||||
#include <descrip.h>
|
||||
#include <ssdef.h>
|
||||
#include <syidef.h>
|
||||
#include <iledef.h>
|
||||
#include <lnmdef.h>
|
||||
#include <ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <inet.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define MAXHOSTNAMELEN 64
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FastMutex EnvironmentImpl::_mutex;
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
const char* val = getenv(name.c_str());
|
||||
if (val)
|
||||
return std::string(val);
|
||||
else
|
||||
throw NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return getenv(name.c_str()) != 0;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (setenv(name.c_str(), value.c_str(), 1))
|
||||
{
|
||||
std::string msg = "cannot set environment variable: ";
|
||||
msg.append(name);
|
||||
throw SystemException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
return getsyi(SYI$_NODE_SWTYPE);
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
return getsyi(SYI$_VERSION);
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
return getsyi(SYI$_ARCH_NAME);
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
return getsyi(SYI$_NODENAME);
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
char name[MAXHOSTNAMELEN];
|
||||
if (gethostname(name, sizeof(name)))
|
||||
return;
|
||||
|
||||
struct hostent* pHost = gethostbyname(name);
|
||||
if (!pHost) return;
|
||||
|
||||
int s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (s == -1) return;
|
||||
|
||||
struct arpreq ar;
|
||||
std::memset(&ar, 0, sizeof(ar));
|
||||
struct sockaddr_in* pAddr = reinterpret_cast<struct sockaddr_in*>(&ar.arp_pa);
|
||||
pAddr->sin_family = AF_INET;
|
||||
std::memcpy(&pAddr->sin_addr, *pHost->h_addr_list, sizeof(struct in_addr));
|
||||
int rc = ioctl(s, SIOCGARP, &ar);
|
||||
close(s);
|
||||
if (rc < 0) return;
|
||||
std::memcpy(&id, ar.arp_ha.sa_data, sizeof(id));
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
|
||||
Poco::UInt32 count;
|
||||
unsigned short length;
|
||||
|
||||
ILE3 items[2];
|
||||
items[0].ile3$w_code = SYI$_ACTIVECPU_CNT;
|
||||
items[0].ile3$w_length = sizeof(count);
|
||||
items[0].ile3$ps_bufaddr = &count;
|
||||
items[0].ile3$ps_retlen_addr = &length;
|
||||
items[1].ile3$w_code = 0;
|
||||
items[1].ile3$w_length = 0;
|
||||
|
||||
if (sys$getsyiw(0, 0, 0, items, 0, 0, 0) == 1)
|
||||
return count;
|
||||
else
|
||||
throw SystemException("$GETSYI failed");
|
||||
|
||||
#pragma pointer_size restore
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getsyi(unsigned short code)
|
||||
{
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
|
||||
unsigned char result[16];
|
||||
unsigned short length;
|
||||
|
||||
ILE3 items[2];
|
||||
items[0].ile3$w_code = code;
|
||||
items[0].ile3$w_length = sizeof(result);
|
||||
items[0].ile3$ps_bufaddr = result;
|
||||
items[0].ile3$ps_retlen_addr = &length;
|
||||
items[1].ile3$w_code = 0;
|
||||
items[1].ile3$w_length = 0;
|
||||
|
||||
if (sys$getsyiw(0, 0, 0, items, 0, 0, 0) == 1)
|
||||
return std::string((char*) result, length);
|
||||
else
|
||||
throw SystemException("$GETSYI failed");
|
||||
|
||||
#pragma pointer_size restore
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::trnlnm(const std::string& name)
|
||||
{
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
|
||||
unsigned char result[LNM$C_NAMLENGTH];
|
||||
unsigned short length;
|
||||
|
||||
ILE3 items[2];
|
||||
items[0].ile3$w_code = LNM$_STRING;
|
||||
items[0].ile3$w_length = sizeof(result);
|
||||
items[0].ile3$ps_bufaddr = result;
|
||||
items[0].ile3$ps_retlen_addr = &length;
|
||||
items[1].ile3$w_code = 0;
|
||||
items[1].ile3$w_length = 0;
|
||||
|
||||
#pragma pointer_size restore
|
||||
|
||||
unsigned int trnAttr = LNM$M_CASE_BLIND;
|
||||
POCO_DESCRIPTOR_LITERAL(tableDsc, "LNM$FILE_DEV");
|
||||
POCO_DESCRIPTOR_STRING(nameDsc, name);
|
||||
if (sys$trnlnm(&trnAttr, &tableDsc, &nameDsc, 0, &items) == 1)
|
||||
{
|
||||
if (result[0] == 0x1B)
|
||||
return std::string((char*) result + 4, length - 4);
|
||||
else
|
||||
return std::string((char*) result, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,181 +0,0 @@
|
||||
|
||||
// Environment_VX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_VX.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_VX.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include <VxWorks.h>
|
||||
#include <envLib.h>
|
||||
#include <hostLib.h>
|
||||
#include <ifLib.h>
|
||||
#include <sockLib.h>
|
||||
#include <ioLib.h>
|
||||
#include <version.h>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/if_ether.h>
|
||||
#include <ifLib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EnvironmentImpl::StringMap EnvironmentImpl::_map;
|
||||
FastMutex EnvironmentImpl::_mutex;
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
const char* val = getenv(name.c_str());
|
||||
if (val)
|
||||
return std::string(val);
|
||||
else
|
||||
throw NotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return getenv(name.c_str()) != 0;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string var = name;
|
||||
var.append("=");
|
||||
var.append(value);
|
||||
_map[name] = var;
|
||||
if (putenv((char*) _map[name].c_str()))
|
||||
{
|
||||
std::string msg = "cannot set environment variable: ";
|
||||
msg.append(name);
|
||||
throw SystemException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
return runtimeName;
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
return runtimeVersion;
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
#if POCO_ARCH == POCO_ARCH_IA32
|
||||
return "i386";
|
||||
#elif POCO_ARCH == POCO_ARCH_MIPS
|
||||
return "mips";
|
||||
#elif POCO_ARCH == POCO_ARCH_PPC
|
||||
return "ppc";
|
||||
#elif POCO_ARCH == POCO_ARCH_ARM
|
||||
return "arm";
|
||||
#elif POCO_ARCH == POCO_ARCH_SH
|
||||
return "sh";
|
||||
#else
|
||||
return "unknown";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
char buffer[64];
|
||||
if (gethostname(buffer, sizeof(buffer)) == OK)
|
||||
return buffer;
|
||||
else
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
|
||||
int ifIndex = 1;
|
||||
char ifName[32];
|
||||
for (;;)
|
||||
{
|
||||
if (ifIndexToIfName(ifIndex, ifName) == OK)
|
||||
{
|
||||
struct ifnet* pIf = ifunit(ifName);
|
||||
if (pIf)
|
||||
{
|
||||
std::memcpy(&id, ((struct arpcom *) pIf)->ac_enaddr, sizeof(id));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else break;
|
||||
++ifIndex;
|
||||
}
|
||||
throw SystemException("cannot get Ethernet hardware address");
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,242 +0,0 @@
|
||||
//
|
||||
// Environment_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_WIN32.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include "Poco/UnWindows.h"
|
||||
#include <iphlpapi.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
DWORD len = GetEnvironmentVariableA(name.c_str(), 0, 0);
|
||||
if (len == 0) throw NotFoundException(name);
|
||||
char* buffer = new char[len];
|
||||
GetEnvironmentVariableA(name.c_str(), buffer, len);
|
||||
std::string result(buffer);
|
||||
delete [] buffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
DWORD len = GetEnvironmentVariableA(name.c_str(), 0, 0);
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (SetEnvironmentVariableA(name.c_str(), value.c_str()) == 0)
|
||||
{
|
||||
std::string msg = "cannot set environment variable: ";
|
||||
msg.append(name);
|
||||
throw SystemException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
switch (vi.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32s:
|
||||
return "Windows 3.x";
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
return vi.dwMinorVersion == 0 ? "Windows 95" : "Windows 98";
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
return "Windows NT";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
switch(vi.dwMajorVersion)
|
||||
{
|
||||
case 6:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows Vista/Server 2008";
|
||||
case 1:
|
||||
return "Windows 7/Server 2008 SP2";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
case 5:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows 2000";
|
||||
case 1:
|
||||
return "Windows XP";
|
||||
case 2:
|
||||
return "Windows Server 2003/Windows Server 2003 R2";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
case 4:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows 95/Windows NT 4.0";
|
||||
case 10:
|
||||
return "Windows 98";
|
||||
case 90:
|
||||
return "Windows ME";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
std::ostringstream str;
|
||||
str << vi.dwMajorVersion << "." << vi.dwMinorVersion << " (Build " << (vi.dwBuildNumber & 0xFFFF);
|
||||
if (vi.szCSDVersion[0]) str << ": " << vi.szCSDVersion;
|
||||
str << ")";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
switch (si.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
return "IA32";
|
||||
case PROCESSOR_ARCHITECTURE_MIPS:
|
||||
return "MIPS";
|
||||
case PROCESSOR_ARCHITECTURE_ALPHA:
|
||||
return "ALPHA";
|
||||
case PROCESSOR_ARCHITECTURE_PPC:
|
||||
return "PPC";
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
return "IA64";
|
||||
#ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
||||
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
|
||||
return "IA64/32";
|
||||
#endif
|
||||
#ifdef PROCESSOR_ARCHITECTURE_AMD64
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
return "AMD64";
|
||||
#endif
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
char name[MAX_COMPUTERNAME_LENGTH + 1];
|
||||
DWORD size = sizeof(name);
|
||||
if (GetComputerNameA(name, &size) == 0) throw SystemException("Cannot get computer name");
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter = 0;
|
||||
ULONG len = sizeof(IP_ADAPTER_INFO);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
// Make an initial call to GetAdaptersInfo to get
|
||||
// the necessary size into len
|
||||
DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
|
||||
if (rc == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
}
|
||||
else if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (GetAdaptersInfo(pAdapterInfo, &len) == NO_ERROR)
|
||||
{
|
||||
pAdapter = pAdapterInfo;
|
||||
bool found = false;
|
||||
while (pAdapter && !found)
|
||||
{
|
||||
if (pAdapter->Type == MIB_IF_TYPE_ETHERNET && pAdapter->AddressLength == sizeof(id))
|
||||
{
|
||||
found = true;
|
||||
std::memcpy(&id, pAdapter->Address, pAdapter->AddressLength);
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return si.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,256 +0,0 @@
|
||||
//
|
||||
// Environment_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WIN32U.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_WIN32U.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include "Poco/UnWindows.h"
|
||||
#include <iphlpapi.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
std::wstring uname;
|
||||
UnicodeConverter::toUTF16(name, uname);
|
||||
DWORD len = GetEnvironmentVariableW(uname.c_str(), 0, 0);
|
||||
if (len == 0) throw NotFoundException(name);
|
||||
Buffer<wchar_t> buffer(len);
|
||||
GetEnvironmentVariableW(uname.c_str(), buffer.begin(), len);
|
||||
std::string result;
|
||||
UnicodeConverter::toUTF8(buffer.begin(), len - 1, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
std::wstring uname;
|
||||
UnicodeConverter::toUTF16(name, uname);
|
||||
DWORD len = GetEnvironmentVariableW(uname.c_str(), 0, 0);
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
std::wstring uname;
|
||||
std::wstring uvalue;
|
||||
UnicodeConverter::toUTF16(name, uname);
|
||||
UnicodeConverter::toUTF16(value, uvalue);
|
||||
if (SetEnvironmentVariableW(uname.c_str(), uvalue.c_str()) == 0)
|
||||
{
|
||||
std::string msg = "cannot set environment variable: ";
|
||||
msg.append(name);
|
||||
throw SystemException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
switch (vi.dwPlatformId)
|
||||
{
|
||||
case VER_PLATFORM_WIN32s:
|
||||
return "Windows 3.x";
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
return vi.dwMinorVersion == 0 ? "Windows 95" : "Windows 98";
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
return "Windows NT";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
OSVERSIONINFO vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
switch(vi.dwMajorVersion)
|
||||
{
|
||||
case 6:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows Vista/Server 2008";
|
||||
case 1:
|
||||
return "Windows 7/Server 2008 SP2";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
case 5:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows 2000";
|
||||
case 1:
|
||||
return "Windows XP";
|
||||
case 2:
|
||||
return "Windows Server 2003/Windows Server 2003 R2";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
case 4:
|
||||
switch (vi.dwMinorVersion)
|
||||
{
|
||||
case 0:
|
||||
return "Windows 95/Windows NT 4.0";
|
||||
case 10:
|
||||
return "Windows 98";
|
||||
case 90:
|
||||
return "Windows ME";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
OSVERSIONINFOW vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionExW(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
std::ostringstream str;
|
||||
str << vi.dwMajorVersion << "." << vi.dwMinorVersion << " (Build " << (vi.dwBuildNumber & 0xFFFF);
|
||||
std::string version;
|
||||
UnicodeConverter::toUTF8(vi.szCSDVersion, version);
|
||||
if (!version.empty()) str << ": " << version;
|
||||
str << ")";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
switch (si.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
return "IA32";
|
||||
case PROCESSOR_ARCHITECTURE_MIPS:
|
||||
return "MIPS";
|
||||
case PROCESSOR_ARCHITECTURE_ALPHA:
|
||||
return "ALPHA";
|
||||
case PROCESSOR_ARCHITECTURE_PPC:
|
||||
return "PPC";
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
return "IA64";
|
||||
#ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
||||
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
|
||||
return "IA64/32";
|
||||
#endif
|
||||
#ifdef PROCESSOR_ARCHITECTURE_AMD64
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
return "AMD64";
|
||||
#endif
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
wchar_t name[MAX_COMPUTERNAME_LENGTH + 1];
|
||||
DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
if (GetComputerNameW(name, &size) == 0) throw SystemException("Cannot get computer name");
|
||||
std::string result;
|
||||
UnicodeConverter::toUTF8(name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(id));
|
||||
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter = 0;
|
||||
ULONG len = sizeof(IP_ADAPTER_INFO);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
// Make an initial call to GetAdaptersInfo to get
|
||||
// the necessary size into len
|
||||
DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
|
||||
if (rc == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
}
|
||||
else if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (GetAdaptersInfo(pAdapterInfo, &len) == NO_ERROR)
|
||||
{
|
||||
pAdapter = pAdapterInfo;
|
||||
bool found = false;
|
||||
while (pAdapter && !found)
|
||||
{
|
||||
if (pAdapter->Type == MIB_IF_TYPE_ETHERNET && pAdapter->AddressLength == sizeof(id))
|
||||
{
|
||||
found = true;
|
||||
std::memcpy(&id, pAdapter->Address, pAdapter->AddressLength);
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return si.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,265 +0,0 @@
|
||||
//
|
||||
// Environment_WINCE.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WINCE.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Environment
|
||||
//
|
||||
// Copyright (c) 2009-2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Environment_WINCE.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <windows.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const std::string EnvironmentImpl::TEMP("TEMP");
|
||||
const std::string EnvironmentImpl::TMP("TMP");
|
||||
const std::string EnvironmentImpl::HOMEPATH("HOMEPATH");
|
||||
const std::string EnvironmentImpl::COMPUTERNAME("COMPUTERNAME");
|
||||
const std::string EnvironmentImpl::OS("OS");
|
||||
const std::string EnvironmentImpl::NUMBER_OF_PROCESSORS("NUMBER_OF_PROCESSORS");
|
||||
const std::string EnvironmentImpl::PROCESSOR_ARCHITECTURE("PROCESSOR_ARCHITECTURE");
|
||||
|
||||
|
||||
std::string EnvironmentImpl::getImpl(const std::string& name)
|
||||
{
|
||||
std::string value;
|
||||
if (!envVar(name, &value)) throw NotFoundException(name);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::hasImpl(const std::string& name)
|
||||
{
|
||||
return envVar(name, 0);
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::setImpl(const std::string& name, const std::string& value)
|
||||
{
|
||||
throw NotImplementedException("Cannot set environment variables on Windows CE");
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osNameImpl()
|
||||
{
|
||||
return "Windows CE";
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
OSVERSIONINFOW vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionExW(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
std::ostringstream str;
|
||||
str << vi.dwMajorVersion << "." << vi.dwMinorVersion << " (Build " << (vi.dwBuildNumber & 0xFFFF);
|
||||
std::string version;
|
||||
UnicodeConverter::toUTF8(vi.szCSDVersion, version);
|
||||
if (!version.empty()) str << ": " << version;
|
||||
str << ")";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osArchitectureImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
switch (si.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
return "IA32";
|
||||
case PROCESSOR_ARCHITECTURE_MIPS:
|
||||
return "MIPS";
|
||||
case PROCESSOR_ARCHITECTURE_ALPHA:
|
||||
return "ALPHA";
|
||||
case PROCESSOR_ARCHITECTURE_PPC:
|
||||
return "PPC";
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
return "IA64";
|
||||
#ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
|
||||
case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
|
||||
return "IA64/32";
|
||||
#endif
|
||||
#ifdef PROCESSOR_ARCHITECTURE_AMD64
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
return "AMD64";
|
||||
#endif
|
||||
case PROCESSOR_ARCHITECTURE_SHX:
|
||||
return "SHX";
|
||||
case PROCESSOR_ARCHITECTURE_ARM:
|
||||
return "ARM";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::nodeNameImpl()
|
||||
{
|
||||
HKEY hKey;
|
||||
DWORD dwDisposition;
|
||||
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"\\Ident", 0, 0, 0, 0, 0, &hKey, &dwDisposition) != ERROR_SUCCESS)
|
||||
throw SystemException("Cannot get node name", "registry key not found");
|
||||
|
||||
std::string value;
|
||||
DWORD dwType;
|
||||
BYTE bData[1026];
|
||||
DWORD dwData = sizeof(bData);
|
||||
if (RegQueryValueExW(hKey, L"Name", 0, &dwType, bData, &dwData) == ERROR_SUCCESS)
|
||||
{
|
||||
switch (dwType)
|
||||
{
|
||||
case REG_SZ:
|
||||
UnicodeConverter::toUTF8(reinterpret_cast<wchar_t*>(bData), value);
|
||||
break;
|
||||
|
||||
default:
|
||||
RegCloseKey(hKey);
|
||||
throw SystemException("Cannot get node name", "registry value has wrong type");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
throw SystemException("Cannot get node name", "registry value not found");
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter = 0;
|
||||
ULONG len = sizeof(IP_ADAPTER_INFO);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
// Make an initial call to GetAdaptersInfo to get
|
||||
// the necessary size into len
|
||||
DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
|
||||
if (rc == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
|
||||
}
|
||||
else if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
throw SystemException("cannot get network adapter list");
|
||||
}
|
||||
try
|
||||
{
|
||||
bool found = false;
|
||||
if (GetAdaptersInfo(pAdapterInfo, &len) == NO_ERROR)
|
||||
{
|
||||
pAdapter = pAdapterInfo;
|
||||
while (pAdapter && !found)
|
||||
{
|
||||
if (pAdapter->Type == MIB_IF_TYPE_ETHERNET && pAdapter->AddressLength == sizeof(id))
|
||||
{
|
||||
std::memcpy(&id, pAdapter->Address, pAdapter->AddressLength);
|
||||
found = true;
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
else throw SystemException("cannot get network adapter list");
|
||||
if (!found) throw SystemException("no Ethernet adapter found");
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
throw;
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(pAdapterInfo);
|
||||
}
|
||||
|
||||
|
||||
unsigned EnvironmentImpl::processorCountImpl()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return si.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
bool EnvironmentImpl::envVar(const std::string& name, std::string* value)
|
||||
{
|
||||
if (icompare(name, TEMP) == 0)
|
||||
{
|
||||
if (value) *value = Path::temp();
|
||||
}
|
||||
else if (icompare(name, TMP) == 0)
|
||||
{
|
||||
if (value) *value = Path::temp();
|
||||
}
|
||||
else if (icompare(name, HOMEPATH) == 0)
|
||||
{
|
||||
if (value) *value = Path::home();
|
||||
}
|
||||
else if (icompare(name, COMPUTERNAME) == 0)
|
||||
{
|
||||
if (value) *value = nodeNameImpl();
|
||||
}
|
||||
else if (icompare(name, OS) == 0)
|
||||
{
|
||||
if (value) *value = osNameImpl();
|
||||
}
|
||||
else if (icompare(name, NUMBER_OF_PROCESSORS) == 0)
|
||||
{
|
||||
if (value) *value = NumberFormatter::format(processorCountImpl());
|
||||
}
|
||||
else if (icompare(name, PROCESSOR_ARCHITECTURE) == 0)
|
||||
{
|
||||
if (value) *value = osArchitectureImpl();
|
||||
}
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,136 +0,0 @@
|
||||
//
|
||||
// ErrorHandler.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/ErrorHandler.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: ErrorHandler
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/ErrorHandler.h"
|
||||
#include "Poco/SingletonHolder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
ErrorHandler* ErrorHandler::_pHandler = ErrorHandler::defaultHandler();
|
||||
FastMutex ErrorHandler::_mutex;
|
||||
|
||||
|
||||
ErrorHandler::ErrorHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ErrorHandler::~ErrorHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::exception(const Exception& exc)
|
||||
{
|
||||
poco_debugger_msg(exc.what());
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::exception(const std::exception& exc)
|
||||
{
|
||||
poco_debugger_msg(exc.what());
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::exception()
|
||||
{
|
||||
poco_debugger_msg("unknown exception");
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::handle(const Exception& exc)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
try
|
||||
{
|
||||
_pHandler->exception(exc);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::handle(const std::exception& exc)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
try
|
||||
{
|
||||
_pHandler->exception(exc);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ErrorHandler::handle()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
try
|
||||
{
|
||||
_pHandler->exception();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ErrorHandler* ErrorHandler::set(ErrorHandler* pHandler)
|
||||
{
|
||||
poco_check_ptr(pHandler);
|
||||
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
ErrorHandler* pOld = _pHandler;
|
||||
_pHandler = pHandler;
|
||||
return pOld;
|
||||
}
|
||||
|
||||
|
||||
ErrorHandler* ErrorHandler::defaultHandler()
|
||||
{
|
||||
// NOTE: Since this is called to initialize the static _pHandler
|
||||
// variable, sh has to be a local static, otherwise we run
|
||||
// into static initialization order issues.
|
||||
static SingletonHolder<ErrorHandler> sh;
|
||||
return sh.get();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// Event.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Event.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Event
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Event_WIN32.cpp"
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include "Event_VX.cpp"
|
||||
#else
|
||||
#include "Event_POSIX.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Event::Event(bool autoReset): EventImpl(autoReset)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// EventArgs.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/EventArgs.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
// Module: EventArgs
|
||||
//
|
||||
// Implementation of EventArgs
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/EventArgs.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EventArgs::EventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EventArgs::~EventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,315 +0,0 @@
|
||||
//
|
||||
// EventLogChannel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/EventLogChannel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: EventLogChannel
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/EventLogChannel.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/String.h"
|
||||
#include "pocomsg.h"
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const std::string EventLogChannel::PROP_NAME = "name";
|
||||
const std::string EventLogChannel::PROP_HOST = "host";
|
||||
const std::string EventLogChannel::PROP_LOGHOST = "loghost";
|
||||
const std::string EventLogChannel::PROP_LOGFILE = "logfile";
|
||||
|
||||
|
||||
EventLogChannel::EventLogChannel():
|
||||
_logFile("Application"),
|
||||
_h(0)
|
||||
{
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
wchar_t name[256];
|
||||
int n = GetModuleFileNameW(NULL, name, sizeof(name));
|
||||
if (n > 0)
|
||||
{
|
||||
wchar_t* end = name + n - 1;
|
||||
while (end > name && *end != '\\') --end;
|
||||
if (*end == '\\') ++end;
|
||||
std::wstring uname(end);
|
||||
UnicodeConverter::toUTF8(uname, _name);
|
||||
}
|
||||
#else
|
||||
char name[256];
|
||||
int n = GetModuleFileNameA(NULL, name, sizeof(name));
|
||||
if (n > 0)
|
||||
{
|
||||
char* end = name + n - 1;
|
||||
while (end > name && *end != '\\') --end;
|
||||
if (*end == '\\') ++end;
|
||||
_name = end;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
EventLogChannel::EventLogChannel(const std::string& name):
|
||||
_name(name),
|
||||
_logFile("Application"),
|
||||
_h(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EventLogChannel::EventLogChannel(const std::string& name, const std::string& host):
|
||||
_name(name),
|
||||
_host(host),
|
||||
_logFile("Application"),
|
||||
_h(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EventLogChannel::~EventLogChannel()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void EventLogChannel::open()
|
||||
{
|
||||
setUpRegistry();
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uhost;
|
||||
UnicodeConverter::toUTF16(_host, uhost);
|
||||
std::wstring uname;
|
||||
UnicodeConverter::toUTF16(_name, uname);
|
||||
_h = RegisterEventSourceW(uhost.empty() ? NULL : uhost.c_str(), uname.c_str());
|
||||
#else
|
||||
_h = RegisterEventSource(_host.empty() ? NULL : _host.c_str(), _name.c_str());
|
||||
#endif
|
||||
if (!_h) throw SystemException("cannot register event source");
|
||||
}
|
||||
|
||||
|
||||
void EventLogChannel::close()
|
||||
{
|
||||
if (_h) DeregisterEventSource(_h);
|
||||
_h = 0;
|
||||
}
|
||||
|
||||
|
||||
void EventLogChannel::log(const Message& msg)
|
||||
{
|
||||
if (!_h) open();
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring utext;
|
||||
UnicodeConverter::toUTF16(msg.getText(), utext);
|
||||
const wchar_t* pMsg = utext.c_str();
|
||||
ReportEventW(_h, getType(msg), getCategory(msg), POCO_MSG_LOG, NULL, 1, 0, &pMsg, NULL);
|
||||
#else
|
||||
const char* pMsg = msg.getText().c_str();
|
||||
ReportEvent(_h, getType(msg), getCategory(msg), POCO_MSG_LOG, NULL, 1, 0, &pMsg, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void EventLogChannel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (icompare(name, PROP_NAME) == 0)
|
||||
_name = value;
|
||||
else if (icompare(name, PROP_HOST) == 0)
|
||||
_host = value;
|
||||
else if (icompare(name, PROP_LOGHOST) == 0)
|
||||
_host = value;
|
||||
else if (icompare(name, PROP_LOGFILE) == 0)
|
||||
_logFile = value;
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
std::string EventLogChannel::getProperty(const std::string& name) const
|
||||
{
|
||||
if (icompare(name, PROP_NAME) == 0)
|
||||
return _name;
|
||||
else if (icompare(name, PROP_HOST) == 0)
|
||||
return _host;
|
||||
else if (icompare(name, PROP_LOGHOST) == 0)
|
||||
return _host;
|
||||
else if (icompare(name, PROP_LOGFILE) == 0)
|
||||
return _logFile;
|
||||
else
|
||||
return Channel::getProperty(name);
|
||||
}
|
||||
|
||||
|
||||
int EventLogChannel::getType(const Message& msg)
|
||||
{
|
||||
switch (msg.getPriority())
|
||||
{
|
||||
case Message::PRIO_TRACE:
|
||||
case Message::PRIO_DEBUG:
|
||||
case Message::PRIO_INFORMATION:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
case Message::PRIO_NOTICE:
|
||||
case Message::PRIO_WARNING:
|
||||
return EVENTLOG_WARNING_TYPE;
|
||||
default:
|
||||
return EVENTLOG_ERROR_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int EventLogChannel::getCategory(const Message& msg)
|
||||
{
|
||||
switch (msg.getPriority())
|
||||
{
|
||||
case Message::PRIO_TRACE:
|
||||
return POCO_CTG_TRACE;
|
||||
case Message::PRIO_DEBUG:
|
||||
return POCO_CTG_DEBUG;
|
||||
case Message::PRIO_INFORMATION:
|
||||
return POCO_CTG_INFORMATION;
|
||||
case Message::PRIO_NOTICE:
|
||||
return POCO_CTG_NOTICE;
|
||||
case Message::PRIO_WARNING:
|
||||
return POCO_CTG_WARNING;
|
||||
case Message::PRIO_ERROR:
|
||||
return POCO_CTG_ERROR;
|
||||
case Message::PRIO_CRITICAL:
|
||||
return POCO_CTG_CRITICAL;
|
||||
case Message::PRIO_FATAL:
|
||||
return POCO_CTG_FATAL;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EventLogChannel::setUpRegistry() const
|
||||
{
|
||||
std::string key = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\";
|
||||
key.append(_logFile);
|
||||
key.append("\\");
|
||||
key.append(_name);
|
||||
HKEY hKey;
|
||||
DWORD disp;
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring ukey;
|
||||
UnicodeConverter::toUTF16(key, ukey);
|
||||
DWORD rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ukey.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
|
||||
#else
|
||||
DWORD rc = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
|
||||
#endif
|
||||
if (rc != ERROR_SUCCESS) return;
|
||||
|
||||
if (disp == REG_CREATED_NEW_KEY)
|
||||
{
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring path;
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
path = findLibrary(L"PocoFoundationd.dll");
|
||||
#else
|
||||
path = findLibrary(L"PocoFoundation.dll");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (path.empty())
|
||||
path = findLibrary(L"PocoMsg.dll");
|
||||
#else
|
||||
std::string path;
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
path = findLibrary("PocoFoundationd.dll");
|
||||
#else
|
||||
path = findLibrary("PocoFoundation.dll");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (path.empty())
|
||||
path = findLibrary("PocoMsg.dll");
|
||||
#endif
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
DWORD count = 8;
|
||||
DWORD types = 7;
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
RegSetValueExW(hKey, L"CategoryMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(sizeof(wchar_t)*(path.size() + 1)));
|
||||
RegSetValueExW(hKey, L"EventMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(sizeof(wchar_t)*(path.size() + 1)));
|
||||
RegSetValueExW(hKey, L"CategoryCount", 0, REG_DWORD, (const BYTE*) &count, static_cast<DWORD>(sizeof(count)));
|
||||
RegSetValueExW(hKey, L"TypesSupported", 0, REG_DWORD, (const BYTE*) &types, static_cast<DWORD>(sizeof(types)));
|
||||
#else
|
||||
RegSetValueEx(hKey, "CategoryMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(path.size() + 1));
|
||||
RegSetValueEx(hKey, "EventMessageFile", 0, REG_SZ, (const BYTE*) path.c_str(), static_cast<DWORD>(path.size() + 1));
|
||||
RegSetValueEx(hKey, "CategoryCount", 0, REG_DWORD, (const BYTE*) &count, static_cast<DWORD>(sizeof(count)));
|
||||
RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (const BYTE*) &types, static_cast<DWORD>(sizeof(types)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring EventLogChannel::findLibrary(const wchar_t* name)
|
||||
{
|
||||
std::wstring path;
|
||||
HMODULE dll = LoadLibraryW(name);
|
||||
if (dll)
|
||||
{
|
||||
wchar_t name[MAX_PATH + 1];
|
||||
int n = GetModuleFileNameW(dll, name, sizeof(name));
|
||||
if (n > 0) path = name;
|
||||
FreeLibrary(dll);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
#else
|
||||
std::string EventLogChannel::findLibrary(const char* name)
|
||||
{
|
||||
std::string path;
|
||||
HMODULE dll = LoadLibraryA(name);
|
||||
if (dll)
|
||||
{
|
||||
char name[MAX_PATH + 1];
|
||||
int n = GetModuleFileNameA(dll, name, sizeof(name));
|
||||
if (n > 0) path = name;
|
||||
FreeLibrary(dll);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,138 +0,0 @@
|
||||
//
|
||||
// Event_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Event_POSIX.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Event
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Event_POSIX.h"
|
||||
#if defined(POCO_VXWORKS)
|
||||
#include <timers.h>
|
||||
#include <cstring>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
// This workaround is for VxWorks 5.x where
|
||||
// pthread_mutex_init() won't properly initialize the mutex
|
||||
// resulting in a subsequent freeze in pthread_mutex_destroy()
|
||||
// if the mutex has never been used.
|
||||
std::memset(&_mutex, 0, sizeof(_mutex));
|
||||
#endif
|
||||
if (pthread_mutex_init(&_mutex, NULL))
|
||||
throw SystemException("cannot create event (mutex)");
|
||||
if (pthread_cond_init(&_cond, NULL))
|
||||
throw SystemException("cannot create event (condition)");
|
||||
}
|
||||
|
||||
|
||||
EventImpl::~EventImpl()
|
||||
{
|
||||
pthread_cond_destroy(&_cond);
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
}
|
||||
|
||||
|
||||
void EventImpl::waitImpl()
|
||||
{
|
||||
if (pthread_mutex_lock(&_mutex))
|
||||
throw SystemException("wait for event failed (lock)");
|
||||
while (!_state)
|
||||
{
|
||||
if (pthread_cond_wait(&_cond, &_mutex))
|
||||
{
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
throw SystemException("wait for event failed");
|
||||
}
|
||||
}
|
||||
if (_auto)
|
||||
_state = false;
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
}
|
||||
|
||||
|
||||
bool EventImpl::waitImpl(long milliseconds)
|
||||
{
|
||||
int rc = 0;
|
||||
struct timespec abstime;
|
||||
|
||||
#if defined(__VMS)
|
||||
struct timespec delta;
|
||||
delta.tv_sec = milliseconds / 1000;
|
||||
delta.tv_nsec = (milliseconds % 1000)*1000000;
|
||||
pthread_get_expiration_np(&delta, &abstime);
|
||||
#elif defined(POCO_VXWORKS)
|
||||
clock_gettime(CLOCK_REALTIME, &abstime);
|
||||
abstime.tv_sec += milliseconds / 1000;
|
||||
abstime.tv_nsec += (milliseconds % 1000)*1000000;
|
||||
if (abstime.tv_nsec >= 1000000000)
|
||||
{
|
||||
abstime.tv_nsec -= 1000000000;
|
||||
abstime.tv_sec++;
|
||||
}
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
abstime.tv_sec = tv.tv_sec + milliseconds / 1000;
|
||||
abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
|
||||
if (abstime.tv_nsec >= 1000000000)
|
||||
{
|
||||
abstime.tv_nsec -= 1000000000;
|
||||
abstime.tv_sec++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pthread_mutex_lock(&_mutex) != 0)
|
||||
throw SystemException("wait for event failed (lock)");
|
||||
while (!_state)
|
||||
{
|
||||
if ((rc = pthread_cond_timedwait(&_cond, &_mutex, &abstime)))
|
||||
{
|
||||
if (rc == ETIMEDOUT) break;
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
throw SystemException("cannot wait for event");
|
||||
}
|
||||
}
|
||||
if (rc == 0 && _auto) _state = false;
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,101 +0,0 @@
|
||||
//
|
||||
// Event_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Event_VX.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Event
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Event_VX.h"
|
||||
#include <sysLib.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EventImpl::EventImpl(bool autoReset): _auto(autoReset), _state(false)
|
||||
{
|
||||
_sem = semCCreate(SEM_Q_PRIORITY, 0);
|
||||
if (_sem == 0)
|
||||
throw Poco::SystemException("cannot create event");
|
||||
}
|
||||
|
||||
|
||||
EventImpl::~EventImpl()
|
||||
{
|
||||
semDelete(_sem);
|
||||
}
|
||||
|
||||
|
||||
void EventImpl::setImpl()
|
||||
{
|
||||
if (_auto)
|
||||
{
|
||||
if (semGive(_sem) != OK)
|
||||
throw SystemException("cannot set event");
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = true;
|
||||
if (semFlush(_sem) != OK)
|
||||
throw SystemException("cannot set event");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EventImpl::resetImpl()
|
||||
{
|
||||
_state = false;
|
||||
}
|
||||
|
||||
|
||||
void EventImpl::waitImpl()
|
||||
{
|
||||
if (!_state)
|
||||
{
|
||||
if (semTake(_sem, WAIT_FOREVER) != OK)
|
||||
throw SystemException("cannot wait for event");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EventImpl::waitImpl(long milliseconds)
|
||||
{
|
||||
if (!_state)
|
||||
{
|
||||
int ticks = milliseconds*sysClkRateGet()/1000;
|
||||
return semTake(_sem, ticks) == OK;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,83 +0,0 @@
|
||||
//
|
||||
// Event_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Event_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Event
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Event_WIN32.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
EventImpl::EventImpl(bool autoReset)
|
||||
{
|
||||
_event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL);
|
||||
if (!_event)
|
||||
throw SystemException("cannot create event");
|
||||
}
|
||||
|
||||
|
||||
EventImpl::~EventImpl()
|
||||
{
|
||||
CloseHandle(_event);
|
||||
}
|
||||
|
||||
|
||||
void EventImpl::waitImpl()
|
||||
{
|
||||
switch (WaitForSingleObject(_event, INFINITE))
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
return;
|
||||
default:
|
||||
throw SystemException("wait for event failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EventImpl::waitImpl(long milliseconds)
|
||||
{
|
||||
switch (WaitForSingleObject(_event, milliseconds + 1))
|
||||
{
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
case WAIT_OBJECT_0:
|
||||
return true;
|
||||
default:
|
||||
throw SystemException("wait for event failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,199 +0,0 @@
|
||||
//
|
||||
// Exception.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Exception.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Exception
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Exception.h"
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Exception::Exception(int code): _pNested(0), _code(code)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Exception::Exception(const std::string& msg, int code): _msg(msg), _pNested(0), _code(code)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Exception::Exception(const std::string& msg, const std::string& arg, int code): _msg(msg), _pNested(0), _code(code)
|
||||
{
|
||||
if (!arg.empty())
|
||||
{
|
||||
_msg.append(": ");
|
||||
_msg.append(arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Exception::Exception(const std::string& msg, const Exception& nested, int code): _msg(msg), _pNested(nested.clone()), _code(code)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Exception::Exception(const Exception& exc):
|
||||
std::exception(exc),
|
||||
_msg(exc._msg),
|
||||
_code(exc._code)
|
||||
{
|
||||
_pNested = exc._pNested ? exc._pNested->clone() : 0;
|
||||
}
|
||||
|
||||
|
||||
Exception::~Exception() throw()
|
||||
{
|
||||
delete _pNested;
|
||||
}
|
||||
|
||||
|
||||
Exception& Exception::operator = (const Exception& exc)
|
||||
{
|
||||
if (&exc != this)
|
||||
{
|
||||
delete _pNested;
|
||||
_msg = exc._msg;
|
||||
_pNested = exc._pNested ? exc._pNested->clone() : 0;
|
||||
_code = exc._code;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const char* Exception::name() const throw()
|
||||
{
|
||||
return "Exception";
|
||||
}
|
||||
|
||||
|
||||
const char* Exception::className() const throw()
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
|
||||
const char* Exception::what() const throw()
|
||||
{
|
||||
return name();
|
||||
}
|
||||
|
||||
|
||||
std::string Exception::displayText() const
|
||||
{
|
||||
std::string txt = name();
|
||||
if (!_msg.empty())
|
||||
{
|
||||
txt.append(": ");
|
||||
txt.append(_msg);
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
|
||||
void Exception::extendedMessage(const std::string& arg)
|
||||
{
|
||||
if (!arg.empty())
|
||||
{
|
||||
if (!_msg.empty()) _msg.append(": ");
|
||||
_msg.append(arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Exception* Exception::clone() const
|
||||
{
|
||||
return new Exception(*this);
|
||||
}
|
||||
|
||||
|
||||
void Exception::rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(LogicException, Exception, "Logic exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(AssertionViolationException, LogicException, "Assertion violation")
|
||||
POCO_IMPLEMENT_EXCEPTION(NullPointerException, LogicException, "Null pointer")
|
||||
POCO_IMPLEMENT_EXCEPTION(NullValueException, LogicException, "Null value")
|
||||
POCO_IMPLEMENT_EXCEPTION(BugcheckException, LogicException, "Bugcheck")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidArgumentException, LogicException, "Invalid argument")
|
||||
POCO_IMPLEMENT_EXCEPTION(NotImplementedException, LogicException, "Not implemented")
|
||||
POCO_IMPLEMENT_EXCEPTION(RangeException, LogicException, "Out of range")
|
||||
POCO_IMPLEMENT_EXCEPTION(IllegalStateException, LogicException, "Illegal state")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidAccessException, LogicException, "Invalid access")
|
||||
POCO_IMPLEMENT_EXCEPTION(SignalException, LogicException, "Signal received")
|
||||
POCO_IMPLEMENT_EXCEPTION(UnhandledException, LogicException, "Unhandled exception")
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(RuntimeException, Exception, "Runtime exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(NotFoundException, RuntimeException, "Not found")
|
||||
POCO_IMPLEMENT_EXCEPTION(ExistsException, RuntimeException, "Exists")
|
||||
POCO_IMPLEMENT_EXCEPTION(TimeoutException, RuntimeException, "Timeout")
|
||||
POCO_IMPLEMENT_EXCEPTION(SystemException, RuntimeException, "System exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(RegularExpressionException, RuntimeException, "Error in regular expression")
|
||||
POCO_IMPLEMENT_EXCEPTION(LibraryLoadException, RuntimeException, "Cannot load library")
|
||||
POCO_IMPLEMENT_EXCEPTION(LibraryAlreadyLoadedException, RuntimeException, "Library already loaded")
|
||||
POCO_IMPLEMENT_EXCEPTION(NoThreadAvailableException, RuntimeException, "No thread available")
|
||||
POCO_IMPLEMENT_EXCEPTION(PropertyNotSupportedException, RuntimeException, "Property not supported")
|
||||
POCO_IMPLEMENT_EXCEPTION(PoolOverflowException, RuntimeException, "Pool overflow")
|
||||
POCO_IMPLEMENT_EXCEPTION(NoPermissionException, RuntimeException, "No permission")
|
||||
POCO_IMPLEMENT_EXCEPTION(OutOfMemoryException, RuntimeException, "Out of memory")
|
||||
POCO_IMPLEMENT_EXCEPTION(DataException, RuntimeException, "Data error")
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(DataFormatException, DataException, "Bad data format")
|
||||
POCO_IMPLEMENT_EXCEPTION(SyntaxException, DataException, "Syntax error")
|
||||
POCO_IMPLEMENT_EXCEPTION(CircularReferenceException, DataException, "Circular reference")
|
||||
POCO_IMPLEMENT_EXCEPTION(PathSyntaxException, SyntaxException, "Bad path syntax")
|
||||
POCO_IMPLEMENT_EXCEPTION(IOException, RuntimeException, "I/O error")
|
||||
POCO_IMPLEMENT_EXCEPTION(ProtocolException, IOException, "Protocol error")
|
||||
POCO_IMPLEMENT_EXCEPTION(FileException, IOException, "File access error")
|
||||
POCO_IMPLEMENT_EXCEPTION(FileExistsException, FileException, "File exists")
|
||||
POCO_IMPLEMENT_EXCEPTION(FileNotFoundException, FileException, "File not found")
|
||||
POCO_IMPLEMENT_EXCEPTION(PathNotFoundException, FileException, "Path not found")
|
||||
POCO_IMPLEMENT_EXCEPTION(FileReadOnlyException, FileException, "File is read-only")
|
||||
POCO_IMPLEMENT_EXCEPTION(FileAccessDeniedException, FileException, "Access to file denied")
|
||||
POCO_IMPLEMENT_EXCEPTION(CreateFileException, FileException, "Cannot create file")
|
||||
POCO_IMPLEMENT_EXCEPTION(OpenFileException, FileException, "Cannot open file")
|
||||
POCO_IMPLEMENT_EXCEPTION(WriteFileException, FileException, "Cannot write file")
|
||||
POCO_IMPLEMENT_EXCEPTION(ReadFileException, FileException, "Cannot read file")
|
||||
POCO_IMPLEMENT_EXCEPTION(UnknownURISchemeException, RuntimeException, "Unknown URI scheme")
|
||||
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception")
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,107 +0,0 @@
|
||||
//
|
||||
// FPEnvironment.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
// pull in platform identification macros needed below
|
||||
#include "Poco/Platform.h"
|
||||
|
||||
|
||||
#if defined(POCO_NO_FPENVIRONMENT)
|
||||
#include "FPEnvironment_DUMMY.cpp"
|
||||
#elif defined(__osf__) || defined(__VMS)
|
||||
#include "FPEnvironment_DEC.cpp"
|
||||
#elif defined(sun) || defined(__sun)
|
||||
#include "FPEnvironment_SUN.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "FPEnvironment_C99.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FPEnvironment_WIN32.cpp"
|
||||
#else
|
||||
#include "FPEnvironment_DUMMY.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
// header file must be included after platform-specific part
|
||||
// due to _XOPEN_SOURCE conflict on Tru64 (see FPEnvironment_DEC.cpp)
|
||||
#include "Poco/FPEnvironment.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironment::FPEnvironment()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironment::FPEnvironment(RoundingMode rm)
|
||||
{
|
||||
setRoundingMode(rm);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironment::FPEnvironment(const FPEnvironment& env): FPEnvironmentImpl(env)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironment::~FPEnvironment()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironment& FPEnvironment::operator = (const FPEnvironment& env)
|
||||
{
|
||||
if (&env != this)
|
||||
{
|
||||
FPEnvironmentImpl::operator = (env);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironment::keepCurrent()
|
||||
{
|
||||
keepCurrentImpl();
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironment::clearFlags()
|
||||
{
|
||||
clearFlagsImpl();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,104 +0,0 @@
|
||||
//
|
||||
// FPEnvironment_C99.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment_C99.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FPEnvironment_C99.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl()
|
||||
{
|
||||
fegetenv(&_env);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::~FPEnvironmentImpl()
|
||||
{
|
||||
fesetenv(&_env);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::keepCurrentImpl()
|
||||
{
|
||||
fegetenv(&_env);
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::clearFlagsImpl()
|
||||
{
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
|
||||
{
|
||||
return fetestexcept(flag) != 0;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
|
||||
{
|
||||
fesetround(mode);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
|
||||
{
|
||||
return (RoundingModeImpl) fegetround();
|
||||
}
|
||||
|
||||
|
||||
long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
|
||||
{
|
||||
return (source >= 0 && target >= 0) || (source < 0 && target < 0) ? target : -target;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,217 +0,0 @@
|
||||
//
|
||||
// FPEnvironment_DEC.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment_DEC.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// _XOPEN_SOURCE disables the ieee fp functions
|
||||
// in <math.h>, therefore we undefine it for this file.
|
||||
//
|
||||
#undef _XOPEN_SOURCE
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <fp.h>
|
||||
#include <fp_class.h>
|
||||
#if defined(__VMS)
|
||||
#include <starlet.h>
|
||||
#endif
|
||||
#include "Poco/FPEnvironment_DEC.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl()
|
||||
{
|
||||
#if defined(__VMS)
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
struct _ieee env;
|
||||
sys$ieee_set_fp_control(0, 0, &env);
|
||||
#pragma pointer_size restore
|
||||
_env = env;
|
||||
#else
|
||||
_env = ieee_get_fp_control();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::~FPEnvironmentImpl()
|
||||
{
|
||||
#if defined(__VMS)
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
struct _ieee mask;
|
||||
mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF;
|
||||
struct _ieee env = _env;
|
||||
sys$ieee_set_fp_control(&mask, &env, 0);
|
||||
#pragma pointer_size restore
|
||||
#else
|
||||
ieee_set_fp_control(_env);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(float value)
|
||||
{
|
||||
int cls = fp_classf(value);
|
||||
return cls == FP_POS_INF || cls == FP_NEG_INF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(double value)
|
||||
{
|
||||
int cls = fp_class(value);
|
||||
return cls == FP_POS_INF || cls == FP_NEG_INF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(long double value)
|
||||
{
|
||||
int cls = fp_classl(value);
|
||||
return cls == FP_POS_INF || cls == FP_NEG_INF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(float value)
|
||||
{
|
||||
return isnanf(value) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(double value)
|
||||
{
|
||||
return isnan(value) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(long double value)
|
||||
{
|
||||
return isnanl(value) != 0;
|
||||
}
|
||||
|
||||
|
||||
float FPEnvironmentImpl::copySignImpl(float target, float source)
|
||||
{
|
||||
return copysignf(target, source);
|
||||
}
|
||||
|
||||
|
||||
double FPEnvironmentImpl::copySignImpl(double target, double source)
|
||||
{
|
||||
return copysign(target, source);
|
||||
}
|
||||
|
||||
|
||||
long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
|
||||
{
|
||||
return copysignl(target, source);
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::keepCurrentImpl()
|
||||
{
|
||||
#if defined(__VMS)
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
struct _ieee env;
|
||||
sys$ieee_set_fp_control(0, 0, &env);
|
||||
#pragma pointer_size restore
|
||||
_env = env;
|
||||
#else
|
||||
ieee_set_fp_control(_env);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::clearFlagsImpl()
|
||||
{
|
||||
#if defined(__VMS)
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
struct _ieee mask;
|
||||
mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF;
|
||||
struct _ieee clr;
|
||||
clr.ieee$q_flags = 0;
|
||||
sys$ieee_set_fp_control(&mask, &clr, 0);
|
||||
#pragma pointer_size restore
|
||||
#else
|
||||
ieee_set_fp_control(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
|
||||
{
|
||||
#if defined(__VMS)
|
||||
#pragma pointer_size save
|
||||
#pragma pointer_size 32
|
||||
struct _ieee flags;
|
||||
sys$ieee_set_fp_control(0, 0, &flags);
|
||||
return (flags.ieee$q_flags & flag) != 0;
|
||||
#pragma pointer_size restore
|
||||
#else
|
||||
return (ieee_get_fp_control() & flag) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
|
||||
{
|
||||
// not supported
|
||||
return FPEnvironmentImpl::RoundingModeImpl(0);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,101 +0,0 @@
|
||||
//
|
||||
// FPEnvironment_C99.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment_DUMMY.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FPEnvironment_DUMMY.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::_roundingMode;
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::~FPEnvironmentImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::keepCurrentImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::clearFlagsImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
|
||||
{
|
||||
_roundingMode = mode;
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
|
||||
{
|
||||
return _roundingMode;
|
||||
}
|
||||
|
||||
|
||||
long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
|
||||
{
|
||||
return (source >= 0 && target >= 0) || (source < 0 && target < 0) ? target : -target;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,163 +0,0 @@
|
||||
//
|
||||
// FPEnvironment_SUN.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment_SUN.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
#ifndef __EXTENSIONS__
|
||||
# define __EXTENSIONS__
|
||||
#endif
|
||||
#include <math.h>
|
||||
#include "Poco/FPEnvironment_SUN.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl()
|
||||
{
|
||||
_rnd = fpgetround();
|
||||
_exc = fpgetmask();
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
|
||||
{
|
||||
_rnd = env._rnd;
|
||||
_exc = env._exc;
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::~FPEnvironmentImpl()
|
||||
{
|
||||
fpsetround(_rnd);
|
||||
fpsetmask(_exc);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
|
||||
{
|
||||
_rnd = env._rnd;
|
||||
_exc = env._exc;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(float value)
|
||||
{
|
||||
int cls = fpclass(value);
|
||||
return cls == FP_PINF || cls == FP_NINF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(double value)
|
||||
{
|
||||
int cls = fpclass(value);
|
||||
return cls == FP_PINF || cls == FP_NINF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isInfiniteImpl(long double value)
|
||||
{
|
||||
int cls = fpclass(value);
|
||||
return cls == FP_PINF || cls == FP_NINF;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(float value)
|
||||
{
|
||||
return isnanf(value) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(double value)
|
||||
{
|
||||
return isnan(value) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isNaNImpl(long double value)
|
||||
{
|
||||
return isnan((double) value) != 0;
|
||||
}
|
||||
|
||||
|
||||
float FPEnvironmentImpl::copySignImpl(float target, float source)
|
||||
{
|
||||
return (float) copysign(target, source);
|
||||
}
|
||||
|
||||
|
||||
double FPEnvironmentImpl::copySignImpl(double target, double source)
|
||||
{
|
||||
return (float) copysign(target, source);
|
||||
}
|
||||
|
||||
|
||||
long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
|
||||
{
|
||||
return (source > 0 && target > 0) || (source < 0 && target < 0) ? target : -target;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::keepCurrentImpl()
|
||||
{
|
||||
fpsetround(_rnd);
|
||||
fpsetmask(_exc);
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::clearFlagsImpl()
|
||||
{
|
||||
fpsetsticky(0);
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
|
||||
{
|
||||
return (fpgetsticky() & flag) != 0;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
|
||||
{
|
||||
fpsetround((fp_rnd) mode);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
|
||||
{
|
||||
return (FPEnvironmentImpl::RoundingModeImpl) fpgetround();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,98 +0,0 @@
|
||||
//
|
||||
// FPEnvironment_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FPEnvironment_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: FPEnvironment
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FPEnvironment_WIN32.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl()
|
||||
{
|
||||
_env = _controlfp(0, 0);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::~FPEnvironmentImpl()
|
||||
{
|
||||
_controlfp(_env, MCW_RC);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
|
||||
{
|
||||
_env = env._env;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::keepCurrentImpl()
|
||||
{
|
||||
_env = _controlfp(0, 0);
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::clearFlagsImpl()
|
||||
{
|
||||
_clearfp();
|
||||
}
|
||||
|
||||
|
||||
bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
|
||||
{
|
||||
return (_statusfp() & flag) != 0;
|
||||
}
|
||||
|
||||
|
||||
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
|
||||
{
|
||||
_controlfp(mode, MCW_RC);
|
||||
}
|
||||
|
||||
|
||||
FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
|
||||
{
|
||||
return RoundingModeImpl(_controlfp(0, 0) & MCW_RC);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,358 +0,0 @@
|
||||
//
|
||||
// File.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/DirectoryIterator.h"
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "File_WINCE.cpp"
|
||||
#else
|
||||
#include "File_WIN32U.cpp"
|
||||
#endif
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "File_WIN32.cpp"
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include "File_VX.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "File_UNIX.cpp"
|
||||
#else
|
||||
#include "File_VMS.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
File::File()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::File(const std::string& path): FileImpl(path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::File(const char* path): FileImpl(std::string(path))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::File(const Path& path): FileImpl(path.toString())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::File(const File& file): FileImpl(file.getPathImpl())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::~File()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File& File::operator = (const File& file)
|
||||
{
|
||||
setPathImpl(file.getPathImpl());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::operator = (const std::string& path)
|
||||
{
|
||||
setPathImpl(path);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::operator = (const char* path)
|
||||
{
|
||||
poco_check_ptr (path);
|
||||
setPathImpl(path);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::operator = (const Path& path)
|
||||
{
|
||||
setPathImpl(path.toString());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void File::swap(File& file)
|
||||
{
|
||||
swapImpl(file);
|
||||
}
|
||||
|
||||
|
||||
bool File::exists() const
|
||||
{
|
||||
return existsImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::canRead() const
|
||||
{
|
||||
return canReadImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::canWrite() const
|
||||
{
|
||||
return canWriteImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::canExecute() const
|
||||
{
|
||||
return canExecuteImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::isFile() const
|
||||
{
|
||||
return isFileImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::isDirectory() const
|
||||
{
|
||||
return isDirectoryImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::isLink() const
|
||||
{
|
||||
return isLinkImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::isDevice() const
|
||||
{
|
||||
return isDeviceImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::isHidden() const
|
||||
{
|
||||
return isHiddenImpl();
|
||||
}
|
||||
|
||||
|
||||
Timestamp File::created() const
|
||||
{
|
||||
return createdImpl();
|
||||
}
|
||||
|
||||
|
||||
Timestamp File::getLastModified() const
|
||||
{
|
||||
return getLastModifiedImpl();
|
||||
}
|
||||
|
||||
|
||||
File& File::setLastModified(const Timestamp& ts)
|
||||
{
|
||||
setLastModifiedImpl(ts);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File::FileSize File::getSize() const
|
||||
{
|
||||
return getSizeImpl();
|
||||
}
|
||||
|
||||
|
||||
File& File::setSize(FileSizeImpl size)
|
||||
{
|
||||
setSizeImpl(size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::setWriteable(bool flag)
|
||||
{
|
||||
setWriteableImpl(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::setReadOnly(bool flag)
|
||||
{
|
||||
setWriteableImpl(!flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
File& File::setExecutable(bool flag)
|
||||
{
|
||||
setExecutableImpl(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void File::copyTo(const std::string& path) const
|
||||
{
|
||||
Path src(getPathImpl());
|
||||
Path dest(path);
|
||||
File destFile(path);
|
||||
if ((destFile.exists() && destFile.isDirectory()) || dest.isDirectory())
|
||||
{
|
||||
dest.makeDirectory();
|
||||
dest.setFileName(src.getFileName());
|
||||
}
|
||||
if (isDirectory())
|
||||
copyDirectory(dest.toString());
|
||||
else
|
||||
copyToImpl(dest.toString());
|
||||
}
|
||||
|
||||
|
||||
void File::copyDirectory(const std::string& path) const
|
||||
{
|
||||
File target(path);
|
||||
target.createDirectories();
|
||||
|
||||
Path src(getPathImpl());
|
||||
src.makeFile();
|
||||
DirectoryIterator it(src);
|
||||
DirectoryIterator end;
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
it->copyTo(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void File::moveTo(const std::string& path)
|
||||
{
|
||||
copyTo(path);
|
||||
remove(true);
|
||||
setPathImpl(path);
|
||||
}
|
||||
|
||||
|
||||
void File::renameTo(const std::string& path)
|
||||
{
|
||||
renameToImpl(path);
|
||||
setPathImpl(path);
|
||||
}
|
||||
|
||||
|
||||
void File::remove(bool recursive)
|
||||
{
|
||||
if (recursive && !isLink() && isDirectory())
|
||||
{
|
||||
std::vector<File> files;
|
||||
list(files);
|
||||
for (std::vector<File>::iterator it = files.begin(); it != files.end(); ++it)
|
||||
{
|
||||
it->remove(true);
|
||||
}
|
||||
}
|
||||
removeImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::createFile()
|
||||
{
|
||||
return createFileImpl();
|
||||
}
|
||||
|
||||
|
||||
bool File::createDirectory()
|
||||
{
|
||||
return createDirectoryImpl();
|
||||
}
|
||||
|
||||
|
||||
void File::createDirectories()
|
||||
{
|
||||
if (!exists())
|
||||
{
|
||||
Path p(getPathImpl());
|
||||
p.makeDirectory();
|
||||
if (p.depth() > 1)
|
||||
{
|
||||
p.makeParent();
|
||||
File f(p);
|
||||
f.createDirectories();
|
||||
}
|
||||
createDirectoryImpl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void File::list(std::vector<std::string>& files) const
|
||||
{
|
||||
files.clear();
|
||||
DirectoryIterator it(*this);
|
||||
DirectoryIterator end;
|
||||
while (it != end)
|
||||
{
|
||||
files.push_back(it.name());
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void File::list(std::vector<File>& files) const
|
||||
{
|
||||
files.clear();
|
||||
DirectoryIterator it(*this);
|
||||
DirectoryIterator end;
|
||||
while (it != end)
|
||||
{
|
||||
files.push_back(*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void File::handleLastError(const std::string& path)
|
||||
{
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,380 +0,0 @@
|
||||
//
|
||||
// FileChannel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FileChannel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: FileChannel
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileChannel.h"
|
||||
#include "Poco/ArchiveStrategy.h"
|
||||
#include "Poco/RotateStrategy.h"
|
||||
#include "Poco/PurgeStrategy.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/LocalDateTime.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Ascii.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const std::string FileChannel::PROP_PATH = "path";
|
||||
const std::string FileChannel::PROP_ROTATION = "rotation";
|
||||
const std::string FileChannel::PROP_ARCHIVE = "archive";
|
||||
const std::string FileChannel::PROP_TIMES = "times";
|
||||
const std::string FileChannel::PROP_COMPRESS = "compress";
|
||||
const std::string FileChannel::PROP_PURGEAGE = "purgeAge";
|
||||
const std::string FileChannel::PROP_PURGECOUNT = "purgeCount";
|
||||
|
||||
|
||||
FileChannel::FileChannel():
|
||||
_times("utc"),
|
||||
_compress(false),
|
||||
_pFile(0),
|
||||
_pRotateStrategy(0),
|
||||
_pArchiveStrategy(new ArchiveByNumberStrategy),
|
||||
_pPurgeStrategy(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileChannel::FileChannel(const std::string& path):
|
||||
_path(path),
|
||||
_times("utc"),
|
||||
_compress(false),
|
||||
_pFile(0),
|
||||
_pRotateStrategy(0),
|
||||
_pArchiveStrategy(new ArchiveByNumberStrategy),
|
||||
_pPurgeStrategy(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileChannel::~FileChannel()
|
||||
{
|
||||
close();
|
||||
delete _pRotateStrategy;
|
||||
delete _pArchiveStrategy;
|
||||
delete _pPurgeStrategy;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::open()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (!_pFile)
|
||||
{
|
||||
_pFile = new LogFile(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::close()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
delete _pFile;
|
||||
_pFile = 0;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::log(const Message& msg)
|
||||
{
|
||||
open();
|
||||
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_pRotateStrategy && _pArchiveStrategy && _pRotateStrategy->mustRotate(_pFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
_pFile = _pArchiveStrategy->archive(_pFile);
|
||||
purge();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
_pFile = new LogFile(_path);
|
||||
}
|
||||
// we must call mustRotate() again to give the
|
||||
// RotateByIntervalStrategy a chance to write its timestamp
|
||||
// to the new file.
|
||||
_pRotateStrategy->mustRotate(_pFile);
|
||||
}
|
||||
_pFile->write(msg.getText());
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (name == PROP_TIMES)
|
||||
{
|
||||
_times = value;
|
||||
|
||||
if (!_rotation.empty())
|
||||
setRotation(_rotation);
|
||||
|
||||
if (!_archive.empty())
|
||||
setArchive(_archive);
|
||||
}
|
||||
else if (name == PROP_PATH)
|
||||
_path = value;
|
||||
else if (name == PROP_ROTATION)
|
||||
setRotation(value);
|
||||
else if (name == PROP_ARCHIVE)
|
||||
setArchive(value);
|
||||
else if (name == PROP_COMPRESS)
|
||||
setCompress(value);
|
||||
else if (name == PROP_PURGEAGE)
|
||||
setPurgeAge(value);
|
||||
else if (name == PROP_PURGECOUNT)
|
||||
setPurgeCount(value);
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
std::string FileChannel::getProperty(const std::string& name) const
|
||||
{
|
||||
if (name == PROP_TIMES)
|
||||
return _times;
|
||||
else if (name == PROP_PATH)
|
||||
return _path;
|
||||
else if (name == PROP_ROTATION)
|
||||
return _rotation;
|
||||
else if (name == PROP_ARCHIVE)
|
||||
return _archive;
|
||||
else if (name == PROP_COMPRESS)
|
||||
return std::string(_compress ? "true" : "false");
|
||||
else if (name == PROP_PURGEAGE)
|
||||
return _purgeAge;
|
||||
else if (name == PROP_PURGECOUNT)
|
||||
return _purgeCount;
|
||||
else
|
||||
return Channel::getProperty(name);
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileChannel::creationDate() const
|
||||
{
|
||||
if (_pFile)
|
||||
return _pFile->creationDate();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
UInt64 FileChannel::size() const
|
||||
{
|
||||
if (_pFile)
|
||||
return _pFile->size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const std::string& FileChannel::path() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setRotation(const std::string& rotation)
|
||||
{
|
||||
std::string::const_iterator it = rotation.begin();
|
||||
std::string::const_iterator end = rotation.end();
|
||||
int n = 0;
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
std::string unit;
|
||||
while (it != end && Ascii::isAlpha(*it)) unit += *it++;
|
||||
|
||||
RotateStrategy* pStrategy = 0;
|
||||
if ((rotation.find(',') != std::string::npos) || (rotation.find(':') != std::string::npos))
|
||||
{
|
||||
if (_times == "utc")
|
||||
pStrategy = new RotateAtTimeStrategy<DateTime>(rotation);
|
||||
else if (_times == "local")
|
||||
pStrategy = new RotateAtTimeStrategy<LocalDateTime>(rotation);
|
||||
else
|
||||
throw PropertyNotSupportedException("times", _times);
|
||||
}
|
||||
else if (unit == "daily")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(1*Timespan::DAYS));
|
||||
else if (unit == "weekly")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(7*Timespan::DAYS));
|
||||
else if (unit == "monthly")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(30*Timespan::DAYS));
|
||||
else if (unit == "seconds") // for testing only
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*Timespan::SECONDS));
|
||||
else if (unit == "minutes")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*Timespan::MINUTES));
|
||||
else if (unit == "hours")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*Timespan::HOURS));
|
||||
else if (unit == "days")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*Timespan::DAYS));
|
||||
else if (unit == "weeks")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*7*Timespan::DAYS));
|
||||
else if (unit == "months")
|
||||
pStrategy = new RotateByIntervalStrategy(Timespan(n*30*Timespan::DAYS));
|
||||
else if (unit == "K")
|
||||
pStrategy = new RotateBySizeStrategy(n*1024);
|
||||
else if (unit == "M")
|
||||
pStrategy = new RotateBySizeStrategy(n*1024*1024);
|
||||
else if (unit.empty())
|
||||
pStrategy = new RotateBySizeStrategy(n);
|
||||
else if (unit != "never")
|
||||
throw InvalidArgumentException("rotation", rotation);
|
||||
delete _pRotateStrategy;
|
||||
_pRotateStrategy = pStrategy;
|
||||
_rotation = rotation;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setArchive(const std::string& archive)
|
||||
{
|
||||
ArchiveStrategy* pStrategy = 0;
|
||||
if (archive == "number")
|
||||
{
|
||||
pStrategy = new ArchiveByNumberStrategy;
|
||||
}
|
||||
else if (archive == "timestamp")
|
||||
{
|
||||
if (_times == "utc")
|
||||
pStrategy = new ArchiveByTimestampStrategy<DateTime>;
|
||||
else if (_times == "local")
|
||||
pStrategy = new ArchiveByTimestampStrategy<LocalDateTime>;
|
||||
else
|
||||
throw PropertyNotSupportedException("times", _times);
|
||||
}
|
||||
else throw InvalidArgumentException("archive", archive);
|
||||
delete _pArchiveStrategy;
|
||||
pStrategy->compress(_compress);
|
||||
_pArchiveStrategy = pStrategy;
|
||||
_archive = archive;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setCompress(const std::string& compress)
|
||||
{
|
||||
_compress = icompare(compress, "true") == 0;
|
||||
if (_pArchiveStrategy)
|
||||
_pArchiveStrategy->compress(_compress);
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setPurgeAge(const std::string& age)
|
||||
{
|
||||
delete _pPurgeStrategy;
|
||||
_pPurgeStrategy = 0;
|
||||
_purgeAge = "none";
|
||||
if (age.empty() || 0 == icompare(age, "none")) return;
|
||||
|
||||
std::string::const_iterator it = age.begin();
|
||||
std::string::const_iterator end = age.end();
|
||||
|
||||
int n = 0;
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
std::string unit;
|
||||
while (it != end && Ascii::isAlpha(*it)) unit += *it++;
|
||||
|
||||
Timespan::TimeDiff factor = Timespan::SECONDS;
|
||||
if (unit == "minutes")
|
||||
factor = Timespan::MINUTES;
|
||||
else if (unit == "hours")
|
||||
factor = Timespan::HOURS;
|
||||
else if (unit == "days")
|
||||
factor = Timespan::DAYS;
|
||||
else if (unit == "weeks")
|
||||
factor = 7*Timespan::DAYS;
|
||||
else if (unit == "months")
|
||||
factor = 30*Timespan::DAYS;
|
||||
else if (unit != "seconds")
|
||||
throw InvalidArgumentException("purgeAge", age);
|
||||
|
||||
if (0 == n)
|
||||
throw InvalidArgumentException("Zero is not valid purge age.");
|
||||
|
||||
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
|
||||
_purgeAge = age;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setPurgeCount(const std::string& count)
|
||||
{
|
||||
delete _pPurgeStrategy;
|
||||
_pPurgeStrategy = 0;
|
||||
_purgeAge = "none";
|
||||
if (count.empty() || 0 == icompare(count, "none")) return;
|
||||
|
||||
int n = 0;
|
||||
std::string::const_iterator it = count.begin();
|
||||
std::string::const_iterator end = count.end();
|
||||
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
|
||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
||||
|
||||
if (0 == n)
|
||||
throw InvalidArgumentException("Zero is not valid purge count.");
|
||||
|
||||
_pPurgeStrategy = new PurgeByCountStrategy(n);
|
||||
_purgeCount = count;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::purge()
|
||||
{
|
||||
if (_pPurgeStrategy)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pPurgeStrategy->purge(_path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,143 +0,0 @@
|
||||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FileStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "FileStream_WIN32.cpp"
|
||||
#else
|
||||
#include "FileStream_POSIX.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileIOS::FileIOS(std::ios::openmode defaultMode):
|
||||
_defaultMode(defaultMode)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
FileIOS::~FileIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
clear();
|
||||
_buf.open(path, mode | _defaultMode);
|
||||
}
|
||||
|
||||
|
||||
void FileIOS::close()
|
||||
{
|
||||
if (!_buf.close())
|
||||
{
|
||||
setstate(ios_base::badbit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf* FileIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream():
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileInputStream::~FileInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream():
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::out),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileOutputStream::~FileOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream():
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStream::FileStream(const std::string& path, std::ios::openmode mode):
|
||||
FileIOS(std::ios::in | std::ios::out),
|
||||
std::iostream(&_buf)
|
||||
{
|
||||
open(path, mode);
|
||||
}
|
||||
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// FileStreamFactory.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FileStreamFactory.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: URI
|
||||
// Module: FileStreamFactory
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStreamFactory.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/FileStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamFactory::FileStreamFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamFactory::~FileStreamFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::istream* FileStreamFactory::open(const URI& uri)
|
||||
{
|
||||
poco_assert (uri.isRelative() || uri.getScheme() == "file");
|
||||
|
||||
std::string uriPath = uri.getPath();
|
||||
if (uriPath.substr(0, 2) == "./")
|
||||
uriPath.erase(0, 2);
|
||||
Path p(uriPath, Path::PATH_UNIX);
|
||||
p.setNode(uri.getHost());
|
||||
return open(p);
|
||||
}
|
||||
|
||||
|
||||
std::istream* FileStreamFactory::open(const Path& path)
|
||||
{
|
||||
File file(path);
|
||||
if (!file.exists()) throw FileNotFoundException(path.toString());
|
||||
|
||||
FileInputStream* istr = new FileInputStream(path.toString(), std::ios::binary);
|
||||
if (!istr->good())
|
||||
{
|
||||
delete istr;
|
||||
throw OpenFileException(path.toString());
|
||||
}
|
||||
return istr;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,192 +0,0 @@
|
||||
//
|
||||
// FileStream_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FileStream_POSIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||
_fd(-1),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_fd == -1);
|
||||
|
||||
_pos = 0;
|
||||
_path = path;
|
||||
setMode(mode);
|
||||
resetBuffers();
|
||||
|
||||
int flags(0);
|
||||
if (mode & std::ios::trunc)
|
||||
flags |= O_TRUNC;
|
||||
if (mode & std::ios::app)
|
||||
flags |= O_APPEND;
|
||||
if (mode & std::ios::out)
|
||||
flags |= O_CREAT;
|
||||
if ((mode & std::ios::in) && (mode & std::ios::out))
|
||||
flags |= O_RDWR;
|
||||
else if (mode & std::ios::in)
|
||||
flags |= O_RDONLY;
|
||||
else
|
||||
flags |= O_WRONLY;
|
||||
|
||||
_fd = ::open(path.c_str(), flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (_fd == -1)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::app) || (mode & std::ios::ate))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
int n = read(_fd, buffer, length);
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_fd == -1) return -1;
|
||||
|
||||
#if defined(POCO_VXWORKS)
|
||||
int n = write(_fd, const_cast<char*>(buffer), length);
|
||||
#else
|
||||
int n = write(_fd, buffer, length);
|
||||
#endif
|
||||
if (n == -1)
|
||||
File::handleLastError(_path);
|
||||
_pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
bool FileStreamBuf::close()
|
||||
{
|
||||
bool success = true;
|
||||
if (_fd != -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
sync();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
::close(_fd);
|
||||
_fd = -1;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
int whence = SEEK_SET;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
whence = SEEK_CUR;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
whence = SEEK_END;
|
||||
}
|
||||
_pos = lseek(_fd, off, whence);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (_fd == -1 || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
_pos = lseek(_fd, pos, SEEK_SET);
|
||||
return _pos;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,230 +0,0 @@
|
||||
//
|
||||
// FileStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FileStream_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: FileStream
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileStreamBuf::FileStreamBuf():
|
||||
BufferedBidirectionalStreamBuf(BUFFER_SIZE, std::ios::in | std::ios::out),
|
||||
_handle(INVALID_HANDLE_VALUE),
|
||||
_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileStreamBuf::~FileStreamBuf()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void FileStreamBuf::open(const std::string& path, std::ios::openmode mode)
|
||||
{
|
||||
poco_assert (_handle == INVALID_HANDLE_VALUE);
|
||||
|
||||
_path = path;
|
||||
_pos = 0;
|
||||
setMode(mode);
|
||||
resetBuffers();
|
||||
|
||||
DWORD access = 0;
|
||||
if (mode & std::ios::in)
|
||||
access |= GENERIC_READ;
|
||||
if (mode & std::ios::out)
|
||||
access |= GENERIC_WRITE;
|
||||
|
||||
DWORD shareMode = FILE_SHARE_READ;
|
||||
if (!(mode & std::ios::out))
|
||||
shareMode |= FILE_SHARE_WRITE;
|
||||
|
||||
DWORD creationDisp = OPEN_EXISTING;
|
||||
if (mode & std::ios::trunc)
|
||||
creationDisp = CREATE_ALWAYS;
|
||||
else if (mode & std::ios::out)
|
||||
creationDisp = OPEN_ALWAYS;
|
||||
|
||||
DWORD flags = FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
#if defined (POCO_WIN32_UTF8)
|
||||
std::wstring utf16Path;
|
||||
UnicodeConverter::toUTF16(path, utf16Path);
|
||||
_handle = CreateFileW(utf16Path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#else
|
||||
_handle = CreateFileA(path.c_str(), access, shareMode, NULL, creationDisp, flags, NULL);
|
||||
#endif
|
||||
|
||||
if (_handle == INVALID_HANDLE_VALUE)
|
||||
File::handleLastError(_path);
|
||||
|
||||
if ((mode & std::ios::ate) || (mode & std::ios::app))
|
||||
seekoff(0, std::ios::end, mode);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::in))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
DWORD bytesRead(0);
|
||||
BOOL rc = ReadFile(_handle, buffer, static_cast<DWORD>(length), &bytesRead, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesRead;
|
||||
|
||||
return static_cast<int>(bytesRead);
|
||||
}
|
||||
|
||||
|
||||
int FileStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & std::ios::out))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::app)
|
||||
{
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = 0;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_END);
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
}
|
||||
|
||||
DWORD bytesWritten(0);
|
||||
BOOL rc = WriteFile(_handle, buffer, static_cast<DWORD>(length), &bytesWritten, NULL);
|
||||
if (rc == 0)
|
||||
File::handleLastError(_path);
|
||||
|
||||
_pos += bytesWritten;
|
||||
|
||||
return static_cast<int>(bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
bool FileStreamBuf::close()
|
||||
{
|
||||
bool success = true;
|
||||
if (_handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
CloseHandle(_handle);
|
||||
_handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
std::streamoff adj;
|
||||
if (mode & std::ios::in)
|
||||
adj = static_cast<std::streamoff>(egptr() - gptr());
|
||||
else
|
||||
adj = 0;
|
||||
|
||||
resetBuffers();
|
||||
|
||||
DWORD offset = FILE_BEGIN;
|
||||
if (dir == std::ios::cur)
|
||||
{
|
||||
offset = FILE_CURRENT;
|
||||
off -= adj;
|
||||
}
|
||||
else if (dir == std::ios::end)
|
||||
{
|
||||
offset = FILE_END;
|
||||
}
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = off;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, offset);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
std::streampos FileStreamBuf::seekpos(std::streampos pos, std::ios::openmode mode)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _handle || !(getMode() & mode))
|
||||
return -1;
|
||||
|
||||
if (getMode() & std::ios::out)
|
||||
sync();
|
||||
|
||||
resetBuffers();
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = pos;
|
||||
li.LowPart = SetFilePointer(_handle, li.LowPart, &li.HighPart, FILE_BEGIN);
|
||||
|
||||
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
File::handleLastError(_path);
|
||||
_pos = li.QuadPart;
|
||||
return std::streampos(static_cast<std::streamoff>(_pos));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,474 +0,0 @@
|
||||
//
|
||||
// File_UNIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_UNIX.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_UNIX.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <utime.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && _path[n - 1] == '/')
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && _path[n - 1] == '/')
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
return stat(_path.c_str(), &st) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
{
|
||||
if (geteuid() == 0)
|
||||
return true;
|
||||
else if (st.st_uid == geteuid())
|
||||
return (st.st_mode & S_IRUSR) != 0;
|
||||
else if (st.st_gid == getegid())
|
||||
return (st.st_mode & S_IRGRP) != 0;
|
||||
else
|
||||
return (st.st_mode & S_IROTH) != 0;
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
{
|
||||
if (geteuid() == 0)
|
||||
return true;
|
||||
else if (st.st_uid == geteuid())
|
||||
return (st.st_mode & S_IWUSR) != 0;
|
||||
else if (st.st_gid == getegid())
|
||||
return (st.st_mode & S_IWGRP) != 0;
|
||||
else
|
||||
return (st.st_mode & S_IWOTH) != 0;
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
{
|
||||
if (st.st_uid == geteuid() || geteuid() == 0)
|
||||
return (st.st_mode & S_IXUSR) != 0;
|
||||
else if (st.st_gid == getegid())
|
||||
return (st.st_mode & S_IXGRP) != 0;
|
||||
else
|
||||
return (st.st_mode & S_IXOTH) != 0;
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return S_ISREG(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return S_ISDIR(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (lstat(_path.c_str(), &st) == 0)
|
||||
return S_ISLNK(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDeviceImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
Path p(_path);
|
||||
p.makeFile();
|
||||
|
||||
return p.getFileName()[0] == '.';
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
#if defined(__APPLE__) && defined(st_birthtime) && !defined(POCO_NO_STAT64) // st_birthtime is available only on 10.5
|
||||
struct stat64 st;
|
||||
if (stat64(_path.c_str(), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_birthtime);
|
||||
#elif defined(__FreeBSD__)
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_birthtime);
|
||||
#else
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_ctime);
|
||||
#endif
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_mtime);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct utimbuf tb;
|
||||
tb.actime = ts.epochTime();
|
||||
tb.modtime = ts.epochTime();
|
||||
if (utime(_path.c_str(), &tb) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return st.st_size;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (truncate(_path.c_str(), size) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
mode_t mode;
|
||||
if (flag)
|
||||
{
|
||||
mode = st.st_mode | S_IWUSR;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode_t wmask = S_IWUSR | S_IWGRP | S_IWOTH;
|
||||
mode = st.st_mode & ~wmask;
|
||||
}
|
||||
if (chmod(_path.c_str(), mode) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
mode_t mode;
|
||||
if (flag)
|
||||
{
|
||||
mode = st.st_mode | S_IXUSR;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode_t wmask = S_IXUSR | S_IXGRP | S_IXOTH;
|
||||
mode = st.st_mode & ~wmask;
|
||||
}
|
||||
if (chmod(_path.c_str(), mode) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int sd = open(_path.c_str(), O_RDONLY);
|
||||
if (sd == -1) handleLastErrorImpl(_path);
|
||||
|
||||
struct stat st;
|
||||
if (fstat(sd, &st) != 0)
|
||||
{
|
||||
close(sd);
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
const long blockSize = st.st_blksize;
|
||||
|
||||
int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU);
|
||||
if (dd == -1)
|
||||
{
|
||||
close(sd);
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
Buffer<char> buffer(blockSize);
|
||||
try
|
||||
{
|
||||
int n;
|
||||
while ((n = read(sd, buffer.begin(), blockSize)) > 0)
|
||||
{
|
||||
if (write(dd, buffer.begin(), n) != n)
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
if (n < 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close(sd);
|
||||
close(dd);
|
||||
throw;
|
||||
}
|
||||
close(sd);
|
||||
if (fsync(dd) != 0)
|
||||
{
|
||||
close(dd);
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
if (close(dd) != 0)
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (rename(_path.c_str(), path.c_str()) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int rc;
|
||||
if (!isLinkImpl() && isDirectoryImpl())
|
||||
rc = rmdir(_path.c_str());
|
||||
else
|
||||
rc = unlink(_path.c_str());
|
||||
if (rc) handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (n != -1)
|
||||
{
|
||||
close(n);
|
||||
return true;
|
||||
}
|
||||
if (n == -1 && errno == EEXIST)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (mkdir(_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case EIO:
|
||||
throw IOException(path);
|
||||
case EPERM:
|
||||
throw FileAccessDeniedException("insufficient permissions", path);
|
||||
case EACCES:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ENOENT:
|
||||
throw FileNotFoundException(path);
|
||||
case ENOTDIR:
|
||||
throw OpenFileException("not a directory", path);
|
||||
case EISDIR:
|
||||
throw OpenFileException("not a file", path);
|
||||
case EROFS:
|
||||
throw FileReadOnlyException(path);
|
||||
case EEXIST:
|
||||
throw FileExistsException(path);
|
||||
case ENOSPC:
|
||||
throw FileException("no space left on device", path);
|
||||
case EDQUOT:
|
||||
throw FileException("disk quota exceeded", path);
|
||||
#if !defined(_AIX)
|
||||
case ENOTEMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
#endif
|
||||
case ENAMETOOLONG:
|
||||
throw PathSyntaxException(path);
|
||||
case ENFILE:
|
||||
case EMFILE:
|
||||
throw FileException("too many open files", path);
|
||||
default:
|
||||
throw FileException(std::strerror(errno), path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,407 +0,0 @@
|
||||
//
|
||||
// File_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_VMS.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_VMS.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/String.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <unixio.h>
|
||||
#include <file.h>
|
||||
#include <stat.h>
|
||||
#include <errno.h>
|
||||
#include <utime.h>
|
||||
#include <lib$routines.h>
|
||||
#include <rmsdef.h>
|
||||
#include <starlet.h>
|
||||
#include <lnmdef.h>
|
||||
#include <ssdef.h>
|
||||
#include <descrip.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
if (!_path.empty())
|
||||
{
|
||||
Path p(_path);
|
||||
p.makeFile();
|
||||
_path = p.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
return access(_path.c_str(), F_OK) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
{
|
||||
if (st.st_uid == geteuid())
|
||||
return (st.st_mode & S_IRUSR) != 0;
|
||||
else if (st.st_gid == getegid())
|
||||
return (st.st_mode & S_IRGRP) != 0;
|
||||
else
|
||||
return (st.st_mode & S_IROTH) != 0;
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
{
|
||||
if (st.st_uid == geteuid())
|
||||
return (st.st_mode & S_IWUSR) != 0;
|
||||
else if (st.st_gid == getegid())
|
||||
return (st.st_mode & S_IWGRP) != 0;
|
||||
else
|
||||
return (st.st_mode & S_IWOTH) != 0;
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
Path p(_path);
|
||||
return icompare(p.getExtension(), "exe") == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return S_ISREG(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return S_ISDIR(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return Timestamp(st.st_ctime);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return Timestamp(st.st_mtime);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct utimbuf tb;
|
||||
tb.actime = ts.epochTime();
|
||||
tb.modtime = ts.epochTime();
|
||||
if (utime(_path.c_str(), &tb) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) == 0)
|
||||
return st.st_size;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (truncate(_path.c_str(), size) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(_path.c_str(), &st) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
mode_t mode;
|
||||
if (flag)
|
||||
{
|
||||
mode = st.st_mode | S_IWUSR;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode_t wmask = S_IWUSR | S_IWGRP | S_IWOTH;
|
||||
mode = st.st_mode & ~wmask;
|
||||
}
|
||||
if (chmod(_path.c_str(), mode) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
// copying a file correctly under OpenVMS is non-trivial,
|
||||
// so we just invoke the COPY program.
|
||||
std::string cmd = "COPY ";
|
||||
cmd.append(_path);
|
||||
cmd.append(" ");
|
||||
cmd.append(path);
|
||||
if (system(cmd.c_str()) != 0)
|
||||
throw FileException("COPY command failed", _path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
POCO_DESCRIPTOR_STRING(oldNameDsc, _path);
|
||||
POCO_DESCRIPTOR_STRING(newNameDsc, path);
|
||||
|
||||
int res;
|
||||
if ((res = lib$rename_file(&oldNameDsc, &newNameDsc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) != 1)
|
||||
{
|
||||
switch (res & 0x0FFFFFFF)
|
||||
{
|
||||
case RMS$_FNF:
|
||||
throw FileNotFoundException(_path);
|
||||
case RMS$_DEV:
|
||||
case RMS$_DNF:
|
||||
throw PathNotFoundException(_path);
|
||||
case RMS$_SYN:
|
||||
throw PathSyntaxException(path);
|
||||
case RMS$_RMV:
|
||||
throw FileAccessDeniedException(_path);
|
||||
case RMS$_PRV:
|
||||
throw FileAccessDeniedException("insufficient privileges", _path);
|
||||
default:
|
||||
throw FileException(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int rc;
|
||||
if (isDirectoryImpl())
|
||||
{
|
||||
setWriteableImpl(true);
|
||||
rc = rmdir(_path.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = unlink(_path.c_str());
|
||||
}
|
||||
if (rc) handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL);
|
||||
if (n != -1)
|
||||
{
|
||||
close(n);
|
||||
return true;
|
||||
}
|
||||
if (n == -1 && errno == EEXIST)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
Path p(_path);
|
||||
p.makeDirectory();
|
||||
if (mkdir(p.toString().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case EIO:
|
||||
throw IOException(path);
|
||||
case EPERM:
|
||||
throw FileAccessDeniedException("insufficient permissions", path);
|
||||
case EACCES:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ENOENT:
|
||||
throw FileNotFoundException(path);
|
||||
case ENOTDIR:
|
||||
throw OpenFileException("not a directory", path);
|
||||
case EISDIR:
|
||||
throw OpenFileException("not a file", path);
|
||||
case EROFS:
|
||||
throw FileReadOnlyException(path);
|
||||
case EEXIST:
|
||||
throw FileExistsException(path);
|
||||
case ENOSPC:
|
||||
throw FileException("no space left on device", path);
|
||||
case EDQUOT:
|
||||
throw FileException("disk quota exceeded", path);
|
||||
case ENOTEMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
case ENAMETOOLONG:
|
||||
throw PathSyntaxException(path);
|
||||
default:
|
||||
throw FileException(strerror(errno), path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,388 +0,0 @@
|
||||
//
|
||||
// File_VX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_VX.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_VX.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <utime.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && _path[n - 1] == '/')
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && _path[n - 1] == '/')
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
return stat(const_cast<char*>(_path.c_str()), &st) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return S_ISREG(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return S_ISDIR(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDeviceImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
Path p(_path);
|
||||
p.makeFile();
|
||||
|
||||
return p.getFileName()[0] == '.';
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_ctime);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return Timestamp::fromEpochTime(st.st_mtime);
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct utimbuf tb;
|
||||
tb.actime = ts.epochTime();
|
||||
tb.modtime = ts.epochTime();
|
||||
if (utime(const_cast<char*>(_path.c_str()), &tb) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
struct stat st;
|
||||
if (stat(const_cast<char*>(_path.c_str()), &st) == 0)
|
||||
return st.st_size;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int fd = open(_path.c_str(), O_WRONLY, S_IRWXU);
|
||||
if (fd != -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ftruncate(fd, size) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close(fd);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int sd = open(_path.c_str(), O_RDONLY, 0);
|
||||
if (sd == -1) handleLastErrorImpl(_path);
|
||||
|
||||
struct stat st;
|
||||
if (fstat(sd, &st) != 0)
|
||||
{
|
||||
close(sd);
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
const long blockSize = st.st_blksize;
|
||||
|
||||
int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU);
|
||||
if (dd == -1)
|
||||
{
|
||||
close(sd);
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
Buffer<char> buffer(blockSize);
|
||||
try
|
||||
{
|
||||
int n;
|
||||
while ((n = read(sd, buffer.begin(), blockSize)) > 0)
|
||||
{
|
||||
if (write(dd, buffer.begin(), n) != n)
|
||||
handleLastErrorImpl(path);
|
||||
}
|
||||
if (n < 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close(sd);
|
||||
close(dd);
|
||||
throw;
|
||||
}
|
||||
close(sd);
|
||||
close(dd);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (rename(_path.c_str(), path.c_str()) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int rc;
|
||||
if (!isLinkImpl() && isDirectoryImpl())
|
||||
rc = rmdir(_path.c_str());
|
||||
else
|
||||
rc = unlink(const_cast<char*>(_path.c_str()));
|
||||
if (rc) handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (n != -1)
|
||||
{
|
||||
close(n);
|
||||
return true;
|
||||
}
|
||||
if (n == -1 && errno == EEXIST)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (mkdir(_path.c_str()) != 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case EIO:
|
||||
throw IOException(path);
|
||||
case EPERM:
|
||||
throw FileAccessDeniedException("insufficient permissions", path);
|
||||
case EACCES:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ENOENT:
|
||||
throw FileNotFoundException(path);
|
||||
case ENOTDIR:
|
||||
throw OpenFileException("not a directory", path);
|
||||
case EISDIR:
|
||||
throw OpenFileException("not a file", path);
|
||||
case EROFS:
|
||||
throw FileReadOnlyException(path);
|
||||
case EEXIST:
|
||||
throw FileExistsException(path);
|
||||
case ENOSPC:
|
||||
throw FileException("no space left on device", path);
|
||||
case ENOTEMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
case ENAMETOOLONG:
|
||||
throw PathSyntaxException(path);
|
||||
case ENFILE:
|
||||
case EMFILE:
|
||||
throw FileException("too many open files", path);
|
||||
default:
|
||||
throw FileException(std::strerror(errno), path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,422 +0,0 @@
|
||||
//
|
||||
// File_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_WIN32.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class FileHandle
|
||||
{
|
||||
public:
|
||||
FileHandle(const std::string& path, DWORD access, DWORD share, DWORD disp)
|
||||
{
|
||||
_h = CreateFileA(path.c_str(), access, share, 0, disp, 0, 0);
|
||||
if (_h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileImpl::handleLastErrorImpl(path);
|
||||
}
|
||||
}
|
||||
|
||||
~FileHandle()
|
||||
{
|
||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||
}
|
||||
|
||||
HANDLE get() const
|
||||
{
|
||||
return _h;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE _h;
|
||||
};
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_NOT_READY:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
Path p(_path);
|
||||
return icompare(p.getExtension(), "exe") == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
return !isDirectoryImpl() && !isDeviceImpl();
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDeviceImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
FileHandle fh(_path, GENERIC_READ, 0, OPEN_EXISTING);
|
||||
DWORD type = GetFileType(fh.get());
|
||||
if (type == FILE_TYPE_CHAR)
|
||||
return true;
|
||||
else if (type == FILE_TYPE_UNKNOWN && GetLastError() != NO_ERROR)
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
UInt32 low;
|
||||
UInt32 high;
|
||||
ts.toFileTimeNP(low, high);
|
||||
FILETIME ft;
|
||||
ft.dwLowDateTime = low;
|
||||
ft.dwHighDateTime = high;
|
||||
FileHandle fh(_path, FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
if (SetFileTime(fh.get(), 0, &ft, &ft) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesEx(_path.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
LARGE_INTEGER li;
|
||||
li.LowPart = fad.nFileSizeLow;
|
||||
li.HighPart = fad.nFileSizeHigh;
|
||||
return li.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
FileHandle fh(_path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = size;
|
||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (SetEndOfFile(fh.get()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributes(_path.c_str());
|
||||
if (attr == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (flag)
|
||||
attr &= ~FILE_ATTRIBUTE_READONLY;
|
||||
else
|
||||
attr |= FILE_ATTRIBUTE_READONLY;
|
||||
if (SetFileAttributes(_path.c_str(), attr) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (CopyFileA(_path.c_str(), path.c_str(), FALSE) != 0)
|
||||
{
|
||||
FileImpl copy(path);
|
||||
copy.setWriteableImpl(true);
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (MoveFileA(_path.c_str(), path.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (isDirectoryImpl())
|
||||
{
|
||||
if (RemoveDirectoryA(_path.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DeleteFileA(_path.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
HANDLE hFile = CreateFileA(_path.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
return true;
|
||||
}
|
||||
else if (GetLastError() == ERROR_FILE_EXISTS)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (CreateDirectoryA(_path.c_str(), 0) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
throw FileNotFoundException(path);
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_BAD_NETPATH:
|
||||
case ERROR_CANT_RESOLVE_FILENAME:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
throw PathNotFoundException(path);
|
||||
case ERROR_ACCESS_DENIED:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
case ERROR_FILE_EXISTS:
|
||||
throw FileExistsException(path);
|
||||
case ERROR_INVALID_NAME:
|
||||
case ERROR_DIRECTORY:
|
||||
case ERROR_FILENAME_EXCED_RANGE:
|
||||
case ERROR_BAD_PATHNAME:
|
||||
throw PathSyntaxException(path);
|
||||
case ERROR_FILE_READ_ONLY:
|
||||
throw FileReadOnlyException(path);
|
||||
case ERROR_CANNOT_MAKE:
|
||||
throw CreateFileException(path);
|
||||
case ERROR_DIR_NOT_EMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
case ERROR_WRITE_FAULT:
|
||||
throw WriteFileException(path);
|
||||
case ERROR_READ_FAULT:
|
||||
throw ReadFileException(path);
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
throw FileException("sharing violation", path);
|
||||
case ERROR_LOCK_VIOLATION:
|
||||
throw FileException("lock violation", path);
|
||||
case ERROR_HANDLE_EOF:
|
||||
throw ReadFileException("EOF reached", path);
|
||||
case ERROR_HANDLE_DISK_FULL:
|
||||
case ERROR_DISK_FULL:
|
||||
throw WriteFileException("disk is full", path);
|
||||
case ERROR_NEGATIVE_SEEK:
|
||||
throw FileException("negative seek", path);
|
||||
default:
|
||||
throw FileException(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,430 +0,0 @@
|
||||
//
|
||||
// File_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_WIN32U.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_WIN32U.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class FileHandle
|
||||
{
|
||||
public:
|
||||
FileHandle(const std::string& path, const std::wstring& upath, DWORD access, DWORD share, DWORD disp)
|
||||
{
|
||||
_h = CreateFileW(upath.c_str(), access, share, 0, disp, 0, 0);
|
||||
if (_h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileImpl::handleLastErrorImpl(path);
|
||||
}
|
||||
}
|
||||
|
||||
~FileHandle()
|
||||
{
|
||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||
}
|
||||
|
||||
HANDLE get() const
|
||||
{
|
||||
return _h;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE _h;
|
||||
};
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
UnicodeConverter::toUTF16(_path, _upath);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
std::swap(_upath, file._upath);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
UnicodeConverter::toUTF16(_path, _upath);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_NOT_READY:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
Path p(_path);
|
||||
return icompare(p.getExtension(), "exe") == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
return !isDirectoryImpl() && !isDeviceImpl();
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDeviceImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
FileHandle fh(_path, _upath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
DWORD type = GetFileType(fh.get());
|
||||
if (type == FILE_TYPE_CHAR)
|
||||
return true;
|
||||
else if (type == FILE_TYPE_UNKNOWN && GetLastError() != NO_ERROR)
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
UInt32 low;
|
||||
UInt32 high;
|
||||
ts.toFileTimeNP(low, high);
|
||||
FILETIME ft;
|
||||
ft.dwLowDateTime = low;
|
||||
ft.dwHighDateTime = high;
|
||||
FileHandle fh(_path, _upath, FILE_ALL_ACCESS, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
if (SetFileTime(fh.get(), 0, &ft, &ft) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
LARGE_INTEGER li;
|
||||
li.LowPart = fad.nFileSizeLow;
|
||||
li.HighPart = fad.nFileSizeHigh;
|
||||
return li.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
FileHandle fh(_path, _upath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = size;
|
||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (SetEndOfFile(fh.get()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (flag)
|
||||
attr &= ~FILE_ATTRIBUTE_READONLY;
|
||||
else
|
||||
attr |= FILE_ATTRIBUTE_READONLY;
|
||||
if (SetFileAttributesW(_upath.c_str(), attr) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
|
||||
{
|
||||
FileImpl copy(path);
|
||||
copy.setWriteableImpl(true);
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (isDirectoryImpl())
|
||||
{
|
||||
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DeleteFileW(_upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
return true;
|
||||
}
|
||||
else if (GetLastError() == ERROR_FILE_EXISTS)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
throw FileNotFoundException(path);
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_BAD_NETPATH:
|
||||
case ERROR_CANT_RESOLVE_FILENAME:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
throw PathNotFoundException(path);
|
||||
case ERROR_ACCESS_DENIED:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
case ERROR_FILE_EXISTS:
|
||||
throw FileExistsException(path);
|
||||
case ERROR_INVALID_NAME:
|
||||
case ERROR_DIRECTORY:
|
||||
case ERROR_FILENAME_EXCED_RANGE:
|
||||
case ERROR_BAD_PATHNAME:
|
||||
throw PathSyntaxException(path);
|
||||
case ERROR_FILE_READ_ONLY:
|
||||
throw FileReadOnlyException(path);
|
||||
case ERROR_CANNOT_MAKE:
|
||||
throw CreateFileException(path);
|
||||
case ERROR_DIR_NOT_EMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
case ERROR_WRITE_FAULT:
|
||||
throw WriteFileException(path);
|
||||
case ERROR_READ_FAULT:
|
||||
throw ReadFileException(path);
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
throw FileException("sharing violation", path);
|
||||
case ERROR_LOCK_VIOLATION:
|
||||
throw FileException("lock violation", path);
|
||||
case ERROR_HANDLE_EOF:
|
||||
throw ReadFileException("EOF reached", path);
|
||||
case ERROR_HANDLE_DISK_FULL:
|
||||
case ERROR_DISK_FULL:
|
||||
throw WriteFileException("disk is full", path);
|
||||
case ERROR_NEGATIVE_SEEK:
|
||||
throw FileException("negative seek", path);
|
||||
default:
|
||||
throw FileException(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,423 +0,0 @@
|
||||
//
|
||||
// File_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/File_WINCE.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: File
|
||||
//
|
||||
// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/File_WINCE.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class FileHandle
|
||||
{
|
||||
public:
|
||||
FileHandle(const std::string& path, const std::wstring& upath, DWORD access, DWORD share, DWORD disp)
|
||||
{
|
||||
_h = CreateFileW(upath.c_str(), access, share, 0, disp, 0, 0);
|
||||
if (_h == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
FileImpl::handleLastErrorImpl(path);
|
||||
}
|
||||
}
|
||||
|
||||
~FileHandle()
|
||||
{
|
||||
if (_h != INVALID_HANDLE_VALUE) CloseHandle(_h);
|
||||
}
|
||||
|
||||
HANDLE get() const
|
||||
{
|
||||
return _h;
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE _h;
|
||||
};
|
||||
|
||||
|
||||
FileImpl::FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
UnicodeConverter::toUTF16(_path, _upath);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::~FileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::swapImpl(FileImpl& file)
|
||||
{
|
||||
std::swap(_path, file._path);
|
||||
std::swap(_upath, file._upath);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setPathImpl(const std::string& path)
|
||||
{
|
||||
_path = path;
|
||||
std::string::size_type n = _path.size();
|
||||
if (n > 1 && (_path[n - 1] == '\\' || _path[n - 1] == '/') && !((n == 3 && _path[1]==':')))
|
||||
{
|
||||
_path.resize(n - 1);
|
||||
}
|
||||
UnicodeConverter::toUTF16(_path, _upath);
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::existsImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_NOT_READY:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canReadImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_ACCESS_DENIED:
|
||||
return false;
|
||||
default:
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canWriteImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::canExecuteImpl() const
|
||||
{
|
||||
Path p(_path);
|
||||
return icompare(p.getExtension(), "exe") == 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isFileImpl() const
|
||||
{
|
||||
return !isDirectoryImpl() && !isDeviceImpl();
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDirectoryImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isLinkImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isDeviceImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == 0xFFFFFFFF)
|
||||
handleLastErrorImpl(_path);
|
||||
return (attr & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftCreationTime.dwLowDateTime, fad.ftCreationTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::getLastModifiedImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setLastModifiedImpl(const Timestamp& ts)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
UInt32 low;
|
||||
UInt32 high;
|
||||
ts.toFileTimeNP(low, high);
|
||||
FILETIME ft;
|
||||
ft.dwLowDateTime = low;
|
||||
ft.dwHighDateTime = high;
|
||||
FileHandle fh(_path, _upath, GENERIC_WRITE, FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
if (SetFileTime(fh.get(), 0, &ft, &ft) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA fad;
|
||||
if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
LARGE_INTEGER li;
|
||||
li.LowPart = fad.nFileSizeLow;
|
||||
li.HighPart = fad.nFileSizeHigh;
|
||||
return li.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setSizeImpl(FileSizeImpl size)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
FileHandle fh(_path, _upath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING);
|
||||
LARGE_INTEGER li;
|
||||
li.QuadPart = size;
|
||||
if (SetFilePointer(fh.get(), li.LowPart, &li.HighPart, FILE_BEGIN) == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (SetEndOfFile(fh.get()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setWriteableImpl(bool flag)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
DWORD attr = GetFileAttributesW(_upath.c_str());
|
||||
if (attr == -1)
|
||||
handleLastErrorImpl(_path);
|
||||
if (flag)
|
||||
attr &= ~FILE_ATTRIBUTE_READONLY;
|
||||
else
|
||||
attr |= FILE_ATTRIBUTE_READONLY;
|
||||
if (SetFileAttributesW(_upath.c_str(), attr) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::setExecutableImpl(bool flag)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) != 0)
|
||||
{
|
||||
FileImpl copy(path);
|
||||
copy.setWriteableImpl(true);
|
||||
}
|
||||
else handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::removeImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (isDirectoryImpl())
|
||||
{
|
||||
if (RemoveDirectoryW(_upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DeleteFileW(_upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createFileImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);
|
||||
if (hFile != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
CloseHandle(hFile);
|
||||
return true;
|
||||
}
|
||||
else if (GetLastError() == ERROR_FILE_EXISTS)
|
||||
return false;
|
||||
else
|
||||
handleLastErrorImpl(_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::createDirectoryImpl()
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (existsImpl() && isDirectoryImpl())
|
||||
return false;
|
||||
if (CreateDirectoryW(_upath.c_str(), 0) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::handleLastErrorImpl(const std::string& path)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
throw FileNotFoundException(path);
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
case ERROR_BAD_NETPATH:
|
||||
case ERROR_CANT_RESOLVE_FILENAME:
|
||||
case ERROR_INVALID_DRIVE:
|
||||
throw PathNotFoundException(path);
|
||||
case ERROR_ACCESS_DENIED:
|
||||
throw FileAccessDeniedException(path);
|
||||
case ERROR_ALREADY_EXISTS:
|
||||
case ERROR_FILE_EXISTS:
|
||||
throw FileExistsException(path);
|
||||
case ERROR_INVALID_NAME:
|
||||
case ERROR_DIRECTORY:
|
||||
case ERROR_FILENAME_EXCED_RANGE:
|
||||
case ERROR_BAD_PATHNAME:
|
||||
throw PathSyntaxException(path);
|
||||
case ERROR_FILE_READ_ONLY:
|
||||
throw FileReadOnlyException(path);
|
||||
case ERROR_CANNOT_MAKE:
|
||||
throw CreateFileException(path);
|
||||
case ERROR_DIR_NOT_EMPTY:
|
||||
throw FileException("directory not empty", path);
|
||||
case ERROR_WRITE_FAULT:
|
||||
throw WriteFileException(path);
|
||||
case ERROR_READ_FAULT:
|
||||
throw ReadFileException(path);
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
throw FileException("sharing violation", path);
|
||||
case ERROR_LOCK_VIOLATION:
|
||||
throw FileException("lock violation", path);
|
||||
case ERROR_HANDLE_EOF:
|
||||
throw ReadFileException("EOF reached", path);
|
||||
case ERROR_HANDLE_DISK_FULL:
|
||||
case ERROR_DISK_FULL:
|
||||
throw WriteFileException("disk is full", path);
|
||||
case ERROR_NEGATIVE_SEEK:
|
||||
throw FileException("negative seek", path);
|
||||
default:
|
||||
throw FileException(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,404 +0,0 @@
|
||||
//
|
||||
// Format.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Format.cpp#5 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: Format
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Ascii.h"
|
||||
#include <sstream>
|
||||
#if !defined(POCO_NO_LOCALE)
|
||||
#include <locale>
|
||||
#endif
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void parseFlags(std::ostream& str, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt)
|
||||
{
|
||||
bool isFlag = true;
|
||||
while (isFlag && itFmt != endFmt)
|
||||
{
|
||||
switch (*itFmt)
|
||||
{
|
||||
case '-': str.setf(std::ios::left); ++itFmt; break;
|
||||
case '+': str.setf(std::ios::showpos); ++itFmt; break;
|
||||
case '0': str.fill('0'); ++itFmt; break;
|
||||
case '#': str.setf(std::ios::showpoint | std::ios_base::showbase); ++itFmt; break;
|
||||
default: isFlag = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void parseWidth(std::ostream& str, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt)
|
||||
{
|
||||
int width = 0;
|
||||
while (itFmt != endFmt && Ascii::isDigit(*itFmt))
|
||||
{
|
||||
width = 10*width + *itFmt - '0';
|
||||
++itFmt;
|
||||
}
|
||||
if (width != 0) str.width(width);
|
||||
}
|
||||
|
||||
|
||||
void parsePrec(std::ostream& str, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt)
|
||||
{
|
||||
if (itFmt != endFmt && *itFmt == '.')
|
||||
{
|
||||
++itFmt;
|
||||
int prec = 0;
|
||||
while (itFmt != endFmt && Ascii::isDigit(*itFmt))
|
||||
{
|
||||
prec = 10*prec + *itFmt - '0';
|
||||
++itFmt;
|
||||
}
|
||||
if (prec >= 0) str.precision(prec);
|
||||
}
|
||||
}
|
||||
|
||||
char parseMod(std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt)
|
||||
{
|
||||
char mod = 0;
|
||||
if (itFmt != endFmt)
|
||||
{
|
||||
switch (*itFmt)
|
||||
{
|
||||
case 'l':
|
||||
case 'h':
|
||||
case 'L':
|
||||
case '?': mod = *itFmt++; break;
|
||||
}
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
|
||||
std::size_t parseIndex(std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt)
|
||||
{
|
||||
int index = 0;
|
||||
while (itFmt != endFmt && Ascii::isDigit(*itFmt))
|
||||
{
|
||||
index = 10*index + *itFmt - '0';
|
||||
++itFmt;
|
||||
}
|
||||
if (itFmt != endFmt && *itFmt == ']') ++itFmt;
|
||||
return index;
|
||||
}
|
||||
|
||||
void prepareFormat(std::ostream& str, char type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 'd':
|
||||
case 'i': str << std::dec; break;
|
||||
case 'o': str << std::oct; break;
|
||||
case 'x': str << std::hex; break;
|
||||
case 'X': str << std::hex << std::uppercase; break;
|
||||
case 'e': str << std::scientific; break;
|
||||
case 'E': str << std::scientific << std::uppercase; break;
|
||||
case 'f': str << std::fixed; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeAnyInt(std::ostream& str, const Any& any)
|
||||
{
|
||||
if (any.type() == typeid(char))
|
||||
str << static_cast<int>(AnyCast<char>(any));
|
||||
else if (any.type() == typeid(signed char))
|
||||
str << static_cast<int>(AnyCast<signed char>(any));
|
||||
else if (any.type() == typeid(unsigned char))
|
||||
str << static_cast<unsigned>(AnyCast<unsigned char>(any));
|
||||
else if (any.type() == typeid(short))
|
||||
str << AnyCast<short>(any);
|
||||
else if (any.type() == typeid(unsigned short))
|
||||
str << AnyCast<unsigned short>(any);
|
||||
else if (any.type() == typeid(int))
|
||||
str << AnyCast<int>(any);
|
||||
else if (any.type() == typeid(unsigned int))
|
||||
str << AnyCast<unsigned int>(any);
|
||||
else if (any.type() == typeid(long))
|
||||
str << AnyCast<long>(any);
|
||||
else if (any.type() == typeid(unsigned long))
|
||||
str << AnyCast<unsigned long>(any);
|
||||
else if (any.type() == typeid(Int64))
|
||||
str << AnyCast<Int64>(any);
|
||||
else if (any.type() == typeid(UInt64))
|
||||
str << AnyCast<UInt64>(any);
|
||||
else if (any.type() == typeid(bool))
|
||||
str << AnyCast<bool>(any);
|
||||
}
|
||||
|
||||
|
||||
void formatOne(std::string& result, std::string::const_iterator& itFmt, const std::string::const_iterator& endFmt, std::vector<Any>::const_iterator& itVal)
|
||||
{
|
||||
std::ostringstream str;
|
||||
#if !defined(POCO_NO_LOCALE)
|
||||
str.imbue(std::locale::classic());
|
||||
#endif
|
||||
try
|
||||
{
|
||||
parseFlags(str, itFmt, endFmt);
|
||||
parseWidth(str, itFmt, endFmt);
|
||||
parsePrec(str, itFmt, endFmt);
|
||||
char mod = parseMod(itFmt, endFmt);
|
||||
if (itFmt != endFmt)
|
||||
{
|
||||
char type = *itFmt++;
|
||||
prepareFormat(str, type);
|
||||
switch (type)
|
||||
{
|
||||
case 'b':
|
||||
str << AnyCast<bool>(*itVal++);
|
||||
break;
|
||||
case 'c':
|
||||
str << AnyCast<char>(*itVal++);
|
||||
break;
|
||||
case 'd':
|
||||
case 'i':
|
||||
switch (mod)
|
||||
{
|
||||
case 'l': str << AnyCast<long>(*itVal++); break;
|
||||
case 'L': str << AnyCast<Int64>(*itVal++); break;
|
||||
case 'h': str << AnyCast<short>(*itVal++); break;
|
||||
case '?': writeAnyInt(str, *itVal++); break;
|
||||
default: str << AnyCast<int>(*itVal++); break;
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
switch (mod)
|
||||
{
|
||||
case 'l': str << AnyCast<unsigned long>(*itVal++); break;
|
||||
case 'L': str << AnyCast<UInt64>(*itVal++); break;
|
||||
case 'h': str << AnyCast<unsigned short>(*itVal++); break;
|
||||
case '?': writeAnyInt(str, *itVal++); break;
|
||||
default: str << AnyCast<unsigned>(*itVal++); break;
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
switch (mod)
|
||||
{
|
||||
case 'l': str << AnyCast<long double>(*itVal++); break;
|
||||
case 'L': str << AnyCast<long double>(*itVal++); break;
|
||||
case 'h': str << AnyCast<float>(*itVal++); break;
|
||||
default: str << AnyCast<double>(*itVal++); break;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
str << RefAnyCast<std::string>(*itVal++);
|
||||
break;
|
||||
case 'z':
|
||||
str << AnyCast<std::size_t>(*itVal++);
|
||||
break;
|
||||
case 'I':
|
||||
case 'D':
|
||||
default:
|
||||
str << type;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Poco::BadCastException&)
|
||||
{
|
||||
str << "[ERRFMT]";
|
||||
}
|
||||
result.append(str.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value1, const Any& value2)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value1, value2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value1, value2, value3);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value1, value2, value3, value4);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value1, value2, value3, value4, value5);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5, const Any& value6)
|
||||
{
|
||||
std::string result;
|
||||
format(result, fmt, value1, value2, value3, value4, value5, value6);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value1);
|
||||
args.push_back(value2);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value1);
|
||||
args.push_back(value2);
|
||||
args.push_back(value3);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value1);
|
||||
args.push_back(value2);
|
||||
args.push_back(value3);
|
||||
args.push_back(value4);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value1);
|
||||
args.push_back(value2);
|
||||
args.push_back(value3);
|
||||
args.push_back(value4);
|
||||
args.push_back(value5);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5, const Any& value6)
|
||||
{
|
||||
std::vector<Any> args;
|
||||
args.push_back(value1);
|
||||
args.push_back(value2);
|
||||
args.push_back(value3);
|
||||
args.push_back(value4);
|
||||
args.push_back(value5);
|
||||
args.push_back(value6);
|
||||
format(result, fmt, args);
|
||||
}
|
||||
|
||||
|
||||
void format(std::string& result, const std::string& fmt, const std::vector<Any>& values)
|
||||
{
|
||||
std::string::const_iterator itFmt = fmt.begin();
|
||||
std::string::const_iterator endFmt = fmt.end();
|
||||
std::vector<Any>::const_iterator itVal = values.begin();
|
||||
std::vector<Any>::const_iterator endVal = values.end();
|
||||
while (itFmt != endFmt)
|
||||
{
|
||||
switch (*itFmt)
|
||||
{
|
||||
case '%':
|
||||
++itFmt;
|
||||
if (itFmt != endFmt && itVal != endVal)
|
||||
{
|
||||
if (*itFmt == '[')
|
||||
{
|
||||
++itFmt;
|
||||
std::size_t index = parseIndex(itFmt, endFmt);
|
||||
if (index < values.size())
|
||||
{
|
||||
std::vector<Any>::const_iterator it = values.begin() + index;
|
||||
formatOne(result, itFmt, endFmt, it);
|
||||
}
|
||||
else throw InvalidArgumentException("format argument index out of range", fmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
formatOne(result, itFmt, endFmt, itVal);
|
||||
}
|
||||
}
|
||||
else if (itFmt != endFmt)
|
||||
{
|
||||
result += *itFmt++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result += *itFmt;
|
||||
++itFmt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// Formatter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Formatter.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Formatter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Formatter::Formatter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Formatter::~Formatter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Formatter::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
throw PropertyNotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
std::string Formatter::getProperty(const std::string& name) const
|
||||
{
|
||||
throw PropertyNotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,148 +0,0 @@
|
||||
//
|
||||
// FormattingChannel.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/FormattingChannel.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Formatter
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/FormattingChannel.h"
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/LoggingRegistry.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
FormattingChannel::FormattingChannel():
|
||||
_pFormatter(0),
|
||||
_pChannel(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FormattingChannel::FormattingChannel(Formatter* pFormatter):
|
||||
_pFormatter(pFormatter),
|
||||
_pChannel(0)
|
||||
{
|
||||
if (_pFormatter) _pFormatter->duplicate();
|
||||
}
|
||||
|
||||
|
||||
FormattingChannel::FormattingChannel(Formatter* pFormatter, Channel* pChannel):
|
||||
_pFormatter(pFormatter),
|
||||
_pChannel(pChannel)
|
||||
{
|
||||
if (_pFormatter) _pFormatter->duplicate();
|
||||
if (_pChannel) _pChannel->duplicate();
|
||||
}
|
||||
|
||||
|
||||
FormattingChannel::~FormattingChannel()
|
||||
{
|
||||
if (_pChannel) _pChannel->release();
|
||||
if (_pFormatter) _pFormatter->release();
|
||||
}
|
||||
|
||||
|
||||
void FormattingChannel::setFormatter(Formatter* pFormatter)
|
||||
{
|
||||
if (_pFormatter) _pFormatter->release();
|
||||
_pFormatter = pFormatter;
|
||||
if (_pFormatter) _pFormatter->duplicate();
|
||||
}
|
||||
|
||||
|
||||
Formatter* FormattingChannel::getFormatter() const
|
||||
{
|
||||
return _pFormatter;
|
||||
}
|
||||
|
||||
|
||||
void FormattingChannel::setChannel(Channel* pChannel)
|
||||
{
|
||||
if (_pChannel) _pChannel->release();
|
||||
_pChannel = pChannel;
|
||||
if (_pChannel) _pChannel->duplicate();
|
||||
}
|
||||
|
||||
|
||||
Channel* FormattingChannel::getChannel() const
|
||||
{
|
||||
return _pChannel;
|
||||
}
|
||||
|
||||
|
||||
void FormattingChannel::log(const Message& msg)
|
||||
{
|
||||
if (_pChannel)
|
||||
{
|
||||
if (_pFormatter)
|
||||
{
|
||||
std::string text;
|
||||
_pFormatter->format(msg, text);
|
||||
_pChannel->log(Message(msg, text));
|
||||
}
|
||||
else
|
||||
{
|
||||
_pChannel->log(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void FormattingChannel::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (name == "channel")
|
||||
setChannel(LoggingRegistry::defaultRegistry().channelForName(value));
|
||||
else if (name == "formatter")
|
||||
setFormatter(LoggingRegistry::defaultRegistry().formatterForName(value));
|
||||
else if (_pChannel)
|
||||
_pChannel->setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
void FormattingChannel::open()
|
||||
{
|
||||
if (_pChannel)
|
||||
_pChannel->open();
|
||||
}
|
||||
|
||||
|
||||
void FormattingChannel::close()
|
||||
{
|
||||
if (_pChannel)
|
||||
_pChannel->close();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,292 +0,0 @@
|
||||
//
|
||||
// Glob.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Glob.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: Glob
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Glob.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/DirectoryIterator.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/UTF8Encoding.h"
|
||||
#include "Poco/Unicode.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Glob::Glob(const std::string& pattern, int options):
|
||||
_pattern(pattern),
|
||||
_options(options)
|
||||
{
|
||||
poco_assert (!_pattern.empty());
|
||||
}
|
||||
|
||||
|
||||
Glob::~Glob()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Glob::match(const std::string& subject)
|
||||
{
|
||||
UTF8Encoding utf8;
|
||||
TextIterator itp(_pattern, utf8);
|
||||
TextIterator endp(_pattern);
|
||||
TextIterator its(subject, utf8);
|
||||
TextIterator ends(subject);
|
||||
|
||||
if ((_options & GLOB_DOT_SPECIAL) && its != ends && *its == '.' && (*itp == '?' || *itp == '*'))
|
||||
return false;
|
||||
else
|
||||
return match(itp, endp, its, ends);
|
||||
}
|
||||
|
||||
|
||||
void Glob::glob(const std::string& pathPattern, std::set<std::string>& files, int options)
|
||||
{
|
||||
glob(Path(Path::expand(pathPattern), Path::PATH_GUESS), files, options);
|
||||
}
|
||||
|
||||
|
||||
void Glob::glob(const char* pathPattern, std::set<std::string>& files, int options)
|
||||
{
|
||||
glob(Path(Path::expand(pathPattern), Path::PATH_GUESS), files, options);
|
||||
}
|
||||
|
||||
|
||||
void Glob::glob(const Path& pathPattern, std::set<std::string>& files, int options)
|
||||
{
|
||||
Path pattern(pathPattern);
|
||||
pattern.makeDirectory(); // to simplify pattern handling later on
|
||||
Path base(pattern);
|
||||
Path absBase(base);
|
||||
absBase.makeAbsolute();
|
||||
while (base.depth() > 0 && base[base.depth() - 1] != "..")
|
||||
{
|
||||
base.popDirectory();
|
||||
absBase.popDirectory();
|
||||
}
|
||||
if (pathPattern.isDirectory()) options |= GLOB_DIRS_ONLY;
|
||||
collect(pattern, absBase, base, pathPattern[base.depth()], files, options);
|
||||
}
|
||||
|
||||
|
||||
bool Glob::match(TextIterator& itp, const TextIterator& endp, TextIterator& its, const TextIterator& ends)
|
||||
{
|
||||
while (itp != endp)
|
||||
{
|
||||
if (its == ends)
|
||||
{
|
||||
while (itp != endp && *itp == '*') ++itp;
|
||||
break;
|
||||
}
|
||||
switch (*itp)
|
||||
{
|
||||
case '?':
|
||||
++itp; ++its;
|
||||
break;
|
||||
case '*':
|
||||
if (++itp != endp)
|
||||
{
|
||||
while (its != ends && !matchAfterAsterisk(itp, endp, its, ends)) ++its;
|
||||
return its != ends;
|
||||
}
|
||||
return true;
|
||||
case '[':
|
||||
if (++itp != endp)
|
||||
{
|
||||
bool invert = *itp == '!';
|
||||
if (invert) ++itp;
|
||||
if (itp != endp)
|
||||
{
|
||||
bool mtch = matchSet(itp, endp, *its++);
|
||||
if ((invert && mtch) || (!invert && !mtch)) return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw SyntaxException("bad range syntax in glob pattern");
|
||||
case '\\':
|
||||
if (++itp == endp) throw SyntaxException("backslash must be followed by character in glob pattern");
|
||||
// fallthrough
|
||||
default:
|
||||
if (_options & GLOB_CASELESS)
|
||||
{
|
||||
if (Unicode::toLower(*itp) != Unicode::toLower(*its)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*itp != *its) return false;
|
||||
}
|
||||
++itp; ++its;
|
||||
}
|
||||
}
|
||||
return itp == endp && its == ends;
|
||||
}
|
||||
|
||||
|
||||
bool Glob::matchAfterAsterisk(TextIterator itp, const TextIterator& endp, TextIterator its, const TextIterator& ends)
|
||||
{
|
||||
return match(itp, endp, its, ends);
|
||||
}
|
||||
|
||||
|
||||
bool Glob::matchSet(TextIterator& itp, const TextIterator& endp, int c)
|
||||
{
|
||||
if (_options & GLOB_CASELESS)
|
||||
c = Unicode::toLower(c);
|
||||
|
||||
while (itp != endp)
|
||||
{
|
||||
switch (*itp)
|
||||
{
|
||||
case ']':
|
||||
++itp;
|
||||
return false;
|
||||
case '\\':
|
||||
if (++itp == endp) throw SyntaxException("backslash must be followed by character in glob pattern");
|
||||
}
|
||||
int first = *itp;
|
||||
int last = first;
|
||||
if (++itp != endp && *itp == '-')
|
||||
{
|
||||
if (++itp != endp)
|
||||
last = *itp++;
|
||||
else
|
||||
throw SyntaxException("bad range syntax in glob pattern");
|
||||
}
|
||||
if (_options & GLOB_CASELESS)
|
||||
{
|
||||
first = Unicode::toLower(first);
|
||||
last = Unicode::toLower(last);
|
||||
}
|
||||
if (first <= c && c <= last)
|
||||
{
|
||||
while (itp != endp)
|
||||
{
|
||||
switch (*itp)
|
||||
{
|
||||
case ']':
|
||||
++itp;
|
||||
return true;
|
||||
case '\\':
|
||||
if (++itp == endp) break;
|
||||
default:
|
||||
++itp;
|
||||
}
|
||||
}
|
||||
throw SyntaxException("range must be terminated by closing bracket in glob pattern");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Glob::collect(const Path& pathPattern, const Path& base, const Path& current, const std::string& pattern, std::set<std::string>& files, int options)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string pp = pathPattern.toString();
|
||||
std::string basep = base.toString();
|
||||
std::string curp = current.toString();
|
||||
Glob g(pattern, options);
|
||||
DirectoryIterator it(base);
|
||||
DirectoryIterator end;
|
||||
while (it != end)
|
||||
{
|
||||
const std::string& name = it.name();
|
||||
if (g.match(name))
|
||||
{
|
||||
Path p(current);
|
||||
if (p.depth() < pathPattern.depth() - 1)
|
||||
{
|
||||
p.pushDirectory(name);
|
||||
collect(pathPattern, it.path(), p, pathPattern[p.depth()], files, options);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.setFileName(name);
|
||||
if (isDirectory(p, (options & GLOB_FOLLOW_SYMLINKS) != 0))
|
||||
{
|
||||
p.makeDirectory();
|
||||
files.insert(p.toString());
|
||||
}
|
||||
else if (!(options & GLOB_DIRS_ONLY))
|
||||
{
|
||||
files.insert(p.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Glob::isDirectory(const Path& path, bool followSymlink)
|
||||
{
|
||||
File f(path);
|
||||
bool isDir = false;
|
||||
try
|
||||
{
|
||||
isDir = f.isDirectory();
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (isDir)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (followSymlink && f.isLink())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Test if link resolves to a directory.
|
||||
DirectoryIterator it(f);
|
||||
return true;
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// Hash.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Hash.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: Hash
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Hash.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::size_t hash(const std::string& str)
|
||||
{
|
||||
std::size_t h = 0;
|
||||
std::string::const_iterator it = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
while (it != end)
|
||||
{
|
||||
h = h * 0xf4243 ^ *it++;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// HashStatistic.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/HashStatistic.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
// Module: HashStatistic
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/HashStatistic.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
HashStatistic::HashStatistic(
|
||||
UInt32 tableSize,
|
||||
UInt32 numEntries,
|
||||
UInt32 numZeroEntries,
|
||||
UInt32 maxEntry,
|
||||
std::vector<UInt32> details):
|
||||
_sizeOfTable(tableSize),
|
||||
_numberOfEntries(numEntries),
|
||||
_numZeroEntries(numZeroEntries),
|
||||
_maxEntriesPerHash(maxEntry),
|
||||
_detailedEntriesPerHash(details)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashStatistic::~HashStatistic()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string HashStatistic::toString() const
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "HashTable of size " << _sizeOfTable << " containing " << _numberOfEntries << " entries:\n";
|
||||
str << " NumberOfZeroEntries: " << _numZeroEntries << "\n";
|
||||
str << " MaxEntry: " << _maxEntriesPerHash << "\n";
|
||||
str << " AvgEntry: " << avgEntriesPerHash() << ", excl Zero slots: " << avgEntriesPerHashExclZeroEntries() << "\n";
|
||||
str << " DetailedStatistics: \n";
|
||||
for (int i = 0; i < _detailedEntriesPerHash.size(); ++i)
|
||||
{
|
||||
// 10 entries per line
|
||||
if (i % 10 == 0)
|
||||
{
|
||||
str << "\n " << i << ":";
|
||||
}
|
||||
str << " " << _detailedEntriesPerHash[i];
|
||||
}
|
||||
str << "\n";
|
||||
str.flush();
|
||||
return str.str();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,116 +0,0 @@
|
||||
//
|
||||
// HexBinaryDecoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/HexBinaryDecoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: HexBinary
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/HexBinaryDecoder.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
HexBinaryDecoderBuf::HexBinaryDecoderBuf(std::istream& istr):
|
||||
_buf(*istr.rdbuf())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoderBuf::~HexBinaryDecoderBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryDecoderBuf::readFromDevice()
|
||||
{
|
||||
int c;
|
||||
int n;
|
||||
if ((n = readOne()) == -1) return -1;
|
||||
if (n >= '0' && n <= '9')
|
||||
c = n - '0';
|
||||
else if (n >= 'A' && n <= 'F')
|
||||
c = n - 'A' + 10;
|
||||
else if (n >= 'a' && n <= 'f')
|
||||
c = n - 'a' + 10;
|
||||
else throw DataFormatException();
|
||||
c <<= 4;
|
||||
if ((n = readOne()) == -1) throw DataFormatException();
|
||||
if (n >= '0' && n <= '9')
|
||||
c |= n - '0';
|
||||
else if (n >= 'A' && n <= 'F')
|
||||
c |= n - 'A' + 10;
|
||||
else if (n >= 'a' && n <= 'f')
|
||||
c |= n - 'a' + 10;
|
||||
else throw DataFormatException();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryDecoderBuf::readOne()
|
||||
{
|
||||
int ch = _buf.sbumpc();
|
||||
while (ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n')
|
||||
ch = _buf.sbumpc();
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoderIOS::HexBinaryDecoderIOS(std::istream& istr): _buf(istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoderIOS::~HexBinaryDecoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoderBuf* HexBinaryDecoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoder::HexBinaryDecoder(std::istream& istr): HexBinaryDecoderIOS(istr), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HexBinaryDecoder::~HexBinaryDecoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,139 +0,0 @@
|
||||
//
|
||||
// HexBinaryEncoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/HexBinaryEncoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: HexBinary
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/HexBinaryEncoder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
HexBinaryEncoderBuf::HexBinaryEncoderBuf(std::ostream& ostr):
|
||||
_pos(0),
|
||||
_lineLength(72),
|
||||
_uppercase(0),
|
||||
_buf(*ostr.rdbuf())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoderBuf::~HexBinaryEncoderBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HexBinaryEncoderBuf::setLineLength(int lineLength)
|
||||
{
|
||||
_lineLength = lineLength;
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryEncoderBuf::getLineLength() const
|
||||
{
|
||||
return _lineLength;
|
||||
}
|
||||
|
||||
|
||||
void HexBinaryEncoderBuf::setUppercase(bool flag)
|
||||
{
|
||||
_uppercase = flag ? 16 : 0;
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryEncoderBuf::writeToDevice(char c)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
static const char digits[] = "0123456789abcdef0123456789ABCDEF";
|
||||
|
||||
if (_buf.sputc(digits[_uppercase + ((c >> 4) & 0xF)]) == eof) return eof;
|
||||
++_pos;
|
||||
if (_buf.sputc(digits[_uppercase + (c & 0xF)]) == eof) return eof;
|
||||
if (++_pos >= _lineLength && _lineLength > 0)
|
||||
{
|
||||
if (_buf.sputc('\n') == eof) return eof;
|
||||
_pos = 0;
|
||||
}
|
||||
return charToInt(c);
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryEncoderBuf::close()
|
||||
{
|
||||
sync();
|
||||
return _buf.pubsync();
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoderIOS::HexBinaryEncoderIOS(std::ostream& ostr): _buf(ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoderIOS::~HexBinaryEncoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int HexBinaryEncoderIOS::close()
|
||||
{
|
||||
return _buf.close();
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoderBuf* HexBinaryEncoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoder::HexBinaryEncoder(std::ostream& ostr): HexBinaryEncoderIOS(ostr), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HexBinaryEncoder::~HexBinaryEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,367 +0,0 @@
|
||||
//
|
||||
// InflatingStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/InflatingStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: ZLibStream
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/InflatingStream.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, StreamType type):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_eof(false),
|
||||
_check(type != STREAM_ZIP)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InflatingStreamBuf::InflatingStreamBuf(std::istream& istr, int windowBits):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_eof(false),
|
||||
_check(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = inflateInit2(&_zstr, windowBits);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, StreamType type):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_eof(false),
|
||||
_check(type != STREAM_ZIP)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = inflateInit2(&_zstr, 15 + (type == STREAM_GZIP ? 16 : 0));
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InflatingStreamBuf::InflatingStreamBuf(std::ostream& ostr, int windowBits):
|
||||
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_eof(false),
|
||||
_check(false)
|
||||
{
|
||||
_zstr.zalloc = Z_NULL;
|
||||
_zstr.zfree = Z_NULL;
|
||||
_zstr.opaque = Z_NULL;
|
||||
_zstr.next_in = 0;
|
||||
_zstr.avail_in = 0;
|
||||
_zstr.next_out = 0;
|
||||
_zstr.avail_out = 0;
|
||||
|
||||
_buffer = new char[INFLATE_BUFFER_SIZE];
|
||||
|
||||
int rc = inflateInit2(&_zstr, windowBits);
|
||||
if (rc != Z_OK)
|
||||
{
|
||||
delete [] _buffer;
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
InflatingStreamBuf::~InflatingStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
delete [] _buffer;
|
||||
inflateEnd(&_zstr);
|
||||
}
|
||||
|
||||
|
||||
int InflatingStreamBuf::close()
|
||||
{
|
||||
sync();
|
||||
_pIstr = 0;
|
||||
_pOstr = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void InflatingStreamBuf::reset()
|
||||
{
|
||||
int rc = inflateReset(&_zstr);
|
||||
if (rc == Z_OK)
|
||||
_eof = false;
|
||||
else
|
||||
throw IOException(zError(rc));
|
||||
}
|
||||
|
||||
|
||||
int InflatingStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (_eof || !_pIstr) return 0;
|
||||
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
int n = 0;
|
||||
if (_pIstr->good())
|
||||
{
|
||||
_pIstr->read(_buffer, INFLATE_BUFFER_SIZE);
|
||||
n = static_cast<int>(_pIstr->gcount());
|
||||
}
|
||||
if (n == 0) return 0;
|
||||
_zstr.next_in = (unsigned char*) _buffer;
|
||||
_zstr.avail_in = n;
|
||||
}
|
||||
_zstr.next_out = (unsigned char*) buffer;
|
||||
_zstr.avail_out = static_cast<unsigned>(length);
|
||||
for (;;)
|
||||
{
|
||||
int rc = inflate(&_zstr, Z_NO_FLUSH);
|
||||
if (rc == Z_DATA_ERROR && !_check)
|
||||
{
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
if (_pIstr->good())
|
||||
rc = Z_OK;
|
||||
else
|
||||
rc = Z_STREAM_END;
|
||||
}
|
||||
}
|
||||
if (rc == Z_STREAM_END)
|
||||
{
|
||||
_eof = true;
|
||||
return static_cast<int>(length) - _zstr.avail_out;
|
||||
}
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
if (_zstr.avail_out == 0)
|
||||
return static_cast<int>(length);
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
int n = 0;
|
||||
if (_pIstr->good())
|
||||
{
|
||||
_pIstr->read(_buffer, INFLATE_BUFFER_SIZE);
|
||||
n = static_cast<int>(_pIstr->gcount());
|
||||
}
|
||||
if (n > 0)
|
||||
{
|
||||
_zstr.next_in = (unsigned char*) _buffer;
|
||||
_zstr.avail_in = n;
|
||||
}
|
||||
else return static_cast<int>(length) - _zstr.avail_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int InflatingStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (length == 0 || !_pOstr) return 0;
|
||||
|
||||
_zstr.next_in = (unsigned char*) buffer;
|
||||
_zstr.avail_in = static_cast<unsigned>(length);
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
||||
for (;;)
|
||||
{
|
||||
int rc = inflate(&_zstr, Z_NO_FLUSH);
|
||||
if (rc == Z_STREAM_END)
|
||||
{
|
||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
break;
|
||||
}
|
||||
if (rc != Z_OK) throw IOException(zError(rc));
|
||||
if (_zstr.avail_out == 0)
|
||||
{
|
||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
||||
}
|
||||
if (_zstr.avail_in == 0)
|
||||
{
|
||||
_pOstr->write(_buffer, INFLATE_BUFFER_SIZE - _zstr.avail_out);
|
||||
if (!_pOstr->good()) throw IOException(zError(rc));
|
||||
_zstr.next_out = (unsigned char*) _buffer;
|
||||
_zstr.avail_out = INFLATE_BUFFER_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return static_cast<int>(length);
|
||||
}
|
||||
|
||||
|
||||
InflatingIOS::InflatingIOS(std::ostream& ostr, InflatingStreamBuf::StreamType type):
|
||||
_buf(ostr, type)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
InflatingIOS::InflatingIOS(std::ostream& ostr, int windowBits):
|
||||
_buf(ostr, windowBits)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
InflatingIOS::InflatingIOS(std::istream& istr, InflatingStreamBuf::StreamType type):
|
||||
_buf(istr, type)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
InflatingIOS::InflatingIOS(std::istream& istr, int windowBits):
|
||||
_buf(istr, windowBits)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
InflatingIOS::~InflatingIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InflatingStreamBuf* InflatingIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
InflatingOutputStream::InflatingOutputStream(std::ostream& ostr, InflatingStreamBuf::StreamType type):
|
||||
InflatingIOS(ostr, type),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InflatingOutputStream::InflatingOutputStream(std::ostream& ostr, int windowBits):
|
||||
InflatingIOS(ostr, windowBits),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InflatingOutputStream::~InflatingOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int InflatingOutputStream::close()
|
||||
{
|
||||
return _buf.close();
|
||||
}
|
||||
|
||||
|
||||
InflatingInputStream::InflatingInputStream(std::istream& istr, InflatingStreamBuf::StreamType type):
|
||||
InflatingIOS(istr, type),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InflatingInputStream::InflatingInputStream(std::istream& istr, int windowBits):
|
||||
InflatingIOS(istr, windowBits),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InflatingInputStream::~InflatingInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void InflatingInputStream::reset()
|
||||
{
|
||||
_buf.reset();
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,140 +0,0 @@
|
||||
//
|
||||
// Latin1Encoding.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Latin1Encoding.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Latin1Encoding
|
||||
//
|
||||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Latin1Encoding.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const char* Latin1Encoding::_names[] =
|
||||
{
|
||||
"ISO-8859-1",
|
||||
"Latin1",
|
||||
"Latin-1",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap Latin1Encoding::_charMap =
|
||||
{
|
||||
/* 00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
/* 10 */ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
/* 20 */ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
/* 30 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
/* 40 */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
/* 50 */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
/* 60 */ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
/* 70 */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
/* 80 */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
/* 90 */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
/* a0 */ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
/* b0 */ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
/* c0 */ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
/* d0 */ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
/* e0 */ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
/* f0 */ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
};
|
||||
|
||||
|
||||
Latin1Encoding::Latin1Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Latin1Encoding::~Latin1Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char* Latin1Encoding::canonicalName() const
|
||||
{
|
||||
return _names[0];
|
||||
}
|
||||
|
||||
|
||||
bool Latin1Encoding::isA(const std::string& encodingName) const
|
||||
{
|
||||
for (const char** name = _names; *name; ++name)
|
||||
{
|
||||
if (Poco::icompare(encodingName, *name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap& Latin1Encoding::characterMap() const
|
||||
{
|
||||
return _charMap;
|
||||
}
|
||||
|
||||
|
||||
int Latin1Encoding::convert(const unsigned char* bytes) const
|
||||
{
|
||||
return _charMap[*bytes];
|
||||
}
|
||||
|
||||
|
||||
int Latin1Encoding::convert(int ch, unsigned char* bytes, int length) const
|
||||
{
|
||||
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
|
||||
{
|
||||
if (bytes && length >= 1)
|
||||
*bytes = (unsigned char) ch;
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
int Latin1Encoding::queryConvert(const unsigned char* bytes, int length) const
|
||||
{
|
||||
if (1 <= length)
|
||||
return _charMap[*bytes];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int Latin1Encoding::sequenceLength(const unsigned char* bytes, int length) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,151 +0,0 @@
|
||||
//
|
||||
// Latin2Encoding.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/src/Latin2Encoding.cpp#12 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Latin2Encoding
|
||||
//
|
||||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Latin2Encoding.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const char* Latin2Encoding::_names[] =
|
||||
{
|
||||
"ISO-8859-2",
|
||||
"Latin2",
|
||||
"Latin-2",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap Latin2Encoding::_charMap =
|
||||
{
|
||||
/* 00 */ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
|
||||
/* 10 */ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
|
||||
/* 20 */ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
|
||||
/* 30 */ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
|
||||
/* 40 */ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
|
||||
/* 50 */ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
|
||||
/* 60 */ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
|
||||
/* 70 */ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
|
||||
/* 80 */ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
|
||||
/* 90 */ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
|
||||
/* a0 */ 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b,
|
||||
/* b0 */ 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c,
|
||||
/* c0 */ 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
|
||||
/* d0 */ 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
|
||||
/* e0 */ 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f,
|
||||
/* f0 */ 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9,
|
||||
};
|
||||
|
||||
|
||||
Latin2Encoding::Latin2Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Latin2Encoding::~Latin2Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char* Latin2Encoding::canonicalName() const
|
||||
{
|
||||
return _names[0];
|
||||
}
|
||||
|
||||
|
||||
bool Latin2Encoding::isA(const std::string& encodingName) const
|
||||
{
|
||||
for (const char** name = _names; *name; ++name)
|
||||
{
|
||||
if (Poco::icompare(encodingName, *name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap& Latin2Encoding::characterMap() const
|
||||
{
|
||||
return _charMap;
|
||||
}
|
||||
|
||||
|
||||
int Latin2Encoding::convert(const unsigned char* bytes) const
|
||||
{
|
||||
return _charMap[*bytes];
|
||||
}
|
||||
|
||||
|
||||
int Latin2Encoding::convert(int ch, unsigned char* bytes, int length) const
|
||||
{
|
||||
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
|
||||
{
|
||||
if (bytes && length >= 1)
|
||||
*bytes = (unsigned char) ch;
|
||||
return 1;
|
||||
}
|
||||
else switch (ch)
|
||||
{/*
|
||||
case 0x0152: if (bytes && length >= 1) *bytes = 0xbc; return 1;
|
||||
case 0x0153: if (bytes && length >= 1) *bytes = 0xbd; return 1;
|
||||
case 0x0160: if (bytes && length >= 1) *bytes = 0xa6; return 1;
|
||||
case 0x0161: if (bytes && length >= 1) *bytes = 0xa8; return 1;
|
||||
case 0x017d: if (bytes && length >= 1) *bytes = 0xb4; return 1;
|
||||
case 0x017e: if (bytes && length >= 1) *bytes = 0xb8; return 1;
|
||||
case 0x0178: if (bytes && length >= 1) *bytes = 0xbe; return 1;
|
||||
case 0x20ac: if (bytes && length >= 1) *bytes = 0xa4; return 1;
|
||||
*/
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Latin2Encoding::queryConvert(const unsigned char* bytes, int length) const
|
||||
{
|
||||
if (1 <= length)
|
||||
return _charMap[*bytes];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int Latin2Encoding::sequenceLength(const unsigned char* bytes, int length) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,151 +0,0 @@
|
||||
//
|
||||
// Latin9Encoding.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Latin9Encoding.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Text
|
||||
// Module: Latin9Encoding
|
||||
//
|
||||
// Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Latin9Encoding.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const char* Latin9Encoding::_names[] =
|
||||
{
|
||||
"ISO-8859-15",
|
||||
"Latin9",
|
||||
"Latin-9",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap Latin9Encoding::_charMap =
|
||||
{
|
||||
/* 00 */ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
|
||||
/* 10 */ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
|
||||
/* 20 */ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
|
||||
/* 30 */ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
|
||||
/* 40 */ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
|
||||
/* 50 */ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
|
||||
/* 60 */ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
|
||||
/* 70 */ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
|
||||
/* 80 */ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
|
||||
/* 90 */ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
|
||||
/* a0 */ 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
|
||||
/* b0 */ 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf,
|
||||
/* c0 */ 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
|
||||
/* d0 */ 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
|
||||
/* e0 */ 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
|
||||
/* f0 */ 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff,
|
||||
};
|
||||
|
||||
|
||||
Latin9Encoding::Latin9Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Latin9Encoding::~Latin9Encoding()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char* Latin9Encoding::canonicalName() const
|
||||
{
|
||||
return _names[0];
|
||||
}
|
||||
|
||||
|
||||
bool Latin9Encoding::isA(const std::string& encodingName) const
|
||||
{
|
||||
for (const char** name = _names; *name; ++name)
|
||||
{
|
||||
if (Poco::icompare(encodingName, *name) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const TextEncoding::CharacterMap& Latin9Encoding::characterMap() const
|
||||
{
|
||||
return _charMap;
|
||||
}
|
||||
|
||||
|
||||
int Latin9Encoding::convert(const unsigned char* bytes) const
|
||||
{
|
||||
return _charMap[*bytes];
|
||||
}
|
||||
|
||||
|
||||
int Latin9Encoding::convert(int ch, unsigned char* bytes, int length) const
|
||||
{
|
||||
if (ch >= 0 && ch <= 255 && _charMap[ch] == ch)
|
||||
{
|
||||
if (bytes && length >= 1)
|
||||
*bytes = ch;
|
||||
return 1;
|
||||
}
|
||||
else switch (ch)
|
||||
{
|
||||
case 0x0152: if (bytes && length >= 1) *bytes = 0xbc; return 1;
|
||||
case 0x0153: if (bytes && length >= 1) *bytes = 0xbd; return 1;
|
||||
case 0x0160: if (bytes && length >= 1) *bytes = 0xa6; return 1;
|
||||
case 0x0161: if (bytes && length >= 1) *bytes = 0xa8; return 1;
|
||||
case 0x017d: if (bytes && length >= 1) *bytes = 0xb4; return 1;
|
||||
case 0x017e: if (bytes && length >= 1) *bytes = 0xb8; return 1;
|
||||
case 0x0178: if (bytes && length >= 1) *bytes = 0xbe; return 1;
|
||||
case 0x20ac: if (bytes && length >= 1) *bytes = 0xa4; return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Latin9Encoding::queryConvert(const unsigned char* bytes, int length) const
|
||||
{
|
||||
if (1 <= length)
|
||||
return _charMap[*bytes];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int Latin9Encoding::sequenceLength(const unsigned char* bytes, int length) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,204 +0,0 @@
|
||||
//
|
||||
// LineEndingConverter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LineEndingConverter.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: LineEndingConverter
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LineEndingConverter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define POCO_DEFAULT_NEWLINE_CHARS "\r\n"
|
||||
#else
|
||||
#define POCO_DEFAULT_NEWLINE_CHARS "\n"
|
||||
#endif
|
||||
|
||||
|
||||
const std::string LineEnding::NEWLINE_DEFAULT(POCO_DEFAULT_NEWLINE_CHARS);
|
||||
const std::string LineEnding::NEWLINE_CR("\r");
|
||||
const std::string LineEnding::NEWLINE_CRLF("\r\n");
|
||||
const std::string LineEnding::NEWLINE_LF("\n");
|
||||
|
||||
|
||||
LineEndingConverterStreamBuf::LineEndingConverterStreamBuf(std::istream& istr):
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_newLine(LineEnding::NEWLINE_DEFAULT),
|
||||
_lastChar(0)
|
||||
{
|
||||
_it = _newLine.end();
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterStreamBuf::LineEndingConverterStreamBuf(std::ostream& ostr):
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_newLine(LineEnding::NEWLINE_DEFAULT),
|
||||
_lastChar(0)
|
||||
{
|
||||
_it = _newLine.end();
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterStreamBuf::~LineEndingConverterStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LineEndingConverterStreamBuf::setNewLine(const std::string& newLineCharacters)
|
||||
{
|
||||
_newLine = newLineCharacters;
|
||||
_it = _newLine.end();
|
||||
}
|
||||
|
||||
|
||||
const std::string& LineEndingConverterStreamBuf::getNewLine() const
|
||||
{
|
||||
return _newLine;
|
||||
}
|
||||
|
||||
|
||||
int LineEndingConverterStreamBuf::readFromDevice()
|
||||
{
|
||||
poco_assert_dbg (_pIstr);
|
||||
|
||||
while (_it == _newLine.end())
|
||||
{
|
||||
int c = _pIstr->get();
|
||||
if (c == '\r')
|
||||
{
|
||||
if (_pIstr->peek() == '\n') _pIstr->get();
|
||||
_it = _newLine.begin();
|
||||
}
|
||||
else if (c == '\n')
|
||||
{
|
||||
_it = _newLine.begin();
|
||||
}
|
||||
else return c;
|
||||
}
|
||||
return *_it++;
|
||||
}
|
||||
|
||||
|
||||
int LineEndingConverterStreamBuf::writeToDevice(char c)
|
||||
{
|
||||
poco_assert_dbg (_pOstr);
|
||||
|
||||
if (c == '\r' || (c == '\n' && _lastChar != '\r'))
|
||||
_pOstr->write(_newLine.data(), (std::streamsize) _newLine.length());
|
||||
if (c != '\n' && c != '\r')
|
||||
_pOstr->put(c);
|
||||
_lastChar = c;
|
||||
return charToInt(c);
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterIOS::LineEndingConverterIOS(std::istream& istr): _buf(istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterIOS::LineEndingConverterIOS(std::ostream& ostr): _buf(ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterIOS::~LineEndingConverterIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LineEndingConverterIOS::setNewLine(const std::string& newLineCharacters)
|
||||
{
|
||||
_buf.setNewLine(newLineCharacters);
|
||||
}
|
||||
|
||||
|
||||
const std::string& LineEndingConverterIOS::getNewLine() const
|
||||
{
|
||||
return _buf.getNewLine();
|
||||
}
|
||||
|
||||
|
||||
LineEndingConverterStreamBuf* LineEndingConverterIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
InputLineEndingConverter::InputLineEndingConverter(std::istream& istr):
|
||||
LineEndingConverterIOS(istr),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
InputLineEndingConverter::InputLineEndingConverter(std::istream& istr, const std::string& newLineCharacters):
|
||||
LineEndingConverterIOS(istr),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
setNewLine(newLineCharacters);
|
||||
}
|
||||
|
||||
|
||||
InputLineEndingConverter::~InputLineEndingConverter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OutputLineEndingConverter::OutputLineEndingConverter(std::ostream& ostr):
|
||||
LineEndingConverterIOS(ostr),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
OutputLineEndingConverter::OutputLineEndingConverter(std::ostream& ostr, const std::string& newLineCharacters):
|
||||
LineEndingConverterIOS(ostr),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
setNewLine(newLineCharacters);
|
||||
}
|
||||
|
||||
|
||||
OutputLineEndingConverter::~OutputLineEndingConverter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,339 +0,0 @@
|
||||
//
|
||||
// LocalDateTime.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LocalDateTime.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: DateTime
|
||||
// Module: LocalDateTime
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LocalDateTime.h"
|
||||
#include "Poco/Timezone.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "wce_time.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime()
|
||||
{
|
||||
determineTzd(true);
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond):
|
||||
_dateTime(year, month, day, hour, minute, second, millisecond, microsecond)
|
||||
{
|
||||
determineTzd();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond):
|
||||
_dateTime(year, month, day, hour, minute, second, millisecond, microsecond),
|
||||
_tzd(tzd)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(double julianDay):
|
||||
_dateTime(julianDay)
|
||||
{
|
||||
determineTzd(true);
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(int tzd, double julianDay):
|
||||
_dateTime(julianDay),
|
||||
_tzd(tzd)
|
||||
{
|
||||
adjustForTzd();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(const DateTime& dateTime):
|
||||
_dateTime(dateTime)
|
||||
{
|
||||
determineTzd(true);
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(int tzd, const DateTime& dateTime):
|
||||
_dateTime(dateTime),
|
||||
_tzd(tzd)
|
||||
{
|
||||
adjustForTzd();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(int tzd, const DateTime& dateTime, bool adjust):
|
||||
_dateTime(dateTime),
|
||||
_tzd(tzd)
|
||||
{
|
||||
if (adjust)
|
||||
adjustForTzd();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(const LocalDateTime& dateTime):
|
||||
_dateTime(dateTime._dateTime),
|
||||
_tzd(dateTime._tzd)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::LocalDateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff, int tzd):
|
||||
_dateTime(utcTime, diff),
|
||||
_tzd(tzd)
|
||||
{
|
||||
adjustForTzd();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime::~LocalDateTime()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::operator = (const LocalDateTime& dateTime)
|
||||
{
|
||||
if (&dateTime != this)
|
||||
{
|
||||
_dateTime = dateTime._dateTime;
|
||||
_tzd = dateTime._tzd;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::operator = (const Timestamp& timestamp)
|
||||
{
|
||||
if (timestamp != this->timestamp())
|
||||
{
|
||||
_dateTime = timestamp;
|
||||
determineTzd(true);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::operator = (double julianDay)
|
||||
{
|
||||
_dateTime = julianDay;
|
||||
determineTzd(true);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::assign(int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
|
||||
{
|
||||
_dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
|
||||
determineTzd(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::assign(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
|
||||
{
|
||||
_dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
|
||||
_tzd = tzd;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::assign(int tzd, double julianDay)
|
||||
{
|
||||
_tzd = tzd;
|
||||
_dateTime = julianDay;
|
||||
adjustForTzd();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void LocalDateTime::swap(LocalDateTime& dateTime)
|
||||
{
|
||||
_dateTime.swap(dateTime._dateTime);
|
||||
std::swap(_tzd, dateTime._tzd);
|
||||
}
|
||||
|
||||
|
||||
DateTime LocalDateTime::utc() const
|
||||
{
|
||||
return DateTime(_dateTime.utcTime(), -((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator == (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() == dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator != (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() != dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator < (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() < dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator <= (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() <= dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator > (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() > dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
bool LocalDateTime::operator >= (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return utcTime() >= dateTime.utcTime();
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime LocalDateTime::operator + (const Timespan& span) const
|
||||
{
|
||||
// First calculate the adjusted UTC time, then calculate the
|
||||
// locally adjusted time by constructing a new LocalDateTime.
|
||||
DateTime tmp(utcTime(), span.totalMicroseconds());
|
||||
return LocalDateTime(tmp);
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime LocalDateTime::operator - (const Timespan& span) const
|
||||
{
|
||||
// First calculate the adjusted UTC time, then calculate the
|
||||
// locally adjusted time by constructing a new LocalDateTime.
|
||||
DateTime tmp(utcTime(), -span.totalMicroseconds());
|
||||
return LocalDateTime(tmp);
|
||||
}
|
||||
|
||||
|
||||
Timespan LocalDateTime::operator - (const LocalDateTime& dateTime) const
|
||||
{
|
||||
return Timespan((utcTime() - dateTime.utcTime())/10);
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::operator += (const Timespan& span)
|
||||
{
|
||||
// Use the same trick as in operator+. Create a UTC time, adjust
|
||||
// it for the span, and convert back to LocalDateTime. This will
|
||||
// recalculate the tzd correctly in the case where the addition
|
||||
// crosses a DST boundary.
|
||||
*this = DateTime(utcTime(), span.totalMicroseconds());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LocalDateTime& LocalDateTime::operator -= (const Timespan& span)
|
||||
{
|
||||
// Use the same trick as in operator-. Create a UTC time, adjust
|
||||
// it for the span, and convert back to LocalDateTime. This will
|
||||
// recalculate the tzd correctly in the case where the subtraction
|
||||
// crosses a DST boundary.
|
||||
*this = DateTime(utcTime(), -span.totalMicroseconds());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void LocalDateTime::determineTzd(bool adjust)
|
||||
{
|
||||
if (adjust)
|
||||
{
|
||||
std::time_t epochTime = _dateTime.timestamp().epochTime();
|
||||
#if defined(_WIN32) || defined(POCO_NO_POSIX_TSF)
|
||||
#if defined(_WIN32_WCE)
|
||||
std::tm* broken = wceex_localtime(&epochTime);
|
||||
#else
|
||||
std::tm* broken = std::localtime(&epochTime);
|
||||
#endif
|
||||
if (!broken) throw Poco::SystemException("cannot get local time");
|
||||
_tzd = (Timezone::utcOffset() + ((broken->tm_isdst == 1) ? 3600 : 0));
|
||||
#else
|
||||
std::tm broken;
|
||||
#if defined(POCO_VXWORKS)
|
||||
if (localtime_r(&epochTime, &broken) != OK)
|
||||
throw Poco::SystemException("cannot get local time");
|
||||
#else
|
||||
if (!localtime_r(&epochTime, &broken))
|
||||
throw Poco::SystemException("cannot get local time");
|
||||
#endif
|
||||
_tzd = (Timezone::utcOffset() + ((broken.tm_isdst == 1) ? 3600 : 0));
|
||||
#endif
|
||||
adjustForTzd();
|
||||
}
|
||||
else
|
||||
{
|
||||
int dst;
|
||||
dstOffset(dst);
|
||||
_tzd = (Timezone::utcOffset() + dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::time_t LocalDateTime::dstOffset(int& dstOffset) const
|
||||
{
|
||||
std::time_t local;
|
||||
std::tm broken;
|
||||
|
||||
broken.tm_year = (_dateTime.year() - 1900);
|
||||
broken.tm_mon = (_dateTime.month() - 1);
|
||||
broken.tm_mday = _dateTime.day();
|
||||
broken.tm_hour = _dateTime.hour();
|
||||
broken.tm_min = _dateTime.minute();
|
||||
broken.tm_sec = _dateTime.second();
|
||||
broken.tm_isdst = -1;
|
||||
#if defined(_WIN32_WCE)
|
||||
local = wceex_mktime(&broken);
|
||||
#else
|
||||
local = std::mktime(&broken);
|
||||
#endif
|
||||
|
||||
dstOffset = (broken.tm_isdst == 1) ? 3600 : 0;
|
||||
return local;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// LogFile.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogFile.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogFile
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogFile.h"
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#include "LogFile_WIN32U.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "LogFile_WIN32.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_VMS)
|
||||
#include "LogFile_VMS.cpp"
|
||||
#else
|
||||
#include "LogFile_STD.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LogFile::LogFile(const std::string& path): LogFileImpl(path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogFile::~LogFile()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// LogFile_STD.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogFile_STD.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogFile
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogFile_STD.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LogFileImpl::LogFileImpl(const std::string& path):
|
||||
_path(path),
|
||||
_str(_path, std::ios::app)
|
||||
{
|
||||
if (sizeImpl() == 0)
|
||||
_creationDate = File(path).getLastModified();
|
||||
else
|
||||
_creationDate = File(path).created();
|
||||
}
|
||||
|
||||
|
||||
LogFileImpl::~LogFileImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
{
|
||||
_str << text << std::endl;
|
||||
if (!_str.good()) throw WriteFileException(_path);
|
||||
}
|
||||
|
||||
|
||||
UInt64 LogFileImpl::sizeImpl() const
|
||||
{
|
||||
return (UInt64) _str.tellp();
|
||||
}
|
||||
|
||||
|
||||
Timestamp LogFileImpl::creationDateImpl() const
|
||||
{
|
||||
return _creationDate;
|
||||
}
|
||||
|
||||
|
||||
const std::string& LogFileImpl::pathImpl() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// LogFile_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogFile_VMS.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogFile
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogFile_VMS.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LogFileImpl::LogFileImpl(const std::string& path): _path(path)
|
||||
{
|
||||
_file = fopen(path.c_str(), "a", "ctx=rec,bin", "shr=get", "fop=dfw", "alq=500", "deq=500");
|
||||
if (!_file) throw OpenFileException(path);
|
||||
if (size() == 0)
|
||||
_creationDate = File(path).getLastModified();
|
||||
else
|
||||
_creationDate = File(path).created();
|
||||
}
|
||||
|
||||
|
||||
LogFileImpl::~LogFileImpl()
|
||||
{
|
||||
fclose(_file);
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
{
|
||||
int rc = fputs(text.c_str(), _file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
rc = fputc('\n', _file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
rc = fflush(_file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
}
|
||||
|
||||
|
||||
UInt64 LogFileImpl::sizeImpl() const
|
||||
{
|
||||
return (UInt64) ftell(_file);
|
||||
}
|
||||
|
||||
|
||||
Timestamp LogFileImpl::creationDateImpl() const
|
||||
{
|
||||
return _creationDate;
|
||||
}
|
||||
|
||||
|
||||
const std::string& LogFileImpl::pathImpl() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,130 +0,0 @@
|
||||
//
|
||||
// LogFile_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogFile_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogFile
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogFile_WIN32.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LogFileImpl::LogFileImpl(const std::string& path): _path(path), _hFile(INVALID_HANDLE_VALUE)
|
||||
{
|
||||
File file(path);
|
||||
if (file.exists())
|
||||
{
|
||||
if (0 == sizeImpl())
|
||||
_creationDate = file.getLastModified();
|
||||
else
|
||||
_creationDate = file.created();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LogFileImpl::~LogFileImpl()
|
||||
{
|
||||
CloseHandle(_hFile);
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile) createFile();
|
||||
|
||||
DWORD bytesWritten;
|
||||
BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
}
|
||||
|
||||
|
||||
UInt64 LogFileImpl::sizeImpl() const
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile)
|
||||
{
|
||||
File file(_path);
|
||||
if (file.exists()) return file.getSize();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.HighPart = 0;
|
||||
li.LowPart = SetFilePointer(_hFile, 0, &li.HighPart, FILE_CURRENT);
|
||||
return li.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
Timestamp LogFileImpl::creationDateImpl() const
|
||||
{
|
||||
return _creationDate;
|
||||
}
|
||||
|
||||
|
||||
const std::string& LogFileImpl::pathImpl() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::createFile()
|
||||
{
|
||||
_hFile = CreateFileA(_path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (_hFile == INVALID_HANDLE_VALUE) throw OpenFileException(_path);
|
||||
SetFilePointer(_hFile, 0, 0, FILE_END);
|
||||
// There seems to be a strange "optimization" in the Windows NTFS
|
||||
// filesystem that causes it to reuse directory entries of deleted
|
||||
// files. Example:
|
||||
// 1. create a file named "test.dat"
|
||||
// note the file's creation date
|
||||
// 2. delete the file "test.dat"
|
||||
// 3. wait a few seconds
|
||||
// 4. create a file named "test.dat"
|
||||
// the new file will have the same creation
|
||||
// date as the old one.
|
||||
// We work around this bug by taking the file's
|
||||
// modification date as a reference when the
|
||||
// file is empty.
|
||||
if (sizeImpl() == 0)
|
||||
_creationDate = File(_path).getLastModified();
|
||||
else
|
||||
_creationDate = File(_path).created();
|
||||
}
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,135 +0,0 @@
|
||||
//
|
||||
// LogFile_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogFile_WIN32U.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogFile
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogFile_WIN32U.h"
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LogFileImpl::LogFileImpl(const std::string& path): _path(path), _hFile(INVALID_HANDLE_VALUE)
|
||||
{
|
||||
File file(path);
|
||||
if (file.exists())
|
||||
{
|
||||
if (0 == sizeImpl())
|
||||
_creationDate = file.getLastModified();
|
||||
else
|
||||
_creationDate = file.created();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LogFileImpl::~LogFileImpl()
|
||||
{
|
||||
CloseHandle(_hFile);
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile) createFile();
|
||||
|
||||
DWORD bytesWritten;
|
||||
BOOL res = WriteFile(_hFile, text.data(), (DWORD) text.size(), &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
}
|
||||
|
||||
|
||||
UInt64 LogFileImpl::sizeImpl() const
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile)
|
||||
{
|
||||
File file(_path);
|
||||
if (file.exists()) return file.getSize();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
LARGE_INTEGER li;
|
||||
li.HighPart = 0;
|
||||
li.LowPart = SetFilePointer(_hFile, 0, &li.HighPart, FILE_CURRENT);
|
||||
return li.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
Timestamp LogFileImpl::creationDateImpl() const
|
||||
{
|
||||
return _creationDate;
|
||||
}
|
||||
|
||||
|
||||
const std::string& LogFileImpl::pathImpl() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
void LogFileImpl::createFile()
|
||||
{
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(_path, upath);
|
||||
|
||||
_hFile = CreateFileW(upath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (_hFile == INVALID_HANDLE_VALUE) throw OpenFileException(_path);
|
||||
SetFilePointer(_hFile, 0, 0, FILE_END);
|
||||
// There seems to be a strange "optimization" in the Windows NTFS
|
||||
// filesystem that causes it to reuse directory entries of deleted
|
||||
// files. Example:
|
||||
// 1. create a file named "test.dat"
|
||||
// note the file's creation date
|
||||
// 2. delete the file "test.dat"
|
||||
// 3. wait a few seconds
|
||||
// 4. create a file named "test.dat"
|
||||
// the new file will have the same creation
|
||||
// date as the old one.
|
||||
// We work around this bug by taking the file's
|
||||
// modification date as a reference when the
|
||||
// file is empty.
|
||||
if (sizeImpl() == 0)
|
||||
_creationDate = File(_path).getLastModified();
|
||||
else
|
||||
_creationDate = File(_path).created();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,237 +0,0 @@
|
||||
//
|
||||
// LogStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LogStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LogStream
|
||||
//
|
||||
// Copyright (c) 2006-2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LogStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
//
|
||||
// LogStreamBuf
|
||||
//
|
||||
|
||||
|
||||
LogStreamBuf::LogStreamBuf(Logger& logger, Message::Priority priority):
|
||||
_logger(logger),
|
||||
_priority(priority)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogStreamBuf::~LogStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LogStreamBuf::setPriority(Message::Priority priority)
|
||||
{
|
||||
_priority = priority;
|
||||
}
|
||||
|
||||
|
||||
int LogStreamBuf::writeToDevice(char c)
|
||||
{
|
||||
if (c == '\n' || c == '\r')
|
||||
{
|
||||
Message msg(_logger.name(), _message, _priority);
|
||||
_message.clear();
|
||||
_logger.log(msg);
|
||||
}
|
||||
else _message += c;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// LogIOS
|
||||
//
|
||||
|
||||
|
||||
LogIOS::LogIOS(Logger& logger, Message::Priority priority):
|
||||
_buf(logger, priority)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
LogIOS::~LogIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogStreamBuf* LogIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// LogStream
|
||||
//
|
||||
|
||||
|
||||
LogStream::LogStream(Logger& logger, Message::Priority priority):
|
||||
LogIOS(logger, priority),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogStream::LogStream(const std::string& loggerName, Message::Priority priority):
|
||||
LogIOS(Logger::get(loggerName), priority),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogStream::~LogStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::fatal()
|
||||
{
|
||||
return priority(Message::PRIO_FATAL);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::fatal(const std::string& message)
|
||||
{
|
||||
_buf.logger().fatal(message);
|
||||
return priority(Message::PRIO_FATAL);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::critical()
|
||||
{
|
||||
return priority(Message::PRIO_CRITICAL);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::critical(const std::string& message)
|
||||
{
|
||||
_buf.logger().critical(message);
|
||||
return priority(Message::PRIO_CRITICAL);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::error()
|
||||
{
|
||||
return priority(Message::PRIO_ERROR);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::error(const std::string& message)
|
||||
{
|
||||
_buf.logger().error(message);
|
||||
return priority(Message::PRIO_ERROR);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::warning()
|
||||
{
|
||||
return priority(Message::PRIO_WARNING);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::warning(const std::string& message)
|
||||
{
|
||||
_buf.logger().warning(message);
|
||||
return priority(Message::PRIO_WARNING);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::notice()
|
||||
{
|
||||
return priority(Message::PRIO_NOTICE);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::notice(const std::string& message)
|
||||
{
|
||||
_buf.logger().notice(message);
|
||||
return priority(Message::PRIO_NOTICE);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::information()
|
||||
{
|
||||
return priority(Message::PRIO_INFORMATION);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::information(const std::string& message)
|
||||
{
|
||||
_buf.logger().information(message);
|
||||
return priority(Message::PRIO_INFORMATION);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::debug()
|
||||
{
|
||||
return priority(Message::PRIO_DEBUG);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::debug(const std::string& message)
|
||||
{
|
||||
_buf.logger().debug(message);
|
||||
return priority(Message::PRIO_DEBUG);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::trace()
|
||||
{
|
||||
return priority(Message::PRIO_TRACE);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::trace(const std::string& message)
|
||||
{
|
||||
_buf.logger().trace(message);
|
||||
return priority(Message::PRIO_TRACE);
|
||||
}
|
||||
|
||||
|
||||
LogStream& LogStream::priority(Message::Priority priority)
|
||||
{
|
||||
_buf.setPriority(priority);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,486 +0,0 @@
|
||||
//
|
||||
// Logger.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Logger.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Logger
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Logger.h"
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/LoggingRegistry.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Logger::LoggerMap* Logger::_pLoggerMap = 0;
|
||||
Mutex Logger::_mapMtx;
|
||||
const std::string Logger::ROOT;
|
||||
|
||||
|
||||
Logger::Logger(const std::string& name, Channel* pChannel, int level): _name(name), _pChannel(pChannel), _level(level)
|
||||
{
|
||||
if (pChannel) pChannel->duplicate();
|
||||
}
|
||||
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
if (_pChannel) _pChannel->release();
|
||||
}
|
||||
|
||||
|
||||
void Logger::setChannel(Channel* pChannel)
|
||||
{
|
||||
if (_pChannel) _pChannel->release();
|
||||
_pChannel = pChannel;
|
||||
if (_pChannel) _pChannel->duplicate();
|
||||
}
|
||||
|
||||
|
||||
Channel* Logger::getChannel() const
|
||||
{
|
||||
return _pChannel;
|
||||
}
|
||||
|
||||
|
||||
void Logger::setLevel(int level)
|
||||
{
|
||||
_level = level;
|
||||
}
|
||||
|
||||
|
||||
void Logger::setLevel(const std::string& level)
|
||||
{
|
||||
setLevel(parseLevel(level));
|
||||
}
|
||||
|
||||
|
||||
void Logger::setProperty(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (name == "channel")
|
||||
setChannel(LoggingRegistry::defaultRegistry().channelForName(value));
|
||||
else if (name == "level")
|
||||
setLevel(value);
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
void Logger::log(const Message& msg)
|
||||
{
|
||||
if (_level >= msg.getPriority() && _pChannel)
|
||||
{
|
||||
_pChannel->log(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::log(const Exception& exc)
|
||||
{
|
||||
error(exc.displayText());
|
||||
}
|
||||
|
||||
|
||||
void Logger::log(const Exception& exc, const char* file, int line)
|
||||
{
|
||||
error(exc.displayText(), file, line);
|
||||
}
|
||||
|
||||
|
||||
void Logger::dump(const std::string& msg, const void* buffer, std::size_t length, Message::Priority prio)
|
||||
{
|
||||
if (_level >= prio && _pChannel)
|
||||
{
|
||||
std::string text(msg);
|
||||
formatDump(text, buffer, length);
|
||||
_pChannel->log(Message(_name, text, prio));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::setLevel(const std::string& name, int level)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
std::string::size_type len = name.length();
|
||||
for (LoggerMap::iterator it = _pLoggerMap->begin(); it != _pLoggerMap->end(); ++it)
|
||||
{
|
||||
if (len == 0 ||
|
||||
(it->first.compare(0, len, name) == 0 && (it->first.length() == len || it->first[len] == '.')))
|
||||
{
|
||||
it->second->setLevel(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::setChannel(const std::string& name, Channel* pChannel)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
std::string::size_type len = name.length();
|
||||
for (LoggerMap::iterator it = _pLoggerMap->begin(); it != _pLoggerMap->end(); ++it)
|
||||
{
|
||||
if (len == 0 ||
|
||||
(it->first.compare(0, len, name) == 0 && (it->first.length() == len || it->first[len] == '.')))
|
||||
{
|
||||
it->second->setChannel(pChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::setProperty(const std::string& loggerName, const std::string& propertyName, const std::string& value)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
std::string::size_type len = loggerName.length();
|
||||
for (LoggerMap::iterator it = _pLoggerMap->begin(); it != _pLoggerMap->end(); ++it)
|
||||
{
|
||||
if (len == 0 ||
|
||||
(it->first.compare(0, len, loggerName) == 0 && (it->first.length() == len || it->first[len] == '.')))
|
||||
{
|
||||
it->second->setProperty(propertyName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string Logger::format(const std::string& fmt, const std::string& arg)
|
||||
{
|
||||
std::string args[] =
|
||||
{
|
||||
arg
|
||||
};
|
||||
return format(fmt, 1, args);
|
||||
}
|
||||
|
||||
|
||||
std::string Logger::format(const std::string& fmt, const std::string& arg0, const std::string& arg1)
|
||||
{
|
||||
std::string args[] =
|
||||
{
|
||||
arg0,
|
||||
arg1
|
||||
};
|
||||
return format(fmt, 2, args);
|
||||
}
|
||||
|
||||
|
||||
std::string Logger::format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2)
|
||||
{
|
||||
std::string args[] =
|
||||
{
|
||||
arg0,
|
||||
arg1,
|
||||
arg2
|
||||
};
|
||||
return format(fmt, 3, args);
|
||||
}
|
||||
|
||||
|
||||
std::string Logger::format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2, const std::string& arg3)
|
||||
{
|
||||
std::string args[] =
|
||||
{
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3
|
||||
};
|
||||
return format(fmt, 4, args);
|
||||
}
|
||||
|
||||
|
||||
std::string Logger::format(const std::string& fmt, int argc, std::string argv[])
|
||||
{
|
||||
std::string result;
|
||||
std::string::const_iterator it = fmt.begin();
|
||||
while (it != fmt.end())
|
||||
{
|
||||
if (*it == '$')
|
||||
{
|
||||
++it;
|
||||
if (*it == '$')
|
||||
{
|
||||
result += '$';
|
||||
}
|
||||
else if (*it >= '0' && *it <= '9')
|
||||
{
|
||||
int i = *it - '0';
|
||||
if (i < argc)
|
||||
result += argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
result += '$';
|
||||
result += *it;
|
||||
}
|
||||
}
|
||||
else result += *it;
|
||||
++it;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Logger::formatDump(std::string& message, const void* buffer, std::size_t length)
|
||||
{
|
||||
const int BYTES_PER_LINE = 16;
|
||||
|
||||
message.reserve(message.size() + length*6);
|
||||
if (!message.empty()) message.append("\n");
|
||||
unsigned char* base = (unsigned char*) buffer;
|
||||
int addr = 0;
|
||||
while (addr < length)
|
||||
{
|
||||
if (addr > 0) message.append("\n");
|
||||
message.append(NumberFormatter::formatHex(addr, 4));
|
||||
message.append(" ");
|
||||
int offset = 0;
|
||||
while (addr + offset < length && offset < BYTES_PER_LINE)
|
||||
{
|
||||
message.append(NumberFormatter::formatHex(base[addr + offset], 2));
|
||||
message.append(offset == 7 ? " " : " ");
|
||||
++offset;
|
||||
}
|
||||
if (offset < 7) message.append(" ");
|
||||
while (offset < BYTES_PER_LINE) { message.append(" "); ++offset; }
|
||||
message.append(" ");
|
||||
offset = 0;
|
||||
while (addr + offset < length && offset < BYTES_PER_LINE)
|
||||
{
|
||||
unsigned char c = base[addr + offset];
|
||||
message += (c >= 32 && c < 127) ? (char) c : '.';
|
||||
++offset;
|
||||
}
|
||||
addr += BYTES_PER_LINE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Logger& Logger::get(const std::string& name)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
return unsafeGet(name);
|
||||
}
|
||||
|
||||
|
||||
Logger& Logger::unsafeGet(const std::string& name)
|
||||
{
|
||||
Logger* pLogger = find(name);
|
||||
if (!pLogger)
|
||||
{
|
||||
if (name == ROOT)
|
||||
{
|
||||
pLogger = new Logger(name, 0, Message::PRIO_INFORMATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger& par = parent(name);
|
||||
pLogger = new Logger(name, par.getChannel(), par.getLevel());
|
||||
}
|
||||
add(pLogger);
|
||||
}
|
||||
return *pLogger;
|
||||
}
|
||||
|
||||
|
||||
Logger& Logger::create(const std::string& name, Channel* pChannel, int level)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (find(name)) throw ExistsException();
|
||||
Logger* pLogger = new Logger(name, pChannel, level);
|
||||
add(pLogger);
|
||||
return *pLogger;
|
||||
}
|
||||
|
||||
|
||||
Logger& Logger::root()
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
return unsafeGet(ROOT);
|
||||
}
|
||||
|
||||
|
||||
Logger* Logger::has(const std::string& name)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
return find(name);
|
||||
}
|
||||
|
||||
|
||||
void Logger::shutdown()
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
for (LoggerMap::iterator it = _pLoggerMap->begin(); it != _pLoggerMap->end(); ++it)
|
||||
{
|
||||
it->second->release();
|
||||
}
|
||||
delete _pLoggerMap;
|
||||
_pLoggerMap = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Logger* Logger::find(const std::string& name)
|
||||
{
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
LoggerMap::iterator it = _pLoggerMap->find(name);
|
||||
if (it != _pLoggerMap->end())
|
||||
return it->second;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Logger::destroy(const std::string& name)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
LoggerMap::iterator it = _pLoggerMap->find(name);
|
||||
if (it != _pLoggerMap->end())
|
||||
{
|
||||
it->second->release();
|
||||
_pLoggerMap->erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Logger::names(std::vector<std::string>& names)
|
||||
{
|
||||
Mutex::ScopedLock lock(_mapMtx);
|
||||
|
||||
names.clear();
|
||||
if (_pLoggerMap)
|
||||
{
|
||||
for (LoggerMap::const_iterator it = _pLoggerMap->begin(); it != _pLoggerMap->end(); ++it)
|
||||
{
|
||||
names.push_back(it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Logger& Logger::parent(const std::string& name)
|
||||
{
|
||||
std::string::size_type pos = name.rfind('.');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
std::string pname = name.substr(0, pos);
|
||||
Logger* pParent = find(pname);
|
||||
if (pParent)
|
||||
return *pParent;
|
||||
else
|
||||
return parent(pname);
|
||||
}
|
||||
else return unsafeGet(ROOT);
|
||||
}
|
||||
|
||||
|
||||
int Logger::parseLevel(const std::string& level)
|
||||
{
|
||||
if (icompare(level, "none") == 0)
|
||||
return 0;
|
||||
else if (icompare(level, "fatal") == 0)
|
||||
return Message::PRIO_FATAL;
|
||||
else if (icompare(level, "critical") == 0)
|
||||
return Message::PRIO_CRITICAL;
|
||||
else if (icompare(level, "error") == 0)
|
||||
return Message::PRIO_ERROR;
|
||||
else if (icompare(level, "warning") == 0)
|
||||
return Message::PRIO_WARNING;
|
||||
else if (icompare(level, "notice") == 0)
|
||||
return Message::PRIO_NOTICE;
|
||||
else if (icompare(level, "information") == 0)
|
||||
return Message::PRIO_INFORMATION;
|
||||
else if (icompare(level, "debug") == 0)
|
||||
return Message::PRIO_DEBUG;
|
||||
else if (icompare(level, "trace") == 0)
|
||||
return Message::PRIO_TRACE;
|
||||
else
|
||||
throw InvalidArgumentException("Not a valid log level", level);
|
||||
}
|
||||
|
||||
|
||||
class AutoLoggerShutdown
|
||||
{
|
||||
public:
|
||||
AutoLoggerShutdown()
|
||||
{
|
||||
}
|
||||
~AutoLoggerShutdown()
|
||||
{
|
||||
Logger::shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static AutoLoggerShutdown als;
|
||||
}
|
||||
|
||||
|
||||
void Logger::add(Logger* pLogger)
|
||||
{
|
||||
if (!_pLoggerMap)
|
||||
_pLoggerMap = new LoggerMap;
|
||||
_pLoggerMap->insert(LoggerMap::value_type(pLogger->name(), pLogger));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,141 +0,0 @@
|
||||
//
|
||||
// LoggingFactory.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LoggingFactory.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LoggingFactory
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LoggingFactory.h"
|
||||
#include "Poco/SingletonHolder.h"
|
||||
#include "Poco/AsyncChannel.h"
|
||||
#include "Poco/ConsoleChannel.h"
|
||||
#include "Poco/FileChannel.h"
|
||||
#include "Poco/FormattingChannel.h"
|
||||
#include "Poco/SplitterChannel.h"
|
||||
#include "Poco/NullChannel.h"
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "Poco/SyslogChannel.h"
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_VMS)
|
||||
#include "Poco/OpcomChannel.h"
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
|
||||
#include "Poco/EventLogChannel.h"
|
||||
#include "Poco/WindowsConsoleChannel.h"
|
||||
#endif
|
||||
#include "Poco/PatternFormatter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LoggingFactory::LoggingFactory()
|
||||
{
|
||||
registerBuiltins();
|
||||
}
|
||||
|
||||
|
||||
LoggingFactory::~LoggingFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void LoggingFactory::registerChannelClass(const std::string& className, ChannelInstantiator* pFactory)
|
||||
{
|
||||
_channelFactory.registerClass(className, pFactory);
|
||||
}
|
||||
|
||||
|
||||
void LoggingFactory::registerFormatterClass(const std::string& className, FormatterFactory* pFactory)
|
||||
{
|
||||
_formatterFactory.registerClass(className, pFactory);
|
||||
}
|
||||
|
||||
|
||||
Channel* LoggingFactory::createChannel(const std::string& className) const
|
||||
{
|
||||
return _channelFactory.createInstance(className);
|
||||
}
|
||||
|
||||
|
||||
Formatter* LoggingFactory::createFormatter(const std::string& className) const
|
||||
{
|
||||
return _formatterFactory.createInstance(className);
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static SingletonHolder<LoggingFactory> sh;
|
||||
}
|
||||
|
||||
|
||||
LoggingFactory& LoggingFactory::defaultFactory()
|
||||
{
|
||||
return *sh.get();
|
||||
}
|
||||
|
||||
|
||||
void LoggingFactory::registerBuiltins()
|
||||
{
|
||||
_channelFactory.registerClass("AsyncChannel", new Instantiator<AsyncChannel, Channel>);
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
|
||||
_channelFactory.registerClass("ConsoleChannel", new Instantiator<WindowsConsoleChannel, Channel>);
|
||||
#else
|
||||
_channelFactory.registerClass("ConsoleChannel", new Instantiator<ConsoleChannel, Channel>);
|
||||
#endif
|
||||
#ifndef POCO_NO_FILECHANNEL
|
||||
_channelFactory.registerClass("FileChannel", new Instantiator<FileChannel, Channel>);
|
||||
#endif
|
||||
_channelFactory.registerClass("FormattingChannel", new Instantiator<FormattingChannel, Channel>);
|
||||
#ifndef POCO_NO_SPLITTERCHANNEL
|
||||
_channelFactory.registerClass("SplitterChannel", new Instantiator<SplitterChannel, Channel>);
|
||||
#endif
|
||||
_channelFactory.registerClass("NullChannel", new Instantiator<NullChannel, Channel>);
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#ifndef POCO_NO_SYSLOGCHANNEL
|
||||
_channelFactory.registerClass("SyslogChannel", new Instantiator<SyslogChannel, Channel>);
|
||||
#endif
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_VMS)
|
||||
_channelFactory.registerClass("OpcomChannel", new Instantiator<OpcomChannel, Channel>);
|
||||
#endif
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
|
||||
_channelFactory.registerClass("EventLogChannel", new Instantiator<EventLogChannel, Channel>);
|
||||
#endif
|
||||
|
||||
_formatterFactory.registerClass("PatternFormatter", new Instantiator<PatternFormatter, Formatter>);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,139 +0,0 @@
|
||||
//
|
||||
// LoggingRegistry.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/LoggingRegistry.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: LoggingRegistry
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/LoggingRegistry.h"
|
||||
#include "Poco/SingletonHolder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
LoggingRegistry::LoggingRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
LoggingRegistry::~LoggingRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Channel* LoggingRegistry::channelForName(const std::string& name) const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
ChannelMap::const_iterator it = _channelMap.find(name);
|
||||
if (it != _channelMap.end())
|
||||
return const_cast<Channel*>(it->second.get());
|
||||
else
|
||||
throw NotFoundException("logging channel", name);
|
||||
}
|
||||
|
||||
|
||||
Formatter* LoggingRegistry::formatterForName(const std::string& name) const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
FormatterMap::const_iterator it = _formatterMap.find(name);
|
||||
if (it != _formatterMap.end())
|
||||
return const_cast<Formatter*>(it->second.get());
|
||||
else
|
||||
throw NotFoundException("logging formatter", name);
|
||||
}
|
||||
|
||||
|
||||
void LoggingRegistry::registerChannel(const std::string& name, Channel* pChannel)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_channelMap[name] = ChannelPtr(pChannel, true);
|
||||
}
|
||||
|
||||
|
||||
void LoggingRegistry::registerFormatter(const std::string& name, Formatter* pFormatter)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_formatterMap[name] = FormatterPtr(pFormatter, true);
|
||||
}
|
||||
|
||||
|
||||
void LoggingRegistry::unregisterChannel(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
ChannelMap::iterator it = _channelMap.find(name);
|
||||
if (it != _channelMap.end())
|
||||
_channelMap.erase(it);
|
||||
else
|
||||
throw NotFoundException("logging channel", name);
|
||||
}
|
||||
|
||||
|
||||
void LoggingRegistry::unregisterFormatter(const std::string& name)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
FormatterMap::iterator it = _formatterMap.find(name);
|
||||
if (it != _formatterMap.end())
|
||||
_formatterMap.erase(it);
|
||||
else
|
||||
throw NotFoundException("logging formatter", name);
|
||||
}
|
||||
|
||||
|
||||
void LoggingRegistry::clear()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_channelMap.clear();
|
||||
_formatterMap.clear();
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static SingletonHolder<LoggingRegistry> sh;
|
||||
}
|
||||
|
||||
|
||||
LoggingRegistry& LoggingRegistry::defaultRegistry()
|
||||
{
|
||||
return *sh.get();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,300 +0,0 @@
|
||||
//
|
||||
// MD4Engine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/MD4Engine.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Crypt
|
||||
// Module: MD4Engine
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//
|
||||
// MD4 (RFC 1320) algorithm:
|
||||
// Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
// rights reserved.
|
||||
//
|
||||
// License to copy and use this software is granted provided that it
|
||||
// is identified as the "RSA Data Security, Inc. MD4 Message-Digest
|
||||
// Algorithm" in all material mentioning or referencing this software
|
||||
// or this function.
|
||||
//
|
||||
// License is also granted to make and use derivative works provided
|
||||
// that such works are identified as "derived from the RSA Data
|
||||
// Security, Inc. MD4 Message-Digest Algorithm" in all material
|
||||
// mentioning or referencing the derived work.
|
||||
//
|
||||
// RSA Data Security, Inc. makes no representations concerning either
|
||||
// the merchantability of this software or the suitability of this
|
||||
// software for any particular purpose. It is provided "as is"
|
||||
// without express or implied warranty of any kind.
|
||||
//
|
||||
// These notices must be retained in any copies of any part of this
|
||||
// documentation and/or software.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/MD4Engine.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MD4Engine::MD4Engine()
|
||||
{
|
||||
_digest.reserve(16);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
MD4Engine::~MD4Engine()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void MD4Engine::updateImpl(const void* input_, unsigned inputLen)
|
||||
{
|
||||
const unsigned char* input = (const unsigned char*) input_;
|
||||
unsigned int i, index, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
index = (unsigned int)((_context.count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((_context.count[0] += ((UInt32) inputLen << 3)) < ((UInt32) inputLen << 3))
|
||||
_context.count[1]++;
|
||||
_context.count[1] += ((UInt32) inputLen >> 29);
|
||||
|
||||
partLen = 64 - index;
|
||||
|
||||
/* Transform as many times as possible. */
|
||||
if (inputLen >= partLen)
|
||||
{
|
||||
std::memcpy(&_context.buffer[index], input, partLen);
|
||||
transform(_context.state, _context.buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
transform(_context.state, &input[i]);
|
||||
|
||||
index = 0;
|
||||
}
|
||||
else i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
std::memcpy(&_context.buffer[index], &input[i], inputLen-i);
|
||||
}
|
||||
|
||||
|
||||
unsigned MD4Engine::digestLength() const
|
||||
{
|
||||
return DIGEST_SIZE;
|
||||
}
|
||||
|
||||
|
||||
void MD4Engine::reset()
|
||||
{
|
||||
std::memset(&_context, 0, sizeof(_context));
|
||||
_context.count[0] = _context.count[1] = 0;
|
||||
_context.state[0] = 0x67452301;
|
||||
_context.state[1] = 0xefcdab89;
|
||||
_context.state[2] = 0x98badcfe;
|
||||
_context.state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
|
||||
const DigestEngine::Digest& MD4Engine::digest()
|
||||
{
|
||||
static const unsigned char PADDING[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
unsigned char bits[8];
|
||||
unsigned int index, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
encode(bits, _context.count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64. */
|
||||
index = (unsigned int)((_context.count[0] >> 3) & 0x3f);
|
||||
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||
update(PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
update(bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
unsigned char digest[16];
|
||||
encode(digest, _context.state, 16);
|
||||
_digest.clear();
|
||||
_digest.insert(_digest.begin(), digest, digest + sizeof(digest));
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
std::memset(&_context, 0, sizeof (_context));
|
||||
reset();
|
||||
return _digest;
|
||||
}
|
||||
|
||||
|
||||
/* Constants for MD4Transform routine. */
|
||||
#define S11 3
|
||||
#define S12 7
|
||||
#define S13 11
|
||||
#define S14 19
|
||||
#define S21 3
|
||||
#define S22 5
|
||||
#define S23 9
|
||||
#define S24 13
|
||||
#define S31 3
|
||||
#define S32 9
|
||||
#define S33 11
|
||||
#define S34 15
|
||||
|
||||
|
||||
/* F, G and H are basic MD4 functions. */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits. */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
|
||||
/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
#define FF(a, b, c, d, x, s) { \
|
||||
(a) += F ((b), (c), (d)) + (x); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UInt32)0x5a827999; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UInt32)0x6ed9eba1; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
|
||||
|
||||
void MD4Engine::transform (UInt32 state[4], const unsigned char block[64])
|
||||
{
|
||||
UInt32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
decode(x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 0], S21); /* 17 */
|
||||
GG (d, a, b, c, x[ 4], S22); /* 18 */
|
||||
GG (c, d, a, b, x[ 8], S23); /* 19 */
|
||||
GG (b, c, d, a, x[12], S24); /* 20 */
|
||||
GG (a, b, c, d, x[ 1], S21); /* 21 */
|
||||
GG (d, a, b, c, x[ 5], S22); /* 22 */
|
||||
GG (c, d, a, b, x[ 9], S23); /* 23 */
|
||||
GG (b, c, d, a, x[13], S24); /* 24 */
|
||||
GG (a, b, c, d, x[ 2], S21); /* 25 */
|
||||
GG (d, a, b, c, x[ 6], S22); /* 26 */
|
||||
GG (c, d, a, b, x[10], S23); /* 27 */
|
||||
GG (b, c, d, a, x[14], S24); /* 28 */
|
||||
GG (a, b, c, d, x[ 3], S21); /* 29 */
|
||||
GG (d, a, b, c, x[ 7], S22); /* 30 */
|
||||
GG (c, d, a, b, x[11], S23); /* 31 */
|
||||
GG (b, c, d, a, x[15], S24); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 0], S31); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32); /* 34 */
|
||||
HH (c, d, a, b, x[ 4], S33); /* 35 */
|
||||
HH (b, c, d, a, x[12], S34); /* 36 */
|
||||
HH (a, b, c, d, x[ 2], S31); /* 37 */
|
||||
HH (d, a, b, c, x[10], S32); /* 38 */
|
||||
HH (c, d, a, b, x[ 6], S33); /* 39 */
|
||||
HH (b, c, d, a, x[14], S34); /* 40 */
|
||||
HH (a, b, c, d, x[ 1], S31); /* 41 */
|
||||
HH (d, a, b, c, x[ 9], S32); /* 42 */
|
||||
HH (c, d, a, b, x[ 5], S33); /* 43 */
|
||||
HH (b, c, d, a, x[13], S34); /* 44 */
|
||||
HH (a, b, c, d, x[ 3], S31); /* 45 */
|
||||
HH (d, a, b, c, x[11], S32); /* 46 */
|
||||
HH (c, d, a, b, x[ 7], S33); /* 47 */
|
||||
HH (b, c, d, a, x[15], S34); /* 48 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
std::memset(x, 0, sizeof(x));
|
||||
}
|
||||
|
||||
|
||||
void MD4Engine::encode(unsigned char* output, const UInt32* input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
{
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MD4Engine::decode(UInt32* output, const unsigned char* input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UInt32)input[j]) | (((UInt32)input[j+1]) << 8) |
|
||||
(((UInt32)input[j+2]) << 16) | (((UInt32)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,331 +0,0 @@
|
||||
//
|
||||
// MD5Engine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/MD5Engine.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Crypt
|
||||
// Module: MD5Engine
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//
|
||||
// MD5 (RFC 1321) algorithm:
|
||||
// Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
// rights reserved.
|
||||
//
|
||||
// License to copy and use this software is granted provided that it
|
||||
// is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
// Algorithm" in all material mentioning or referencing this software
|
||||
// or this function.
|
||||
//
|
||||
// License is also granted to make and use derivative works provided
|
||||
// that such works are identified as "derived from the RSA Data
|
||||
// Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
// mentioning or referencing the derived work.
|
||||
//
|
||||
// RSA Data Security, Inc. makes no representations concerning either
|
||||
// the merchantability of this software or the suitability of this
|
||||
// software for any particular purpose. It is provided "as is"
|
||||
// without express or implied warranty of any kind.
|
||||
//
|
||||
// These notices must be retained in any copies of any part of this
|
||||
// documentation and/or software.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/MD5Engine.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MD5Engine::MD5Engine()
|
||||
{
|
||||
_digest.reserve(16);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
MD5Engine::~MD5Engine()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void MD5Engine::updateImpl(const void* input_, unsigned inputLen)
|
||||
{
|
||||
const unsigned char* input = (const unsigned char*) input_;
|
||||
unsigned int i, index, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
index = (unsigned int)((_context.count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((_context.count[0] += ((UInt32) inputLen << 3)) < ((UInt32) inputLen << 3))
|
||||
_context.count[1]++;
|
||||
_context.count[1] += ((UInt32) inputLen >> 29);
|
||||
|
||||
partLen = 64 - index;
|
||||
|
||||
/* Transform as many times as possible. */
|
||||
if (inputLen >= partLen)
|
||||
{
|
||||
std::memcpy(&_context.buffer[index], input, partLen);
|
||||
transform(_context.state, _context.buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
transform(_context.state, &input[i]);
|
||||
|
||||
index = 0;
|
||||
}
|
||||
else i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
std::memcpy(&_context.buffer[index], &input[i],inputLen-i);
|
||||
}
|
||||
|
||||
|
||||
unsigned MD5Engine::digestLength() const
|
||||
{
|
||||
return DIGEST_SIZE;
|
||||
}
|
||||
|
||||
|
||||
void MD5Engine::reset()
|
||||
{
|
||||
std::memset(&_context, 0, sizeof(_context));
|
||||
_context.count[0] = _context.count[1] = 0;
|
||||
_context.state[0] = 0x67452301;
|
||||
_context.state[1] = 0xefcdab89;
|
||||
_context.state[2] = 0x98badcfe;
|
||||
_context.state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
|
||||
const DigestEngine::Digest& MD5Engine::digest()
|
||||
{
|
||||
static const unsigned char PADDING[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
unsigned char bits[8];
|
||||
unsigned int index, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
encode(bits, _context.count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64. */
|
||||
index = (unsigned int)((_context.count[0] >> 3) & 0x3f);
|
||||
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||
update(PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
update(bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
unsigned char digest[16];
|
||||
encode(digest, _context.state, 16);
|
||||
_digest.clear();
|
||||
_digest.insert(_digest.begin(), digest, digest + sizeof(digest));
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
std::memset(&_context, 0, sizeof (_context));
|
||||
reset();
|
||||
return _digest;
|
||||
}
|
||||
|
||||
|
||||
/* Constants for MD5Transform routine. */
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
|
||||
/* F, G, H and I are basic MD5 functions. */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits. */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
Rotation is separate from addition to prevent recomputation. */
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UInt32)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UInt32)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UInt32)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UInt32)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
|
||||
void MD5Engine::transform (UInt32 state[4], const unsigned char block[64])
|
||||
{
|
||||
UInt32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
decode(x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
std::memset(x, 0, sizeof(x));
|
||||
}
|
||||
|
||||
|
||||
void MD5Engine::encode(unsigned char* output, const UInt32* input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
{
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MD5Engine::decode(UInt32* output, const unsigned char* input, unsigned int len)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UInt32)input[j]) | (((UInt32)input[j+1]) << 8) |
|
||||
(((UInt32)input[j+2]) << 16) | (((UInt32)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
Binary file not shown.
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// Manifest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Manifest.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: SharedLibrary
|
||||
// Module: ClassLoader
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Manifest.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
ManifestBase::ManifestBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ManifestBase::~ManifestBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,104 +0,0 @@
|
||||
//
|
||||
// MemoryPool.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/MemoryPool.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
// Module: MemoryPool
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/MemoryPool.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MemoryPool::MemoryPool(std::size_t blockSize, int preAlloc, int maxAlloc):
|
||||
_blockSize(blockSize),
|
||||
_maxAlloc(maxAlloc),
|
||||
_allocated(preAlloc)
|
||||
{
|
||||
poco_assert (maxAlloc == 0 || maxAlloc >= preAlloc);
|
||||
poco_assert (preAlloc >= 0 && maxAlloc >= 0);
|
||||
|
||||
int r = BLOCK_RESERVE;
|
||||
if (preAlloc > r)
|
||||
r = preAlloc;
|
||||
if (maxAlloc > 0 && maxAlloc < r)
|
||||
r = maxAlloc;
|
||||
_blocks.reserve(r);
|
||||
for (int i = 0; i < preAlloc; ++i)
|
||||
{
|
||||
_blocks.push_back(new char[_blockSize]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MemoryPool::~MemoryPool()
|
||||
{
|
||||
for (BlockVec::iterator it = _blocks.begin(); it != _blocks.end(); ++it)
|
||||
{
|
||||
delete [] *it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void* MemoryPool::get()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_blocks.empty())
|
||||
{
|
||||
if (_maxAlloc == 0 || _allocated < _maxAlloc)
|
||||
{
|
||||
++_allocated;
|
||||
return new char[_blockSize];
|
||||
}
|
||||
else throw OutOfMemoryException("MemoryPool exhausted");
|
||||
}
|
||||
else
|
||||
{
|
||||
char* ptr = _blocks.back();
|
||||
_blocks.pop_back();
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MemoryPool::release(void* ptr)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_blocks.push_back(reinterpret_cast<char*>(ptr));
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// MemoryStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/MemoryStream.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: MemoryStream
|
||||
//
|
||||
// Copyright (c) 2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/MemoryStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MemoryIOS::MemoryIOS(char* pBuffer, std::streamsize bufferSize):
|
||||
_buf(pBuffer, bufferSize)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
MemoryIOS::~MemoryIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MemoryInputStream::MemoryInputStream(const char* pBuffer, std::streamsize bufferSize):
|
||||
MemoryIOS(const_cast<char*>(pBuffer), bufferSize),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MemoryInputStream::~MemoryInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MemoryOutputStream::MemoryOutputStream(char* pBuffer, std::streamsize bufferSize):
|
||||
MemoryIOS(pBuffer, bufferSize),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MemoryOutputStream::~MemoryOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,243 +0,0 @@
|
||||
//
|
||||
// Message.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Message.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Logging
|
||||
// Module: Message
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if !defined(POCO_VXWORKS)
|
||||
#include "Poco/Process.h"
|
||||
#endif
|
||||
#include "Poco/Thread.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Message::Message():
|
||||
_prio(PRIO_FATAL),
|
||||
_tid(0),
|
||||
_pid(0),
|
||||
_file(0),
|
||||
_line(0),
|
||||
_pMap(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Message::Message(const std::string& source, const std::string& text, Priority prio):
|
||||
_source(source),
|
||||
_text(text),
|
||||
_prio(prio),
|
||||
_tid(0),
|
||||
_pid(0),
|
||||
_file(0),
|
||||
_line(0),
|
||||
_pMap(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Message::Message(const std::string& source, const std::string& text, Priority prio, const char* file, int line):
|
||||
_source(source),
|
||||
_text(text),
|
||||
_prio(prio),
|
||||
_tid(0),
|
||||
_pid(0),
|
||||
_file(file),
|
||||
_line(line),
|
||||
_pMap(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Message::Message(const Message& msg):
|
||||
_source(msg._source),
|
||||
_text(msg._text),
|
||||
_prio(msg._prio),
|
||||
_time(msg._time),
|
||||
_tid(msg._tid),
|
||||
_thread(msg._thread),
|
||||
_pid(msg._pid),
|
||||
_file(msg._file),
|
||||
_line(msg._line)
|
||||
{
|
||||
if (msg._pMap)
|
||||
_pMap = new StringMap(*msg._pMap);
|
||||
else
|
||||
_pMap = 0;
|
||||
}
|
||||
|
||||
|
||||
Message::Message(const Message& msg, const std::string& text):
|
||||
_source(msg._source),
|
||||
_text(text),
|
||||
_prio(msg._prio),
|
||||
_time(msg._time),
|
||||
_tid(msg._tid),
|
||||
_thread(msg._thread),
|
||||
_pid(msg._pid),
|
||||
_file(msg._file),
|
||||
_line(msg._line)
|
||||
{
|
||||
if (msg._pMap)
|
||||
_pMap = new StringMap(*msg._pMap);
|
||||
else
|
||||
_pMap = 0;
|
||||
}
|
||||
|
||||
|
||||
Message::~Message()
|
||||
{
|
||||
delete _pMap;
|
||||
}
|
||||
|
||||
|
||||
void Message::init()
|
||||
{
|
||||
#if !defined(POCO_VXWORKS)
|
||||
_pid = Process::id();
|
||||
#endif
|
||||
Thread* pThread = Thread::current();
|
||||
if (pThread)
|
||||
{
|
||||
_tid = pThread->id();
|
||||
_thread = pThread->name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Message& Message::operator = (const Message& msg)
|
||||
{
|
||||
if (&msg != this)
|
||||
{
|
||||
Message tmp(msg);
|
||||
swap(tmp);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Message::swap(Message& msg)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_source, msg._source);
|
||||
swap(_text, msg._text);
|
||||
swap(_prio, msg._prio);
|
||||
swap(_time, msg._time);
|
||||
swap(_tid, msg._tid);
|
||||
swap(_thread, msg._thread);
|
||||
swap(_pid, msg._pid);
|
||||
swap(_file, msg._file);
|
||||
swap(_line, msg._line);
|
||||
swap(_pMap, msg._pMap);
|
||||
}
|
||||
|
||||
|
||||
void Message::setSource(const std::string& src)
|
||||
{
|
||||
_source = src;
|
||||
}
|
||||
|
||||
|
||||
void Message::setText(const std::string& text)
|
||||
{
|
||||
_text = text;
|
||||
}
|
||||
|
||||
|
||||
void Message::setPriority(Priority prio)
|
||||
{
|
||||
_prio = prio;
|
||||
}
|
||||
|
||||
|
||||
void Message::setTime(const Timestamp& t)
|
||||
{
|
||||
_time = t;
|
||||
}
|
||||
|
||||
|
||||
void Message::setThread(const std::string& thread)
|
||||
{
|
||||
_thread = thread;
|
||||
}
|
||||
|
||||
|
||||
void Message::setTid(long tid)
|
||||
{
|
||||
_tid = tid;
|
||||
}
|
||||
|
||||
|
||||
void Message::setPid(long pid)
|
||||
{
|
||||
_pid = pid;
|
||||
}
|
||||
|
||||
|
||||
void Message::setSourceFile(const char* file)
|
||||
{
|
||||
_file = file;
|
||||
}
|
||||
|
||||
|
||||
void Message::setSourceLine(int line)
|
||||
{
|
||||
_line = line;
|
||||
}
|
||||
|
||||
|
||||
const std::string& Message::operator [] (const std::string& param) const
|
||||
{
|
||||
if (_pMap)
|
||||
return (*_pMap)[param];
|
||||
else
|
||||
throw NotFoundException();
|
||||
}
|
||||
|
||||
|
||||
std::string& Message::operator [] (const std::string& param)
|
||||
{
|
||||
if (!_pMap)
|
||||
_pMap = new StringMap;
|
||||
return (*_pMap)[param];
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,76 +0,0 @@
|
||||
//
|
||||
// Mutex.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Mutex.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "Mutex_WINCE.cpp"
|
||||
#else
|
||||
#include "Mutex_WIN32.cpp"
|
||||
#endif
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#include "Mutex_VX.cpp"
|
||||
#else
|
||||
#include "Mutex_POSIX.cpp"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FastMutex::FastMutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FastMutex::~FastMutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,178 +0,0 @@
|
||||
//
|
||||
// Mutex_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Mutex_POSIX.cpp#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex_POSIX.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#if !defined(POCO_NO_SYS_SELECT_H)
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#if defined(POCO_VXWORKS)
|
||||
#include <timers.h>
|
||||
#include <cstring>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#if defined(_POSIX_TIMEOUTS) && (_POSIX_TIMEOUTS - 200112L) >= 0L
|
||||
#if defined(_POSIX_THREADS) && (_POSIX_THREADS - 200112L) >= 0L
|
||||
#if !(defined(__SUNPRO_CC))
|
||||
#define POCO_HAVE_MUTEX_TIMEOUT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
// This workaround is for VxWorks 5.x where
|
||||
// pthread_mutex_init() won't properly initialize the mutex
|
||||
// resulting in a subsequent freeze in pthread_mutex_destroy()
|
||||
// if the mutex has never been used.
|
||||
std::memset(&_mutex, 0, sizeof(_mutex));
|
||||
#endif
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
#if defined(PTHREAD_MUTEX_RECURSIVE_NP)
|
||||
pthread_mutexattr_settype_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
#elif !defined(POCO_VXWORKS)
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
#endif
|
||||
if (pthread_mutex_init(&_mutex, &attr))
|
||||
{
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
throw SystemException("cannot create mutex");
|
||||
}
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool fast)
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
// This workaround is for VxWorks 5.x where
|
||||
// pthread_mutex_init() won't properly initialize the mutex
|
||||
// resulting in a subsequent freeze in pthread_mutex_destroy()
|
||||
// if the mutex has never been used.
|
||||
std::memset(&_mutex, 0, sizeof(_mutex));
|
||||
#endif
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
#if defined(PTHREAD_MUTEX_RECURSIVE_NP)
|
||||
pthread_mutexattr_settype_np(&attr, fast ? PTHREAD_MUTEX_NORMAL_NP : PTHREAD_MUTEX_RECURSIVE_NP);
|
||||
#elif !defined(POCO_VXWORKS)
|
||||
pthread_mutexattr_settype(&attr, fast ? PTHREAD_MUTEX_NORMAL : PTHREAD_MUTEX_RECURSIVE);
|
||||
#endif
|
||||
if (pthread_mutex_init(&_mutex, &attr))
|
||||
{
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
throw SystemException("cannot create mutex");
|
||||
}
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::~MutexImpl()
|
||||
{
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl(long milliseconds)
|
||||
{
|
||||
#if defined(POCO_HAVE_MUTEX_TIMEOUT)
|
||||
struct timespec abstime;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
abstime.tv_sec = tv.tv_sec + milliseconds / 1000;
|
||||
abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
|
||||
if (abstime.tv_nsec >= 1000000000)
|
||||
{
|
||||
abstime.tv_nsec -= 1000000000;
|
||||
abstime.tv_sec++;
|
||||
}
|
||||
int rc = pthread_mutex_timedlock(&_mutex, &abstime);
|
||||
if (rc == 0)
|
||||
return true;
|
||||
else if (rc == ETIMEDOUT)
|
||||
return false;
|
||||
else
|
||||
throw SystemException("cannot lock mutex");
|
||||
#else
|
||||
const int sleepMillis = 5;
|
||||
Timestamp now;
|
||||
Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);
|
||||
do
|
||||
{
|
||||
int rc = pthread_mutex_trylock(&_mutex);
|
||||
if (rc == 0)
|
||||
return true;
|
||||
else if (rc != EBUSY)
|
||||
throw SystemException("cannot lock mutex");
|
||||
#if defined(POCO_VXWORKS)
|
||||
struct timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = sleepMillis*1000000;
|
||||
nanosleep(&ts, NULL);
|
||||
|
||||
#else
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = sleepMillis * 1000;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
#endif
|
||||
}
|
||||
while (!now.isElapsed(diff));
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
FastMutexImpl::FastMutexImpl(): MutexImpl(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FastMutexImpl::~FastMutexImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,90 +0,0 @@
|
||||
//
|
||||
// Mutex_VX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Mutex_VX.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex_VX.h"
|
||||
#include <sysLib.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl()
|
||||
{
|
||||
_sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
|
||||
if (_sem == 0)
|
||||
throw Poco::SystemException("cannot create mutex");
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::MutexImpl(bool fast)
|
||||
{
|
||||
if (fast)
|
||||
{
|
||||
_sem = semBCreate(SEM_Q_PRIORITY, SEM_FULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY);
|
||||
}
|
||||
if (_sem == 0)
|
||||
throw Poco::SystemException("cannot create mutex");
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::~MutexImpl()
|
||||
{
|
||||
semDelete(_sem);
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl(long milliseconds)
|
||||
{
|
||||
int ticks = milliseconds*sysClkRateGet()/1000;
|
||||
return semTake(_sem, ticks) == OK;
|
||||
}
|
||||
|
||||
|
||||
FastMutexImpl::FastMutexImpl(): MutexImpl(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FastMutexImpl::~FastMutexImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// Mutex_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Mutex_WIN32.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex_WIN32.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl()
|
||||
{
|
||||
// the fct has a boolean return value under WInnNt/2000/XP but not on Win98
|
||||
// the return only checks if the input address of &_cs was valid, so it is safe to omit it
|
||||
InitializeCriticalSectionAndSpinCount(&_cs, 4000);
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::~MutexImpl()
|
||||
{
|
||||
DeleteCriticalSection(&_cs);
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl(long milliseconds)
|
||||
{
|
||||
const int sleepMillis = 5;
|
||||
Timestamp now;
|
||||
Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TryEnterCriticalSection(&_cs) == TRUE)
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
Sleep(sleepMillis);
|
||||
}
|
||||
while (!now.isElapsed(diff));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
@@ -1,102 +0,0 @@
|
||||
//
|
||||
// Mutex_WINCE.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Mutex_WINCE.cpp#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: Mutex
|
||||
//
|
||||
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Mutex_WINCE.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
MutexImpl::MutexImpl()
|
||||
{
|
||||
_mutex = CreateMutexW(NULL, FALSE, NULL);
|
||||
if (!_mutex) throw SystemException("cannot create mutex");
|
||||
}
|
||||
|
||||
|
||||
MutexImpl::~MutexImpl()
|
||||
{
|
||||
CloseHandle(_mutex);
|
||||
}
|
||||
|
||||
|
||||
void MutexImpl::lockImpl()
|
||||
{
|
||||
switch (WaitForSingleObject(_mutex, INFINITE))
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
return;
|
||||
default:
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl()
|
||||
{
|
||||
switch (WaitForSingleObject(_mutex, 0))
|
||||
{
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
case WAIT_OBJECT_0:
|
||||
return true;
|
||||
default:
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MutexImpl::tryLockImpl(long milliseconds)
|
||||
{
|
||||
switch (WaitForSingleObject(_mutex, milliseconds + 1))
|
||||
{
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
case WAIT_OBJECT_0:
|
||||
return true;
|
||||
default:
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MutexImpl::unlockImpl()
|
||||
{
|
||||
ReleaseMutex(_mutex);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user