diff options
author | George Hazan <george.hazan@gmail.com> | 2013-12-26 12:38:05 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-12-26 12:38:05 +0000 |
commit | 7969931ecab74a0d251de7613a8427f2a9a5c86c (patch) | |
tree | dbf064e60b0720b299ae92b34285d018bd8b21b4 /plugins/UserInfoEx/src/mir_db.cpp | |
parent | 5eda5b13296dd4e56717948d0aecc5e0f8a0d84e (diff) |
various code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@7382 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/UserInfoEx/src/mir_db.cpp')
-rw-r--r-- | plugins/UserInfoEx/src/mir_db.cpp | 881 |
1 files changed, 415 insertions, 466 deletions
diff --git a/plugins/UserInfoEx/src/mir_db.cpp b/plugins/UserInfoEx/src/mir_db.cpp index fcd347e373..9b8a8a2798 100644 --- a/plugins/UserInfoEx/src/mir_db.cpp +++ b/plugins/UserInfoEx/src/mir_db.cpp @@ -25,31 +25,19 @@ namespace DB { namespace MetaContact {
-/**
- *
- *
- **/
-INT_PTR SubCount(HANDLE hMetaContact)
+INT_PTR SubCount(HANDLE hMetaContact)
{
INT_PTR result = CallService(MS_MC_GETNUMCONTACTS, (WPARAM) hMetaContact, 0);
return (result == CALLSERVICE_NOTFOUND) ? -1 : result;
}
-/**
- *
- *
- **/
-INT_PTR SubDefNum(HANDLE hMetaContact)
+INT_PTR SubDefNum(HANDLE hMetaContact)
{
INT_PTR result = CallService(MS_MC_GETDEFAULTCONTACTNUM, (WPARAM) hMetaContact, 0);
return (result == CALLSERVICE_NOTFOUND) ? -1 : result;
}
-/**
- *
- *
- **/
-HANDLE Sub(HANDLE hMetaContact, int idx)
+HANDLE Sub(HANDLE hMetaContact, int idx)
{
if (idx != -1) {
INT_PTR result = CallService(MS_MC_GETSUBCONTACT, (WPARAM) hMetaContact, (LPARAM) idx);
@@ -58,34 +46,20 @@ HANDLE Sub(HANDLE hMetaContact, int idx) return NULL;
}
-/**
- *
- *
- **/
-BYTE IsSub(HANDLE hContact)
+bool IsSub(HANDLE hContact)
{
return myGlobals.szMetaProto &&
db_get_b(NULL, myGlobals.szMetaProto, "Enabled", TRUE) &&
db_get_b(hContact, myGlobals.szMetaProto, "IsSubcontact", FALSE);
}
-/**
- *
- *
- **/
-HANDLE GetMeta(HANDLE hContact)
+HANDLE GetMeta(HANDLE hContact)
{
- HANDLE result;
- if (myGlobals.szMetaProto){
- result = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0);
- if (result == (HANDLE)CALLSERVICE_NOTFOUND) {
- result = NULL;
- }
- }
- else {
- result = NULL;
- }
- return (HANDLE) result;
+ if (!myGlobals.szMetaProto)
+ return NULL;
+
+ HANDLE result = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0);
+ return (result == (HANDLE)CALLSERVICE_NOTFOUND) ? NULL : result;
}
} /* namespace MetaContact */
@@ -93,23 +67,26 @@ HANDLE GetMeta(HANDLE hContact) /**
* This namespace contains all functions used to access or modify contacts in the database.
**/
+
namespace Contact {
/**
- * This function retrieves the display name for a contact.
- * @param hContact - handle to the contact
- * @return Returns the display name of a contact.
- **/
-LPTSTR DisplayName(HANDLE hContact)
+* This function retrieves the display name for a contact.
+* @param hContact - handle to the contact
+* @return Returns the display name of a contact.
+**/
+
+LPTSTR DisplayName(HANDLE hContact)
{
- return (LPTSTR) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR);
+ return pcli->pfnGetContactDisplayName(hContact, 0);
}
/**
- * This function is used to retrieve a contact's basic protocol
- * @param hContact - handle to the contact
- * @return This function returns the basic protocol of a contact.
- **/
+* This function is used to retrieve a contact's basic protocol
+* @param hContact - handle to the contact
+* @return This function returns the basic protocol of a contact.
+**/
+
LPSTR Proto(HANDLE hContact)
{
if (hContact) {
@@ -126,7 +103,7 @@ LPSTR Proto(HANDLE hContact) * @return Returns the number of contacts. They can be retrieved using
* contact/findfirst and contact/findnext
**/
-INT_PTR GetCount()
+INT_PTR GetCount()
{
return CallService(MS_DB_CONTACT_GETCOUNT, 0, 0);
}
@@ -135,7 +112,7 @@ INT_PTR GetCount() * Simply adds a new contact without setting up any protocol or something else
* @return HANDLE The function returns the HANDLE of the new contact
**/
-HANDLE Add()
+HANDLE Add()
{
return (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0);
}
@@ -144,7 +121,7 @@ HANDLE Add() * This function deletes a contact from the database.
* @param hContact - handle to the contact
**/
-BYTE Delete(HANDLE hContact)
+BYTE Delete(HANDLE hContact)
{
return CallService(MS_DB_CONTACT_DELETE, (WPARAM) hContact, 0) != 0;
}
@@ -154,22 +131,17 @@ BYTE Delete(HANDLE hContact) **/
DWORD WhenAdded(DWORD dwUIN, LPCSTR pszProto)
{
- DBEVENTINFO dbei;
- HANDLE edbe;
- DWORD dwEvtUIN;
-
- ZeroMemory(&dbei, sizeof(dbei));
- dbei.cbSize = sizeof(dbei);
- for (edbe = db_event_first(NULL); edbe != NULL; edbe = db_event_next(edbe)) {
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ for (HANDLE edbe = db_event_first(NULL); edbe != NULL; edbe = db_event_next(edbe)) {
// get eventtype and compare
if (!DB::Event::GetInfo(edbe, &dbei) && dbei.eventType == EVENTTYPE_ADDED) {
if (!DB::Event::GetInfoWithData(edbe, &dbei)) {
// extract UIN and compare with given one
+ DWORD dwEvtUIN;
CopyMemory(&dwEvtUIN, dbei.pBlob, sizeof(DWORD));
MIR_FREE(dbei.pBlob);
- if (dwEvtUIN == dwUIN) {
+ if (dwEvtUIN == dwUIN)
return dbei.timestamp;
- }
}
}
}
@@ -181,54 +153,56 @@ DWORD WhenAdded(DWORD dwUIN, LPCSTR pszProto) namespace Module {
/**
- * Deletes all settings in the module.
- * @param hContact - handle to the contact
- * @param pszModule - the module to delete the setting from (e.g. USERINFO)
- * return: nothing
- **/
+* Deletes all settings in the module.
+* @param hContact - handle to the contact
+* @param pszModule - the module to delete the setting from (e.g. USERINFO)
+* return: nothing
+**/
+
void Delete(HANDLE hContact, LPCSTR pszModule)
{
- CEnumList Settings;
+ CEnumList Settings;
if (!Settings.EnumSettings(hContact, pszModule))
for (int i = 0; i < Settings.getCount(); i++)
db_unset(hContact, pszModule, Settings[i]);
}
/**
- * Enum Proc for DBModule_IsEmpty
- * @param pszSetting - the setting
- * @param lParam - DBCONTACTENUMSETTINGS - (LPARAM)&dbces
- * @retval TRUE - always true
- **/
-static int IsEmptyEnumProc(LPCSTR pszSetting, LPARAM lParam)
+* Enum Proc for DBModule_IsEmpty
+* @param pszSetting - the setting
+* @param lParam - DBCONTACTENUMSETTINGS - (LPARAM)&dbces
+* @retval TRUE - always true
+**/
+
+static int IsEmptyEnumProc(LPCSTR pszSetting, LPARAM lParam)
{
return 1;
}
/**
- * This function tests, whether a module is empty for the given contact or not
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @retval TRUE - the module is empty
- * @retval FALSE - the module contains settings
- **/
-BYTE IsEmpty(HANDLE hContact, LPCSTR pszModule)
+* This function tests, whether a module is empty for the given contact or not
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @retval TRUE - the module is empty
+* @retval FALSE - the module contains settings
+**/
+
+bool IsEmpty(HANDLE hContact, LPCSTR pszModule)
{
- DBCONTACTENUMSETTINGS dbces;
- dbces.pfnEnumProc = IsEmptyEnumProc;
- dbces.szModule = pszModule;
- dbces.ofsSettings = 0;
- dbces.lParam = 0;
+ DBCONTACTENUMSETTINGS dbces = { 0 };
+ dbces.pfnEnumProc = IsEmptyEnumProc;
+ dbces.szModule = pszModule;
return (0 > CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces));
}
/**
- * This function tests, whether a module belongs to a metacontact protocol
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @retval TRUE - the module belongs to a metacontact protocol
- * @retval FALSE - the module belongs to a other protocol
- **/
-BYTE IsMeta(LPCSTR pszModule)
+* This function tests, whether a module belongs to a metacontact protocol
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @retval TRUE - the module belongs to a metacontact protocol
+* @retval FALSE - the module belongs to a other protocol
+**/
+
+bool IsMeta(LPCSTR pszModule)
{
if (myGlobals.szMetaProto)
return !mir_strcmp(pszModule, myGlobals.szMetaProto);
@@ -236,14 +210,15 @@ BYTE IsMeta(LPCSTR pszModule) }
/**
- * This function tests, whether a module is a meta contact, and user wants to scan it for settings
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @retval TRUE - the module is empty
- * @retval FALSE - the module contains settings
- **/
-BYTE IsMetaAndScan(LPCSTR pszModule)
+* This function tests, whether a module is a meta contact, and user wants to scan it for settings
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @retval TRUE - the module is empty
+* @retval FALSE - the module contains settings
+**/
+
+bool IsMetaAndScan(LPCSTR pszModule)
{
- return db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE) && IsMeta(pszModule);
+ return 0 != db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE) && IsMeta(pszModule);
}
} /* namespace Module */
@@ -251,83 +226,85 @@ BYTE IsMetaAndScan(LPCSTR pszModule) namespace Setting {
/**
- * This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to read
- * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
-BYTE Get(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
+* This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSetting - the setting to read
+* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
+*
+* @retval 0 - success
+* @retval 1 - error
+**/
+
+BYTE Get(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
{
// read value without translation to specific type
BYTE result = db_get_s(hContact, pszModule, pszSetting, dbv, 0) != 0;
// Is value read successfully and destination type set?
- if (!result && destType) {
+ if (!result && destType)
result = DB::Variant::ConvertString(dbv, destType);
- }
return result;
}
/**
- * This function reads a value from the database and returns it as an ansi encoded string.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to read
- *
- * @return string value
- **/
+* This function reads a value from the database and returns it as an ansi encoded string.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSetting - the setting to read
+*
+* @return string value
+**/
+
LPSTR GetAString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting)
{
DBVARIANT dbv;
if (GetAString(hContact, pszModule, pszSetting, &dbv) == 0){
- if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) {
+ if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0)
return dbv.pszVal;
- }
+
db_free(&dbv);
}
return NULL;
}
/**
- * This function reads a value from the database and returns it as an unicode encoded string.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to read
- *
- * @return string value
- **/
-LPWSTR GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting)
+* This function reads a value from the database and returns it as an unicode encoded string.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSetting - the setting to read
+*
+* @return string value
+**/
+
+LPWSTR GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting)
{
DBVARIANT dbv;
if (GetWString(hContact, pszModule, pszSetting, &dbv) == 0) {
- if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) {
+ if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0)
return dbv.pwszVal;
- }
+
db_free(&dbv);
}
return NULL;
}
/**
- * This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values.
- * It searches in pszModule first and if the setting does not exist there it tries proto to retrieve it.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param szProto - the contact's protocol to read the setting from (e.g. ICQ)
- * @param szSetting - the setting to read
- * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
-BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
+* This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values.
+* It searches in pszModule first and if the setting does not exist there it tries proto to retrieve it.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param szProto - the contact's protocol to read the setting from (e.g. ICQ)
+* @param szSetting - the setting to read
+* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
+*
+* @retval 0 - success
+* @retval 1 - error
+**/
+
+BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
{
- BYTE result;
- result = !pszModule || Get(hContact, pszModule, pszSetting, dbv, destType);
+ BYTE result = !pszModule || Get(hContact, pszModule, pszSetting, dbv, destType);
// try to read setting from the contact's protocol module
if (result && pszProto) {
result = Get(hContact, pszProto, pszSetting, dbv, destType) != 0;
@@ -350,42 +327,43 @@ BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting for (i = 0; result && i < cnt; i++) {
if (i != def) {
hSubContact = DB::MetaContact::Sub(hContact, i);
- if (hSubContact != NULL) {
+ if (hSubContact != NULL)
result = DB::Setting::GetEx(hSubContact, pszModule, DB::Contact::Proto(hSubContact), pszSetting, dbv, destType) != 0;
- } } } } } } }
+ } } } } } }
+
return result;
}
/**
- * This function is used by the controls of the details dialog and calls MS_DB_CONTACT_GETSETTING_STR service
- * to get database values. It searches in pszModule first and if the setting does not exist there it tries proto
- * to retrieve it.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSubModule - the module to read the setting from a meta subcontract (e.g. USERINFO)
- * @param pszProto - the contact's protocol to read the setting from (e.g. ICQ)
- * @param pszSetting - the setting to read
- * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
- *
- * @return This function returns the WORD which contains the source of information.
- **/
-WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
+* This function is used by the controls of the details dialog and calls MS_DB_CONTACT_GETSETTING_STR service
+* to get database values. It searches in pszModule first and if the setting does not exist there it tries proto
+* to retrieve it.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSubModule - the module to read the setting from a meta subcontract (e.g. USERINFO)
+* @param pszProto - the contact's protocol to read the setting from (e.g. ICQ)
+* @param pszSetting - the setting to read
+* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8)
+*
+* @return This function returns the WORD which contains the source of information.
+**/
+
+WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType)
{
WORD wFlags = 0;
// read setting from given module
if (hContact && pszModule && *pszModule && !Get(hContact, pszModule, pszSetting, dbv, destType)) {
wFlags |= CTRLF_HASCUSTOM;
- if (Exists(hContact, pszProto, pszSetting)) {
+ if (Exists(hContact, pszProto, pszSetting))
wFlags |= CTRLF_HASPROTO;
- }
}
// read setting from contact's basic protocol
else if (pszProto && *pszProto) {
// try to read the setting from the basic protocol
- if (!Get(hContact, pszProto, pszSetting, dbv, destType)) {
+ if (!Get(hContact, pszProto, pszSetting, dbv, destType))
wFlags |= CTRLF_HASPROTO;
- }
+
// try to read the setting from the sub contacts' modules
else if (DB::Module::IsMetaAndScan(pszProto)) {
const INT_PTR def = DB::MetaContact::SubDefNum(hContact);
@@ -415,39 +393,41 @@ WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszP wFlags |= CTRLF_HASMETA;
break;
} } } } } } }
- if (wFlags == 0) {
+
+ if (wFlags == 0)
dbv->type = DBVT_DELETED;
- }
+
return wFlags;
}
/**
- * This function reads a setting from database into a predefined portion of memory
- * and convert numbers into a string, too.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to read
- * @param pszValue - buffer, that retrieves the value
- * @param cchValue - number of characters the buffer can take
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
-BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszValue, int cchValue)
+* This function reads a setting from database into a predefined portion of memory
+* and convert numbers into a string, too.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSetting - the setting to read
+* @param pszValue - buffer, that retrieves the value
+* @param cchValue - number of characters the buffer can take
+*
+* @retval 0 - success
+* @retval 1 - error
+**/
+
+BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszValue, int cchValue)
{
DBVARIANT dbv;
DBCONTACTGETSETTING sVal;
if (pszValue && cchValue) {
- pszValue[0] = 0;
- dbv.pszVal = pszValue;
- dbv.cchVal = cchValue;
- dbv.type = DBVT_ASCIIZ;
-
- sVal.pValue = &dbv;
- sVal.szModule = pszModule;
- sVal.szSetting = pszSetting;
-
+ pszValue[0] = 0;
+ dbv.pszVal = pszValue;
+ dbv.cchVal = cchValue;
+ dbv.type = DBVT_ASCIIZ;
+
+ sVal.pValue = &dbv;
+ sVal.szModule = pszModule;
+ sVal.szSetting = pszSetting;
+
if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal)) {
switch (dbv.type) {
case DBVT_BYTE:
@@ -466,50 +446,51 @@ BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszVa }
/**
- * This function checks for the existence of the given setting in the database
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszSetting - the setting to check
- *
- * @retval TRUE - setting exists
- * @retval FALSE - setting does not exist
- **/
-BYTE Exists(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting)
+* This function checks for the existence of the given setting in the database
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszSetting - the setting to check
+*
+* @retval TRUE - setting exists
+* @retval FALSE - setting does not exist
+**/
+
+BYTE Exists(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting)
{
if (pszModule && pszSetting) {
- DBCONTACTGETSETTING cgs;
- DBVARIANT dbv;
CHAR szDummy[1];
+ DBVARIANT dbv;
+ dbv.pszVal = szDummy;
+ dbv.cchVal = sizeof(szDummy);
+ dbv.type = 0;
- dbv.pszVal = szDummy;
- dbv.cchVal = sizeof(szDummy);
- dbv.type = 0;
- cgs.pValue = &dbv;
- cgs.szModule = pszModule;
- cgs.szSetting = pszSetting;
- if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM) hContact, (LPARAM) &cgs)) {
+ DBCONTACTGETSETTING cgs;
+ cgs.pValue = &dbv;
+ cgs.szModule = pszModule;
+ cgs.szSetting = pszSetting;
+ if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM) hContact, (LPARAM) &cgs))
return (dbv.type > DBVT_DELETED);
- }
}
return FALSE;
}
/**
- * This function deletes all reluctant settings of an setting array such as My-phoneXX.
- * @param hContact - handle to the contact
- * @param pszModule - the module to read the setting from (e.g. USERINFO)
- * @param pszFormat - the format, telling what a array of settings is ment
- * @param iStart - the first index of the setting to delete
- *
- * @return nothing
- **/
-void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart)
+* This function deletes all reluctant settings of an setting array such as My-phoneXX.
+* @param hContact - handle to the contact
+* @param pszModule - the module to read the setting from (e.g. USERINFO)
+* @param pszFormat - the format, telling what a array of settings is ment
+* @param iStart - the first index of the setting to delete
+*
+* @return nothing
+**/
+
+void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart)
{
CHAR pszSetting[MAXSETTING];
do {
mir_snprintf(pszSetting, MAXSETTING, pszFormat, iStart++);
}
- while (!db_unset(hContact, pszModule, pszSetting));
+ while (!db_unset(hContact, pszModule, pszSetting));
}
} /* namespace Setting */
@@ -517,177 +498,155 @@ void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart namespace Variant {
/**
- * This function converts a string value of the DBVARIANT to the destination type
- * but keeps all other values as is.
- * @param dbv - pointer to DBVARIANT structure which is to manipulate
- * @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR)
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
-BYTE ConvertString(DBVARIANT* dbv, const BYTE destType)
+* This function converts a string value of the DBVARIANT to the destination type
+* but keeps all other values as is.
+* @param dbv - pointer to DBVARIANT structure which is to manipulate
+* @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR)
+*
+* @retval 0 - success
+* @retval 1 - error
+**/
+
+BYTE ConvertString(DBVARIANT* dbv, const BYTE destType)
{
- if (dbv) {
- switch (dbv->type) {
- // source value is of type "ascii"
- case DBVT_ASCIIZ:
- {
- switch (destType) {
- // destination type is "utf8"
- case DBVT_UTF8:
- {
- LPSTR tmpBuf = mir_utf8encode(dbv->pszVal);
- mir_free(dbv->pszVal);
- dbv->pszVal = tmpBuf;
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // destination type is "wchar"
- case DBVT_WCHAR:
- {
- LPWSTR tmpBuf = mir_a2u(dbv->pszVal);
- mir_free(dbv->pszVal);
- dbv->pwszVal = tmpBuf;
- dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
- }
- }
- } break;
- // source value is of type "utf8"
+ if (dbv == NULL)
+ return 1;
+
+ LPSTR tmpBuf;
+ switch (dbv->type) {
+ // source value is of type "ascii"
+ case DBVT_ASCIIZ:
+ switch (destType) {
+ // destination type is "utf8"
case DBVT_UTF8:
- {
- switch (destType) {
- // destination type is "ascii"
- case DBVT_ASCIIZ:
- {
- mir_utf8decode(dbv->pszVal, NULL);
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // destination type is "wchar"
- case DBVT_WCHAR:
- {
- LPSTR savePtr = dbv->pszVal;
- dbv->pszVal = NULL;
- mir_utf8decode(savePtr, &dbv->pwszVal);
- mir_free(savePtr);
- dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
- }
- }
- } break;
- // source value is of type "wchar"
+ tmpBuf = mir_utf8encode(dbv->pszVal);
+ mir_free(dbv->pszVal);
+ dbv->pszVal = tmpBuf;
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // destination type is "wchar"
case DBVT_WCHAR:
- {
- switch (destType) {
- // destination type is "ascii"
- case DBVT_ASCIIZ:
- {
- LPSTR tmpBuf = mir_u2a(dbv->pwszVal);
- mir_free(dbv->pwszVal);
- dbv->pszVal = tmpBuf;
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // destination type is "utf8"
- case DBVT_UTF8:
- {
- LPSTR tmpBuf = mir_utf8encodeW(dbv->pwszVal);
- mir_free(dbv->pwszVal);
- dbv->pszVal = tmpBuf;
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- }
- }
- }
+ LPWSTR tmpBuf = mir_a2u(dbv->pszVal);
+ mir_free(dbv->pszVal);
+ dbv->pwszVal = tmpBuf;
+ dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
+ }
+ break;
+ // source value is of type "utf8"
+ case DBVT_UTF8:
+ switch (destType) {
+ // destination type is "ascii"
+ case DBVT_ASCIIZ:
+ mir_utf8decode(dbv->pszVal, NULL);
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // destination type is "wchar"
+ case DBVT_WCHAR:
+ LPSTR savePtr = dbv->pszVal;
+ dbv->pszVal = NULL;
+ mir_utf8decode(savePtr, &dbv->pwszVal);
+ mir_free(savePtr);
+ dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
+ }
+ break;
+ // source value is of type "wchar"
+ case DBVT_WCHAR:
+ switch (destType) {
+ // destination type is "ascii"
+ case DBVT_ASCIIZ:
+ tmpBuf = mir_u2a(dbv->pwszVal);
+ mir_free(dbv->pwszVal);
+ dbv->pszVal = tmpBuf;
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // destination type is "utf8"
+ case DBVT_UTF8:
+ tmpBuf = mir_utf8encodeW(dbv->pwszVal);
+ mir_free(dbv->pwszVal);
+ dbv->pszVal = tmpBuf;
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
}
- return dbv->type == DBVT_DELETED;
}
- return 1;
+ return dbv->type == DBVT_DELETED;
}
/**
- * This function completely converts a DBVARIANT to the destination string type.
- * It includes BYTE, WORD, DWORD and all string types
- * @param dbv - pointer to DBVARIANT structure which is to manipulate
- * @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR)
- *
- * @retval 0 - success
- * @retval 1 - error
- **/
+* This function completely converts a DBVARIANT to the destination string type.
+* It includes BYTE, WORD, DWORD and all string types
+* @param dbv - pointer to DBVARIANT structure which is to manipulate
+* @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR)
+*
+* @retval 0 - success
+* @retval 1 - error
+**/
+
BYTE dbv2String(DBVARIANT* dbv, const BYTE destType)
{
- if (dbv) {
- switch (destType) {
- // destination type is "utf8" or "ascii"
+ if (dbv == NULL)
+ return 1;
+
+ switch (destType) {
+ CHAR buf[32];
+ // destination type is "utf8" or "ascii"
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ switch (dbv->type) {
+ // source value is of type "byte"
+ case DBVT_BYTE:
+ _ultoa(dbv->bVal, buf, 10);
+ dbv->pszVal = mir_strdup(buf);
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of type "word"
+ case DBVT_WORD:
+ _ultoa(dbv->wVal, buf, 10);
+ dbv->pszVal = mir_strdup(buf);
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of type "dword"
+ case DBVT_DWORD:
+ _ultoa(dbv->dVal, buf, 10);
+ dbv->pszVal = mir_strdup(buf);
+ dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of any string type
case DBVT_ASCIIZ:
+ case DBVT_WCHAR:
case DBVT_UTF8:
- {
- CHAR buf[32];
- switch (dbv->type) {
- // source value is of type "byte"
- case DBVT_BYTE:
- {
- _ultoa(dbv->bVal, buf, 10);
- dbv->pszVal = mir_strdup(buf);
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of type "word"
- case DBVT_WORD:
- {
- _ultoa(dbv->wVal, buf, 10);
- dbv->pszVal = mir_strdup(buf);
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of type "dword"
- case DBVT_DWORD:
- {
- _ultoa(dbv->dVal, buf, 10);
- dbv->pszVal = mir_strdup(buf);
- dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of any string type
- case DBVT_ASCIIZ:
- case DBVT_WCHAR:
- case DBVT_UTF8:
- {
- return ConvertString(dbv, destType);
- }
- }
- } break;
- // destination type is "wchar"
+ return ConvertString(dbv, destType);
+ }
+ break;
+
+ // destination type is "wchar"
+ case DBVT_WCHAR:
+ switch (dbv->type) {
+ WCHAR buf[32];
+ // source value is of type "byte"
+ case DBVT_BYTE:
+ _ultow(dbv->bVal, buf, 10);
+ dbv->pwszVal = mir_wcsdup(buf);
+ dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of type "word"
+ case DBVT_WORD:
+ _ultow(dbv->wVal, buf, 10);
+ dbv->pwszVal = mir_wcsdup(buf);
+ dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of type "dword"
+ case DBVT_DWORD:
+ _ultow(dbv->dVal, buf, 10);
+ dbv->pwszVal = mir_wcsdup(buf);
+ dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
+ break;
+ // source value is of any string type
+ case DBVT_ASCIIZ:
case DBVT_WCHAR:
- {
- WCHAR buf[32];
- switch (dbv->type) {
- // source value is of type "byte"
- case DBVT_BYTE:
- {
- _ultow(dbv->bVal, buf, 10);
- dbv->pwszVal = mir_wcsdup(buf);
- dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of type "word"
- case DBVT_WORD:
- {
- _ultow(dbv->wVal, buf, 10);
- dbv->pwszVal = mir_wcsdup(buf);
- dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of type "dword"
- case DBVT_DWORD:
- {
- _ultow(dbv->dVal, buf, 10);
- dbv->pwszVal = mir_wcsdup(buf);
- dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED;
- } break;
- // source value is of any string type
- case DBVT_ASCIIZ:
- case DBVT_WCHAR:
- case DBVT_UTF8:
- {
- return ConvertString(dbv, destType);
- }
- }
- }
+ case DBVT_UTF8:
+ return ConvertString(dbv, destType);
}
- return dbv->type != destType;
}
- return 1;
+ return dbv->type != destType;
}
} /* namespace Variant */
@@ -695,15 +654,16 @@ BYTE dbv2String(DBVARIANT* dbv, const BYTE destType) namespace Event {
/**
- * This function initializes the DBEVENTINFO structure and calls
- * db_event_get() to retrieve information about an event.
- * @param hEvent - the handle of the event to get information for
- * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information.
- *
- * @retval 0 - success
- * @retval nonezero - failure
- **/
-BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei)
+* This function initializes the DBEVENTINFO structure and calls
+* db_event_get() to retrieve information about an event.
+* @param hEvent - the handle of the event to get information for
+* @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information.
+*
+* @retval 0 - success
+* @retval nonezero - failure
+**/
+
+bool GetInfo(HANDLE hEvent, DBEVENTINFO *dbei)
{
dbei->cbSize = sizeof(DBEVENTINFO);
dbei->cbBlob = 0;
@@ -712,15 +672,16 @@ BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) }
/**
- * This function initializes the DBEVENTINFO structure and calls
- * db_event_get() to retrieve information about an event.
- * @param hEvent - the handle of the event to get information for
- * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information.
- *
- * @retval 0 - success
- * @retval 1 - failure
- **/
-BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei)
+* This function initializes the DBEVENTINFO structure and calls
+* db_event_get() to retrieve information about an event.
+* @param hEvent - the handle of the event to get information for
+* @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information.
+*
+* @retval 0 - success
+* @retval 1 - failure
+**/
+
+bool GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei)
{
dbei->cbSize = sizeof(DBEVENTINFO);
if (!dbei->cbBlob) {
@@ -729,13 +690,12 @@ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) }
if (dbei->cbBlob) {
dbei->pBlob = (PBYTE) mir_alloc(dbei->cbBlob);
- if (dbei->pBlob == NULL) {
+ if (dbei->pBlob == NULL)
dbei->cbBlob = 0;
- }
}
else dbei->pBlob = NULL;
- BYTE result = db_event_get(hEvent, dbei) != 0;
+ bool result = db_event_get(hEvent, dbei) != 0;
if (result && dbei->pBlob) {
mir_free(dbei->pBlob);
dbei->pBlob = NULL;
@@ -744,86 +704,83 @@ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) }
/**
- * This function returns the timestamp for the given event.
- * @param hEvent - the handle of the event to get the timestamp for
- *
- * @retval 0 if no timestamp is available
- * @retval timestamp
- **/
+* This function returns the timestamp for the given event.
+* @param hEvent - the handle of the event to get the timestamp for
+*
+* @retval 0 if no timestamp is available
+* @retval timestamp
+**/
+
DWORD TimeOf(HANDLE hEvent)
{
DBEVENTINFO dbei;
- if (!GetInfo(hEvent, &dbei)) {
+ if (!GetInfo(hEvent, &dbei))
return dbei.timestamp;
- }
+
return 0;
}
/**
- * This function compares two DBEVENTINFO structures against each other.
- * It compares the timestamp, eventType and module names.
- * @param d1 - pointer to the first DBEVENTINFO structure
- * @param d2 - pointer to the second DBEVENTINFO structure
- * @param Data - default false, if true compare also blob data
+* This function compares two DBEVENTINFO structures against each other.
+* It compares the timestamp, eventType and module names.
+* @param d1 - pointer to the first DBEVENTINFO structure
+* @param d2 - pointer to the second DBEVENTINFO structure
+* @param Data - default false, if true compare also blob data
.*
- * @retval TRUE - The structures describe the same event.
- * @retval FALSE - The two structure's events differ from each other.
- **/
-static FORCEINLINE
-BYTE IsEqual(const DBEVENTINFO *d1, const DBEVENTINFO *d2, bool Data)
+* @retval TRUE - The structures describe the same event.
+* @retval FALSE - The two structure's events differ from each other.
+**/
+
+static FORCEINLINE bool IsEqual(const DBEVENTINFO *d1, const DBEVENTINFO *d2, bool Data)
{
- BYTE res = d1 && d2 &&
+ bool res = d1 && d2 &&
(d1->timestamp == d2->timestamp) &&
(d1->eventType == d2->eventType) &&
(d1->cbBlob == d2->cbBlob) &&
- (!d1->szModule || !d2->szModule || !_stricmp(d1->szModule, d2->szModule))
- ;
- if (Data) {
- return res &&
- (!d1->pBlob || !d2->pBlob || !memcmp(d1->pBlob,d2->pBlob,d1->cbBlob))
- ;
- }
+ (!d1->szModule || !d2->szModule || !_stricmp(d1->szModule, d2->szModule));
+ if (Data)
+ return res && (!d1->pBlob || !d2->pBlob || !memcmp(d1->pBlob,d2->pBlob,d1->cbBlob));
+
return res;
}
/**
- * This functions searches for an existing event in the database, which matches
- * the information provided by 'dbei'. In order to fasten up the search e.g.
- * while checking many events, this function stars searching from the last
- * found event.
- * @param hContact - the handle of the contact to search events for
- * @param hDbExistingEvent - an existing database event to start the search from.
- * @param dbei - the pointer to a DBEVENTINFO structure
- *
- * @retval TRUE - the event identified by its information in @c dbei exists.
- * @retval FALSE - no event with the information of @c dbei exists.
- *
- **/
-BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei)
+* This functions searches for an existing event in the database, which matches
+* the information provided by 'dbei'. In order to fasten up the search e.g.
+* while checking many events, this function stars searching from the last
+* found event.
+* @param hContact - the handle of the contact to search events for
+* @param hDbExistingEvent - an existing database event to start the search from.
+* @param dbei - the pointer to a DBEVENTINFO structure
+*
+* @retval TRUE - the event identified by its information in @c dbei exists.
+* @retval FALSE - no event with the information of @c dbei exists.
+*
+**/
+
+bool Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei)
{
- BYTE result = FALSE;
+ bool result = false;
DBEVENTINFO edbei;
- HANDLE sdbe,
- edbe;
if (!hDbExistingEvent) {
hDbExistingEvent = db_event_first(hContact);
if (hDbExistingEvent) {
if (!GetInfo(hDbExistingEvent, &edbei)) {
- if ((dbei->timestamp < edbei.timestamp)) {
- return FALSE;
- }
+ if ((dbei->timestamp < edbei.timestamp))
+ return false;
+
if (IsEqual(dbei, &edbei, false)) {
if (!GetInfoWithData(hDbExistingEvent, &edbei)) {
if (IsEqual(dbei, &edbei, true)) {
mir_free(edbei.pBlob);
- return TRUE;
+ return true;
}
mir_free(edbei.pBlob);
}
}
}
- edbe = db_event_last(hContact);
+ HANDLE edbe = db_event_last(hContact);
if (edbe == hDbExistingEvent)
return FALSE;
@@ -831,37 +788,35 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) }
}
if (hDbExistingEvent) {
- sdbe = hDbExistingEvent;
- for ( edbe = sdbe;
- edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp <= edbei.timestamp);
- edbe = db_event_prev(edbe)) {
+ HANDLE sdbe = hDbExistingEvent;
+ for (HANDLE edbe = sdbe; edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp <= edbei.timestamp); edbe = db_event_prev(edbe)) {
hDbExistingEvent = edbe;
//compare without data (faster)
if ( result = IsEqual(dbei, &edbei, false)) {
- if (NULL == (result = !GetInfoWithData(edbe, &edbei))) continue;
+ if (NULL == (result = !GetInfoWithData(edbe, &edbei)))
+ continue;
+
//compare with data
result = IsEqual(dbei, &edbei, true);
mir_free(edbei.pBlob);
- if (result) {
+ if (result)
break;
- }
}
} /*end for*/
if (!result) {
- for ( edbe = db_event_next(sdbe);
- edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp >= edbei.timestamp);
- edbe = db_event_next(edbe)) {
+ for (HANDLE edbe = db_event_next(sdbe); edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp >= edbei.timestamp); edbe = db_event_next(edbe)) {
hDbExistingEvent = edbe;
//compare without data (faster)
- if ( result = IsEqual(dbei, &edbei, false)) {
- if (NULL == (result = !GetInfoWithData(edbe, &edbei))) continue;
+ if (result = IsEqual(dbei, &edbei, false)) {
+ if (NULL == (result = !GetInfoWithData(edbe, &edbei)))
+ continue;
+
//compare with data
result = IsEqual(dbei, &edbei, true);
mir_free(edbei.pBlob);
- if (result) {
+ if (result)
break;
- }
}
}
}
@@ -873,9 +828,8 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) int CEnumList::EnumProc(LPCSTR pszName, DWORD ofsModuleName, LPARAM lParam)
{
- if (pszName) {
+ if (pszName)
((CEnumList*)lParam)->Insert(pszName);
- }
return 0;
}
@@ -887,9 +841,9 @@ int CEnumList::EnumSettingsProc(LPCSTR pszName, LPARAM lParam) int CEnumList::CompareProc(LPCSTR p1, LPCSTR p2)
{
if (p1) {
- if (p2) {
+ if (p2)
return strcmp(p1, p2);
- }
+
return 1;
}
return 0;
@@ -901,14 +855,10 @@ CEnumList::CEnumList() : LIST<CHAR>(50, (FTSortFunc)CEnumList::CompareProc) CEnumList::~CEnumList()
{
- int i, cnt;
- LPSTR p;
-
- for (i = 0, cnt = getCount(); i < cnt; i++) {
- p = (*this)[i];
- if (p) {
+ for (int i = 0, cnt = getCount(); i < cnt; i++) {
+ LPSTR p = (*this)[i];
+ if (p)
mir_free(p);
- }
}
destroy();
}
@@ -929,17 +879,16 @@ INT_PTR CEnumList::EnumModules() }
/**
- * @retval -1 - no settings to enumerate
- * @retval 0 - success
- **/
+* @retval -1 - no settings to enumerate
+* @retval 0 - success
+**/
+
INT_PTR CEnumList::EnumSettings(HANDLE hContact, LPCSTR pszModule)
{
- DBCONTACTENUMSETTINGS dbces;
-
+ DBCONTACTENUMSETTINGS dbces = { 0 };
dbces.pfnEnumProc = (DBSETTINGENUMPROC)CEnumList::EnumSettingsProc;
dbces.szModule = pszModule;
dbces.lParam = (LPARAM)this;
- dbces.ofsSettings = 0;
return CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces);
}
|