Index: ext/libicpf/src/callback.cpp =================================================================== diff -u -N -rc53cff389f468ccd962ceeea6c1f45da58a49258 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/callback.cpp (.../callback.cpp) (revision c53cff389f468ccd962ceeea6c1f45da58a49258) +++ ext/libicpf/src/callback.cpp (.../callback.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -22,21 +22,53 @@ */ #include "callback.h" #include +#include BEGIN_ICPF_NAMESPACE #define STORAGE ((std::vector*)m_pStorage) -callback_list::callback_list() +callback_list::callback_list() : + m_lock(), + m_pStorage(NULL) { m_pStorage=(void*)new std::vector; } +callback_list::callback_list(const callback_list& rSrc) : + m_lock(), + m_pStorage(NULL) +{ + m_pStorage=(void*)new std::vector; + STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); + assert(false); // we should not use the copy constructor at all !!! +} + callback_list::~callback_list() { - delete STORAGE; + try + { + delete STORAGE; + } + catch(...) + { + + } } +const callback_list& callback_list::operator=(const callback_list& rSrc) +{ + assert(false); // we shouldn't use the assignment operator at all!!! + if (this != &rSrc) + { + delete STORAGE; + m_pStorage=(void*)new std::vector; + STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); + } + + return *this; +} + void callback_list::add(PFNFUNC pfn, ptr_t param) { m_lock.lock(); Index: ext/libicpf/src/callback.h =================================================================== diff -u -N -re1fe275afd58c6df65f3ceac3b8959d39d3fbc3d -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/callback.h (.../callback.h) (revision e1fe275afd58c6df65f3ceac3b8959d39d3fbc3d) +++ ext/libicpf/src/callback.h (.../callback.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -47,7 +47,8 @@ /** \name Construction/destruction */ /**@{*/ callback_list(); - ~callback_list(); + callback_list(const callback_list& rSrc); + virtual ~callback_list(); /**@}*/ void add(PFNFUNC pfn, ptr_t param); @@ -59,6 +60,8 @@ void lock(); void unlock(); + const callback_list& operator=(const callback_list& rSrc); + protected: icpf::mutex m_lock; ///< A locking mechanism for the storage area @@ -83,7 +86,7 @@ /** \name Construction/destruction */ /**@{*/ callback1() { }; ///< Standard constructor - ~callback1() { }; ///< Standard destructor + virtual ~callback1() { }; ///< Standard destructor /**@}*/ /** \name User interface */ @@ -140,7 +143,7 @@ /** \name Construction/destruction */ /**@{*/ callback2() { }; ///< Standard constructor - ~callback2() { }; ///< Standard destructor + virtual ~callback2() { }; ///< Standard destructor /**@}*/ /** \name User interface */ @@ -198,7 +201,7 @@ /** \name Construction/destruction */ /**@{*/ callback3() { }; ///< Standard constructor - ~callback3() { }; ///< Standard destructor + virtual ~callback3() { }; ///< Standard destructor /**@}*/ /** \name User interface */ Index: ext/libicpf/src/cfg.cpp =================================================================== diff -u -N -r8d691767fb8f0643d990f2613daffd4ec18422fa -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/cfg.cpp (.../cfg.cpp) (revision 8d691767fb8f0643d990f2613daffd4ec18422fa) +++ ext/libicpf/src/cfg.cpp (.../cfg.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -23,7 +23,6 @@ */ #include "cfg.h" -#include #include #include "str.h" #include @@ -47,42 +46,49 @@ config *__g_cfg=NULL; // to make access faster -#define m_pvProperties ((std::vector*)m_pProperties) +#define m_pvProperties ((std::vector*)m_pProperties) ////////////////////////////////////////////////////////////////////////////////// // prop_group class /** Standard constructor */ -prop_group::prop_group(ulong_t ulID) +prop_group::prop_group(ulong_t ulID) : + m_pProperties(NULL), + m_ulGroupID(ulID) { - m_ulGroupID=ulID; - m_pProperties=(void*)new std::vector; + m_pProperties=(void*)new std::vector; } /** Standard destructor */ prop_group::~prop_group() { - delete m_pvProperties; + try + { + delete m_pvProperties; + } + catch(...) + { + } } /** Function adds a new property id to the group. - * \param[in] iProp - id of a property to add + * \param[in] ulProp - id of a property to add */ -void prop_group::add(int_t iProp) +void prop_group::add(ulong_t ulProp) { - m_pvProperties->push_back(iProp); + m_pvProperties->push_back(ulProp); } /** Function searches for a specific property id inside the list. * \return True if the property has been found, false if not. */ -bool prop_group::is_set(int_t iProp) +bool prop_group::is_set(ulong_t ulProp) { - for (std::vector::iterator it=m_pvProperties->begin();it != m_pvProperties->end();it++) + for (std::vector::iterator it=m_pvProperties->begin();it != m_pvProperties->end();it++) { - if ((*it) == iProp) + if ((*it) == ulProp) return true; } @@ -92,24 +98,24 @@ /** Function returns a count of properties contained in the list. * \return A count of properties. */ -ulong_t prop_group::count() +ulong_t prop_group::count() const { return (ulong_t)m_pvProperties->size(); } /** Function returns a property ID at a specified index. - * \param[in] - an index + * \param[in] ulIndex - an index * \return A property id. */ -int_t prop_group::get_at(int_t iIndex) +ulong_t prop_group::get_at(ulong_t ulIndex) { - return m_pvProperties->at(iIndex); + return m_pvProperties->at(ulIndex); } /** Function returns the group id. * \return A group ID. */ -ulong_t prop_group::get_groupid() +ulong_t prop_group::get_groupid() const { return m_ulGroupID; } @@ -132,8 +138,15 @@ * \param[in] bGlobal - specifies if this class should be globally accessible by the get_config() friend * function. */ -config::config(bool bGlobal) - :m_bModified(false) +config::config(bool bGlobal) : + m_lock(), + m_pProps(NULL), + m_pUnreg(NULL), + m_bModified(false), +#ifdef USE_ENCRYPTION + m_strPassword(), +#endif + m_clbPropertyChanged() { m_pProps=(void*)new std::vector<_PROP>; m_pUnreg=(void*)new std::vector<_PROP>; @@ -146,8 +159,14 @@ */ config::~config() { - delete m_pvProps; - delete m_pvUnreg; + try + { + delete m_pvProps; + delete m_pvUnreg; + } + catch(...) + { + } } /** Function opens the specified file, reads all the lines sequentially @@ -227,7 +246,7 @@ char_t szLine[MAX_LINE]; while(fgets(szLine, MAX_LINE, pFile)) { - vLines.push_back((const char_t*)trim(szLine)); + vLines.push_back((string)trim(szLine)); } fclose(pFile); @@ -294,9 +313,9 @@ if ( (pFile=fopen(pszFile, "w")) == NULL) return -1; - for (std::vector::iterator it=vLines.begin();it != vLines.end();it++) + for (std::vector::iterator vit=vLines.begin();vit != vLines.end();vit++) { - if (fprintf(pFile, STRFMT "\n", (const char_t*)(*it)) < 0) + if (fprintf(pFile, STRFMT "\n", (const char_t*)(*vit)) < 0) return -1; } @@ -307,14 +326,14 @@ /** Function returns a property type for a given property id. * \note The function returns only the type, and not the rest of the property flags. - * \param[in] iProp - property id to get info about. + * \param[in] ulProp - property id to get info about. * \return The property type. */ -int_t config::get_proptype(int_t iProp) +int_t config::get_proptype(ulong_t ulProp) { m_lock.lock(); - int_t iRet=m_pvProps->at(iProp).iType & PTM_TYPE; + int_t iRet=m_pvProps->at(ulProp).iType & PTM_TYPE; m_lock.unlock(); return iRet; @@ -330,22 +349,22 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_int(const char_t* pszName, int_t iDef, int_t iLo, int_t iHi, int_t iFlags) +ulong_t config::register_int(const char_t* pszName, int_t iDef, int_t iLo, int_t iHi, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; // check if the property is in the unreg container - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { // property not found in the unreg - means that this is quite new stuff prop.bModified=true; @@ -356,8 +375,8 @@ else { // get the entry - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); // set the value from a string int_t iVal=atol(prop.val.pszVal); @@ -373,10 +392,10 @@ // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } @@ -390,21 +409,21 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_uint(const char_t* pszName, uint_t uiDef, uint_t uiLo, uint_t uiHi, int_t iFlags) +ulong_t config::register_uint(const char_t* pszName, uint_t uiDef, uint_t uiLo, uint_t uiHi, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { prop.pszName=new char_t[strlen(pszName)+1]; strcpy(prop.pszName, pszName); @@ -414,8 +433,8 @@ else { // get the entry - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); uint_t uiVal=strtoul(prop.val.pszVal, NULL, 10); delete [] prop.val.pszVal; @@ -430,10 +449,10 @@ // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } @@ -447,21 +466,21 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_longlong(const char_t* pszName, longlong_t llDef, longlong_t llLo, longlong_t llHi, int_t iFlags) +ulong_t config::register_longlong(const char_t* pszName, longlong_t llDef, longlong_t llLo, longlong_t llHi, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { prop.pszName=new char_t[strlen(pszName)+1]; strcpy(prop.pszName, pszName); @@ -471,8 +490,8 @@ else { // get the entry - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); ll_t llVal; #ifdef _WIN32 @@ -492,10 +511,10 @@ // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } @@ -509,21 +528,21 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_ulonglong(const char_t* pszName, ulonglong_t ullDef, ulonglong_t ullLo, ulonglong_t ullHi, int_t iFlags) +ulong_t config::register_ulonglong(const char_t* pszName, ulonglong_t ullDef, ulonglong_t ullLo, ulonglong_t ullHi, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { prop.pszName=new char_t[strlen(pszName)+1]; strcpy(prop.pszName, pszName); @@ -532,8 +551,8 @@ } else { - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); ull_t ullVal; #ifdef _WIN32 @@ -553,10 +572,10 @@ // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } @@ -568,21 +587,21 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_bool(const char_t* pszName, bool bDef, int_t iFlags) +ulong_t config::register_bool(const char_t* pszName, bool bDef, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { prop.pszName=new char_t[strlen(pszName)+1]; strcpy(prop.pszName, pszName); @@ -591,8 +610,8 @@ } else { - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); bool bVal; if (strcmp(prop.val.pszVal, "yes") == 0) @@ -612,10 +631,10 @@ // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } @@ -629,21 +648,21 @@ * \param[in] iFlags - additional flags that should be associated with property * \return Property ID of the newly registered property. */ -int_t config::register_string(const char_t* pszName, const char_t* pszDef, int_t iFlags) +ulong_t config::register_string(const char_t* pszName, const char_t* pszDef, int_t iFlags) { // check if there is already registered value with the given name m_lock.lock(); - int_t iRes; - if (iFlags & PF_CHECK && (iRes=is_registered(pszName)) != -1) + ulong_t ulRes; + if (iFlags & PF_CHECK && (ulRes=is_registered(pszName)) != (ulong_t)-1) { m_lock.unlock(); - return iRes; + return ulRes; } else { _PROP prop; - if ( (iRes = is_unreg(pszName)) == -1 ) + if ( (ulRes = is_unreg(pszName)) == (ulong_t)-1 ) { prop.iType=PT_STRING | iFlags; #ifdef USE_ENCRYPTION @@ -659,115 +678,115 @@ } else { - prop=m_pvUnreg->at(iRes); - m_pvUnreg->erase(m_pvUnreg->begin()+iRes); + prop=m_pvUnreg->at(ulRes); + m_pvUnreg->erase(m_pvUnreg->begin()+ulRes); prop.iType = PT_STRING | iFlags; } // add to the list m_pvProps->push_back(prop); m_bModified=true; - iRes=(int_t)(m_pvProps->size()-1); + ulRes=(ulong_t)(m_pvProps->size()-1); m_lock.unlock(); - return iRes; + return ulRes; } } /** Functions retrieves the int_t value associated with a given property ID. Can be called * from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The property value. */ -int_t config::get_int(int_t iProp) +int_t config::get_int(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_INT); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_INT); - int_t iRet=m_pvProps->at(iProp).val.i.iVal; + int_t iRet=m_pvProps->at(ulProp).val.i.iVal; m_lock.unlock(); return iRet; } /** Functions retrieves the uint_t value associated with a given property ID. Can be called * from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The property value. */ -uint_t config::get_uint(int_t iProp) +uint_t config::get_uint(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_UINT); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_UINT); - int_t ulRet=m_pvProps->at(iProp).val.ui.uiVal; + uint_t ulRet=m_pvProps->at(ulProp).val.ui.uiVal; m_lock.unlock(); return ulRet; } /** Functions retrieves the longlong_t value associated with a given property ID. Can be called * from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The property value. */ -longlong_t config::get_longlong(int_t iProp) +longlong_t config::get_longlong(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_LONGLONG); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_LONGLONG); - longlong_t llRet=m_pvProps->at(iProp).val.ll.llVal; + longlong_t llRet=m_pvProps->at(ulProp).val.ll.llVal; m_lock.unlock(); return llRet; } /** Functions retrieves the ulonglong_t value associated with a given property ID. Can be called * from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The property value. */ -ulonglong_t config::get_ulonglong(int_t iProp) +ulonglong_t config::get_ulonglong(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_ULONGLONG); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_ULONGLONG); - ulonglong_t ullRet=m_pvProps->at(iProp).val.ull.ullVal; + ulonglong_t ullRet=m_pvProps->at(ulProp).val.ull.ullVal; m_lock.unlock(); return ullRet; } /** Functions retrieves the bool value associated with a given property ID. Can be called * from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The property value. */ -bool config::get_bool(int_t iProp) +bool config::get_bool(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_BOOL); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_BOOL); - bool bRet=m_pvProps->at(iProp).val.bVal; + bool bRet=m_pvProps->at(ulProp).val.bVal; m_lock.unlock(); return bRet; } /** Functions retrieves the string value associated with a given property ID. Can be called * from any thread. The string contained in the internal structure is copied to the buffer * specified by user. Max count of chars that can be copied is specified by the buffer length. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[out] psz - buffer for the string * \param[in] tMaxLen - length of the buffer */ -void config::get_string(int_t iProp, char_t* psz, size_t tMaxLen) +void config::get_string(ulong_t ulProp, char_t* psz, size_t tMaxLen) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_STRING); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_STRING); - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); #ifdef USE_ENCRYPTION // if the property is encrypted and not decoded yet - decode it @@ -792,16 +811,16 @@ /** Functions retrieves the int_t value associated with a given property ID. Can be called * from any thread. Function returns a pointer to a string contained in the internal structures * so it is definitely faster than the other get_string function, but is much nore dangerous. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \return The pointer to a string contained in the internal structure. */ -char_t* config::get_string(int_t iProp) +char_t* config::get_string(ulong_t ulProp) { m_lock.lock(); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_STRING); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_STRING); - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); #ifdef USE_ENCRYPTION // if the property is encrypted and not decoded yet - decode it @@ -827,17 +846,17 @@ /** Function sets the int_t value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] lVal - the new value of property to set */ -void config::set_int(int_t iProp, int_t iVal, prop_group* pGroup) +void config::set_int(ulong_t ulProp, int_t iVal, prop_group* pGroup) { m_lock.lock(); // get the data - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_INT); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_INT); int_t iOldVal=prop.val.i.iVal; @@ -860,29 +879,29 @@ if (bMod) { if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } } /** Function sets the uint_t value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] uiVal - the new value of property to set */ -void config::set_uint(int_t iProp, uint_t uiVal, prop_group* pGroup) +void config::set_uint(ulong_t ulProp, uint_t uiVal, prop_group* pGroup) { m_lock.lock(); // get the data - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_UINT); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_UINT); uint_t uiOldVal=prop.val.ui.uiVal; @@ -906,29 +925,29 @@ if (bMod) { if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } } /** Function sets the longlong_t value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] llVal - the new value of property to set */ -void config::set_longlong(int_t iProp, longlong_t llVal, prop_group* pGroup) +void config::set_longlong(ulong_t ulProp, longlong_t llVal, prop_group* pGroup) { m_lock.lock(); // get the data - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_LONGLONG); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_LONGLONG); ll_t llOldVal=prop.val.ll.llVal; @@ -952,29 +971,29 @@ if (bMod) { if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } } /** Function sets the ulonglong_t value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] ullVal - the new value of property to set */ -void config::set_ulonglong(int_t iProp, ulonglong_t ullVal, prop_group* pGroup) +void config::set_ulonglong(ulong_t ulProp, ulonglong_t ullVal, prop_group* pGroup) { m_lock.lock(); // get the data - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_ULONGLONG); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_ULONGLONG); ull_t ullOldVal=prop.val.ull.ullVal; @@ -998,28 +1017,28 @@ if (bMod) { if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } } /** Function sets the bool value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] bVal - the new value of property to set */ -void config::set_bool(int_t iProp, bool bVal, prop_group* pGroup) +void config::set_bool(ulong_t ulProp, bool bVal, prop_group* pGroup) { m_lock.lock(); // get the data - _PROP& prop=m_pvProps->at(iProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_BOOL); + _PROP& prop=m_pvProps->at(ulProp); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_BOOL); bool bMod=(prop.val.bVal != bVal); if (bMod) @@ -1034,28 +1053,28 @@ if (bMod) { if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } } /** Function sets the string value for a property with specified ID. Can be * called from any thread. - * \param[in] iProp - property identifier returned by one of the register_* functions + * \param[in] ulProp - property identifier returned by one of the register_* functions * \param[in] pszVal - the new value of property to set */ -void config::set_string(int_t iProp, const char_t* pszVal, prop_group* pGroup) +void config::set_string(ulong_t ulProp, const char_t* pszVal, prop_group* pGroup) { m_lock.lock(); - _PROP& prop=m_pvProps->at(iProp); + _PROP& prop=m_pvProps->at(ulProp); - assert((m_pvProps->at(iProp).iType & PTM_TYPE) == PT_STRING); + assert((m_pvProps->at(ulProp).iType & PTM_TYPE) == PT_STRING); delete [] prop.val.pszVal; prop.val.pszVal=new char_t[strlen(pszVal)+1]; @@ -1073,11 +1092,11 @@ m_lock.unlock(); if (pGroup) - pGroup->add(iProp); + pGroup->add(ulProp); else { - prop_group* pg=begin_group(-1); - pg->add(iProp); + prop_group* pg=begin_group((ulong_t)-1); + pg->add(ulProp); end_group(pg); } } @@ -1090,7 +1109,7 @@ * \param[in] ulID - group id * \return A pointer to a new property group. Must be released using end_group(). */ -prop_group* config::begin_group(ulong_t ulID) +prop_group* config::begin_group(ulong_t ulID) const { return new prop_group(ulID); } @@ -1146,15 +1165,15 @@ * the correctness of the property. If it does not met the criteria, then function does nothing. * \param[in/out] prop - address of the structure describing the property. */ -void config::encrypt_property(_PROP* prop) +void config::encrypt_property(_PROP* prop) const { printf("Encrypting...\n"); if ((prop->iType & (PT_STRING | PF_ENCRYPTED | PF_DECODED)) == (PT_STRING | PF_ENCRYPTED | PF_DECODED)) { printf("Real encrypt...\n"); - int_t iLen=(int_t)(((strlen(prop->val.pszVal)+1)*sizeof(char_t)+16)*2); - char_t *pszOut=new char_t[iLen]; + ulong_t ulLen=(ulong_t)(((strlen(prop->val.pszVal)+1)*sizeof(char_t)+16)*2); + char_t *pszOut=new char_t[ulLen]; try { strcrypt_aes256(prop->val.pszVal, (const char_t*)m_strPassword, pszOut); @@ -1176,12 +1195,12 @@ * the correctness of the property. If it does not met the criteria, then function does nothing. * \param[in/out] prop - address of the structure describing the property. */ -void config::decrypt_property(_PROP* prop) +void config::decrypt_property(_PROP* prop) const { if ((prop->iType & (PT_STRING | PF_ENCRYPTED | PF_DECODED)) == (PT_STRING | PF_ENCRYPTED)) { - int_t iLen=(int_t)(strlen(prop->val.pszVal)/2); - char_t *pszOut=new char_t[iLen]; + ulong_t ulLen=(ulong_t)(strlen(prop->val.pszVal)/2); + char_t *pszOut=new char_t[ulLen]; try { strdecrypt_aes256(prop->val.pszVal, (const char_t*)m_strPassword, pszOut); @@ -1208,7 +1227,7 @@ * \param[in,out] pszString - string to process * \return Pointer to the first non-whitespace character in a string. */ -char_t* config::trim(char_t* pszString) +char_t* config::trim(char_t* pszString) const { char_t *pszData=pszString; @@ -1299,6 +1318,8 @@ break; } + default: + break; } // we need not more processing @@ -1324,7 +1345,7 @@ * \param[in] prop - pointer to the internal structure with property description * \param[out] pres - pointer to a string object that will receive the line of text */ -void config::prepare_line(const _PROP* prop, string* pres) +void config::prepare_line(const _PROP* prop, string* pres) const { assert(prop && pres); @@ -1361,6 +1382,8 @@ snprintf(szLine, MAX_LINE, STRFMT " = " STRFMT, prop->pszName, prop->val.pszVal); break; } + default: + break; } szLine[MAX_LINE-1]='\0'; @@ -1373,33 +1396,33 @@ * \param[in] pszName - property name to search for * \return The property ID if property has been found, or -1 if not. */ -int_t config::is_registered(const char_t* pszName) +ulong_t config::is_registered(const char_t* pszName) { // enum through all of the existing nodes for (std::vector<_PROP>::iterator it=m_pvProps->begin();it != m_pvProps->end();it++) { if (strcmp(pszName, (*it).pszName) == 0) - return (int_t)(it-m_pvProps->begin()); + return (ulong_t)(it-m_pvProps->begin()); } - return -1; // no property found + return (ulong_t)-1; // no property found } /** Searches for an unregistered property contained in the unreg container. Returns an * index in the container unreg (if the entry have been found) or -1 (if not). * \param[in] pszName - name of the property to search for * \return Property index if found, -1 if not. */ -int_t config::is_unreg(const char_t* pszName) +ulong_t config::is_unreg(const char_t* pszName) { // enum through all of the existing nodes for (std::vector<_PROP>::iterator it=m_pvUnreg->begin();it != m_pvUnreg->end();it++) { if (strcmp(pszName, (*it).pszName) == 0) - return (int_t)(it-m_pvUnreg->begin()); + return (ulong_t)(it-m_pvUnreg->begin()); } - return -1; // no property found + return (ulong_t)-1; // no property found } END_ICPF_NAMESPACE Index: ext/libicpf/src/cfg.h =================================================================== diff -u -N -r8d691767fb8f0643d990f2613daffd4ec18422fa -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/cfg.h (.../cfg.h) (revision 8d691767fb8f0643d990f2613daffd4ec18422fa) +++ ext/libicpf/src/cfg.h (.../cfg.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -122,14 +122,14 @@ class LIBICPF_API prop_group { public: - prop_group(ulong_t ulID); ///< Standard constructor - ~prop_group(); ///< Standard destructor + explicit prop_group(ulong_t ulID); ///< Standard constructor + ~prop_group(); ///< Standard destructor - void add(int_t iProp); ///< Adds a new property id to the list - bool is_set(int_t iProp); ///< Checks if a property id is set inside this list - ulong_t count(); ///< Returns a count of properties in a list - int_t get_at(int_t iIndex); ///< Returns a property id at a given index - ulong_t get_groupid(); ///< Retrieves the group id + void add(ulong_t ulProp); ///< Adds a new property id to the list + bool is_set(ulong_t ulProp); ///< Checks if a property id is set inside this list + ulong_t count() const; ///< Returns a count of properties in a list + ulong_t get_at(ulong_t ulIndex); ///< Returns a property id at a given index + ulong_t get_groupid() const; ///< Retrieves the group id protected: void* m_pProperties; ///< Internal member. Pointer to a storage structure with an int_t. @@ -149,7 +149,7 @@ public: /** \name Construction/destruction */ /**@{*/ - config(bool bGlobal); ///< Standard constructor + explicit config(bool bGlobal); ///< Standard constructor ~config(); ///< Standard destructor /**@}*/ @@ -170,51 +170,51 @@ // property type management /** Property types */ /**@{*/ - int_t get_proptype(int_t iProp); ///< Retrieves the property type + int_t get_proptype(ulong_t ulProp); ///< Retrieves the property type /**@}*/ // registering the properties /** \name Properties registration functions */ /**@{*/ /// Registers int_t-type property - int_t register_int(const char_t* pszName, int_t iDef, int_t iLo, int_t iHi, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_int(const char_t* pszName, int_t iDef, int_t iLo, int_t iHi, int_t iFlags=PF_NULL | PF_CHECK); /// Registers uint_t-type property - int_t register_uint(const char_t* pszName, uint_t uiDef, uint_t uiLo, uint_t uiHi, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_uint(const char_t* pszName, uint_t uiDef, uint_t uiLo, uint_t uiHi, int_t iFlags=PF_NULL | PF_CHECK); /// Registers longlong_t-type property - int_t register_longlong(const char_t* pszName, longlong_t llDef, longlong_t llLo, longlong_t llHi, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_longlong(const char_t* pszName, longlong_t llDef, longlong_t llLo, longlong_t llHi, int_t iFlags=PF_NULL | PF_CHECK); /// Registers ulonglong_t-type property - int_t register_ulonglong(const char_t* pszName, ulonglong_t ullDef, ulonglong_t ullLo, ulonglong_t ullHi, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_ulonglong(const char_t* pszName, ulonglong_t ullDef, ulonglong_t ullLo, ulonglong_t ullHi, int_t iFlags=PF_NULL | PF_CHECK); /// Registers bool-type property - int_t register_bool(const char_t* pszName, bool bDef, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_bool(const char_t* pszName, bool bDef, int_t iFlags=PF_NULL | PF_CHECK); /// Registers string-type property - int_t register_string(const char_t* pszName, const char_t* pszDef, int_t iFlags=PF_NULL | PF_CHECK); + ulong_t register_string(const char_t* pszName, const char_t* pszDef, int_t iFlags=PF_NULL | PF_CHECK); /**@}*/ // getting property data /** \name Getting and setting values */ /**@{*/ - int_t get_int(int_t iProp); ///< Gets the value of int_t-type property - uint_t get_uint(int_t iProp); ///< Gets the value of uint_t-type property - longlong_t get_longlong(int_t iProp); ///< Gets the value of longlong_t-type property - ulonglong_t get_ulonglong(int_t iProp); ///< Gets the value of ulonglong_t-type property - bool get_bool(int_t iProp); ///< Gets the value of bool-type property - void get_string(int_t iProp, char_t* psz, size_t tMaxLen); ///< Gets the value of string-type property - char_t* get_string(int_t iProp); ///< Gets the value of ulonglong_t-type property (faster and more dangerous) + int_t get_int(ulong_t ulProp); ///< Gets the value of int_t-type property + uint_t get_uint(ulong_t ulProp); ///< Gets the value of uint_t-type property + longlong_t get_longlong(ulong_t ulProp); ///< Gets the value of longlong_t-type property + ulonglong_t get_ulonglong(ulong_t ulProp); ///< Gets the value of ulonglong_t-type property + bool get_bool(ulong_t ulProp); ///< Gets the value of bool-type property + void get_string(ulong_t ulProp, char_t* psz, size_t tMaxLen); ///< Gets the value of string-type property + char_t* get_string(ulong_t ulProp); ///< Gets the value of ulonglong_t-type property (faster and more dangerous) // setting property data - void set_int(int_t iProp, int_t iVal, prop_group* pGroup=NULL); ///< Sets the value of int_t-type property - void set_uint(int_t iProp, uint_t uiVal, prop_group* pGroup=NULL); ///< Sets the value of uint_t-type property - void set_longlong(int_t iProp, longlong_t llVal, prop_group* pGroup=NULL); ///< Sets the value of longlong_t-type property - void set_ulonglong(int_t iProp, ulonglong_t ullVal, prop_group* pGroup=NULL); ///< Sets the value of ulonglong_t-type property - void set_bool(int_t iProp, bool bVal, prop_group* pGroup=NULL); ///< Sets the value of bool-type property - void set_string(int_t iProp, const char_t* pszVal, prop_group* pGroup=NULL); ///< Sets the value of string-type property + void set_int(ulong_t ulProp, int_t iVal, prop_group* pGroup=NULL); ///< Sets the value of int_t-type property + void set_uint(ulong_t ulProp, uint_t uiVal, prop_group* pGroup=NULL); ///< Sets the value of uint_t-type property + void set_longlong(ulong_t ulProp, longlong_t llVal, prop_group* pGroup=NULL); ///< Sets the value of longlong_t-type property + void set_ulonglong(ulong_t ulProp, ulonglong_t ullVal, prop_group* pGroup=NULL); ///< Sets the value of ulonglong_t-type property + void set_bool(ulong_t ulProp, bool bVal, prop_group* pGroup=NULL); ///< Sets the value of bool-type property + void set_string(ulong_t ulProp, const char_t* pszVal, prop_group* pGroup=NULL); ///< Sets the value of string-type property /**@}*/ // group support /** \name Property group support */ /**@{*/ - prop_group* begin_group(ulong_t ulID); ///< Begins a property group (currently handles multiple property changes when setting property values) + prop_group* begin_group(ulong_t ulID) const; ///< Begins a property group (currently handles multiple property changes when setting property values) void end_group(prop_group* pGroup); ///< Ends a property group /**@}*/ @@ -228,18 +228,18 @@ friend config* get_config(); ///< Retrieves the pointer to the global config class protected: - char_t* trim(char_t* pszString); ///< Gets rid of whitespace characters from a string + char_t* trim(char_t* pszString) const; ///< Gets rid of whitespace characters from a string void process_line(const char_t* pszName, const char_t* pszValue); ///< Sets a property value if registered - void prepare_line(const _PROP* prop, string* pres); ///< Prepares a line of text with property key and value to write to a file - int_t is_registered(const char_t* pszName); ///< Checks if a property with a given key has been registered - int_t is_unreg(const char_t* pszName); ///< Chacks if the path is contained in unreg container + void prepare_line(const _PROP* prop, string* pres) const; ///< Prepares a line of text with property key and value to write to a file + ulong_t is_registered(const char_t* pszName); ///< Checks if a property with a given key has been registered + ulong_t is_unreg(const char_t* pszName); ///< Chacks if the path is contained in unreg container #ifdef USE_ENCRYPTION - void encrypt_property(_PROP* prop); ///< Encrypts a string property - void decrypt_property(_PROP* prop); ///< Decrypts a string property + void encrypt_property(_PROP* prop) const; ///< Encrypts a string property + void decrypt_property(_PROP* prop) const; ///< Decrypts a string property #endif -public: +protected: mutex m_lock; ///< Lock for the multi-threaded access to the properties void* m_pProps; ///< Properties' storage void* m_pUnreg; ///< Properties read from file, but not registered. Index: ext/libicpf/src/circ_buffer.cpp =================================================================== diff -u -N -r6595bc5b8ba8079e6651ecb5f4c99a7aedc5af9f -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/circ_buffer.cpp (.../circ_buffer.cpp) (revision 6595bc5b8ba8079e6651ecb5f4c99a7aedc5af9f) +++ ext/libicpf/src/circ_buffer.cpp (.../circ_buffer.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -20,7 +20,6 @@ #include "circ_buffer.h" #include #include -#include #include BEGIN_ICPF_NAMESPACE @@ -41,29 +40,42 @@ // internal buffer if it does not find the specified value inside of it #define _FAILSEEK_TRUNCATES 1 -circular_buffer::circular_buffer() +circular_buffer::circular_buffer() : + m_pbyBuffer(NULL), + m_tSize(0), + m_tDataSize(0), + m_tBitsAtEndCount(0) { - m_pbyBuffer=NULL; - m_tSize=0; - m_tDataSize=0; - m_tBitsAtEndCount=0; } -circular_buffer::circular_buffer(const circular_buffer& rSrc) +circular_buffer::circular_buffer(const circular_buffer& rSrc) : + m_pbyBuffer(NULL), + m_tSize(0), + m_tDataSize(0), + m_tBitsAtEndCount(0) { copy_from(rSrc); } circular_buffer::~circular_buffer() { - destroy(); + try + { + destroy(); + } + catch(...) + { + } } circular_buffer& circular_buffer::operator=(const circular_buffer& rSrc) { - // delete the old stuff - destroy(); - copy_from(rSrc); + if (this == &rSrc) + { + // delete the old stuff + destroy(); + copy_from(rSrc); + } return *this; } @@ -96,6 +108,8 @@ void circular_buffer::push_data(const byte_t* pbyBuffer, size_t tCount) { + assert(m_pbyBuffer); + // check if there is enough space if (m_tDataSize+tCount > m_tSize) resize_buffer(m_tDataSize+tCount); @@ -190,13 +204,13 @@ return (pop_data((byte_t*)pby, 1) == 1); } -long circular_buffer::pop_string(char_t** pszString) +ulong_t circular_buffer::pop_string(char_t** pszString) { ulong_t ul; if (!pop_ulong(&ul)) { *pszString=NULL; - return -1; + return (ulong_t)-1; } if (ul == 0) @@ -208,15 +222,15 @@ { // check if there is enough data if (m_tDataSize < ul) - return -1; + return (ulong_t)-1; // alloc buffer for a string (*pszString)=new char_t[ul]; if (pop_data((byte_t*)(*pszString), ul) != ul) { delete [] (*pszString); *pszString=NULL; - return -1; + return (ulong_t)-1; } else { @@ -226,8 +240,9 @@ } } -size_t circular_buffer::find(size_t tStartAt, ulong_t ulFnd) +size_t circular_buffer::find(size_t tStartAt, ulong_t ulFnd) const { + assert(m_pbyBuffer); // printf("searching for %lu from %lu\n", ulFnd, ulStartAt); // printf("internal structures: buf: 0x%lx, data size: %lu, buf size: %lu\n", m_pbyBuffer, m_tDataSize, m_tSize); for (size_t i=tStartAt;i m_tDataSize) m_tDataSize=0; else @@ -295,11 +312,11 @@ { // copy the old buffer to the new one memcpy(pszBuf, m_pbyBuffer, m_tDataSize); - - // destroy the old buffer - delete [] m_pbyBuffer; } + // destroy the old buffer + delete [] m_pbyBuffer; + // update data m_pbyBuffer=pszBuf; m_tSize=tNewSize; @@ -308,6 +325,8 @@ void circular_buffer::shrink_buffer() { #if _USE_SHRINKING == 1 + assert(m_pbyBuffer); + // check the current size of the data size_t tNewSize=(m_tDataSize & ~(_BUFFER_INC-1)) + _BUFFER_INC; if (m_tSize-tNewSize > _BUFFER_DEC) @@ -331,6 +350,7 @@ void circular_buffer::push_bits(ulong_t ulBits, byte_t byCount) { + assert(m_pbyBuffer); assert(byCount <= 32 && byCount >= 1); // count of bits must be a sane value assert(m_tBitsAtEndCount <= 7); // the internal bits count must be from the range [0..7]. For 8 bits in a buffer // there is value of 0. @@ -350,7 +370,7 @@ byte_t uc=(byte_t)(ulBits & 0x000000ff); // we are getting from it only ulCopy lowest bits, so shift if a bit - uc <<= 8-ulCopy; + uc <<= (8-ulCopy); // and apply m_pbyBuffer[m_tDataSize-1] |= uc; @@ -415,8 +435,9 @@ // enumerates all the bit-packs that exists in a buffer. If there were any bits operations performed // on a buffer - they must be finished by the PushBitsFinish. -void circular_buffer::enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) +void circular_buffer::enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const { + assert(m_pbyBuffer); assert(ulBitsCount >= 1 && ulBitsCount <=8); assert(pfn); Index: ext/libicpf/src/circ_buffer.h =================================================================== diff -u -N -r6595bc5b8ba8079e6651ecb5f4c99a7aedc5af9f -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/circ_buffer.h (.../circ_buffer.h) (revision 6595bc5b8ba8079e6651ecb5f4c99a7aedc5af9f) +++ ext/libicpf/src/circ_buffer.h (.../circ_buffer.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -57,18 +57,18 @@ size_t pop_data(byte_t* pbyBuffer, size_t tCount); bool pop_ulonglong(ull_t* pull); bool pop_ulong(ulong_t* pul); - long pop_string(char_t** pszString); // returns the length of alloc string (-1 for error) + ulong_t pop_string(char_t** pszString); // returns the length of alloc string (-1 for error) bool pop_ushort(ushort_t* pw); bool pop_uchar(uchar_t* pby); // operation on single bits void push_bits(ulong_t ulBits, byte_t byCount); // void PushBitsFinish(); // finishes the operation of pushing bits, so we could use normal Push/PopData - void enum_bit_packets(unsigned long ulBitsCount, PFNBITSCALLBACK pfn, void* pParam); + void enum_bit_packets(unsigned long ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const; // searching int forward_seek(ulong_t ulFnd); // seeks for the value and skips the bytes previous to it - size_t find(size_t tStartAt, ulong_t ulFnd); // searches for the specified value in the buffer, returns an index + size_t find(size_t tStartAt, ulong_t ulFnd) const; // searches for the specified value in the buffer, returns an index // (size_t)-1 if not found void skip_bytes(size_t tCount); // skips some bytes from the beginning of a buffer @@ -78,8 +78,8 @@ size_t get_datasize() const { return m_tDataSize; }; bool is_empty() const { return m_tDataSize == 0; }; - operator byte_t*() const { return m_pbyBuffer; }; - byte_t* get_buffer() const { return m_pbyBuffer; }; + operator const byte_t*() const { return m_pbyBuffer; }; + const byte_t* get_buffer() const { return m_pbyBuffer; }; // void dump(); @@ -88,7 +88,7 @@ void resize_buffer(size_t tNewSize); // enlarges buffer void shrink_buffer(); -public: +protected: byte_t *m_pbyBuffer; // internal buffer size_t m_tSize; // size of the buffer size_t m_tDataSize; // data size inside the buffer (the last byte could be partially filled with data Index: ext/libicpf/src/conv.cpp =================================================================== diff -u -N -r7e9a010922bf3325f4b1376bb166736540301dd8 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/conv.cpp (.../conv.cpp) (revision 7e9a010922bf3325f4b1376bb166736540301dd8) +++ ext/libicpf/src/conv.cpp (.../conv.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -24,7 +24,7 @@ char_t __hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; -LIBICPF_API void bin2hex(uchar_t* pbyIn, uint_t tInCount, char_t *pszOut) +LIBICPF_API void bin2hex(const uchar_t* pbyIn, uint_t tInCount, char_t *pszOut) { for (uint_t i=0;i= '0' && *pszIn <= '9') - by=(*pszIn - '0') << 4; + by=(byte_t)(*pszIn - '0') << 4; else if (*pszIn >= 'a' && *pszIn <= 'f') - by=(*pszIn - 'a' + 10) << 4; + by=(byte_t)(*pszIn - 'a' + 10) << 4; else if (*pszIn >= 'A' && *pszIn <= 'F') - by=(*pszIn - 'A' + 10) << 4; + by=(byte_t)(*pszIn - 'A' + 10) << 4; else return false; // lsb 4bits - *pszIn++; + pszIn++; if (*pszIn >= '0' && *pszIn <= '9') by|=(*pszIn - '0'); else if (*pszIn >= 'a' && *pszIn <= 'f') @@ -65,7 +65,7 @@ else return false; - *pszIn++; + pszIn++; *pbyOut++=by; } Index: ext/libicpf/src/conv.h =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/conv.h (.../conv.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/conv.h (.../conv.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -25,7 +25,7 @@ BEGIN_ICPF_NAMESPACE -LIBICPF_API void bin2hex(uchar_t *pbyIn, uint_t tInCount, char_t *pszOut); +LIBICPF_API void bin2hex(const uchar_t *pbyIn, uint_t tInCount, char_t *pszOut); LIBICPF_API bool hex2bin(const char_t* pszIn, uint_t tInCount, uchar_t* pbyOut); END_ICPF_NAMESPACE Index: ext/libicpf/src/crc32.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/crc32.cpp (.../crc32.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/crc32.cpp (.../crc32.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -104,6 +104,7 @@ */ inline void __crc32partial(byte_t byte, uint_t *pdwCrc32) { +// assert(pdwCrc32 != NULL); *pdwCrc32 = ((*pdwCrc32) >> 8) ^ __crc32data__[byte ^ ((*pdwCrc32) & 0x000000FF)]; } @@ -112,7 +113,7 @@ * \param[in] tLen - length of the data in a buffer * \return Calculated crc32 checksum. */ -uint_t crc32(byte_t* pbyData, size_t tLen) +uint_t crc32(const byte_t* pbyData, size_t tLen) { uint_t dwCRC=0xffffffff; for (size_t i=0;i #include #ifdef _WIN32 #include #endif -#ifdef ENABLE_MUTEX_DEBUGGING - BEGIN_ICPF_NAMESPACE /////////////////////////////////////////////////////////////// Index: ext/libicpf/src/dumpctx.cpp =================================================================== diff -u -N -rcf97f25f2da163004d0b231b47027304ded79453 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/dumpctx.cpp (.../dumpctx.cpp) (revision cf97f25f2da163004d0b231b47027304ded79453) +++ ext/libicpf/src/dumpctx.cpp (.../dumpctx.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -23,7 +23,6 @@ #include "dumpctx.h" #include #include "log.h" -#include "macros.h" BEGIN_ICPF_NAMESPACE @@ -35,7 +34,13 @@ * \param[in] uiType - type of dump (one of the DCX_*) * \param[in] pParam - additional param - the type of theis param depends on the ulType */ -dumpctx::dumpctx(uint_t uiType, ptr_t pParam) +dumpctx::dumpctx(uint_t uiType, ptr_t pParam) : + m_lock(), + m_strBuffer(), + m_szBuffer(), + m_uiType(uiType), + m_pParam(pParam) + { m_uiType=uiType; if (uiType == DCX_FILE) @@ -44,8 +49,6 @@ m_pParam=(ptr_t)new char_t[tLen+1]; strcpy((char_t*)m_pParam, (const char_t*)pParam); } - else - m_pParam=pParam; } /** Destructor frees the internal data if needed @@ -54,6 +57,8 @@ { if (m_uiType == DCX_FILE) delete [] (char_t*)m_pParam; + else + m_pParam=NULL; // we won't have a leak here, since we don't alloc memory for case m_uiType != DCX_FILE } /** Function opens the dump. It means initializing the internal string @@ -102,6 +107,8 @@ ((log_file*)m_pParam)->logd(m_strBuffer); break; } + default: + break; } // clean the internal buffer Index: ext/libicpf/src/dumpctx.h =================================================================== diff -u -N -rcf97f25f2da163004d0b231b47027304ded79453 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/dumpctx.h (.../dumpctx.h) (revision cf97f25f2da163004d0b231b47027304ded79453) +++ ext/libicpf/src/dumpctx.h (.../dumpctx.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -58,7 +58,7 @@ public: /** \name Construction/destruction */ /**@{*/ - dumpctx(uint_t ulType, ptr_t pParam=NULL); ///< Standard constructor + explicit dumpctx(uint_t ulType, ptr_t pParam=NULL); ///< Standard constructor ~dumpctx(); ///< Standard destructor /**@}*/ Index: ext/libicpf/src/exception.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/exception.cpp (.../exception.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/exception.cpp (.../exception.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -44,15 +44,18 @@ * \param[in] uiSystemCode - system error code (platform dependent) * \param[in] uiReserved - currently unused; must be 0 */ -exception::exception(const char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) +exception::exception(const char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : + m_pszDesc(NULL), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(uiLine), + m_uiAppCode(uiAppCode), + m_uiSystemCode(uiSystemCode), + m_uiReserved(uiReserved) { set_string(&m_pszDesc, pszDesc); set_string(&m_pszFilename, pszFilename); set_string(&m_pszFunction, pszFunction); - m_uiLine=uiLine; - m_uiAppCode=uiAppCode; - m_uiSystemCode=uiSystemCode; - m_uiReserved=uiReserved; } /** Constructor that takes the ptr to a buffer as a description. The pointer to a buffer is @@ -66,15 +69,17 @@ * \param[in] uiSystemCode - system error code (platform dependent) * \param[in] uiReserved - currently unused; must be 0 */ -exception::exception(char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) +exception::exception(char_t* pszDesc, const char_t* pszFilename, const char_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : + m_pszDesc(pszDesc), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(uiLine), + m_uiAppCode(uiAppCode), + m_uiSystemCode(uiSystemCode), + m_uiReserved(uiReserved) { - m_pszDesc=pszDesc; set_string(&m_pszFilename, pszFilename); set_string(&m_pszFunction, pszFunction); - m_uiLine=uiLine; - m_uiAppCode=uiAppCode; - m_uiSystemCode=uiSystemCode; - m_uiReserved=uiReserved; } /** Destructor deletes all the allocated memory for the exception object @@ -120,7 +125,7 @@ */ const char_t* exception::get_info(char_t* pszInfo, intptr_t tMaxLen) { - snprintf(pszInfo, tMaxLen, "description: " STRFMT "\nfile: " STRFMT "\nfunction: " STRFMT "\nline: " ULFMT "\napp code: " ULFMT "\nsys code: " ULFMT "\nreserved: " ULFMT "\n", + snprintf(pszInfo, (size_t)tMaxLen, "description: " STRFMT "\nfile: " STRFMT "\nfunction: " STRFMT "\nline: " ULFMT "\napp code: " ULFMT "\nsys code: " ULFMT "\nreserved: " ULFMT "\n", m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); pszInfo[tMaxLen-1]='\0'; @@ -164,8 +169,8 @@ va_start(vl, pszFormat); // alloc some space - no more than MAX_EXCEPTION chracters - char_t* psz=new char_t[MAX_EXCEPTION]; - vsnprintf(psz, MAX_EXCEPTION, pszFormat, vl); + char_t* psz=new char_t[(size_t)MAX_EXCEPTION]; + vsnprintf(psz, (size_t)MAX_EXCEPTION, pszFormat, vl); psz[MAX_EXCEPTION-1]='\0'; return psz; } @@ -175,9 +180,9 @@ * \param[out] pszOut - pointer to char_t* which will receive the new buffer address * \param[in] pszIn - string to make a copy of */ -void exception::set_string(char_t** pszOut, const char_t* pszIn) +void exception::set_string(char_t** pszOut, const char_t* pszIn) const { - *pszOut=new char_t[strlen(pszIn)+1]; + *pszOut=new char_t[strlen(pszIn)+(uint_t)1]; strcpy(*pszOut, pszIn); } Index: ext/libicpf/src/exception.h =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/exception.h (.../exception.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/exception.h (.../exception.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -83,9 +83,9 @@ /**@}*/ protected: - void set_string(char_t** pszOut, const char_t* pszIn); ///< Makes a copy of an input string + void set_string(char_t** pszOut, const char_t* pszIn) const; ///< Makes a copy of an input string -public: +protected: char_t* m_pszDesc; ///< Exception description char_t* m_pszFilename; ///< Source file in which the exception has been thrown char_t* m_pszFunction; ///< Function name in the source file in which the exception has been thrown Index: ext/libicpf/src/file.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/file.cpp (.../file.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/file.cpp (.../file.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -65,22 +65,26 @@ /** Standard constructor - nullifies all member variables. */ -file::file() +file::file() : + m_hFile(FNULL), + m_pszPath(NULL), + m_uiFlags(0), + m_bLastOperation(false), + m_bBuffered(false), + m_uiBufferSize(0), + m_pbyBuffer(NULL), + m_uiCurrentPos(0), + m_uiDataCount(0), + m_bRememberedState(false), + m_bSerializing(0), + m_pbySerialBuffer(NULL), + m_uiSerialBufferSize(0), + m_uiSerialBufferPos(0), + m_uiDataBlockFlags(BF_NONE) +#ifdef USE_ENCRYPTION + , m_strPassword() +#endif { - m_hFile=FNULL; - m_pszPath=NULL; - m_uiFlags=0; - m_uiBufferSize=0; - m_pbyBuffer=NULL; - m_uiCurrentPos=0; - m_uiDataCount=0; - m_bBuffered=false; - m_bLastOperation=false; - m_bRememberedState=false; - m_pbySerialBuffer=NULL; - m_uiSerialBufferSize=0; - m_uiSerialBufferPos=0; - m_bSerializing=0; } /** Standard destructor - tries to close a file, but catches any exception thrown @@ -256,7 +260,7 @@ { // last - reading data // set file pointer to position current-(m_uiDataCount-m_uiCurrentPos) - _seek(-(int_t)(m_uiDataCount-m_uiCurrentPos), FS_CURRENT); + _seek(-(longlong_t)(m_uiDataCount-m_uiCurrentPos), FS_CURRENT); m_uiCurrentPos=0; m_uiDataCount=0; } @@ -270,10 +274,9 @@ * \param[in] iSize - count of bytes to read * \return Count of bytes that has been read (could be less than iSize) */ -int_t file::read(ptr_t pBuffer, int_t iSize) +ulong_t file::read(ptr_t pBuffer, ulong_t ulSize) { assert(m_hFile); // forgot to open the file ? - assert(iSize >= 0); // you out of your mind to try to read negative value of bytes ??? // flush if needed if (m_bLastOperation) @@ -287,20 +290,20 @@ // unbuffered operation (read what is needed) #ifdef _WIN32 DWORD rd=0; - if (!ReadFile(m_hFile, pBuffer, iSize, &rd, NULL)) + if (!ReadFile(m_hFile, pBuffer, ulSize, &rd, NULL)) #else int_t rd=0; - if ((rd=::read(m_hFile, pBuffer, iSize)) < 0) + if ((rd=::read(m_hFile, pBuffer, ulSize)) < 0) #endif THROW(exception::format("Cannot read data from file " STRFMT, m_pszPath), FERR_READ, CURRENT_LAST_ERROR, 0); - return (int_t)rd; // if 0 - eof (not treated as exception) + return rd; // if 0 - eof (not treated as exception) } else { // reads must be done by packets uint_t uiCurrPos=0; // position in external buffer - while (uiCurrPos < (uint_t)iSize) + while (uiCurrPos < ulSize) { // are there any data left ? if (m_uiDataCount == 0 || m_uiCurrentPos == m_uiDataCount) @@ -310,7 +313,7 @@ } // copy data into external buffer - uint_t uiCount=minval(m_uiDataCount-m_uiCurrentPos, iSize-uiCurrPos); + uint_t uiCount=minval(m_uiDataCount-m_uiCurrentPos, ulSize-uiCurrPos); memcpy(((byte_t*)pBuffer)+uiCurrPos, m_pbyBuffer+m_uiCurrentPos, uiCount); // update positions @@ -329,7 +332,7 @@ * \param[in] iSize - count of data to store * \return Count of data that has been stored */ -int_t file::write(ptr_t pBuffer, int_t iSize) +ulong_t file::write(ptr_t pBuffer, ulong_t ulSize) { assert(m_hFile); @@ -344,27 +347,27 @@ // standard write #ifdef _WIN32 DWORD wr=0; - if (!WriteFile(m_hFile, pBuffer, iSize, &wr, NULL)) + if (!WriteFile(m_hFile, pBuffer, ulSize, &wr, NULL)) #else int_t wr; - if ((wr=::write(m_hFile, pBuffer, iSize) == -1)) + if ((wr=::write(m_hFile, pBuffer, ulSize) == -1)) #endif THROW(exception::format("[file] Cannot write data to a file", m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); - return (int_t)wr; + return (ulong_t)wr; } else { uint_t uiPos=0; - while (uiPos < (uint_t)iSize) + while (uiPos < ulSize) { // check if buffer need storing if (m_uiCurrentPos == m_uiBufferSize) _write_packet(); // now add to internal buffer some data - uint_t uiCount=minval(m_uiBufferSize-m_uiCurrentPos, iSize-uiPos); + uint_t uiCount=minval(m_uiBufferSize-m_uiCurrentPos, ulSize-uiPos); memcpy(m_pbyBuffer+m_uiCurrentPos, ((byte_t*)pBuffer)+uiPos, uiCount); @@ -465,14 +468,14 @@ #endif THROW(exception::format("Cannot write data to a file " STRFMT, m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); } - - delete [] pszData; } catch(...) { delete [] pszData; throw; } + + delete [] pszData; } /** Moves the file pointer to some place in the file. If the file is in buffered @@ -666,7 +669,7 @@ // determine the size of the remaining data in file SERIALIZEINFOHEADER* psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - uint_t uiSize=psih->iRealSize-sizeof(SERIALIZEINFOHEADER); + uint_t uiSize=(uint_t)(psih->iRealSize-sizeof(SERIALIZEINFOHEADER)); // check the header crc uint_t uihc=crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(uint_t)); @@ -677,7 +680,7 @@ } // resize the buffer - _sbuf_resize(psih->iRealSize); + _sbuf_resize((uint_t)psih->iRealSize); // refresh the psih psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; @@ -1173,6 +1176,7 @@ void file::_sbuf_append(ptr_t pData, uint_t uiCount) { // check if we are writing + assert(m_pbySerialBuffer); assert(m_uiFlags & FA_WRITE); // check serial buffer size (if there is enough room for the data) @@ -1199,6 +1203,8 @@ */ void file::_sbuf_resize(uint_t uiNewLen) { + assert(m_pbySerialBuffer); + // alloc the new buffer byte_t* pbyNewBuffer=new byte_t[uiNewLen]; @@ -1225,6 +1231,7 @@ bool file::_read_string(char_t* pszStr, uint_t uiMaxLen) { assert(m_hFile); // file wasn't opened - error opening or you've forgotten to do so ? + assert(m_pbyBuffer != NULL); // last time was writing - free buffer if (m_bLastOperation) Index: ext/libicpf/src/file.h =================================================================== diff -u -N -r2fbc37353d34089b513dab08f83d494d5aea3e7f -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/file.h (.../file.h) (revision 2fbc37353d34089b513dab08f83d494d5aea3e7f) +++ ext/libicpf/src/file.h (.../file.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -118,8 +118,8 @@ void close(); ///< Closes the currently opened file // reads or writes the data from/to a file (uses buffering for these operations if enabled) - int_t read(ptr_t pBuffer, int_t iSize); ///< Reads some data from a file - int_t write(ptr_t pBuffer, int_t iSize); ///< Writes some data to a file + ulong_t read(ptr_t pBuffer, ulong_t ulSize); ///< Reads some data from a file + ulong_t write(ptr_t pBuffer, ulong_t ulSize); ///< Writes some data to a file // handling the lines of text in a file (autodetecting the windows/unix style of line ending) bool read_line(char_t* pszStr, uint_t uiMaxLen); ///< Reads a line of text from a file @@ -145,9 +145,9 @@ /// Enables or disables the buffering void set_buffering(bool bEnable=true, uint_t dwSize=4096); /// Returns the buffering state - bool is_buffered() { return m_bBuffered; }; + bool is_buffered() const { return m_bBuffered; }; /// Returns the current buffer size (for buffered operations) - uint_t get_buffersize() { return m_uiBufferSize; }; + uint_t get_buffersize() const { return m_uiBufferSize; }; void switch_unbuffered(); ///< Stores current buffered/unbuffered state and switches to unbuffered void switch_buffered(); ///< Stores current buffered/unbuffered state and switches to buffered @@ -172,9 +172,9 @@ // state checking /// Checks if the class is performing write-type serialization - bool is_storing() { return (m_uiFlags & FA_WRITE) != 0; }; + bool is_storing() const { return (m_uiFlags & FA_WRITE) != 0; }; /// Checks if the class is performing read-type serialization - bool is_loading() { return (m_uiFlags & FA_READ) != 0; }; + bool is_loading() const { return (m_uiFlags & FA_READ) != 0; }; // storing&reading data file& operator<<(bool val); ///< Stores a given 'val' parameter in the file Index: ext/libicpf/src/libicpf.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/libicpf.cpp (.../libicpf.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/libicpf.cpp (.../libicpf.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -4,9 +4,9 @@ #ifdef _WIN32 #include -BOOL APIENTRY DllMain( HANDLE hModule, +BOOL APIENTRY DllMain( HANDLE /*hModule*/, DWORD ul_reason_for_call, - LPVOID lpReserved + LPVOID /*lpReserved*/ ) { switch (ul_reason_for_call) @@ -16,6 +16,8 @@ case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; + default: + break; } return TRUE; } Index: ext/libicpf/src/libicpf.h =================================================================== diff -u -N -rd8dcefd5413af0498db7d6252a528b195ac07b3d -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/libicpf.h (.../libicpf.h) (revision d8dcefd5413af0498db7d6252a528b195ac07b3d) +++ ext/libicpf/src/libicpf.h (.../libicpf.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -64,6 +64,6 @@ /// Begins ch namespace #define BEGIN_ICPF_NAMESPACE namespace icpf { /// Ends ch namespace -#define END_ICPF_NAMESPACE }; +#define END_ICPF_NAMESPACE } #endif Index: ext/libicpf/src/log.cpp =================================================================== diff -u -N -rb939d4dc7fa1eb332df91ae6fa49bac51e444072 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/log.cpp (.../log.cpp) (revision b939d4dc7fa1eb332df91ae6fa49bac51e444072) +++ ext/libicpf/src/log.cpp (.../log.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -23,7 +23,6 @@ #include "log.h" #include #include -#include #include #include #include "macros.h" @@ -56,10 +55,12 @@ * Only one global log_file instance could exist in the application. */ log_file::log_file(bool bGlobal) : - m_bGlobal(bGlobal), m_pszPath(NULL), + m_iMaxSize(262144), m_bLogStd(false), - m_iLogLevel(LT_DEBUG) + m_iLogLevel(LT_DEBUG), + m_bGlobal(bGlobal), + m_lock() { if (m_bGlobal) { @@ -90,10 +91,13 @@ */ bool create_log(const char_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean) { - log_file* pLog=new log_file(true); - if (!pLog->init(pszPath, iMaxSize, iLogLevel, bLogStd, bClean)) + assert(__g_log == NULL); + + __g_log=new log_file(true); + if (!__g_log->init(pszPath, iMaxSize, iLogLevel, bLogStd, bClean)) { - delete pLog; + delete __g_log; + __g_log=NULL; return false; } @@ -130,7 +134,7 @@ * Quite slow function - have to access the file by opening and closing it. * \return Current file size. */ -int_t log_file::size() +int_t log_file::size() const { assert(m_pszPath); @@ -140,10 +144,10 @@ { if (fseek(pFile, 0, SEEK_END) == 0) iSize=ftell(pFile); + + fclose(pFile); } - fclose(pFile); - return iSize; } @@ -153,7 +157,7 @@ * \param[in] iAdd - size of the new string to be added to the log file * \return True if truncate succeeded or false if not. */ -bool log_file::truncate(int_t iAdd) +bool log_file::truncate(int_t iAdd) const { assert(m_pszPath); @@ -198,28 +202,28 @@ if (SetFilePointer(hFile, iSize-iNewSize, NULL, FILE_BEGIN) != INVALID_SET_FILE_POINTER) { - int_t iSrc=SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - int_t iDst=0; + long_t lSrc=(long_t)SetFilePointer(hFile, 0, NULL, FILE_CURRENT); + long_t lDst=0; DWORD tRD, tWR; do { // seek to src - SetFilePointer(hFile, iSrc, NULL, FILE_BEGIN); + SetFilePointer(hFile, lSrc, NULL, FILE_BEGIN); // read 4k chars from source offset if (ReadFile(hFile, szBuffer, 4096, &tRD, NULL)) { // seek to the dst - SetFilePointer(hFile, iDst, NULL, FILE_BEGIN); + SetFilePointer(hFile, lDst, NULL, FILE_BEGIN); FlushFileBuffers(hFile); // write the buffer to the dest offset WriteFile(hFile, szBuffer, tRD, &tWR, NULL); - iDst+=tWR; + lDst+=(long_t)tWR; } - iSrc+=tRD; + lSrc+=(long_t)tRD; } while(tRD != 0); @@ -590,10 +594,10 @@ * \param[out] pszOut - pointer to a buffer that will receive the data (must be 2048 bytes in size) * \return If the %err string was found and replaced within a given format string. */ -bool log_file::prepare_fmt(const char_t* pszStr, int iSysErr, char_t* pszOut) +bool log_file::prepare_fmt(const char_t* pszStr, int iSysErr, char_t* pszOut) const { // find the %err in pszStr - char_t* pszFnd=strstr(pszStr, "%err"); + const char_t* pszFnd=strstr(pszStr, "%err"); if (pszFnd) { // find an error description for the error @@ -612,7 +616,7 @@ // replace %err with the new data pszOut[0]='\0'; - strncat(pszOut, pszStr, pszFnd-pszStr); + strncat(pszOut, pszStr, (size_t)(pszFnd-pszStr)); strcat(pszOut, szError); strcat(pszOut, pszFnd+4); Index: ext/libicpf/src/log.h =================================================================== diff -u -N -raea5c1302fae74ec41e9d7649f8b8b2b8138aee1 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/log.h (.../log.h) (revision aea5c1302fae74ec41e9d7649f8b8b2b8138aee1) +++ ext/libicpf/src/log.h (.../log.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -100,7 +100,7 @@ public: /** \name Construction/destruction */ /**@{*/ - log_file(bool bGlobal); ///< Standard constructor + explicit log_file(bool bGlobal=false); ///< Standard constructor ~log_file(); ///< Standard destructor /**@}*/ @@ -155,15 +155,15 @@ protected: /// Truncates a log file not to exceed the max file size - bool truncate(int_t iAdd); + bool truncate(int_t iAdd) const; /// Returns the size of a log file - int_t size(); + int_t size() const; private: /// Prepares a new format string for logerr(s) functions - bool prepare_fmt(const char_t* pszStr, int iSysErr, char_t* pszOut); + bool prepare_fmt(const char_t* pszStr, int iSysErr, char_t* pszOut) const; -public: +protected: char_t* m_pszPath; ///< Path to the log file int_t m_iMaxSize; ///< Maximum size of the log file bool m_bLogStd; ///< Log also to stdout/stderr Index: ext/libicpf/src/mutex.cpp =================================================================== diff -u -N -r30ed05249d32bbb24596169c77afa3c878299cb3 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision 30ed05249d32bbb24596169c77afa3c878299cb3) +++ ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -7,20 +7,25 @@ BEGIN_ICPF_NAMESPACE -#define m_pcsLock ((CRITICAL_SECTION*)m_pLock) -#define m_pmLock ((pthread_mutex_t*)m_pLock) +#ifdef _WIN32 + #define m_pcsLock ((CRITICAL_SECTION*)m_pLock) +#else + #define m_pmLock ((pthread_mutex_t*)m_pLock) +#endif /** Standard constructor. */ -mutex::mutex() +mutex::mutex() : + m_pLock(NULL) { construct(); } /** Compatibility layer constructor (with d_mutex). Can take a fake dumpctx pointer and a fake mutex name, * although does nothing with it. Effectively it is almost the same as standard constructor. */ -mutex::mutex(const char_t* /*pszStr*/) +mutex::mutex(const char_t* /*pszStr*/) : + m_pLock(NULL) { construct(); } Index: ext/libicpf/src/mutex.h =================================================================== diff -u -N -r30ed05249d32bbb24596169c77afa3c878299cb3 -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/mutex.h (.../mutex.h) (revision 30ed05249d32bbb24596169c77afa3c878299cb3) +++ ext/libicpf/src/mutex.h (.../mutex.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -51,7 +51,7 @@ mutex(); ///< Standard constructor // the constructor below will not be excluded without ENABLE_MUTEX_DEBUGGING, sice it would require // too much changes throughout the code that once was designed for debugging. - mutex(const char_t* /*pszStr*/); ///< Helper constructor, used as a compatibility layer with d_mutex + explicit mutex(const char_t* /*pszStr*/); ///< Helper constructor, used as a compatibility layer with d_mutex virtual ~mutex(); ///< Standard destructor /**@}*/ Index: ext/libicpf/src/sha256.h =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/sha256.h (.../sha256.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/sha256.h (.../sha256.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -19,8 +19,7 @@ uint32 total[2]; uint32 state[8]; uint8 buffer[64]; -} -sha256_context; +} sha256_context; void sha256_starts( sha256_context *ctx ); void sha256_update( sha256_context *ctx, uint8 *input, uint32 length ); Index: ext/libicpf/src/str.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/str.cpp (.../str.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/str.cpp (.../str.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -57,7 +57,13 @@ */ str_data::~str_data() { - free_buffer(); + try + { + free_buffer(); + } + catch(...) + { + } } /** Resets the object - frees buffer memory and sets internal members into the initial state. @@ -81,6 +87,8 @@ */ str_data* str_data::dup() { + assert(m_pszBuffer); + str_data* psd=new str_data(m_wFlags); psd->m_tBufSize=m_tBufSize; #ifdef ALLOW_UNICODE @@ -297,7 +305,8 @@ /** Standard constructor - allocates the underlying data object */ -string::string() +string::string() : + m_psd(NULL) { m_psd=new str_data(SDF_NONE); } @@ -306,7 +315,8 @@ * a given ansi string. * \param[in] pszStr - source ansi string */ -string::string(const char_t* pszStr) +string::string(const char_t* pszStr) : + m_psd(NULL) { m_psd=new str_data(SDF_NONE); set_str(pszStr); @@ -317,7 +327,8 @@ * a given unicode string. * \param[in] pszStr - source unicode string */ -string::string(const wchar_t* pszStr) +string::string(const wchar_t* pszStr) : + m_psd(NULL) { m_psd=new str_data(SDF_UNICODE); set_str(pszStr); @@ -328,17 +339,23 @@ * and copies only the data object address. * \param[in] str - source string object */ -string::string(const string& str) +string::string(const string& str) : + m_psd(str.m_psd) { - m_psd=str.m_psd; m_psd->inc_refcount(); } /** Destructor releases the underlying data object. */ string::~string() { - release_data(); + try + { + release_data(); + } + catch(...) + { + } } /** Operator releases the current data object, stores a pointer to @@ -349,9 +366,12 @@ */ const string& string::operator=(const string& src) { - release_data(); - m_psd=src.m_psd; - m_psd->inc_refcount(); + if (this != &src) + { + release_data(); + m_psd=src.m_psd; + m_psd->inc_refcount(); + } return *this; } @@ -472,6 +492,7 @@ */ size_t string::bytelen() const { + assert(m_psd); return m_psd->bytelen(); } @@ -617,6 +638,7 @@ */ string string::left(size_t tLen) const { + assert(m_psd); string str; size_t tStrLen=length(); tStrLen=minval(tStrLen, tLen); @@ -625,14 +647,14 @@ if (is_unicode()) { str.make_unicode(); - str.m_psd->resize_buffer_check(ROUNDUP(tStrLen+1, CHUNK_INCSIZE), false); + str.m_psd->resize_buffer_check(ROUNDUP((tStrLen+1), CHUNK_INCSIZE), false); wcsncpy((wchar_t*)str.m_psd->m_pszBuffer, (wchar_t*)m_psd->m_pszBuffer, tStrLen); ((wchar_t*)str.m_psd->m_pszBuffer)[tStrLen]=L'\0'; } else { #endif - str.m_psd->resize_buffer_check(ROUNDUP(tStrLen+1, CHUNK_INCSIZE), false); + str.m_psd->resize_buffer_check(ROUNDUP((tStrLen+1), CHUNK_INCSIZE), false); strncpy(str.m_psd->m_pszBuffer, m_psd->m_pszBuffer, tStrLen); str.m_psd->m_pszBuffer[tStrLen]='\0'; #ifdef ALLOW_UNICODE @@ -654,13 +676,13 @@ if (is_unicode()) { str.make_unicode(); - str.m_psd->resize_buffer_check(ROUNDUP(tStrLen+1, CHUNK_INCSIZE), false); + str.m_psd->resize_buffer_check(ROUNDUP((tStrLen+1), CHUNK_INCSIZE), false); wcsncpy((wchar_t*)str.m_psd->m_pszBuffer, ((wchar_t*)m_psd->m_pszBuffer)+tFullLen-tStrLen, tStrLen+1); } else { #endif - str.m_psd->resize_buffer_check(ROUNDUP(tStrLen+1, CHUNK_INCSIZE), false); + str.m_psd->resize_buffer_check(ROUNDUP((tStrLen+1), CHUNK_INCSIZE), false); strncpy(str.m_psd->m_pszBuffer, m_psd->m_pszBuffer+tFullLen-tStrLen, tStrLen+1); #ifdef ALLOW_UNICODE } @@ -849,6 +871,7 @@ */ int_t string::cmp(const string& str) const { + assert(m_psd); #ifdef ALLOW_UNICODE if (str.is_unicode()) { @@ -959,47 +982,47 @@ { #ifdef ALLOW_UNICODE if (str.is_unicode()) -{ - if (is_unicode()) { - // both strings unicode - return wcsicmp((wchar_t*)str.m_psd->m_pszBuffer, (wchar_t*)m_psd->m_pszBuffer); - } - else - { - // only the external string is unicode - char_t* pszConv=NULL; - int_t iRes=-1; - if (convert_to_ansi((wchar_t*)str.m_psd->m_pszBuffer, &pszConv) > 0) - iRes=stricmp(pszConv, m_psd->m_pszBuffer); + if (is_unicode()) + { + // both strings unicode + return wcsicmp((wchar_t*)str.m_psd->m_pszBuffer, (wchar_t*)m_psd->m_pszBuffer); + } + else + { + // only the external string is unicode + char_t* pszConv=NULL; + int_t iRes=-1; + if (convert_to_ansi((wchar_t*)str.m_psd->m_pszBuffer, &pszConv) > 0) + iRes=stricmp(pszConv, m_psd->m_pszBuffer); + + delete [] pszConv; - delete [] pszConv; - - return iRes; + return iRes; + } } -} else -{ - if (is_unicode()) { - // only internal string unicode - char_t* pszConv=NULL; - int_t iRes=-1; - if (convert_to_ansi((wchar_t*)m_psd->m_pszBuffer, &pszConv) > 0) - iRes=stricmp(pszConv, str.m_psd->m_pszBuffer); + if (is_unicode()) + { + // only internal string unicode + char_t* pszConv=NULL; + int_t iRes=-1; + if (convert_to_ansi((wchar_t*)m_psd->m_pszBuffer, &pszConv) > 0) + iRes=stricmp(pszConv, str.m_psd->m_pszBuffer); + + delete [] pszConv; - delete [] pszConv; - - return iRes; - } - else - { + return iRes; + } + else + { #endif - // both string ansi - return stricmp(str.m_psd->m_pszBuffer, m_psd->m_pszBuffer); + // both string ansi + return stricmp(str.m_psd->m_pszBuffer, m_psd->m_pszBuffer); #ifdef ALLOW_UNICODE + } } -} #endif } @@ -1335,15 +1358,15 @@ #ifdef ALLOW_UNICODE if (is_unicode()) { - if (tPos < tSize && tPos >=0) + if (tPos < tSize) return (int_t)(((wchar_t*)m_psd->m_pszBuffer)[tPos]); else return -1; } else { #endif - if (tPos < tSize && tPos >=0) + if (tPos < tSize) return (int_t)(((char_t*)m_psd->m_pszBuffer)[tPos]); else return -1; @@ -1401,7 +1424,7 @@ * job of this function is to make sure the string will terminate with null * character at the end of the buffer. */ -void string::release_buffer() +void string::release_buffer() const { // just to make sure user does not crash everything #ifdef ALLOW_UNICODE @@ -1418,6 +1441,7 @@ */ void string::make_unicode() { + assert(m_psd); if (!is_unicode()) { // make a string conversion @@ -1482,10 +1506,10 @@ pctx->close(); } -/** Displays the string contents on screen using standard printf() function. The format of displayed +/** Displays the string contents on screen using standard printf function. The format of displayed * string is either ansi("string_content") or unicode("string_content"). */ -void string::print() +void string::print() const { #ifdef ALLOW_UNICODE if (is_unicode()) @@ -1527,6 +1551,7 @@ */ string::operator const wchar_t*() const { + assert(m_psd); if (m_psd->m_pszBuffer) { if (m_psd->m_wFlags & SDF_UNICODE) @@ -1556,10 +1581,10 @@ #ifdef _WIN32 size_t tLen; - if ( (tLen=WideCharToMultiByte(CP_ACP, 0, pszIn, -1, NULL, 0, NULL, NULL)) != 0 ) + if ( (tLen=(size_t)WideCharToMultiByte(CP_ACP, 0, pszIn, -1, NULL, 0, NULL, NULL)) != 0 ) { *pszOut=new char_t[tLen]; - return WideCharToMultiByte(CP_ACP, 0, pszIn, -1, *pszOut, (int_t)tLen, NULL, NULL); + return (size_t)WideCharToMultiByte(CP_ACP, 0, pszIn, -1, *pszOut, (int_t)tLen, NULL, NULL); } else { @@ -1612,10 +1637,10 @@ #ifdef _WIN32 size_t tLen; - if ( (tLen=MultiByteToWideChar(CP_ACP, 0, pszIn, -1, NULL, 0)) != 0 ) + if ( (tLen=(size_t)MultiByteToWideChar(CP_ACP, 0, pszIn, -1, NULL, 0)) != 0 ) { *pszOut=new wchar_t[tLen]; - return MultiByteToWideChar(CP_ACP, 0, pszIn, -1, *pszOut, (int_t)tLen); + return (size_t)MultiByteToWideChar(CP_ACP, 0, pszIn, -1, *pszOut, (int_t)tLen); } else { @@ -1695,7 +1720,7 @@ size_t tLen=wcslen(pszStr)+1; // new str length m_psd->resize_buffer_check(ROUNDUP(tLen, CHUNK_INCSIZE), false); - wcscpy((wchar_t*)m_psd->m_pszBuffer, (wchar_t*)pszStr); + wcscpy((wchar_t*)m_psd->m_pszBuffer, pszStr); } #endif @@ -1739,9 +1764,11 @@ psd->resize_buffer_check(ROUNDUP((size_t)pParam, CHUNK_INCSIZE), false); release_data(); m_psd=psd; + break; } default: assert(false); // some strange flag + break; } } else @@ -1781,6 +1808,7 @@ */ void string::release_data() { + assert(m_psd); if (m_psd->dec_refcount()) delete m_psd; m_psd=NULL; Index: ext/libicpf/src/str.h =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/str.h (.../str.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/str.h (.../str.h) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -75,7 +75,7 @@ public: /** \name Construction/destruction */ /*@{*/ - str_data(short_t wFlags); + explicit str_data(short_t wFlags); ~str_data(); /*@}*/ @@ -117,11 +117,13 @@ /*@}*/ -public: +protected: char_t* m_pszBuffer; ///< Contents of the string (could be the wchar_t*) size_t m_tBufSize; ///< Size of the buffer (in chars, *NOT* bytes) short_t m_wRefCount; ///< Reference count short_t m_wFlags; ///< Flags + + friend class string; }; /////////////////////////////////////////////////////////////// @@ -138,9 +140,9 @@ /** \name Construction/destruction */ /*@{*/ string(); ///< Standard constructor - string(const char_t* pszStr); ///< Constructor that takes const char_t* as an initial string + explicit string(const char_t* pszStr); ///< Constructor that takes const char_t* as an initial string #ifdef ALLOW_UNICODE - string(const wchar_t* pszStr); ///< Constructor that takes const wchar_t* as an initial string + explicit string(const wchar_t* pszStr); ///< Constructor that takes const wchar_t* as an initial string #endif string(const string& str); ///< Standard copy constructor @@ -248,7 +250,7 @@ int_t at(size_t tPos) const; ///< Gets a character at a specified position char_t* get_buffera(size_t tMinSize); ///< Gives user access to the ansi internal buffer wchar_t* get_bufferu(size_t tMinSize); ///< Gives user access to the unicode internal buffer - void release_buffer(); ///< Releases the buffer get from get_bufferx functions + void release_buffer() const; ///< Releases the buffer get from get_bufferx functions size_t length() const; ///< Returns the length of this string in chars size_t bytelen() const; ///< Returns the length of a string in bytes (with terminating null character) @@ -272,7 +274,7 @@ /** \name Debug stuff */ /**@{*/ void dump(dumpctx* pctx); ///< Dumps the contents of this class to the dump context - void print(); ///< Prints the contents of this class + void print() const; ///< Prints the contents of this class /**@}*/ protected: @@ -292,7 +294,7 @@ // checks the refcount and frees the data (refcount <=0) or leaves untouched (refcount >0) void release_data(); ///< Releases an underlying data object from this string (if refcount <= 0 then data object is deleted) -public: +protected: str_data *m_psd; ///< Pointer to an underlying data object (str_data) }; Index: ext/libicpf/src/str_help.cpp =================================================================== diff -u -N -re17c80d36eaa0430313e7d1058aa7a301d1510af -r338a33bbdb8c82416f0351408eea3243520784e5 --- ext/libicpf/src/str_help.cpp (.../str_help.cpp) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/str_help.cpp (.../str_help.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) @@ -30,7 +30,7 @@ */ LIBICPF_API bool is_whitespace(char_t ch) { - return (ch >= 0x09 && ch <= 0x0d) || ch == 0x20; + return ((ch >= 0x09) && (ch <= 0x0d)) || (ch == 0x20); } END_ICPF_NAMESPACE