From 7bdb598e26e7e98788933af43090d34027166969 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 14 Sep 2016 18:01:49 +0000 Subject: second major wipeout of database services & structures: - DBCONTACTENUMSETTINGS removed; - all helpers moved to mir_core.dll git-svn-id: http://svn.miranda-ng.org/main/trunk@17296 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_app/src/chat_clist.cpp | 2 +- src/mir_app/src/chat_manager.cpp | 2 +- src/mir_app/src/clc.cpp | 2 +- src/mir_app/src/clistmod.cpp | 4 +- src/mir_app/src/clui.cpp | 2 +- src/mir_app/src/database.cpp | 7 +- src/mir_app/src/db_events.cpp | 315 +++++++++++++++++++ src/mir_app/src/db_ini.cpp | 633 +++++++++++++++++++++++++++++++++++++ src/mir_app/src/db_intf.cpp | 98 ++++++ src/mir_app/src/dbini.cpp | 640 -------------------------------------- src/mir_app/src/dbintf.cpp | 167 ---------- src/mir_app/src/dbutils.cpp | 341 -------------------- src/mir_app/src/ignore.cpp | 2 +- src/mir_app/src/menu_options.cpp | 2 +- src/mir_app/src/menu_utils.cpp | 2 +- src/mir_app/src/meta_menu.cpp | 6 +- src/mir_app/src/meta_services.cpp | 2 +- src/mir_app/src/mir_app.def | 2 +- src/mir_app/src/mir_app64.def | 1 - src/mir_app/src/options_ei.cpp | 2 +- src/mir_app/src/proto_accs.cpp | 14 +- 21 files changed, 1068 insertions(+), 1178 deletions(-) create mode 100644 src/mir_app/src/db_events.cpp create mode 100644 src/mir_app/src/db_ini.cpp create mode 100644 src/mir_app/src/db_intf.cpp delete mode 100644 src/mir_app/src/dbini.cpp delete mode 100644 src/mir_app/src/dbintf.cpp delete mode 100644 src/mir_app/src/dbutils.cpp (limited to 'src/mir_app') diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 859c93e59a..d371083f5f 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -54,7 +54,7 @@ MCONTACT AddRoom(const char *pszModule, const wchar_t *pszRoom, const wchar_t *p } // here we create a new one since no one is to be found - if ((hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0)) == NULL) + if ((hContact = db_add_contact()) == NULL) return NULL; Proto_AddToContact(hContact, pszModule); diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 83044f9d79..3ec71e4886 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -137,7 +137,7 @@ static int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL re // contact may have been deleted here already, since function may be called after deleting // contact so the handle may be invalid, therefore db_get_b shall return 0 if (pTemp->hContact && removeContact) - CallService(MS_DB_CONTACT_DELETE, (WPARAM)pTemp->hContact, 0); + db_delete_contact(pTemp->hContact); SM_FreeSession(pTemp); diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index f0f947ad0f..0af50af530 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -495,7 +495,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam contact = NULL; group = NULL; if (!cli.pfnFindItem(hwnd, dat, wParam, &contact, &group, NULL)) { - if (shouldShow && CallService(MS_DB_CONTACT_IS, wParam, 0)) { + if (shouldShow && db_is_contact(wParam)) { if (dat->selection >= 0 && cli.pfnGetRowByIndex(dat, dat->selection, &selcontact, NULL) != -1) hSelItem = Clist_ContactToHItem(selcontact); cli.pfnAddContactToTree(hwnd, dat, wParam, (style & CLS_CONTACTLIST) == 0, 0); diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp index b74a591854..2255ed5ff7 100644 --- a/src/mir_app/src/clistmod.cpp +++ b/src/mir_app/src/clistmod.cpp @@ -125,7 +125,7 @@ static int ProtocolAck(WPARAM, LPARAM lParam) for (MCONTACT hContact = db_find_first(ack->szModule); hContact; ) { MCONTACT hNext = db_find_next(hContact, ack->szModule); if (db_get_b(hContact, "CList", "Delete", 0)) - CallService(MS_DB_CONTACT_DELETE, hContact, 0); + db_delete_contact(hContact); hContact = hNext; } } @@ -453,7 +453,7 @@ void UnloadContactListModule() for (MCONTACT hContact = db_find_first(); hContact != NULL; ) { MCONTACT hNext = db_find_next(hContact); if (db_get_b(hContact, "CList", "NotOnList", 0)) - CallService(MS_DB_CONTACT_DELETE, hContact, 0); + db_delete_contact(hContact); hContact = hNext; } ImageList_Destroy(hCListImages); diff --git a/src/mir_app/src/clui.cpp b/src/mir_app/src/clui.cpp index c679c6a15f..873caf139f 100644 --- a/src/mir_app/src/clui.cpp +++ b/src/mir_app/src/clui.cpp @@ -195,7 +195,7 @@ static INT_PTR MenuItem_DeleteContact(WPARAM wParam, LPARAM lParam) } } - CallService(MS_DB_CONTACT_DELETE, wParam, 0); + db_delete_contact(wParam); break; } diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp index 420e442f15..70db2791ef 100644 --- a/src/mir_app/src/database.cpp +++ b/src/mir_app/src/database.cpp @@ -25,14 +25,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "profilemanager.h" +MIDatabase *currDb = NULL; +DATABASELINK *currDblink = NULL; + // contains the location of mirandaboot.ini bool g_bDbCreated; wchar_t g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH]; wchar_t* g_defaultProfile; void EnsureCheckerLoaded(bool); -void LoadDatabaseServices(); - bool fileExist(const wchar_t *fname) { if (*fname == 0) @@ -486,8 +487,6 @@ int LoadDatabaseModule(void) _tchdir(szProfile); szProfile[0] = 0; - LoadDatabaseServices(); - // find out which profile to load if (!getProfile(szProfile, _countof(szProfile))) return 1; diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp new file mode 100644 index 0000000000..bc3fb4d470 --- /dev/null +++ b/src/mir_app/src/db_events.cpp @@ -0,0 +1,315 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-16 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "profilemanager.h" + +static int CompareEventTypes(const DBEVENTTYPEDESCR *p1, const DBEVENTTYPEDESCR *p2) +{ + int result = mir_strcmp(p1->module, p2->module); + if (result) + return result; + + return p1->eventType - p2->eventType; +} + +static LIST eventTypes(10, CompareEventTypes); + +void UnloadEventsModule() +{ + for (int i = 0; i < eventTypes.getCount(); i++) { + DBEVENTTYPEDESCR *p = eventTypes[i]; + mir_free(p->module); + mir_free(p->descr); + mir_free(p->textService); + mir_free(p->iconService); + mir_free(p); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) DbEvent_RegisterType(DBEVENTTYPEDESCR *et) +{ + if (et == NULL || et->cbSize != sizeof(DBEVENTTYPEDESCR)) + return -1; + + if (eventTypes.getIndex(et) != -1) + return -1; + + DBEVENTTYPEDESCR *p = (DBEVENTTYPEDESCR*)mir_calloc(sizeof(DBEVENTTYPEDESCR)); + p->cbSize = sizeof(DBEVENTTYPEDESCR); + p->module = mir_strdup(et->module); + p->eventType = et->eventType; + p->descr = mir_strdup(et->descr); + if (et->textService) + p->textService = mir_strdup(et->textService); + if (et->iconService) + p->iconService = mir_strdup(et->iconService); + p->eventIcon = et->eventIcon; + p->flags = et->flags; + + if (!p->textService) { + char szServiceName[100]; + mir_snprintf(szServiceName, "%s/GetEventText%d", p->module, p->eventType); + p->textService = mir_strdup(szServiceName); + } + if (!p->iconService) { + char szServiceName[100]; + mir_snprintf(szServiceName, "%s/GetEventIcon%d", p->module, p->eventType); + p->iconService = mir_strdup(szServiceName); + } + eventTypes.insert(p); + return 0; +} + +MIR_APP_DLL(DBEVENTTYPEDESCR*) DbEvent_GetType(const char *szModule, int eventType) +{ + DBEVENTTYPEDESCR tmp; + tmp.module = (char*)szModule; + tmp.eventType = eventType; + return eventTypes.find(&tmp); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static wchar_t* getEventString(DBEVENTINFO *dbei, LPSTR &buf) +{ + LPSTR in = buf; + buf += mir_strlen(buf) + 1; + return (dbei->flags & DBEF_UTF) ? Utf8DecodeT(in) : mir_a2u(in); +} + +static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatype) +{ + if (dbei == NULL || dbei->szModule == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) + return 0; + + DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType); + if (et && ServiceExists(et->textService)) + return CallService(et->textService, (WPARAM)dbei, datatype); + + if (!dbei->pBlob) + return 0; + + if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) { + // EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) + // EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) + DWORD uin = *(DWORD*)dbei->pBlob; + MCONTACT hContact = (MCONTACT)*(DWORD*)(dbei->pBlob + sizeof(DWORD)); + char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2; + ptrW tszNick(getEventString(dbei, buf)); + ptrW tszFirst(getEventString(dbei, buf)); + ptrW tszLast(getEventString(dbei, buf)); + ptrW tszEmail(getEventString(dbei, buf)); + + CMStringW nick, text; + if (tszFirst || tszLast) { + nick.AppendFormat(L"%s %s", tszFirst, tszLast); + nick.Trim(); + } + if (tszEmail) { + if (!nick.IsEmpty()) + nick.Append(L", "); + nick.Append(tszEmail); + } + if (uin != 0) { + if (!nick.IsEmpty()) + nick.Append(L", "); + nick.AppendFormat(L"%d", uin); + } + if (!nick.IsEmpty()) + nick = L"(" + nick + L")"; + + if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { + ptrW tszReason(getEventString(dbei, buf)); + text.Format(TranslateT("Authorization request from %s%s: %s"), + (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason); + } + else text.Format(TranslateT("You were added by %s%s"), + (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick); + return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text); + } + + if (dbei->eventType == EVENTTYPE_CONTACTS) { + CMStringW text(TranslateT("Contacts: ")); + // blob is: [uin(ASCIIZ), nick(ASCIIZ)]* + char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob; + while (buf < limit) { + ptrW tszUin(getEventString(dbei, buf)); + ptrW tszNick(getEventString(dbei, buf)); + if (tszNick && *tszNick) + text.AppendFormat(L"\"%s\" ", tszNick); + if (tszUin && *tszUin) + text.AppendFormat(L"<%s>; ", tszUin); + } + return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text); + } + + if (dbei->eventType == EVENTTYPE_FILE) { + char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD); + ptrW tszFileName(getEventString(dbei, buf)); + ptrW tszDescription(getEventString(dbei, buf)); + ptrW &ptszText = (mir_wstrlen(tszDescription) == 0) ? tszFileName : tszDescription; + switch (datatype) { + case DBVT_WCHAR: + return (INT_PTR)ptszText.detach(); + case DBVT_ASCIIZ: + return (INT_PTR)mir_u2a(ptszText); + } + return 0; + } + + // by default treat an event's blob as a string + if (datatype == DBVT_WCHAR) { + char *str = (char*)alloca(dbei->cbBlob + 1); + memcpy(str, dbei->pBlob, dbei->cbBlob); + str[dbei->cbBlob] = 0; + + if (dbei->flags & DBEF_UTF) { + WCHAR *msg = NULL; + Utf8DecodeCP(str, codepage, &msg); + if (msg) + return (INT_PTR)msg; + } + + return (INT_PTR)mir_a2u_cp(str, codepage); + } + + if (datatype == DBVT_ASCIIZ) { + char *msg = mir_strdup((char*)dbei->pBlob); + if (dbei->flags & DBEF_UTF) + Utf8DecodeCP(msg, codepage, NULL); + + return (INT_PTR)msg; + } + return 0; +} + +MIR_APP_DLL(char*) DbEvent_GetTextA(DBEVENTINFO *dbei, int codepage) +{ + return (char*)DbEventGetTextWorker(dbei, codepage, DBVT_ASCIIZ); +} + +MIR_APP_DLL(wchar_t*) DbEvent_GetTextW(DBEVENTINFO *dbei, int codepage) +{ + return (wchar_t*)DbEventGetTextWorker(dbei, codepage, DBVT_WCHAR); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(HICON) DbEvent_GetIcon(DBEVENTINFO *dbei, int flags) +{ + DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType); + if (et && ServiceExists(et->iconService)) { + HICON icon = (HICON)CallService(et->iconService, (WPARAM)dbei, flags); + if (icon) + return icon; + } + + HICON icon = NULL; + if (et && et->eventIcon) + icon = IcoLib_GetIconByHandle(et->eventIcon); + if (!icon) { + char szName[100]; + mir_snprintf(szName, "eventicon_%s%d", dbei->szModule, dbei->eventType); + icon = IcoLib_GetIcon(szName); + } + + if (!icon) { + switch(dbei->eventType) { + case EVENTTYPE_URL: + icon = Skin_LoadIcon(SKINICON_EVENT_URL); + break; + + case EVENTTYPE_FILE: + icon = Skin_LoadIcon(SKINICON_EVENT_FILE); + break; + + default: // EVENTTYPE_MESSAGE and unknown types + icon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); + break; + } + } + + return (flags & LR_SHARED) ? icon : CopyIcon(icon); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(wchar_t*) DbEvent_GetString(DBEVENTINFO *dbei, const char *str) +{ + if (dbei->flags & DBEF_UTF) + return Utf8DecodeW(str); + + return mir_a2u(str); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Profile_GetPathA(size_t cbLen, char *pszDest) +{ + if (!pszDest || !cbLen) + return 1; + + strncpy_s(pszDest, cbLen, _T2A(g_profileDir), _TRUNCATE); + return 0; +} + +MIR_APP_DLL(int) Profile_GetPathW(size_t cbLen, wchar_t *pwszDest) +{ + if (!pwszDest || !cbLen) + return 1; + + wcsncpy_s(pwszDest, cbLen, g_profileDir, _TRUNCATE); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Profile_GetNameA(size_t cbLen, char *pszDest) +{ + if (!cbLen || !pszDest) + return 1; + + strncpy_s(pszDest, cbLen, ptrA(makeFileName(g_profileName)), _TRUNCATE); + return 0; +} + +MIR_APP_DLL(int) Profile_GetNameW(size_t cbLen, wchar_t *pwszDest) +{ + if (!cbLen || !pwszDest) + return 1; + + wcsncpy_s(pwszDest, cbLen, g_profileName, _TRUNCATE); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(void) Profile_SetDefault(const wchar_t *pwszPath) +{ + extern wchar_t* g_defaultProfile; + replaceStrW(g_defaultProfile, pwszPath); +} diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp new file mode 100644 index 0000000000..b33095de6c --- /dev/null +++ b/src/mir_app/src/db_ini.cpp @@ -0,0 +1,633 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-16 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "profilemanager.h" + +static bool bModuleInitialized = false; +static HANDLE hIniChangeNotification; + +////////////////////////////////////////////////////// + +class CInstallIniDlg : public CDlgBase +{ + wchar_t *m_szIniPath; + + CCtrlButton m_viewIni; + CCtrlButton m_noToAll; + + CCtrlBase m_iniName; + CCtrlBase m_securityInfo; + +protected: + void OnInitDialog(); + + void ViewIni_OnClick(CCtrlBase*); + void NoToAll_OnClick(CCtrlBase*); + +public: + CInstallIniDlg(wchar_t *szIniPath); +}; + +CInstallIniDlg::CInstallIniDlg(wchar_t *szIniPath) + : CDlgBase(g_hInst, IDD_INSTALLINI), + m_noToAll(this, IDC_NOTOALL), m_viewIni(this, IDC_VIEWINI), + m_iniName(this, IDC_ININAME), m_securityInfo(this, IDC_SECURITYINFO) +{ + m_szIniPath = szIniPath; + + m_noToAll.OnClick = Callback(this, &CInstallIniDlg::NoToAll_OnClick); + m_viewIni.OnClick = Callback(this, &CInstallIniDlg::ViewIni_OnClick); +} + +void CInstallIniDlg::OnInitDialog() +{ + m_iniName.SetText(m_szIniPath); + + wchar_t szSecurity[11]; + const wchar_t *pszSecurityInfo; + + GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini); + if (!mir_wstrcmpi(szSecurity, L"all")) + pszSecurityInfo = LPGENW("Security systems to prevent malicious changes are in place and you will be warned before every change that is made."); + else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe")) + pszSecurityInfo = LPGENW("Security systems to prevent malicious changes are in place and you will be warned before changes that are known to be unsafe."); + else if (!mir_wstrcmpi(szSecurity, L"none")) + pszSecurityInfo = LPGENW("Security systems to prevent malicious changes have been disabled. You will receive no further warnings."); + else pszSecurityInfo = NULL; + if (pszSecurityInfo) m_securityInfo.SetText(TranslateW(pszSecurityInfo)); +} + +void CInstallIniDlg::ViewIni_OnClick(CCtrlBase*) +{ + ptrW szPath(m_iniName.GetText()); + ShellExecute(m_hwnd, L"open", szPath, NULL, NULL, SW_SHOW); +} + +void CInstallIniDlg::NoToAll_OnClick(CCtrlBase*) +{ + Close(); +} + +////////////////////////////////////////////////////// + +static bool IsInSpaceSeparatedList(const char *szWord, const char *szList) +{ + const char *szItem, *szEnd; + size_t wordLen = mir_strlen(szWord); + + for (szItem = szList;;) { + szEnd = strchr(szItem, ' '); + if (szEnd == NULL) + return !mir_strcmp(szItem, szWord); + + if (size_t(szEnd - szItem) == wordLen) + if (!strncmp(szItem, szWord, wordLen)) + return true; + + szItem = szEnd + 1; + } +} + +struct warnSettingChangeInfo_t +{ + wchar_t *szIniPath; + char *szSection; + char *szSafeSections; + char *szUnsafeSections; + char *szName; + char *szValue; + int warnNoMore, cancel; +}; + +class CWarnIniChangeDlg : public CDlgBase +{ + warnSettingChangeInfo_t *m_warnInfo; + + CCtrlButton m_yes; + CCtrlButton m_no; + CCtrlButton m_cancel; + + CCtrlCheck m_noWarn; + + CCtrlBase m_iniName; + CCtrlBase m_settingName; + CCtrlBase m_securityInfo; + CCtrlBase m_newValue; + +protected: + void OnInitDialog(); + + void YesNo_OnClick(CCtrlBase*); + void Cancel_OnClick(CCtrlBase*); + +public: + CWarnIniChangeDlg(warnSettingChangeInfo_t *warnInfo); +}; + +CWarnIniChangeDlg::CWarnIniChangeDlg(warnSettingChangeInfo_t *warnInfo) + : CDlgBase(g_hInst, IDD_WARNINICHANGE), + m_yes(this, IDYES), m_no(this, IDNO), + m_cancel(this, IDCANCEL), m_noWarn(this, IDC_WARNNOMORE), + m_iniName(this, IDC_ININAME), m_settingName(this, IDC_SETTINGNAME), + m_newValue(this, IDC_NEWVALUE), m_securityInfo(this, IDC_SECURITYINFO) +{ + m_warnInfo = warnInfo; + + m_yes.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick); + m_no.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick); + m_cancel.OnClick = Callback(this, &CWarnIniChangeDlg::Cancel_OnClick); +} + +void CWarnIniChangeDlg::OnInitDialog() +{ + char szSettingName[256]; + const wchar_t *pszSecurityInfo; + m_iniName.SetText(m_warnInfo->szIniPath); + mir_strcpy(szSettingName, m_warnInfo->szSection); + mir_strcat(szSettingName, " / "); + mir_strcat(szSettingName, m_warnInfo->szName); + m_settingName.SetTextA(szSettingName); + m_newValue.SetTextA(m_warnInfo->szValue); + if (IsInSpaceSeparatedList(m_warnInfo->szSection, m_warnInfo->szSafeSections)) + pszSecurityInfo = LPGENW("This change is known to be safe."); + else if (IsInSpaceSeparatedList(m_warnInfo->szSection, m_warnInfo->szUnsafeSections)) + pszSecurityInfo = LPGENW("This change is known to be potentially hazardous."); + else + pszSecurityInfo = LPGENW("This change is not known to be safe."); + m_securityInfo.SetText(TranslateW(pszSecurityInfo)); +} + +void CWarnIniChangeDlg::YesNo_OnClick(CCtrlBase*) +{ + m_warnInfo->warnNoMore = m_noWarn.GetState(); + Close(); +} + +void CWarnIniChangeDlg::Cancel_OnClick(CCtrlBase*) +{ + m_warnInfo->cancel = 1; + m_warnInfo->warnNoMore = m_noWarn.GetState(); +} + +////////////////////////////////////////////////////// + +class CIniImportDoneDlg : public CDlgBase +{ + wchar_t *m_path; + + CCtrlButton m_delete; + CCtrlButton m_leave; + CCtrlButton m_recycle; + CCtrlButton m_move; + + CCtrlBase m_iniPath; + CCtrlEdit m_newPath; + +protected: + void OnInitDialog(); + + void Delete_OnClick(CCtrlBase*); + void Leave_OnClick(CCtrlBase*); + void Recycle_OnClick(CCtrlBase*); + void Move_OnClick(CCtrlBase*); + +public: + CIniImportDoneDlg(wchar_t *path); +}; + +void CIniImportDoneDlg::OnInitDialog() +{ + m_iniPath.SetText(m_path); + m_newPath.SetText(m_path); +} + +CIniImportDoneDlg::CIniImportDoneDlg(wchar_t *path) + : CDlgBase(g_hInst, IDD_INIIMPORTDONE), + m_delete(this, IDC_DELETE), m_leave(this, IDC_LEAVE), + m_recycle(this, IDC_RECYCLE), m_move(this, IDC_MOVE), + m_iniPath(this, IDC_ININAME), m_newPath(this, IDC_NEWNAME) +{ + m_path = path; +} +void CIniImportDoneDlg::Delete_OnClick(CCtrlBase*) +{ + ptrW szIniPath(m_iniPath.GetText()); + DeleteFile(szIniPath); + Close(); +} + +void CIniImportDoneDlg::Recycle_OnClick(CCtrlBase*) +{ + ptrW szIniPath(m_iniPath.GetText()); + SHFILEOPSTRUCT shfo = { 0 }; + shfo.wFunc = FO_DELETE; + shfo.pFrom = szIniPath; + szIniPath[mir_wstrlen(szIniPath) + 1] = '\0'; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; + SHFileOperation(&shfo); + Close(); +} + +void CIniImportDoneDlg::Move_OnClick(CCtrlBase*) +{ + ptrW szIniPath(m_iniPath.GetText()); + ptrW szNewPath(m_newPath.GetText()); + MoveFile(szIniPath, szNewPath); + Close(); +} + +void CIniImportDoneDlg::Leave_OnClick(CCtrlBase*) +{ + Close(); +} + +////////////////////////////////////////////////////// + +// settings: +struct SettingsList +{ + char *name; + SettingsList *next; +} *setting_items = NULL; + +int SettingsEnumProc(const char *szSetting, LPARAM) +{ + SettingsList *newItem = (SettingsList *)mir_alloc(sizeof(SettingsList)); + newItem->name = mir_strdup(szSetting); + newItem->next = setting_items; + setting_items = newItem; + return 0; +} + +static void ConvertBackslashes(char *str, UINT fileCp) +{ + char *pstr; + for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) { + if (*pstr == '\\') { + switch (pstr[1]) { + case 'n': *pstr = '\n'; break; + case 't': *pstr = '\t'; break; + case 'r': *pstr = '\r'; break; + default: *pstr = pstr[1]; break; + } + memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); + } + } +} + +struct ESFDParam +{ + LIST *pList; + const char *pMask; +}; + +static int EnumSettingsForDeletion(const char *szSetting, LPARAM param) +{ + ESFDParam *pParam = (ESFDParam*)param; + if (wildcmpi(szSetting, pParam->pMask)) + pParam->pList->insert(mir_strdup(szSetting)); + return 0; +} + +static void ProcessIniFile(wchar_t* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) +{ + FILE *fp = _wfopen(szIniPath, L"rt"); + if (fp == NULL) + return; + + bool warnThisSection = false; + char szSection[128]; szSection[0] = 0; + + while (!feof(fp)) { + char szLine[2048]; + if (fgets(szLine, sizeof(szLine), fp) == NULL) + break; +LBL_NewLine: + size_t lineLength = mir_strlen(szLine); + while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') + szLine[--lineLength] = '\0'; + + if (szLine[0] == ';' || szLine[0] <= ' ') + continue; + + if (szLine[0] == '[') { + char *szEnd = strchr(szLine + 1, ']'); + if (szEnd == NULL) + continue; + + if (szLine[1] == '!') + szSection[0] = '\0'; + else { + mir_strncpy(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); + switch (secur) { + case 0: + warnThisSection = false; + break; + + case 1: + warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); + break; + + case 2: + warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); + break; + + default: + warnThisSection = true; + break; + } + if (secFN) warnThisSection = 0; + } + if (szLine[1] == '?') { + mir_strncpy(szSection, szLine + 2, min(sizeof(szSection), (int)(szEnd - szLine - 1))); + db_enum_settings(NULL, SettingsEnumProc, szSection); + while (setting_items) { + SettingsList *next = setting_items->next; + + db_unset(NULL, szSection, setting_items->name); + + mir_free(setting_items->name); + mir_free(setting_items); + setting_items = next; + } + } + continue; + } + + if (szSection[0] == '\0') + continue; + + char *szValue = strchr(szLine, '='); + if (szValue == NULL) + continue; + + char szName[128]; + mir_strncpy(szName, szLine, min(sizeof(szName), (int)(szValue - szLine + 1))); + szValue++; + { + warnSettingChangeInfo_t warnInfo; + warnInfo.szIniPath = szIniPath; + warnInfo.szName = szName; + warnInfo.szSafeSections = szSafeSections; + warnInfo.szSection = szSection; + warnInfo.szUnsafeSections = szUnsafeSections; + warnInfo.szValue = szValue; + warnInfo.warnNoMore = 0; + warnInfo.cancel = 0; + CWarnIniChangeDlg dlg(&warnInfo); + if (warnThisSection && IDNO == dlg.DoModal()) + continue; + if (warnInfo.cancel) + break; + if (warnInfo.warnNoMore) + warnThisSection = 0; + } + + switch (szValue[0]) { + case 'b': + case 'B': + db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue + 1, NULL, 0)); + break; + case 'w': + case 'W': + db_set_w(NULL, szSection, szName, (WORD)strtol(szValue + 1, NULL, 0)); + break; + case 'd': + case 'D': + db_set_dw(NULL, szSection, szName, (DWORD)strtoul(szValue + 1, NULL, 0)); + break; + case 'l': + case 'L': + case '-': + if (szValue[1] == '*') { + LIST arSettings(1); + ESFDParam param = { &arSettings, szName }; + db_enum_settings(NULL, EnumSettingsForDeletion, szSection, ¶m); + + while (arSettings.getCount()) { + db_unset(NULL, szSection, arSettings[0]); + mir_free(arSettings[0]); + arSettings.remove(0); + } + } + db_unset(NULL, szSection, szName); + break; + case 'e': + case 'E': + ConvertBackslashes(szValue + 1, Langpack_GetDefaultCodePage()); + case 's': + case 'S': + db_set_s(NULL, szSection, szName, szValue + 1); + break; + case 'g': + case 'G': + for (char *pstr = szValue + 1; *pstr; pstr++) { + if (*pstr == '\\') { + switch (pstr[1]) { + case 'n': *pstr = '\n'; break; + case 't': *pstr = '\t'; break; + case 'r': *pstr = '\r'; break; + default: *pstr = pstr[1]; break; + } + memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); + } + } + case 'u': + case 'U': + db_set_utf(NULL, szSection, szName, szValue + 1); + break; + case 'm': + case 'M': + { + CMStringA memo(szValue + 1); + memo.Append("\r\n"); + while (fgets(szLine, sizeof(szLine), fp) != NULL) { + switch (szLine[0]) { + case 0: case '\r': case '\n': case ' ': case '\t': + break; + default: + db_set_utf(NULL, szSection, szName, memo); + goto LBL_NewLine; + } + + memo.Append(rtrim(szLine + 1)); + memo.Append("\r\n"); + } + db_set_utf(NULL, szSection, szName, memo); + } + break; + case 'n': + case 'h': + case 'N': + case 'H': + { + int len; + char *pszValue, *pszEnd; + + PBYTE buf = (PBYTE)mir_alloc(mir_strlen(szValue + 1)); + for (len = 0, pszValue = szValue + 1;; len++) { + buf[len] = (BYTE)strtol(pszValue, &pszEnd, 0x10); + if (pszValue == pszEnd) + break; + pszValue = pszEnd; + } + db_set_blob(NULL, szSection, szName, buf, len); + mir_free(buf); + } + break; + default: + wchar_t buf[250]; + mir_snwprintf(buf, TranslateT("Invalid setting type for '%s'. The first character of every value must be b, w, d, l, s, e, u, g, h or n."), _A2T(szName)); + MessageBox(NULL, buf, TranslateT("Install database settings"), MB_ICONWARNING | MB_OK); + break; + } + } + fclose(fp); +} + +static void DoAutoExec(void) +{ + wchar_t szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH]; + wchar_t buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH]; + + GetPrivateProfileString(L"AutoExec", L"Use", L"prompt", szUse, _countof(szUse), mirandabootini); + if (!mir_wstrcmpi(szUse, L"no")) return; + GetPrivateProfileString(L"AutoExec", L"Safe", L"CLC Icons CLUI CList SkinSounds", buf, _countof(buf), mirandabootini); + ptrA szSafeSections(mir_u2a(buf)); + GetPrivateProfileString(L"AutoExec", L"Unsafe", L"AIM Facebook GG ICQ IRC JABBER MRA MSN SKYPE Tlen TWITTER VKontakte XFire", buf, _countof(buf), mirandabootini); + ptrA szUnsafeSections(mir_u2a(buf)); + GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini); + + int secur = 0; + if (!mir_wstrcmpi(szSecurity, L"none")) secur = 0; + else if (!mir_wstrcmpi(szSecurity, L"notsafe")) secur = 1; + else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe")) secur = 2; + + GetPrivateProfileString(L"AutoExec", L"OverrideSecurityFilename", L"", szOverrideSecurityFilename, _countof(szOverrideSecurityFilename), mirandabootini); + GetPrivateProfileString(L"AutoExec", L"OnCreateFilename", L"", szOnCreateFilename, _countof(szOnCreateFilename), mirandabootini); + GetPrivateProfileString(L"AutoExec", L"Glob", L"autoexec_*.ini", szFindPath, _countof(szFindPath), mirandabootini); + + if (g_bDbCreated && szOnCreateFilename[0]) { + PathToAbsoluteW(VARSW(szOnCreateFilename), szIniPath); + ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1); + } + + PathToAbsoluteW(VARSW(szFindPath), szFindPath); + + WIN32_FIND_DATA fd; + HANDLE hFind = FindFirstFile(szFindPath, &fd); + if (hFind == INVALID_HANDLE_VALUE) + return; + + wchar_t *str2 = wcsrchr(szFindPath, '\\'); + if (str2 == NULL) + szFindPath[0] = 0; + else + str2[1] = 0; + + do { + bool secFN = mir_wstrcmpi(fd.cFileName, szOverrideSecurityFilename) == 0; + + mir_snwprintf(szIniPath, L"%s%s", szFindPath, fd.cFileName); + if (!mir_wstrcmpi(szUse, L"prompt") && !secFN) { + CInstallIniDlg dlg(szIniPath); + int result = dlg.DoModal(); + if (result == IDC_NOTOALL) break; + if (result == IDCANCEL) continue; + } + + ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, secur, secFN); + + if (secFN) + DeleteFile(szIniPath); + else { + wchar_t szOnCompletion[8]; + GetPrivateProfileString(L"AutoExec", L"OnCompletion", L"recycle", szOnCompletion, _countof(szOnCompletion), mirandabootini); + if (!mir_wstrcmpi(szOnCompletion, L"delete")) + DeleteFile(szIniPath); + else if (!mir_wstrcmpi(szOnCompletion, L"recycle")) { + SHFILEOPSTRUCT shfo = { 0 }; + shfo.wFunc = FO_DELETE; + shfo.pFrom = szIniPath; + szIniPath[mir_wstrlen(szIniPath) + 1] = 0; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; + SHFileOperation(&shfo); + } + else if (!mir_wstrcmpi(szOnCompletion, L"rename")) { + wchar_t szRenamePrefix[MAX_PATH], szNewPath[MAX_PATH]; + GetPrivateProfileString(L"AutoExec", L"RenamePrefix", L"done_", szRenamePrefix, _countof(szRenamePrefix), mirandabootini); + mir_wstrcpy(szNewPath, szFindPath); + mir_wstrcat(szNewPath, szRenamePrefix); + mir_wstrcat(szNewPath, fd.cFileName); + MoveFile(szIniPath, szNewPath); + } + else if (!mir_wstrcmpi(szOnCompletion, L"ask")) { + CIniImportDoneDlg dlg(szIniPath); + dlg.DoModal(); + } + } + } while (FindNextFile(hFind, &fd)); + + FindClose(hFind); +} + +static INT_PTR CheckIniImportNow(WPARAM, LPARAM) +{ + DoAutoExec(); + FindNextChangeNotification(hIniChangeNotification); + return 0; +} + +static INT_PTR ImportINI(WPARAM wParam, LPARAM) +{ + ptrW tszIniPath(mir_utf8decodeW((char*)wParam)); + ProcessIniFile(tszIniPath, "", "", 0, 0); + return 0; +} + +int InitIni(void) +{ + bModuleInitialized = true; + CreateServiceFunction("DB/Ini/ImportFile", ImportINI); + DoAutoExec(); + + wchar_t szMirandaDir[MAX_PATH]; + PathToAbsoluteW(L".", szMirandaDir); + hIniChangeNotification = FindFirstChangeNotification(szMirandaDir, 0, FILE_NOTIFY_CHANGE_FILE_NAME); + if (hIniChangeNotification != INVALID_HANDLE_VALUE) { + CreateServiceFunction("DB/Ini/CheckImportNow", CheckIniImportNow); + CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hIniChangeNotification, (LPARAM)"DB/Ini/CheckImportNow"); + } + return 0; +} + +void UninitIni(void) +{ + if (!bModuleInitialized) + return; + + CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0); + FindCloseChangeNotification(hIniChangeNotification); +} diff --git a/src/mir_app/src/db_intf.cpp b/src/mir_app/src/db_intf.cpp new file mode 100644 index 0000000000..eaab4d9e9b --- /dev/null +++ b/src/mir_app/src/db_intf.cpp @@ -0,0 +1,98 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-16 Miranda NG project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "database.h" + +/////////////////////////////////////////////////////////////////////////////// +// Database list + +LIST arDbPlugins(5); + +static INT_PTR srvRegisterPlugin(WPARAM, LPARAM lParam) +{ + DATABASELINK* pPlug = (DATABASELINK*)lParam; + if (pPlug == NULL) + return 1; + + arDbPlugins.insert(pPlug); + return 0; +} + +static INT_PTR srvFindPlugin(WPARAM, LPARAM lParam) +{ + for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { + int error = arDbPlugins[i]->grokHeader((wchar_t*)lParam); + if (error == ERROR_SUCCESS || error == EGROKPRF_OBSOLETE) + return (INT_PTR)arDbPlugins[i]; + } + + return NULL; +} + +static INT_PTR srvGetCurrentDb(WPARAM, LPARAM) +{ + return (INT_PTR)currDb; +} + +static INT_PTR srvInitInstance(WPARAM, LPARAM lParam) +{ + MIDatabase *pDb = (MIDatabase*)lParam; + if (pDb != NULL) + pDb->m_cache = new MDatabaseCache(pDb->GetContactSize()); + return 0; +} + +static INT_PTR srvDestroyInstance(WPARAM, LPARAM lParam) +{ + MIDatabase *pDb = (MIDatabase*)lParam; + if (pDb != NULL) { + MDatabaseCache *pCache = (MDatabaseCache*)pDb->m_cache; + pDb->m_cache = NULL; + delete pCache; + } + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +int LoadDbintfModule() +{ + CreateServiceFunction(MS_DB_REGISTER_PLUGIN, srvRegisterPlugin); + CreateServiceFunction(MS_DB_FIND_PLUGIN, srvFindPlugin); + CreateServiceFunction(MS_DB_GET_CURRENT, srvGetCurrentDb); + + CreateServiceFunction(MS_DB_INIT_INSTANCE, srvInitInstance); + CreateServiceFunction(MS_DB_DESTROY_INSTANCE, srvDestroyInstance); + + // create events once, they will be inherited by all database plugins + CreateHookableEvent(ME_DB_CONTACT_DELETED); + CreateHookableEvent(ME_DB_CONTACT_ADDED); + CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED); + CreateHookableEvent(ME_DB_EVENT_MARKED_READ); + + CreateHookableEvent(ME_DB_EVENT_ADDED); + CreateHookableEvent(ME_DB_EVENT_DELETED); + CreateHookableEvent(ME_DB_EVENT_FILTER_ADD); + return 0; +} diff --git a/src/mir_app/src/dbini.cpp b/src/mir_app/src/dbini.cpp deleted file mode 100644 index 8239b448e2..0000000000 --- a/src/mir_app/src/dbini.cpp +++ /dev/null @@ -1,640 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-16 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" -#include "profilemanager.h" - -static bool bModuleInitialized = false; -static HANDLE hIniChangeNotification; - -////////////////////////////////////////////////////// - -class CInstallIniDlg : public CDlgBase -{ - wchar_t *m_szIniPath; - - CCtrlButton m_viewIni; - CCtrlButton m_noToAll; - - CCtrlBase m_iniName; - CCtrlBase m_securityInfo; - -protected: - void OnInitDialog(); - - void ViewIni_OnClick(CCtrlBase*); - void NoToAll_OnClick(CCtrlBase*); - -public: - CInstallIniDlg(wchar_t *szIniPath); -}; - -CInstallIniDlg::CInstallIniDlg(wchar_t *szIniPath) - : CDlgBase(g_hInst, IDD_INSTALLINI), - m_noToAll(this, IDC_NOTOALL), m_viewIni(this, IDC_VIEWINI), - m_iniName(this, IDC_ININAME), m_securityInfo(this, IDC_SECURITYINFO) -{ - m_szIniPath = szIniPath; - - m_noToAll.OnClick = Callback(this, &CInstallIniDlg::NoToAll_OnClick); - m_viewIni.OnClick = Callback(this, &CInstallIniDlg::ViewIni_OnClick); -} - -void CInstallIniDlg::OnInitDialog() -{ - m_iniName.SetText(m_szIniPath); - - wchar_t szSecurity[11]; - const wchar_t *pszSecurityInfo; - - GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini); - if (!mir_wstrcmpi(szSecurity, L"all")) - pszSecurityInfo = LPGENW("Security systems to prevent malicious changes are in place and you will be warned before every change that is made."); - else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe")) - pszSecurityInfo = LPGENW("Security systems to prevent malicious changes are in place and you will be warned before changes that are known to be unsafe."); - else if (!mir_wstrcmpi(szSecurity, L"none")) - pszSecurityInfo = LPGENW("Security systems to prevent malicious changes have been disabled. You will receive no further warnings."); - else pszSecurityInfo = NULL; - if (pszSecurityInfo) m_securityInfo.SetText(TranslateW(pszSecurityInfo)); -} - -void CInstallIniDlg::ViewIni_OnClick(CCtrlBase*) -{ - ptrW szPath(m_iniName.GetText()); - ShellExecute(m_hwnd, L"open", szPath, NULL, NULL, SW_SHOW); -} - -void CInstallIniDlg::NoToAll_OnClick(CCtrlBase*) -{ - Close(); -} - -////////////////////////////////////////////////////// - -static bool IsInSpaceSeparatedList(const char *szWord, const char *szList) -{ - const char *szItem, *szEnd; - size_t wordLen = mir_strlen(szWord); - - for (szItem = szList;;) { - szEnd = strchr(szItem, ' '); - if (szEnd == NULL) - return !mir_strcmp(szItem, szWord); - - if (size_t(szEnd - szItem) == wordLen) - if (!strncmp(szItem, szWord, wordLen)) - return true; - - szItem = szEnd + 1; - } -} - -struct warnSettingChangeInfo_t -{ - wchar_t *szIniPath; - char *szSection; - char *szSafeSections; - char *szUnsafeSections; - char *szName; - char *szValue; - int warnNoMore, cancel; -}; - -class CWarnIniChangeDlg : public CDlgBase -{ - warnSettingChangeInfo_t *m_warnInfo; - - CCtrlButton m_yes; - CCtrlButton m_no; - CCtrlButton m_cancel; - - CCtrlCheck m_noWarn; - - CCtrlBase m_iniName; - CCtrlBase m_settingName; - CCtrlBase m_securityInfo; - CCtrlBase m_newValue; - -protected: - void OnInitDialog(); - - void YesNo_OnClick(CCtrlBase*); - void Cancel_OnClick(CCtrlBase*); - -public: - CWarnIniChangeDlg(warnSettingChangeInfo_t *warnInfo); -}; - -CWarnIniChangeDlg::CWarnIniChangeDlg(warnSettingChangeInfo_t *warnInfo) - : CDlgBase(g_hInst, IDD_WARNINICHANGE), - m_yes(this, IDYES), m_no(this, IDNO), - m_cancel(this, IDCANCEL), m_noWarn(this, IDC_WARNNOMORE), - m_iniName(this, IDC_ININAME), m_settingName(this, IDC_SETTINGNAME), - m_newValue(this, IDC_NEWVALUE), m_securityInfo(this, IDC_SECURITYINFO) -{ - m_warnInfo = warnInfo; - - m_yes.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick); - m_no.OnClick = Callback(this, &CWarnIniChangeDlg::YesNo_OnClick); - m_cancel.OnClick = Callback(this, &CWarnIniChangeDlg::Cancel_OnClick); -} - -void CWarnIniChangeDlg::OnInitDialog() -{ - char szSettingName[256]; - const wchar_t *pszSecurityInfo; - m_iniName.SetText(m_warnInfo->szIniPath); - mir_strcpy(szSettingName, m_warnInfo->szSection); - mir_strcat(szSettingName, " / "); - mir_strcat(szSettingName, m_warnInfo->szName); - m_settingName.SetTextA(szSettingName); - m_newValue.SetTextA(m_warnInfo->szValue); - if (IsInSpaceSeparatedList(m_warnInfo->szSection, m_warnInfo->szSafeSections)) - pszSecurityInfo = LPGENW("This change is known to be safe."); - else if (IsInSpaceSeparatedList(m_warnInfo->szSection, m_warnInfo->szUnsafeSections)) - pszSecurityInfo = LPGENW("This change is known to be potentially hazardous."); - else - pszSecurityInfo = LPGENW("This change is not known to be safe."); - m_securityInfo.SetText(TranslateW(pszSecurityInfo)); -} - -void CWarnIniChangeDlg::YesNo_OnClick(CCtrlBase*) -{ - m_warnInfo->warnNoMore = m_noWarn.GetState(); - Close(); -} - -void CWarnIniChangeDlg::Cancel_OnClick(CCtrlBase*) -{ - m_warnInfo->cancel = 1; - m_warnInfo->warnNoMore = m_noWarn.GetState(); -} - -////////////////////////////////////////////////////// - -class CIniImportDoneDlg : public CDlgBase -{ - wchar_t *m_path; - - CCtrlButton m_delete; - CCtrlButton m_leave; - CCtrlButton m_recycle; - CCtrlButton m_move; - - CCtrlBase m_iniPath; - CCtrlEdit m_newPath; - -protected: - void OnInitDialog(); - - void Delete_OnClick(CCtrlBase*); - void Leave_OnClick(CCtrlBase*); - void Recycle_OnClick(CCtrlBase*); - void Move_OnClick(CCtrlBase*); - -public: - CIniImportDoneDlg(wchar_t *path); -}; - -void CIniImportDoneDlg::OnInitDialog() -{ - m_iniPath.SetText(m_path); - m_newPath.SetText(m_path); -} - -CIniImportDoneDlg::CIniImportDoneDlg(wchar_t *path) - : CDlgBase(g_hInst, IDD_INIIMPORTDONE), - m_delete(this, IDC_DELETE), m_leave(this, IDC_LEAVE), - m_recycle(this, IDC_RECYCLE), m_move(this, IDC_MOVE), - m_iniPath(this, IDC_ININAME), m_newPath(this, IDC_NEWNAME) -{ - m_path = path; -} -void CIniImportDoneDlg::Delete_OnClick(CCtrlBase*) -{ - ptrW szIniPath(m_iniPath.GetText()); - DeleteFile(szIniPath); - Close(); -} - -void CIniImportDoneDlg::Recycle_OnClick(CCtrlBase*) -{ - ptrW szIniPath(m_iniPath.GetText()); - SHFILEOPSTRUCT shfo = { 0 }; - shfo.wFunc = FO_DELETE; - shfo.pFrom = szIniPath; - szIniPath[mir_wstrlen(szIniPath) + 1] = '\0'; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); - Close(); -} - -void CIniImportDoneDlg::Move_OnClick(CCtrlBase*) -{ - ptrW szIniPath(m_iniPath.GetText()); - ptrW szNewPath(m_newPath.GetText()); - MoveFile(szIniPath, szNewPath); - Close(); -} - -void CIniImportDoneDlg::Leave_OnClick(CCtrlBase*) -{ - Close(); -} - -////////////////////////////////////////////////////// - -// settings: -struct SettingsList -{ - char *name; - SettingsList *next; -} *setting_items = NULL; - -int SettingsEnumProc(const char *szSetting, LPARAM) -{ - SettingsList *newItem = (SettingsList *)mir_alloc(sizeof(SettingsList)); - newItem->name = mir_strdup(szSetting); - newItem->next = setting_items; - setting_items = newItem; - return 0; -} - -static void ConvertBackslashes(char *str, UINT fileCp) -{ - char *pstr; - for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) { - if (*pstr == '\\') { - switch (pstr[1]) { - case 'n': *pstr = '\n'; break; - case 't': *pstr = '\t'; break; - case 'r': *pstr = '\r'; break; - default: *pstr = pstr[1]; break; - } - memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); - } - } -} - -struct ESFDParam -{ - LIST *pList; - const char *pMask; -}; - -static int EnumSettingsForDeletion(const char *szSetting, LPARAM param) -{ - ESFDParam *pParam = (ESFDParam*)param; - if (wildcmpi(szSetting, pParam->pMask)) - pParam->pList->insert(mir_strdup(szSetting)); - return 0; -} - -static void ProcessIniFile(wchar_t* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) -{ - FILE *fp = _wfopen(szIniPath, L"rt"); - if (fp == NULL) - return; - - bool warnThisSection = false; - char szSection[128]; szSection[0] = 0; - - while (!feof(fp)) { - char szLine[2048]; - if (fgets(szLine, sizeof(szLine), fp) == NULL) - break; -LBL_NewLine: - size_t lineLength = mir_strlen(szLine); - while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') - szLine[--lineLength] = '\0'; - - if (szLine[0] == ';' || szLine[0] <= ' ') - continue; - - if (szLine[0] == '[') { - char *szEnd = strchr(szLine + 1, ']'); - if (szEnd == NULL) - continue; - - if (szLine[1] == '!') - szSection[0] = '\0'; - else { - mir_strncpy(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); - switch (secur) { - case 0: - warnThisSection = false; - break; - - case 1: - warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); - break; - - case 2: - warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); - break; - - default: - warnThisSection = true; - break; - } - if (secFN) warnThisSection = 0; - } - if (szLine[1] == '?') { - DBCONTACTENUMSETTINGS dbces; - dbces.pfnEnumProc = SettingsEnumProc; - mir_strncpy(szSection, szLine + 2, min(sizeof(szSection), (int)(szEnd - szLine - 1))); - dbces.szModule = szSection; - dbces.ofsSettings = 0; - CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces); - while (setting_items) { - SettingsList *next = setting_items->next; - - db_unset(NULL, szSection, setting_items->name); - - mir_free(setting_items->name); - mir_free(setting_items); - setting_items = next; - } - } - continue; - } - - if (szSection[0] == '\0') - continue; - - char *szValue = strchr(szLine, '='); - if (szValue == NULL) - continue; - - char szName[128]; - mir_strncpy(szName, szLine, min(sizeof(szName), (int)(szValue - szLine + 1))); - szValue++; - { - warnSettingChangeInfo_t warnInfo; - warnInfo.szIniPath = szIniPath; - warnInfo.szName = szName; - warnInfo.szSafeSections = szSafeSections; - warnInfo.szSection = szSection; - warnInfo.szUnsafeSections = szUnsafeSections; - warnInfo.szValue = szValue; - warnInfo.warnNoMore = 0; - warnInfo.cancel = 0; - CWarnIniChangeDlg dlg(&warnInfo); - if (warnThisSection && IDNO == dlg.DoModal()) - continue; - if (warnInfo.cancel) - break; - if (warnInfo.warnNoMore) - warnThisSection = 0; - } - - switch (szValue[0]) { - case 'b': - case 'B': - db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue + 1, NULL, 0)); - break; - case 'w': - case 'W': - db_set_w(NULL, szSection, szName, (WORD)strtol(szValue + 1, NULL, 0)); - break; - case 'd': - case 'D': - db_set_dw(NULL, szSection, szName, (DWORD)strtoul(szValue + 1, NULL, 0)); - break; - case 'l': - case 'L': - case '-': - if (szValue[1] == '*') { - LIST arSettings(1); - ESFDParam param = { &arSettings, szName }; - DBCONTACTENUMSETTINGS dbep = {}; - dbep.pfnEnumProc = EnumSettingsForDeletion; - dbep.szModule = szSection; - dbep.lParam = (LPARAM)¶m; - CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, LPARAM(&dbep)); - while (arSettings.getCount()) { - db_unset(NULL, szSection, arSettings[0]); - mir_free(arSettings[0]); - arSettings.remove(0); - } - } - db_unset(NULL, szSection, szName); - break; - case 'e': - case 'E': - ConvertBackslashes(szValue + 1, Langpack_GetDefaultCodePage()); - case 's': - case 'S': - db_set_s(NULL, szSection, szName, szValue + 1); - break; - case 'g': - case 'G': - for (char *pstr = szValue + 1; *pstr; pstr++) { - if (*pstr == '\\') { - switch (pstr[1]) { - case 'n': *pstr = '\n'; break; - case 't': *pstr = '\t'; break; - case 'r': *pstr = '\r'; break; - default: *pstr = pstr[1]; break; - } - memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); - } - } - case 'u': - case 'U': - db_set_utf(NULL, szSection, szName, szValue + 1); - break; - case 'm': - case 'M': - { - CMStringA memo(szValue + 1); - memo.Append("\r\n"); - while (fgets(szLine, sizeof(szLine), fp) != NULL) { - switch (szLine[0]) { - case 0: case '\r': case '\n': case ' ': case '\t': - break; - default: - db_set_utf(NULL, szSection, szName, memo); - goto LBL_NewLine; - } - - memo.Append(rtrim(szLine + 1)); - memo.Append("\r\n"); - } - db_set_utf(NULL, szSection, szName, memo); - } - break; - case 'n': - case 'h': - case 'N': - case 'H': - { - int len; - char *pszValue, *pszEnd; - - PBYTE buf = (PBYTE)mir_alloc(mir_strlen(szValue + 1)); - for (len = 0, pszValue = szValue + 1;; len++) { - buf[len] = (BYTE)strtol(pszValue, &pszEnd, 0x10); - if (pszValue == pszEnd) - break; - pszValue = pszEnd; - } - db_set_blob(NULL, szSection, szName, buf, len); - mir_free(buf); - } - break; - default: - wchar_t buf[250]; - mir_snwprintf(buf, TranslateT("Invalid setting type for '%s'. The first character of every value must be b, w, d, l, s, e, u, g, h or n."), _A2T(szName)); - MessageBox(NULL, buf, TranslateT("Install database settings"), MB_ICONWARNING | MB_OK); - break; - } - } - fclose(fp); -} - -static void DoAutoExec(void) -{ - wchar_t szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH]; - wchar_t buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH]; - - GetPrivateProfileString(L"AutoExec", L"Use", L"prompt", szUse, _countof(szUse), mirandabootini); - if (!mir_wstrcmpi(szUse, L"no")) return; - GetPrivateProfileString(L"AutoExec", L"Safe", L"CLC Icons CLUI CList SkinSounds", buf, _countof(buf), mirandabootini); - ptrA szSafeSections(mir_u2a(buf)); - GetPrivateProfileString(L"AutoExec", L"Unsafe", L"AIM Facebook GG ICQ IRC JABBER MRA MSN SKYPE Tlen TWITTER VKontakte XFire", buf, _countof(buf), mirandabootini); - ptrA szUnsafeSections(mir_u2a(buf)); - GetPrivateProfileString(L"AutoExec", L"Warn", L"notsafe", szSecurity, _countof(szSecurity), mirandabootini); - - int secur = 0; - if (!mir_wstrcmpi(szSecurity, L"none")) secur = 0; - else if (!mir_wstrcmpi(szSecurity, L"notsafe")) secur = 1; - else if (!mir_wstrcmpi(szSecurity, L"onlyunsafe")) secur = 2; - - GetPrivateProfileString(L"AutoExec", L"OverrideSecurityFilename", L"", szOverrideSecurityFilename, _countof(szOverrideSecurityFilename), mirandabootini); - GetPrivateProfileString(L"AutoExec", L"OnCreateFilename", L"", szOnCreateFilename, _countof(szOnCreateFilename), mirandabootini); - GetPrivateProfileString(L"AutoExec", L"Glob", L"autoexec_*.ini", szFindPath, _countof(szFindPath), mirandabootini); - - if (g_bDbCreated && szOnCreateFilename[0]) { - PathToAbsoluteW(VARSW(szOnCreateFilename), szIniPath); - ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1); - } - - PathToAbsoluteW(VARSW(szFindPath), szFindPath); - - WIN32_FIND_DATA fd; - HANDLE hFind = FindFirstFile(szFindPath, &fd); - if (hFind == INVALID_HANDLE_VALUE) - return; - - wchar_t *str2 = wcsrchr(szFindPath, '\\'); - if (str2 == NULL) - szFindPath[0] = 0; - else - str2[1] = 0; - - do { - bool secFN = mir_wstrcmpi(fd.cFileName, szOverrideSecurityFilename) == 0; - - mir_snwprintf(szIniPath, L"%s%s", szFindPath, fd.cFileName); - if (!mir_wstrcmpi(szUse, L"prompt") && !secFN) { - CInstallIniDlg dlg(szIniPath); - int result = dlg.DoModal(); - if (result == IDC_NOTOALL) break; - if (result == IDCANCEL) continue; - } - - ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, secur, secFN); - - if (secFN) - DeleteFile(szIniPath); - else { - wchar_t szOnCompletion[8]; - GetPrivateProfileString(L"AutoExec", L"OnCompletion", L"recycle", szOnCompletion, _countof(szOnCompletion), mirandabootini); - if (!mir_wstrcmpi(szOnCompletion, L"delete")) - DeleteFile(szIniPath); - else if (!mir_wstrcmpi(szOnCompletion, L"recycle")) { - SHFILEOPSTRUCT shfo = { 0 }; - shfo.wFunc = FO_DELETE; - shfo.pFrom = szIniPath; - szIniPath[mir_wstrlen(szIniPath) + 1] = 0; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); - } - else if (!mir_wstrcmpi(szOnCompletion, L"rename")) { - wchar_t szRenamePrefix[MAX_PATH], szNewPath[MAX_PATH]; - GetPrivateProfileString(L"AutoExec", L"RenamePrefix", L"done_", szRenamePrefix, _countof(szRenamePrefix), mirandabootini); - mir_wstrcpy(szNewPath, szFindPath); - mir_wstrcat(szNewPath, szRenamePrefix); - mir_wstrcat(szNewPath, fd.cFileName); - MoveFile(szIniPath, szNewPath); - } - else if (!mir_wstrcmpi(szOnCompletion, L"ask")) { - CIniImportDoneDlg dlg(szIniPath); - dlg.DoModal(); - } - } - } while (FindNextFile(hFind, &fd)); - - FindClose(hFind); -} - -static INT_PTR CheckIniImportNow(WPARAM, LPARAM) -{ - DoAutoExec(); - FindNextChangeNotification(hIniChangeNotification); - return 0; -} - -static INT_PTR ImportINI(WPARAM wParam, LPARAM) -{ - ptrW tszIniPath(mir_utf8decodeW((char*)wParam)); - ProcessIniFile(tszIniPath, "", "", 0, 0); - return 0; -} - -int InitIni(void) -{ - bModuleInitialized = true; - CreateServiceFunction("DB/Ini/ImportFile", ImportINI); - DoAutoExec(); - - wchar_t szMirandaDir[MAX_PATH]; - PathToAbsoluteW(L".", szMirandaDir); - hIniChangeNotification = FindFirstChangeNotification(szMirandaDir, 0, FILE_NOTIFY_CHANGE_FILE_NAME); - if (hIniChangeNotification != INVALID_HANDLE_VALUE) { - CreateServiceFunction("DB/Ini/CheckImportNow", CheckIniImportNow); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hIniChangeNotification, (LPARAM)"DB/Ini/CheckImportNow"); - } - return 0; -} - -void UninitIni(void) -{ - if (!bModuleInitialized) - return; - - CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0); - FindCloseChangeNotification(hIniChangeNotification); -} diff --git a/src/mir_app/src/dbintf.cpp b/src/mir_app/src/dbintf.cpp deleted file mode 100644 index ffa510f9e9..0000000000 --- a/src/mir_app/src/dbintf.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (C) 2012-16 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" -#include "database.h" - -MIDatabase *currDb = NULL; -DATABASELINK *currDblink = NULL; - -MIR_CORE_DLL(void) db_setCurrent(MIDatabase*); - -static INT_PTR srvSetSafetyMode(WPARAM wParam, LPARAM) -{ - if (!currDb) return 1; - - currDb->SetCacheSafetyMode(wParam != 0); - return 0; -} - -static INT_PTR srvGetContactCount(WPARAM, LPARAM) -{ - return (currDb) ? currDb->GetContactCount() : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Contacts - -static INT_PTR srvDeleteContact(WPARAM wParam, LPARAM) -{ - DBVARIANT dbv = { 0 }; - if (!db_get_ws(wParam, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.ptszVal); - db_free(&dbv); - } - return (currDb) ? currDb->DeleteContact(wParam) : 0; -} - -static INT_PTR srvAddContact(WPARAM, LPARAM) -{ - MCONTACT hNew = (currDb) ? currDb->AddContact() : 0; - Netlib_Logf(NULL, "New contact created: %d", hNew); - return hNew; -} - -static INT_PTR srvIsDbContact(WPARAM wParam, LPARAM) -{ - return (currDb) ? currDb->IsDbContact(wParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Module chain - -static INT_PTR srvEnumModuleNames(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumModuleNames((DBMODULEENUMPROC)lParam, (void*)wParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Settings - -static INT_PTR srvEnumContactSettings(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumContactSettings(wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0; -} - -static INT_PTR srvEnumResidentSettings(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumResidentSettings((DBMODULEENUMPROC)wParam, (void*)lParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Database list - -LIST arDbPlugins(5); - -static INT_PTR srvRegisterPlugin(WPARAM, LPARAM lParam) -{ - DATABASELINK* pPlug = (DATABASELINK*)lParam; - if (pPlug == NULL) - return 1; - - arDbPlugins.insert(pPlug); - return 0; -} - -static INT_PTR srvFindPlugin(WPARAM, LPARAM lParam) -{ - for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { - int error = arDbPlugins[i]->grokHeader((wchar_t*)lParam); - if (error == ERROR_SUCCESS || error == EGROKPRF_OBSOLETE) - return (INT_PTR)arDbPlugins[i]; - } - - return NULL; -} - -static INT_PTR srvGetCurrentDb(WPARAM, LPARAM) -{ - return (INT_PTR)currDb; -} - -static INT_PTR srvInitInstance(WPARAM, LPARAM lParam) -{ - MIDatabase* pDb = (MIDatabase*)lParam; - if (pDb != NULL) - pDb->m_cache = new MDatabaseCache(pDb->GetContactSize()); - return 0; -} - -static INT_PTR srvDestroyInstance(WPARAM, LPARAM lParam) -{ - MIDatabase* pDb = (MIDatabase*)lParam; - if (pDb != NULL) { - MDatabaseCache *pCache = (MDatabaseCache*)pDb->m_cache; - pDb->m_cache = NULL; - delete pCache; - } - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -int LoadDbintfModule() -{ - CreateServiceFunction(MS_DB_CONTACT_GETCOUNT, srvGetContactCount); - CreateServiceFunction(MS_DB_CONTACT_DELETE, srvDeleteContact); - CreateServiceFunction(MS_DB_CONTACT_ADD, srvAddContact); - CreateServiceFunction(MS_DB_CONTACT_IS, srvIsDbContact); - - CreateServiceFunction(MS_DB_MODULES_ENUM, srvEnumModuleNames); - - CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS, srvEnumContactSettings); - CreateServiceFunction("DB/ResidentSettings/Enum", srvEnumResidentSettings); - - CreateServiceFunction(MS_DB_REGISTER_PLUGIN, srvRegisterPlugin); - CreateServiceFunction(MS_DB_FIND_PLUGIN, srvFindPlugin); - CreateServiceFunction(MS_DB_GET_CURRENT, srvGetCurrentDb); - - CreateServiceFunction(MS_DB_INIT_INSTANCE, srvInitInstance); - CreateServiceFunction(MS_DB_DESTROY_INSTANCE, srvDestroyInstance); - return 0; -} - -void LoadDatabaseServices() -{ - CreateServiceFunction(MS_DB_SETSAFETYMODE, srvSetSafetyMode); -} diff --git a/src/mir_app/src/dbutils.cpp b/src/mir_app/src/dbutils.cpp deleted file mode 100644 index 155851a2e5..0000000000 --- a/src/mir_app/src/dbutils.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-16 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" -#include "profilemanager.h" - -static int CompareEventTypes(const DBEVENTTYPEDESCR *p1, const DBEVENTTYPEDESCR *p2) -{ - int result = mir_strcmp(p1->module, p2->module); - if (result) - return result; - - return p1->eventType - p2->eventType; -} - -static LIST eventTypes(10, CompareEventTypes); - -void UnloadEventsModule() -{ - for (int i = 0; i < eventTypes.getCount(); i++) { - DBEVENTTYPEDESCR *p = eventTypes[i]; - mir_free(p->module); - mir_free(p->descr); - mir_free(p->textService); - mir_free(p->iconService); - mir_free(p); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(int) DbEvent_RegisterType(DBEVENTTYPEDESCR *et) -{ - if (et == NULL || et->cbSize != sizeof(DBEVENTTYPEDESCR)) - return -1; - - if (eventTypes.getIndex(et) != -1) - return -1; - - DBEVENTTYPEDESCR *p = (DBEVENTTYPEDESCR*)mir_calloc(sizeof(DBEVENTTYPEDESCR)); - p->cbSize = sizeof(DBEVENTTYPEDESCR); - p->module = mir_strdup(et->module); - p->eventType = et->eventType; - p->descr = mir_strdup(et->descr); - if (et->textService) - p->textService = mir_strdup(et->textService); - if (et->iconService) - p->iconService = mir_strdup(et->iconService); - p->eventIcon = et->eventIcon; - p->flags = et->flags; - - if (!p->textService) { - char szServiceName[100]; - mir_snprintf(szServiceName, "%s/GetEventText%d", p->module, p->eventType); - p->textService = mir_strdup(szServiceName); - } - if (!p->iconService) { - char szServiceName[100]; - mir_snprintf(szServiceName, "%s/GetEventIcon%d", p->module, p->eventType); - p->iconService = mir_strdup(szServiceName); - } - eventTypes.insert(p); - return 0; -} - -MIR_APP_DLL(DBEVENTTYPEDESCR*) DbEvent_GetType(const char *szModule, int eventType) -{ - DBEVENTTYPEDESCR tmp; - tmp.module = (char*)szModule; - tmp.eventType = eventType; - return eventTypes.find(&tmp); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static wchar_t* getEventString(DBEVENTINFO *dbei, LPSTR &buf) -{ - LPSTR in = buf; - buf += mir_strlen(buf) + 1; - return (dbei->flags & DBEF_UTF) ? Utf8DecodeT(in) : mir_a2u(in); -} - -static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatype) -{ - if (dbei == NULL || dbei->szModule == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) - return 0; - - DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType); - if (et && ServiceExists(et->textService)) - return CallService(et->textService, (WPARAM)dbei, datatype); - - if (!dbei->pBlob) - return 0; - - if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) { - // EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - // EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - DWORD uin = *(DWORD*)dbei->pBlob; - MCONTACT hContact = (MCONTACT)*(DWORD*)(dbei->pBlob + sizeof(DWORD)); - char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2; - ptrW tszNick(getEventString(dbei, buf)); - ptrW tszFirst(getEventString(dbei, buf)); - ptrW tszLast(getEventString(dbei, buf)); - ptrW tszEmail(getEventString(dbei, buf)); - - CMStringW nick, text; - if (tszFirst || tszLast) { - nick.AppendFormat(L"%s %s", tszFirst, tszLast); - nick.Trim(); - } - if (tszEmail) { - if (!nick.IsEmpty()) - nick.Append(L", "); - nick.Append(tszEmail); - } - if (uin != 0) { - if (!nick.IsEmpty()) - nick.Append(L", "); - nick.AppendFormat(L"%d", uin); - } - if (!nick.IsEmpty()) - nick = L"(" + nick + L")"; - - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { - ptrW tszReason(getEventString(dbei, buf)); - text.Format(TranslateT("Authorization request from %s%s: %s"), - (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason); - } - else text.Format(TranslateT("You were added by %s%s"), - (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick); - return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text); - } - - if (dbei->eventType == EVENTTYPE_CONTACTS) { - CMStringW text(TranslateT("Contacts: ")); - // blob is: [uin(ASCIIZ), nick(ASCIIZ)]* - char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob; - while (buf < limit) { - ptrW tszUin(getEventString(dbei, buf)); - ptrW tszNick(getEventString(dbei, buf)); - if (tszNick && *tszNick) - text.AppendFormat(L"\"%s\" ", tszNick); - if (tszUin && *tszUin) - text.AppendFormat(L"<%s>; ", tszUin); - } - return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text); - } - - if (dbei->eventType == EVENTTYPE_FILE) { - char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD); - ptrW tszFileName(getEventString(dbei, buf)); - ptrW tszDescription(getEventString(dbei, buf)); - ptrW &ptszText = (mir_wstrlen(tszDescription) == 0) ? tszFileName : tszDescription; - switch (datatype) { - case DBVT_WCHAR: - return (INT_PTR)ptszText.detach(); - case DBVT_ASCIIZ: - return (INT_PTR)mir_u2a(ptszText); - } - return 0; - } - - // by default treat an event's blob as a string - if (datatype == DBVT_WCHAR) { - char *str = (char*)alloca(dbei->cbBlob + 1); - memcpy(str, dbei->pBlob, dbei->cbBlob); - str[dbei->cbBlob] = 0; - - if (dbei->flags & DBEF_UTF) { - WCHAR *msg = NULL; - Utf8DecodeCP(str, codepage, &msg); - if (msg) - return (INT_PTR)msg; - } - - return (INT_PTR)mir_a2u_cp(str, codepage); - } - - if (datatype == DBVT_ASCIIZ) { - char *msg = mir_strdup((char*)dbei->pBlob); - if (dbei->flags & DBEF_UTF) - Utf8DecodeCP(msg, codepage, NULL); - - return (INT_PTR)msg; - } - return 0; -} - -MIR_APP_DLL(char*) DbEvent_GetTextA(DBEVENTINFO *dbei, int codepage) -{ - return (char*)DbEventGetTextWorker(dbei, codepage, DBVT_ASCIIZ); -} - -MIR_APP_DLL(wchar_t*) DbEvent_GetTextW(DBEVENTINFO *dbei, int codepage) -{ - return (wchar_t*)DbEventGetTextWorker(dbei, codepage, DBVT_WCHAR); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(HICON) DbEvent_GetIcon(DBEVENTINFO *dbei, int flags) -{ - DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType); - if (et && ServiceExists(et->iconService)) { - HICON icon = (HICON)CallService(et->iconService, (WPARAM)dbei, flags); - if (icon) - return icon; - } - - HICON icon = NULL; - if (et && et->eventIcon) - icon = IcoLib_GetIconByHandle(et->eventIcon); - if (!icon) { - char szName[100]; - mir_snprintf(szName, "eventicon_%s%d", dbei->szModule, dbei->eventType); - icon = IcoLib_GetIcon(szName); - } - - if (!icon) { - switch(dbei->eventType) { - case EVENTTYPE_URL: - icon = Skin_LoadIcon(SKINICON_EVENT_URL); - break; - - case EVENTTYPE_FILE: - icon = Skin_LoadIcon(SKINICON_EVENT_FILE); - break; - - default: // EVENTTYPE_MESSAGE and unknown types - icon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); - break; - } - } - - return (flags & LR_SHARED) ? icon : CopyIcon(icon); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(wchar_t*) DbEvent_GetString(DBEVENTINFO *dbei, const char *str) -{ - if (dbei->flags & DBEF_UTF) - return Utf8DecodeW(str); - - return mir_a2u(str); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static int sttEnumVars(const char *szVarName, LPARAM lParam) -{ - LIST* vars = (LIST*)lParam; - vars->insert(mir_strdup(szVarName)); - return 0; -} - -MIR_APP_DLL(int) DbModule_Delete(MCONTACT hContact, const char *szModuleName) -{ - LIST vars(20); - - DBCONTACTENUMSETTINGS dbces = { 0 }; - dbces.pfnEnumProc = sttEnumVars; - dbces.lParam = (LPARAM)&vars; - dbces.szModule = (char*)szModuleName; - CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces); - - for (int i = vars.getCount()-1; i >= 0; i--) { - db_unset(hContact, szModuleName, vars[i]); - mir_free(vars[i]); - } - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(int) Profile_GetPathA(size_t cbLen, char *pszDest) -{ - if (!pszDest || !cbLen) - return 1; - - strncpy_s(pszDest, cbLen, _T2A(g_profileDir), _TRUNCATE); - return 0; -} - -MIR_APP_DLL(int) Profile_GetPathW(size_t cbLen, wchar_t *pwszDest) -{ - if (!pwszDest || !cbLen) - return 1; - - wcsncpy_s(pwszDest, cbLen, g_profileDir, _TRUNCATE); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(int) Profile_GetNameA(size_t cbLen, char *pszDest) -{ - if (!cbLen || !pszDest) - return 1; - - strncpy_s(pszDest, cbLen, ptrA(makeFileName(g_profileName)), _TRUNCATE); - return 0; -} - -MIR_APP_DLL(int) Profile_GetNameW(size_t cbLen, wchar_t *pwszDest) -{ - if (!cbLen || !pwszDest) - return 1; - - wcsncpy_s(pwszDest, cbLen, g_profileName, _TRUNCATE); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -MIR_APP_DLL(void) Profile_SetDefault(const wchar_t *pwszPath) -{ - extern wchar_t* g_defaultProfile; - replaceStrW(g_defaultProfile, pwszPath); -} diff --git a/src/mir_app/src/ignore.cpp b/src/mir_app/src/ignore.cpp index 4ea32d150c..3a5baf7905 100644 --- a/src/mir_app/src/ignore.cpp +++ b/src/mir_app/src/ignore.cpp @@ -409,7 +409,7 @@ static int IgnoreAddedNotify(WPARAM, LPARAM lParam) DBEVENTINFO *dbei = (DBEVENTINFO*)lParam; if (dbei && dbei->eventType == EVENTTYPE_ADDED && dbei->pBlob != NULL) { MCONTACT hContact = DbGetAuthEventContact(dbei); - if (CallService(MS_DB_CONTACT_IS, hContact, 0) && IsIgnored(hContact, IGNOREEVENT_YOUWEREADDED)) + if (db_is_contact(hContact) && IsIgnored(hContact, IGNOREEVENT_YOUWEREADDED)) return 1; } return 0; diff --git a/src/mir_app/src/menu_options.cpp b/src/mir_app/src/menu_options.cpp index 5a9a88b60c..7863b338c0 100644 --- a/src/mir_app/src/menu_options.cpp +++ b/src/mir_app/src/menu_options.cpp @@ -130,7 +130,7 @@ class CGenMenuOptionsPage : public CDlgBase char szModule[256]; mir_snprintf(szModule, "%s_Items", pmo->pszName); - DbModule_Delete(NULL, szModule); + db_delete_module(NULL, szModule); SaveTreeInternal(NULL, m_menuItems.GetRoot(), szModule); db_set_b(NULL, szModule, "MenuFormat", 1); } diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index c714f06418..2b2f07e35d 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -935,7 +935,7 @@ static INT_PTR sttUpdateMenuService(WPARAM wParam, LPARAM) MO_RecursiveWalkMenu(pmo->m_items.first, sttReadOldItem, szModule); // wipe out old trash, write new data & compatibility flag - DbModule_Delete(NULL, szModule); + db_delete_module(NULL, szModule); db_set_b(NULL, szModule, "MenuFormat", true); MO_RecursiveWalkMenu(pmo->m_items.first, sttDumpItem, szModule); } diff --git a/src/mir_app/src/meta_menu.cpp b/src/mir_app/src/meta_menu.cpp index cac1b4bdb2..674b55a9cd 100644 --- a/src/mir_app/src/meta_menu.cpp +++ b/src/mir_app/src/meta_menu.cpp @@ -52,7 +52,7 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM) ptrW tszGroup(db_get_wsa(wParam, "CList", "Group")); // Create a new metacontact - MCONTACT hMetaContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); + MCONTACT hMetaContact = db_add_contact(); if (hMetaContact == NULL) return NULL; @@ -73,7 +73,7 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM) // Assign the contact to the MetaContact just created (and make default). if (!Meta_Assign(wParam, hMetaContact, TRUE)) { MessageBox(0, TranslateT("There was a problem in assigning the contact to the metacontact"), TranslateT("Error"), MB_ICONEXCLAMATION); - CallService(MS_DB_CONTACT_DELETE, hMetaContact, 0); + db_delete_contact(hMetaContact); return 0; } @@ -200,7 +200,7 @@ INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion) Meta_RemoveContactNumber(cc, i, false); NotifyEventHooks(hSubcontactsChanged, hContact, 0); - CallService(MS_DB_CONTACT_DELETE, hContact, 0); + db_delete_contact(hContact); } else if (cc->IsSub()) { if ((cc = currDb->m_cache->GetCachedContact(cc->parentID)) == NULL) diff --git a/src/mir_app/src/meta_services.cpp b/src/mir_app/src/meta_services.cpp index 7a862f79df..37b23f355c 100644 --- a/src/mir_app/src/meta_services.cpp +++ b/src/mir_app/src/meta_services.cpp @@ -473,7 +473,7 @@ int Meta_ContactDeleted(WPARAM hContact, LPARAM) // no more subs? remove the meta itself if (ccMeta->nSubs == 0) - CallService(MS_DB_CONTACT_DELETE, ccMeta->contactID, 0); + db_delete_contact(ccMeta->contactID); } return 0; } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index dfc1f380b4..d4755280f1 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -286,9 +286,9 @@ DbEvent_GetTextA @285 DbEvent_GetTextW @286 DbEvent_GetType @287 DbEvent_RegisterType @288 -DbModule_Delete @289 Profile_GetNameA @290 Profile_GetNameW @291 Profile_GetPathA @292 Profile_GetPathW @293 Profile_SetDefault @294 +DbModule_Delete @295 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 309b40d02d..db6e5def22 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -286,7 +286,6 @@ DbEvent_GetTextA @285 DbEvent_GetTextW @286 DbEvent_GetType @287 DbEvent_RegisterType @288 -DbModule_Delete @289 Profile_GetNameA @290 Profile_GetNameW @291 Profile_GetPathA @292 diff --git a/src/mir_app/src/options_ei.cpp b/src/mir_app/src/options_ei.cpp index d38dc19f6a..f9e11d7268 100644 --- a/src/mir_app/src/options_ei.cpp +++ b/src/mir_app/src/options_ei.cpp @@ -372,7 +372,7 @@ public: db_set_w(NULL, MODULE_NAME, setting, extra->getSlot()); } - DbModule_Delete(NULL, MODULE_NAME "Groups"); + db_delete_module(NULL, MODULE_NAME "Groups"); db_set_w(NULL, MODULE_NAME "Groups", "Count", groups.getCount()); for (int k = 0; k < groups.getCount(); k++) { ExtraIconGroup *group = groups[k]; diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp index 5c8edc3d13..d6d5e7ec68 100644 --- a/src/mir_app/src/proto_accs.cpp +++ b/src/mir_app/src/proto_accs.cpp @@ -114,7 +114,7 @@ void LoadDbAccounts(void) WriteDbAccounts(); int anum = accounts.getCount(); - CallService(MS_DB_MODULES_ENUM, 0, (LPARAM)EnumDbModules); + db_enum_modules(EnumDbModules); if (anum != accounts.getCount()) WriteDbAccounts(); } @@ -144,13 +144,7 @@ void WriteDbAccounts() { // enum all old settings to delete enumDB_ProtoProcParam param = { 0, NULL }; - - DBCONTACTENUMSETTINGS dbces; - dbces.pfnEnumProc = enumDB_ProtoProc; - dbces.szModule = "Protocols"; - dbces.ofsSettings = 0; - dbces.lParam = (LPARAM)¶m; - CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces); + db_enum_settings(NULL, enumDB_ProtoProc, "Protocols", ¶m); // delete all settings if (param.arrlen) { @@ -383,12 +377,12 @@ void EraseAccount(const char *pszModuleName) // remove protocol contacts first for (MCONTACT hContact = db_find_first(pszModuleName); hContact != NULL;) { MCONTACT hNext = db_find_next(hContact, pszModuleName); - CallService(MS_DB_CONTACT_DELETE, hContact, 0); + db_delete_contact(hContact); hContact = hNext; } // remove all protocol settings - DbModule_Delete(NULL, pszModuleName); + db_delete_module(NULL, pszModuleName); } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3