From 7f35b5c32df443cf13dbb476c641e01f30db1d6c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 Jan 2014 15:19:47 +0000 Subject: encrypted settings are not displayed in dbeditor git-svn-id: http://svn.miranda-ng.org/main/trunk@7631 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/DbEditorPP/src/main.cpp | 224 ++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 121 deletions(-) (limited to 'plugins/DbEditorPP/src/main.cpp') diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp index c74fa638cb..642f73bb4d 100644 --- a/plugins/DbEditorPP/src/main.cpp +++ b/plugins/DbEditorPP/src/main.cpp @@ -2,6 +2,7 @@ HINSTANCE hInst = NULL; +MIDatabase *g_db; HANDLE hTTBButt = NULL; BOOL bServiceMode = FALSE; BOOL usePopups; @@ -17,7 +18,9 @@ HANDLE hModulesLoadedHook = NULL, hSettingsChangedHook=NULL, hOptInitHook=NULL, //======================== // MirandaPluginInfo //======================== -PLUGININFOEX pluginInfoEx={ + +PLUGININFOEX pluginInfoEx = +{ sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -55,25 +58,20 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam; HANDLE hContact = (HANDLE)wParam; char *setting; - int i; SettingListInfo* info; - if (hwnd2mainWindow) - { + if (hwnd2mainWindow) { HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS); - if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings,GWLP_USERDATA)) - { - if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) - { + if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA)) { + if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) { setting = mir_strdup(cws->szSetting); - if (cws->value.type == DBVT_DELETED) - { + if (cws->value.type == DBVT_DELETED) { LVFINDINFO lvfi; int index; lvfi.flags = LVFI_STRING; lvfi.psz = setting; lvfi.vkDirection = VK_DOWN; - index = ListView_FindItem(hwnd2Settings,-1,&lvfi); + index = ListView_FindItem(hwnd2Settings, -1, &lvfi); if (index > -1) ListView_DeleteItem(hwnd2Settings, index); mir_free(setting); @@ -84,17 +82,15 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) } } } + // watch list - if (!hwnd2watchedVarsWindow && !usePopups) return 0; + if (!hwnd2watchedVarsWindow && !usePopups) + return 0; - for (i=0; iszModule, WatchListArray.item[i].module)) - { - if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) - { + for (int i = 0; i < WatchListArray.count; i++) { + if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) { + if (!mir_strcmp(cws->szModule, WatchListArray.item[i].module)) { + if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) { if (usePopups) popupWatchedVar(hContact, cws->szModule, cws->szSetting); if (hwnd2watchedVarsWindow) @@ -109,15 +105,12 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam) INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM lParam) { - - if (!hwnd2mainWindow) // so only opens 1 at a time - { + if (!hwnd2mainWindow) { // so only opens 1 at a time hRestore = (HANDLE)wParam; SetCursor(LoadCursor(NULL,IDC_WAIT)); CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc); } - else - { + else { ShowWindow(hwnd2mainWindow, SW_RESTORE); SetForegroundWindow(hwnd2mainWindow); if (!hRestore && wParam) { @@ -135,7 +128,6 @@ INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM lParam) BOOL IsCP_UTF8(void) { CPINFO CPInfo; - return GetCPInfo(CP_UTF8, &CPInfo); } @@ -167,7 +159,7 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) ZeroMemory(&mi, sizeof(mi)); mi.cbSize = sizeof(mi); mi.position = 1900000001; - mi.flags = db_get_b(NULL,modname,"UserMenuItem",0) ? 0 : CMIF_HIDDEN; + mi.flags = db_get_b(NULL, modname, "UserMenuItem", 0) ? 0 : CMIF_HIDDEN; mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGUSER)); mi.pszName = LPGEN("Open user tree in DBE++"); mi.pszService = "DBEditorpp/MenuCommand"; @@ -179,7 +171,7 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) hkd.pszService = "DBEditorpp/MenuCommand"; hkd.ptszDescription = LPGEN("Open Database Editor"); hkd.ptszSection = modFullname; - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT|HOTKEYF_EXT, 'D'); + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_EXT, 'D'); Hotkey_Register(&hkd); // icons @@ -189,27 +181,27 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam) UnhookEvent(hModulesLoadedHook); - usePopups = db_get_b(NULL,modname,"UsePopUps",0); + usePopups = db_get_b(NULL, modname, "UsePopUps", 0); // Load the name order - for(int i=0; i < NAMEORDERCOUNT; i++) + for (int i = 0; i < NAMEORDERCOUNT; i++) nameOrder[i] = i; DBVARIANT dbv; - if (!db_get(NULL,"Contact","NameOrder",&dbv)) { - CopyMemory(nameOrder,dbv.pbVal,dbv.cpbVal); + if (!db_get(NULL, "Contact", "NameOrder", &dbv)) { + CopyMemory(nameOrder, dbv.pbVal, dbv.cpbVal); db_free(&dbv); } HookEvent(ME_TTB_MODULELOADED, OnTTBLoaded); - if ( bServiceMode ) - CallService("DBEditorpp/MenuCommand",0,0); + if (bServiceMode) + CallService("DBEditorpp/MenuCommand", 0, 0); return 0; } -int PreShutdown(WPARAM wParam,LPARAM lParam) +int PreShutdown(WPARAM wParam, LPARAM lParam) { if (hwnd2watchedVarsWindow) DestroyWindow(hwnd2watchedVarsWindow); if (hwnd2mainWindow) DestroyWindow(hwnd2mainWindow); @@ -225,13 +217,13 @@ int PreShutdown(WPARAM wParam,LPARAM lParam) return 0; } -INT_PTR ServiceMode(WPARAM wParam,LPARAM lParam) +INT_PTR ServiceMode(WPARAM wParam, LPARAM lParam) { bServiceMode = TRUE; return SERVICE_ONLYDB; // load database and then call us } -INT_PTR ImportFromFile(WPARAM wParam,LPARAM lParam) +INT_PTR ImportFromFile(WPARAM wParam, LPARAM lParam) { ImportSettingsFromFileMenuItem((HANDLE)wParam, (char*)lParam); return 0; @@ -241,23 +233,24 @@ extern "C" __declspec(dllexport) int Load(void) { mir_getLP(&pluginInfoEx); - hwnd2mainWindow = 0; - hwnd2watchedVarsWindow = 0; - hwnd2importWindow = 0; + hwnd2mainWindow = hwnd2watchedVarsWindow = hwnd2importWindow = 0; hRestore = NULL; - hSettingsChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED,DBSettingChanged); - hOptInitHook = HookEvent(ME_OPT_INITIALISE,OptInit); + g_db = GetCurrentDatabase(); + + hSettingsChangedHook = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged); + hOptInitHook = HookEvent(ME_OPT_INITIALISE, OptInit); hPreShutdownHook = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); - hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded); + hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + sMenuCommand = CreateServiceFunction("DBEditorpp/MenuCommand", DBEditorppMenuCommand); sImport = CreateServiceFunction("DBEditorpp/Import", ImportFromFile); - + sServicemodeLaunch = CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode); // Ensure that the common control DLL is loaded. INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); - icex.dwICC = ICC_LISTVIEW_CLASSES; + icex.dwICC = ICC_LISTVIEW_CLASSES; InitCommonControlsEx(&icex); ZeroMemory(&WatchListArray, sizeof(WatchListArray)); @@ -270,23 +263,19 @@ extern "C" __declspec(dllexport) int Unload(void) return 0; } - - //======================================================= -//db_get_s (prob shouldnt use this unless u know how big the string is gonna be..) +// db_get_s (prob shouldnt use this unless u know how big the string is gonna be..) //======================================================= int DBGetContactSettingStringStatic(HANDLE hContact, char* szModule, char* szSetting, char* value, int maxLength) { DBVARIANT dbv; - if (!db_get(hContact, szModule, szSetting, &dbv)) - { + if (!db_get(hContact, szModule, szSetting, &dbv)) { strncpy(value, dbv.pszVal, maxLength); db_free(&dbv); return 1; } - else - { + else { db_free(&dbv); return 0; } @@ -301,22 +290,19 @@ int WriteBlobFromString(HANDLE hContact,const char *szModule,const char *szSetti BYTE b; int tmp; - if (!(data = (BYTE *)_alloca(2+len/2))) - { + if (!(data = (BYTE *)_alloca(2 + len / 2))) { msg(Translate("Couldn't allocate enough memory!"), modFullname); return 0; } - while(j='0' && b<='9') || - (b>='A' && b<='F') || - (b>='a' && b<='f')) + if ((b >= '0' && b <= '9') || + (b >= 'A' && b <= 'F') || + (b >= 'a' && b <= 'f')) { - if (sscanf(&szValue[j], "%02X", &tmp) == 1) - { + if (sscanf(&szValue[j], "%02X", &tmp) == 1) { data[i++] = (BYTE)tmp; j++; } @@ -325,12 +311,11 @@ int WriteBlobFromString(HANDLE hContact,const char *szModule,const char *szSetti } if (i) - return db_set_blob(hContact,szModule,szSetting, data, (WORD)i); + return db_set_blob(hContact, szModule, szSetting, data, (WORD)i); return 0; } - int GetSetting(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) { return db_get_s(hContact, szModule, szSetting, dbv, 0); @@ -341,22 +326,22 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* DBVARIANT dbv = {0}; if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) { - switch(dbv.type) { + switch (dbv.type) { case DBVT_ASCIIZ: strncpy(Value, dbv.pszVal, length); break; case DBVT_DWORD: - _itoa(dbv.dVal,Value,10); + _itoa(dbv.dVal, Value, 10); break; case DBVT_BYTE: - _itoa(dbv.bVal,Value,10); + _itoa(dbv.bVal, Value, 10); break; case DBVT_WORD: - _itoa(dbv.wVal,Value,10); + _itoa(dbv.wVal, Value, 10); break; case DBVT_UTF8: - int len = (int)strlen(dbv.pszVal)+1; - char *sz = (char*)_alloca(len*3); + int len = (int)strlen(dbv.pszVal) + 1; + char *sz = (char*)_alloca(len * 3); WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); WideCharToMultiByte(CP_ACP, 0, wc, -1, sz, len, NULL, NULL); @@ -366,7 +351,7 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* db_free(&dbv); - Value[length-1] = 0; + Value[length - 1] = 0; return 1; } @@ -376,47 +361,44 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* return 0; } - int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHAR* Value, int length) { - DBVARIANT dbv ={0}; + DBVARIANT dbv = { 0 }; + WCHAR *wc; + int len; if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) { - switch(dbv.type) { + switch (dbv.type) { case DBVT_UTF8: - { - int len = (int)strlen(dbv.pszVal) + 1; - WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); - wcsncpy((WCHAR*)Value, wc, length); - } + len = (int)strlen(dbv.pszVal) + 1; + wc = (WCHAR*)_alloca(length*sizeof(WCHAR)); + MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len); + wcsncpy((WCHAR*)Value, wc, length); break; case DBVT_ASCIIZ: - { - int len = (int)strlen(dbv.pszVal) + 1; - WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len); - wcsncpy((WCHAR*)Value, wc, length); - } + len = (int)strlen(dbv.pszVal) + 1; + wc = (WCHAR*)_alloca(len*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len); + wcsncpy((WCHAR*)Value, wc, length); break; case DBVT_DWORD: - _itow(dbv.dVal,Value,10); + _itow(dbv.dVal, Value, 10); break; case DBVT_BYTE: - _itow(dbv.bVal,Value,10); + _itow(dbv.bVal, Value, 10); break; case DBVT_WORD: - _itow(dbv.wVal,Value,10); + _itow(dbv.wVal, Value, 10); break; } db_free(&dbv); - Value[length-1] = 0; + Value[length - 1] = 0; return 1; } @@ -426,29 +408,29 @@ int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHA return 0; } -char *u2a( wchar_t* src ) +char* u2a(wchar_t *src) { - if (!src) - return NULL; + if (!src) + return NULL; - int cbLen = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL ); - char* result = (char*)mir_calloc((cbLen+1)*sizeof(char)); - if ( result == NULL ) + int cbLen = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL); + char* result = (char*)mir_calloc((cbLen + 1)*sizeof(char)); + if (result == NULL) return NULL; - WideCharToMultiByte( CP_ACP, 0, src, -1, result, cbLen, NULL, NULL ); - result[ cbLen ] = 0; + WideCharToMultiByte(CP_ACP, 0, src, -1, result, cbLen, NULL, NULL); + result[cbLen] = 0; return result; } -wchar_t *a2u( char* src , wchar_t *buffer, int len ) +wchar_t* a2u(char* src, wchar_t *buffer, int len) { wchar_t *result = buffer; - if ( result == NULL || len < 3) + if (result == NULL || len < 3) return NULL; - MultiByteToWideChar( CP_ACP, 0, src, -1, result, len - 1 ); - result[ len - 1 ] = 0; + MultiByteToWideChar(CP_ACP, 0, src, -1, result, len - 1); + result[len - 1] = 0; return result; } @@ -461,7 +443,7 @@ int GetDatabaseString(HANDLE hContact, const char *szModule, const char* szSetti return GetValue(hContact, szModule, szSetting, (char*)Value, length); } -WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) +WCHAR* GetContactName(HANDLE hContact, const char *szProto, int unicode) { int i, r = 0; static WCHAR res[512]; @@ -469,46 +451,45 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) char name[256]; if (hContact && !proto) - if (GetValue(hContact,"Protocol","p",name,SIZEOF(name))) - proto = name; + if (GetValue(hContact, "Protocol", "p", name, SIZEOF(name))) + proto = name; if (proto) { - for(i=0; i < NAMEORDERCOUNT-1; i++) { - switch(nameOrder[i]) { + for (i = 0; i < NAMEORDERCOUNT - 1; i++) { + switch (nameOrder[i]) { case 0: // custom name - r = GetDatabaseString(hContact,"CList","MyHandle",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, "CList", "MyHandle", res, SIZEOF(res), unicode); break; case 1: // nick - r = GetDatabaseString(hContact,proto,"Nick",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "Nick", res, SIZEOF(res), unicode); break; case 2: // First Name - r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode); break; case 3: // E-mail - r = GetDatabaseString(hContact,proto,"e-mail",res,SIZEOF(res),unicode); + r = GetDatabaseString(hContact, proto, "e-mail", res, SIZEOF(res), unicode); break; case 4: // Last Name - if (GetDatabaseString(hContact,proto,"LastName",res,SIZEOF(res),unicode)) + if (GetDatabaseString(hContact, proto, "LastName", res, SIZEOF(res), unicode)) break; case 5: // Unique id { // protocol must define a PFLAG_UNIQUEIDSETTING - char *uid = (char*)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); + char *uid = (char*)CallProtoService(proto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) - r = GetDatabaseString(hContact,proto,uid,res,SIZEOF(res),unicode); - break; + r = GetDatabaseString(hContact, proto, uid, res, SIZEOF(res), unicode); } + break; case 6: // first + last name { int len = 0; - if (r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode)) - { + if (r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode)) { if (unicode) len = (int)wcslen(res); else @@ -519,21 +500,22 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode) if (len && len < SIZEOF(res) - 2) { if (unicode) - wcscat(res,L" "); + wcscat(res, L" "); else - strcat((char*)res," "); + strcat((char*)res, " "); len++; } - if (SIZEOF(res)-len > 1) - r |= GetDatabaseString(hContact,proto,"LastName",&res[len],SIZEOF(res)-len,unicode); + if (SIZEOF(res) - len > 1) + r |= GetDatabaseString(hContact, proto, "LastName", &res[len], SIZEOF(res) - len, unicode); break; } } - if (r) return res; + if (r) + return res; } } -- cgit v1.2.3