static TlenProtocol *tlenProtoInit( const char* pszProtoName, const TCHAR* tszUserName ) { DBVARIANT dbv; char text[_MAX_PATH]; TlenProtocol *proto = (TlenProtocol *)mir_alloc(sizeof(TlenProtocol)); memset(proto, 0, sizeof(TlenProtocol)); proto->iface.m_tszUserName = mir_tstrdup( tszUserName ); proto->iface.m_szModuleName = mir_strdup(pszProtoName); proto->iface.m_szProtoName = mir_strdup(pszProtoName); _strlwr( proto->iface.m_szProtoName ); proto->iface.m_szProtoName[0] = toupper( proto->iface.m_szProtoName[0] ); proto->iface.m_iStatus = ID_STATUS_OFFLINE; TlenInitServicesVTbl(proto); InitializeCriticalSection(&proto->modeMsgMutex); InitializeCriticalSection(&proto->csSend); sprintf(text, "%s/%s", proto->iface.m_szModuleName, "Nudge"); proto->hTlenNudge = CreateHookableEvent(text); HookEventObj_Ex(ME_SYSTEM_MODULESLOADED, proto, TlenSystemModulesLoaded); HookEventObj_Ex(ME_OPT_INITIALISE, proto, TlenOptionsInit); HookEventObj_Ex(ME_DB_CONTACT_SETTINGCHANGED, proto, JabberDbSettingChanged); HookEventObj_Ex(ME_DB_CONTACT_DELETED, proto, JabberContactDeleted); HookEventObj_Ex(ME_CLIST_PREBUILDCONTACTMENU, proto, TlenPrebuildContactMenu); // HookEventObj_Ex(ME_SKIN2_ICONSCHANGED, proto, TlenIconsChanged); HookEventObj_Ex(ME_SYSTEM_PRESHUTDOWN, proto, TlenPreShutdown); if (!DBGetContactSetting(NULL, proto->iface.m_szModuleName, "LoginServer", &dbv)) { DBFreeVariant(&dbv); } else { DBWriteContactSettingString(NULL, proto->iface.m_szModuleName, "LoginServer", "tlen.pl"); } if (!DBGetContactSetting(NULL, proto->iface.m_szModuleName, "ManualHost", &dbv)) { DBFreeVariant(&dbv); } else { DBWriteContactSettingString(NULL, proto->iface.m_szModuleName, "ManualHost", "s1.tlen.pl"); } TlenLoadOptions(proto); JabberWsInit(proto); JabberSerialInit(proto); JabberIqInit(proto); JabberListInit(proto); return proto; }
int __declspec(dllexport) Load(PLUGINLINK *link) { PROTOCOLDESCRIPTOR pd; HANDLE hContact; char s[256]; char text[_MAX_PATH]; char *p, *q; char *szProto; CLISTMENUITEM mi, clmi; DBVARIANT dbv; pluginLink = link; memoryManagerInterface.cbSize = sizeof(struct MM_INTERFACE); CallService(MS_SYSTEM_GET_MMI,0,(LPARAM)&memoryManagerInterface); GetModuleFileName(hInst, text, sizeof(text)); p = strrchr(text, '\\'); p++; q = strrchr(p, '.'); *q = '\0'; jabberProtoName = mir_strdup(p); _strupr(jabberProtoName); jabberModuleName = mir_strdup(jabberProtoName); _strlwr(jabberModuleName); jabberModuleName[0] = toupper(jabberModuleName[0]); JabberLog("Setting protocol/module name to '%s/%s'", jabberProtoName, jabberModuleName); DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, THREAD_SET_CONTEXT, FALSE, 0); jabberMainThreadId = GetCurrentThreadId(); //hLibSSL = NULL; // hWndListGcLog = (HANDLE) CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); TlenRegisterIcons(); TlenLoadOptions(); HookEvent_Ex(ME_OPT_INITIALISE, TlenOptInit); HookEvent_Ex(ME_SYSTEM_MODULESLOADED, ModulesLoaded); HookEvent_Ex(ME_SYSTEM_PRESHUTDOWN, PreShutdown); sprintf(s, "%s/%s", jabberProtoName, "Nudge"); hTlenNudge = CreateHookableEvent(s); // Register protocol module ZeroMemory(&pd, sizeof(PROTOCOLDESCRIPTOR)); pd.cbSize = sizeof(PROTOCOLDESCRIPTOR); pd.szName = jabberProtoName; pd.type = PROTOTYPE_PROTOCOL; CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM) &pd); memset(&mi, 0, sizeof(CLISTMENUITEM)); mi.cbSize = sizeof(CLISTMENUITEM); memset(&clmi, 0, sizeof(CLISTMENUITEM)); clmi.cbSize = sizeof(CLISTMENUITEM); clmi.flags = CMIM_FLAGS | CMIF_GRAYED; mi.pszPopupName = jabberModuleName; mi.popupPosition = 500090000; wsprintf(text, "%s/MainMenuChats", jabberModuleName); CreateServiceFunction_Ex(text, TlenMUCMenuHandleChats); mi.pszName = TranslateT("Tlen Chats"); mi.position = 2000050001; mi.hIcon = tlenIcons[TLEN_IDI_CHATS]; mi.pszService = text; hMenuChats = (HANDLE) CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM) &mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM) hMenuChats, (LPARAM) &clmi); // "Multi-User Conference" wsprintf(text, "%s/MainMenuMUC", jabberModuleName); CreateServiceFunction_Ex(text, TlenMUCMenuHandleMUC); mi.pszName = TranslateT("Multi-User Conference"); mi.position = 2000050002; mi.hIcon = tlenIcons[TLEN_IDI_MUC]; mi.pszService = text; hMenuMUC = (HANDLE) CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM) &mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM) hMenuMUC, (LPARAM) &clmi); wsprintf(text, "%s/MainMenuInbox", jabberModuleName); CreateServiceFunction_Ex(text, TlenMenuHandleInbox); mi.pszName = TranslateT("Tlen Inbox"); mi.position = 2000050003; mi.hIcon = tlenIcons[TLEN_IDI_MAIL]; mi.pszService = text; hMenuInbox = (HANDLE) CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM) &mi); // "Invite to MUC" sprintf(text, "%s/ContactMenuMUC", jabberModuleName); CreateServiceFunction_Ex(text, TlenMUCContactMenuHandleMUC); mi.pszName = TranslateT("Multi-User Conference"); mi.position = -2000020000; mi.hIcon = tlenIcons[TLEN_IDI_MUC]; mi.pszService = text; mi.pszContactOwner = jabberProtoName; hMenuContactMUC = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); // "Invite to voice chat" sprintf(text, "%s/ContactMenuVoice", jabberModuleName); CreateServiceFunction_Ex(text, TlenVoiceContactMenuHandleVoice); mi.pszName = TranslateT("Voice Chat"); mi.position = -2000018000; mi.hIcon = tlenIcons[TLEN_IDI_VOICE]; mi.pszService = text; mi.pszContactOwner = jabberProtoName; hMenuContactVoice = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); // "Request authorization" sprintf(text, "%s/RequestAuth", jabberModuleName); CreateServiceFunction_Ex(text, TlenContactMenuHandleRequestAuth); mi.pszName = TranslateT("Request authorization"); mi.position = -2000001001; mi.hIcon = tlenIcons[TLEN_IDI_REQUEST]; mi.pszService = text; mi.pszContactOwner = jabberProtoName; hMenuContactRequestAuth = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); // "Grant authorization" sprintf(text, "%s/GrantAuth", jabberModuleName); CreateServiceFunction_Ex(text, TlenContactMenuHandleGrantAuth); mi.pszName = TranslateT("Grant authorization"); mi.position = -2000001000; mi.hIcon = tlenIcons[TLEN_IDI_GRANT]; mi.pszService = text; mi.pszContactOwner = jabberProtoName; hMenuContactGrantAuth = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); // "Send picture" sprintf(text, "%s/SendPicture", jabberModuleName); CreateServiceFunction_Ex(text, TlenContactMenuHandleSendPicture); mi.pszName = TranslateT("Send picture"); // clmi.flags = CMIM_FLAGS | CMIF_NOTOFFLINE;// | CMIF_GRAYED; mi.position = -2000001002; mi.hIcon = tlenIcons[TLEN_IDI_GRANT]; mi.pszService = text; mi.pszContactOwner = jabberProtoName; //CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); //hMenuContactGrantAuth = (HANDLE) mi.position = -2000020000; mi.flags = CMIF_NOTONLINE; mi.hIcon = LoadSkinnedIcon(SKINICON_EVENT_FILE); mi.pszName = TranslateT("&File"); mi.pszService = MS_FILE_SENDFILE; mi.pszContactOwner = jabberProtoName; hMenuContactFile = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) &mi); HookEvent_Ex(ME_CLIST_PREBUILDCONTACTMENU, TlenPrebuildContactMenu); if (!DBGetContactSetting(NULL, jabberProtoName, "LoginServer", &dbv)) { DBFreeVariant(&dbv); } else { DBWriteContactSettingString(NULL, jabberProtoName, "LoginServer", "tlen.pl"); } if (!DBGetContactSetting(NULL, jabberProtoName, "ManualHost", &dbv)) { DBFreeVariant(&dbv); } else { DBWriteContactSettingString(NULL, jabberProtoName, "ManualHost", "s1.tlen.pl"); } // Set all contacts to offline hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while (hContact != NULL) { szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if(szProto!=NULL && !strcmp(szProto, jabberProtoName)) { if (DBGetContactSettingWord(hContact, jabberProtoName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) { DBWriteContactSettingWord(hContact, jabberProtoName, "Status", ID_STATUS_OFFLINE); } } hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); } streamId = NULL; jabberThreadInfo = NULL; jabberConnected = FALSE; jabberOnline = FALSE; jabberStatus = ID_STATUS_OFFLINE; memset((char *) &modeMsgs, 0, sizeof(JABBER_MODEMSGS)); //jabberModeMsg = NULL; jabberCodePage = CP_ACP; InitializeCriticalSection(&mutex); InitializeCriticalSection(&modeMsgMutex); srand((unsigned) time(NULL)); JabberSerialInit(); JabberIqInit(); JabberListInit(); JabberSvcInit(); return 0; }
static void ApplyChanges(TlenProtocol *proto, int i) { changed &= ~i; if (changed == 0) { TlenLoadOptions(proto); } }
INT_PTR CALLBACK TlenAccMgrUIDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { char text[256]; TlenProtocol *proto = (TlenProtocol *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: { DBVARIANT dbv; proto = (TlenProtocol *)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)proto); TranslateDialogDefault(hwndDlg); if (!db_get_ts(NULL, proto->m_szModuleName, "LoginName", &dbv)) { SetDlgItemText(hwndDlg, IDC_EDIT_USERNAME, dbv.ptszVal); db_free(&dbv); } if (!db_get(NULL, proto->m_szModuleName, "Password", &dbv)) { SetDlgItemTextA(hwndDlg, IDC_EDIT_PASSWORD, dbv.pszVal); db_free(&dbv); } CheckDlgButton(hwndDlg, IDC_SAVEPASSWORD, db_get_b(NULL, proto->m_szModuleName, "SavePassword", TRUE)); mir_subclassWindow(GetDlgItem(hwndDlg, IDC_EDIT_USERNAME), TlenValidateUsernameWndProc); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_EDIT_USERNAME: case IDC_EDIT_PASSWORD: if ((HWND)lParam == GetFocus() && HIWORD(wParam) == EN_CHANGE) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_SAVEPASSWORD: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_REGISTERACCOUNT: CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) TLEN_REGISTER); break; } break; case WM_NOTIFY: switch (((LPNMHDR) lParam)->code) { case PSN_APPLY: { BOOL reconnectRequired = FALSE; DBVARIANT dbv; GetDlgItemTextA(hwndDlg, IDC_EDIT_USERNAME, text, sizeof(text)); if (db_get(NULL, proto->m_szModuleName, "LoginName", &dbv) || strcmp(text, dbv.pszVal)) reconnectRequired = TRUE; if (dbv.pszVal != NULL) db_free(&dbv); db_set_s(NULL, proto->m_szModuleName, "LoginName", strlwr(text)); if (IsDlgButtonChecked(hwndDlg, IDC_SAVEPASSWORD)) { GetDlgItemTextA(hwndDlg, IDC_EDIT_PASSWORD, text, sizeof(text)); if (db_get(NULL, proto->m_szModuleName, "Password", &dbv) || strcmp(text, dbv.pszVal)) reconnectRequired = TRUE; if (dbv.pszVal != NULL) db_free(&dbv); db_set_s(NULL, proto->m_szModuleName, "Password", text); } else db_unset(NULL, proto->m_szModuleName, "Password"); db_set_b(NULL, proto->m_szModuleName, "SavePassword", (BYTE) IsDlgButtonChecked(hwndDlg, IDC_SAVEPASSWORD)); if (reconnectRequired && proto->isConnected) MessageBox(hwndDlg, TranslateT("These changes will take effect the next time you connect to the Tlen network."), TranslateT("Tlen Protocol Option"), MB_OK|MB_SETFOREGROUND); TlenLoadOptions(proto); return TRUE; } } break; } return FALSE; }