diff options
author | George Hazan <george.hazan@gmail.com> | 2012-11-30 16:26:36 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-11-30 16:26:36 +0000 |
commit | 8c85373fcb86aae9a09e19cae045fa667ba929a4 (patch) | |
tree | 6e9d763efadca018c658b7ece8c100ac86e4e70f /protocols/IcqOscarJ/src/icq_db.cpp | |
parent | 540f5010d9ebdec65b09bdc71fcd6cdf2010beaf (diff) |
some helpers wiped out of ICQ
git-svn-id: http://svn.miranda-ng.org/main/trunk@2567 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IcqOscarJ/src/icq_db.cpp')
-rw-r--r-- | protocols/IcqOscarJ/src/icq_db.cpp | 188 |
1 files changed, 61 insertions, 127 deletions
diff --git a/protocols/IcqOscarJ/src/icq_db.cpp b/protocols/IcqOscarJ/src/icq_db.cpp index 9e9ca34fb2..ebb0f08ac1 100644 --- a/protocols/IcqOscarJ/src/icq_db.cpp +++ b/protocols/IcqOscarJ/src/icq_db.cpp @@ -29,7 +29,6 @@ // -----------------------------------------------------------------------------
#include "icqoscar.h"
-
void CIcqProto::CreateResidentSetting(const char *szSetting)
{
char pszSetting[2*MAX_PATH];
@@ -40,152 +39,131 @@ void CIcqProto::CreateResidentSetting(const char *szSetting) CallService(MS_DB_SETSETTINGRESIDENT, 1, (WPARAM)pszSetting);
}
-
int CIcqProto::getSetting(HANDLE hContact, const char *szSetting, DBVARIANT *dbv)
{
- return DBGetContactSettingW(hContact, m_szModuleName, szSetting, dbv);
+ return db_get_s(hContact, m_szModuleName, szSetting, dbv, 0);
}
-
BYTE CIcqProto::getSettingByte(HANDLE hContact, const char *szSetting, BYTE byDef)
{
- return DBGetContactSettingByte(hContact, m_szModuleName, szSetting, byDef);
+ return db_get_b(hContact, m_szModuleName, szSetting, byDef);
}
-
WORD CIcqProto::getSettingWord(HANDLE hContact, const char *szSetting, WORD wDef)
{
- return DBGetContactSettingWord(hContact, m_szModuleName, szSetting, wDef);
+ return db_get_w(hContact, m_szModuleName, szSetting, wDef);
}
-
DWORD CIcqProto::getSettingDword(HANDLE hContact, const char *szSetting, DWORD dwDef)
{
- DBVARIANT dbv = {DBVT_DELETED};
+ DBVARIANT dbv = {DBVT_DELETED};
DWORD dwRes;
- if (getSetting(hContact, szSetting, &dbv))
- return dwDef; // not found, give default
+ if (getSetting(hContact, szSetting, &dbv))
+ return dwDef; // not found, give default
if (dbv.type != DBVT_DWORD)
dwRes = dwDef; // invalid type, give default
else // found and valid, give result
dwRes = dbv.dVal;
- ICQFreeVariant(&dbv);
+ db_free(&dbv);
return dwRes;
}
-
double CIcqProto::getSettingDouble(HANDLE hContact, const char *szSetting, double dDef)
{
- DBVARIANT dbv = {DBVT_DELETED};
- double dRes;
+ DBVARIANT dbv = {DBVT_DELETED};
+ double dRes;
- if (getSetting(hContact, szSetting, &dbv))
- return dDef; // not found, give default
+ if (getSetting(hContact, szSetting, &dbv))
+ return dDef; // not found, give default
- if (dbv.type != DBVT_BLOB || dbv.cpbVal != sizeof(double))
- dRes = dDef;
- else
- dRes = *(double*)dbv.pbVal;
+ if (dbv.type != DBVT_BLOB || dbv.cpbVal != sizeof(double))
+ dRes = dDef;
+ else
+ dRes = *(double*)dbv.pbVal;
- ICQFreeVariant(&dbv);
- return dRes;
+ db_free(&dbv);
+ return dRes;
}
-
DWORD CIcqProto::getContactUin(HANDLE hContact)
{
return getSettingDword(hContact, UNIQUEIDSETTING, 0);
}
-
int CIcqProto::getContactUid(HANDLE hContact, DWORD *pdwUin, uid_str *ppszUid)
{
- DBVARIANT dbv = {DBVT_DELETED};
+ DBVARIANT dbv = {DBVT_DELETED};
int iRes = 1;
*pdwUin = 0;
if (ppszUid) *ppszUid[0] = '\0';
- if (!getSetting(hContact, UNIQUEIDSETTING, &dbv))
- {
- if (dbv.type == DBVT_DWORD)
- {
+ if (!getSetting(hContact, UNIQUEIDSETTING, &dbv)) {
+ if (dbv.type == DBVT_DWORD) {
*pdwUin = dbv.dVal;
iRes = 0;
}
- else if (dbv.type == DBVT_ASCIIZ)
- {
- if (ppszUid && m_bAimEnabled)
- {
+ else if (dbv.type == DBVT_ASCIIZ) {
+ if (ppszUid && m_bAimEnabled) {
strcpy(*ppszUid, dbv.pszVal);
iRes = 0;
}
else
NetLog_Server("AOL screennames not accepted");
}
- ICQFreeVariant(&dbv);
+ db_free(&dbv);
}
return iRes;
}
-
int CIcqProto::getSettingString(HANDLE hContact, const char *szSetting, DBVARIANT *dbv)
{
- int res = DBGetContactSettingString(hContact, m_szModuleName, szSetting, dbv);
-
- if (res)
- ICQFreeVariant(dbv);
+ int res = db_get_s(hContact, m_szModuleName, szSetting, dbv);
+ if (res)
+ db_free(dbv);
return res;
}
-
int CIcqProto::getSettingStringW(HANDLE hContact, const char *szSetting, DBVARIANT *dbv)
{
- int res = DBGetContactSettingWString(hContact, m_szModuleName, szSetting, dbv);
-
- if (res)
- ICQFreeVariant(dbv);
+ int res = db_get_ws(hContact, m_szModuleName, szSetting, dbv);
+ if (res)
+ db_free(dbv);
return res;
}
-
char* CIcqProto::getSettingStringUtf(HANDLE hContact, const char *szModule, const char *szSetting, char *szDef)
{
DBVARIANT dbv = {DBVT_DELETED};
-
- if (DBGetContactSettingUTF8String(hContact, szModule, szSetting, &dbv))
- {
- ICQFreeVariant(&dbv); // for a setting with invalid contents/type
+ if ( db_get_utf(hContact, szModule, szSetting, &dbv)) {
+ db_free(&dbv); // for a setting with invalid contents/type
return null_strdup(szDef);
- }
+ }
char *szRes = null_strdup(dbv.pszVal);
- ICQFreeVariant(&dbv);
+ db_free(&dbv);
return szRes;
}
-
char* CIcqProto::getSettingStringUtf(HANDLE hContact, const char *szSetting, char *szDef)
{
return getSettingStringUtf(hContact, m_szModuleName, szSetting, szDef);
}
-
WORD CIcqProto::getContactStatus(HANDLE hContact)
{
- return getSettingWord(hContact, "Status", ID_STATUS_OFFLINE);
+ return getSettingWord(hContact, "Status", ID_STATUS_OFFLINE);
}
-
int CIcqProto::getSettingStringStatic(HANDLE hContact, const char *szSetting, char *dest, int dest_len)
{
- DBVARIANT dbv = {DBVT_DELETED};
- DBCONTACTGETSETTING sVal = {0};
+ DBVARIANT dbv = {DBVT_DELETED};
+ DBCONTACTGETSETTING sVal = {0};
dbv.pszVal = dest;
dbv.cchVal = dest_len;
@@ -195,8 +173,7 @@ int CIcqProto::getSettingStringStatic(HANDLE hContact, const char *szSetting, ch sVal.szModule = m_szModuleName;
sVal.szSetting = szSetting;
- if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal) != 0)
- { // due to MS_DB_CONTACT_GETSETTINGSTATIC setting type check, we need to request UTF8 as well
+ if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal) != 0) {
dbv.pszVal = dest;
dbv.cchVal = dest_len;
dbv.type = DBVT_UTF8;
@@ -208,93 +185,77 @@ int CIcqProto::getSettingStringStatic(HANDLE hContact, const char *szSetting, ch return (dbv.type != DBVT_ASCIIZ);
}
-
int CIcqProto::deleteSetting(HANDLE hContact, const char *szSetting)
{
- return DBDeleteContactSetting(hContact, m_szModuleName, szSetting);
+ return db_unset(hContact, m_szModuleName, szSetting);
}
-
int CIcqProto::setSettingByte(HANDLE hContact, const char *szSetting, BYTE byValue)
{
- return DBWriteContactSettingByte(hContact, m_szModuleName, szSetting, byValue);
+ return db_set_b(hContact, m_szModuleName, szSetting, byValue);
}
-
int CIcqProto::setSettingWord(HANDLE hContact, const char *szSetting, WORD wValue)
{
- return DBWriteContactSettingWord(hContact, m_szModuleName, szSetting, wValue);
+ return db_set_w(hContact, m_szModuleName, szSetting, wValue);
}
-
int CIcqProto::setSettingDword(HANDLE hContact, const char *szSetting, DWORD dwValue)
{
- return DBWriteContactSettingDword(hContact, m_szModuleName, szSetting, dwValue);
+ return db_set_dw(hContact, m_szModuleName, szSetting, dwValue);
}
-
int CIcqProto::setSettingDouble(HANDLE hContact, const char *szSetting, double dValue)
{
- return setSettingBlob(hContact, szSetting, (BYTE*)&dValue, sizeof(double));
+ return setSettingBlob(hContact, szSetting, (BYTE*)&dValue, sizeof(double));
}
-
int CIcqProto::setSettingString(HANDLE hContact, const char *szSetting, const char *szValue)
{
- return DBWriteContactSettingString(hContact, m_szModuleName, szSetting, szValue);
+ return db_set_s(hContact, m_szModuleName, szSetting, szValue);
}
-
int CIcqProto::setSettingStringW(HANDLE hContact, const char *szSetting, const WCHAR *wszValue)
{
- return DBWriteContactSettingWString(hContact, m_szModuleName, szSetting, wszValue);
+ return db_set_ws(hContact, m_szModuleName, szSetting, wszValue);
}
-
int CIcqProto::setSettingStringUtf(HANDLE hContact, const char *szModule, const char *szSetting, const char *szValue)
{
- return DBWriteContactSettingUTF8String(hContact, szModule, szSetting, (char*)szValue);
+ return db_set_utf(hContact, szModule, szSetting, szValue);
}
-
int CIcqProto::setSettingStringUtf(HANDLE hContact, const char *szSetting, const char *szValue)
{
- return setSettingStringUtf(hContact, m_szModuleName, szSetting, szValue);
+ return db_set_utf(hContact, m_szModuleName, szSetting, szValue);
}
-
int CIcqProto::setSettingBlob(HANDLE hContact, const char *szSetting, const BYTE *pValue, const int cbValue)
{
- return DBWriteContactSettingBlob(hContact, m_szModuleName, szSetting, (void*)pValue, cbValue);
+ return db_set_blob(hContact, m_szModuleName, szSetting, (void*)pValue, cbValue);
}
-
int CIcqProto::setContactHidden(HANDLE hContact, BYTE bHidden)
{
- int nResult = DBWriteContactSettingByte(hContact, "CList", "Hidden", bHidden);
-
+ int nResult = db_set_b(hContact, "CList", "Hidden", bHidden);
if (!bHidden) // clear zero setting
- DBDeleteContactSetting(hContact, "CList", "Hidden");
+ db_unset(hContact, "CList", "Hidden");
- return nResult;
+ return nResult;
}
void CIcqProto::setStatusMsgVar(HANDLE hContact, char* szStatusMsg, bool isAnsi)
{
- if (szStatusMsg && szStatusMsg[0])
- {
- if (isAnsi)
- {
+ if (szStatusMsg && szStatusMsg[0]) {
+ if (isAnsi) {
char* szStatusNote = getSettingStringUtf(hContact, DBSETTING_STATUS_NOTE, "");
wchar_t* szStatusNoteW = make_unicode_string(szStatusNote);
int len = (int)wcslen(szStatusNoteW) * 3 + 1;
char* szStatusNoteAnsi = (char*)alloca(len);
WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, szStatusNoteW, -1, szStatusNoteAnsi, len, NULL, NULL);
bool notmatch = false;
- for (int i=0; ;++i)
- {
- if (szStatusNoteAnsi[i] != szStatusMsg[i] && szStatusNoteAnsi[i] != '?' && szStatusMsg[i] != '?')
- {
+ for (int i=0; ;++i) {
+ if (szStatusNoteAnsi[i] != szStatusMsg[i] && szStatusNoteAnsi[i] != '?' && szStatusMsg[i] != '?') {
notmatch = true;
break;
}
@@ -303,41 +264,25 @@ void CIcqProto::setStatusMsgVar(HANDLE hContact, char* szStatusMsg, bool isAnsi) }
szStatusMsg = notmatch ? ansi_to_utf8(szStatusMsg) : szStatusNote;
SAFE_FREE(&szStatusNoteW);
- if (notmatch) SAFE_FREE(&szStatusNote);
+ if (notmatch)
+ SAFE_FREE(&szStatusNote);
}
char* oldStatusMsg = NULL;
DBVARIANT dbv;
- if (!DBGetContactSetting(hContact, "CList", "StatusMsg", &dbv))
- {
- switch (dbv.type)
- {
- case DBVT_UTF8:
- oldStatusMsg = null_strdup(dbv.pszVal);
- break;
-
- case DBVT_WCHAR:
- oldStatusMsg = make_utf8_string(dbv.pwszVal);
- break;
- }
- ICQFreeVariant(&dbv);
+ if ( !db_get_ts(hContact, "CList", "StatusMsg", &dbv)) {
+ oldStatusMsg = make_utf8_string(dbv.ptszVal);
+ db_free(&dbv);
}
-
+
if (!oldStatusMsg || strcmp(oldStatusMsg, szStatusMsg))
setSettingStringUtf(hContact, "CList", "StatusMsg", szStatusMsg);
SAFE_FREE(&oldStatusMsg);
if (isAnsi) SAFE_FREE(&szStatusMsg);
}
- else
- DBDeleteContactSetting(hContact, "CList", "StatusMsg");
-}
-
-int __fastcall ICQFreeVariant(DBVARIANT *dbv)
-{
- return DBFreeVariant(dbv);
+ else db_unset(hContact, "CList", "StatusMsg");
}
-
int CIcqProto::IsICQContact(HANDLE hContact)
{
char* szProto = GetContactProto(hContact);
@@ -345,7 +290,6 @@ int CIcqProto::IsICQContact(HANDLE hContact) return !strcmpnull(szProto, m_szModuleName);
}
-
HANDLE CIcqProto::AddEvent(HANDLE hContact, WORD wType, DWORD dwTime, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = {0};
@@ -361,7 +305,6 @@ HANDLE CIcqProto::AddEvent(HANDLE hContact, WORD wType, DWORD dwTime, DWORD flag return (HANDLE)CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei);
}
-
HANDLE CIcqProto::FindFirstContact()
{
HANDLE hContact = db_find_first(m_szModuleName);
@@ -372,7 +315,6 @@ HANDLE CIcqProto::FindFirstContact() return FindNextContact(hContact);
}
-
HANDLE CIcqProto::FindNextContact(HANDLE hContact)
{
hContact = db_find_next(hContact, m_szModuleName);
@@ -385,15 +327,7 @@ HANDLE CIcqProto::FindNextContact(HANDLE hContact) return hContact;
}
-
char* CIcqProto::getContactCListGroup(HANDLE hContact)
{
return getSettingStringUtf(hContact, "CList", "Group", NULL);
}
-
-
-int __stdcall ICQSetContactCListGroup(HANDLE hContact, const char *szGroup)
-{
- /// TODO
- return 0;
-}
|