backport changes from 1.4.3 branch

This commit is contained in:
Marian Krivos
2012-01-07 11:06:14 +00:00
parent cc90b38ae5
commit 6268aa3865
69 changed files with 10381 additions and 5761 deletions

View File

@@ -37,7 +37,11 @@
#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 {

View File

@@ -42,6 +42,11 @@
#include "Poco/Data/DataException.h"
#include "Poco/DateTimeParser.h"
#include "Poco/Exception.h"
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
#include <cstdlib>

View File

@@ -40,7 +40,11 @@
#include "Poco/String.h"
#include <cstdlib>
#include <cstring>
#if defined(POCO_UNBUNDLED)
#include <sqlite3.h>
#else
#include "sqlite3.h"
#endif
namespace Poco {

View File

@@ -41,7 +41,11 @@
#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 {

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

@@ -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
@@ -45,8 +45,10 @@
#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
#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"
#endif // POCO_OS
@@ -73,6 +75,7 @@ class Foundation_API AtomicCounter
/// primitives:
/// - Windows
/// - Mac OS X
/// - GCC 4.1+ (Intel platforms only)
{
public:
typedef int ValueType; /// The underlying integer type.
@@ -119,10 +122,10 @@ 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)
#elif defined(POCO_HAVE_GCC_ATOMICS)
typedef int ImplType;
#else // generic implementation based on FastMutex
struct ImplType
@@ -236,31 +239,10 @@ inline bool AtomicCounter::operator ! () const
return _counter == 0;
}
#elif defined(POCO_ARCH_GCC_INTEL_X32_64)
#elif defined(POCO_HAVE_GCC_ATOMICS)
//
// Generic Intel & GCC
// GCC 4.1+ atomic builtins.
//
//
// 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;
@@ -275,25 +257,25 @@ inline AtomicCounter::ValueType AtomicCounter::value() const
inline AtomicCounter::ValueType AtomicCounter::operator ++ () // prefix
{
return poco_atomic_exchange_and_add( &_counter, +1 ) + 1;
return __sync_add_and_fetch(&_counter, 1);
}
inline AtomicCounter::ValueType AtomicCounter::operator ++ (int) // postfix
{
return poco_atomic_exchange_and_add( &_counter, +1 );
return __sync_fetch_and_add(&_counter, 1);
}
inline AtomicCounter::ValueType AtomicCounter::operator -- () // prefix
{
return poco_atomic_exchange_and_add( &_counter, -1 ) - 1;
return __sync_sub_and_fetch(&_counter, 1);
}
inline AtomicCounter::ValueType AtomicCounter::operator -- (int) // postfix
{
return poco_atomic_exchange_and_add( &_counter, -1 );
return __sync_fetch_and_sub(&_counter, 1);
}

View File

@@ -74,6 +74,16 @@ public:
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.

View File

@@ -57,6 +57,7 @@ public:
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();

View File

@@ -56,6 +56,7 @@ public:
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();

View File

@@ -57,6 +57,7 @@ public:
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();

View File

@@ -55,6 +55,7 @@ public:
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();

View File

@@ -55,6 +55,7 @@ public:
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();

View File

@@ -340,6 +340,10 @@ public:
/// returns the result. To include a dollar sign in the result string,
/// specify two dollar signs ($$) in the format string.
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.
@@ -407,7 +411,6 @@ protected:
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);

View File

@@ -86,7 +86,7 @@ inline bool MutexImpl::tryLockImpl()
{
try
{
return TryEnterCriticalSection(&_cs) == TRUE;
return TryEnterCriticalSection(&_cs) != 0;
}
catch (...)
{

View File

@@ -43,6 +43,7 @@
#include "Poco/Foundation.h"
#include <istream>
#include <ostream>
#include <cstddef>
namespace Poco {
@@ -53,20 +54,50 @@ class Foundation_API StreamCopier
/// into another.
{
public:
static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, unsigned bufferSize = 8192);
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.
static std::streamsize copyToString(std::istream& istr, std::string& str, unsigned bufferSize = 8192);
#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
};

View File

@@ -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,32 +356,56 @@ 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. */
# 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 */

File diff suppressed because it is too large Load Diff

View File

@@ -122,9 +122,9 @@ 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)
@@ -151,14 +151,14 @@ AtomicCounter::~AtomicCounter()
AtomicCounter& AtomicCounter::operator = (const AtomicCounter& counter)
{
_counter = counter.value();
__sync_lock_test_and_set(&_counter, counter.value());
return *this;
}
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
_counter = value;
__sync_lock_test_and_set(&_counter, value);
return *this;
}

View File

@@ -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
@@ -93,6 +93,12 @@ std::string Environment::osName()
}
std::string Environment::osDisplayName()
{
return EnvironmentImpl::osDisplayNameImpl();
}
std::string Environment::osVersion()
{
return EnvironmentImpl::osVersionImpl();

View File

@@ -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,6 +102,12 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
return osNameImpl();
}
std::string EnvironmentImpl::osVersionImpl()
{
struct utsname uts;

View File

@@ -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,6 +103,12 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
return osNameImpl();
}
std::string EnvironmentImpl::osVersionImpl()
{
return getsyi(SYI$_VERSION);

View File

@@ -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,6 +108,12 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
return osNameImpl();
}
std::string EnvironmentImpl::osVersionImpl()
{
return runtimeVersion;

View File

@@ -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
@@ -94,6 +94,53 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
switch(vi.dwMajorVersion)
{
case 6:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows Vista/Server 2008";
case 1:
return "Windows 7/Server 2008 SP2";
default:
return "Unknown";
}
case 5:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 2000";
case 1:
return "Windows XP";
case 2:
return "Windows Server 2003/Windows Server 2003 R2";
default:
return "Unknown";
}
case 4:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 95/Windows NT 4.0";
case 10:
return "Windows 98";
case 90:
return "Windows ME";
default:
return "Unknown";
}
default:
return "Unknown";
}
}
std::string EnvironmentImpl::osVersionImpl()
{
OSVERSIONINFO vi;

View File

@@ -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
@@ -104,6 +104,53 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
if (GetVersionEx(&vi) == 0) throw SystemException("Cannot get OS version information");
switch(vi.dwMajorVersion)
{
case 6:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows Vista/Server 2008";
case 1:
return "Windows 7/Server 2008 SP2";
default:
return "Unknown";
}
case 5:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 2000";
case 1:
return "Windows XP";
case 2:
return "Windows Server 2003/Windows Server 2003 R2";
default:
return "Unknown";
}
case 4:
switch (vi.dwMinorVersion)
{
case 0:
return "Windows 95/Windows NT 4.0";
case 10:
return "Windows 98";
case 90:
return "Windows ME";
default:
return "Unknown";
}
default:
return "Unknown";
}
}
std::string EnvironmentImpl::osVersionImpl()
{
OSVERSIONINFOW vi;

View File

@@ -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,6 +84,12 @@ std::string EnvironmentImpl::osNameImpl()
}
std::string EnvironmentImpl::osDisplayNameImpl()
{
return osNameImpl();
}
std::string EnvironmentImpl::osVersionImpl()
{
OSVERSIONINFOW vi;

View File

@@ -38,6 +38,7 @@
#include "Poco/Exception.h"
#include "Poco/Ascii.h"
#include <sstream>
#include <locale>
#include <cstddef>
@@ -166,6 +167,7 @@ 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;
str.imbue(std::locale::classic());
parseFlags(str, itFmt, endFmt);
parseWidth(str, itFmt, endFmt);
parsePrec(str, itFmt, endFmt);

View File

@@ -260,7 +260,16 @@ 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())
bool isDir = false;
try
{
isDir = f.isDirectory();
}
catch (Poco::Exception&)
{
return false;
}
if (isDir)
{
return true;
}

View File

@@ -35,6 +35,9 @@
#include "Poco/NumberFormatter.h"
#include "Poco/MemoryStream.h"
#include <iomanip>
#include <locale>
#include <cstdio>
#include <cctype>
@@ -357,16 +360,20 @@ 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);
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);
Poco::MemoryOutputStream ostr(buffer, sizeof(buffer));
ostr.imbue(std::locale::classic());
ostr << std::setprecision(16) << value;
str.append(buffer, ostr.charsWritten());
}
@@ -375,8 +382,10 @@ void NumberFormatter::append(std::string& str, double value, int precision)
poco_assert (precision >= 0 && precision < 32);
char buffer[64];
std::sprintf(buffer, "%.*f", precision, value);
str.append(buffer);
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());
}
@@ -385,8 +394,10 @@ void NumberFormatter::append(std::string& str, double value, int width, int prec
poco_assert (width > 0 && width < 64 && precision >= 0 && precision < width);
char buffer[64];
std::sprintf(buffer, "%*.*f", width, precision, value);
str.append(buffer);
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());
}

View File

@@ -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>
@@ -173,8 +175,10 @@ double NumberParser::parseFloat(const std::string& 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();
}

View File

@@ -643,7 +643,16 @@ bool Path::find(StringVec::const_iterator it, StringVec::const_iterator end, con
{
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);

View File

@@ -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,7 +41,7 @@
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);
@@ -64,7 +64,32 @@ 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);
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);
@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -1,7 +1,7 @@
//
// pocomsg.mc[.h]
//
// $Id: //poco/svn/Foundation/src/pocomsg.mc#2 $
// $Id: //poco/1.4/Foundation/src/pocomsg.h#1 $
//
// The Poco message source/header file.
//

View File

@@ -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.
;//

View 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 */

View File

@@ -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));

View File

@@ -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"

View File

@@ -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

View File

@@ -85,6 +85,9 @@ public:
/// a StreamSocketImpl, otherwise an InvalidArgumentException
/// will be thrown.
DialogSocket(const DialogSocket& socket);
/// Creates the DialogSocket as copy of another dialog socket.
~DialogSocket();
/// Destroys the DialogSocket.

View File

@@ -59,6 +59,13 @@ 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.
///
/// 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();
@@ -136,6 +143,21 @@ public:
///
/// 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.
@@ -164,6 +186,20 @@ public:
/// Returns the MIME boundary used for writing
/// 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"
@@ -177,6 +213,11 @@ private:
HTMLForm(const HTMLForm&);
HTMLForm& operator = (const HTMLForm&);
enum Limits
{
DFL_FIELD_LIMIT = 100
};
struct Part
{
std::string name;
@@ -185,6 +226,7 @@ private:
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

View File

@@ -69,6 +69,11 @@ public:
/// Throws a NotAuthenticatedException if the request does
/// not contain basic authentication information.
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.
@@ -89,9 +94,15 @@ public:
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);
HTTPBasicCredentials& operator = (const HTTPBasicCredentials&);
std::string _username;
std::string _password;

View File

@@ -76,6 +76,25 @@ public:
/// 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.
///
/// 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.
///

View File

@@ -65,9 +65,13 @@ public:
HostEntry(struct hostent* entry);
/// Creates the HostEntry from the data in a hostent structure.
#if defined(_WIN32) && defined(POCO_HAVE_IPv6)
#if defined(POCO_HAVE_IPv6) || defined(POCO_HAVE_ADDRINFO)
HostEntry(struct addrinfo* info);
/// Creates the HostEntry from the data in a Windows addrinfo structure.
/// Creates the HostEntry from the data in an addrinfo structure.
#endif
#if defined(POCO_VXWORKS)
HostEntry(const std::string& name, const IPAddress& addr);
#endif
HostEntry(const HostEntry& entry);

View File

@@ -62,6 +62,13 @@ class Net_API MessageHeader: public NameValueCollection
///
/// 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();
@@ -102,6 +109,20 @@ public:
/// 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.
@@ -146,8 +167,11 @@ private:
/// Limits for basic sanity checks when reading a header
{
MAX_NAME_LENGTH = 256,
MAX_VALUE_LENGTH = 4096
MAX_VALUE_LENGTH = 4096,
DFL_FIELD_LIMIT = 100
};
int _fieldLimit;
};

View File

@@ -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

View File

@@ -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)

View File

@@ -75,7 +75,7 @@ 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));
@@ -113,7 +113,7 @@ 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);

View File

@@ -72,6 +72,16 @@ DialogSocket::DialogSocket(const Socket& socket):
}
DialogSocket::DialogSocket(const DialogSocket& socket):
StreamSocket(socket),
_pBuffer(0),
_pNext(0),
_pEnd(0)
{
allocBuffer();
}
DialogSocket::~DialogSocket()
{
delete [] _pBuffer;

View File

@@ -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,30 +66,35 @@ const std::string HTMLForm::ENCODING_MULTIPART = "multipart/form-data";
HTMLForm::HTMLForm():
_fieldLimit(DFL_FIELD_LIMIT),
_encoding(ENCODING_URL)
{
}
HTMLForm::HTMLForm(const std::string& 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);
}
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody)
HTMLForm::HTMLForm(const HTTPRequest& request, std::istream& requestBody):
_fieldLimit(DFL_FIELD_LIMIT)
{
load(request, requestBody);
}
HTMLForm::HTMLForm(const HTTPRequest& request)
HTMLForm::HTMLForm(const HTTPRequest& request):
_fieldLimit(DFL_FIELD_LIMIT)
{
load(request);
}
@@ -173,6 +178,19 @@ 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)
@@ -243,9 +261,12 @@ void HTMLForm::readUrl(std::istream& istr)
{
static const int eof = std::char_traits<char>::eof();
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 != '&')
@@ -269,6 +290,7 @@ void HTMLForm::readUrl(std::istream& istr)
URI::decode(name, decodedName);
URI::decode(value, decodedValue);
add(decodedName, decodedValue);
++fields;
if (ch == '&') ch = istr.get();
}
}
@@ -278,9 +300,12 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
{
static const int eof = std::char_traits<char>::eof();
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;
@@ -309,6 +334,7 @@ void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
}
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

View File

@@ -69,32 +69,23 @@ 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 info;
request.getCredentials(scheme, info);
std::string authInfo;
request.getCredentials(scheme, authInfo);
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();
}
parseAuthInfo(authInfo);
}
else throw NotAuthenticatedException("Basic authentication expected");
}
HTTPBasicCredentials::HTTPBasicCredentials(const std::string& authInfo)
{
parseAuthInfo(authInfo);
}
HTTPBasicCredentials::~HTTPBasicCredentials()
{
}
@@ -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

View File

@@ -111,6 +111,28 @@ std::streamsize HTTPMessage::getContentLength() const
}
#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())
{
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)

View File

@@ -39,6 +39,7 @@
#include "Poco/Net/NameValueCollection.h"
#include "Poco/NumberFormatter.h"
#include "Poco/Ascii.h"
#include "Poco/String.h"
using Poco::NumberFormatter;
@@ -151,7 +152,7 @@ void HTTPRequest::setCookies(const NameValueCollection& cookies)
void HTTPRequest::getCookies(NameValueCollection& cookies) const
{
NameValueCollection::ConstIterator it = find(COOKIE);
while (it != end() && it->first == COOKIE)
while (it != end() && Poco::icompare(it->first, COOKIE) == 0)
{
splitParameters(it->second.begin(), it->second.end(), cookies);
++it;

View File

@@ -43,6 +43,7 @@
#include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeParser.h"
#include "Poco/Ascii.h"
#include "Poco/String.h"
using Poco::DateTime;
@@ -200,7 +201,7 @@ void HTTPResponse::getCookies(std::vector<HTTPCookie>& cookies) const
{
cookies.clear();
NameValueCollection::ConstIterator it = find(SET_COOKIE);
while (it != end() && it->first == SET_COOKIE)
while (it != end() && Poco::icompare(it->first, SET_COOKIE) == 0)
{
NameValueCollection nvc;
splitParameters(it->second.begin(), it->second.end(), nvc);

View File

@@ -119,7 +119,11 @@ void HTTPServerResponseImpl::sendFile(const std::string& path, const std::string
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);

View File

@@ -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;
@@ -89,11 +92,17 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
URI resolvedURI(uri);
URI proxyUri;
HTTPClientSession* pSession = 0;
HTTPResponse res;
bool retry = false;
bool authorize = false;
std::string username;
std::string password;
try
{
do
{
if (!pSession)
{
pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
@@ -102,12 +111,20 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
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);
HTTPResponse res;
std::istream& rs = pSession->receiveResponse(res);
bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY ||
res.getStatus() == HTTPResponse::HTTP_FOUND ||
@@ -116,6 +133,10 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
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)
@@ -133,10 +154,14 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
delete pSession; pSession = 0;
retry = true; // only allow useproxy once
}
else
else if (res.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED && !authorize)
{
throw HTTPException(res.getReason(), uri.toString());
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());

View File

@@ -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)
@@ -94,9 +94,11 @@ HostEntry::HostEntry(struct addrinfo* ainfo)
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
}
}
}

View File

@@ -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)
{
}
@@ -88,8 +90,11 @@ void MessageHeader::read(std::istream& istr)
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(); }
@@ -114,11 +119,26 @@ void MessageHeader::read(std::istream& istr)
}
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();

View File

@@ -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

View File

@@ -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,7 +292,6 @@ 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)
{
@@ -300,31 +299,25 @@ NetworkInterface NetworkInterface::forName(const std::string& name, bool require
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
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);
}
@@ -375,6 +368,41 @@ 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);
@@ -406,30 +434,44 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
pAddress = pAdapterAddresses;
while (pAddress)
{
if (pAddress->FirstUnicastAddress)
if (pAddress->OperStatus == IfOperStatusUp)
{
IPAddress addr;
switch (pAddress->FirstUnicastAddress->Address.lpSockaddr->sa_family)
PIP_ADAPTER_UNICAST_ADDRESS pUniAddr = pAddress->FirstUnicastAddress;
while (pUniAddr)
{
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;
#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);
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;
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");
@@ -441,7 +483,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
delete [] reinterpret_cast<char*>(pAdapterAddresses);
return result;
#endif
#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));
@@ -474,7 +516,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
{
IPAddress subnetMask(std::string(pInfo->IpAddressList.IpMask.String));
IPAddress broadcastAddress(address);
broadcastAddress.mask(subnetMask, IPAddress("255.255.255.255"));
broadcastAddress.mask(subnetMask, IPAddress::broadcast());
std::string name(pInfo->AdapterName);
std::string displayName(pInfo->Description);
result.push_back(NetworkInterface(name, displayName, address, subnetMask, broadcastAddress));
@@ -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
@@ -538,9 +633,10 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
#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));
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, if_nametoindex(ifap->ifa_name)));
result.push_back(NetworkInterface(name, name, addr, ifIndex));
}
#endif
}
@@ -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 {
@@ -602,12 +760,6 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
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;
@@ -617,11 +769,7 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
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));
}
@@ -641,6 +789,9 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
} } // namespace Poco::Net
#endif // POCO_HAVE_IPv6
#else
//
// Non-BSD Unix variants
@@ -694,12 +845,14 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
#endif
IPAddress addr;
bool haveAddr = false;
int ifIndex(-1);
switch (ifr->ifr_addr.sa_family)
{
#if defined(POCO_HAVE_IPv6)
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));
addr = IPAddress(&reinterpret_cast<const struct sockaddr_in6*>(&ifr->ifr_addr)->sin6_addr, sizeof(struct in6_addr), ifIndex);
haveAddr = true;
break;
#endif
@@ -713,13 +866,8 @@ NetworkInterface::NetworkInterfaceList NetworkInterface::list()
}
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));
result.push_back(NetworkInterface(name, name, addr, ifIndex));
}
len += sizeof(ifr->ifr_name);
ptr += len;

View File

@@ -260,8 +260,12 @@ public:
///
/// Does nothing if the key does not exist.
void setPropertyEventingMode(bool enabled);
/// Enable/Disable property eventing.
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
@@ -301,10 +305,9 @@ private:
AbstractConfiguration& operator = (const AbstractConfiguration&);
mutable int _depth;
bool _eventsEnabled;
mutable Poco::FastMutex _mutex;
bool _propertyEventing;
friend class LayeredConfiguration;
friend class ConfigurationView;
friend class ConfigurationMapper;

View File

@@ -57,13 +57,15 @@ class Util_API WinRegistryConfiguration: public AbstractConfiguration
/// in a NotImplementedException being thrown.
{
public:
WinRegistryConfiguration(const std::string& rootPath);
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();
@@ -80,6 +82,7 @@ protected:
private:
std::string _rootPath;
REGSAM _extraSam;
};

View File

@@ -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);
if (_eventsEnabled)
{
propertyRemoving(this, key);
}
{
FastMutex::ScopedLock lock(_mutex);
removeRaw(key);
}
if (_propertyEventing) propertyRemoved(this, key);
if (_eventsEnabled)
{
propertyRemoved(this, key);
}
}
void AbstractConfiguration::enableEvents(bool enable)
{
_eventsEnabled = enable;
}
bool AbstractConfiguration::eventsEnabled() const
{
return _eventsEnabled;
}
@@ -386,18 +406,20 @@ 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);
if (_eventsEnabled)
{
propertyChanging(this, kv);
}
{
FastMutex::ScopedLock lock(_mutex);
setRaw(key, value);
}
if (_propertyEventing) propertyChanged(this, kv);
if (_eventsEnabled)
{
propertyChanged(this, kv);
}
}
void AbstractConfiguration::setPropertyEventingMode(bool enabled)
{
_propertyEventing = enabled;
}
} } // namespace Poco::Util

View File

@@ -34,6 +34,9 @@
//
#if !defined(_WIN32_WCE)
#include "Poco/Util/WinRegistryConfiguration.h"
#include "Poco/Util/WinRegistryKey.h"
#include "Poco/NumberFormatter.h"
@@ -45,7 +48,7 @@ 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();
@@ -63,7 +66,7 @@ bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value
{
std::string keyName;
std::string fullPath = _rootPath + ConvertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath, true);
WinRegistryKey aKey(fullPath, true, _extraSam);
bool exists = aKey.exists(keyName);
if (exists)
{
@@ -92,7 +95,7 @@ void WinRegistryConfiguration::setRaw(const std::string& key, const std::string&
{
std::string keyName;
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath);
WinRegistryKey aKey(fullPath, false, _extraSam);
aKey.setString(keyName, value);
}
@@ -113,7 +116,7 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
{
std::string keyName;
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath, true);
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)

View File

@@ -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)

View File

@@ -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"
@@ -285,6 +288,8 @@ void WinService::open() const
bool WinService::tryOpen() const
{
if (!_svcHandle)
{
#if defined(POCO_WIN32_UTF8)
std::wstring uname;
@@ -293,6 +298,7 @@ bool WinService::tryOpen() const
#else
_svcHandle = OpenService(_scmHandle, _name.c_str(), SERVICE_ALL_ACCESS);
#endif
}
return _svcHandle != 0;
}
@@ -302,6 +308,7 @@ void WinService::close() const
if (_svcHandle)
{
CloseServiceHandle(_svcHandle);
_svcHandle = 0;
}
}
@@ -340,3 +347,6 @@ POCO_LPQUERY_SERVICE_CONFIG WinService::config() const
} } // namespace Poco::Util
#endif // !defined(_WIN32_WCE)

View File

@@ -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;

View File

@@ -82,7 +82,9 @@ ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEnt
_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)
@@ -92,12 +94,11 @@ ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEnt
_ptrBuf = new AutoDetectInputStream(istr, "", "", reposition, start);
}
else
{
_ptrBuf = new PartialInputStream(istr, start, end, reposition);
}
else
{
throw Poco::NotImplementedException("Unsupported compression method");
}
else throw Poco::NotImplementedException("Unsupported compression method");
}
@@ -145,12 +146,10 @@ ZipStreamBuf::ZipStreamBuf(std::ostream& ostr, ZipLocalFileHeader& fileEntry, bo
else if (fileEntry.getCompressionMethod() == ZipCommon::CM_STORE)
{
_ptrOHelper = new PartialOutputStream(*_pOstr, 0, 0, false);
_ptrOBuf = _ptrOHelper;
}
else
{
throw Poco::NotImplementedException("Unsupported compression method");
_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()));