summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-11-24 13:15:32 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-11-24 13:15:32 +0300
commit355c41643beadff74d490dc36f2c0432a2286e4c (patch)
tree9f5320227208ddc3e767e341af3c632a4a521c9a /src
parent6d6cb956a78b2dbfa7e8d62f4234d8f27b100468 (diff)
more common database code moved to MDatabaseCommon
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/MDatabaseCommon.cpp108
-rw-r--r--src/mir_app/src/mir_app.def7
-rw-r--r--src/mir_app/src/mir_app64.def7
-rw-r--r--src/mir_core/src/db.cpp16
4 files changed, 123 insertions, 15 deletions
diff --git a/src/mir_app/src/MDatabaseCommon.cpp b/src/mir_app/src/MDatabaseCommon.cpp
index 66e16968c4..67e13b8614 100644
--- a/src/mir_app/src/MDatabaseCommon.cpp
+++ b/src/mir_app/src/MDatabaseCommon.cpp
@@ -35,6 +35,114 @@ MDatabaseCommon::MDatabaseCommon() :
m_codePage = Langpack_GetDefaultCodePage();
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int MDatabaseCommon::CheckProto(DBCachedContact *cc, const char *proto)
+{
+ if (cc->szProto == nullptr) {
+ char protobuf[MAX_PATH] = { 0 };
+ DBVARIANT dbv;
+ dbv.type = DBVT_ASCIIZ;
+ dbv.pszVal = protobuf;
+ dbv.cchVal = sizeof(protobuf);
+ if (GetContactSettingStatic(cc->contactID, "Protocol", "p", &dbv) != 0 || (dbv.type != DBVT_ASCIIZ))
+ return 0;
+
+ cc->szProto = m_cache->GetCachedSetting(nullptr, protobuf, 0, (int)mir_strlen(protobuf));
+ }
+
+ return !mir_strcmp(cc->szProto, proto);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int sttEnumVars(const char *szVarName, void *param)
+{
+ LIST<char>* vars = (LIST<char>*)param;
+ vars->insert(mir_strdup(szVarName));
+ return 0;
+}
+
+BOOL MDatabaseCommon::DeleteModule(MCONTACT hContact, LPCSTR szModule)
+{
+ LIST<char> vars(20);
+ EnumContactSettings(hContact, sttEnumVars, szModule, &vars);
+
+ for (int i = vars.getCount() - 1; i >= 0; i--) {
+ DeleteContactSetting(hContact, szModule, vars[i]);
+ mir_free(vars[i]);
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+STDMETHODIMP_(MCONTACT) MDatabaseCommon::FindFirstContact(const char *szProto)
+{
+ mir_cslock lck(m_csDbAccess);
+ DBCachedContact *cc = m_cache->GetFirstContact();
+ if (cc == nullptr)
+ return 0;
+
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
+
+ return FindNextContact(cc->contactID, szProto);
+}
+
+STDMETHODIMP_(MCONTACT) MDatabaseCommon::FindNextContact(MCONTACT contactID, const char *szProto)
+{
+ mir_cslock lck(m_csDbAccess);
+ while (contactID) {
+ DBCachedContact *cc = m_cache->GetNextContact(contactID);
+ if (cc == nullptr)
+ break;
+
+ if (!szProto || CheckProto(cc, szProto))
+ return cc->contactID;
+
+ contactID = cc->contactID;
+ }
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+BOOL MDatabaseCommon::IsSettingEncrypted(LPCSTR szModule, LPCSTR szSetting)
+{
+ if (!_strnicmp(szSetting, "password", 8)) return true;
+ if (!mir_strcmp(szSetting, "NLProxyAuthPassword")) return true;
+ if (!mir_strcmp(szSetting, "LNPassword")) return true;
+ if (!mir_strcmp(szSetting, "FileProxyPassword")) return true;
+ if (!mir_strcmp(szSetting, "TokenSecret")) return true;
+
+ if (!mir_strcmp(szModule, "SecureIM")) {
+ if (!mir_strcmp(szSetting, "pgp")) return true;
+ if (!mir_strcmp(szSetting, "pgpPrivKey")) return true;
+ }
+ return false;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+BOOL MDatabaseCommon::MetaDetouchSub(DBCachedContact *cc, int nSub)
+{
+ return DeleteModule(cc->pSubs[nSub], META_PROTO);
+}
+
+BOOL MDatabaseCommon::MetaSetDefault(DBCachedContact *cc)
+{
+ DBCONTACTWRITESETTING cws;
+ cws.szModule = META_PROTO;
+ cws.szSetting = "Default";
+ cws.value.type = DBVT_DWORD;
+ cws.value.dVal = cc->nDefault;
+ return WriteContactSetting(cc->contactID, &cws);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
STDMETHODIMP_(BOOL) MDatabaseCommon::GetContactSetting(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 90a77bfe25..cff4a26030 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -479,3 +479,10 @@ Clist_SetStatusMode @464
?GetContactSettingStatic@MDatabaseCommon@@UAGHIPBD0PAUDBVARIANT@@@Z @484 NONAME
?GetContactSettingStr@MDatabaseCommon@@UAGHIPBD0PAUDBVARIANT@@@Z @485 NONAME
?SetSettingResident@MDatabaseCommon@@UAGHHPBD@Z @486 NONAME
+?IsSettingEncrypted@MDatabaseCommon@@UAGHPBD0@Z @487 NONAME
+?CheckProto@MDatabaseCommon@@IAEHPAUDBCachedContact@@PBD@Z @488 NONAME
+?DeleteModule@MDatabaseCommon@@UAGHIPBD@Z @489 NONAME
+?FindFirstContact@MDatabaseCommon@@UAGIPBD@Z @490 NONAME
+?FindNextContact@MDatabaseCommon@@UAGIIPBD@Z @491 NONAME
+?MetaDetouchSub@MDatabaseCommon@@UAGHPAUDBCachedContact@@H@Z @492 NONAME
+?MetaSetDefault@MDatabaseCommon@@UAGHPAUDBCachedContact@@@Z @493 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 2bb0247a06..4bb67009d7 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -479,3 +479,10 @@ Clist_SetStatusMode @464
?GetContactSettingStatic@MDatabaseCommon@@UEAAHIPEBD0PEAUDBVARIANT@@@Z @484 NONAME
?GetContactSettingStr@MDatabaseCommon@@UEAAHIPEBD0PEAUDBVARIANT@@@Z @485 NONAME
?SetSettingResident@MDatabaseCommon@@UEAAHHPEBD@Z @486 NONAME
+?IsSettingEncrypted@MDatabaseCommon@@UEAAHPEBD0@Z @487 NONAME
+?CheckProto@MDatabaseCommon@@IEAAHPEAUDBCachedContact@@PEBD@Z @488 NONAME
+?DeleteModule@MDatabaseCommon@@UEAAHIPEBD@Z @489 NONAME
+?FindFirstContact@MDatabaseCommon@@UEAAIPEBD@Z @490 NONAME
+?FindNextContact@MDatabaseCommon@@UEAAIIPEBD@Z @491 NONAME
+?MetaDetouchSub@MDatabaseCommon@@UEAAHPEAUDBCachedContact@@H@Z @492 NONAME
+?MetaSetDefault@MDatabaseCommon@@UEAAHPEAUDBCachedContact@@@Z @493 NONAME
diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp
index 15e9f2465d..7aa591db19 100644
--- a/src/mir_core/src/db.cpp
+++ b/src/mir_core/src/db.cpp
@@ -45,23 +45,9 @@ MIR_CORE_DLL(MIDatabase*) db_get_current()
return currDb;
}
-static int sttEnumVars(const char *szVarName, void *param)
-{
- LIST<char>* vars = (LIST<char>*)param;
- vars->insert(mir_strdup(szVarName));
- return 0;
-}
-
MIR_CORE_DLL(int) db_delete_module(MCONTACT hContact, const char *szModuleName)
{
- LIST<char> vars(20);
- db_enum_settings(hContact, sttEnumVars, szModuleName, &vars);
-
- for (int i = vars.getCount() - 1; i >= 0; i--) {
- db_unset(hContact, szModuleName, vars[i]);
- mir_free(vars[i]);
- }
- return 0;
+ return (currDb) ? currDb->DeleteModule(hContact, szModuleName) : 0;
}
/////////////////////////////////////////////////////////////////////////////////////////