mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-08 12:36:43 +02:00
backport changes from 1.4.3 branch
This commit is contained in:
@@ -1,92 +1,96 @@
|
||||
//
|
||||
// Connector.cpp
|
||||
//
|
||||
//
|
||||
// Connector.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Connector.cpp#2 $
|
||||
//
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Connector
|
||||
//
|
||||
// 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/Data/SQLite/Connector.h"
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
// Package: SQLite
|
||||
// Module: Connector
|
||||
//
|
||||
// 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/Data/SQLite/Connector.h"
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string Connector::KEY("sqlite");
|
||||
|
||||
|
||||
Connector::Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Connector::~Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Connector::Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Connector::~Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> Connector::createSession(const std::string& connectionString,
|
||||
std::size_t timeout)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(connectionString, timeout));
|
||||
}
|
||||
|
||||
|
||||
void Connector::registerConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(new Connector());
|
||||
}
|
||||
|
||||
|
||||
void Connector::unregisterConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSharedCache(bool flag)
|
||||
{
|
||||
sqlite3_enable_shared_cache(flag ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSoftHeapLimit(int limit)
|
||||
{
|
||||
sqlite3_soft_heap_limit(limit);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
std::size_t timeout)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(connectionString, timeout));
|
||||
}
|
||||
|
||||
|
||||
void Connector::registerConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(new Connector());
|
||||
}
|
||||
|
||||
|
||||
void Connector::unregisterConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSharedCache(bool flag)
|
||||
{
|
||||
sqlite3_enable_shared_cache(flag ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSoftHeapLimit(int limit)
|
||||
{
|
||||
sqlite3_soft_heap_limit(limit);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
@@ -1,257 +1,262 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
|
||||
//
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// 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/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// 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/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::DateTimeParser;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
bool Extractor::extract(std::size_t pos, long& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_double(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
|
||||
if (!pBuf)
|
||||
val.clear();
|
||||
else
|
||||
val = std::string(pBuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_double(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
|
||||
if (!pBuf)
|
||||
val.clear();
|
||||
else
|
||||
val = std::string(pBuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Date& val)
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Time& val)
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
{
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
{
|
||||
std::string dt;
|
||||
extract(pos, dt);
|
||||
int tzd;
|
||||
DateTimeParser::parse(dt, val, tzd);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
std::string dt;
|
||||
extract(pos, dt);
|
||||
int tzd;
|
||||
DateTimeParser::parse(dt, val, tzd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Any& val)
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::DynamicAny& val)
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::isNull(std::size_t pos, std::size_t)
|
||||
{
|
||||
if (pos >= _nulls.size())
|
||||
_nulls.resize(pos + 1);
|
||||
|
||||
if (!_nulls[pos].first)
|
||||
{
|
||||
_nulls[pos].first = true;
|
||||
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
|
||||
}
|
||||
|
||||
return _nulls[pos].second;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
if (pos >= _nulls.size())
|
||||
_nulls.resize(pos + 1);
|
||||
|
||||
if (!_nulls[pos].first)
|
||||
{
|
||||
_nulls[pos].first = true;
|
||||
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
|
||||
}
|
||||
|
||||
return _nulls[pos].second;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
@@ -1,307 +1,311 @@
|
||||
//
|
||||
// SQLiteStatementImpl.cpp
|
||||
//
|
||||
//
|
||||
// SQLiteStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
|
||||
//
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// 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/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// 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/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
|
||||
StatementImpl(rSession),
|
||||
_pDB(pDB),
|
||||
_pStmt(0),
|
||||
_stepCalled(false),
|
||||
_nextResponse(0),
|
||||
_affectedRowCount(0),
|
||||
_canBind(false),
|
||||
_isExtracted(false),
|
||||
_canCompile(true)
|
||||
{
|
||||
_columns.resize(1);
|
||||
}
|
||||
StatementImpl(rSession),
|
||||
_pDB(pDB),
|
||||
_pStmt(0),
|
||||
_stepCalled(false),
|
||||
_nextResponse(0),
|
||||
_affectedRowCount(0),
|
||||
_canBind(false),
|
||||
_isExtracted(false),
|
||||
_canCompile(true)
|
||||
{
|
||||
_columns.resize(1);
|
||||
}
|
||||
|
||||
|
||||
SQLiteStatementImpl::~SQLiteStatementImpl()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::compileImpl()
|
||||
{
|
||||
if (!_pLeftover) _bindBegin = bindings().begin();
|
||||
|
||||
std::string statement(toString());
|
||||
sqlite3_stmt* pStmt = 0;
|
||||
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
|
||||
|
||||
if (0 == std::strlen(pSql))
|
||||
throw InvalidSQLStatementException("Empty statements are illegal");
|
||||
|
||||
int rc = SQLITE_OK;
|
||||
const char* pLeftover = 0;
|
||||
bool queryFound = false;
|
||||
|
||||
do
|
||||
{
|
||||
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
if (pStmt) sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
std::string errMsg = sqlite3_errmsg(_pDB);
|
||||
Utility::throwException(rc, errMsg);
|
||||
}
|
||||
else if (rc == SQLITE_OK && pStmt)
|
||||
{
|
||||
queryFound = true;
|
||||
}
|
||||
else if (rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
|
||||
{
|
||||
pSql = pLeftover;
|
||||
if (std::strlen(pSql) == 0)
|
||||
{
|
||||
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
|
||||
// this is valid
|
||||
queryFound = true;
|
||||
}
|
||||
}
|
||||
} while (rc == SQLITE_OK && !pStmt && !queryFound);
|
||||
|
||||
//Finalization call in clear() invalidates the pointer, so the value is remembered here.
|
||||
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
|
||||
// to compileImpl() shall return false immediately when there are no more statements left.
|
||||
std::string leftOver(pLeftover);
|
||||
trimInPlace(leftOver);
|
||||
clear();
|
||||
_pStmt = pStmt;
|
||||
if (!leftOver.empty())
|
||||
{
|
||||
_pLeftover = new std::string(leftOver);
|
||||
_canCompile = true;
|
||||
}
|
||||
else _canCompile = false;
|
||||
|
||||
_pBinder = new Binder(_pStmt);
|
||||
_pExtractor = new Extractor(_pStmt);
|
||||
|
||||
if (SQLITE_DONE == _nextResponse && _isExtracted)
|
||||
{
|
||||
//if this is not the first compile and there has already been extraction
|
||||
//during previous step, switch to the next set if there is one provided
|
||||
if (hasMoreDataSets())
|
||||
{
|
||||
activateNextDataSet();
|
||||
_isExtracted = false;
|
||||
}
|
||||
}
|
||||
|
||||
SQLiteStatementImpl::~SQLiteStatementImpl()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
int colCount = sqlite3_column_count(_pStmt);
|
||||
|
||||
if (colCount)
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
{
|
||||
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
_columns[curDataSet].push_back(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::bindImpl()
|
||||
{
|
||||
_stepCalled = false;
|
||||
_nextResponse = 0;
|
||||
if (_pStmt == 0) return;
|
||||
|
||||
sqlite3_reset(_pStmt);
|
||||
|
||||
int paramCount = sqlite3_bind_parameter_count(_pStmt);
|
||||
BindIt bindEnd = bindings().end();
|
||||
if (0 == paramCount || bindEnd == _bindBegin)
|
||||
{
|
||||
_canBind = false;
|
||||
return;
|
||||
}
|
||||
|
||||
int availableCount = 0;
|
||||
Bindings::difference_type bindCount = 0;
|
||||
Bindings::iterator it = _bindBegin;
|
||||
for (; it != bindEnd; ++it)
|
||||
{
|
||||
availableCount += (*it)->numOfColumnsHandled();
|
||||
if (availableCount <= paramCount) ++bindCount;
|
||||
else break;
|
||||
}
|
||||
|
||||
Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
|
||||
if (bindCount < remainingBindCount)
|
||||
{
|
||||
bindEnd = _bindBegin + bindCount;
|
||||
_canBind = true;
|
||||
}
|
||||
else if (bindCount > remainingBindCount)
|
||||
throw ParameterCountMismatchException();
|
||||
|
||||
if (_bindBegin != bindings().end())
|
||||
{
|
||||
_affectedRowCount = (*_bindBegin)->numOfRowsHandled();
|
||||
|
||||
void SQLiteStatementImpl::compileImpl()
|
||||
{
|
||||
if (!_pLeftover) _bindBegin = bindings().begin();
|
||||
Bindings::iterator oldBegin = _bindBegin;
|
||||
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
|
||||
{
|
||||
if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
|
||||
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
|
||||
|
||||
std::string statement(toString());
|
||||
sqlite3_stmt* pStmt = 0;
|
||||
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
|
||||
|
||||
if (0 == std::strlen(pSql))
|
||||
throw InvalidSQLStatementException("Empty statements are illegal");
|
||||
|
||||
int rc = SQLITE_OK;
|
||||
const char* pLeftover = 0;
|
||||
bool queryFound = false;
|
||||
|
||||
do
|
||||
{
|
||||
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
if (pStmt) sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
std::string errMsg = sqlite3_errmsg(_pDB);
|
||||
Utility::throwException(rc, errMsg);
|
||||
}
|
||||
else if (rc == SQLITE_OK && pStmt)
|
||||
{
|
||||
queryFound = true;
|
||||
}
|
||||
else if(rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
|
||||
{
|
||||
pSql = pLeftover;
|
||||
if (std::strlen(pSql) == 0)
|
||||
{
|
||||
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
|
||||
// this is valid
|
||||
queryFound = true;
|
||||
}
|
||||
}
|
||||
} while (rc == SQLITE_OK && !pStmt && !queryFound);
|
||||
|
||||
//Finalization call in clear() invalidates the pointer, so the value is remembered here.
|
||||
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
|
||||
// to compileImpl() shall return false immediately when there are no more statements left.
|
||||
std::string leftOver(pLeftover);
|
||||
trimInPlace(leftOver);
|
||||
clear();
|
||||
_pStmt = pStmt;
|
||||
if (!leftOver.empty())
|
||||
{
|
||||
_pLeftover = new std::string(leftOver);
|
||||
_canCompile = true;
|
||||
}
|
||||
else _canCompile = false;
|
||||
|
||||
_pBinder = new Binder(_pStmt);
|
||||
_pExtractor = new Extractor(_pStmt);
|
||||
|
||||
if (SQLITE_DONE == _nextResponse && _isExtracted)
|
||||
{
|
||||
//if this is not the first compile and there has already been extraction
|
||||
//during previous step, switch to the next set if there is one provided
|
||||
if (hasMoreDataSets())
|
||||
{
|
||||
activateNextDataSet();
|
||||
_isExtracted = false;
|
||||
}
|
||||
}
|
||||
|
||||
int colCount = sqlite3_column_count(_pStmt);
|
||||
|
||||
if (colCount)
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
{
|
||||
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
_columns[curDataSet].push_back(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::bindImpl()
|
||||
{
|
||||
_stepCalled = false;
|
||||
_nextResponse = 0;
|
||||
if (_pStmt == 0) return;
|
||||
|
||||
sqlite3_reset(_pStmt);
|
||||
|
||||
int paramCount = sqlite3_bind_parameter_count(_pStmt);
|
||||
BindIt bindEnd = bindings().end();
|
||||
if (0 == paramCount || bindEnd == _bindBegin)
|
||||
{
|
||||
_canBind = false;
|
||||
return;
|
||||
}
|
||||
|
||||
int availableCount = 0;
|
||||
Bindings::difference_type bindCount = 0;
|
||||
Bindings::iterator it = _bindBegin;
|
||||
for (; it != bindEnd; ++it)
|
||||
{
|
||||
availableCount += (*it)->numOfColumnsHandled();
|
||||
if (availableCount <= paramCount) ++bindCount;
|
||||
else break;
|
||||
}
|
||||
|
||||
Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
|
||||
if (bindCount < remainingBindCount)
|
||||
{
|
||||
bindEnd = _bindBegin + bindCount;
|
||||
_canBind = true;
|
||||
}
|
||||
else if (bindCount > remainingBindCount)
|
||||
throw ParameterCountMismatchException();
|
||||
|
||||
if (_bindBegin != bindings().end())
|
||||
{
|
||||
_affectedRowCount = (*_bindBegin)->numOfRowsHandled();
|
||||
|
||||
Bindings::iterator oldBegin = _bindBegin;
|
||||
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
|
||||
{
|
||||
if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
|
||||
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
|
||||
|
||||
(*_bindBegin)->bind(pos);
|
||||
pos += (*_bindBegin)->numOfColumnsHandled();
|
||||
}
|
||||
|
||||
if ((*oldBegin)->canBind())
|
||||
{
|
||||
//container binding will come back for more, so we must rewind
|
||||
_bindBegin = oldBegin;
|
||||
_canBind = true;
|
||||
}
|
||||
else _canBind = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::clear()
|
||||
{
|
||||
_columns[currentDataSet()].clear();
|
||||
_affectedRowCount = 0;
|
||||
|
||||
if (_pStmt)
|
||||
{
|
||||
sqlite3_finalize(_pStmt);
|
||||
_pStmt=0;
|
||||
}
|
||||
_pLeftover = 0;
|
||||
}
|
||||
|
||||
|
||||
bool SQLiteStatementImpl::hasNext()
|
||||
{
|
||||
if (_stepCalled)
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
|
||||
// _pStmt is allowed to be null for conditional SQL statements
|
||||
if (_pStmt == 0)
|
||||
{
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_stepCalled = true;
|
||||
_nextResponse = sqlite3_step(_pStmt);
|
||||
|
||||
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
|
||||
Utility::throwException(_nextResponse);
|
||||
|
||||
_pExtractor->reset();//clear the cached null indicators
|
||||
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
}
|
||||
(*_bindBegin)->bind(pos);
|
||||
pos += (*_bindBegin)->numOfColumnsHandled();
|
||||
}
|
||||
|
||||
if ((*oldBegin)->canBind())
|
||||
{
|
||||
//container binding will come back for more, so we must rewind
|
||||
_bindBegin = oldBegin;
|
||||
_canBind = true;
|
||||
}
|
||||
else _canBind = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::clear()
|
||||
{
|
||||
_columns[currentDataSet()].clear();
|
||||
_affectedRowCount = 0;
|
||||
|
||||
if (_pStmt)
|
||||
{
|
||||
sqlite3_finalize(_pStmt);
|
||||
_pStmt=0;
|
||||
}
|
||||
_pLeftover = 0;
|
||||
}
|
||||
|
||||
|
||||
bool SQLiteStatementImpl::hasNext()
|
||||
{
|
||||
if (_stepCalled)
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
|
||||
// _pStmt is allowed to be null for conditional SQL statements
|
||||
if (_pStmt == 0)
|
||||
{
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_stepCalled = true;
|
||||
_nextResponse = sqlite3_step(_pStmt);
|
||||
|
||||
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
|
||||
Utility::throwException(_nextResponse);
|
||||
|
||||
_pExtractor->reset();//clear the cached null indicators
|
||||
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
}
|
||||
|
||||
|
||||
std::size_t SQLiteStatementImpl::next()
|
||||
{
|
||||
if (SQLITE_ROW == _nextResponse)
|
||||
{
|
||||
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
|
||||
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
_isExtracted = true;
|
||||
}
|
||||
_stepCalled = false;
|
||||
}
|
||||
else if (SQLITE_DONE == _nextResponse)
|
||||
{
|
||||
throw Poco::Data::DataException("No data received");
|
||||
}
|
||||
else
|
||||
{
|
||||
int rc = _nextResponse;
|
||||
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
|
||||
return 1u;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
if (SQLITE_ROW == _nextResponse)
|
||||
{
|
||||
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
|
||||
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
_isExtracted = true;
|
||||
}
|
||||
_stepCalled = false;
|
||||
}
|
||||
else if (SQLITE_DONE == _nextResponse)
|
||||
{
|
||||
throw Poco::Data::DataException("No data received");
|
||||
}
|
||||
else
|
||||
{
|
||||
int rc = _nextResponse;
|
||||
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
|
||||
return 1u;
|
||||
}
|
||||
|
||||
|
||||
std::size_t SQLiteStatementImpl::columnsReturned() const
|
||||
{
|
||||
return (std::size_t) _columns[currentDataSet()].size();
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
return (std::size_t) _columns[currentDataSet()].size();
|
||||
}
|
||||
|
||||
|
||||
const MetaColumn& SQLiteStatementImpl::metaColumn(std::size_t pos) const
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
|
||||
return _columns[curDataSet][pos];
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
|
||||
return _columns[curDataSet][pos];
|
||||
}
|
||||
|
||||
|
||||
std::size_t SQLiteStatementImpl::affectedRowCount() const
|
||||
{
|
||||
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
{
|
||||
return _affectedRowCount ? _affectedRowCount : sqlite3_changes(_pDB);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
@@ -1,208 +1,212 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#5 $
|
||||
//
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Implementation of Utility
|
||||
//
|
||||
// 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/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Implementation of Utility
|
||||
//
|
||||
// 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/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string Utility::SQLITE_DATE_FORMAT = "%Y-%m-%d";
|
||||
const std::string Utility::SQLITE_TIME_FORMAT = "%H:%M:%S";
|
||||
Utility::TypeMap Utility::_types;
|
||||
|
||||
|
||||
Utility::TypeMap Utility::_types;
|
||||
|
||||
|
||||
Utility::Utility()
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
|
||||
if (_types.empty())
|
||||
{
|
||||
_types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BOOL", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BOOLEAN", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BIT", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("UINT8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UTINY", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UINTEGER8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("INT8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("TINY", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("INTEGER8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("UINT16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("USHORT", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("UINTEGER16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("INT16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("SHORT", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("INTEGER16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("UINT", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINT32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINTEGER32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("INT", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INT32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("UINT64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("ULONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("UINTEGER64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("INT64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("LONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("INTEGER64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("COUNTER", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("AUTOINCREMENT", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("REAL", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOA", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOAT", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUB", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUBLE", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("CHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("CLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("TEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("VARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NTEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NVARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BLOB", MetaColumn::FDT_BLOB));
|
||||
_types.insert(TypeMap::value_type("DATE", MetaColumn::FDT_DATE));
|
||||
_types.insert(TypeMap::value_type("TIME", MetaColumn::FDT_TIME));
|
||||
_types.insert(TypeMap::value_type("DATETIME", MetaColumn::FDT_TIMESTAMP));
|
||||
_types.insert(TypeMap::value_type("TIMESTAMP", MetaColumn::FDT_TIMESTAMP));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3 *pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
}
|
||||
|
||||
|
||||
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
|
||||
{
|
||||
poco_assert_dbg (pStmt);
|
||||
|
||||
static Utility u;
|
||||
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
|
||||
std::string sqliteType = pc ? pc : "";
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
sqliteType = sqliteType.substr(0, sqliteType.find_first_of(" ("));
|
||||
|
||||
TypeMap::const_iterator it = _types.find(Poco::trimInPlace(sqliteType));
|
||||
if (_types.end() == it) throw Poco::NotFoundException();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void Utility::throwException(int rc, const std::string& addErrMsg)
|
||||
{
|
||||
switch (rc)
|
||||
{
|
||||
case SQLITE_OK:
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
throw InvalidSQLStatementException(std::string("SQL error or missing database"), addErrMsg);
|
||||
case SQLITE_INTERNAL:
|
||||
throw InternalDBErrorException(std::string("An internal logic error in SQLite"), addErrMsg);
|
||||
case SQLITE_PERM:
|
||||
throw DBAccessDeniedException(std::string("Access permission denied"), addErrMsg);
|
||||
case SQLITE_ABORT:
|
||||
throw ExecutionAbortedException(std::string("Callback routine requested an abort"), addErrMsg);
|
||||
case SQLITE_BUSY:
|
||||
throw DBLockedException(std::string("The database file is locked"), addErrMsg);
|
||||
case SQLITE_LOCKED:
|
||||
throw TableLockedException(std::string("A table in the database is locked"), addErrMsg);
|
||||
case SQLITE_NOMEM:
|
||||
throw NoMemoryException(std::string("A malloc() failed"), addErrMsg);
|
||||
case SQLITE_READONLY:
|
||||
throw ReadOnlyException(std::string("Attempt to write a readonly database"), addErrMsg);
|
||||
case SQLITE_INTERRUPT:
|
||||
throw InterruptException(std::string("Operation terminated by sqlite_interrupt()"), addErrMsg);
|
||||
case SQLITE_IOERR:
|
||||
throw IOErrorException(std::string("Some kind of disk I/O error occurred"), addErrMsg);
|
||||
case SQLITE_CORRUPT:
|
||||
throw CorruptImageException(std::string("The database disk image is malformed"), addErrMsg);
|
||||
case SQLITE_NOTFOUND:
|
||||
throw TableNotFoundException(std::string("Table or record not found"), addErrMsg);
|
||||
case SQLITE_FULL:
|
||||
throw DatabaseFullException(std::string("Insertion failed because database is full"), addErrMsg);
|
||||
case SQLITE_CANTOPEN:
|
||||
throw CantOpenDBFileException(std::string("Unable to open the database file"), addErrMsg);
|
||||
case SQLITE_PROTOCOL:
|
||||
throw LockProtocolException(std::string("Database lock protocol error"), addErrMsg);
|
||||
case SQLITE_EMPTY:
|
||||
throw InternalDBErrorException(std::string("(Internal Only) Database table is empty"), addErrMsg);
|
||||
case SQLITE_SCHEMA:
|
||||
throw SchemaDiffersException(std::string("The database schema changed"), addErrMsg);
|
||||
case SQLITE_TOOBIG:
|
||||
throw RowTooBigException(std::string("Too much data for one row of a table"), addErrMsg);
|
||||
case SQLITE_CONSTRAINT:
|
||||
throw ConstraintViolationException(std::string("Abort due to constraint violation"), addErrMsg);
|
||||
case SQLITE_MISMATCH:
|
||||
throw DataTypeMismatchException(std::string("Data type mismatch"), addErrMsg);
|
||||
case SQLITE_MISUSE:
|
||||
throw InvalidLibraryUseException(std::string("Library used incorrectly"), addErrMsg);
|
||||
case SQLITE_NOLFS:
|
||||
throw OSFeaturesMissingException(std::string("Uses OS features not supported on host"), addErrMsg);
|
||||
case SQLITE_AUTH:
|
||||
throw AuthorizationDeniedException(std::string("Authorization denied"), addErrMsg);
|
||||
case SQLITE_FORMAT:
|
||||
throw CorruptImageException(std::string("Auxiliary database format error"), addErrMsg);
|
||||
case SQLITE_NOTADB:
|
||||
throw CorruptImageException(std::string("File opened that is not a database file"), addErrMsg);
|
||||
case SQLITE_RANGE:
|
||||
throw InvalidSQLStatementException(std::string("Bind Parameter out of range (Access of invalid position 0? bind starts with 1!)"), addErrMsg);
|
||||
case SQLITE_ROW:
|
||||
break; // sqlite_step() has another row ready
|
||||
case SQLITE_DONE:
|
||||
break; // sqlite_step() has finished executing
|
||||
default:
|
||||
throw SQLiteException(std::string("Unkown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
|
||||
if (_types.empty())
|
||||
{
|
||||
_types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BOOL", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BOOLEAN", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BIT", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("UINT8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UTINY", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UINTEGER8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("INT8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("TINY", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("INTEGER8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("UINT16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("USHORT", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("UINTEGER16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("INT16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("SHORT", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("INTEGER16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("UINT", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINT32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINTEGER32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("INT", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INT32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("UINT64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("ULONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("UINTEGER64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("INT64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("LONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("INTEGER64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("COUNTER", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("AUTOINCREMENT", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("REAL", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOA", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOAT", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUB", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUBLE", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("CHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("CLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("TEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("VARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NTEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NVARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BLOB", MetaColumn::FDT_BLOB));
|
||||
_types.insert(TypeMap::value_type("DATE", MetaColumn::FDT_DATE));
|
||||
_types.insert(TypeMap::value_type("TIME", MetaColumn::FDT_TIME));
|
||||
_types.insert(TypeMap::value_type("DATETIME", MetaColumn::FDT_TIMESTAMP));
|
||||
_types.insert(TypeMap::value_type("TIMESTAMP", MetaColumn::FDT_TIMESTAMP));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3 *pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
}
|
||||
|
||||
|
||||
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
|
||||
{
|
||||
poco_assert_dbg (pStmt);
|
||||
|
||||
static Utility u;
|
||||
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
|
||||
std::string sqliteType = pc ? pc : "";
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
sqliteType = sqliteType.substr(0, sqliteType.find_first_of(" ("));
|
||||
|
||||
TypeMap::const_iterator it = _types.find(Poco::trimInPlace(sqliteType));
|
||||
if (_types.end() == it) throw Poco::NotFoundException();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void Utility::throwException(int rc, const std::string& addErrMsg)
|
||||
{
|
||||
switch (rc)
|
||||
{
|
||||
case SQLITE_OK:
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
throw InvalidSQLStatementException(std::string("SQL error or missing database"), addErrMsg);
|
||||
case SQLITE_INTERNAL:
|
||||
throw InternalDBErrorException(std::string("An internal logic error in SQLite"), addErrMsg);
|
||||
case SQLITE_PERM:
|
||||
throw DBAccessDeniedException(std::string("Access permission denied"), addErrMsg);
|
||||
case SQLITE_ABORT:
|
||||
throw ExecutionAbortedException(std::string("Callback routine requested an abort"), addErrMsg);
|
||||
case SQLITE_BUSY:
|
||||
throw DBLockedException(std::string("The database file is locked"), addErrMsg);
|
||||
case SQLITE_LOCKED:
|
||||
throw TableLockedException(std::string("A table in the database is locked"), addErrMsg);
|
||||
case SQLITE_NOMEM:
|
||||
throw NoMemoryException(std::string("A malloc() failed"), addErrMsg);
|
||||
case SQLITE_READONLY:
|
||||
throw ReadOnlyException(std::string("Attempt to write a readonly database"), addErrMsg);
|
||||
case SQLITE_INTERRUPT:
|
||||
throw InterruptException(std::string("Operation terminated by sqlite_interrupt()"), addErrMsg);
|
||||
case SQLITE_IOERR:
|
||||
throw IOErrorException(std::string("Some kind of disk I/O error occurred"), addErrMsg);
|
||||
case SQLITE_CORRUPT:
|
||||
throw CorruptImageException(std::string("The database disk image is malformed"), addErrMsg);
|
||||
case SQLITE_NOTFOUND:
|
||||
throw TableNotFoundException(std::string("Table or record not found"), addErrMsg);
|
||||
case SQLITE_FULL:
|
||||
throw DatabaseFullException(std::string("Insertion failed because database is full"), addErrMsg);
|
||||
case SQLITE_CANTOPEN:
|
||||
throw CantOpenDBFileException(std::string("Unable to open the database file"), addErrMsg);
|
||||
case SQLITE_PROTOCOL:
|
||||
throw LockProtocolException(std::string("Database lock protocol error"), addErrMsg);
|
||||
case SQLITE_EMPTY:
|
||||
throw InternalDBErrorException(std::string("(Internal Only) Database table is empty"), addErrMsg);
|
||||
case SQLITE_SCHEMA:
|
||||
throw SchemaDiffersException(std::string("The database schema changed"), addErrMsg);
|
||||
case SQLITE_TOOBIG:
|
||||
throw RowTooBigException(std::string("Too much data for one row of a table"), addErrMsg);
|
||||
case SQLITE_CONSTRAINT:
|
||||
throw ConstraintViolationException(std::string("Abort due to constraint violation"), addErrMsg);
|
||||
case SQLITE_MISMATCH:
|
||||
throw DataTypeMismatchException(std::string("Data type mismatch"), addErrMsg);
|
||||
case SQLITE_MISUSE:
|
||||
throw InvalidLibraryUseException(std::string("Library used incorrectly"), addErrMsg);
|
||||
case SQLITE_NOLFS:
|
||||
throw OSFeaturesMissingException(std::string("Uses OS features not supported on host"), addErrMsg);
|
||||
case SQLITE_AUTH:
|
||||
throw AuthorizationDeniedException(std::string("Authorization denied"), addErrMsg);
|
||||
case SQLITE_FORMAT:
|
||||
throw CorruptImageException(std::string("Auxiliary database format error"), addErrMsg);
|
||||
case SQLITE_NOTADB:
|
||||
throw CorruptImageException(std::string("File opened that is not a database file"), addErrMsg);
|
||||
case SQLITE_RANGE:
|
||||
throw InvalidSQLStatementException(std::string("Bind Parameter out of range (Access of invalid position 0? bind starts with 1!)"), addErrMsg);
|
||||
case SQLITE_ROW:
|
||||
break; // sqlite_step() has another row ready
|
||||
case SQLITE_DONE:
|
||||
break; // sqlite_step() has finished executing
|
||||
default:
|
||||
throw SQLiteException(std::string("Unkown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -107,9 +107,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.7.7.1"
|
||||
#define SQLITE_VERSION_NUMBER 3007007
|
||||
#define SQLITE_SOURCE_ID "2011-06-28 17:39:05 af0d91adf497f5f36ec3813f04235a6e195a605f"
|
||||
#define SQLITE_VERSION "3.7.9"
|
||||
#define SQLITE_VERSION_NUMBER 3007009
|
||||
#define SQLITE_SOURCE_ID "2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
@@ -741,6 +741,41 @@ struct sqlite3_io_methods {
|
||||
** Applications should not call [sqlite3_file_control()] with this
|
||||
** opcode as doing so may disrupt the operation of the specialized VFSes
|
||||
** that do require it.
|
||||
**
|
||||
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
|
||||
** retry counts and intervals for certain disk I/O operations for the
|
||||
** windows [VFS] in order to work to provide robustness against
|
||||
** anti-virus programs. By default, the windows VFS will retry file read,
|
||||
** file write, and file delete operations up to 10 times, with a delay
|
||||
** of 25 milliseconds before the first retry and with the delay increasing
|
||||
** by an additional 25 milliseconds with each subsequent retry. This
|
||||
** opcode allows those to values (10 retries and 25 milliseconds of delay)
|
||||
** to be adjusted. The values are changed for all database connections
|
||||
** within the same process. The argument is a pointer to an array of two
|
||||
** integers where the first integer i the new retry count and the second
|
||||
** integer is the delay. If either integer is negative, then the setting
|
||||
** is not changed but instead the prior value of that setting is written
|
||||
** into the array entry, allowing the current retry settings to be
|
||||
** interrogated. The zDbName parameter is ignored.
|
||||
**
|
||||
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
|
||||
** persistent [WAL | Write AHead Log] setting. By default, the auxiliary
|
||||
** write ahead log and shared memory files used for transaction control
|
||||
** are automatically deleted when the latest connection to the database
|
||||
** closes. Setting persistent WAL mode causes those files to persist after
|
||||
** close. Persisting the files is useful when other processes that do not
|
||||
** have write permission on the directory containing the database file want
|
||||
** to read the database file, as the WAL and shared memory files must exist
|
||||
** in order for the database to be readable. The fourth parameter to
|
||||
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
|
||||
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
|
||||
** WAL mode. If the integer is -1, then it is overwritten with the current
|
||||
** WAL persistence setting.
|
||||
**
|
||||
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
|
||||
** a write transaction to indicate that, unless it is rolled back for some
|
||||
** reason, the entire database file will be overwritten by the current
|
||||
** transaction. This is used by VACUUM operations.
|
||||
*/
|
||||
#define SQLITE_FCNTL_LOCKSTATE 1
|
||||
#define SQLITE_GET_LOCKPROXYFILE 2
|
||||
@@ -750,7 +785,9 @@ struct sqlite3_io_methods {
|
||||
#define SQLITE_FCNTL_CHUNK_SIZE 6
|
||||
#define SQLITE_FCNTL_FILE_POINTER 7
|
||||
#define SQLITE_FCNTL_SYNC_OMITTED 8
|
||||
|
||||
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
|
||||
#define SQLITE_FCNTL_PERSIST_WAL 10
|
||||
#define SQLITE_FCNTL_OVERWRITE 11
|
||||
|
||||
/*
|
||||
** CAPI3REF: Mutex Handle
|
||||
@@ -1178,16 +1215,10 @@ SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
|
||||
** order to verify that SQLite recovers gracefully from such
|
||||
** conditions.
|
||||
**
|
||||
** The xMalloc and xFree methods must work like the
|
||||
** malloc() and free() functions from the standard C library.
|
||||
** The xRealloc method must work like realloc() from the standard C library
|
||||
** with the exception that if the second argument to xRealloc is zero,
|
||||
** xRealloc must be a no-op - it must not perform any allocation or
|
||||
** deallocation. ^SQLite guarantees that the second argument to
|
||||
** The xMalloc, xRealloc, and xFree methods must work like the
|
||||
** malloc(), realloc() and free() functions from the standard C library.
|
||||
** ^SQLite guarantees that the second argument to
|
||||
** xRealloc is always a value returned by a prior call to xRoundup.
|
||||
** And so in cases where xRoundup always returns a positive number,
|
||||
** xRealloc can perform exactly as the standard library realloc() and
|
||||
** still be in compliance with this specification.
|
||||
**
|
||||
** xSize should return the allocated size of a memory allocation
|
||||
** previously obtained from xMalloc or xRealloc. The allocated size
|
||||
@@ -1373,8 +1404,8 @@ struct sqlite3_mem_methods {
|
||||
** allocator is engaged to handle all of SQLites memory allocation needs.
|
||||
** The first pointer (the memory pointer) must be aligned to an 8-byte
|
||||
** boundary or subsequent behavior of SQLite will be undefined.
|
||||
** The minimum allocation size is capped at 2^12. Reasonable values
|
||||
** for the minimum allocation size are 2^5 through 2^8.</dd>
|
||||
** The minimum allocation size is capped at 2**12. Reasonable values
|
||||
** for the minimum allocation size are 2**5 through 2**8.</dd>
|
||||
**
|
||||
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
|
||||
** <dd> ^(This option takes a single argument which is a pointer to an
|
||||
@@ -2773,7 +2804,8 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
|
||||
** that the supplied string is nul-terminated, then there is a small
|
||||
** performance advantage to be gained by passing an nByte parameter that
|
||||
** is equal to the number of bytes in the input string <i>including</i>
|
||||
** the nul-terminator bytes.
|
||||
** the nul-terminator bytes as this saves SQLite from having to
|
||||
** make a copy of the input string.
|
||||
**
|
||||
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
|
||||
** past the end of the first SQL statement in zSql. These routines only
|
||||
@@ -2824,7 +2856,7 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
|
||||
** ^The specific value of WHERE-clause [parameter] might influence the
|
||||
** choice of query plan if the parameter is the left-hand side of a [LIKE]
|
||||
** or [GLOB] operator or if the parameter is compared to an indexed column
|
||||
** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
|
||||
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
|
||||
** the
|
||||
** </li>
|
||||
** </ol>
|
||||
@@ -2994,6 +3026,13 @@ typedef struct sqlite3_context sqlite3_context;
|
||||
** number of <u>bytes</u> in the value, not the number of characters.)^
|
||||
** ^If the fourth parameter is negative, the length of the string is
|
||||
** the number of bytes up to the first zero terminator.
|
||||
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
|
||||
** or sqlite3_bind_text16() then that parameter must be the byte offset
|
||||
** where the NUL terminator would occur assuming the string were NUL
|
||||
** terminated. If any NUL characters occur at byte offsets less than
|
||||
** the value of the fourth parameter then the resulting string value will
|
||||
** contain embedded NULs. The result of expressions involving strings
|
||||
** with embedded NULs is undefined.
|
||||
**
|
||||
** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
|
||||
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
|
||||
@@ -3327,6 +3366,12 @@ SQLITE_API int sqlite3_step(sqlite3_stmt*);
|
||||
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
|
||||
** interfaces) then sqlite3_data_count(P) returns 0.
|
||||
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
|
||||
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
|
||||
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
|
||||
** will return non-zero if previous call to [sqlite3_step](P) returned
|
||||
** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
|
||||
** where it always returns zero since each step of that multi-step
|
||||
** pragma returns 0 columns of data.
|
||||
**
|
||||
** See also: [sqlite3_column_count()]
|
||||
*/
|
||||
@@ -4006,7 +4051,12 @@ typedef void (*sqlite3_destructor_type)(void*);
|
||||
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
|
||||
** is non-negative, then as many bytes (not characters) of the text
|
||||
** pointed to by the 2nd parameter are taken as the application-defined
|
||||
** function result.
|
||||
** function result. If the 3rd parameter is non-negative, then it
|
||||
** must be the byte offset into the string where the NUL terminator would
|
||||
** appear if the string where NUL terminated. If any NUL characters occur
|
||||
** in the string at a byte offset that is less than the value of the 3rd
|
||||
** parameter, then the resulting string will contain embedded NULs and the
|
||||
** result of expressions operating on strings with embedded NULs is undefined.
|
||||
** ^If the 4th parameter to the sqlite3_result_text* interfaces
|
||||
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
|
||||
** function as the destructor on the text or BLOB result when it has
|
||||
@@ -5789,6 +5839,18 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
|
||||
** the database connection.)^
|
||||
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
|
||||
** </dd>
|
||||
**
|
||||
** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
|
||||
** <dd>This parameter returns the number of pager cache hits that have
|
||||
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
|
||||
** is always 0.
|
||||
** </dd>
|
||||
**
|
||||
** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
|
||||
** <dd>This parameter returns the number of pager cache misses that have
|
||||
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
|
||||
** is always 0.
|
||||
** </dd>
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
|
||||
@@ -5798,7 +5860,9 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
|
||||
#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
|
||||
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
|
||||
#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
|
||||
#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */
|
||||
#define SQLITE_DBSTATUS_CACHE_HIT 7
|
||||
#define SQLITE_DBSTATUS_CACHE_MISS 8
|
||||
#define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */
|
||||
|
||||
|
||||
/*
|
||||
@@ -5852,7 +5916,6 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
|
||||
** A non-zero value in this counter may indicate an opportunity to
|
||||
** improvement performance by adding permanent indices that do not
|
||||
** need to be reinitialized each time the statement is run.</dd>
|
||||
**
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// AtomicCounter.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/AtomicCounter.h#1 $
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/AtomicCounter.h#4 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -42,13 +42,15 @@
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#if POCO_OS == POCO_OS_WINDOWS_NT
|
||||
#include "Poco/UnWindows.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
#include <libkern/OSAtomic.h>
|
||||
#elif (POCO_OS == POCO_OS_LINUX) && ((POCO_ARCH == POCO_ARCH_IA32) || (POCO_ARCH == POCO_ARCH_AMD64)) && defined(__GNUC__)
|
||||
#define POCO_ARCH_GCC_INTEL_X32_64 1
|
||||
#include <libkern/OSAtomic.h>
|
||||
#elif ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) && (defined(__x86_64__) || defined(__i386__))
|
||||
#if !defined(POCO_HAVE_GCC_ATOMICS)
|
||||
#define POCO_HAVE_GCC_ATOMICS
|
||||
#endif
|
||||
#else
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#endif // POCO_OS
|
||||
|
||||
|
||||
@@ -70,12 +72,13 @@ class Foundation_API AtomicCounter
|
||||
/// atomic primitives, operations are guarded by a FastMutex.
|
||||
///
|
||||
/// The following platforms currently have atomic
|
||||
/// primitives:
|
||||
/// - Windows
|
||||
/// - Mac OS X
|
||||
/// primitives:
|
||||
/// - Windows
|
||||
/// - Mac OS X
|
||||
/// - GCC 4.1+ (Intel platforms only)
|
||||
{
|
||||
public:
|
||||
typedef int ValueType; /// The underlying integer type.
|
||||
typedef int ValueType; /// The underlying integer type.
|
||||
|
||||
AtomicCounter();
|
||||
/// Creates a new AtomicCounter and initializes it to zero.
|
||||
@@ -119,20 +122,20 @@ public:
|
||||
|
||||
private:
|
||||
#if POCO_OS == POCO_OS_WINDOWS_NT
|
||||
typedef LONG ImplType;
|
||||
typedef volatile LONG ImplType;
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
typedef int32_t ImplType;
|
||||
#elif defined(POCO_ARCH_GCC_INTEL_X32_64)
|
||||
typedef int ImplType;
|
||||
typedef int32_t ImplType;
|
||||
#elif defined(POCO_HAVE_GCC_ATOMICS)
|
||||
typedef int ImplType;
|
||||
#else // generic implementation based on FastMutex
|
||||
struct ImplType
|
||||
struct ImplType
|
||||
{
|
||||
mutable FastMutex mutex;
|
||||
volatile int value;
|
||||
};
|
||||
};
|
||||
#endif // POCO_OS
|
||||
|
||||
volatile ImplType _counter;
|
||||
volatile ImplType _counter;
|
||||
};
|
||||
|
||||
|
||||
@@ -162,11 +165,11 @@ inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
|
||||
return InterlockedIncrement(&_counter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
|
||||
{
|
||||
ValueType result = InterlockedIncrement(&_counter);
|
||||
return --result;
|
||||
ValueType result = InterlockedIncrement(&_counter);
|
||||
return --result;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,14 +178,14 @@ inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
|
||||
return InterlockedDecrement(&_counter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
|
||||
{
|
||||
ValueType result = InterlockedDecrement(&_counter);
|
||||
return ++result;
|
||||
ValueType result = InterlockedDecrement(&_counter);
|
||||
return ++result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline bool AtomicCounter::operator ! () const
|
||||
{
|
||||
return _counter == 0;
|
||||
@@ -210,11 +213,11 @@ inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
|
||||
return OSAtomicIncrement32(&_counter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
|
||||
{
|
||||
ValueType result = OSAtomicIncrement32(&_counter);
|
||||
return --result;
|
||||
ValueType result = OSAtomicIncrement32(&_counter);
|
||||
return --result;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,11 +226,56 @@ inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
|
||||
return OSAtomicDecrement32(&_counter);
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
|
||||
{
|
||||
ValueType result = OSAtomicDecrement32(&_counter);
|
||||
return ++result;
|
||||
}
|
||||
|
||||
|
||||
inline bool AtomicCounter::operator ! () const
|
||||
{
|
||||
return _counter == 0;
|
||||
}
|
||||
|
||||
#elif defined(POCO_HAVE_GCC_ATOMICS)
|
||||
//
|
||||
// GCC 4.1+ atomic builtins.
|
||||
//
|
||||
inline AtomicCounter::operator AtomicCounter::ValueType () const
|
||||
{
|
||||
return _counter;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::value() const
|
||||
{
|
||||
return _counter;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
|
||||
{
|
||||
return __sync_add_and_fetch(&_counter, 1);
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
|
||||
{
|
||||
return __sync_fetch_and_add(&_counter, 1);
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
|
||||
{
|
||||
return __sync_sub_and_fetch(&_counter, 1);
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
|
||||
{
|
||||
ValueType result = OSAtomicDecrement32(&_counter);
|
||||
return ++result;
|
||||
return __sync_fetch_and_sub(&_counter, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,72 +285,6 @@ inline bool AtomicCounter::operator ! () const
|
||||
}
|
||||
|
||||
|
||||
#elif defined(POCO_ARCH_GCC_INTEL_X32_64)
|
||||
//
|
||||
// Generic Intel & GCC
|
||||
//
|
||||
|
||||
//
|
||||
// From boost atomic_count_gcc_x86
|
||||
//
|
||||
inline int poco_atomic_exchange_and_add( volatile int * pw, int dv )
|
||||
{
|
||||
int r;
|
||||
|
||||
__asm__ __volatile__
|
||||
(
|
||||
"lock\n\t"
|
||||
"xadd %1, %0":
|
||||
"+m"( *pw ), "=r"( r ): // outputs (%0, %1)
|
||||
"1"( dv ): // inputs (%2 == %1)
|
||||
"memory", "cc" // clobbers
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
inline AtomicCounter::operator AtomicCounter::ValueType () const
|
||||
{
|
||||
return _counter;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::value() const
|
||||
{
|
||||
return _counter;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
|
||||
{
|
||||
return poco_atomic_exchange_and_add( &_counter, +1 ) + 1;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
|
||||
{
|
||||
return poco_atomic_exchange_and_add( &_counter, +1 );
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
|
||||
{
|
||||
return poco_atomic_exchange_and_add( &_counter, -1 ) - 1;
|
||||
}
|
||||
|
||||
|
||||
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
|
||||
{
|
||||
return poco_atomic_exchange_and_add( &_counter, -1 );
|
||||
}
|
||||
|
||||
|
||||
inline bool AtomicCounter::operator ! () const
|
||||
{
|
||||
return _counter == 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
//
|
||||
// Generic implementation based on FastMutex
|
||||
|
@@ -71,12 +71,22 @@ public:
|
||||
/// Sets the environment variable with the given name
|
||||
/// to the given value.
|
||||
|
||||
static std::string osName();
|
||||
/// Returns the operating system name.
|
||||
|
||||
static std::string osVersion();
|
||||
/// Returns the operating system version.
|
||||
|
||||
static std::string osName();
|
||||
/// Returns the operating system name.
|
||||
|
||||
static std::string osDisplayName();
|
||||
/// Returns the operating system name in a
|
||||
/// "user-friendly" way.
|
||||
///
|
||||
/// Currently this is only implemented for
|
||||
/// Windows. There it will return names like
|
||||
/// "Windows XP" or "Windows 7/Server 2008 SP2".
|
||||
/// On other platform, returns the same as
|
||||
/// osName().
|
||||
|
||||
static std::string osVersion();
|
||||
/// Returns the operating system version.
|
||||
|
||||
static std::string osArchitecture();
|
||||
/// Returns the operating system architecture.
|
||||
|
||||
|
@@ -54,12 +54,13 @@ public:
|
||||
typedef UInt8 NodeId[6]; /// Ethernet address.
|
||||
|
||||
static std::string getImpl(const std::string& name);
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osDisplayNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static void nodeIdImpl(NodeId& id);
|
||||
static unsigned processorCountImpl();
|
||||
|
||||
|
@@ -53,12 +53,13 @@ public:
|
||||
typedef UInt8 NodeId[6]; /// Ethernet address.
|
||||
|
||||
static std::string getImpl(const std::string& name);
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osDisplayNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static void nodeIdImpl(NodeId& id);
|
||||
static unsigned processorCountImpl();
|
||||
|
||||
|
@@ -54,12 +54,13 @@ public:
|
||||
typedef UInt8 NodeId[6]; /// Ethernet address.
|
||||
|
||||
static std::string getImpl(const std::string& name);
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osDisplayNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static void nodeIdImpl(NodeId& id);
|
||||
static unsigned processorCountImpl();
|
||||
|
||||
|
@@ -52,12 +52,13 @@ public:
|
||||
typedef UInt8 NodeId[6]; /// Ethernet address.
|
||||
|
||||
static std::string getImpl(const std::string& name);
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osDisplayNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static void nodeIdImpl(NodeId& id);
|
||||
static unsigned processorCountImpl();
|
||||
};
|
||||
|
@@ -52,12 +52,13 @@ public:
|
||||
typedef UInt8 NodeId[6]; /// Ethernet address.
|
||||
|
||||
static std::string getImpl(const std::string& name);
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static bool hasImpl(const std::string& name);
|
||||
static void setImpl(const std::string& name, const std::string& value);
|
||||
static std::string osNameImpl();
|
||||
static std::string osDisplayNameImpl();
|
||||
static std::string osVersionImpl();
|
||||
static std::string osArchitectureImpl();
|
||||
static std::string nodeNameImpl();
|
||||
static void nodeIdImpl(NodeId& id);
|
||||
static unsigned processorCountImpl();
|
||||
};
|
||||
|
@@ -110,25 +110,25 @@ public:
|
||||
|
||||
Channel* getChannel() const;
|
||||
/// Returns the Channel attached to the logger.
|
||||
|
||||
void setLevel(int level);
|
||||
/// Sets the Logger's log level.
|
||||
///
|
||||
/// See Message::Priority for valid log levels.
|
||||
/// Setting the log level to zero turns off
|
||||
/// logging for that Logger.
|
||||
|
||||
int getLevel() const;
|
||||
/// Returns the Logger's log level.
|
||||
|
||||
void setLevel(int level);
|
||||
/// Sets the Logger's log level.
|
||||
///
|
||||
/// See Message::Priority for valid log levels.
|
||||
/// Setting the log level to zero turns off
|
||||
/// logging for that Logger.
|
||||
|
||||
int getLevel() const;
|
||||
/// Returns the Logger's log level.
|
||||
|
||||
void setLevel(const std::string& level);
|
||||
/// Sets the Logger's log level using a symbolic value.
|
||||
///
|
||||
/// Valid values are:
|
||||
/// - none (turns off logging)
|
||||
/// - fatal
|
||||
/// - critical
|
||||
/// - error
|
||||
/// Sets the Logger's log level using a symbolic value.
|
||||
///
|
||||
/// Valid values are:
|
||||
/// - none (turns off logging)
|
||||
/// - fatal
|
||||
/// - critical
|
||||
/// - error
|
||||
/// - warning
|
||||
/// - notice
|
||||
/// - information
|
||||
@@ -337,12 +337,16 @@ public:
|
||||
|
||||
static std::string format(const std::string& fmt, const std::string& arg0, const std::string& arg1, const std::string& arg2, const std::string& arg3);
|
||||
/// Replaces all occurences of $<n> in fmt with the string given in arg<n> and
|
||||
/// returns the result. To include a dollar sign in the result string,
|
||||
/// specify two dollar signs ($$) in the format string.
|
||||
/// returns the result. To include a dollar sign in the result string,
|
||||
/// specify two dollar signs ($$) in the format string.
|
||||
|
||||
static void setLevel(const std::string& name, int level);
|
||||
/// Sets the given log level on all loggers that are
|
||||
/// descendants of the Logger with the given name.
|
||||
static void formatDump(std::string& message, const void* buffer, std::size_t length);
|
||||
/// Creates a hex-dump of the given buffer and appends it to the
|
||||
/// given message string.
|
||||
|
||||
static void setLevel(const std::string& name, int level);
|
||||
/// Sets the given log level on all loggers that are
|
||||
/// descendants of the Logger with the given name.
|
||||
|
||||
static void setChannel(const std::string& name, Channel* pChannel);
|
||||
/// Attaches the given Channel to all loggers that are
|
||||
@@ -404,13 +408,12 @@ protected:
|
||||
~Logger();
|
||||
|
||||
void log(const std::string& text, Message::Priority prio);
|
||||
void log(const std::string& text, Message::Priority prio, const char* file, int line);
|
||||
void log(const std::string& text, Message::Priority prio, const char* file, int line);
|
||||
|
||||
static std::string format(const std::string& fmt, int argc, std::string argv[]);
|
||||
static void formatDump(std::string& message, const void* buffer, std::size_t length);
|
||||
static Logger& parent(const std::string& name);
|
||||
static void add(Logger* pLogger);
|
||||
static Logger* find(const std::string& name);
|
||||
static std::string format(const std::string& fmt, int argc, std::string argv[]);
|
||||
static Logger& parent(const std::string& name);
|
||||
static void add(Logger* pLogger);
|
||||
static Logger* find(const std::string& name);
|
||||
|
||||
private:
|
||||
Logger();
|
||||
|
@@ -84,12 +84,12 @@ inline void MutexImpl::lockImpl()
|
||||
|
||||
inline bool MutexImpl::tryLockImpl()
|
||||
{
|
||||
try
|
||||
{
|
||||
return TryEnterCriticalSection(&_cs) == TRUE;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
try
|
||||
{
|
||||
return TryEnterCriticalSection(&_cs) != 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
throw SystemException("cannot lock mutex");
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "Poco/Foundation.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -50,23 +51,53 @@ namespace Poco {
|
||||
|
||||
class Foundation_API StreamCopier
|
||||
/// This class provides static methods to copy the contents from one stream
|
||||
/// into another.
|
||||
/// into another.
|
||||
{
|
||||
public:
|
||||
static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, unsigned bufferSize = 8192);
|
||||
/// Writes all bytes readable from istr to ostr, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
|
||||
/// Writes all bytes readable from istr to ostr, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
static Poco::UInt64 copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
|
||||
/// Writes all bytes readable from istr to ostr, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied as a 64-bit unsigned integer.
|
||||
///
|
||||
/// Note: the only difference to copyStream() is that a 64-bit unsigned
|
||||
/// integer is used to count the number of bytes copied.
|
||||
#endif
|
||||
|
||||
static std::streamsize copyStreamUnbuffered(std::istream& istr, std::ostream& ostr);
|
||||
/// Writes all bytes readable from istr to ostr.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
/// Writes all bytes readable from istr to ostr.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
|
||||
static std::streamsize copyToString(std::istream& istr, std::string& str, unsigned bufferSize = 8192);
|
||||
/// Appends all bytes readable from istr to the given string, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
static Poco::UInt64 copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr);
|
||||
/// Writes all bytes readable from istr to ostr.
|
||||
///
|
||||
/// Returns the number of bytes copied as a 64-bit unsigned integer.
|
||||
///
|
||||
/// Note: the only difference to copyStreamUnbuffered() is that a 64-bit unsigned
|
||||
/// integer is used to count the number of bytes copied.
|
||||
#endif
|
||||
|
||||
static std::streamsize copyToString(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
|
||||
/// Appends all bytes readable from istr to the given string, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied.
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
static Poco::UInt64 copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize = 8192);
|
||||
/// Appends all bytes readable from istr to the given string, using an internal buffer.
|
||||
///
|
||||
/// Returns the number of bytes copied as a 64-bit unsigned integer.
|
||||
///
|
||||
/// Note: the only difference to copyToString() is that a 64-bit unsigned
|
||||
/// integer is used to count the number of bytes copied.
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||
* Copyright (C) 1995-2010 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: //poco/svn/Foundation/include/Poco/zconf.h#2 $ */
|
||||
/* @(#) $Id: //poco/1.4/Foundation/include/Poco/zconf.h#2 $ */
|
||||
|
||||
#ifndef ZCONF_H
|
||||
#define ZCONF_H
|
||||
@@ -11,52 +11,124 @@
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
* Even better than compiling with -DZ_PREFIX would be to use configure to set
|
||||
* this permanently in zconf.h using "./configure --zprefix".
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||
|
||||
/* all linked symbols */
|
||||
# define _dist_code z__dist_code
|
||||
# define _length_code z__length_code
|
||||
# define _tr_align z__tr_align
|
||||
# define _tr_flush_block z__tr_flush_block
|
||||
# define _tr_init z__tr_init
|
||||
# define _tr_stored_block z__tr_stored_block
|
||||
# define _tr_tally z__tr_tally
|
||||
# define adler32 z_adler32
|
||||
# define adler32_combine z_adler32_combine
|
||||
# define adler32_combine64 z_adler32_combine64
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define compressBound z_compressBound
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define crc32_combine z_crc32_combine
|
||||
# define crc32_combine64 z_crc32_combine64
|
||||
# define deflate z_deflate
|
||||
# define deflateBound z_deflateBound
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflateParams z_deflateParams
|
||||
# define deflatePrime z_deflatePrime
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateSetHeader z_deflateSetHeader
|
||||
# define deflateTune z_deflateTune
|
||||
# define deflate_copyright z_deflate_copyright
|
||||
# define get_crc_table z_get_crc_table
|
||||
# define gz_error z_gz_error
|
||||
# define gz_intmax z_gz_intmax
|
||||
# define gz_strwinerror z_gz_strwinerror
|
||||
# define gzbuffer z_gzbuffer
|
||||
# define gzclearerr z_gzclearerr
|
||||
# define gzclose z_gzclose
|
||||
# define gzclose_r z_gzclose_r
|
||||
# define gzclose_w z_gzclose_w
|
||||
# define gzdirect z_gzdirect
|
||||
# define gzdopen z_gzdopen
|
||||
# define gzeof z_gzeof
|
||||
# define gzerror z_gzerror
|
||||
# define gzflush z_gzflush
|
||||
# define gzgetc z_gzgetc
|
||||
# define gzgets z_gzgets
|
||||
# define gzoffset z_gzoffset
|
||||
# define gzoffset64 z_gzoffset64
|
||||
# define gzopen z_gzopen
|
||||
# define gzopen64 z_gzopen64
|
||||
# define gzprintf z_gzprintf
|
||||
# define gzputc z_gzputc
|
||||
# define gzputs z_gzputs
|
||||
# define gzread z_gzread
|
||||
# define gzrewind z_gzrewind
|
||||
# define gzseek z_gzseek
|
||||
# define gzseek64 z_gzseek64
|
||||
# define gzsetparams z_gzsetparams
|
||||
# define gztell z_gztell
|
||||
# define gztell64 z_gztell64
|
||||
# define gzungetc z_gzungetc
|
||||
# define gzwrite z_gzwrite
|
||||
# define inflate z_inflate
|
||||
# define inflateBack z_inflateBack
|
||||
# define inflateBackEnd z_inflateBackEnd
|
||||
# define inflateBackInit_ z_inflateBackInit_
|
||||
# define inflateCopy z_inflateCopy
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define inflateGetHeader z_inflateGetHeader
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflateMark z_inflateMark
|
||||
# define inflatePrime z_inflatePrime
|
||||
# define inflateReset z_inflateReset
|
||||
# define inflateReset2 z_inflateReset2
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateUndermine z_inflateUndermine
|
||||
# define inflate_copyright z_inflate_copyright
|
||||
# define inflate_fast z_inflate_fast
|
||||
# define inflate_table z_inflate_table
|
||||
# define uncompress z_uncompress
|
||||
# define zError z_zError
|
||||
# define zcalloc z_zcalloc
|
||||
# define zcfree z_zcfree
|
||||
# define zlibCompileFlags z_zlibCompileFlags
|
||||
# define zlibVersion z_zlibVersion
|
||||
|
||||
# define alloc_func z_alloc_func
|
||||
# define free_func z_free_func
|
||||
# define in_func z_in_func
|
||||
# define out_func z_out_func
|
||||
/* all zlib typedefs in zlib.h and zconf.h */
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define alloc_func z_alloc_func
|
||||
# define charf z_charf
|
||||
# define free_func z_free_func
|
||||
# define gzFile z_gzFile
|
||||
# define gz_header z_gz_header
|
||||
# define gz_headerp z_gz_headerp
|
||||
# define in_func z_in_func
|
||||
# define intf z_intf
|
||||
# define out_func z_out_func
|
||||
# define uInt z_uInt
|
||||
# define uIntf z_uIntf
|
||||
# define uLong z_uLong
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
# define voidpc z_voidpc
|
||||
# define voidpf z_voidpf
|
||||
|
||||
/* all zlib structs in zlib.h and zconf.h */
|
||||
# define gz_header_s z_gz_header_s
|
||||
# define internal_state z_internal_state
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
@@ -284,49 +356,73 @@ typedef uLong FAR uLongf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# define z_off_t off_t
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# include <sys/types.h> /* for off_t */
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
* though the former does not conform to the LFS document), but considering
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
# define z_off64_t off64_t
|
||||
#else
|
||||
# define z_off64_t z_off_t
|
||||
#endif
|
||||
|
||||
#if defined(__OS400__)
|
||||
# define NO_vsnprintf
|
||||
#endif
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(deflateBound,"DEBND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(compressBound,"CMBND")
|
||||
# pragma map(inflate_table,"INTABL")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
#pragma map(deflateInit_,"DEIN")
|
||||
#pragma map(deflateInit2_,"DEIN2")
|
||||
#pragma map(deflateEnd,"DEEND")
|
||||
#pragma map(deflateBound,"DEBND")
|
||||
#pragma map(inflateInit_,"ININ")
|
||||
#pragma map(inflateInit2_,"ININ2")
|
||||
#pragma map(inflateEnd,"INEND")
|
||||
#pragma map(inflateSync,"INSY")
|
||||
#pragma map(inflateSetDictionary,"INSEDI")
|
||||
#pragma map(compressBound,"CMBND")
|
||||
#pragma map(inflate_table,"INTABL")
|
||||
#pragma map(inflate_fast,"INFA")
|
||||
#pragma map(inflate_copyright,"INCOPY")
|
||||
#endif
|
||||
|
||||
#endif /* ZCONF_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -122,12 +122,12 @@ AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
}
|
||||
|
||||
|
||||
#elif defined(POCO_ARCH_GCC_INTEL_X32_64)
|
||||
#elif defined(POCO_HAVE_GCC_ATOMICS)
|
||||
//
|
||||
// GCC & Linux
|
||||
// GCC 4.1+ atomic builtins.
|
||||
//
|
||||
AtomicCounter::AtomicCounter():
|
||||
_counter(0)
|
||||
_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -151,15 +151,15 @@ AtomicCounter::~AtomicCounter()
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
|
||||
{
|
||||
_counter = counter.value();
|
||||
return *this;
|
||||
__sync_lock_test_and_set(&_counter, counter.value());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
|
||||
{
|
||||
_counter = value;
|
||||
return *this;
|
||||
__sync_lock_test_and_set(&_counter, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment.cpp#4 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -92,10 +92,16 @@ std::string Environment::osName()
|
||||
return EnvironmentImpl::osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Environment::osDisplayName()
|
||||
{
|
||||
return EnvironmentImpl::osDisplayNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Environment::osVersion()
|
||||
{
|
||||
return EnvironmentImpl::osVersionImpl();
|
||||
return EnvironmentImpl::osVersionImpl();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
// Environment_UNIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment_UNIX.cpp#7 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_UNIX.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -102,9 +102,15 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
struct utsname uts;
|
||||
struct utsname uts;
|
||||
uname(&uts);
|
||||
return uts.release;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment_VMS.cpp#3 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_VMS.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -103,9 +103,15 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
return getsyi(SYI$_VERSION);
|
||||
return getsyi(SYI$_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
// Environment_VX.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_VX.cpp#2 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_VX.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -108,9 +108,15 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
return runtimeVersion;
|
||||
return runtimeVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,25 +156,25 @@ unsigned EnvironmentImpl::processorCountImpl()
|
||||
|
||||
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||
{
|
||||
std::memset(&id, 0, sizeof(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");
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment_WIN32.cpp#6 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WIN32.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -88,9 +88,56 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
return vi.dwMinorVersion == 0 ? "Windows 95" : "Windows 98";
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
return "Windows NT";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment_WIN32U.cpp#5 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WIN32U.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -98,9 +98,56 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
return vi.dwMinorVersion == 0 ? "Windows 95" : "Windows 98";
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
return "Windows NT";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment_WINCE.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WINCE.cpp#1 $
|
||||
// $Id: //poco/1.4/Foundation/src/Environment_WINCE.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -84,9 +84,15 @@ std::string EnvironmentImpl::osNameImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osDisplayNameImpl()
|
||||
{
|
||||
return osNameImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string EnvironmentImpl::osVersionImpl()
|
||||
{
|
||||
OSVERSIONINFOW vi;
|
||||
OSVERSIONINFOW vi;
|
||||
vi.dwOSVersionInfoSize = sizeof(vi);
|
||||
if (GetVersionExW(&vi) == 0) throw SystemException("Cannot get OS version information");
|
||||
std::ostringstream str;
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Ascii.h"
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
@@ -63,13 +64,13 @@ namespace
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
@@ -78,13 +79,13 @@ namespace
|
||||
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;
|
||||
{
|
||||
++itFmt;
|
||||
int prec = 0;
|
||||
while (itFmt != endFmt && Ascii::isDigit(*itFmt))
|
||||
{
|
||||
prec = 10*prec + *itFmt - '0';
|
||||
++itFmt;
|
||||
}
|
||||
if (prec >= 0) str.precision(prec);
|
||||
}
|
||||
@@ -103,23 +104,23 @@ namespace
|
||||
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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
void prepareFormat(std::ostream& str, char type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 'd':
|
||||
@@ -163,12 +164,13 @@ namespace
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
parseFlags(str, itFmt, endFmt);
|
||||
parseWidth(str, itFmt, endFmt);
|
||||
parsePrec(str, itFmt, endFmt);
|
||||
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;
|
||||
str.imbue(std::locale::classic());
|
||||
parseFlags(str, itFmt, endFmt);
|
||||
parseWidth(str, itFmt, endFmt);
|
||||
parsePrec(str, itFmt, endFmt);
|
||||
char mod = parseMod(itFmt, endFmt);
|
||||
if (itFmt != endFmt)
|
||||
{
|
||||
@@ -355,33 +357,33 @@ void format(std::string& result, const std::string& fmt, const std::vector<Any>&
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -129,13 +129,13 @@ bool Glob::match(TextIterator& itp, const TextIterator& endp, TextIterator& its,
|
||||
{
|
||||
bool invert = *itp == '!';
|
||||
if (invert) ++itp;
|
||||
if (itp != endp)
|
||||
{
|
||||
bool mtch = matchSet(itp, endp, *its++);
|
||||
if ((invert && mtch) || (!invert && !mtch)) return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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");
|
||||
@@ -259,11 +259,20 @@ void Glob::collect(const Path& pathPattern, const Path& base, const Path& curren
|
||||
|
||||
bool Glob::isDirectory(const Path& path, bool followSymlink)
|
||||
{
|
||||
File f(path);
|
||||
if (f.isDirectory())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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
|
||||
|
@@ -16,14 +16,14 @@
|
||||
// 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
|
||||
@@ -35,13 +35,16 @@
|
||||
|
||||
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/MemoryStream.h"
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define I64_FMT "I64"
|
||||
#elif defined(__APPLE__)
|
||||
#elif defined(__APPLE__)
|
||||
#define I64_FMT "q"
|
||||
#else
|
||||
#define I64_FMT "ll"
|
||||
@@ -53,28 +56,28 @@ namespace Poco {
|
||||
|
||||
std::string NumberFormatter::format(bool value, BoolFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
default:
|
||||
case FMT_TRUE_FALSE:
|
||||
if (value == true)
|
||||
return "true";
|
||||
return "false";
|
||||
case FMT_YES_NO:
|
||||
if (value == true)
|
||||
return "yes";
|
||||
return "no";
|
||||
case FMT_ON_OFF:
|
||||
if (value == true)
|
||||
return "on";
|
||||
return "off";
|
||||
}
|
||||
switch(format)
|
||||
{
|
||||
default:
|
||||
case FMT_TRUE_FALSE:
|
||||
if (value == true)
|
||||
return "true";
|
||||
return "false";
|
||||
case FMT_YES_NO:
|
||||
if (value == true)
|
||||
return "yes";
|
||||
return "no";
|
||||
case FMT_ON_OFF:
|
||||
if (value == true)
|
||||
return "on";
|
||||
return "off";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::append(std::string& str, int value)
|
||||
{
|
||||
char buffer[64];
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%d", value);
|
||||
str.append(buffer);
|
||||
}
|
||||
@@ -356,37 +359,45 @@ void NumberFormatter::appendHex(std::string& str, UInt64 value, int width)
|
||||
|
||||
void NumberFormatter::append(std::string& str, float value)
|
||||
{
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%.*g", 8, (double) value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
|
||||
ostr.imbue(std::locale::classic());
|
||||
ostr << std::setprecision(8) << value;
|
||||
str.append(buffer, ostr.charsWritten());
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::append(std::string& str, double value)
|
||||
{
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%.*g", 16, value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
|
||||
ostr.imbue(std::locale::classic());
|
||||
ostr << std::setprecision(16) << value;
|
||||
str.append(buffer, ostr.charsWritten());
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::append(std::string& str, double value, int precision)
|
||||
{
|
||||
poco_assert (precision >= 0 && precision < 32);
|
||||
poco_assert (precision >= 0 && precision < 32);
|
||||
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%.*f", precision, value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
|
||||
ostr.imbue(std::locale::classic());
|
||||
ostr << std::fixed << std::showpoint << std::setprecision(precision) << value;
|
||||
str.append(buffer, ostr.charsWritten());
|
||||
}
|
||||
|
||||
|
||||
void NumberFormatter::append(std::string& str, double value, int width, int precision)
|
||||
{
|
||||
poco_assert (width > 0 && width < 64 && precision >= 0 && precision < width);
|
||||
poco_assert (width > 0 && width < 64 && precision >= 0 && precision < width);
|
||||
|
||||
char buffer[64];
|
||||
std::sprintf(buffer, "%*.*f", width, precision, value);
|
||||
str.append(buffer);
|
||||
char buffer[64];
|
||||
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
|
||||
ostr.imbue(std::locale::classic());
|
||||
ostr << std::fixed << std::showpoint << std::setw(width) << std::setprecision(precision) << value;
|
||||
str.append(buffer, ostr.charsWritten());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -36,7 +36,9 @@
|
||||
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/MemoryStream.h"
|
||||
#include "Poco/String.h"
|
||||
#include <locale>
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
|
||||
@@ -170,66 +172,68 @@ double NumberParser::parseFloat(const std::string& s)
|
||||
throw SyntaxException("Not a valid floating-point number", s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool NumberParser::tryParseFloat(const std::string& s, double& value)
|
||||
{
|
||||
char temp;
|
||||
return std::sscanf(s.c_str(), "%lf%c", &value, &temp) == 1;
|
||||
Poco::MemoryInputStream istr(s.data(), s.size());
|
||||
istr.imbue(std::locale::classic());
|
||||
istr >> value;
|
||||
return istr.eof() && !istr.fail();
|
||||
}
|
||||
|
||||
|
||||
bool NumberParser::parseBool(const std::string& s)
|
||||
{
|
||||
bool result;
|
||||
if (tryParseBool(s, result))
|
||||
return result;
|
||||
else
|
||||
throw SyntaxException("Not a valid bool number", s);
|
||||
bool result;
|
||||
if (tryParseBool(s, result))
|
||||
return result;
|
||||
else
|
||||
throw SyntaxException("Not a valid bool number", s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool NumberParser::tryParseBool(const std::string& s, bool& value)
|
||||
{
|
||||
int n;
|
||||
if (NumberParser::tryParse(s, n))
|
||||
{
|
||||
value = (n != 0);
|
||||
return true;
|
||||
}
|
||||
int n;
|
||||
if (NumberParser::tryParse(s, n))
|
||||
{
|
||||
value = (n != 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (icompare(s, "true") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "yes") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "on") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (icompare(s, "false") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "no") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "off") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (icompare(s, "true") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "yes") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "on") == 0)
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (icompare(s, "false") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "no") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
else if (icompare(s, "off") == 0)
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -456,20 +456,20 @@ Path& Path::resolve(const Path& path)
|
||||
|
||||
Path& Path::setNode(const std::string& node)
|
||||
{
|
||||
_node = node;
|
||||
_absolute = _absolute || !node.empty();
|
||||
return *this;
|
||||
_node = node;
|
||||
_absolute = _absolute || !node.empty();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Path& Path::setDevice(const std::string& device)
|
||||
{
|
||||
_device = device;
|
||||
_absolute = _absolute || !device.empty();
|
||||
return *this;
|
||||
_device = device;
|
||||
_absolute = _absolute || !device.empty();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::string& Path::directory(int n) const
|
||||
{
|
||||
poco_assert (0 <= n && n <= _dirs.size());
|
||||
@@ -491,11 +491,11 @@ const std::string& Path::operator [] (int n) const
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Path& Path::pushDirectory(const std::string& dir)
|
||||
{
|
||||
if (!dir.empty() && dir != ".")
|
||||
{
|
||||
if (!dir.empty() && dir != ".")
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_VMS)
|
||||
if (dir == ".." || dir == "-")
|
||||
{
|
||||
@@ -513,49 +513,49 @@ Path& Path::pushDirectory(const std::string& dir)
|
||||
else if (!_absolute)
|
||||
_dirs.push_back(dir);
|
||||
}
|
||||
else _dirs.push_back(dir);
|
||||
else _dirs.push_back(dir);
|
||||
#endif
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Path& Path::popDirectory()
|
||||
{
|
||||
poco_assert (!_dirs.empty());
|
||||
|
||||
_dirs.pop_back();
|
||||
return *this;
|
||||
poco_assert (!_dirs.empty());
|
||||
|
||||
_dirs.pop_back();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Path& Path::popFrontDirectory()
|
||||
{
|
||||
poco_assert (!_dirs.empty());
|
||||
|
||||
StringVec::iterator it = _dirs.begin();
|
||||
_dirs.erase(it);
|
||||
return *this;
|
||||
poco_assert (!_dirs.empty());
|
||||
|
||||
StringVec::iterator it = _dirs.begin();
|
||||
_dirs.erase(it);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Path& Path::setFileName(const std::string& name)
|
||||
{
|
||||
_name = name;
|
||||
return *this;
|
||||
_name = name;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Path& Path::setBaseName(const std::string& name)
|
||||
{
|
||||
std::string ext = getExtension();
|
||||
_name = name;
|
||||
std::string ext = getExtension();
|
||||
_name = name;
|
||||
if (!ext.empty())
|
||||
{
|
||||
_name.append(".");
|
||||
_name.append(ext);
|
||||
}
|
||||
return *this;
|
||||
_name.append(".");
|
||||
_name.append(ext);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -571,16 +571,16 @@ std::string Path::getBaseName() const
|
||||
|
||||
Path& Path::setExtension(const std::string& extension)
|
||||
{
|
||||
_name = getBaseName();
|
||||
if (!extension.empty())
|
||||
_name = getBaseName();
|
||||
if (!extension.empty())
|
||||
{
|
||||
_name.append(".");
|
||||
_name.append(extension);
|
||||
}
|
||||
return *this;
|
||||
_name.append(".");
|
||||
_name.append(extension);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Path::getExtension() const
|
||||
{
|
||||
std::string::size_type pos = _name.rfind('.');
|
||||
@@ -593,12 +593,12 @@ std::string Path::getExtension() const
|
||||
|
||||
Path& Path::clear()
|
||||
{
|
||||
_node.clear();
|
||||
_device.clear();
|
||||
_node.clear();
|
||||
_device.clear();
|
||||
_name.clear();
|
||||
_dirs.clear();
|
||||
_version.clear();
|
||||
_absolute = false;
|
||||
_dirs.clear();
|
||||
_version.clear();
|
||||
_absolute = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -641,12 +641,21 @@ void Path::listRoots(std::vector<std::string>& roots)
|
||||
|
||||
bool Path::find(StringVec::const_iterator it, StringVec::const_iterator end, const std::string& name, Path& path)
|
||||
{
|
||||
while (it != end)
|
||||
{
|
||||
Path p(*it);
|
||||
p.makeDirectory();
|
||||
p.resolve(Path(name));
|
||||
File f(p);
|
||||
while (it != end)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
std::string cleanPath(*it);
|
||||
if (cleanPath.size() > 1 && cleanPath[0] == '"' && cleanPath[cleanPath.size() - 1] == '"')
|
||||
{
|
||||
cleanPath = cleanPath.substr(1, cleanPath.size() - 2);
|
||||
}
|
||||
Path p(cleanPath);
|
||||
#else
|
||||
Path p(*it);
|
||||
#endif
|
||||
p.makeDirectory();
|
||||
p.resolve(Path(name));
|
||||
File f(p);
|
||||
if (f.exists())
|
||||
{
|
||||
path = p;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// StreamCopier.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/StreamCopier.cpp#2 $
|
||||
// $Id: //poco/1.4/Foundation/src/StreamCopier.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
@@ -41,9 +41,9 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
std::streamsize StreamCopier::copyStream(std::istream& istr, std::ostream& ostr, unsigned bufferSize)
|
||||
std::streamsize StreamCopier::copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
||||
{
|
||||
poco_assert (bufferSize > 0);
|
||||
poco_assert (bufferSize > 0);
|
||||
|
||||
Buffer<char> buffer(bufferSize);
|
||||
std::streamsize len = 0;
|
||||
@@ -64,9 +64,34 @@ std::streamsize StreamCopier::copyStream(std::istream& istr, std::ostream& ostr,
|
||||
}
|
||||
|
||||
|
||||
std::streamsize StreamCopier::copyToString(std::istream& istr, std::string& str, unsigned bufferSize)
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
Poco::UInt64 StreamCopier::copyStream64(std::istream& istr, std::ostream& ostr, std::size_t bufferSize)
|
||||
{
|
||||
poco_assert (bufferSize > 0);
|
||||
poco_assert (bufferSize > 0);
|
||||
|
||||
Buffer<char> buffer(bufferSize);
|
||||
Poco::UInt64 len = 0;
|
||||
istr.read(buffer.begin(), bufferSize);
|
||||
std::streamsize n = istr.gcount();
|
||||
while (n > 0)
|
||||
{
|
||||
len += n;
|
||||
ostr.write(buffer.begin(), n);
|
||||
if (istr && ostr)
|
||||
{
|
||||
istr.read(buffer.begin(), bufferSize);
|
||||
n = istr.gcount();
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
std::streamsize StreamCopier::copyToString(std::istream& istr, std::string& str, std::size_t bufferSize)
|
||||
{
|
||||
poco_assert (bufferSize > 0);
|
||||
|
||||
Buffer<char> buffer(bufferSize);
|
||||
std::streamsize len = 0;
|
||||
@@ -87,6 +112,31 @@ std::streamsize StreamCopier::copyToString(std::istream& istr, std::string& str,
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
Poco::UInt64 StreamCopier::copyToString64(std::istream& istr, std::string& str, std::size_t bufferSize)
|
||||
{
|
||||
poco_assert (bufferSize > 0);
|
||||
|
||||
Buffer<char> buffer(bufferSize);
|
||||
Poco::UInt64 len = 0;
|
||||
istr.read(buffer.begin(), bufferSize);
|
||||
std::streamsize n = istr.gcount();
|
||||
while (n > 0)
|
||||
{
|
||||
len += n;
|
||||
str.append(buffer.begin(), static_cast<std::string::size_type>(n));
|
||||
if (istr)
|
||||
{
|
||||
istr.read(buffer.begin(), bufferSize);
|
||||
n = istr.gcount();
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
std::streamsize StreamCopier::copyStreamUnbuffered(std::istream& istr, std::ostream& ostr)
|
||||
{
|
||||
char c;
|
||||
@@ -102,4 +152,21 @@ std::streamsize StreamCopier::copyStreamUnbuffered(std::istream& istr, std::ostr
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
Poco::UInt64 StreamCopier::copyStreamUnbuffered64(std::istream& istr, std::ostream& ostr)
|
||||
{
|
||||
char c;
|
||||
Poco::UInt64 len = 0;
|
||||
istr.get(c);
|
||||
while (istr && ostr)
|
||||
{
|
||||
++len;
|
||||
ostr.put(c);
|
||||
istr.get(c);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
@@ -54,7 +54,7 @@ supporting internal functions that are not used by other modules. */
|
||||
/* When DEBUG is defined, we need the pcre_printint() function, which is also
|
||||
used by pcretest. DEBUG is not defined when building a production library. */
|
||||
|
||||
#ifdef DEBUG
|
||||
#if defined(DEBUG)
|
||||
#include "pcre_printint.src"
|
||||
#endif
|
||||
|
||||
|
@@ -72,12 +72,12 @@ setjmp and stdarg are used is when NO_RECURSE is set. */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* When compiling a DLL for Windows, the exported symbols have to be declared
|
||||
using some MS magic. I found some useful information on this web page:
|
||||
@@ -113,7 +113,7 @@ PCRE_EXP_DATA_DEFN only if they are not already set. */
|
||||
# define PCRE_EXP_DEFN __declspec(dllexport)
|
||||
# define PCRE_EXP_DATA_DEFN __declspec(dllexport)
|
||||
# else
|
||||
# define PCRE_EXP_DECL extern
|
||||
# define PCRE_EXP_DECL extern
|
||||
# define PCRE_EXP_DEFN
|
||||
# define PCRE_EXP_DATA_DEFN
|
||||
# endif
|
||||
|
@@ -1,158 +1,158 @@
|
||||
//
|
||||
// pocomsg.mc[.h]
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/pocomsg.mc#2 $
|
||||
//
|
||||
// The Poco message source/header file.
|
||||
//
|
||||
// NOTE: pocomsg.h is automatically generated from pocomsg.mc.
|
||||
// Never edit pocomsg.h directly!
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Categories
|
||||
//
|
||||
//
|
||||
// Values are 32 bit values laid out as follows:
|
||||
//
|
||||
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
|
||||
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
// |Sev|C|R| Facility | Code |
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
//
|
||||
// where
|
||||
//
|
||||
// Sev - is the severity code
|
||||
//
|
||||
// 00 - Success
|
||||
// 01 - Informational
|
||||
// 10 - Warning
|
||||
// 11 - Error
|
||||
//
|
||||
// C - is the Customer code flag
|
||||
//
|
||||
// R - is a reserved bit
|
||||
//
|
||||
// Facility - is the facility code
|
||||
//
|
||||
// Code - is the facility's status code
|
||||
//
|
||||
//
|
||||
// Define the facility codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Define the severity codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_FATAL
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Fatal
|
||||
//
|
||||
#define POCO_CTG_FATAL 0x00000001L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_CRITICAL
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Critical
|
||||
//
|
||||
#define POCO_CTG_CRITICAL 0x00000002L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_ERROR
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Error
|
||||
//
|
||||
#define POCO_CTG_ERROR 0x00000003L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_WARNING
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Warning
|
||||
//
|
||||
#define POCO_CTG_WARNING 0x00000004L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_NOTICE
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Notice
|
||||
//
|
||||
#define POCO_CTG_NOTICE 0x00000005L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_INFORMATION
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Information
|
||||
//
|
||||
#define POCO_CTG_INFORMATION 0x00000006L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_DEBUG
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Debug
|
||||
//
|
||||
#define POCO_CTG_DEBUG 0x00000007L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_TRACE
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Trace
|
||||
//
|
||||
#define POCO_CTG_TRACE 0x00000008L
|
||||
|
||||
//
|
||||
// Event Identifiers
|
||||
//
|
||||
//
|
||||
// MessageId: POCO_MSG_LOG
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// %1
|
||||
//
|
||||
#define POCO_MSG_LOG 0x00001000L
|
||||
|
||||
//
|
||||
// pocomsg.mc[.h]
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/pocomsg.h#1 $
|
||||
//
|
||||
// The Poco message source/header file.
|
||||
//
|
||||
// NOTE: pocomsg.h is automatically generated from pocomsg.mc.
|
||||
// Never edit pocomsg.h directly!
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// Categories
|
||||
//
|
||||
//
|
||||
// Values are 32 bit values laid out as follows:
|
||||
//
|
||||
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
|
||||
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
// |Sev|C|R| Facility | Code |
|
||||
// +---+-+-+-----------------------+-------------------------------+
|
||||
//
|
||||
// where
|
||||
//
|
||||
// Sev - is the severity code
|
||||
//
|
||||
// 00 - Success
|
||||
// 01 - Informational
|
||||
// 10 - Warning
|
||||
// 11 - Error
|
||||
//
|
||||
// C - is the Customer code flag
|
||||
//
|
||||
// R - is a reserved bit
|
||||
//
|
||||
// Facility - is the facility code
|
||||
//
|
||||
// Code - is the facility's status code
|
||||
//
|
||||
//
|
||||
// Define the facility codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Define the severity codes
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_FATAL
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Fatal
|
||||
//
|
||||
#define POCO_CTG_FATAL 0x00000001L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_CRITICAL
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Critical
|
||||
//
|
||||
#define POCO_CTG_CRITICAL 0x00000002L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_ERROR
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Error
|
||||
//
|
||||
#define POCO_CTG_ERROR 0x00000003L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_WARNING
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Warning
|
||||
//
|
||||
#define POCO_CTG_WARNING 0x00000004L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_NOTICE
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Notice
|
||||
//
|
||||
#define POCO_CTG_NOTICE 0x00000005L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_INFORMATION
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Information
|
||||
//
|
||||
#define POCO_CTG_INFORMATION 0x00000006L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_DEBUG
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Debug
|
||||
//
|
||||
#define POCO_CTG_DEBUG 0x00000007L
|
||||
|
||||
//
|
||||
// MessageId: POCO_CTG_TRACE
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// Trace
|
||||
//
|
||||
#define POCO_CTG_TRACE 0x00000008L
|
||||
|
||||
//
|
||||
// Event Identifiers
|
||||
//
|
||||
//
|
||||
// MessageId: POCO_MSG_LOG
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// %1
|
||||
//
|
||||
#define POCO_MSG_LOG 0x00001000L
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
;//
|
||||
;// pocomsg.mc[.h]
|
||||
;//
|
||||
;// $Id: //poco/svn/Foundation/src/pocomsg.mc#2 $
|
||||
;// $Id: //poco/1.4/Foundation/src/pocomsg.mc#1 $
|
||||
;//
|
||||
;// The Poco message source/header file.
|
||||
;//
|
||||
|
@@ -291,7 +291,7 @@
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include "Poco/UnWindows.h"
|
||||
# include <windows.h>
|
||||
/* No need for _export, use ZLIB.DEF instead. */
|
||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||
# define ZEXPORT WINAPI
|
||||
@@ -356,14 +356,34 @@ typedef uLong FAR uLongf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||
# define Z_HAVE_UNISTD_H
|
||||
#endif
|
||||
|
||||
#ifdef STDC
|
||||
# include <sys/types.h> /* for off_t */
|
||||
#endif
|
||||
|
||||
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||
* though the former does not conform to the LFS document), but considering
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# ifdef VMS
|
||||
# include <unixio.h> /* for off_t */
|
||||
# endif
|
||||
# ifndef z_off_t
|
||||
# define z_off_t off_t
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
@@ -386,9 +406,6 @@ typedef uLong FAR uLongf;
|
||||
|
||||
#if defined(__MVS__)
|
||||
# define NO_vsnprintf
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
|
@@ -1578,7 +1578,7 @@ ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
|
||||
# define gzoffset gzoffset64
|
||||
# define adler32_combine adler32_combine64
|
||||
# define crc32_combine crc32_combine64
|
||||
# ifndef _LARGEFILE64_SOURCE
|
||||
# ifdef _LARGEFILE64_SOURCE
|
||||
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
||||
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
|
||||
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
|
||||
|
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
/* @(#) $Id: //poco/1.4/Foundation/src/zutil.c#2 $ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id$ */
|
||||
/* @(#) $Id: //poco/1.4/Foundation/src/zutil.h#2 $ */
|
||||
|
||||
#ifndef ZUTIL_H
|
||||
#define ZUTIL_H
|
||||
|
@@ -82,11 +82,14 @@ public:
|
||||
DialogSocket(const Socket& socket);
|
||||
/// Creates the DialogSocket with the SocketImpl
|
||||
/// from another socket. The SocketImpl must be
|
||||
/// a StreamSocketImpl, otherwise an InvalidArgumentException
|
||||
/// will be thrown.
|
||||
/// a StreamSocketImpl, otherwise an InvalidArgumentException
|
||||
/// will be thrown.
|
||||
|
||||
~DialogSocket();
|
||||
/// Destroys the DialogSocket.
|
||||
DialogSocket(const DialogSocket& socket);
|
||||
/// Creates the DialogSocket as copy of another dialog socket.
|
||||
|
||||
~DialogSocket();
|
||||
/// Destroys the DialogSocket.
|
||||
|
||||
DialogSocket& operator = (const Socket& socket);
|
||||
/// Assignment operator.
|
||||
|
@@ -57,11 +57,18 @@ class PartSource;
|
||||
|
||||
|
||||
class Net_API HTMLForm: public NameValueCollection
|
||||
/// HTMLForm is a helper class for working with HTML forms,
|
||||
/// both on the client and on the server side.
|
||||
/// HTMLForm is a helper class for working with HTML forms,
|
||||
/// both on the client and on the server side.
|
||||
///
|
||||
/// The maximum number of form fields can be restricted
|
||||
/// by calling setFieldLimit(). This is useful to
|
||||
/// defend against certain kinds of denial-of-service
|
||||
/// attacks. The limit is only enforced when parsing
|
||||
/// form data from a stream or string, not when adding
|
||||
/// form fields programmatically. The default limit is 100.
|
||||
{
|
||||
public:
|
||||
HTMLForm();
|
||||
HTMLForm();
|
||||
/// Creates an empty HTMLForm and sets the
|
||||
/// encoding to "application/x-www-form-urlencoded".
|
||||
|
||||
@@ -133,12 +140,27 @@ public:
|
||||
|
||||
void read(std::istream& istr, PartHandler& handler);
|
||||
/// Reads the form data from the given input stream.
|
||||
///
|
||||
/// The form data read from the stream must be
|
||||
/// in the encoding specified for the form.
|
||||
|
||||
void prepareSubmit(HTTPRequest& request);
|
||||
/// Fills out the request object for submitting the form.
|
||||
///
|
||||
/// The form data read from the stream must be
|
||||
/// in the encoding specified for the form.
|
||||
///
|
||||
/// Note that read() does not clear the form before
|
||||
/// reading the new values.
|
||||
|
||||
void read(std::istream& istr);
|
||||
/// Reads the URL-encoded form data from the given input stream.
|
||||
///
|
||||
/// Note that read() does not clear the form before
|
||||
/// reading the new values.
|
||||
|
||||
void read(const std::string& queryString);
|
||||
/// Reads the form data from the given HTTP query string.
|
||||
///
|
||||
/// Note that read() does not clear the form before
|
||||
/// reading the new values.
|
||||
|
||||
void prepareSubmit(HTTPRequest& request);
|
||||
/// Fills out the request object for submitting the form.
|
||||
///
|
||||
/// If the request method is GET, the encoded form is appended to the
|
||||
/// request URI as query string. Otherwise (the method is
|
||||
@@ -161,11 +183,25 @@ public:
|
||||
/// using the specified encoding.
|
||||
|
||||
const std::string& boundary() const;
|
||||
/// Returns the MIME boundary used for writing
|
||||
/// multipart form data.
|
||||
/// Returns the MIME boundary used for writing
|
||||
/// multipart form data.
|
||||
|
||||
static const std::string ENCODING_URL; /// "application/x-www-form-urlencoded"
|
||||
static const std::string ENCODING_MULTIPART; /// "multipart/form-data"
|
||||
int getFieldLimit() const;
|
||||
/// Returns the maximum number of header fields
|
||||
/// allowed.
|
||||
///
|
||||
/// See setFieldLimit() for more information.
|
||||
|
||||
void setFieldLimit(int limit);
|
||||
/// Sets the maximum number of header fields
|
||||
/// allowed. This limit is used to defend certain
|
||||
/// kinds of denial-of-service attacks.
|
||||
/// Specify 0 for unlimited (not recommended).
|
||||
///
|
||||
/// The default limit is 100.
|
||||
|
||||
static const std::string ENCODING_URL; /// "application/x-www-form-urlencoded"
|
||||
static const std::string ENCODING_MULTIPART; /// "multipart/form-data"
|
||||
|
||||
protected:
|
||||
void readUrl(std::istream& istr);
|
||||
@@ -174,20 +210,26 @@ protected:
|
||||
void writeMultipart(std::ostream& ostr);
|
||||
|
||||
private:
|
||||
HTMLForm(const HTMLForm&);
|
||||
HTMLForm& operator = (const HTMLForm&);
|
||||
HTMLForm(const HTMLForm&);
|
||||
HTMLForm& operator = (const HTMLForm&);
|
||||
|
||||
struct Part
|
||||
{
|
||||
std::string name;
|
||||
enum Limits
|
||||
{
|
||||
DFL_FIELD_LIMIT = 100
|
||||
};
|
||||
|
||||
struct Part
|
||||
{
|
||||
std::string name;
|
||||
PartSource* pSource;
|
||||
};
|
||||
|
||||
typedef std::vector<Part> PartVec;
|
||||
|
||||
std::string _encoding;
|
||||
std::string _boundary;
|
||||
PartVec _parts;
|
||||
|
||||
typedef std::vector<Part> PartVec;
|
||||
|
||||
int _fieldLimit;
|
||||
std::string _encoding;
|
||||
std::string _boundary;
|
||||
PartVec _parts;
|
||||
};
|
||||
|
||||
|
||||
@@ -206,6 +248,12 @@ inline const std::string& HTMLForm::boundary() const
|
||||
}
|
||||
|
||||
|
||||
inline int HTMLForm::getFieldLimit() const
|
||||
{
|
||||
return _fieldLimit;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
|
@@ -66,11 +66,16 @@ public:
|
||||
/// Creates a HTTPBasicCredentials object with the authentication information
|
||||
/// from the given request.
|
||||
///
|
||||
/// Throws a NotAuthenticatedException if the request does
|
||||
/// not contain basic authentication information.
|
||||
/// Throws a NotAuthenticatedException if the request does
|
||||
/// not contain basic authentication information.
|
||||
|
||||
~HTTPBasicCredentials();
|
||||
/// Destroys the HTTPBasicCredentials.
|
||||
explicit HTTPBasicCredentials(const std::string& authInfo);
|
||||
/// Creates a HTTPBasicCredentials object with the authentication information
|
||||
/// in the given string. The authentication information can be extracted
|
||||
/// from a HTTPRequest object by calling HTTPRequest::getCredentials().
|
||||
|
||||
~HTTPBasicCredentials();
|
||||
/// Destroys the HTTPBasicCredentials.
|
||||
|
||||
void setUsername(const std::string& username);
|
||||
/// Sets the username.
|
||||
@@ -87,14 +92,20 @@ public:
|
||||
void authenticate(HTTPRequest& request);
|
||||
/// Adds authentication information to the given HTTPRequest.
|
||||
|
||||
static const std::string SCHEME;
|
||||
static const std::string SCHEME;
|
||||
|
||||
protected:
|
||||
void parseAuthInfo(const std::string& authInfo);
|
||||
/// Extracts username and password from Basic authentication info
|
||||
/// by base64-decoding authInfo and splitting the resulting
|
||||
/// string at the ':' delimiter.
|
||||
|
||||
private:
|
||||
HTTPBasicCredentials(const HTTPBasicCredentials&);
|
||||
HTTPBasicCredentials& operator = (const HTTPBasicCredentials);
|
||||
|
||||
std::string _username;
|
||||
std::string _password;
|
||||
HTTPBasicCredentials(const HTTPBasicCredentials&);
|
||||
HTTPBasicCredentials& operator = (const HTTPBasicCredentials&);
|
||||
|
||||
std::string _username;
|
||||
std::string _password;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -62,23 +62,42 @@ public:
|
||||
void setVersion(const std::string& version);
|
||||
/// Sets the HTTP version for this message.
|
||||
|
||||
const std::string& getVersion() const;
|
||||
/// Returns the HTTP version for this message.
|
||||
|
||||
void setContentLength(std::streamsize length);
|
||||
const std::string& getVersion() const;
|
||||
/// Returns the HTTP version for this message.
|
||||
|
||||
void setContentLength(std::streamsize length);
|
||||
/// Sets the Content-Length header.
|
||||
///
|
||||
/// If length is UNKNOWN_CONTENT_LENGTH, removes
|
||||
/// the Content-Length header.
|
||||
|
||||
std::streamsize getContentLength() const;
|
||||
/// Returns the content length for this message,
|
||||
/// which may be UNKNOWN_CONTENT_LENGTH if
|
||||
/// no Content-Length header is present.
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
void setContentLength64(Poco::Int64 length);
|
||||
/// Sets the Content-Length header.
|
||||
///
|
||||
/// If length is UNKNOWN_CONTENT_LENGTH, removes
|
||||
/// the Content-Length header.
|
||||
|
||||
std::streamsize getContentLength() const;
|
||||
///
|
||||
/// In contrast to setContentLength(), this method takes
|
||||
/// a 64-bit integer as content length.
|
||||
|
||||
Poco::Int64 getContentLength64() const;
|
||||
/// Returns the content length for this message,
|
||||
/// which may be UNKNOWN_CONTENT_LENGTH if
|
||||
/// no Content-Length header is present.
|
||||
///
|
||||
/// In contrast to getContentLength(), this method
|
||||
/// always returns a 64-bit integer for content length.
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
void setTransferEncoding(const std::string& transferEncoding);
|
||||
/// Sets the transfer encoding for this message.
|
||||
///
|
||||
void setTransferEncoding(const std::string& transferEncoding);
|
||||
/// Sets the transfer encoding for this message.
|
||||
///
|
||||
/// The value should be either IDENTITY_TRANSFER_CODING
|
||||
/// or CHUNKED_TRANSFER_CODING.
|
||||
|
||||
|
@@ -62,15 +62,19 @@ public:
|
||||
HostEntry();
|
||||
/// Creates an empty HostEntry.
|
||||
|
||||
HostEntry(struct hostent* entry);
|
||||
/// Creates the HostEntry from the data in a hostent structure.
|
||||
HostEntry(struct hostent* entry);
|
||||
/// Creates the HostEntry from the data in a hostent structure.
|
||||
|
||||
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
|
||||
HostEntry(struct addrinfo* info);
|
||||
/// Creates the HostEntry from the data in a Windows addrinfo structure.
|
||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||
HostEntry(struct addrinfo* info);
|
||||
/// Creates the HostEntry from the data in an addrinfo structure.
|
||||
#endif
|
||||
|
||||
HostEntry(const HostEntry& entry);
|
||||
#if defined(POCO_VXWORKS)
|
||||
HostEntry(const std::string& name, const IPAddress& addr);
|
||||
#endif
|
||||
|
||||
HostEntry(const HostEntry& entry);
|
||||
/// Creates the HostEntry by copying another one.
|
||||
|
||||
HostEntry& operator = (const HostEntry& entry);
|
||||
|
@@ -59,12 +59,19 @@ class Net_API MessageHeader: public NameValueCollection
|
||||
///
|
||||
/// There can be more than one name-value pair with the
|
||||
/// same name.
|
||||
///
|
||||
/// MessageHeader supports writing and reading the
|
||||
/// header data in RFC 2822 format.
|
||||
///
|
||||
/// MessageHeader supports writing and reading the
|
||||
/// header data in RFC 2822 format.
|
||||
///
|
||||
/// The maximum number of fields can be restricted
|
||||
/// by calling setFieldLimit(). This is useful to
|
||||
/// defend against certain kinds of denial-of-service
|
||||
/// attacks. The limit is only enforced when parsing
|
||||
/// header fields from a stream, not when programmatically
|
||||
/// adding them. The default limit is 100.
|
||||
{
|
||||
public:
|
||||
MessageHeader();
|
||||
MessageHeader();
|
||||
/// Creates the MessageHeader.
|
||||
|
||||
MessageHeader(const MessageHeader& messageHeader);
|
||||
@@ -99,12 +106,26 @@ public:
|
||||
/// Some basic sanity checking of the input stream is
|
||||
/// performed.
|
||||
///
|
||||
/// Throws a MessageException if the input stream is
|
||||
/// malformed.
|
||||
|
||||
static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
|
||||
/// Splits the given string into separate elements. Elements are expected
|
||||
/// to be separated by commas.
|
||||
/// Throws a MessageException if the input stream is
|
||||
/// malformed.
|
||||
|
||||
int getFieldLimit() const;
|
||||
/// Returns the maximum number of header fields
|
||||
/// allowed.
|
||||
///
|
||||
/// See setFieldLimit() for more information.
|
||||
|
||||
void setFieldLimit(int limit);
|
||||
/// Sets the maximum number of header fields
|
||||
/// allowed. This limit is used to defend certain
|
||||
/// kinds of denial-of-service attacks.
|
||||
/// Specify 0 for unlimited (not recommended).
|
||||
///
|
||||
/// The default limit is 100.
|
||||
|
||||
static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
|
||||
/// Splits the given string into separate elements. Elements are expected
|
||||
/// to be separated by commas.
|
||||
///
|
||||
/// For example, the string
|
||||
/// text/plain; q=0.5, text/html, text/x-dvi; q=0.8
|
||||
@@ -136,18 +157,21 @@ public:
|
||||
///
|
||||
/// Enclosing quotes of parameter values are removed.
|
||||
|
||||
static void quote(const std::string& value, std::string& result, bool allowSpace = false);
|
||||
/// Checks if the value must be quoted. If so, the value is
|
||||
/// appended to result, enclosed in double-quotes.
|
||||
/// Otherwise, the value is appended to result as-is.
|
||||
|
||||
static void quote(const std::string& value, std::string& result, bool allowSpace = false);
|
||||
/// Checks if the value must be quoted. If so, the value is
|
||||
/// appended to result, enclosed in double-quotes.
|
||||
/// Otherwise, the value is appended to result as-is.
|
||||
|
||||
private:
|
||||
enum Limits
|
||||
/// Limits for basic sanity checks when reading a header
|
||||
{
|
||||
MAX_NAME_LENGTH = 256,
|
||||
MAX_VALUE_LENGTH = 4096
|
||||
};
|
||||
enum Limits
|
||||
/// Limits for basic sanity checks when reading a header
|
||||
{
|
||||
MAX_NAME_LENGTH = 256,
|
||||
MAX_VALUE_LENGTH = 4096,
|
||||
DFL_FIELD_LIMIT = 100
|
||||
};
|
||||
|
||||
int _fieldLimit;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -69,6 +69,7 @@ POCO_DECLARE_EXCEPTION(Net_API, FTPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, SMTPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, HTMLFormException, NetException)
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@@ -236,11 +236,23 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if POCO_OS != POCO_OS_VXWORKS
|
||||
#define POCO_HAVE_ADDRINFO 1
|
||||
#endif
|
||||
|
||||
|
||||
#if (POCO_OS == POCO_OS_HPUX) || (POCO_OS == POCO_OS_SOLARIS) || (POCO_OS == POCO_OS_WINDOWS_CE)
|
||||
#define POCO_BROKEN_TIMEOUTS 1
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_ADDRINFO)
|
||||
#if !defined(AI_ADDRCONFIG)
|
||||
#define AI_ADDRCONFIG 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_SALEN)
|
||||
#define poco_set_sa_len(pSA, len) (pSA)->sa_len = (len)
|
||||
#define poco_set_sin_len(pSA) (pSA)->sin_len = sizeof(struct sockaddr_in)
|
||||
|
212
Net/src/DNS.cpp
212
Net/src/DNS.cpp
@@ -51,7 +51,7 @@ using Poco::IOException;
|
||||
|
||||
namespace
|
||||
{
|
||||
class NetworkInitializer
|
||||
class NetworkInitializer
|
||||
{
|
||||
public:
|
||||
NetworkInitializer()
|
||||
@@ -61,9 +61,9 @@ namespace
|
||||
|
||||
~NetworkInitializer()
|
||||
{
|
||||
Poco::Net::uninitializeNetwork();
|
||||
}
|
||||
};
|
||||
Poco::Net::uninitializeNetwork();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -75,37 +75,37 @@ HostEntry DNS::hostByName(const std::string& hostname)
|
||||
{
|
||||
NetworkInitializer networkInitializer;
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||
struct addrinfo* pAI;
|
||||
struct addrinfo hints;
|
||||
std::memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
|
||||
int rc = getaddrinfo(hostname.c_str(), NULL, &hints, &pAI);
|
||||
if (rc == 0)
|
||||
{
|
||||
HostEntry result(pAI);
|
||||
freeaddrinfo(pAI);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, hostname);
|
||||
}
|
||||
hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
|
||||
int rc = getaddrinfo(hostname.c_str(), NULL, &hints, &pAI);
|
||||
if (rc == 0)
|
||||
{
|
||||
HostEntry result(pAI);
|
||||
freeaddrinfo(pAI);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, hostname);
|
||||
}
|
||||
#elif defined(POCO_VXWORKS)
|
||||
int addr = hostGetByName(const_cast<char*>(hostname.c_str()));
|
||||
if (addr != ERROR)
|
||||
{
|
||||
return HostEntry(hostname, IPAddress(&addr, sizeof(addr)));
|
||||
}
|
||||
int addr = hostGetByName(const_cast<char*>(hostname.c_str()));
|
||||
if (addr != ERROR)
|
||||
{
|
||||
return HostEntry(hostname, IPAddress(&addr, sizeof(addr)));
|
||||
}
|
||||
#else
|
||||
struct hostent* he = gethostbyname(hostname.c_str());
|
||||
if (he)
|
||||
{
|
||||
return HostEntry(he);
|
||||
}
|
||||
struct hostent* he = gethostbyname(hostname.c_str());
|
||||
if (he)
|
||||
{
|
||||
return HostEntry(he);
|
||||
}
|
||||
#endif
|
||||
error(lastError(), hostname); // will throw an appropriate exception
|
||||
throw NetException(); // to silence compiler
|
||||
error(lastError(), hostname); // will throw an appropriate exception
|
||||
throw NetException(); // to silence compiler
|
||||
}
|
||||
|
||||
|
||||
@@ -113,46 +113,46 @@ HostEntry DNS::hostByAddress(const IPAddress& address)
|
||||
{
|
||||
NetworkInitializer networkInitializer;
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||
SocketAddress sa(address, 0);
|
||||
static char fqname[1024];
|
||||
int rc = getnameinfo(sa.addr(), sa.length(), fqname, sizeof(fqname), NULL, 0, NI_NAMEREQD);
|
||||
if (rc == 0)
|
||||
{
|
||||
struct addrinfo* pAI;
|
||||
struct addrinfo hints;
|
||||
std::memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
|
||||
rc = getaddrinfo(fqname, NULL, &hints, &pAI);
|
||||
if (rc == 0)
|
||||
{
|
||||
HostEntry result(pAI);
|
||||
freeaddrinfo(pAI);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, address.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, address.toString());
|
||||
}
|
||||
if (rc == 0)
|
||||
{
|
||||
struct addrinfo* pAI;
|
||||
struct addrinfo hints;
|
||||
std::memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG;
|
||||
rc = getaddrinfo(fqname, NULL, &hints, &pAI);
|
||||
if (rc == 0)
|
||||
{
|
||||
HostEntry result(pAI);
|
||||
freeaddrinfo(pAI);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, address.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aierror(rc, address.toString());
|
||||
}
|
||||
#elif defined(POCO_VXWORKS)
|
||||
char name[MAXHOSTNAMELEN + 1];
|
||||
if (hostGetByAddr(*reinterpret_cast<const int*>(address.addr()), name) == OK)
|
||||
{
|
||||
return HostEntry(std::string(name), address);
|
||||
}
|
||||
char name[MAXHOSTNAMELEN + 1];
|
||||
if (hostGetByAddr(*reinterpret_cast<const int*>(address.addr()), name) == OK)
|
||||
{
|
||||
return HostEntry(std::string(name), address);
|
||||
}
|
||||
#else
|
||||
struct hostent* he = gethostbyaddr(reinterpret_cast<const char*>(address.addr()), address.length(), address.af());
|
||||
if (he)
|
||||
{
|
||||
return HostEntry(he);
|
||||
}
|
||||
struct hostent* he = gethostbyaddr(reinterpret_cast<const char*>(address.addr()), address.length(), address.af());
|
||||
if (he)
|
||||
{
|
||||
return HostEntry(he);
|
||||
}
|
||||
#endif
|
||||
int err = lastError();
|
||||
int err = lastError();
|
||||
error(err, address.toString()); // will throw an appropriate exception
|
||||
throw NetException(); // to silence compiler
|
||||
}
|
||||
@@ -160,11 +160,11 @@ HostEntry DNS::hostByAddress(const IPAddress& address)
|
||||
|
||||
HostEntry DNS::resolve(const std::string& address)
|
||||
{
|
||||
NetworkInitializer networkInitializer;
|
||||
NetworkInitializer networkInitializer;
|
||||
|
||||
IPAddress ip;
|
||||
if (IPAddress::tryParse(address, ip))
|
||||
return hostByAddress(ip);
|
||||
IPAddress ip;
|
||||
if (IPAddress::tryParse(address, ip))
|
||||
return hostByAddress(ip);
|
||||
else
|
||||
return hostByName(address);
|
||||
}
|
||||
@@ -172,11 +172,11 @@ HostEntry DNS::resolve(const std::string& address)
|
||||
|
||||
IPAddress DNS::resolveOne(const std::string& address)
|
||||
{
|
||||
NetworkInitializer networkInitializer;
|
||||
NetworkInitializer networkInitializer;
|
||||
|
||||
const HostEntry& entry = resolve(address);
|
||||
if (!entry.addresses().empty())
|
||||
return entry.addresses()[0];
|
||||
const HostEntry& entry = resolve(address);
|
||||
if (!entry.addresses().empty())
|
||||
return entry.addresses()[0];
|
||||
else
|
||||
throw NoAddressFoundException(address);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ IPAddress DNS::resolveOne(const std::string& address)
|
||||
|
||||
HostEntry DNS::thisHost()
|
||||
{
|
||||
return hostByName(hostName());
|
||||
return hostByName(hostName());
|
||||
}
|
||||
|
||||
|
||||
@@ -195,11 +195,11 @@ void DNS::flushCache()
|
||||
|
||||
std::string DNS::hostName()
|
||||
{
|
||||
NetworkInitializer networkInitializer;
|
||||
NetworkInitializer networkInitializer;
|
||||
|
||||
char buffer[256];
|
||||
int rc = gethostname(buffer, sizeof(buffer));
|
||||
if (rc == 0)
|
||||
char buffer[256];
|
||||
int rc = gethostname(buffer, sizeof(buffer));
|
||||
if (rc == 0)
|
||||
return std::string(buffer);
|
||||
else
|
||||
throw NetException("Cannot get host name");
|
||||
@@ -243,30 +243,30 @@ void DNS::error(int code, const std::string& arg)
|
||||
void DNS::aierror(int code, const std::string& arg)
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
switch (code)
|
||||
{
|
||||
case EAI_AGAIN:
|
||||
throw DNSException("Temporary DNS error while resolving", arg);
|
||||
case EAI_FAIL:
|
||||
throw DNSException("Non recoverable DNS error while resolving", arg);
|
||||
switch (code)
|
||||
{
|
||||
case EAI_AGAIN:
|
||||
throw DNSException("Temporary DNS error while resolving", arg);
|
||||
case EAI_FAIL:
|
||||
throw DNSException("Non recoverable DNS error while resolving", arg);
|
||||
#if !defined(_WIN32) // EAI_NODATA and EAI_NONAME have the same value
|
||||
case EAI_NODATA:
|
||||
throw NoAddressFoundException(arg);
|
||||
case EAI_NODATA:
|
||||
throw NoAddressFoundException(arg);
|
||||
#endif
|
||||
case EAI_NONAME:
|
||||
throw HostNotFoundException(arg);
|
||||
case EAI_NONAME:
|
||||
throw HostNotFoundException(arg);
|
||||
#if defined(EAI_SYSTEM)
|
||||
case EAI_SYSTEM:
|
||||
error(lastError(), arg);
|
||||
break;
|
||||
case EAI_SYSTEM:
|
||||
error(lastError(), arg);
|
||||
break;
|
||||
#endif
|
||||
#if defined(_WIN32)
|
||||
case WSANO_DATA: // may happen on XP
|
||||
throw HostNotFoundException(arg);
|
||||
case WSANO_DATA: // may happen on XP
|
||||
throw HostNotFoundException(arg);
|
||||
#endif
|
||||
default:
|
||||
throw DNSException("EAI", NumberFormatter::format(code));
|
||||
}
|
||||
default:
|
||||
throw DNSException("EAI", NumberFormatter::format(code));
|
||||
}
|
||||
#endif // POCO_HAVE_IPv6
|
||||
}
|
||||
|
||||
@@ -279,24 +279,24 @@ static Poco::AtomicCounter initializeCount;
|
||||
void initializeNetwork()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (++initializeCount == 1)
|
||||
{
|
||||
WORD version = MAKEWORD(2, 2);
|
||||
WSADATA data;
|
||||
if (WSAStartup(version, &data) != 0)
|
||||
throw NetException("Failed to initialize network subsystem");
|
||||
}
|
||||
if (++initializeCount == 1)
|
||||
{
|
||||
WORD version = MAKEWORD(2, 2);
|
||||
WSADATA data;
|
||||
if (WSAStartup(version, &data) != 0)
|
||||
throw NetException("Failed to initialize network subsystem");
|
||||
}
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uninitializeNetwork()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (--initializeCount == 0)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
if (--initializeCount == 0)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
|
@@ -63,12 +63,22 @@ DialogSocket::DialogSocket(const SocketAddress& address):
|
||||
|
||||
|
||||
DialogSocket::DialogSocket(const Socket& socket):
|
||||
StreamSocket(socket),
|
||||
_pBuffer(0),
|
||||
_pNext(0),
|
||||
_pEnd(0)
|
||||
StreamSocket(socket),
|
||||
_pBuffer(0),
|
||||
_pNext(0),
|
||||
_pEnd(0)
|
||||
{
|
||||
allocBuffer();
|
||||
allocBuffer();
|
||||
}
|
||||
|
||||
|
||||
DialogSocket::DialogSocket(const DialogSocket& socket):
|
||||
StreamSocket(socket),
|
||||
_pBuffer(0),
|
||||
_pNext(0),
|
||||
_pEnd(0)
|
||||
{
|
||||
allocBuffer();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -41,10 +41,10 @@
|
||||
#include "Poco/Net/MultipartWriter.h"
|
||||
#include "Poco/Net/MultipartReader.h"
|
||||
#include "Poco/Net/NullPartHandler.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/NullStream.h"
|
||||
#include "Poco/CountingStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/String.h"
|
||||
#include <sstream>
|
||||
@@ -66,32 +66,37 @@ const std::string HTMLForm::ENCODING_MULTIPART = "multipart/form-data";
|
||||
|
||||
|
||||
HTMLForm::HTMLForm():
|
||||
_encoding(ENCODING_URL)
|
||||
_fieldLimit(DFL_FIELD_LIMIT),
|
||||
_encoding(ENCODING_URL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
HTMLForm::HTMLForm(const std::string& encoding):
|
||||
_encoding(encoding)
|
||||
_fieldLimit(DFL_FIELD_LIMIT),
|
||||
_encoding(encoding)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler)
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler):
|
||||
_fieldLimit(DFL_FIELD_LIMIT)
|
||||
{
|
||||
load(request, requestBody, handler);
|
||||
load(request, requestBody, handler);
|
||||
}
|
||||
|
||||
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody)
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody):
|
||||
_fieldLimit(DFL_FIELD_LIMIT)
|
||||
{
|
||||
load(request, requestBody);
|
||||
load(request, requestBody);
|
||||
}
|
||||
|
||||
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request)
|
||||
HTMLForm::HTMLForm(const HTTPRequest& request):
|
||||
_fieldLimit(DFL_FIELD_LIMIT)
|
||||
{
|
||||
load(request);
|
||||
load(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,9 +178,22 @@ void HTMLForm::read(std::istream& istr, PartHandler& handler)
|
||||
}
|
||||
|
||||
|
||||
void HTMLForm::read(std::istream& istr)
|
||||
{
|
||||
readUrl(istr);
|
||||
}
|
||||
|
||||
|
||||
void HTMLForm::read(const std::string& queryString)
|
||||
{
|
||||
std::istringstream istr(queryString);
|
||||
readUrl(istr);
|
||||
}
|
||||
|
||||
|
||||
void HTMLForm::prepareSubmit(HTTPRequest& request)
|
||||
{
|
||||
if (request.getMethod() == HTTPRequest::HTTP_POST || request.getMethod() == HTTPRequest::HTTP_PUT)
|
||||
if (request.getMethod() == HTTPRequest::HTTP_POST || request.getMethod() == HTTPRequest::HTTP_PUT)
|
||||
{
|
||||
if (_encoding == ENCODING_URL)
|
||||
{
|
||||
@@ -241,14 +259,17 @@ void HTMLForm::write(std::ostream& ostr)
|
||||
|
||||
void HTMLForm::readUrl(std::istream& istr)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
int ch = istr.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
while (ch != eof && ch != '=' && ch != '&')
|
||||
int fields = 0;
|
||||
int ch = istr.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
if (_fieldLimit > 0 && fields == _fieldLimit)
|
||||
throw HTMLFormException("Too many form fields");
|
||||
std::string name;
|
||||
std::string value;
|
||||
while (ch != eof && ch != '=' && ch != '&')
|
||||
{
|
||||
if (ch == '+') ch = ' ';
|
||||
name += (char) ch;
|
||||
@@ -266,24 +287,28 @@ void HTMLForm::readUrl(std::istream& istr)
|
||||
}
|
||||
std::string decodedName;
|
||||
std::string decodedValue;
|
||||
URI::decode(name, decodedName);
|
||||
URI::decode(value, decodedValue);
|
||||
add(decodedName, decodedValue);
|
||||
if (ch == '&') ch = istr.get();
|
||||
}
|
||||
URI::decode(name, decodedName);
|
||||
URI::decode(value, decodedValue);
|
||||
add(decodedName, decodedValue);
|
||||
++fields;
|
||||
if (ch == '&') ch = istr.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
MultipartReader reader(istr, _boundary);
|
||||
while (reader.hasNextPart())
|
||||
{
|
||||
MessageHeader header;
|
||||
reader.nextPart(header);
|
||||
std::string disp;
|
||||
int fields = 0;
|
||||
MultipartReader reader(istr, _boundary);
|
||||
while (reader.hasNextPart())
|
||||
{
|
||||
if (_fieldLimit > 0 && fields == _fieldLimit)
|
||||
throw HTMLFormException("Too many form fields");
|
||||
MessageHeader header;
|
||||
reader.nextPart(header);
|
||||
std::string disp;
|
||||
NameValueCollection params;
|
||||
if (header.has("Content-Disposition"))
|
||||
{
|
||||
@@ -306,10 +331,11 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
|
||||
{
|
||||
value += (char) ch;
|
||||
ch = istr.get();
|
||||
}
|
||||
add(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
add(name, value);
|
||||
}
|
||||
++fields;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -363,4 +389,12 @@ void HTMLForm::writeMultipart(std::ostream& ostr)
|
||||
}
|
||||
|
||||
|
||||
void HTMLForm::setFieldLimit(int limit)
|
||||
{
|
||||
poco_assert (limit >= 0);
|
||||
|
||||
_fieldLimit = limit;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@@ -69,29 +69,20 @@ HTTPBasicCredentials::HTTPBasicCredentials(const std::string& username, const st
|
||||
|
||||
HTTPBasicCredentials::HTTPBasicCredentials(const HTTPRequest& request)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
std::string scheme;
|
||||
std::string authInfo;
|
||||
request.getCredentials(scheme, authInfo);
|
||||
if (icompare(scheme, SCHEME) == 0)
|
||||
{
|
||||
parseAuthInfo(authInfo);
|
||||
}
|
||||
else throw NotAuthenticatedException("Basic authentication expected");
|
||||
}
|
||||
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
request.getCredentials(scheme, info);
|
||||
if (icompare(scheme, SCHEME) == 0)
|
||||
{
|
||||
std::istringstream istr(info);
|
||||
Base64Decoder decoder(istr);
|
||||
int ch = decoder.get();
|
||||
while (ch != eof && ch != ':')
|
||||
{
|
||||
_username += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
if (ch == ':') ch = decoder.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
_password += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
}
|
||||
else throw NotAuthenticatedException("Basic authentication expected");
|
||||
|
||||
HTTPBasicCredentials::HTTPBasicCredentials(const std::string& authInfo)
|
||||
{
|
||||
parseAuthInfo(authInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,4 +114,25 @@ void HTTPBasicCredentials::authenticate(HTTPRequest& request)
|
||||
}
|
||||
|
||||
|
||||
void HTTPBasicCredentials::parseAuthInfo(const std::string& authInfo)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
std::istringstream istr(authInfo);
|
||||
Base64Decoder decoder(istr);
|
||||
int ch = decoder.get();
|
||||
while (ch != eof && ch != ':')
|
||||
{
|
||||
_username += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
if (ch == ':') ch = decoder.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
_password += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@@ -90,30 +90,52 @@ void HTTPMessage::setVersion(const std::string& version)
|
||||
|
||||
void HTTPMessage::setContentLength(std::streamsize length)
|
||||
{
|
||||
if (length != UNKNOWN_CONTENT_LENGTH)
|
||||
set(CONTENT_LENGTH, NumberFormatter::format(length));
|
||||
if (length != UNKNOWN_CONTENT_LENGTH)
|
||||
set(CONTENT_LENGTH, NumberFormatter::format(length));
|
||||
else
|
||||
erase(CONTENT_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::streamsize HTTPMessage::getContentLength() const
|
||||
{
|
||||
const std::string& contentLength = get(CONTENT_LENGTH, EMPTY);
|
||||
if (!contentLength.empty())
|
||||
{
|
||||
if (sizeof(std::streamsize) == sizeof(Poco::Int64))
|
||||
return static_cast<std::streamsize>(NumberParser::parse64(contentLength));
|
||||
else
|
||||
return static_cast<std::streamsize>(NumberParser::parse(contentLength));
|
||||
}
|
||||
else return UNKNOWN_CONTENT_LENGTH;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
void HTTPMessage::setContentLength64(Poco::Int64 length)
|
||||
{
|
||||
if (length != UNKNOWN_CONTENT_LENGTH)
|
||||
set(CONTENT_LENGTH, NumberFormatter::format(length));
|
||||
else
|
||||
erase(CONTENT_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
Poco::Int64 HTTPMessage::getContentLength64() const
|
||||
{
|
||||
const std::string& contentLength = get(CONTENT_LENGTH, EMPTY);
|
||||
if (!contentLength.empty())
|
||||
{
|
||||
if (sizeof(std::streamsize) == sizeof(Poco::Int64))
|
||||
return static_cast<std::streamsize>(NumberParser::parse64(contentLength));
|
||||
else
|
||||
return static_cast<std::streamsize>(NumberParser::parse(contentLength));
|
||||
return NumberParser::parse64(contentLength);
|
||||
}
|
||||
else return UNKNOWN_CONTENT_LENGTH;
|
||||
}
|
||||
#endif // defined(POCO_HAVE_INT64)
|
||||
|
||||
|
||||
void HTTPMessage::setTransferEncoding(const std::string& transferEncoding)
|
||||
{
|
||||
if (icompare(transferEncoding, IDENTITY_TRANSFER_ENCODING) == 0)
|
||||
if (icompare(transferEncoding, IDENTITY_TRANSFER_ENCODING) == 0)
|
||||
erase(TRANSFER_ENCODING);
|
||||
else
|
||||
set(TRANSFER_ENCODING, transferEncoding);
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Ascii.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
using Poco::NumberFormatter;
|
||||
@@ -150,11 +151,11 @@ void HTTPRequest::setCookies(const NameValueCollection& cookies)
|
||||
|
||||
void HTTPRequest::getCookies(NameValueCollection& cookies) const
|
||||
{
|
||||
NameValueCollection::ConstIterator it = find(COOKIE);
|
||||
while (it != end() && it->first == COOKIE)
|
||||
{
|
||||
splitParameters(it->second.begin(), it->second.end(), cookies);
|
||||
++it;
|
||||
NameValueCollection::ConstIterator it = find(COOKIE);
|
||||
while (it != end() && Poco::icompare(it->first, COOKIE) == 0)
|
||||
{
|
||||
splitParameters(it->second.begin(), it->second.end(), cookies);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/Ascii.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
using Poco::DateTime;
|
||||
@@ -198,12 +199,12 @@ void HTTPResponse::addCookie(const HTTPCookie& cookie)
|
||||
|
||||
void HTTPResponse::getCookies(std::vector<HTTPCookie>& cookies) const
|
||||
{
|
||||
cookies.clear();
|
||||
NameValueCollection::ConstIterator it = find(SET_COOKIE);
|
||||
while (it != end() && it->first == SET_COOKIE)
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
splitParameters(it->second.begin(), it->second.end(), nvc);
|
||||
cookies.clear();
|
||||
NameValueCollection::ConstIterator it = find(SET_COOKIE);
|
||||
while (it != end() && Poco::icompare(it->first, SET_COOKIE) == 0)
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
splitParameters(it->second.begin(), it->second.end(), nvc);
|
||||
cookies.push_back(HTTPCookie(nvc));
|
||||
++it;
|
||||
}
|
||||
|
@@ -116,12 +116,16 @@ void HTTPServerResponseImpl::sendFile(const std::string& path, const std::string
|
||||
poco_assert (!_pStream);
|
||||
|
||||
File f(path);
|
||||
Timestamp dateTime = f.getLastModified();
|
||||
File::FileSize length = f.getSize();
|
||||
set("Last-Modified", DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
|
||||
setContentLength(static_cast<int>(length));
|
||||
setContentType(mediaType);
|
||||
setChunkedTransferEncoding(false);
|
||||
Timestamp dateTime = f.getLastModified();
|
||||
File::FileSize length = f.getSize();
|
||||
set("Last-Modified", DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
|
||||
#if defined(POCO_HAVE_INT64)
|
||||
setContentLength64(length);
|
||||
#else
|
||||
setContentLength(static_cast<int>(length));
|
||||
#endif
|
||||
setContentType(mediaType);
|
||||
setChunkedTransferEncoding(false);
|
||||
|
||||
Poco::FileInputStream istr(path);
|
||||
if (istr.good())
|
||||
|
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// HTTPStreamFactory.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/src/HTTPStreamFactory.cpp#3 $
|
||||
// $Id: //poco/1.4/Net/src/HTTPStreamFactory.cpp#2 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTP
|
||||
// Module: HTTPStreamFactory
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// Copyright (c) 2005-2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
@@ -39,10 +39,13 @@
|
||||
#include "Poco/Net/HTTPIOStream.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPCredentials.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/URIStreamOpener.h"
|
||||
#include "Poco/UnbufferedStreamBuf.h"
|
||||
#include "Poco/NullStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
|
||||
|
||||
using Poco::URIStreamFactory;
|
||||
@@ -86,39 +89,57 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
|
||||
{
|
||||
poco_assert (uri.getScheme() == "http");
|
||||
|
||||
URI resolvedURI(uri);
|
||||
URI proxyUri;
|
||||
HTTPClientSession* pSession = 0;
|
||||
bool retry = false;
|
||||
URI resolvedURI(uri);
|
||||
URI proxyUri;
|
||||
HTTPClientSession* pSession = 0;
|
||||
HTTPResponse res;
|
||||
bool retry = false;
|
||||
bool authorize = false;
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
|
||||
|
||||
if (proxyUri.empty())
|
||||
pSession->setProxy(_proxyHost, _proxyPort);
|
||||
else
|
||||
pSession->setProxy(proxyUri.getHost(), proxyUri.getPort());
|
||||
pSession->setProxyCredentials(_proxyUsername, _proxyPassword);
|
||||
|
||||
std::string path = resolvedURI.getPathAndQuery();
|
||||
if (path.empty()) path = "/";
|
||||
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
pSession->sendRequest(req);
|
||||
HTTPResponse res;
|
||||
std::istream& rs = pSession->receiveResponse(res);
|
||||
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||
|
||||
res.getStatus() == HTTPResponse::HTTP_FOUND ||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!pSession)
|
||||
{
|
||||
pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
|
||||
|
||||
if (proxyUri.empty())
|
||||
pSession->setProxy(_proxyHost, _proxyPort);
|
||||
else
|
||||
pSession->setProxy(proxyUri.getHost(), proxyUri.getPort());
|
||||
pSession->setProxyCredentials(_proxyUsername, _proxyPassword);
|
||||
}
|
||||
|
||||
std::string path = resolvedURI.getPathAndQuery();
|
||||
if (path.empty()) path = "/";
|
||||
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
|
||||
if (authorize)
|
||||
{
|
||||
HTTPCredentials::extractCredentials(uri, username, password);
|
||||
HTTPCredentials cred(username, password);
|
||||
cred.authenticate(req, res);
|
||||
}
|
||||
|
||||
pSession->sendRequest(req);
|
||||
std::istream& rs = pSession->receiveResponse(res);
|
||||
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||
|
||||
res.getStatus() == HTTPResponse::HTTP_FOUND ||
|
||||
res.getStatus() == HTTPResponse::HTTP_SEE_OTHER ||
|
||||
res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
|
||||
if (moved)
|
||||
{
|
||||
resolvedURI.resolve(res.get("Location"));
|
||||
throw URIRedirection(resolvedURI.toString());
|
||||
}
|
||||
else if (res.getStatus() == HTTPResponse::HTTP_OK)
|
||||
if (moved)
|
||||
{
|
||||
resolvedURI.resolve(res.get("Location"));
|
||||
if (!username.empty())
|
||||
{
|
||||
resolvedURI.setUserInfo(username + ":" + password);
|
||||
}
|
||||
throw URIRedirection(resolvedURI.toString());
|
||||
}
|
||||
else if (res.getStatus() == HTTPResponse::HTTP_OK)
|
||||
{
|
||||
return new HTTPResponseStream(rs, pSession);
|
||||
}
|
||||
@@ -130,16 +151,20 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
|
||||
// single request via the proxy. 305 responses MUST only be generated by origin servers.
|
||||
// only use for one single request!
|
||||
proxyUri.resolve(res.get("Location"));
|
||||
delete pSession; pSession = 0;
|
||||
retry = true; // only allow useproxy once
|
||||
}
|
||||
else
|
||||
{
|
||||
throw HTTPException(res.getReason(), uri.toString());
|
||||
}
|
||||
}
|
||||
while(retry);
|
||||
throw HTTPException("Too many redirects", uri.toString());
|
||||
delete pSession; pSession = 0;
|
||||
retry = true; // only allow useproxy once
|
||||
}
|
||||
else if (res.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED && !authorize)
|
||||
{
|
||||
authorize = true;
|
||||
retry = true;
|
||||
Poco::NullOutputStream null;
|
||||
Poco::StreamCopier::copyStream(rs, null);
|
||||
}
|
||||
else throw HTTPException(res.getReason(), uri.toString());
|
||||
}
|
||||
while (retry);
|
||||
throw HTTPException("Too many redirects", uri.toString());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
@@ -74,7 +74,7 @@ HostEntry::HostEntry(struct hostent* entry)
|
||||
}
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
|
||||
|
||||
|
||||
HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
@@ -91,15 +91,17 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
{
|
||||
switch (ai->ai_addr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
case AF_INET:
|
||||
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in*>(ai->ai_addr)->sin_addr, sizeof(in_addr)));
|
||||
break;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
case AF_INET6:
|
||||
_addresses.push_back(IPAddress(&reinterpret_cast<struct sockaddr_in6*>(ai->ai_addr)->sin6_addr, sizeof(in6_addr), reinterpret_cast<struct sockaddr_in6*>(ai->ai_addr)->sin6_scope_id));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,9 +112,9 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
|
||||
|
||||
|
||||
HostEntry::HostEntry(const std::string& name, const IPAddress& addr):
|
||||
_name(name)
|
||||
_name(name)
|
||||
{
|
||||
_addresses.push_back(addr);
|
||||
_addresses.push_back(addr);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessageHeader.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Net/src/MessageHeader.cpp#3 $
|
||||
// $Id: //poco/1.4/Net/src/MessageHeader.cpp#4 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Messages
|
||||
@@ -44,13 +44,15 @@ namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
MessageHeader::MessageHeader()
|
||||
MessageHeader::MessageHeader():
|
||||
_fieldLimit(DFL_FIELD_LIMIT)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MessageHeader::MessageHeader(const MessageHeader& messageHeader):
|
||||
NameValueCollection(messageHeader)
|
||||
NameValueCollection(messageHeader),
|
||||
_fieldLimit(DFL_FIELD_LIMIT)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -85,14 +87,17 @@ void MessageHeader::read(std::istream& istr)
|
||||
|
||||
std::string name;
|
||||
std::string value;
|
||||
name.reserve(32);
|
||||
value.reserve(64);
|
||||
int ch = buf.sbumpc();
|
||||
while (ch != eof && ch != '\r' && ch != '\n')
|
||||
{
|
||||
name.clear();
|
||||
value.clear();
|
||||
while (ch != eof && ch != ':' && ch != '\n' && name.length() < MAX_NAME_LENGTH) { name += ch; ch = buf.sbumpc(); }
|
||||
name.reserve(32);
|
||||
value.reserve(64);
|
||||
int ch = buf.sbumpc();
|
||||
int fields = 0;
|
||||
while (ch != eof && ch != '\r' && ch != '\n')
|
||||
{
|
||||
if (_fieldLimit > 0 && fields == _fieldLimit)
|
||||
throw MessageException("Too many header fields");
|
||||
name.clear();
|
||||
value.clear();
|
||||
while (ch != eof && ch != ':' && ch != '\n' && name.length() < MAX_NAME_LENGTH) { name += ch; ch = buf.sbumpc(); }
|
||||
if (ch == '\n') { ch = buf.sbumpc(); continue; } // ignore invalid header lines
|
||||
if (ch != ':') throw MessageException("Field name too long/no colon found");
|
||||
if (ch != eof) ch = buf.sbumpc(); // ':'
|
||||
@@ -111,17 +116,32 @@ void MessageHeader::read(std::istream& istr)
|
||||
ch = buf.sbumpc();
|
||||
else if (ch != eof)
|
||||
throw MessageException("Folded field value too long/no CRLF found");
|
||||
}
|
||||
Poco::trimRightInPlace(value);
|
||||
add(name, value);
|
||||
}
|
||||
istr.putback(ch);
|
||||
}
|
||||
Poco::trimRightInPlace(value);
|
||||
add(name, value);
|
||||
++fields;
|
||||
}
|
||||
istr.putback(ch);
|
||||
}
|
||||
|
||||
|
||||
int MessageHeader::getFieldLimit() const
|
||||
{
|
||||
return _fieldLimit;
|
||||
}
|
||||
|
||||
|
||||
void MessageHeader::setFieldLimit(int limit)
|
||||
{
|
||||
poco_assert (limit >= 0);
|
||||
|
||||
_fieldLimit = limit;
|
||||
}
|
||||
|
||||
|
||||
void MessageHeader::splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty)
|
||||
{
|
||||
elements.clear();
|
||||
elements.clear();
|
||||
std::string::const_iterator it = s.begin();
|
||||
std::string::const_iterator end = s.end();
|
||||
std::string elem;
|
||||
|
@@ -66,6 +66,7 @@ POCO_IMPLEMENT_EXCEPTION(FTPException, NetException, "FTP Exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(SMTPException, NetException, "SMTP Exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(POP3Exception, NetException, "POP3 Exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(ICMPException, NetException, "ICMP Exception")
|
||||
POCO_IMPLEMENT_EXCEPTION(HTMLFormException, NetException, "HTML Form Exception")
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// NetworkInterface.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Net/src/NetworkInterface.cpp#3 $
|
||||
// $Id: //poco/1.4/Net/src/NetworkInterface.cpp#9 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: Sockets
|
||||
@@ -292,42 +292,35 @@ bool NetworkInterface::supportsIPv6() const
|
||||
|
||||
NetworkInterface NetworkInterface::forName(const std::string& name, bool requireIPv6)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
NetworkInterfaceList ifs = list();
|
||||
for (NetworkInterfaceList::const_iterator it = ifs.begin(); it != ifs.end(); ++it)
|
||||
{
|
||||
NetworkInterfaceList ifs = list();
|
||||
for (NetworkInterfaceList::const_iterator it = ifs.begin(); it != ifs.end(); ++it)
|
||||
{
|
||||
if (it->name() == name && ((requireIPv6 && it->supportsIPv6()) || !requireIPv6))
|
||||
return *it;
|
||||
}
|
||||
throw InterfaceNotFoundException(name);
|
||||
#else
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
struct ifreq ifr;
|
||||
std::strncpy(ifr.ifr_name, name.c_str(), IFNAMSIZ);
|
||||
DatagramSocket ds(requireIPv6 ? IPAddress::IPv6 : IPAddress::IPv4);
|
||||
ds.impl()->ioctl(SIOCGIFADDR, &ifr);
|
||||
IPAddress addr;
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
if (ifr.ifr_addr.sa_family == AF_INET)
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in*>(&ifr.ifr_addr)->sin_addr, sizeof(struct in_addr));
|
||||
else if (ifr.ifr_addr.sa_family == AF_INET6)
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(&ifr.ifr_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
else
|
||||
throw InterfaceNotFoundException(addr.toString(), "interface has no IP address");
|
||||
int index = if_nametoindex(name.c_str());
|
||||
#else
|
||||
if (ifr.ifr_addr.sa_family == AF_INET)
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in*>(&ifr.ifr_addr)->sin_addr, sizeof(struct in_addr));
|
||||
else
|
||||
throw InterfaceNotFoundException(addr.toString(), "interface has no IP address");
|
||||
int index = 0;
|
||||
#endif
|
||||
return NetworkInterface(name, name, addr, index);
|
||||
#endif
|
||||
return *it;
|
||||
}
|
||||
throw InterfaceNotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NetworkInterface NetworkInterface::forName(const std::string& name, IPVersion ipVersion)
|
||||
{
|
||||
NetworkInterfaceList ifs = list();
|
||||
for (NetworkInterfaceList::const_iterator it = ifs.begin(); it != ifs.end(); ++it)
|
||||
{
|
||||
if (it->name() == name)
|
||||
{
|
||||
if (ipVersion == IPv4_ONLY && it->supportsIPv4())
|
||||
return *it;
|
||||
else if (ipVersion == IPv6_ONLY && it->supportsIPv6())
|
||||
return *it;
|
||||
else if (ipVersion == IPv4_OR_IPv6)
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
throw InterfaceNotFoundException(name);
|
||||
}
|
||||
|
||||
|
||||
NetworkInterface NetworkInterface::forAddress(const IPAddress& addr)
|
||||
{
|
||||
NetworkInterfaceList ifs = list();
|
||||
@@ -374,10 +367,45 @@ NetworkInterface NetworkInterface::forIndex(int i)
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
IPAddress subnetMaskForInterface(const std::string& name, bool isLoopback)
|
||||
{
|
||||
if (isLoopback)
|
||||
{
|
||||
return IPAddress::parse("255.0.0.0");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string subKey("SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\");
|
||||
subKey += name;
|
||||
std::wstring usubKey;
|
||||
Poco::UnicodeConverter::toUTF16(subKey, usubKey);
|
||||
HKEY hKey;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, usubKey.c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||
return IPAddress();
|
||||
wchar_t unetmask[16];
|
||||
DWORD size = sizeof(unetmask);
|
||||
if (RegQueryValueExW(hKey, L"DhcpSubnetMask", NULL, NULL, (LPBYTE) &unetmask, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
if (RegQueryValueExW(hKey, L"SubnetMask", NULL, NULL, (LPBYTE) &unetmask, &size) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hKey);
|
||||
return IPAddress();
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
std::string netmask;
|
||||
Poco::UnicodeConverter::toUTF8(unetmask, netmask);
|
||||
return IPAddress::parse(netmask);
|
||||
}
|
||||
}
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
NetworkInterfaceList result;
|
||||
DWORD rc;
|
||||
|
||||
@@ -403,48 +431,62 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
if (GetAdaptersAddresses(AF_UNSPEC, 0, 0, pAdapterAddresses, &addrLen) == NO_ERROR)
|
||||
{
|
||||
pAddress = pAdapterAddresses;
|
||||
while (pAddress)
|
||||
{
|
||||
if (pAddress->FirstUnicastAddress)
|
||||
{
|
||||
IPAddress addr;
|
||||
switch (pAddress->FirstUnicastAddress->Address.lpSockaddr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
addr = IPAddress(&reinterpret_cast<struct sockaddr_in*>(pAddress->FirstUnicastAddress->Address.lpSockaddr)->sin_addr, sizeof(in_addr));
|
||||
break;
|
||||
case AF_INET6:
|
||||
addr = IPAddress(&reinterpret_cast<struct sockaddr_in6*>(pAddress->FirstUnicastAddress->Address.lpSockaddr)->sin6_addr, sizeof(in6_addr));
|
||||
break;
|
||||
}
|
||||
std::string name(pAddress->AdapterName);
|
||||
std::string displayName;
|
||||
pAddress = pAdapterAddresses;
|
||||
while (pAddress)
|
||||
{
|
||||
if (pAddress->OperStatus == IfOperStatusUp)
|
||||
{
|
||||
PIP_ADAPTER_UNICAST_ADDRESS pUniAddr = pAddress->FirstUnicastAddress;
|
||||
while (pUniAddr)
|
||||
{
|
||||
std::string name(pAddress->AdapterName);
|
||||
std::string displayName;
|
||||
#ifdef POCO_WIN32_UTF8
|
||||
Poco::UnicodeConverter::toUTF8(pAddress->Description, displayName);
|
||||
Poco::UnicodeConverter::toUTF8(pAddress->FriendlyName, displayName);
|
||||
#else
|
||||
char displayNameBuffer[1024];
|
||||
int rc = WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, pAddress->Description, -1, displayNameBuffer, sizeof(displayNameBuffer), NULL, NULL);
|
||||
if (rc) displayName = displayNameBuffer;
|
||||
char displayNameBuffer[1024];
|
||||
int rc = WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, pAddress->FriendlyName, -1, displayNameBuffer, sizeof(displayNameBuffer), NULL, NULL);
|
||||
if (rc) displayName = displayNameBuffer;
|
||||
#endif
|
||||
result.push_back(NetworkInterface(name, displayName, addr, pAddress->Ipv6IfIndex));
|
||||
pAddress = pAddress->Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
else throw NetException("cannot get network adapter list");
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
IPAddress address;
|
||||
IPAddress subnetMask;
|
||||
IPAddress broadcastAddress;
|
||||
switch (pUniAddr->Address.lpSockaddr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
address = IPAddress(&reinterpret_cast<struct sockaddr_in*>(pUniAddr->Address.lpSockaddr)->sin_addr, sizeof(in_addr));
|
||||
subnetMask = subnetMaskForInterface(name, address.isLoopback());
|
||||
if (!address.isLoopback())
|
||||
{
|
||||
broadcastAddress = address;
|
||||
broadcastAddress.mask(subnetMask, IPAddress::broadcast());
|
||||
}
|
||||
result.push_back(NetworkInterface(name, displayName, address, subnetMask, broadcastAddress));
|
||||
break;
|
||||
case AF_INET6:
|
||||
address = IPAddress(&reinterpret_cast<struct sockaddr_in6*>(pUniAddr->Address.lpSockaddr)->sin6_addr, sizeof(in6_addr), reinterpret_cast<struct sockaddr_in6*>(pUniAddr->Address.lpSockaddr)->sin6_scope_id);
|
||||
result.push_back(NetworkInterface(name, displayName, address, pAddress->Ipv6IfIndex));
|
||||
break;
|
||||
}
|
||||
pUniAddr = pUniAddr->Next;
|
||||
}
|
||||
}
|
||||
pAddress = pAddress->Next;
|
||||
}
|
||||
}
|
||||
else throw NetException("cannot get network adapter list");
|
||||
}
|
||||
catch (Poco::Exception&)
|
||||
{
|
||||
delete [] reinterpret_cast<char*>(pAdapterAddresses);
|
||||
throw;
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(pAdapterAddresses);
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
delete [] reinterpret_cast<char*>(pAdapterAddresses);
|
||||
return result;
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
// Add IPv4 loopback interface (not returned by GetAdaptersInfo)
|
||||
result.push_back(NetworkInterface("Loopback", "Loopback Interface", IPAddress("127.0.0.1"), IPAddress("255.0.0.0"), IPAddress(), -1));
|
||||
// Add IPv4 loopback interface (not returned by GetAdaptersInfo)
|
||||
result.push_back(NetworkInterface("Loopback", "Loopback Interface", IPAddress("127.0.0.1"), IPAddress("255.0.0.0"), IPAddress(), -1));
|
||||
// On Windows 2000 we use GetAdaptersInfo.
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pInfo = 0;
|
||||
@@ -471,13 +513,13 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
IPAddress address(std::string(pInfo->IpAddressList.IpAddress.String));
|
||||
if (!address.isWildcard()) // only return interfaces that have an address assigned.
|
||||
{
|
||||
IPAddress subnetMask(std::string(pInfo->IpAddressList.IpMask.String));
|
||||
IPAddress broadcastAddress(address);
|
||||
broadcastAddress.mask(subnetMask, IPAddress("255.255.255.255"));
|
||||
std::string name(pInfo->AdapterName);
|
||||
std::string displayName(pInfo->Description);
|
||||
result.push_back(NetworkInterface(name, displayName, address, subnetMask, broadcastAddress));
|
||||
{
|
||||
IPAddress subnetMask(std::string(pInfo->IpAddressList.IpMask.String));
|
||||
IPAddress broadcastAddress(address);
|
||||
broadcastAddress.mask(subnetMask, IPAddress::broadcast());
|
||||
std::string name(pInfo->AdapterName);
|
||||
std::string displayName(pInfo->Description);
|
||||
result.push_back(NetworkInterface(name, displayName, address, subnetMask, broadcastAddress));
|
||||
}
|
||||
pInfo = pInfo->Next;
|
||||
}
|
||||
@@ -498,6 +540,59 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#elif defined(POCO_VXWORKS)
|
||||
//
|
||||
// VxWorks
|
||||
//
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
NetworkInterfaceList result;
|
||||
|
||||
int ifIndex = 1;
|
||||
char ifName[32];
|
||||
char ifAddr[INET_ADDR_LEN];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (ifIndexToIfName(ifIndex, ifName) == OK)
|
||||
{
|
||||
std::string name(ifName);
|
||||
IPAddress addr;
|
||||
IPAddress mask;
|
||||
IPAddress bcst;
|
||||
if (ifAddrGet(ifName, ifAddr) == OK)
|
||||
{
|
||||
addr = IPAddress(std::string(ifAddr));
|
||||
}
|
||||
int ifMask;
|
||||
if (ifMaskGet(ifName, &ifMask) == OK)
|
||||
{
|
||||
mask = IPAddress(&ifMask, sizeof(ifMask));
|
||||
}
|
||||
if (ifBroadcastGet(ifName, ifAddr) == OK)
|
||||
{
|
||||
bcst = IPAddress(std::string(ifAddr));
|
||||
}
|
||||
result.push_back(NetworkInterface(name, name, addr, mask, bcst));
|
||||
ifIndex++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#elif defined(POCO_OS_FAMILY_BSD) || POCO_OS == POCO_OS_QNX
|
||||
//
|
||||
// BSD variants
|
||||
@@ -536,14 +631,15 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
result.push_back(NetworkInterface(name, name, addr, subnetMask, broadcastAddr));
|
||||
}
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
else if (ifap->ifa_addr->sa_family == AF_INET6)
|
||||
{
|
||||
IPAddress addr(&reinterpret_cast<struct sockaddr_in6*>(ifap->ifa_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
std::string name(ifap->ifa_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, if_nametoindex(ifap->ifa_name)));
|
||||
}
|
||||
else if (ifap->ifa_addr->sa_family == AF_INET6)
|
||||
{
|
||||
Poco::UInt32 ifIndex = if_nametoindex(ifap->ifa_name);
|
||||
IPAddress addr(&reinterpret_cast<struct sockaddr_in6*>(ifap->ifa_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex);
|
||||
std::string name(ifap->ifa_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, ifIndex));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
freeifaddrs(ifaphead);
|
||||
return result;
|
||||
@@ -557,6 +653,68 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
//
|
||||
// Linux
|
||||
//
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
NetworkInterfaceList result;
|
||||
|
||||
struct ifaddrs* ifaces = 0;
|
||||
struct ifaddrs* currIface = 0;
|
||||
|
||||
if (getifaddrs(&ifaces) < 0)
|
||||
throw NetException("cannot get network adapter list");
|
||||
|
||||
try
|
||||
{
|
||||
for (currIface = ifaces; currIface != 0; currIface = currIface->ifa_next)
|
||||
{
|
||||
IPAddress addr;
|
||||
bool haveAddr = false;
|
||||
int ifIndex(-1);
|
||||
switch (currIface->ifa_addr->sa_family)
|
||||
{
|
||||
case AF_INET6:
|
||||
ifIndex = if_nametoindex(currIface->ifa_name);
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(currIface->ifa_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex);
|
||||
haveAddr = true;
|
||||
break;
|
||||
case AF_INET:
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in*>(currIface->ifa_addr)->sin_addr, sizeof(struct in_addr));
|
||||
haveAddr = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (haveAddr)
|
||||
{
|
||||
std::string name(currIface->ifa_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, ifIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
if (ifaces) freeifaddrs(ifaces);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#else // !POCO_HAVE_IPv6
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -599,32 +757,22 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
{
|
||||
const struct ifreq* ifr = reinterpret_cast<const struct ifreq*>(ptr);
|
||||
IPAddress addr;
|
||||
bool haveAddr = false;
|
||||
switch (ifr->ifr_addr.sa_family)
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
case AF_INET6:
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(&ifr->ifr_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
haveAddr = true;
|
||||
break;
|
||||
#endif
|
||||
case AF_INET:
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in*>(&ifr->ifr_addr)->sin_addr, sizeof(struct in_addr));
|
||||
haveAddr = true;
|
||||
bool haveAddr = false;
|
||||
switch (ifr->ifr_addr.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in*>(&ifr->ifr_addr)->sin_addr, sizeof(struct in_addr));
|
||||
haveAddr = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (haveAddr)
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
int index = if_nametoindex(ifr->ifr_name);
|
||||
#else
|
||||
int index = -1;
|
||||
#endif
|
||||
std::string name(ifr->ifr_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, index));
|
||||
}
|
||||
}
|
||||
if (haveAddr)
|
||||
{
|
||||
int index = -1;
|
||||
std::string name(ifr->ifr_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, index));
|
||||
}
|
||||
ptr += sizeof(struct ifreq);
|
||||
}
|
||||
}
|
||||
@@ -641,6 +789,9 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // POCO_HAVE_IPv6
|
||||
|
||||
|
||||
#else
|
||||
//
|
||||
// Non-BSD Unix variants
|
||||
@@ -692,16 +843,18 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
#else
|
||||
len = sizeof(struct sockaddr);
|
||||
#endif
|
||||
IPAddress addr;
|
||||
bool haveAddr = false;
|
||||
switch (ifr->ifr_addr.sa_family)
|
||||
{
|
||||
IPAddress addr;
|
||||
bool haveAddr = false;
|
||||
int ifIndex(-1);
|
||||
switch (ifr->ifr_addr.sa_family)
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
case AF_INET6:
|
||||
if (len < sizeof(struct sockaddr_in6)) len = sizeof(struct sockaddr_in6);
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(&ifr->ifr_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
haveAddr = true;
|
||||
break;
|
||||
case AF_INET6:
|
||||
ifIndex = if_nametoindex(ifr->ifr_name);
|
||||
if (len < sizeof(struct sockaddr_in6)) len = sizeof(struct sockaddr_in6);
|
||||
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(&ifr->ifr_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex);
|
||||
haveAddr = true;
|
||||
break;
|
||||
#endif
|
||||
case AF_INET:
|
||||
if (len < sizeof(struct sockaddr_in)) len = sizeof(struct sockaddr_in);
|
||||
@@ -710,19 +863,14 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (haveAddr)
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
int index = if_nametoindex(ifr->ifr_name);
|
||||
#else
|
||||
int index = -1;
|
||||
#endif
|
||||
std::string name(ifr->ifr_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, index));
|
||||
}
|
||||
len += sizeof(ifr->ifr_name);
|
||||
ptr += len;
|
||||
}
|
||||
if (haveAddr)
|
||||
{
|
||||
std::string name(ifr->ifr_name);
|
||||
result.push_back(NetworkInterface(name, name, addr, ifIndex));
|
||||
}
|
||||
len += sizeof(ifr->ifr_name);
|
||||
ptr += len;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
|
@@ -257,14 +257,18 @@ public:
|
||||
|
||||
void remove(const std::string& key);
|
||||
/// Removes the property with the given key.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
|
||||
void setPropertyEventingMode(bool enabled);
|
||||
/// Enable/Disable property eventing.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
|
||||
void enableEvents(bool enable = true);
|
||||
/// Enables (or disables) events.
|
||||
|
||||
bool eventsEnabled() const;
|
||||
/// Returns true iff events are enabled.
|
||||
|
||||
protected:
|
||||
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
|
||||
/// If the property with the given key exists, stores the property's value
|
||||
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
|
||||
/// If the property with the given key exists, stores the property's value
|
||||
/// in value and returns true. Otherwise, returns false.
|
||||
///
|
||||
/// Must be overridden by subclasses.
|
||||
@@ -298,16 +302,15 @@ private:
|
||||
std::string uncheckedExpand(const std::string& value) const;
|
||||
|
||||
AbstractConfiguration(const AbstractConfiguration&);
|
||||
AbstractConfiguration& operator = (const AbstractConfiguration&);
|
||||
AbstractConfiguration& operator = (const AbstractConfiguration&);
|
||||
|
||||
mutable int _depth;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
|
||||
bool _propertyEventing;
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
mutable int _depth;
|
||||
bool _eventsEnabled;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -54,19 +54,21 @@ class Util_API WinRegistryConfiguration: public AbstractConfiguration
|
||||
/// in the Windows registry.
|
||||
///
|
||||
/// Removing key is not supported. An attempt to remove a key results
|
||||
/// in a NotImplementedException being thrown.
|
||||
/// in a NotImplementedException being thrown.
|
||||
{
|
||||
public:
|
||||
WinRegistryConfiguration(const std::string& rootPath);
|
||||
/// Creates the WinRegistryConfiguration.
|
||||
/// The rootPath must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
/// All further keys are relativ to the root path and can be
|
||||
/// dot seperated, e.g. the path MyService.ServiceName will be converted to
|
||||
/// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\ServiceName.
|
||||
WinRegistryConfiguration(const std::string& rootPath, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryConfiguration.
|
||||
/// The rootPath must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
/// All further keys are relativ to the root path and can be
|
||||
/// dot seperated, e.g. the path MyService.ServiceName will be converted to
|
||||
/// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\ServiceName.
|
||||
/// The extraSam parameter will be passed along to WinRegistryKey, to control
|
||||
/// registry virtualization for example.
|
||||
|
||||
protected:
|
||||
~WinRegistryConfiguration();
|
||||
~WinRegistryConfiguration();
|
||||
/// Destroys the WinRegistryConfiguration.
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
@@ -79,7 +81,8 @@ protected:
|
||||
/// registry format A\B\C, the last entry is the keyName, the rest is returned as path
|
||||
|
||||
private:
|
||||
std::string _rootPath;
|
||||
std::string _rootPath;
|
||||
REGSAM _extraSam;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -55,7 +55,9 @@ namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
AbstractConfiguration::AbstractConfiguration(): _depth(0), _propertyEventing(true)
|
||||
AbstractConfiguration::AbstractConfiguration():
|
||||
_depth(0),
|
||||
_eventsEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -292,13 +294,31 @@ std::string AbstractConfiguration::expand(const std::string& value) const
|
||||
|
||||
void AbstractConfiguration::remove(const std::string& key)
|
||||
{
|
||||
if (_propertyEventing) propertyRemoving(this, key);
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (_eventsEnabled)
|
||||
{
|
||||
propertyRemoving(this, key);
|
||||
}
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
removeRaw(key);
|
||||
}
|
||||
if (_propertyEventing) propertyRemoved(this, key);
|
||||
removeRaw(key);
|
||||
}
|
||||
if (_eventsEnabled)
|
||||
{
|
||||
propertyRemoved(this, key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractConfiguration::enableEvents(bool enable)
|
||||
{
|
||||
_eventsEnabled = enable;
|
||||
}
|
||||
|
||||
|
||||
bool AbstractConfiguration::eventsEnabled() const
|
||||
{
|
||||
return _eventsEnabled;
|
||||
}
|
||||
|
||||
|
||||
@@ -385,19 +405,21 @@ bool AbstractConfiguration::parseBool(const std::string& value)
|
||||
|
||||
void AbstractConfiguration::setRawWithEvent(const std::string& key, std::string value)
|
||||
{
|
||||
KeyValue kv(key, value);
|
||||
if (_propertyEventing) propertyChanging(this, kv);
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
KeyValue kv(key, value);
|
||||
if (_eventsEnabled)
|
||||
{
|
||||
propertyChanging(this, kv);
|
||||
}
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
setRaw(key, value);
|
||||
}
|
||||
if (_propertyEventing) propertyChanged(this, kv);
|
||||
setRaw(key, value);
|
||||
}
|
||||
if (_eventsEnabled)
|
||||
{
|
||||
propertyChanged(this, kv);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractConfiguration::setPropertyEventingMode(bool enabled)
|
||||
{
|
||||
_propertyEventing = enabled;
|
||||
}
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
@@ -34,6 +34,9 @@
|
||||
//
|
||||
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
|
||||
|
||||
#include "Poco/Util/WinRegistryConfiguration.h"
|
||||
#include "Poco/Util/WinRegistryKey.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
@@ -45,10 +48,10 @@ namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
WinRegistryConfiguration::WinRegistryConfiguration(const std::string& rootPath): _rootPath(rootPath)
|
||||
WinRegistryConfiguration::WinRegistryConfiguration(const std::string& rootPath, REGSAM extraSam): _rootPath(rootPath), _extraSam(extraSam)
|
||||
{
|
||||
// rootPath must end with backslash
|
||||
std::string::iterator it = _rootPath.end();
|
||||
// rootPath must end with backslash
|
||||
std::string::iterator it = _rootPath.end();
|
||||
if (*(--it) != '\\')
|
||||
_rootPath.append("\\");
|
||||
}
|
||||
@@ -61,12 +64,12 @@ WinRegistryConfiguration::~WinRegistryConfiguration()
|
||||
|
||||
bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value) const
|
||||
{
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath + ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath, true);
|
||||
bool exists = aKey.exists(keyName);
|
||||
if (exists)
|
||||
{
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath + ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath, true, _extraSam);
|
||||
bool exists = aKey.exists(keyName);
|
||||
if (exists)
|
||||
{
|
||||
WinRegistryKey::Type type = aKey.type(keyName);
|
||||
|
||||
switch (type)
|
||||
@@ -90,10 +93,10 @@ bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value
|
||||
|
||||
void WinRegistryConfiguration::setRaw(const std::string& key, const std::string& value)
|
||||
{
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath);
|
||||
aKey.setString(keyName, value);
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath, false, _extraSam);
|
||||
aKey.setString(keyName, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,13 +113,13 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
|
||||
range.push_back("HKEY_USERS");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath, true);
|
||||
aKey.values(range);
|
||||
aKey.subKeys(range);
|
||||
}
|
||||
{
|
||||
std::string keyName;
|
||||
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
|
||||
WinRegistryKey aKey(fullPath, true, _extraSam);
|
||||
aKey.values(range);
|
||||
aKey.subKeys(range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,3 +145,6 @@ std::string WinRegistryConfiguration::ConvertToRegFormat(const std::string& key,
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // !defined(_WIN32_WCE)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// WinRegistryKey.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Util/src/WinRegistryKey.cpp#14 $
|
||||
// $Id: //poco/1.4/Util/src/WinRegistryKey.cpp#3 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
@@ -34,6 +34,9 @@
|
||||
//
|
||||
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
|
||||
|
||||
#include "Poco/Util/WinRegistryKey.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
@@ -531,3 +534,6 @@ void WinRegistryKey::values(WinRegistryKey::Values& vals)
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // !defined(_WIN32_WCE)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// WinService.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Util/src/WinService.cpp#10 $
|
||||
// $Id: //poco/1.4/Util/src/WinService.cpp#4 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
@@ -34,6 +34,9 @@
|
||||
//
|
||||
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
|
||||
|
||||
#include "Poco/Util/WinService.h"
|
||||
#include "Poco/Util/WinRegistryKey.h"
|
||||
#include "Poco/Thread.h"
|
||||
@@ -261,48 +264,52 @@ WinService::Startup WinService::getStartup() const
|
||||
|
||||
void WinService::setDescription(const std::string& description)
|
||||
{
|
||||
std::string key(REGISTRY_KEY);
|
||||
key += _name;
|
||||
WinRegistryKey regKey(HKEY_LOCAL_MACHINE, key);
|
||||
regKey.setString(REGISTRY_DESCRIPTION, description);
|
||||
std::string key(REGISTRY_KEY);
|
||||
key += _name;
|
||||
WinRegistryKey regKey(HKEY_LOCAL_MACHINE, key);
|
||||
regKey.setString(REGISTRY_DESCRIPTION, description);
|
||||
}
|
||||
|
||||
|
||||
std::string WinService::getDescription() const
|
||||
{
|
||||
std::string key(REGISTRY_KEY);
|
||||
key += _name;
|
||||
WinRegistryKey regKey(HKEY_LOCAL_MACHINE, key, true);
|
||||
return regKey.getString(REGISTRY_DESCRIPTION);
|
||||
std::string key(REGISTRY_KEY);
|
||||
key += _name;
|
||||
WinRegistryKey regKey(HKEY_LOCAL_MACHINE, key, true);
|
||||
return regKey.getString(REGISTRY_DESCRIPTION);
|
||||
}
|
||||
|
||||
|
||||
void WinService::open() const
|
||||
{
|
||||
if (!tryOpen())
|
||||
if (!tryOpen())
|
||||
throw NotFoundException("service does not exist", _name);
|
||||
}
|
||||
|
||||
|
||||
bool WinService::tryOpen() const
|
||||
{
|
||||
if (!_svcHandle)
|
||||
{
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(_name, uname);
|
||||
_svcHandle = OpenServiceW(_scmHandle, uname.c_str(), SERVICE_ALL_ACCESS);
|
||||
std::wstring uname;
|
||||
Poco::UnicodeConverter::toUTF16(_name, uname);
|
||||
_svcHandle = OpenServiceW(_scmHandle, uname.c_str(), SERVICE_ALL_ACCESS);
|
||||
#else
|
||||
_svcHandle = OpenService(_scmHandle, _name.c_str(), SERVICE_ALL_ACCESS);
|
||||
_svcHandle = OpenService(_scmHandle, _name.c_str(), SERVICE_ALL_ACCESS);
|
||||
#endif
|
||||
return _svcHandle != 0;
|
||||
}
|
||||
return _svcHandle != 0;
|
||||
}
|
||||
|
||||
|
||||
void WinService::close() const
|
||||
{
|
||||
if (_svcHandle)
|
||||
{
|
||||
CloseServiceHandle(_svcHandle);
|
||||
}
|
||||
if (_svcHandle)
|
||||
{
|
||||
CloseServiceHandle(_svcHandle);
|
||||
_svcHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,3 +347,6 @@ POCO_LPQUERY_SERVICE_CONFIG WinService::config() const
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // !defined(_WIN32_WCE)
|
||||
|
@@ -6122,12 +6122,13 @@ poolGrow(STRING_POOL *pool)
|
||||
}
|
||||
if (pool->blocks && pool->start == pool->blocks->s) {
|
||||
int blockSize = (int)(pool->end - pool->start)*2;
|
||||
pool->blocks = (BLOCK *)
|
||||
BLOCK *temp = (BLOCK *)
|
||||
pool->mem->realloc_fcn(pool->blocks,
|
||||
(offsetof(BLOCK, s)
|
||||
+ blockSize * sizeof(XML_Char)));
|
||||
if (pool->blocks == NULL)
|
||||
if (temp == NULL)
|
||||
return XML_FALSE;
|
||||
pool->blocks = temp;
|
||||
pool->blocks->size = blockSize;
|
||||
pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
|
||||
pool->start = pool->blocks->s;
|
||||
|
@@ -1,319 +1,318 @@
|
||||
//
|
||||
// ZipStream.cpp
|
||||
//
|
||||
//
|
||||
// ZipStream.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Zip/src/ZipStream.cpp#14 $
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipStream
|
||||
//
|
||||
// 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/Zip/ZipStream.h"
|
||||
#include "Poco/zlib.h"
|
||||
#include "Poco/Zip/ZipArchive.h"
|
||||
#include "Poco/Zip/AutoDetectStream.h"
|
||||
#include "Poco/Zip/PartialStream.h"
|
||||
#include "Poco/Zip/ZipDataInfo.h"
|
||||
#include "Poco/Zip/ZipException.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/InflatingStream.h"
|
||||
#include "Poco/DeflatingStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition):
|
||||
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_ptrBuf(),
|
||||
_ptrOBuf(),
|
||||
_ptrHelper(),
|
||||
_ptrOHelper(),
|
||||
_crc32(Poco::Checksum::TYPE_CRC32),
|
||||
_expectedCrc32(0),
|
||||
_checkCRC(true),
|
||||
_bytesWritten(0),
|
||||
_pHeader(0)
|
||||
{
|
||||
if (fileEntry.isDirectory())
|
||||
return;
|
||||
_expectedCrc32 = fileEntry.getCRC();
|
||||
std::streamoff start = fileEntry.getDataStartPos();
|
||||
std::streamoff end = fileEntry.getDataEndPos();
|
||||
_checkCRC = !fileEntry.searchCRCAndSizesAfterData();
|
||||
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
// Fake init bytes at beginning of stream
|
||||
std::string init = ZipUtil::fakeZLibInitString(fileEntry.getCompressionLevel());
|
||||
|
||||
// Fake adler at end of stream: just some dummy value, not checked anway
|
||||
std::string crc(4, ' ');
|
||||
if (fileEntry.searchCRCAndSizesAfterData())
|
||||
{
|
||||
_ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, start);
|
||||
}
|
||||
else
|
||||
_ptrHelper = new PartialInputStream(istr, start, end, reposition, init, crc);
|
||||
_ptrBuf = new Poco::InflatingInputStream(*_ptrHelper, Poco::InflatingStreamBuf::STREAM_ZIP);
|
||||
}
|
||||
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
|
||||
{
|
||||
if (fileEntry.searchCRCAndSizesAfterData())
|
||||
{
|
||||
_ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start);
|
||||
}
|
||||
else
|
||||
_ptrBuf = new PartialInputStream(istr, start, end, reposition);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Poco::NotImplementedException("Unsupported compression method");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition):
|
||||
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_ptrBuf(),
|
||||
_ptrOBuf(),
|
||||
_ptrHelper(),
|
||||
_ptrOHelper(),
|
||||
_crc32(Poco::Checksum::TYPE_CRC32),
|
||||
_expectedCrc32(0),
|
||||
_checkCRC(false),
|
||||
_bytesWritten(0),
|
||||
_pHeader(&fileEntry)
|
||||
{
|
||||
if (fileEntry.isEncrypted())
|
||||
throw Poco::NotImplementedException("Encryption not supported");
|
||||
|
||||
if (fileEntry.isDirectory())
|
||||
{
|
||||
// only header, no payload, zero crc
|
||||
fileEntry.setSearchCRCAndSizesAfterData(false);
|
||||
fileEntry.setCompressedSize(0);
|
||||
fileEntry.setUncompressedSize(0);
|
||||
fileEntry.setCRC(0);
|
||||
std::string header = fileEntry.createHeader();
|
||||
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
}
|
||||
else
|
||||
{
|
||||
fileEntry.setSearchCRCAndSizesAfterData(!reposition);
|
||||
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
int level = Z_DEFAULT_COMPRESSION;
|
||||
if (fileEntry.getCompressionLevel() == ZipCommon::CL_FAST || fileEntry.getCompressionLevel() == ZipCommon::CL_SUPERFAST)
|
||||
level = Z_BEST_SPEED;
|
||||
else if (fileEntry.getCompressionLevel() == ZipCommon::CL_MAXIMUM)
|
||||
level = Z_BEST_COMPRESSION;
|
||||
// ignore the zlib init string which is of size 2 and also ignore the 4 byte adler32 value at the end of the stream!
|
||||
_ptrOHelper = new PartialOutputStream(*_pOstr, 2, 4, false);
|
||||
_ptrOBuf = new Poco::DeflatingOutputStream(*_ptrOHelper, DeflatingStreamBuf::STREAM_ZLIB, level);
|
||||
}
|
||||
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
|
||||
{
|
||||
_ptrOHelper = new PartialOutputStream(*_pOstr, 0, 0, false);
|
||||
_ptrOBuf = _ptrOHelper;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Poco::NotImplementedException("Unsupported compression method");
|
||||
}
|
||||
// now write the header to the ostr!
|
||||
std::string header = fileEntry.createHeader();
|
||||
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf::~ZipStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int ZipStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_ptrBuf) return 0; // directory entry
|
||||
_ptrBuf->read(buffer, length);
|
||||
int cnt = _ptrBuf->gcount();
|
||||
if (cnt > 0)
|
||||
{
|
||||
_crc32.update(buffer, cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_crc32.checksum() != _expectedCrc32)
|
||||
{
|
||||
if (_checkCRC)
|
||||
throw ZipException("CRC failure");
|
||||
else
|
||||
{
|
||||
// the CRC value is written directly after the data block
|
||||
// parse it directly from the input stream
|
||||
ZipDataInfo nfo(*_pIstr, false);
|
||||
// now push back the header to the stream, so that the ZipLocalFileHeader can read it
|
||||
Poco::Int32 size = static_cast<Poco::Int32>(nfo.getFullHeaderSize());
|
||||
_expectedCrc32 = nfo.getCRC32();
|
||||
const char* rawHeader = nfo.getRawHeader();
|
||||
for (Poco::Int32 i = size-1; i >= 0; --i)
|
||||
_pIstr->putback(rawHeader[i]);
|
||||
if (!crcValid())
|
||||
throw ZipException("CRC failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
int ZipStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_ptrOBuf) return 0; // directory entry
|
||||
if (length == 0)
|
||||
return 0;
|
||||
_bytesWritten += length;
|
||||
_ptrOBuf->write(buffer, length);
|
||||
_crc32.update(buffer, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
void ZipStreamBuf::close()
|
||||
{
|
||||
if (_ptrOBuf && _pHeader)
|
||||
{
|
||||
_ptrOBuf->flush();
|
||||
DeflatingOutputStream* pDO = dynamic_cast<DeflatingOutputStream*>(_ptrOBuf.get());
|
||||
if (pDO)
|
||||
pDO->close();
|
||||
if (_ptrOHelper)
|
||||
{
|
||||
_ptrOHelper->flush();
|
||||
_ptrOHelper->close();
|
||||
}
|
||||
_ptrOBuf = 0;
|
||||
poco_assert (*_pOstr);
|
||||
// write an extra datablock if required
|
||||
// or fix the crc entries
|
||||
if (_pHeader->searchCRCAndSizesAfterData())
|
||||
{
|
||||
ZipDataInfo info;
|
||||
info.setCRC32(_crc32.checksum());
|
||||
info.setUncompressedSize(_bytesWritten);
|
||||
info.setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
|
||||
_pOstr->write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
}
|
||||
else
|
||||
{
|
||||
poco_check_ptr (_pHeader);
|
||||
_pHeader->setCRC(_crc32.checksum());
|
||||
_pHeader->setUncompressedSize(_bytesWritten);
|
||||
_pHeader->setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
|
||||
_pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg);
|
||||
poco_assert (*_pOstr);
|
||||
std::string header = _pHeader->createHeader();
|
||||
_pOstr->write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
_pOstr->seekp(0, std::ios_base::end);
|
||||
poco_assert (*_pOstr);
|
||||
}
|
||||
_pHeader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ZipStreamBuf::crcValid() const
|
||||
{
|
||||
if (!_ptrBuf) return true; // directory entry
|
||||
return _crc32.checksum() == _expectedCrc32;
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): _buf(istr, fileEntry, reposition)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition): _buf(ostr, fileEntry, reposition)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::~ZipIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf* ZipIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
ZipInputStream::ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): ZipIOS(istr, fileEntry, reposition), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipInputStream::~ZipInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool ZipInputStream::crcValid() const
|
||||
{
|
||||
return _buf.crcValid();
|
||||
}
|
||||
|
||||
|
||||
ZipOutputStream::ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput): ZipIOS(ostr, fileEntry, seekableOutput), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipOutputStream::~ZipOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ZipOutputStream::close()
|
||||
{
|
||||
flush();
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
//
|
||||
// Library: Zip
|
||||
// Package: Zip
|
||||
// Module: ZipStream
|
||||
//
|
||||
// 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/Zip/ZipStream.h"
|
||||
#include "Poco/zlib.h"
|
||||
#include "Poco/Zip/ZipArchive.h"
|
||||
#include "Poco/Zip/AutoDetectStream.h"
|
||||
#include "Poco/Zip/PartialStream.h"
|
||||
#include "Poco/Zip/ZipDataInfo.h"
|
||||
#include "Poco/Zip/ZipException.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/InflatingStream.h"
|
||||
#include "Poco/DeflatingStream.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Zip {
|
||||
|
||||
|
||||
ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition):
|
||||
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_ptrBuf(),
|
||||
_ptrOBuf(),
|
||||
_ptrHelper(),
|
||||
_ptrOHelper(),
|
||||
_crc32(Poco::Checksum::TYPE_CRC32),
|
||||
_expectedCrc32(0),
|
||||
_checkCRC(true),
|
||||
_bytesWritten(0),
|
||||
_pHeader(0)
|
||||
{
|
||||
if (fileEntry.isDirectory())
|
||||
return;
|
||||
_expectedCrc32 = fileEntry.getCRC();
|
||||
std::streamoff start = fileEntry.getDataStartPos();
|
||||
std::streamoff end = fileEntry.getDataEndPos();
|
||||
_checkCRC = !fileEntry.searchCRCAndSizesAfterData();
|
||||
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
// Fake init bytes at beginning of stream
|
||||
std::string init = ZipUtil::fakeZLibInitString(fileEntry.getCompressionLevel());
|
||||
|
||||
// Fake adler at end of stream: just some dummy value, not checked anway
|
||||
std::string crc(4, ' ');
|
||||
if (fileEntry.searchCRCAndSizesAfterData())
|
||||
{
|
||||
_ptrHelper = new AutoDetectInputStream(istr, init, crc, reposition, start);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ptrHelper = new PartialInputStream(istr, start, end, reposition, init, crc);
|
||||
}
|
||||
_ptrBuf = new Poco::InflatingInputStream(*_ptrHelper, Poco::InflatingStreamBuf::STREAM_ZIP);
|
||||
}
|
||||
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
|
||||
{
|
||||
if (fileEntry.searchCRCAndSizesAfterData())
|
||||
{
|
||||
_ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ptrBuf = new PartialInputStream(istr, start, end, reposition);
|
||||
}
|
||||
}
|
||||
else throw Poco::NotImplementedException("Unsupported compression method");
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition):
|
||||
Poco::BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::out),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_ptrBuf(),
|
||||
_ptrOBuf(),
|
||||
_ptrHelper(),
|
||||
_ptrOHelper(),
|
||||
_crc32(Poco::Checksum::TYPE_CRC32),
|
||||
_expectedCrc32(0),
|
||||
_checkCRC(false),
|
||||
_bytesWritten(0),
|
||||
_pHeader(&fileEntry)
|
||||
{
|
||||
if (fileEntry.isEncrypted())
|
||||
throw Poco::NotImplementedException("Encryption not supported");
|
||||
|
||||
if (fileEntry.isDirectory())
|
||||
{
|
||||
// only header, no payload, zero crc
|
||||
fileEntry.setSearchCRCAndSizesAfterData(false);
|
||||
fileEntry.setCompressedSize(0);
|
||||
fileEntry.setUncompressedSize(0);
|
||||
fileEntry.setCRC(0);
|
||||
std::string header = fileEntry.createHeader();
|
||||
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
}
|
||||
else
|
||||
{
|
||||
fileEntry.setSearchCRCAndSizesAfterData(!reposition);
|
||||
if (fileEntry.getCompressionMethod() == ZipCommon::CM_DEFLATE)
|
||||
{
|
||||
int level = Z_DEFAULT_COMPRESSION;
|
||||
if (fileEntry.getCompressionLevel() == ZipCommon::CL_FAST || fileEntry.getCompressionLevel() == ZipCommon::CL_SUPERFAST)
|
||||
level = Z_BEST_SPEED;
|
||||
else if (fileEntry.getCompressionLevel() == ZipCommon::CL_MAXIMUM)
|
||||
level = Z_BEST_COMPRESSION;
|
||||
// ignore the zlib init string which is of size 2 and also ignore the 4 byte adler32 value at the end of the stream!
|
||||
_ptrOHelper = new PartialOutputStream(*_pOstr, 2, 4, false);
|
||||
_ptrOBuf = new Poco::DeflatingOutputStream(*_ptrOHelper, DeflatingStreamBuf::STREAM_ZLIB, level);
|
||||
}
|
||||
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
|
||||
{
|
||||
_ptrOHelper = new PartialOutputStream(*_pOstr, 0, 0, false);
|
||||
_ptrOBuf = new PartialOutputStream(*_ptrOHelper, 0, 0, false);
|
||||
}
|
||||
else throw Poco::NotImplementedException("Unsupported compression method");
|
||||
|
||||
// now write the header to the ostr!
|
||||
std::string header = fileEntry.createHeader();
|
||||
ostr.write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf::~ZipStreamBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int ZipStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_ptrBuf) return 0; // directory entry
|
||||
_ptrBuf->read(buffer, length);
|
||||
int cnt = _ptrBuf->gcount();
|
||||
if (cnt > 0)
|
||||
{
|
||||
_crc32.update(buffer, cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_crc32.checksum() != _expectedCrc32)
|
||||
{
|
||||
if (_checkCRC)
|
||||
throw ZipException("CRC failure");
|
||||
else
|
||||
{
|
||||
// the CRC value is written directly after the data block
|
||||
// parse it directly from the input stream
|
||||
ZipDataInfo nfo(*_pIstr, false);
|
||||
// now push back the header to the stream, so that the ZipLocalFileHeader can read it
|
||||
Poco::Int32 size = static_cast<Poco::Int32>(nfo.getFullHeaderSize());
|
||||
_expectedCrc32 = nfo.getCRC32();
|
||||
const char* rawHeader = nfo.getRawHeader();
|
||||
for (Poco::Int32 i = size-1; i >= 0; --i)
|
||||
_pIstr->putback(rawHeader[i]);
|
||||
if (!crcValid())
|
||||
throw ZipException("CRC failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
int ZipStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_ptrOBuf) return 0; // directory entry
|
||||
if (length == 0)
|
||||
return 0;
|
||||
_bytesWritten += length;
|
||||
_ptrOBuf->write(buffer, length);
|
||||
_crc32.update(buffer, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
void ZipStreamBuf::close()
|
||||
{
|
||||
if (_ptrOBuf && _pHeader)
|
||||
{
|
||||
_ptrOBuf->flush();
|
||||
DeflatingOutputStream* pDO = dynamic_cast<DeflatingOutputStream*>(_ptrOBuf.get());
|
||||
if (pDO)
|
||||
pDO->close();
|
||||
if (_ptrOHelper)
|
||||
{
|
||||
_ptrOHelper->flush();
|
||||
_ptrOHelper->close();
|
||||
}
|
||||
_ptrOBuf = 0;
|
||||
poco_assert (*_pOstr);
|
||||
// write an extra datablock if required
|
||||
// or fix the crc entries
|
||||
if (_pHeader->searchCRCAndSizesAfterData())
|
||||
{
|
||||
ZipDataInfo info;
|
||||
info.setCRC32(_crc32.checksum());
|
||||
info.setUncompressedSize(_bytesWritten);
|
||||
info.setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
|
||||
_pOstr->write(info.getRawHeader(), static_cast<std::streamsize>(info.getFullHeaderSize()));
|
||||
}
|
||||
else
|
||||
{
|
||||
poco_check_ptr (_pHeader);
|
||||
_pHeader->setCRC(_crc32.checksum());
|
||||
_pHeader->setUncompressedSize(_bytesWritten);
|
||||
_pHeader->setCompressedSize(static_cast<Poco::UInt32>(_ptrOHelper->bytesWritten()));
|
||||
_pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg);
|
||||
poco_assert (*_pOstr);
|
||||
std::string header = _pHeader->createHeader();
|
||||
_pOstr->write(header.c_str(), static_cast<std::streamsize>(header.size()));
|
||||
_pOstr->seekp(0, std::ios_base::end);
|
||||
poco_assert (*_pOstr);
|
||||
}
|
||||
_pHeader = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ZipStreamBuf::crcValid() const
|
||||
{
|
||||
if (!_ptrBuf) return true; // directory entry
|
||||
return _crc32.checksum() == _expectedCrc32;
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::ZipIOS(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): _buf(istr, fileEntry, reposition)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::ZipIOS(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool reposition): _buf(ostr, fileEntry, reposition)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
ZipIOS::~ZipIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipStreamBuf* ZipIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
ZipInputStream::ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): ZipIOS(istr, fileEntry, reposition), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipInputStream::~ZipInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool ZipInputStream::crcValid() const
|
||||
{
|
||||
return _buf.crcValid();
|
||||
}
|
||||
|
||||
|
||||
ZipOutputStream::ZipOutputStream(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bool seekableOutput): ZipIOS(ostr, fileEntry, seekableOutput), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ZipOutputStream::~ZipOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ZipOutputStream::close()
|
||||
{
|
||||
flush();
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Zip
|
||||
|
Reference in New Issue
Block a user