1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

File diff suppressed because it is too large Load Diff

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: configcpp.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: configcpp.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
/**
* @file
*/
@ -38,7 +38,6 @@
namespace messageqcpp
{
class ByteStream;
}
@ -51,7 +50,6 @@ class ByteStream;
namespace config
{
/** @brief a config file I/F class
*
* This is a singleton pattern: you must use the makeConfig() factory method to get a
@ -61,201 +59,199 @@ namespace config
*/
class Config
{
public:
/** @brief Config factory method
*
* Creates a singleton Config object
*/
EXPORT static Config* makeConfig(const char* cf = 0);
public:
/** @brief Config factory method
*
* Creates a singleton Config object
*/
EXPORT static Config* makeConfig(const char* cf = 0);
/** @brief Config factory method
*
* Creates a singleton Config object
*/
EXPORT static Config* makeConfig(const std::string& cf);
/** @brief Config factory method
*
* Creates a singleton Config object
*/
EXPORT static Config* makeConfig(const std::string& cf);
/** @brief dtor
*/
EXPORT virtual ~Config();
/** @brief dtor
*/
EXPORT virtual ~Config();
/** @brief get name's value from section
*
* get name's value from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
*/
EXPORT const std::string getConfig(const std::string& section, const std::string& name);
/** @brief get name's value from section
*
* get name's value from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
*/
EXPORT const std::string getConfig(const std::string& section, const std::string& name);
/** @brief get name's value from section
*
* get name's value from section in the current config file re-reading the
* config file if it was updated.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
*/
const std::string getFromActualConfig(const std::string& section, const std::string& name);
/** @brief get name's value from section
*
* get name's value from section in the current config file re-reading the
* config file if it was updated.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
*/
const std::string getFromActualConfig(const std::string& section, const std::string& name);
/** @brief get all name's values from a section
*
* get name's values from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
* @param values the values in the section are returned in this vector
*/
EXPORT void getConfig(const std::string& section, const std::string& name,
std::vector<std::string>& values);
/** @brief get all name's values from a section
*
* get name's values from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose value is to be returned
* @param values the values in the section are returned in this vector
*/
EXPORT void getConfig(const std::string& section, const std::string& name,
std::vector<std::string>& values);
/** @brief set name's value in section
*
* set name's value in section in the current config file.
* @param section the name of the config file section to update
* @param name the param name whose value is to be updated
* @param value the param value
*/
// !!!Don't ever ever use this in the engine code b/c it might result in a race
// b/w getConfig and setConfig methods.!!!
EXPORT void setConfig(const std::string& section, const std::string& name, const std::string& value);
/** @brief set name's value in section
*
* set name's value in section in the current config file.
* @param section the name of the config file section to update
* @param name the param name whose value is to be updated
* @param value the param value
*/
// !!!Don't ever ever use this in the engine code b/c it might result in a race
// b/w getConfig and setConfig methods.!!!
EXPORT void setConfig(const std::string& section, const std::string& name, const std::string& value);
/** @brief delete name from section
*
* delete name from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose entry is to be deleted
* @note if you delete the last param from a section, the section will still remain
*/
EXPORT void delConfig(const std::string& section, const std::string& name);
/** @brief delete name from section
*
* delete name from section in the current config file.
* @param section the name of the config file section to search
* @param name the param name whose entry is to be deleted
* @note if you delete the last param from a section, the section will still remain
*/
EXPORT void delConfig(const std::string& section, const std::string& name);
/** @brief write the config file back out to disk
*
* write the config file back out to disk using the current filename.
*/
EXPORT void write(void) const;
/** @brief write the config file back out to disk
*
* write the config file back out to disk using the current filename.
*/
EXPORT void write(void) const;
/** @brief write the config file back out to disk as fileName
*
* write the config file out to disk as a new file fileName. Does not affect the current
* config filename.
*/
EXPORT void write(const std::string& fileName) const;
/** @brief write the config file back out to disk as fileName
*
* write the config file out to disk as a new file fileName. Does not affect the current
* config filename.
*/
EXPORT void write(const std::string& fileName) const;
/** @brief write a stream copy of config file to disk
*
* write a stream copy of config file to disk. used to distributed mass updates to system nodes
*
*/
EXPORT void writeConfigFile(messageqcpp::ByteStream msg) const;
/** @brief write a stream copy of config file to disk
*
* write a stream copy of config file to disk. used to distributed mass updates to system nodes
*
*/
EXPORT void writeConfigFile(messageqcpp::ByteStream msg) const;
/** @brief return the name of this config file
*
* return the name of this config file.
*/
EXPORT inline const std::string& configFile() const
{
return fConfigFile;
}
/** @brief return the name of this config file
*
* return the name of this config file.
*/
EXPORT inline const std::string& configFile() const
{
return fConfigFile;
}
/** @brief delete all config file instances
*
* deletes \b all config file maps
*/
EXPORT static void deleteInstanceMap();
/** @brief delete all config file instances
*
* deletes \b all config file maps
*/
EXPORT static void deleteInstanceMap();
/** @brief parse config file numerics
*
* Convert human-friendly number formats to machine-friendly. Handle suffixes 'K', 'M', 'G'.
* Handle decimal, hex and octal notation in the same way as the C compiler.
* Ignore any 'B' following [KMG]. Ignore case in suffixes.
* An empty string or an unparseable string returns 0.
* Return a signed numeric value.
*/
EXPORT static int64_t fromText(const std::string& text);
/** @brief parse config file numerics
*
* Convert human-friendly number formats to machine-friendly. Handle suffixes 'K', 'M', 'G'.
* Handle decimal, hex and octal notation in the same way as the C compiler.
* Ignore any 'B' following [KMG]. Ignore case in suffixes.
* An empty string or an unparseable string returns 0.
* Return a signed numeric value.
*/
EXPORT static int64_t fromText(const std::string& text);
/** @brief parse config file numerics
*
* Return an unsigned numeric value.
*/
EXPORT static inline uint64_t uFromText(const std::string& text)
{
return static_cast<uint64_t>(fromText(text));
}
/** @brief parse config file numerics
*
* Return an unsigned numeric value.
*/
EXPORT static inline uint64_t uFromText(const std::string& text)
{
return static_cast<uint64_t>(fromText(text));
}
/** @brief Used externally to check whether there has been a config change without loading everything
*
*/
inline time_t getLastMTime() const
{
return fMtime;
}
/** @brief Used externally to check whether there has been a config change without loading everything
*
*/
inline time_t getLastMTime() const
{
return fMtime;
}
/** @brief Used externally to check whether there has been a config change without loading everything
*
*/
EXPORT time_t getCurrentMTime();
/** @brief Used externally to check whether there has been a config change without loading everything
*
*/
EXPORT time_t getCurrentMTime();
/** @brief Enumerate all the sections in the config file
*
*/
EXPORT const std::vector<std::string> enumConfig();
/** @brief Enumerate all the sections in the config file
*
*/
EXPORT const std::vector<std::string> enumConfig();
/** @brief Enumerate all the names in a section in the config file
*
*/
EXPORT const std::vector<std::string> enumSection(const std::string& section);
/** @brief Enumerate all the names in a section in the config file
*
*/
EXPORT const std::vector<std::string> enumSection(const std::string& section);
enum class TempDirPurpose
{
Joins, ///< disk joins
Aggregates ///< disk-based aggregation
};
/** @brief Return temporaru directory path for the specified purpose */
EXPORT std::string getTempFileDir(TempDirPurpose what);
enum class TempDirPurpose
{
Joins, ///< disk joins
Aggregates ///< disk-based aggregation
};
/** @brief Return temporaru directory path for the specified purpose */
EXPORT std::string getTempFileDir(TempDirPurpose what);
protected:
/** @brief parse the XML file
*
*/
void parseDoc(void);
protected:
/** @brief parse the XML file
*
*/
void parseDoc(void);
/** @brief write the XML tree to disk
*
*/
EXPORT void writeConfig(const std::string& fileName) const;
/** @brief write the XML tree to disk
*
*/
EXPORT void writeConfig(const std::string& fileName) const;
/** @brief stop processing this XML file
*
*/
void closeConfig(void);
/** @brief stop processing this XML file
*
*/
void closeConfig(void);
private:
typedef std::map<std::string, Config*> configMap_t;
private:
typedef std::map<std::string, Config*> configMap_t;
/*
*/
Config(const Config& rhs);
/*
*/
Config& operator=(const Config& rhs);
/*
*/
Config(const Config& rhs);
/*
*/
Config& operator=(const Config& rhs);
/** @brief ctor with config file specified
*/
Config(const std::string& configFile);
/** @brief ctor with config file specified
*/
Config(const std::string& configFile);
static configMap_t fInstanceMap;
static boost::mutex fInstanceMapMutex;
static boost::mutex fXmlLock;
static boost::mutex fWriteXmlLock;
xmlDocPtr fDoc;
const std::string fConfigFile;
time_t fMtime;
mutable boost::recursive_mutex fLock;
XMLParser fParser;
static configMap_t fInstanceMap;
static boost::mutex fInstanceMapMutex;
static boost::mutex fXmlLock;
static boost::mutex fWriteXmlLock;
xmlDocPtr fDoc;
const std::string fConfigFile;
time_t fMtime;
mutable boost::recursive_mutex fLock;
XMLParser fParser;
};
}
} // namespace config
#undef EXPORT
// vim:ts=4 sw=4:

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id$
*
******************************************************************************************/
* $Id$
*
******************************************************************************************/
#include "mcsconfig.h"
#include <string>
@ -34,39 +34,34 @@ using namespace messageqcpp;
namespace config
{
ConfigStream::ConfigStream(const ByteStream& bs) :
fParser()
ConfigStream::ConfigStream(const ByteStream& bs) : fParser()
{
init(reinterpret_cast<const xmlChar*>(bs.buf()));
init(reinterpret_cast<const xmlChar*>(bs.buf()));
}
ConfigStream::ConfigStream(const string& str) :
fParser()
ConfigStream::ConfigStream(const string& str) : fParser()
{
init(reinterpret_cast<const xmlChar*>(str.c_str()));
init(reinterpret_cast<const xmlChar*>(str.c_str()));
}
ConfigStream::ConfigStream(const char* cptr) :
fParser()
ConfigStream::ConfigStream(const char* cptr) : fParser()
{
init(reinterpret_cast<const xmlChar*>(cptr));
init(reinterpret_cast<const xmlChar*>(cptr));
}
ConfigStream::~ConfigStream()
{
if (fDoc != NULL)
xmlFreeDoc(fDoc);
if (fDoc != NULL)
xmlFreeDoc(fDoc);
}
void ConfigStream::init(const xmlChar* xp)
{
fDoc = xmlParseDoc(xp);
fDoc = xmlParseDoc(xp);
if (fDoc == NULL)
throw runtime_error("ConfigStream::ConfigStream: bad XML stream");
if (fDoc == NULL)
throw runtime_error("ConfigStream::ConfigStream: bad XML stream");
}
} //namespace
} // namespace config
// vim:ts=4 sw=4:

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id$
*
******************************************************************************************/
* $Id$
*
******************************************************************************************/
/**
* @file
*/
@ -33,34 +33,32 @@
namespace config
{
/** @brief a config ByteStream I/F class
*
*/
class ConfigStream
{
public:
ConfigStream(const messageqcpp::ByteStream& bs);
ConfigStream(const std::string& str);
ConfigStream(const char* cptr);
~ConfigStream();
public:
ConfigStream(const messageqcpp::ByteStream& bs);
ConfigStream(const std::string& str);
ConfigStream(const char* cptr);
~ConfigStream();
const std::string getConfig(const std::string& section, const std::string& name) const
{
return fParser.getConfig(fDoc, section, name);
}
const std::string getConfig(const std::string& section, const std::string& name) const
{
return fParser.getConfig(fDoc, section, name);
}
private:
ConfigStream(const ConfigStream& rhs);
ConfigStream& operator=(const ConfigStream& rhs);
private:
ConfigStream(const ConfigStream& rhs);
ConfigStream& operator=(const ConfigStream& rhs);
void init(const xmlChar* xp);
void init(const xmlChar* xp);
XMLParser fParser;
xmlDocPtr fDoc;
XMLParser fParser;
xmlDocPtr fDoc;
};
} //namespace
} // namespace config
// vim:ts=4 sw=4:

View File

@ -142,135 +142,146 @@
*/
#undef ROTATE
#ifndef PEDANTIC
# if defined(_MSC_VER) || defined(__ICC)
# define ROTATE(a,n) _lrotl(a,n)
# elif defined(__MWERKS__)
# if defined(__POWERPC__)
# define ROTATE(a,n) __rlwinm(a,n,0,31)
# elif defined(__MC68K__)
#if defined(_MSC_VER) || defined(__ICC)
#define ROTATE(a, n) _lrotl(a, n)
#elif defined(__MWERKS__)
#if defined(__POWERPC__)
#define ROTATE(a, n) __rlwinm(a, n, 0, 31)
#elif defined(__MC68K__)
/* Motorola specific tweak. <appro@fy.chalmers.se> */
# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
# else
# define ROTATE(a,n) __rol(a,n)
# endif
# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
#define ROTATE(a, n) (n < 24 ? __rol(a, n) : __ror(a, 32 - n))
#else
#define ROTATE(a, n) __rol(a, n)
#endif
#elif defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
/*
* Some GNU C inline assembler templates. Note that these are
* rotates by *constant* number of bits! But that's exactly
* what we need here...
* <appro@fy.chalmers.se>
*/
# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
# define ROTATE(a,n) ({ register unsigned int ret; \
asm ( \
"roll %1,%0" \
: "=r"(ret) \
: "I"(n), "0"((unsigned int)(a)) \
: "cc"); \
ret; \
})
# elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
# define ROTATE(a,n) ({ register unsigned int ret; \
asm ( \
"rlwinm %0,%1,%2,0,31" \
: "=r"(ret) \
: "r"(a), "I"(n)); \
ret; \
})
# elif defined(__s390x__)
# define ROTATE(a,n) ({ register unsigned int ret; \
asm ("rll %0,%1,%2" \
: "=r"(ret) \
: "r"(a), "I"(n)); \
ret; \
})
# endif
# endif
#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
#define ROTATE(a, n) \
( \
{ \
register unsigned int ret; \
asm("roll %1,%0" : "=r"(ret) : "I"(n), "0"((unsigned int)(a)) : "cc"); \
ret; \
})
#elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || defined(__powerpc) || defined(__ppc__) || \
defined(__powerpc64__)
#define ROTATE(a, n) \
( \
{ \
register unsigned int ret; \
asm("rlwinm %0,%1,%2,0,31" : "=r"(ret) : "r"(a), "I"(n)); \
ret; \
})
#elif defined(__s390x__)
#define ROTATE(a, n) \
( \
{ \
register unsigned int ret; \
asm("rll %0,%1,%2" : "=r"(ret) : "r"(a), "I"(n)); \
ret; \
})
#endif
#endif
#endif /* PEDANTIC */
#ifndef ROTATE
#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
#define ROTATE(a, n) (((a) << (n)) | (((a)&0xffffffff) >> (32 - (n))))
#endif
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
#ifndef PEDANTIC
# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \
(defined(__x86_64) || defined(__x86_64__))
# if !defined(B_ENDIAN)
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
#if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \
(defined(__x86_64) || defined(__x86_64__))
#if !defined(B_ENDIAN)
/*
* This gives ~30-40% performance improvement in SHA-256 compiled
* with gcc [on P4]. Well, first macro to be frank. We can pull
* this trick on x86* platforms only, because these CPUs can fetch
* unaligned data without raising an exception.
*/
# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \
asm ("bswapl %0":"=r"(r):"0"(r)); \
(c)+=4; (l)=r; })
# define HOST_l2c(l,c) ({ unsigned int r=(l); \
asm ("bswapl %0":"=r"(r):"0"(r)); \
*((unsigned int *)(c))=r; (c)+=4; r; })
# endif
# endif
# endif
#define HOST_c2l(c, l) \
( \
{ \
unsigned int r = *((const unsigned int*)(c)); \
asm("bswapl %0" : "=r"(r) : "0"(r)); \
(c) += 4; \
(l) = r; \
})
#define HOST_l2c(l, c) \
( \
{ \
unsigned int r = (l); \
asm("bswapl %0" : "=r"(r) : "0"(r)); \
*((unsigned int*)(c)) = r; \
(c) += 4; \
r; \
})
#endif
#endif
#endif
#endif
#if defined(__s390__) || defined(__s390x__)
# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l))
#define HOST_c2l(c, l) ((l) = *((const unsigned int*)(c)), (c) += 4, (l))
#define HOST_l2c(l, c) (*((unsigned int*)(c)) = (l), (c) += 4, (l))
#endif
#ifndef HOST_c2l
#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++))) ), \
l)
#define HOST_c2l(c, l) \
(l = (((unsigned long)(*((c)++))) << 24), l |= (((unsigned long)(*((c)++))) << 16), \
l |= (((unsigned long)(*((c)++))) << 8), l |= (((unsigned long)(*((c)++)))), l)
#endif
#ifndef HOST_l2c
#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff), \
l)
#define HOST_l2c(l, c) \
(*((c)++) = (unsigned char)(((l) >> 24) & 0xff), *((c)++) = (unsigned char)(((l) >> 16) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 8) & 0xff), *((c)++) = (unsigned char)(((l)) & 0xff), l)
#endif
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
#ifndef PEDANTIC
# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
# if defined(__s390x__)
# define HOST_c2l(c,l) ({ asm ("lrv %0,%1" \
:"=d"(l) :"m"(*(const unsigned int *)(c)));\
(c)+=4; (l); })
# define HOST_l2c(l,c) ({ asm ("strv %1,%0" \
:"=m"(*(unsigned int *)(c)) :"d"(l));\
(c)+=4; (l); })
# endif
# endif
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
#if defined(__s390x__)
#define HOST_c2l(c, l) \
( \
{ \
asm("lrv %0,%1" : "=d"(l) : "m"(*(const unsigned int*)(c))); \
(c) += 4; \
(l); \
})
#define HOST_l2c(l, c) \
( \
{ \
asm("strv %1,%0" : "=m"(*(unsigned int*)(c)) : "d"(l)); \
(c) += 4; \
(l); \
})
#endif
#endif
#endif
#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
# ifndef B_ENDIAN
#ifndef B_ENDIAN
/* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, l)
# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l)
# endif
#define HOST_c2l(c, l) ((l) = *((const unsigned int*)(c)), (c) += 4, l)
#define HOST_l2c(l, c) (*((unsigned int*)(c)) = (l), (c) += 4, l)
#endif
#endif
#ifndef HOST_c2l
#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<<24), \
l)
#define HOST_c2l(c, l) \
(l = (((unsigned long)(*((c)++)))), l |= (((unsigned long)(*((c)++))) << 8), \
l |= (((unsigned long)(*((c)++))) << 16), l |= (((unsigned long)(*((c)++))) << 24), l)
#endif
#ifndef HOST_l2c
#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>>24)&0xff), \
l)
#define HOST_l2c(l, c) \
(*((c)++) = (unsigned char)(((l)) & 0xff), *((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 16) & 0xff), *((c)++) = (unsigned char)(((l) >> 24) & 0xff), l)
#endif
#endif
@ -279,113 +290,112 @@
* Time for some action:-)
*/
int HASH_UPDATE (HASH_CTX* c, const void* data_, size_t len)
int HASH_UPDATE(HASH_CTX* c, const void* data_, size_t len)
{
const unsigned char* data = data_;
unsigned char* p;
HASH_LONG l;
size_t n;
if (len == 0) return 1;
l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL;
/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
* Wei Dai <weidai@eskimo.com> for pointing it out. */
if (l < c->Nl) /* overflow */
c->Nh++;
c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on 16-bit */
c->Nl = l;
n = c->num;
if (n != 0)
{
p = (unsigned char*)c->data;
if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK)
{
memcpy (p + n, data, HASH_CBLOCK - n);
HASH_BLOCK_DATA_ORDER (c, p, 1);
n = HASH_CBLOCK - n;
data += n;
len -= n;
c->num = 0;
memset (p, 0, HASH_CBLOCK); /* keep it zeroed */
}
else
{
memcpy (p + n, data, len);
c->num += (unsigned int)len;
return 1;
}
}
n = len / HASH_CBLOCK;
if (n > 0)
{
HASH_BLOCK_DATA_ORDER (c, data, n);
n *= HASH_CBLOCK;
data += n;
len -= n;
}
if (len != 0)
{
p = (unsigned char*)c->data;
c->num = (unsigned int)len;
memcpy (p, data, len);
}
const unsigned char* data = data_;
unsigned char* p;
HASH_LONG l;
size_t n;
if (len == 0)
return 1;
}
l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL;
void HASH_TRANSFORM (HASH_CTX* c, const unsigned char* data)
{
HASH_BLOCK_DATA_ORDER (c, data, 1);
}
/* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
* Wei Dai <weidai@eskimo.com> for pointing it out. */
if (l < c->Nl) /* overflow */
c->Nh++;
c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on 16-bit */
c->Nl = l;
int HASH_FINAL (unsigned char* md, HASH_CTX* c)
{
unsigned char* p = (unsigned char*)c->data;
size_t n = c->num;
n = c->num;
p[n] = 0x80; /* there is always room for one */
n++;
if (n != 0)
{
p = (unsigned char*)c->data;
if (n > (HASH_CBLOCK - 8))
if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK)
{
memset (p + n, 0, HASH_CBLOCK - n);
n = 0;
HASH_BLOCK_DATA_ORDER (c, p, 1);
memcpy(p + n, data, HASH_CBLOCK - n);
HASH_BLOCK_DATA_ORDER(c, p, 1);
n = HASH_CBLOCK - n;
data += n;
len -= n;
c->num = 0;
memset(p, 0, HASH_CBLOCK); /* keep it zeroed */
}
else
{
memcpy(p + n, data, len);
c->num += (unsigned int)len;
return 1;
}
}
memset (p + n, 0, HASH_CBLOCK - 8 - n);
n = len / HASH_CBLOCK;
p += HASH_CBLOCK - 8;
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
(void)HOST_l2c(c->Nh, p);
(void)HOST_l2c(c->Nl, p);
if (n > 0)
{
HASH_BLOCK_DATA_ORDER(c, data, n);
n *= HASH_CBLOCK;
data += n;
len -= n;
}
if (len != 0)
{
p = (unsigned char*)c->data;
c->num = (unsigned int)len;
memcpy(p, data, len);
}
return 1;
}
void HASH_TRANSFORM(HASH_CTX* c, const unsigned char* data)
{
HASH_BLOCK_DATA_ORDER(c, data, 1);
}
int HASH_FINAL(unsigned char* md, HASH_CTX* c)
{
unsigned char* p = (unsigned char*)c->data;
size_t n = c->num;
p[n] = 0x80; /* there is always room for one */
n++;
if (n > (HASH_CBLOCK - 8))
{
memset(p + n, 0, HASH_CBLOCK - n);
n = 0;
HASH_BLOCK_DATA_ORDER(c, p, 1);
}
memset(p + n, 0, HASH_CBLOCK - 8 - n);
p += HASH_CBLOCK - 8;
#if defined(DATA_ORDER_IS_BIG_ENDIAN)
(void)HOST_l2c(c->Nh, p);
(void)HOST_l2c(c->Nl, p);
#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
(void)HOST_l2c(c->Nl, p);
(void)HOST_l2c(c->Nh, p);
(void)HOST_l2c(c->Nl, p);
(void)HOST_l2c(c->Nh, p);
#endif
p -= HASH_CBLOCK;
HASH_BLOCK_DATA_ORDER (c, p, 1);
c->num = 0;
memset (p, 0, HASH_CBLOCK);
p -= HASH_CBLOCK;
HASH_BLOCK_DATA_ORDER(c, p, 1);
c->num = 0;
memset(p, 0, HASH_CBLOCK);
#ifndef HASH_MAKE_STRING
#error "HASH_MAKE_STRING must be defined!"
#else
HASH_MAKE_STRING(c, md);
HASH_MAKE_STRING(c, md);
#endif
return 1;
return 1;
}
#ifndef MD32_REG_T

View File

@ -60,20 +60,21 @@
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef OPENSSL_NO_MD5
#error MD5 is disabled.
#endif
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
* ! MD5_LONG_LOG2 has to be defined along. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
* ! MD5_LONG_LOG2 has to be defined along. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
#if defined(__LP32__)
#define MD5_LONG unsigned long
@ -91,24 +92,23 @@ extern "C" {
#define MD5_LONG unsigned int
#endif
#define MD5_CBLOCK 64
#define MD5_LBLOCK (MD5_CBLOCK/4)
#define MD5_CBLOCK 64
#define MD5_LBLOCK (MD5_CBLOCK / 4)
#define MD5_DIGEST_LENGTH 16
typedef struct MD5state_st
{
typedef struct MD5state_st
{
MD5_LONG A, B, C, D;
MD5_LONG Nl, Nh;
MD5_LONG data[MD5_LBLOCK];
unsigned int num;
} MD5_CTX;
} MD5_CTX;
int MD5_Init(MD5_CTX* c);
int MD5_Update(MD5_CTX* c, const void* data, size_t len);
int MD5_Final(unsigned char* md, MD5_CTX* c);
unsigned char* MD5(const unsigned char* d, size_t n, unsigned char* md);
void MD5_Transform(MD5_CTX* c, const unsigned char* b);
#ifdef __cplusplus
int MD5_Init(MD5_CTX* c);
int MD5_Update(MD5_CTX* c, const void* data, size_t len);
int MD5_Final(unsigned char* md, MD5_CTX* c);
unsigned char* MD5(const unsigned char* d, size_t n, unsigned char* md);
void MD5_Transform(MD5_CTX* c, const unsigned char* b);
#ifdef __cplusplus
}
#endif

View File

@ -68,32 +68,38 @@
#endif
#ifdef MD5_ASM
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || \
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
# define md5_block_data_order md5_block_asm_data_order
# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
# define md5_block_data_order md5_block_asm_data_order
# endif
#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || defined(__x86_64) || \
defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
#define md5_block_data_order md5_block_asm_data_order
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#define md5_block_data_order md5_block_asm_data_order
#endif
#endif
void md5_block_data_order (MD5_CTX* c, const void* p, size_t num);
void md5_block_data_order(MD5_CTX* c, const void* p, size_t num);
#define DATA_ORDER_IS_LITTLE_ENDIAN
#define HASH_LONG MD5_LONG
#define HASH_CTX MD5_CTX
#define HASH_CBLOCK MD5_CBLOCK
#define HASH_UPDATE MD5_Update
#define HASH_TRANSFORM MD5_Transform
#define HASH_FINAL MD5_Final
#define HASH_MAKE_STRING(c,s) do { \
unsigned long ll; \
ll=(c)->A; HOST_l2c(ll,(s)); \
ll=(c)->B; HOST_l2c(ll,(s)); \
ll=(c)->C; HOST_l2c(ll,(s)); \
ll=(c)->D; HOST_l2c(ll,(s)); \
} while (0)
#define HASH_BLOCK_DATA_ORDER md5_block_data_order
#define HASH_LONG MD5_LONG
#define HASH_CTX MD5_CTX
#define HASH_CBLOCK MD5_CBLOCK
#define HASH_UPDATE MD5_Update
#define HASH_TRANSFORM MD5_Transform
#define HASH_FINAL MD5_Final
#define HASH_MAKE_STRING(c, s) \
do \
{ \
unsigned long ll; \
ll = (c)->A; \
HOST_l2c(ll, (s)); \
ll = (c)->B; \
HOST_l2c(ll, (s)); \
ll = (c)->C; \
HOST_l2c(ll, (s)); \
ll = (c)->D; \
HOST_l2c(ll, (s)); \
} while (0)
#define HASH_BLOCK_DATA_ORDER md5_block_data_order
#include "md32_common.h"
@ -106,27 +112,35 @@ void md5_block_data_order (MD5_CTX* c, const void* p, size_t num);
* simplified to the code below. Wei attributes these optimizations
* to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
*/
#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
#define H(b,c,d) ((b) ^ (c) ^ (d))
#define I(b,c,d) (((~(d)) | (b)) ^ (c))
#define F(b, c, d) ((((c) ^ (d)) & (b)) ^ (d))
#define G(b, c, d) ((((b) ^ (c)) & (d)) ^ (c))
#define H(b, c, d) ((b) ^ (c) ^ (d))
#define I(b, c, d) (((~(d)) | (b)) ^ (c))
#define R0(a,b,c,d,k,s,t) { \
a+=((k)+(t)+F((b),(c),(d))); \
a=ROTATE(a,s); \
a+=b; };\
#define R0(a, b, c, d, k, s, t) \
{ \
a += ((k) + (t) + F((b), (c), (d))); \
a = ROTATE(a, s); \
a += b; \
};
#define R1(a,b,c,d,k,s,t) { \
a+=((k)+(t)+G((b),(c),(d))); \
a=ROTATE(a,s); \
a+=b; };
#define R1(a, b, c, d, k, s, t) \
{ \
a += ((k) + (t) + G((b), (c), (d))); \
a = ROTATE(a, s); \
a += b; \
};
#define R2(a,b,c,d,k,s,t) { \
a+=((k)+(t)+H((b),(c),(d))); \
a=ROTATE(a,s); \
a+=b; };
#define R2(a, b, c, d, k, s, t) \
{ \
a += ((k) + (t) + H((b), (c), (d))); \
a = ROTATE(a, s); \
a += b; \
};
#define R3(a,b,c,d,k,s,t) { \
a+=((k)+(t)+I((b),(c),(d))); \
a=ROTATE(a,s); \
a+=b; };
#define R3(a, b, c, d, k, s, t) \
{ \
a += ((k) + (t) + I((b), (c), (d))); \
a = ROTATE(a, s); \
a += b; \
};

View File

@ -6,9 +6,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -39,340 +39,333 @@ using namespace config;
class ConfigFileTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(ConfigFileTest);
CPPUNIT_TEST_SUITE( ConfigFileTest );
CPPUNIT_TEST(test1);
CPPUNIT_TEST( test1 );
CPPUNIT_TEST_EXCEPTION(test2, std::runtime_error);
CPPUNIT_TEST(test3);
CPPUNIT_TEST(test4);
CPPUNIT_TEST_EXCEPTION(test5, std::runtime_error);
CPPUNIT_TEST_EXCEPTION(test6, std::runtime_error);
CPPUNIT_TEST_EXCEPTION(test7, std::invalid_argument);
CPPUNIT_TEST_EXCEPTION(test8, std::invalid_argument);
CPPUNIT_TEST(test9);
CPPUNIT_TEST(test10);
CPPUNIT_TEST(test11);
CPPUNIT_TEST(test12);
CPPUNIT_TEST_EXCEPTION(test13_1, std::runtime_error);
CPPUNIT_TEST_EXCEPTION(test13_2, std::runtime_error);
CPPUNIT_TEST(test14);
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
CPPUNIT_TEST( test3 );
CPPUNIT_TEST( test4 );
CPPUNIT_TEST_EXCEPTION( test5, std::runtime_error );
CPPUNIT_TEST_EXCEPTION( test6, std::runtime_error );
CPPUNIT_TEST_EXCEPTION( test7, std::invalid_argument );
CPPUNIT_TEST_EXCEPTION( test8, std::invalid_argument );
CPPUNIT_TEST( test9 );
CPPUNIT_TEST( test10 );
CPPUNIT_TEST( test11 );
CPPUNIT_TEST( test12 );
CPPUNIT_TEST_EXCEPTION( test13_1, std::runtime_error );
CPPUNIT_TEST_EXCEPTION( test13_2, std::runtime_error );
CPPUNIT_TEST( test14 );
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp()
{
}
private:
public:
void setUp()
void tearDown()
{
}
void test1()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string value;
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
value = c1->getConfig("Message", "xName");
CPPUNIT_ASSERT(value.size() == 0);
Config::deleteInstanceMap();
}
void test2()
{
Config* c1 = Config::makeConfig("./yadayada.xml");
string value;
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value.size() == 0);
value = c1->getConfig("Message", "xName");
CPPUNIT_ASSERT(value.size() == 0);
Config::deleteInstanceMap();
}
void test3()
{
Config* c1;
string value;
for (int i = 0; i < 1000; i++)
{
c1 = Config::makeConfig("./Columnstore.xml");
value = c1->getConfig("Message", "Name");
assert(value == "Message");
}
void tearDown()
Config::deleteInstanceMap();
}
void test4()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string value;
value = c1->getConfig("SystemConfig", "SystemVersion");
c1->setConfig("SystemConfig", "SystemVersion", "2.2.versionversionversion");
value = c1->getConfig("SystemConfig", "SystemVersion");
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
::unlink("./Columnstore.xml.new");
c1->write("./Columnstore.xml.new");
value = c1->getConfig("SystemConfig", "SystemVersion");
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
c1->setConfig("SystemConfig", "SystemVersion1", "V1.x");
value = c1->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.x");
c1->setConfig("SystemConfig1", "SystemVersion1", "Vx.x");
value = c1->getConfig("SystemConfig1", "SystemVersion1");
CPPUNIT_ASSERT(value == "Vx.x");
c1->write("./Columnstore.xml.new");
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
value = c2->getConfig("SystemConfig1", "SystemVersion1");
CPPUNIT_ASSERT(value == "Vx.x");
c2->setConfig("SystemConfig", "SystemVersion1", "V1.1");
value = c2->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.1");
c2->write();
Config::deleteInstanceMap();
}
void test5()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
c1->write("/cantwritethis");
Config::deleteInstanceMap();
}
void test6()
{
Config* c1 = Config::makeConfig("./XColumnstore.xml");
// compiler warning...we won't actually get here
c1 = 0;
}
void test7()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string s;
string n;
string v;
c1->setConfig(s, n, v);
Config::deleteInstanceMap();
}
void test8()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string s;
string n;
string v;
v = c1->getConfig(s, n);
Config::deleteInstanceMap();
}
void test9()
{
string value;
Config* c1 = Config::makeConfig("./Columnstore.xml");
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
value = c2->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.1");
Config::deleteInstanceMap();
}
void test10()
{
string value;
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
Config* c1 = Config::makeConfig();
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
Config::deleteInstanceMap();
}
void test11()
{
string value;
struct stat stat_buf;
struct utimbuf utime_buf;
CPPUNIT_ASSERT(stat("./Columnstore.xml.new", &stat_buf) == 0);
Config* c1 = Config::makeConfig("./Columnstore.xml.new");
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
utime_buf.actime = utime_buf.modtime = stat_buf.st_mtime + 1;
CPPUNIT_ASSERT(utime("./Columnstore.xml.new", &utime_buf) == 0);
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
Config::deleteInstanceMap();
}
void test12()
{
string value;
int64_t ival;
uint64_t uval;
value = "10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 10);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 10);
value = "0x10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 0x10);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x10);
value = "010";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 010);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 010);
value = "-10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == -10);
value = "10K";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024));
value = "10k";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024));
value = "10M";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "10m";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "10G";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
value = "10g";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
value = "10MB";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "0x7afafafafafafafa";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 0x7afafafafafafafaLL);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x7afafafafafafafaULL);
value = "-0x7afafafafafafafa";
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x8505050505050506ULL);
value = "-1";
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0xffffffffffffffffULL);
}
void test13_1()
{
string value;
int64_t ival;
value = "2.2MB"; // invalid char causes throw
ival = Config::fromText(value);
}
void test13_2()
{
string value;
int64_t ival;
value = "10,000"; // invalid char causes throw
ival = Config::fromText(value);
}
void test14()
{
ByteStream bs;
ifstream ifs("./Columnstore.xml");
ifs >> bs;
string id(".");
string value;
{
ConfigStream cs(bs, id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
void test1()
string bss(reinterpret_cast<const char*>(bs.buf()), bs.length());
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string value;
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
value = c1->getConfig("Message", "xName");
CPPUNIT_ASSERT(value.size() == 0);
Config::deleteInstanceMap();
ConfigStream cs(bss, id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
void test2()
{
Config* c1 = Config::makeConfig("./yadayada.xml");
string value;
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value.size() == 0);
value = c1->getConfig("Message", "xName");
CPPUNIT_ASSERT(value.size() == 0);
Config::deleteInstanceMap();
ConfigStream cs(bss.c_str(), id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
void test3()
{
Config* c1;
string value;
for (int i = 0; i < 1000; i++)
{
c1 = Config::makeConfig("./Columnstore.xml");
value = c1->getConfig("Message", "Name");
assert(value == "Message");
}
Config::deleteInstanceMap();
}
void test4()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string value;
value = c1->getConfig("SystemConfig", "SystemVersion");
c1->setConfig("SystemConfig", "SystemVersion", "2.2.versionversionversion");
value = c1->getConfig("SystemConfig", "SystemVersion");
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
::unlink("./Columnstore.xml.new");
c1->write("./Columnstore.xml.new");
value = c1->getConfig("SystemConfig", "SystemVersion");
CPPUNIT_ASSERT(value == "2.2.versionversionversion");
c1->setConfig("SystemConfig", "SystemVersion1", "V1.x");
value = c1->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.x");
c1->setConfig("SystemConfig1", "SystemVersion1", "Vx.x");
value = c1->getConfig("SystemConfig1", "SystemVersion1");
CPPUNIT_ASSERT(value == "Vx.x");
c1->write("./Columnstore.xml.new");
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
value = c2->getConfig("SystemConfig1", "SystemVersion1");
CPPUNIT_ASSERT(value == "Vx.x");
c2->setConfig("SystemConfig", "SystemVersion1", "V1.1");
value = c2->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.1");
c2->write();
Config::deleteInstanceMap();
}
void test5()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
c1->write("/cantwritethis");
Config::deleteInstanceMap();
}
void test6()
{
Config* c1 = Config::makeConfig("./XColumnstore.xml");
// compiler warning...we won't actually get here
c1 = 0;
}
void test7()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string s;
string n;
string v;
c1->setConfig(s, n, v);
Config::deleteInstanceMap();
}
void test8()
{
Config* c1 = Config::makeConfig("./Columnstore.xml");
string s;
string n;
string v;
v = c1->getConfig(s, n);
Config::deleteInstanceMap();
}
void test9()
{
string value;
Config* c1 = Config::makeConfig("./Columnstore.xml");
Config* c2 = Config::makeConfig("./Columnstore.xml.new");
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
value = c2->getConfig("SystemConfig", "SystemVersion1");
CPPUNIT_ASSERT(value == "V1.1");
Config::deleteInstanceMap();
}
void test10()
{
string value;
setenv("CALPONT_CONFIG_FILE", "./Columnstore.xml", 1);
Config* c1 = Config::makeConfig();
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
Config::deleteInstanceMap();
}
void test11()
{
string value;
struct stat stat_buf;
struct utimbuf utime_buf;
CPPUNIT_ASSERT(stat("./Columnstore.xml.new", &stat_buf) == 0);
Config* c1 = Config::makeConfig("./Columnstore.xml.new");
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
utime_buf.actime = utime_buf.modtime = stat_buf.st_mtime + 1;
CPPUNIT_ASSERT(utime("./Columnstore.xml.new", &utime_buf) == 0);
value = c1->getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
Config::deleteInstanceMap();
}
void test12()
{
string value;
int64_t ival;
uint64_t uval;
value = "10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 10);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 10);
value = "0x10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 0x10);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x10);
value = "010";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 010);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 010);
value = "-10";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == -10);
value = "10K";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024));
value = "10k";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024));
value = "10M";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "10m";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "10G";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
value = "10g";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024 * 1024LL));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024 * 1024ULL));
value = "10MB";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == (10 * 1024 * 1024));
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == (10 * 1024 * 1024));
value = "0x7afafafafafafafa";
ival = Config::fromText(value);
CPPUNIT_ASSERT(ival == 0x7afafafafafafafaLL);
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x7afafafafafafafaULL);
value = "-0x7afafafafafafafa";
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0x8505050505050506ULL);
value = "-1";
uval = Config::uFromText(value);
CPPUNIT_ASSERT(uval == 0xffffffffffffffffULL);
}
void test13_1()
{
string value;
int64_t ival;
value = "2.2MB"; //invalid char causes throw
ival = Config::fromText(value);
}
void test13_2()
{
string value;
int64_t ival;
value = "10,000"; //invalid char causes throw
ival = Config::fromText(value);
}
void test14()
{
ByteStream bs;
ifstream ifs("./Columnstore.xml");
ifs >> bs;
string id(".");
string value;
{
ConfigStream cs(bs, id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
string bss(reinterpret_cast<const char*>(bs.buf()), bs.length());
{
ConfigStream cs(bss, id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
{
ConfigStream cs(bss.c_str(), id);
value = cs.getConfig("Message", "Name");
CPPUNIT_ASSERT(value == "Message");
}
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( ConfigFileTest );
CPPUNIT_TEST_SUITE_REGISTRATION(ConfigFileTest);
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char** argv)
int main(int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
bool wasSuccessful = runner.run("", false);
return (wasSuccessful ? 0 : 1);
}

View File

@ -40,92 +40,88 @@ const string cf("./woparms.dat");
class WOConfigFileTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(WOConfigFileTest);
CPPUNIT_TEST_SUITE( WOConfigFileTest );
CPPUNIT_TEST(test1);
CPPUNIT_TEST_EXCEPTION(test2, std::runtime_error);
CPPUNIT_TEST_EXCEPTION(test3, std::runtime_error);
CPPUNIT_TEST_EXCEPTION(test4, std::runtime_error);
CPPUNIT_TEST(test5);
CPPUNIT_TEST( test1 );
CPPUNIT_TEST_EXCEPTION( test2, std::runtime_error );
CPPUNIT_TEST_EXCEPTION( test3, std::runtime_error );
CPPUNIT_TEST_EXCEPTION( test4, std::runtime_error );
CPPUNIT_TEST( test5 );
CPPUNIT_TEST_SUITE_END();
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp()
{
unlink(cf.c_str());
}
private:
void tearDown()
{
unlink(cf.c_str());
}
public:
void setUp()
{
unlink(cf.c_str());
}
void test1()
{
WriteOnceConfig woc(cf);
CPPUNIT_ASSERT(woc.owns("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRMRoot"));
void tearDown()
{
unlink(cf.c_str());
}
CPPUNIT_ASSERT(!woc.owns("dummy", "dummy"));
void test1()
{
WriteOnceConfig woc(cf);
CPPUNIT_ASSERT(woc.owns("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(woc.owns("SystemConfig", "DBRMRoot"));
int vali;
CPPUNIT_ASSERT(!woc.owns("dummy", "dummy"));
vali = Config::fromText(woc.getConfig("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(vali == 13);
int vali;
woc.setConfig("SystemConfig", "DBRootCount", "10");
vali = Config::fromText(woc.getConfig("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(vali == 10);
vali = Config::fromText(woc.getConfig("PrimitiveServers", "LBID_Shift"));
CPPUNIT_ASSERT(vali == 13);
WriteOnceConfig woc2(cf.c_str());
vali = Config::fromText(woc2.getConfig("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(vali == 10);
}
woc.setConfig("SystemConfig", "DBRootCount", "10");
vali = Config::fromText(woc.getConfig("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(vali == 10);
void test2()
{
WriteOnceConfig woc(cf);
woc.getConfig("dummy", "dummy");
}
WriteOnceConfig woc2(cf.c_str());
vali = Config::fromText(woc2.getConfig("SystemConfig", "DBRootCount"));
CPPUNIT_ASSERT(vali == 10);
}
void test3()
{
WriteOnceConfig woc(cf);
woc.setConfig("dummy", "dummy", "100");
}
void test2()
{
WriteOnceConfig woc(cf);
woc.getConfig("dummy", "dummy");
}
void test3()
{
WriteOnceConfig woc(cf);
woc.setConfig("dummy", "dummy", "100");
}
void test4()
{
WriteOnceConfig woc(cf);
woc.setConfig("SystemConfig", "DBRootCount", "10");
woc.setConfig("SystemConfig", "DBRootCount", "11");
}
void test5()
{
WriteOnceConfig woc(cf);
woc.setConfig("SystemConfig", "DBRootCount", "10");
woc.setConfig("SystemConfig", "DBRootCount", "11", true);
}
void test4()
{
WriteOnceConfig woc(cf);
woc.setConfig("SystemConfig", "DBRootCount", "10");
woc.setConfig("SystemConfig", "DBRootCount", "11");
}
void test5()
{
WriteOnceConfig woc(cf);
woc.setConfig("SystemConfig", "DBRootCount", "10");
woc.setConfig("SystemConfig", "DBRootCount", "11", true);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( WOConfigFileTest );
CPPUNIT_TEST_SUITE_REGISTRATION(WOConfigFileTest);
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main( int argc, char** argv)
int main(int argc, char** argv)
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run( "", false );
return (wasSuccessful ? 0 : 1);
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
bool wasSuccessful = runner.run("", false);
return (wasSuccessful ? 0 : 1);
}

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id: writeonce.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
* $Id: writeonce.h 3495 2013-01-21 14:09:51Z rdempsey $
*
******************************************************************************************/
/**
* @file
*/
@ -37,106 +37,104 @@
namespace config
{
/** @brief a write-once config file I/F class
*
* This class handles write-once config items
*/
class WriteOnceConfig
{
public:
/** @brief ctor
*
*/
explicit WriteOnceConfig(const char* cf = 0);
public:
/** @brief ctor
*
*/
explicit WriteOnceConfig(const char* cf = 0);
/** @brief ctor
*
*/
explicit WriteOnceConfig(const std::string& cf) :
fConfigFileName(cf)
{
setup();
}
/** @brief ctor
*
*/
explicit WriteOnceConfig(const std::string& cf) : fConfigFileName(cf)
{
setup();
}
/** @brief dtor
*
*/
virtual ~WriteOnceConfig() {}
/** @brief dtor
*
*/
virtual ~WriteOnceConfig()
{
}
/** @brief check if this class owns parm
*
*/
bool owns(const std::string& section, const std::string& name) const
{
return (fEntryMap.find(std::string(section + "." + name)) != fEntryMap.end());
}
/** @brief check if this class owns parm
*
*/
bool owns(const std::string& section, const std::string& name) const
{
return (fEntryMap.find(std::string(section + "." + name)) != fEntryMap.end());
}
/** @brief set parm to value
*
* If you attempt to set a value more than once, and force is false, this will throw a runtime_error.
*/
void setConfig(const std::string& section, const std::string& name, const std::string& value, bool force = false);
/** @brief set parm to value
*
* If you attempt to set a value more than once, and force is false, this will throw a runtime_error.
*/
void setConfig(const std::string& section, const std::string& name, const std::string& value,
bool force = false);
/** @brief get value of parm
*
*/
const std::string getConfig(const std::string& section, const std::string& name) const;
/** @brief get value of parm
*
*/
const std::string getConfig(const std::string& section, const std::string& name) const;
protected:
/** @brief load from file
*
*/
messageqcpp::ByteStream load();
protected:
/** @brief load from file
*
*/
messageqcpp::ByteStream load();
/** @brief save to file
*
*/
void save(messageqcpp::ByteStream& ibs) const;
/** @brief save to file
*
*/
void save(messageqcpp::ByteStream& ibs) const;
/** @brief serialize to ByteStream
*
*/
virtual void serialize(messageqcpp::ByteStream& obs) const;
/** @brief serialize to ByteStream
*
*/
virtual void serialize(messageqcpp::ByteStream& obs) const;
/** @brief load from ByteStream
*
*/
virtual void unserialize(messageqcpp::ByteStream& ibs);
/** @brief load from ByteStream
*
*/
virtual void unserialize(messageqcpp::ByteStream& ibs);
private:
typedef std::pair<std::string, bool> ConfigItem_t;
typedef std::tr1::unordered_map<std::string, ConfigItem_t*> EntryMap_t;
private:
typedef std::pair<std::string, bool> ConfigItem_t;
typedef std::tr1::unordered_map<std::string, ConfigItem_t*> EntryMap_t;
static const uint32_t WriteOnceConfigVersion = 1;
static const uint32_t WriteOnceConfigVersion = 1;
//defaults okay
//WriteOnceConfig(const WriteOnceConfig& rhs);
//WriteOnceConfig& operator=(const WriteOnceConfig& rhs);
// defaults okay
// WriteOnceConfig(const WriteOnceConfig& rhs);
// WriteOnceConfig& operator=(const WriteOnceConfig& rhs);
/** @brief ctor helper
*
*/
void setup();
/** @brief ctor helper
*
*/
void setup();
/** @brief setup defaults when file doesn't exist
*
*/
void initializeDefaults();
/** @brief setup defaults when file doesn't exist
*
*/
void initializeDefaults();
EntryMap_t fEntryMap;
EntryMap_t fEntryMap;
std::string fConfigFileName;
ConfigItem_t fLBID_Shift;
ConfigItem_t fDBRootCount;
ConfigItem_t fDBRMRoot;
ConfigItem_t fSharedMemoryTmpFile1;
ConfigItem_t fTxnIDFile;
ConfigItem_t fSharedMemoryTmpFile2;
std::string fConfigFileName;
ConfigItem_t fLBID_Shift;
ConfigItem_t fDBRootCount;
ConfigItem_t fDBRMRoot;
ConfigItem_t fSharedMemoryTmpFile1;
ConfigItem_t fTxnIDFile;
ConfigItem_t fSharedMemoryTmpFile2;
};
}
} // namespace config

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id$
*
******************************************************************************************/
* $Id$
*
******************************************************************************************/
#include "mcsconfig.h"
#include <string>
@ -33,257 +33,256 @@ using namespace std;
namespace config
{
const string XMLParser::getConfig(const xmlDocPtr doc, const string& section, const string& name) const
{
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
while (cur1 != NULL)
{
string cur1name = (const char*)cur1->name;
if ((boost::iequals(cur1name, section)))
{
string cur1name = (const char*)cur1->name;
xmlNodePtr cur2 = cur1->xmlChildrenNode;
if ((boost::iequals(cur1name, section)))
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if ((boost::iequals(cur2name, name)))
{
xmlNodePtr cur2 = cur1->xmlChildrenNode;
xmlNodePtr cur3 = cur2->xmlChildrenNode;
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if (cur3)
res = (const char*)cur3->content;
if ((boost::iequals(cur2name, name)))
{
xmlNodePtr cur3 = cur2->xmlChildrenNode;
if (cur3)
res = (const char*)cur3->content;
return res;
}
cur2 = cur2->next;
}
return res;
}
cur1 = cur1->next;
cur2 = cur2->next;
}
}
// maybe nullstr if not found
return res;
cur1 = cur1->next;
}
// maybe nullstr if not found
return res;
}
void XMLParser::getConfig(const xmlDocPtr doc, const string& section, const string& name, vector<string>& values) const
void XMLParser::getConfig(const xmlDocPtr doc, const string& section, const string& name,
vector<string>& values) const
{
string res;
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
while (cur1 != NULL)
{
string cur1name = (const char*)cur1->name;
if ((boost::iequals(cur1name, section)))
{
string cur1name = (const char*)cur1->name;
xmlNodePtr cur2 = cur1->xmlChildrenNode;
if ((boost::iequals(cur1name, section)))
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if ((boost::iequals(cur2name, name)))
{
xmlNodePtr cur2 = cur1->xmlChildrenNode;
res.clear();
xmlNodePtr cur3 = cur2->xmlChildrenNode;
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if (cur3)
res = (const char*)cur3->content;
if ((boost::iequals(cur2name, name)))
{
res.clear();
xmlNodePtr cur3 = cur2->xmlChildrenNode;
if (cur3)
res = (const char*)cur3->content;
values.push_back(res);
}
cur2 = cur2->next;
}
values.push_back(res);
}
cur1 = cur1->next;
cur2 = cur2->next;
}
}
cur1 = cur1->next;
}
}
void XMLParser::setConfig(xmlDocPtr doc, const string& section, const string& name, const string& value)
{
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::setConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::setConfig: error accessing XML root");
xmlNodePtr cur2;
xmlNodePtr cur2;
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
while (cur1 != NULL)
{
string cur1name = (const char*)cur1->name;
if (boost::iequals(cur1name, section))
{
string cur1name = (const char*)cur1->name;
cur2 = cur1->xmlChildrenNode;
if (boost::iequals(cur1name, section))
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if (boost::iequals(cur2name, name))
{
cur2 = cur1->xmlChildrenNode;
xmlNodePtr cur3 = cur2->xmlChildrenNode;
while (cur2 != NULL)
{
string cur2name = (const char*)cur2->name;
if (cur3 == NULL)
{
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\t"));
cur3 = cur2->xmlChildrenNode;
}
else
{
xmlFree(cur3->content);
}
if (boost::iequals(cur2name, name))
{
xmlNodePtr cur3 = cur2->xmlChildrenNode;
if (cur3 == NULL)
{
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\t"));
cur3 = cur2->xmlChildrenNode;
}
else
{
xmlFree(cur3->content);
}
cur3->content = xmlStrdup((const xmlChar*)value.c_str());
return;
}
cur2 = cur2->next;
}
// We found the section, but not the name, so we need to add a new node here
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
xmlNewTextChild(cur1, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n\t"));
return;
cur3->content = xmlStrdup((const xmlChar*)value.c_str());
return;
}
cur1 = cur1->next;
cur2 = cur2->next;
}
// We found the section, but not the name, so we need to add a new node here
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
xmlNewTextChild(cur1, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n\t"));
return;
}
// We did not find the section, so we need to add it and the name here
cur1 = xmlDocGetRootElement(doc);
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
cur2 = xmlNewChild(cur1, NULL, (const xmlChar*)section.c_str(), NULL);
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t\t"));
xmlNewTextChild(cur2, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t"));
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n"));
cur1 = cur1->next;
}
return;
// We did not find the section, so we need to add it and the name here
cur1 = xmlDocGetRootElement(doc);
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\t"));
cur2 = xmlNewChild(cur1, NULL, (const xmlChar*)section.c_str(), NULL);
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t\t"));
xmlNewTextChild(cur2, NULL, (const xmlChar*)name.c_str(), (const xmlChar*)value.c_str());
xmlAddChild(cur2, xmlNewText((const xmlChar*)"\n\t"));
xmlAddChild(cur1, xmlNewText((const xmlChar*)"\n"));
return;
}
void XMLParser::delConfig(xmlDocPtr doc, const string& section, const string& name)
{
string res;
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::delConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::delConfig: error accessing XML root");
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
while (cur1 != NULL)
{
string cur1name = (const char*)cur1->name;
if ((boost::iequals(cur1name, section)))
{
string cur1name = (const char*)cur1->name;
xmlNodePtr cur2 = cur1->xmlChildrenNode;
if ((boost::iequals(cur1name, section)))
while (cur2 != NULL)
{
xmlNodePtr tmp = cur2;
cur2 = cur2->next;
string tmpname = (const char*)tmp->name;
if ((boost::iequals(tmpname, name)))
{
xmlNodePtr cur2 = cur1->xmlChildrenNode;
while (cur2 != NULL)
{
xmlNodePtr tmp = cur2;
cur2 = cur2->next;
string tmpname = (const char*)tmp->name;
if ((boost::iequals(tmpname, name)))
{
xmlUnlinkNode(tmp);
xmlFreeNode(tmp);
}
}
xmlUnlinkNode(tmp);
xmlFreeNode(tmp);
}
cur1 = cur1->next;
}
}
return;
cur1 = cur1->next;
}
return;
}
const vector<string> XMLParser::enumConfig(const xmlDocPtr doc) const
{
vector<string> resv;
string res;
vector<string> resv;
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
{
res = reinterpret_cast<const char*>(cur1->name);
while (cur1 != NULL)
{
res = reinterpret_cast<const char*>(cur1->name);
if (res != "text" && res != "comment")
resv.push_back(res);
if (res != "text" && res != "comment")
resv.push_back(res);
cur1 = cur1->next;
}
cur1 = cur1->next;
}
return resv;
return resv;
}
const vector<string> XMLParser::enumSection(const xmlDocPtr doc, const string& section) const
{
vector<string> resv;
string res;
vector<string> resv;
string res;
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
xmlNodePtr cur1 = xmlDocGetRootElement(doc);
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
if (cur1 == NULL)
throw runtime_error("XMLParser::getConfig: error accessing XML root");
cur1 = cur1->xmlChildrenNode;
cur1 = cur1->xmlChildrenNode;
while (cur1 != NULL)
while (cur1 != NULL)
{
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
{
if ((!xmlStrcmp(cur1->name, (const xmlChar*)section.c_str())))
{
xmlNodePtr cur2 = cur1->xmlChildrenNode;
xmlNodePtr cur2 = cur1->xmlChildrenNode;
while (cur2 != NULL)
{
res = reinterpret_cast<const char*>(cur2->name);
while (cur2 != NULL)
{
res = reinterpret_cast<const char*>(cur2->name);
if (res != "text" && res != "comment")
resv.push_back(res);
if (res != "text" && res != "comment")
resv.push_back(res);
cur2 = cur2->next;
}
}
cur1 = cur1->next;
cur2 = cur2->next;
}
}
return resv;
cur1 = cur1->next;
}
return resv;
}
} //namespace
} // namespace config
// vim:ts=4 sw=4:

View File

@ -16,9 +16,9 @@
MA 02110-1301, USA. */
/******************************************************************************************
* $Id$
*
******************************************************************************************/
* $Id$
*
******************************************************************************************/
/**
* @file
*/
@ -30,37 +30,37 @@
namespace config
{
/** class XMLParser */
class XMLParser
{
public:
XMLParser() { }
~XMLParser() { }
public:
XMLParser()
{
}
~XMLParser()
{
}
const std::string getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name) const;
const std::string getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name) const;
void getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name,
std::vector<std::string>& values) const;
void getConfig(const xmlDocPtr doc, const std::string& section, const std::string& name,
std::vector<std::string>& values) const;
void setConfig(xmlDocPtr doc, const std::string& section, const std::string& name,
const std::string& value);
void setConfig(xmlDocPtr doc, const std::string& section, const std::string& name,
const std::string& value);
void delConfig(xmlDocPtr doc, const std::string& section, const std::string& name);
void delConfig(xmlDocPtr doc, const std::string& section, const std::string& name);
const std::vector<std::string> enumConfig(const xmlDocPtr doc) const;
const std::vector<std::string> enumSection(const xmlDocPtr doc, const std::string& section) const;
private:
//defaults okay
//XMLParser(const XMLParser& rhs);
//XMLParser& operator=(const XMLParser& rhs);
const std::vector<std::string> enumConfig(const xmlDocPtr doc) const;
const std::vector<std::string> enumSection(const xmlDocPtr doc, const std::string& section) const;
private:
// defaults okay
// XMLParser(const XMLParser& rhs);
// XMLParser& operator=(const XMLParser& rhs);
};
} //namespace
} // namespace config
// vim:ts=4 sw=4: