From 35489ce3659220b4ebd25d1b3ab0258115cf10a4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 16 Aug 2013 14:34:41 +0000 Subject: Tlen: - custom base64 removed; - strict prototype verification git-svn-id: http://svn.miranda-ng.org/main/trunk@5719 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tlen/src/jabber.h | 46 +++-- protocols/Tlen/src/jabber_opt.cpp | 14 +- protocols/Tlen/src/jabber_svc.cpp | 316 ++++++++++++++------------------ protocols/Tlen/src/jabber_util.cpp | 137 -------------- protocols/Tlen/src/tlen.cpp | 208 ++++++++++----------- protocols/Tlen/src/tlen_muc.cpp | 342 ++++++++++++++++------------------- protocols/Tlen/src/tlen_muc.h | 3 - protocols/Tlen/src/tlen_userinfo.cpp | 27 ++- protocols/Tlen/src/tlen_voice.cpp | 17 +- protocols/Tlen/src/tlen_voice.h | 19 +- 10 files changed, 455 insertions(+), 674 deletions(-) (limited to 'protocols/Tlen/src') diff --git a/protocols/Tlen/src/jabber.h b/protocols/Tlen/src/jabber.h index deab57ac51..e8cd777b74 100644 --- a/protocols/Tlen/src/jabber.h +++ b/protocols/Tlen/src/jabber.h @@ -266,10 +266,42 @@ struct TlenProtocol : public PROTO virtual int __cdecl OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam); + //==================================================================================== + // Services + + INT_PTR __cdecl GetName(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl GetAvatarInfo(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl SendAlert(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl GetAvatarCaps(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl SetMyAvatar(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl GetMyAvatar(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl GetStatus(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl AccMgrUI(WPARAM wParam, LPARAM lParam); + + INT_PTR __cdecl MUCMenuHandleChats(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl MUCMenuHandleMUC(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl MenuHandleInbox(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl ContactMenuHandleSendPicture(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl MUCContactMenuHandleMUC(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl VoiceContactMenuHandleVoice(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl ContactMenuHandleRequestAuth(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl ContactMenuHandleGrantAuth(WPARAM wParam, LPARAM lParam); + + //==================================================================================== + // Events + int __cdecl OnModulesLoaded(WPARAM wParam, LPARAM lParam); + int __cdecl OptionsInit(WPARAM wParam, LPARAM lParam); + int __cdecl JabberDbSettingChanged(WPARAM wParam, LPARAM lParam); + int __cdecl JabberContactDeleted(WPARAM wParam, LPARAM lParam); + int __cdecl PrebuildContactMenu(WPARAM wParam, LPARAM lParam); + int __cdecl PreShutdown(WPARAM wParam, LPARAM lParam); + int __cdecl UserInfoInit(WPARAM wParam, LPARAM lParam); + int __cdecl MUCHandleEvent(WPARAM wParam, LPARAM lParam); + //==================================================================================== HANDLE hNetlibUser; HANDLE hFileNetlibUser; @@ -286,12 +318,6 @@ struct TlenProtocol : public PROTO HGENMENU hMenuContactRequestAuth; HGENMENU hMenuPicture; - HANDLE* hServices; - unsigned serviceNum; - HANDLE* hHooks; - unsigned hookNum; - - int listsCount; struct JABBER_LIST_ITEM_STRUCT *lists; CRITICAL_SECTION csLists; @@ -308,6 +334,7 @@ struct TlenProtocol : public PROTO CRITICAL_SECTION modeMsgMutex; + void initMenuItems(); HGENMENU hMenuRoot; char *searchJID; @@ -438,11 +465,8 @@ int JabberWsSend(TlenProtocol *proto, JABBER_SOCKET s, char *data, int datalen); int JabberWsRecv(TlenProtocol *proto, JABBER_SOCKET s, char *data, long datalen); int JabberWsSendAES(TlenProtocol *proto, char *data, int datalen, aes_context *aes_ctx, unsigned char *aes_iv); int JabberWsRecvAES(TlenProtocol *proto, char *data, long datalen, aes_context *aes_ctx, unsigned char *aes_iv); + // jabber_util.cpp -HANDLE HookEventObj_Ex(const char *name, TlenProtocol *proto, MIRANDAHOOKOBJ hook); -HANDLE CreateServiceFunction_Ex(const char *name, TlenProtocol *proto, MIRANDASERVICEOBJ service); -void UnhookEvents_Ex(TlenProtocol *proto); -void DestroyServices_Ex(TlenProtocol *proto); void JabberSerialInit(TlenProtocol *proto); void JabberSerialUninit(TlenProtocol *proto); unsigned int JabberSerialNext(TlenProtocol *proto); @@ -462,8 +486,6 @@ void TlenUrlDecode(char *str); char *TlenUrlEncode(const char *str); char *JabberTextEncode(const char *str); char *JabberTextDecode(const char *str); -char *JabberBase64Encode(const char *buffer, int bufferLen); -char *JabberBase64Decode(const char *buffer, int *resultLen); void TlenLogMessage(TlenProtocol *proto, HANDLE hContact, DWORD flags, const char *message); BOOL IsAuthorized(TlenProtocol *proto, const char *jid); //char *JabberGetVersionText(); diff --git a/protocols/Tlen/src/jabber_opt.cpp b/protocols/Tlen/src/jabber_opt.cpp index ccdb6369d9..f73ac40f68 100644 --- a/protocols/Tlen/src/jabber_opt.cpp +++ b/protocols/Tlen/src/jabber_opt.cpp @@ -82,19 +82,15 @@ static void MarkChanges(int i, HWND hWnd) { } -int TlenOptionsInit(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::OptionsInit(WPARAM wParam, LPARAM lParam) { - int i; - TlenProtocol *proto = (TlenProtocol *)ptr; - - OPTIONSDIALOGPAGE odp = { 0 }; - odp.cbSize = sizeof(odp); + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.hInstance = hInst; odp.ptszGroup = LPGENT("Network"); - odp.ptszTitle = proto->m_tszUserName; + odp.ptszTitle = m_tszUserName; odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; - odp.dwInitParam = (LPARAM)proto; - for (i = 0; i < SIZEOF(tabPages); i++) { + odp.dwInitParam = (LPARAM)this; + for (int i = 0; i < SIZEOF(tabPages); i++) { odp.pszTemplate = MAKEINTRESOURCEA(tabPages[i].dlgId); odp.pfnDlgProc = tabPages[i].dlgProc; odp.ptszTab = tabPages[i].tabName; diff --git a/protocols/Tlen/src/jabber_svc.cpp b/protocols/Tlen/src/jabber_svc.cpp index 9f8110f01d..56df40f443 100644 --- a/protocols/Tlen/src/jabber_svc.cpp +++ b/protocols/Tlen/src/jabber_svc.cpp @@ -33,13 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "tlen_avatar.h" #include "tlen_file.h" -extern int TlenOnModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam); -extern int TlenOptionsInit(void *ptr, WPARAM wParam, LPARAM lParam); -extern int TlenPreShutdown(void *ptr, WPARAM wParam, LPARAM lParam); -extern int TlenSystemModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam); -extern int TlenPrebuildContactMenu(void *ptr, WPARAM wParam, LPARAM lParam); - -DWORD_PTR __cdecl TlenProtocol::GetCaps(int type, HANDLE hContact) +DWORD_PTR TlenProtocol::GetCaps(int type, HANDLE hContact) { if (type == PFLAGNUM_1) return PF1_IM|PF1_AUTHREQ|PF1_SERVERCLIST|PF1_MODEMSG|PF1_BASICSEARCH|PF1_SEARCHBYEMAIL|PF1_EXTSEARCH|PF1_EXTSEARCHUI|PF1_SEARCHBYNAME|PF1_FILE;//|PF1_VISLIST|PF1_INVISLIST; @@ -56,10 +50,9 @@ DWORD_PTR __cdecl TlenProtocol::GetCaps(int type, HANDLE hContact) return 0; } -INT_PTR TlenGetName(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::GetName(WPARAM wParam, LPARAM lParam) { - TlenProtocol *proto = (TlenProtocol *)ptr; - strncpy((char*)lParam, proto->m_szModuleName, wParam); + strncpy((char*)lParam, m_szModuleName, wParam); return 0; } @@ -89,7 +82,7 @@ void TlenResetSearchQuery(TlenProtocol *proto) { proto->searchID = JabberSerialNext(proto); } -HANDLE __cdecl TlenProtocol::SearchBasic(const PROTOCHAR* id) +HANDLE TlenProtocol::SearchBasic(const PROTOCHAR* id) { char *jid; int iqId = 0; @@ -107,7 +100,7 @@ HANDLE __cdecl TlenProtocol::SearchBasic(const PROTOCHAR* id) return (HANDLE)iqId; } -HANDLE __cdecl TlenProtocol::SearchByEmail(const PROTOCHAR* email) +HANDLE TlenProtocol::SearchByEmail(const PROTOCHAR* email) { char *emailEnc; int iqId = 0; @@ -126,7 +119,7 @@ HANDLE __cdecl TlenProtocol::SearchByEmail(const PROTOCHAR* email) return (HANDLE)iqId; } -HANDLE __cdecl TlenProtocol::SearchByName(const PROTOCHAR* nickT, const PROTOCHAR* firstNameT, const PROTOCHAR* lastNameT) +HANDLE TlenProtocol::SearchByName(const PROTOCHAR* nickT, const PROTOCHAR* firstNameT, const PROTOCHAR* lastNameT) { char* nick = mir_t2a(nickT); @@ -163,12 +156,12 @@ HANDLE __cdecl TlenProtocol::SearchByName(const PROTOCHAR* nickT, const PROTOCHA return (HANDLE)iqId; } -HWND __cdecl TlenProtocol::CreateExtendedSearchUI(HWND owner) +HWND TlenProtocol::CreateExtendedSearchUI(HWND owner) { return (HWND) CreateDialog(hInst, MAKEINTRESOURCE(IDD_ADVSEARCH), owner, TlenAdvSearchDlgProc); } -HWND __cdecl TlenProtocol::SearchAdvanced(HWND owner) +HWND TlenProtocol::SearchAdvanced(HWND owner) { int iqId; if (!isOnline) return 0; @@ -221,7 +214,7 @@ static HANDLE AddToListByJID(TlenProtocol *proto, const char *newJid, DWORD flag return hContact; } -HANDLE __cdecl TlenProtocol::AddToList(int flags, PROTOSEARCHRESULT *psr) +HANDLE TlenProtocol::AddToList(int flags, PROTOSEARCHRESULT *psr) { HANDLE hContact; JABBER_SEARCH_RESULT *jsr = (JABBER_SEARCH_RESULT*)psr; @@ -231,7 +224,7 @@ HANDLE __cdecl TlenProtocol::AddToList(int flags, PROTOSEARCHRESULT *psr) return hContact; } -HANDLE __cdecl TlenProtocol::AddToListByEvent( int flags, int iContact, HANDLE hDbEvent ) +HANDLE TlenProtocol::AddToListByEvent( int flags, int iContact, HANDLE hDbEvent ) { DBEVENTINFO dbei = { sizeof(dbei) }; if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) @@ -269,7 +262,7 @@ HANDLE __cdecl TlenProtocol::AddToListByEvent( int flags, int iContact, HANDLE h return hContact; } -int __cdecl TlenProtocol::Authorize(HANDLE hDbEvent) +int TlenProtocol::Authorize(HANDLE hDbEvent) { if (!isOnline) return 1; @@ -318,7 +311,7 @@ int __cdecl TlenProtocol::Authorize(HANDLE hDbEvent) return 0; } -int __cdecl TlenProtocol::AuthDeny(HANDLE hDbEvent, const PROTOCHAR* szReason) +int TlenProtocol::AuthDeny(HANDLE hDbEvent, const PROTOCHAR* szReason) { if (!isOnline) return 1; @@ -370,7 +363,7 @@ static void TlenConnect(TlenProtocol *proto, int initialStatus) } } -int __cdecl TlenProtocol::SetStatus(int iNewStatus) +int TlenProtocol::SetStatus(int iNewStatus) { int oldStatus; HANDLE s; @@ -418,14 +411,12 @@ int __cdecl TlenProtocol::SetStatus(int iNewStatus) return 0; } -INT_PTR TlenGetStatus(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::GetStatus(WPARAM wParam, LPARAM lParam) { - TlenProtocol *proto = (TlenProtocol *)ptr; - return proto->m_iStatus; + return m_iStatus; } - -int __cdecl TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) +int TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) { char **szMsg; char *newModeMsg; @@ -482,7 +473,7 @@ int __cdecl TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) return 0; } -int __cdecl TlenProtocol::GetInfo(HANDLE hContact, int infoType) +int TlenProtocol::GetInfo(HANDLE hContact, int infoType) { DBVARIANT dbv; int iqId; @@ -509,7 +500,7 @@ int __cdecl TlenProtocol::GetInfo(HANDLE hContact, int infoType) return 0; } -int __cdecl TlenProtocol::SetApparentMode(HANDLE hContact, int mode) +int TlenProtocol::SetApparentMode(HANDLE hContact, int mode) { DBVARIANT dbv; int oldMode; @@ -591,20 +582,19 @@ static void __cdecl TlenGetAwayMsgThread(void *ptr) delete data; } -INT_PTR TlenSendAlert(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::SendAlert(WPARAM wParam, LPARAM lParam) { HANDLE hContact = ( HANDLE )wParam; DBVARIANT dbv; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (proto->isOnline && !db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { - JabberSend(proto, "", dbv.pszVal); + if (isOnline && !db_get(hContact, m_szModuleName, "jid", &dbv)) { + JabberSend(this, "", dbv.pszVal); db_free(&dbv); } return 0; } -int __cdecl TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW) +int TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW) { DBVARIANT dbv; char *msgEnc; @@ -674,63 +664,62 @@ int __cdecl TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW ///////////////////////////////////////////////////////////////////////////////////////// // JabberGetAvatarInfo - retrieves the avatar info -static INT_PTR TlenGetAvatarInfo(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam) { BOOL downloadingAvatar = FALSE; char *avatarHash = NULL; JABBER_LIST_ITEM *item = NULL; DBVARIANT dbv; - TlenProtocol *proto = (TlenProtocol *)ptr; PROTO_AVATAR_INFORMATIONT* AI = ( PROTO_AVATAR_INFORMATIONT* )lParam; - if (!proto->tlenOptions.enableAvatars) return GAIR_NOAVATAR; + if (!tlenOptions.enableAvatars) return GAIR_NOAVATAR; if (AI->hContact != NULL) { - if (!db_get(AI->hContact, proto->m_szModuleName, "jid", &dbv)) { - item = JabberListGetItemPtr(proto, LIST_ROSTER, dbv.pszVal); + if (!db_get(AI->hContact, m_szModuleName, "jid", &dbv)) { + item = JabberListGetItemPtr(this, LIST_ROSTER, dbv.pszVal); db_free(&dbv); if (item != NULL) { downloadingAvatar = item->newAvatarDownloading; avatarHash = item->avatarHash; } } - } else { - if (proto->threadData != NULL) { - avatarHash = proto->threadData->avatarHash; - } } - if ((avatarHash == NULL || avatarHash[0] == '\0') && !downloadingAvatar) { + else if (threadData != NULL) + avatarHash = threadData->avatarHash; + + if ((avatarHash == NULL || avatarHash[0] == '\0') && !downloadingAvatar) return GAIR_NOAVATAR; - } + if (avatarHash != NULL && !downloadingAvatar) { - TlenGetAvatarFileName(proto, item, AI->filename, sizeof(AI->filename)); - AI->format = ( AI->hContact == NULL ) ? proto->threadData->avatarFormat : item->avatarFormat; + TlenGetAvatarFileName(this, item, AI->filename, sizeof(AI->filename)); + AI->format = ( AI->hContact == NULL ) ? threadData->avatarFormat : item->avatarFormat; return GAIR_SUCCESS; } - if (( wParam & GAIF_FORCE ) != 0 && AI->hContact != NULL && proto->isOnline) { - /* get avatar */ + + /* get avatar */ + if (( wParam & GAIF_FORCE ) != 0 && AI->hContact != NULL && isOnline) return GAIR_WAITFOR; - } + return GAIR_NOAVATAR; } -HANDLE __cdecl TlenProtocol::GetAwayMsg(HANDLE hContact) +HANDLE TlenProtocol::GetAwayMsg(HANDLE hContact) { SENDACKTHREADDATA *tdata = new SENDACKTHREADDATA(this, hContact, 0); JabberForkThread((void (__cdecl *)(void*))TlenGetAwayMsgThread, 0, (void*)tdata); return (HANDLE)1; } -int __cdecl TlenProtocol::RecvAwayMsg(HANDLE hContact, int mode, PROTORECVEVENT* evt) +int TlenProtocol::RecvAwayMsg(HANDLE hContact, int mode, PROTORECVEVENT* evt) { return 0; } -int __cdecl TlenProtocol::SendAwayMsg(HANDLE hContact, HANDLE hProcess, const char* msg) +int TlenProtocol::SendAwayMsg(HANDLE hContact, HANDLE hProcess, const char* msg) { return 0; } -HANDLE __cdecl TlenProtocol::FileAllow(HANDLE hContact, HANDLE hTransfer, const PROTOCHAR* szPath) +HANDLE TlenProtocol::FileAllow(HANDLE hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { TLEN_FILE_TRANSFER *ft; JABBER_LIST_ITEM *item; @@ -753,7 +742,7 @@ HANDLE __cdecl TlenProtocol::FileAllow(HANDLE hContact, HANDLE hTransfer, const return (HANDLE)hTransfer; } -int __cdecl TlenProtocol::FileDeny(HANDLE hContact, HANDLE hTransfer, const PROTOCHAR* szReason) +int TlenProtocol::FileDeny(HANDLE hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { TLEN_FILE_TRANSFER *ft; char *nick; @@ -772,11 +761,11 @@ int __cdecl TlenProtocol::FileDeny(HANDLE hContact, HANDLE hTransfer, const PROT return 0; } -int __cdecl TlenProtocol::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { +int TlenProtocol::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { return 0; } -int __cdecl TlenProtocol::FileCancel(HANDLE hContact, HANDLE hTransfer) +int TlenProtocol::FileCancel(HANDLE hContact, HANDLE hTransfer) { TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *) hTransfer; JabberLog(this, "Invoking FileCancel()"); @@ -795,7 +784,7 @@ int __cdecl TlenProtocol::FileCancel(HANDLE hContact, HANDLE hTransfer) return 0; } -HANDLE __cdecl TlenProtocol::SendFile(HANDLE hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles) +HANDLE TlenProtocol::SendFile(HANDLE hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles) { TLEN_FILE_TRANSFER *ft; int i, j; @@ -863,25 +852,26 @@ HANDLE __cdecl TlenProtocol::SendFile(HANDLE hContact, const PROTOCHAR* szDescri return (HANDLE) ft; } -int __cdecl TlenProtocol::SendContacts(HANDLE hContact, int flags, int nContacts, HANDLE* hContactsList){ +int TlenProtocol::SendContacts(HANDLE hContact, int flags, int nContacts, HANDLE* hContactsList){ return 0; } -int __cdecl TlenProtocol::SendUrl(HANDLE hContact, int flags, const char* urlt){ +int TlenProtocol::SendUrl(HANDLE hContact, int flags, const char* urlt){ return 0; } -int __cdecl TlenProtocol::RecvMsg(HANDLE hContact, PROTORECVEVENT* evt) +int TlenProtocol::RecvMsg(HANDLE hContact, PROTORECVEVENT* evt) { return Proto_RecvMessage(hContact, evt); } -int __cdecl TlenProtocol::RecvFile(HANDLE hContact, PROTOFILEEVENT* evt) +int TlenProtocol::RecvFile(HANDLE hContact, PROTOFILEEVENT* evt) { return Proto_RecvFile(hContact, evt); } -int __cdecl TlenProtocol::RecvUrl(HANDLE hContact, PROTORECVEVENT*){ +int TlenProtocol::RecvUrl(HANDLE hContact, PROTORECVEVENT*) +{ return 0; } @@ -896,13 +886,12 @@ static char* settingToChar( DBCONTACTWRITESETTING* cws ) return NULL; } -int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::JabberDbSettingChanged(WPARAM wParam, LPARAM lParam) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; - TlenProtocol *proto = (TlenProtocol *)ptr; // no action for hContact == NULL or when offline if ((HANDLE) wParam == NULL) return 0; - if (!proto->isConnected) return 0; + if (!isConnected) return 0; if (!strcmp(cws->szModule, "CList")) { HANDLE hContact; @@ -912,32 +901,34 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) hContact = (HANDLE) wParam; szProto = GetContactProto(hContact); - if (szProto == NULL || strcmp(szProto, proto->m_szModuleName)) return 0; + if (szProto == NULL || strcmp(szProto, m_szModuleName)) return 0; // A contact's group is changed if (!strcmp(cws->szSetting, "Group")) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { - if ((item=JabberListGetItemPtr(proto, LIST_ROSTER, dbv.pszVal)) != NULL) { + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { + if ((item=JabberListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL) { db_free(&dbv); if (!db_get(hContact, "CList", "MyHandle", &dbv)) { nick = JabberTextEncode(dbv.pszVal); db_free(&dbv); - } else if (!db_get(hContact, proto->m_szModuleName, "Nick", &dbv)) { + } + else if (!db_get(hContact, this->m_szModuleName, "Nick", &dbv)) { nick = JabberTextEncode(dbv.pszVal); db_free(&dbv); - } else { - nick = JabberNickFromJID(item->jid); } + else nick = JabberNickFromJID(item->jid); + if (nick != NULL) { // Note: we need to compare with item->group to prevent infinite loop if (cws->value.type == DBVT_DELETED && item->group != NULL) { - JabberLog(proto, "Group set to nothing"); - JabberSend(proto, "", nick, item->jid); - } else if (cws->value.pszVal != NULL) { + JabberLog(this, "Group set to nothing"); + JabberSend(this, "", nick, item->jid); + } + else if (cws->value.pszVal != NULL) { char *newGroup = settingToChar(cws); if (item->group == NULL || strcmp(newGroup, item->group)) { - JabberLog(proto, "Group set to %s", newGroup); + JabberLog(this, "Group set to %s", newGroup); if ((group=TlenGroupEncode(newGroup)) != NULL) { - JabberSend(proto, "%s", nick, item->jid, group); + JabberSend(this, "%s", nick, item->jid, group); mir_free(group); } } @@ -959,9 +950,9 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) // szProto = GetContactProto(hContact); // if (szProto == NULL || strcmp(szProto, proto->m_szModuleName)) return 0; - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { jid = dbv.pszVal; - if ((item=JabberListGetItemPtr(proto, LIST_ROSTER, dbv.pszVal)) != NULL) { + if ((item=JabberListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL) { if (cws->value.type == DBVT_DELETED) { newNick = mir_strdup((char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_NOMYHANDLE)); } else if (cws->value.pszVal != NULL) { @@ -972,12 +963,12 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) // Note: we need to compare with item->nick to prevent infinite loop if (newNick != NULL && (item->nick == NULL || (item->nick != NULL && strcmp(item->nick, newNick)))) { if ((nick=JabberTextEncode(newNick)) != NULL) { - JabberLog(proto, "Nick set to %s", newNick); + JabberLog(this, "Nick set to %s", newNick); if (item->group != NULL && (group=TlenGroupEncode(item->group)) != NULL) { - JabberSend(proto, "%s", nick, jid, group); + JabberSend(this, "%s", nick, jid, group); mir_free(group); } else { - JabberSend(proto, "", nick, jid); + JabberSend(this, "", nick, jid); } mir_free(nick); } @@ -992,10 +983,10 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) char *jid, *nick, *pGroup; if (cws->value.type==DBVT_DELETED || (cws->value.type==DBVT_BYTE && cws->value.bVal==0)) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { jid = mir_strdup(dbv.pszVal); db_free(&dbv); - JabberLog(proto, "Add %s permanently to list", jid); + JabberLog(this, "Add %s permanently to list", jid); if (!db_get(hContact, "CList", "MyHandle", &dbv)) { nick = JabberTextEncode(dbv.pszVal); //Utf8Encode db_free(&dbv); @@ -1004,18 +995,18 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) nick = JabberNickFromJID(jid); } if (nick != NULL) { - JabberLog(proto, "jid=%s nick=%s", jid, nick); + JabberLog(this, "jid=%s nick=%s", jid, nick); if (!db_get(hContact, "CList", "Group", &dbv)) { if ((pGroup=TlenGroupEncode(dbv.pszVal)) != NULL) { - JabberSend(proto, "%s", nick, jid, pGroup); - JabberSend(proto, "", jid); + JabberSend(this, "%s", nick, jid, pGroup); + JabberSend(this, "", jid); mir_free(pGroup); } db_free(&dbv); } else { - JabberSend(proto, "", nick, jid); - JabberSend(proto, "", jid); + JabberSend(this, "", nick, jid); + JabberSend(this, "", jid); } mir_free(nick); db_unset(hContact, "CList", "Hidden"); @@ -1029,18 +1020,17 @@ int JabberDbSettingChanged(void *ptr, WPARAM wParam, LPARAM lParam) return 0; } -int JabberContactDeleted(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::JabberContactDeleted(WPARAM wParam, LPARAM lParam) { - char *szProto; - DBVARIANT dbv; - TlenProtocol *proto = (TlenProtocol *)ptr; - - if (!proto->isOnline) // should never happen + if (!isOnline) // should never happen return 0; - szProto = GetContactProto((HANDLE)wParam); - if (szProto == NULL || strcmp(szProto, proto->m_szModuleName)) + + char *szProto = GetContactProto((HANDLE)wParam); + if (szProto == NULL || strcmp(szProto, m_szModuleName)) return 0; - if (!db_get((HANDLE) wParam, proto->m_szModuleName, "jid", &dbv)) { + + DBVARIANT dbv; + if (!db_get((HANDLE) wParam, m_szModuleName, "jid", &dbv)) { char *jid, *p, *q; jid = dbv.pszVal; @@ -1048,17 +1038,17 @@ int JabberContactDeleted(void *ptr, WPARAM wParam, LPARAM lParam) if ((q=strchr(p, '/')) != NULL) *q = '\0'; } - if (JabberListExist(proto, LIST_ROSTER, jid)) { - // Remove from roster, server also handles the presence unsubscription process. - JabberSend(proto, "", jid); - } + + // Remove from roster, server also handles the presence unsubscription process. + if (JabberListExist(this, LIST_ROSTER, jid)) + JabberSend(this, "", jid); db_free(&dbv); } return 0; } -int __cdecl TlenProtocol::UserIsTyping(HANDLE hContact, int type) +int TlenProtocol::UserIsTyping(HANDLE hContact, int type) { DBVARIANT dbv; JABBER_LIST_ITEM *item; @@ -1080,17 +1070,14 @@ int __cdecl TlenProtocol::UserIsTyping(HANDLE hContact, int type) return 0; } -INT_PTR TlenGetMyAvatar(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::GetMyAvatar(WPARAM wParam, LPARAM lParam) { TCHAR* buf = (TCHAR*)wParam; int size = ( int )lParam; - TlenProtocol *proto = (TlenProtocol *)ptr; - if ( buf == NULL || size <= 0 ) return -1; - TlenGetAvatarFileName( proto, NULL, buf, size ); - //wParam (buf) is output var + TlenGetAvatarFileName(this, NULL, buf, size); return 0; } @@ -1123,42 +1110,39 @@ static INT_PTR CALLBACK TlenChangeAvatarDlgProc( HWND hwndDlg, UINT msg, WPARAM return 0; } -INT_PTR TlenSetMyAvatar(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::SetMyAvatar(WPARAM wParam, LPARAM lParam) { TCHAR* szFileName = ( TCHAR* )lParam; TCHAR tFileName[ MAX_PATH ]; - int fileIn; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!proto->isOnline) return 1; + if (!isOnline) return 1; if (szFileName != NULL) { int result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_USER_CHANGEAVATAR), NULL, TlenChangeAvatarDlgProc, (LPARAM) NULL); - TlenGetAvatarFileName( proto, NULL, tFileName, MAX_PATH); - if ( CopyFile( szFileName, tFileName, FALSE ) == FALSE ) { + TlenGetAvatarFileName(this, NULL, tFileName, MAX_PATH); + if ( CopyFile( szFileName, tFileName, FALSE ) == FALSE ) return 1; - } + char* tFileNameA = mir_t2a(tFileName); //TODO - drop io.h - fileIn = open( tFileNameA, O_RDWR | O_BINARY, S_IREAD | S_IWRITE ); + int fileIn = open( tFileNameA, O_RDWR | O_BINARY, S_IREAD | S_IWRITE ); if ( fileIn != -1 ) { long dwPngSize = filelength(fileIn); BYTE* pResult = (BYTE *)mir_alloc(dwPngSize); if (pResult != NULL) { read( fileIn, pResult, dwPngSize ); close( fileIn ); - TlenUploadAvatar(proto, pResult, dwPngSize, (result & 0x10000) != 0); + TlenUploadAvatar(this, pResult, dwPngSize, (result & 0x10000) != 0); mir_free(pResult); } } mir_free(tFileName); mir_free(tFileNameA); - } else { - TlenRemoveAvatar(proto); } + else TlenRemoveAvatar(this); + return 0; } -INT_PTR TlenGetAvatarCaps(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::GetAvatarCaps(WPARAM wParam, LPARAM lParam) { - TlenProtocol *proto = (TlenProtocol *)ptr; switch (wParam) { case AF_MAXSIZE: { @@ -1172,7 +1156,7 @@ INT_PTR TlenGetAvatarCaps(void *ptr, LPARAM wParam, LPARAM lParam) case AF_FORMATSUPPORTED: return (lParam == PA_FORMAT_PNG) ? 1 : 0; case AF_ENABLED: - return (proto->tlenOptions.enableAvatars && proto->isOnline) ? 1 : 0; + return (tlenOptions.enableAvatars && isOnline) ? 1 : 0; case AF_DONTNEEDDELAYS: return 1; case AF_MAXFILESIZE: @@ -1183,13 +1167,13 @@ INT_PTR TlenGetAvatarCaps(void *ptr, LPARAM wParam, LPARAM lParam) return 0; } -int __cdecl TlenProtocol::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) +int TlenProtocol::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) { //TlenProtocol *proto = (TlenProtocol *)ptr; switch( iEventType ) { - case EV_PROTO_ONLOAD: return TlenOnModulesLoaded(this, 0, 0 ); - case EV_PROTO_ONOPTIONS: return TlenOptionsInit(this, wParam, lParam ); - case EV_PROTO_ONEXIT: return TlenPreShutdown(this, 0, 0 ); + case EV_PROTO_ONLOAD: return OnModulesLoaded(0, 0); + case EV_PROTO_ONOPTIONS: return OptionsInit(wParam, lParam); + case EV_PROTO_ONEXIT: return PreShutdown(0, 0); case EV_PROTO_ONRENAME: { CLISTMENUITEM mi = { sizeof(mi) }; @@ -1203,64 +1187,45 @@ int __cdecl TlenProtocol::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPAR } // PSS_ADDED -int __cdecl TlenProtocol::AuthRecv(HANDLE hContact, PROTORECVEVENT* evt) +int TlenProtocol::AuthRecv(HANDLE hContact, PROTORECVEVENT* evt) { return 1; } // PSS_AUTHREQUEST -int __cdecl TlenProtocol::AuthRequest(HANDLE hContact, const PROTOCHAR* szMessage) +int TlenProtocol::AuthRequest(HANDLE hContact, const PROTOCHAR* szMessage) { return 1; } -HANDLE __cdecl TlenProtocol::ChangeInfo(int iInfoType, void* pInfoData) +HANDLE TlenProtocol::ChangeInfo(int iInfoType, void* pInfoData) { return NULL; } -int __cdecl TlenProtocol::RecvContacts(HANDLE hContact, PROTORECVEVENT* evt) +int TlenProtocol::RecvContacts(HANDLE hContact, PROTORECVEVENT* evt) { return 1; } - extern INT_PTR CALLBACK TlenAccMgrUIDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -INT_PTR TlenAccMgrUI(void *ptr, LPARAM wParam, LPARAM lParam) +INT_PTR TlenProtocol::AccMgrUI(WPARAM wParam, LPARAM lParam) { - return (INT_PTR) CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, TlenAccMgrUIDlgProc, (LPARAM) ptr); + return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ACCMGRUI), (HWND)lParam, TlenAccMgrUIDlgProc, (LPARAM)this); } -void TlenInitServicesVTbl(TlenProtocol *proto) { - - char s[128]; - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_GETNAME); - CreateServiceFunction_Ex(s, proto, TlenGetName); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_GETAVATARINFO); - CreateServiceFunction_Ex(s, proto, TlenGetAvatarInfo); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_SEND_NUDGE); - CreateServiceFunction_Ex(s, proto, TlenSendAlert); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_GETAVATARCAPS); - CreateServiceFunction_Ex(s, proto, TlenGetAvatarCaps); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_SETMYAVATART); - CreateServiceFunction_Ex(s, proto, TlenSetMyAvatar); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_GETMYAVATART); - CreateServiceFunction_Ex(s, proto, TlenGetMyAvatar); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_GETSTATUS); - CreateServiceFunction_Ex(s, proto, TlenGetStatus); - - mir_snprintf(s, SIZEOF(s), "%s%s", proto->m_szModuleName, PS_CREATEACCMGRUI); - CreateServiceFunction_Ex(s, proto, TlenAccMgrUI); - +void TlenInitServicesVTbl(TlenProtocol *proto) +{ + proto->CreateProtoService(PS_GETNAME, &TlenProtocol::GetName); + proto->CreateProtoService(PS_GETAVATARINFO, &TlenProtocol::GetAvatarInfo); + proto->CreateProtoService(PS_SEND_NUDGE, &TlenProtocol::SendAlert); + proto->CreateProtoService(PS_GETAVATARCAPS, &TlenProtocol::GetAvatarCaps); + proto->CreateProtoService(PS_SETMYAVATART, &TlenProtocol::SetMyAvatar); + proto->CreateProtoService(PS_GETMYAVATART, &TlenProtocol::GetMyAvatar); + proto->CreateProtoService(PS_GETSTATUS, &TlenProtocol::GetStatus); + proto->CreateProtoService(PS_CREATEACCMGRUI, &TlenProtocol::AccMgrUI); } TlenProtocol::TlenProtocol( const char *aProtoName, const TCHAR *aUserName) : @@ -1271,30 +1236,24 @@ TlenProtocol::TlenProtocol( const char *aProtoName, const TCHAR *aUserName) : InitializeCriticalSection(&modeMsgMutex); InitializeCriticalSection(&csSend); - char text[_MAX_PATH]; - mir_snprintf(text, SIZEOF(text), "%s/%s", m_szModuleName, "Nudge"); - hTlenNudge = CreateProtoEvent(text); - - HookEventObj_Ex(ME_SYSTEM_MODULESLOADED, this, TlenSystemModulesLoaded); - HookEventObj_Ex(ME_OPT_INITIALISE, this, TlenOptionsInit); - HookEventObj_Ex(ME_DB_CONTACT_SETTINGCHANGED, this, JabberDbSettingChanged); - HookEventObj_Ex(ME_DB_CONTACT_DELETED, this, JabberContactDeleted); - HookEventObj_Ex(ME_CLIST_PREBUILDCONTACTMENU, this, TlenPrebuildContactMenu); -// HookEventObj_Ex(ME_SKIN2_ICONSCHANGED, this, TlenIconsChanged); - HookEventObj_Ex(ME_SYSTEM_PRESHUTDOWN, this, TlenPreShutdown); + hTlenNudge = CreateProtoEvent("/Nudge"); + HookProtoEvent(ME_OPT_INITIALISE, &TlenProtocol::OptionsInit); + HookProtoEvent(ME_DB_CONTACT_SETTINGCHANGED, &TlenProtocol::JabberDbSettingChanged); + HookProtoEvent(ME_DB_CONTACT_DELETED, &TlenProtocol::JabberContactDeleted); + HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &TlenProtocol::PrebuildContactMenu); + HookProtoEvent(ME_SYSTEM_PRESHUTDOWN, &TlenProtocol::PreShutdown); DBVARIANT dbv; - if (!db_get(NULL, m_szModuleName, "LoginServer", &dbv)) { + if (!db_get(NULL, m_szModuleName, "LoginServer", &dbv)) db_free(&dbv); - } else { + else db_set_s(NULL, m_szModuleName, "LoginServer", "tlen.pl"); - } - if (!db_get(NULL, m_szModuleName, "ManualHost", &dbv)) { + + if (!db_get(NULL, m_szModuleName, "ManualHost", &dbv)) db_free(&dbv); - } else { + else db_set_s(NULL, m_szModuleName, "ManualHost", "s1.tlen.pl"); - } TlenLoadOptions(this); @@ -1302,23 +1261,22 @@ TlenProtocol::TlenProtocol( const char *aProtoName, const TCHAR *aUserName) : JabberSerialInit(this); JabberIqInit(this); JabberListInit(this); + + initMenuItems(); } TlenProtocol::~TlenProtocol() { - uninitMenuItems(this); TlenVoiceCancelAll(this); TlenFileCancelAll(this); if (hTlenNudge) DestroyHookableEvent(hTlenNudge); - UnhookEvents_Ex(this); JabberListUninit(this); JabberIqUninit(this); JabberSerialUninit(this); DeleteCriticalSection(&modeMsgMutex); DeleteCriticalSection(&csSend); - //DestroyServices_Ex(this); JabberWsUninit(this); mir_free(modeMsgs.szOnline); diff --git a/protocols/Tlen/src/jabber_util.cpp b/protocols/Tlen/src/jabber_util.cpp index a05c16d87a..71a18155b6 100644 --- a/protocols/Tlen/src/jabber_util.cpp +++ b/protocols/Tlen/src/jabber_util.cpp @@ -26,47 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include - -HANDLE HookEventObj_Ex(const char *name, TlenProtocol *proto, MIRANDAHOOKOBJ hook) -{ - proto->hookNum ++; - proto->hHooks = (HANDLE *) mir_realloc(proto->hHooks, sizeof(HANDLE) * (proto->hookNum)); - proto->hHooks[proto->hookNum - 1] = HookEventObj(name, hook, proto); - return proto->hHooks[proto->hookNum - 1] ; -} - - -HANDLE CreateServiceFunction_Ex(const char *name, TlenProtocol *proto, MIRANDASERVICEOBJ service) { - proto->serviceNum++; - proto->hServices = (HANDLE *) mir_realloc(proto->hServices, sizeof(HANDLE) * (proto->serviceNum)); - proto->hServices[proto->serviceNum - 1] = CreateServiceFunctionObj(name, service, proto); - return proto->hServices[proto->serviceNum - 1] ; -} - -void UnhookEvents_Ex(TlenProtocol *proto) { - unsigned int i; - for (i=0; ihookNum; ++i) { - if (proto->hHooks[i] != NULL) { - UnhookEvent(proto->hHooks[i]); - } - } - mir_free(proto->hHooks); - proto->hookNum = 0; - proto->hHooks = NULL; -} - -void DestroyServices_Ex(TlenProtocol *proto) { - unsigned int i; - for (i=0; iserviceNum; ++i) { - if (proto->hServices[i] != NULL) { - DestroyServiceFunction(proto->hServices[i]); - } - } - mir_free(proto->hServices); - proto->serviceNum = 0; - proto->hServices = NULL; -} - void JabberSerialInit(TlenProtocol *proto) { InitializeCriticalSection(&proto->csSerial); @@ -420,102 +379,6 @@ char *JabberTextDecode(const char *str) return s1; } -static char b64table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -char *JabberBase64Encode(const char *buffer, int bufferLen) -{ - int n; - unsigned char igroup[3]; - char *p, *peob; - char *res, *r; - - if (buffer == NULL || bufferLen <= 0) return NULL; - if ((res=(char *) mir_alloc((((bufferLen+2)/3)*4) + 1)) == NULL) return NULL; - - for (p=(char*)buffer,peob=p+bufferLen,r=res; p= peob) break; - igroup[n] = (unsigned char) *p; - p++; - } - if (n > 0) { - r[0] = b64table[ igroup[0]>>2 ]; - r[1] = b64table[ ((igroup[0]&3)<<4) | (igroup[1]>>4) ]; - r[2] = b64table[ ((igroup[1]&0xf)<<2) | (igroup[2]>>6) ]; - r[3] = b64table[ igroup[2]&0x3f ]; - if (n < 3) { - r[3] = '='; - if (n < 2) - r[2] = '='; - } - r += 4; - } - } - *r = '\0'; - - return res; -} - -static unsigned char b64rtable[256]; - -char *JabberBase64Decode(const char *str, int *resultLen) -{ - char *res; - unsigned char *p, *r, igroup[4], a[4]; - int n, num, count; - - if (str == NULL || resultLen == NULL) return NULL; - if ((res=(char *) mir_alloc(((strlen(str)+3)/4)*3)) == NULL) return NULL; - - for (n=0; n<256; n++) - b64rtable[n] = (unsigned char) 0x80; - for (n=0; n<26; n++) - b64rtable['A'+n] = n; - for (n=0; n<26; n++) - b64rtable['a'+n] = n + 26; - for (n=0; n<10; n++) - b64rtable['0'+n] = n + 52; - b64rtable['+'] = 62; - b64rtable['/'] = 63; - b64rtable['='] = 0; - count = 0; - for (p=(unsigned char *)str,r=(unsigned char *)res; *p != '\0';) { - for (n=0; n<4; n++) { - if ( *p == '\r' || *p == '\n' ) { - n--; p++; - continue; - } - - if ( *p=='\0' ) { - if ( n == 0 ) - goto LBL_Exit; - mir_free( res ); - return NULL; - } - - if ( b64rtable[*p] == 0x80 ) { - mir_free( res ); - return NULL; - } - - a[n] = *p; - igroup[n] = b64rtable[*p]; - p++; - } - r[0] = igroup[0]<<2 | igroup[1]>>4; - r[1] = igroup[1]<<4 | igroup[2]>>2; - r[2] = igroup[2]<<6 | igroup[3]; - r += 3; - num = ( a[2] == '='?1:( a[3] == '='?2:3 )); - count += num; - if ( num < 3 ) break; - } -LBL_Exit: - *resultLen = count; - return res; -} - /* * Apply Polish Daylight Saving Time rules to get "DST-unbiased" timestamp */ diff --git a/protocols/Tlen/src/tlen.cpp b/protocols/Tlen/src/tlen.cpp index 9e1f4bc1d4..d03ad838b1 100644 --- a/protocols/Tlen/src/tlen.cpp +++ b/protocols/Tlen/src/tlen.cpp @@ -55,9 +55,6 @@ PLUGININFOEX pluginInfoEx = { // Main jabber server connection thread global variables -int TlenUserInfoInit(void *ptr, WPARAM wParam, LPARAM lParam); -int TlenSystemModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam); - BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpvReserved) { #ifdef _DEBUG @@ -114,72 +111,68 @@ static void TlenRegisterIcons() Icon_Register(hInst, "Protocols/Tlen", iconList, SIZEOF(iconList), "TLEN"); } -int TlenPrebuildContactMenu(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::PrebuildContactMenu(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (hContact != NULL && proto->isOnline) { + if (hContact != NULL && isOnline) { DBVARIANT dbv; - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { - JABBER_LIST_ITEM *item = JabberListGetItemPtr(proto, LIST_ROSTER, dbv.pszVal); + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { + JABBER_LIST_ITEM *item = JabberListGetItemPtr(this, LIST_ROSTER, dbv.pszVal); db_free(&dbv); if (item != NULL) { - Menu_ShowItem(proto->hMenuContactRequestAuth, item->subscription == SUB_NONE || item->subscription == SUB_FROM); - Menu_ShowItem(proto->hMenuContactGrantAuth, item->subscription == SUB_NONE || item->subscription == SUB_TO); - Menu_ShowItem(proto->hMenuContactMUC, item->status != ID_STATUS_OFFLINE); - Menu_ShowItem(proto->hMenuContactVoice, item->status != ID_STATUS_OFFLINE && !TlenVoiceIsInUse(proto)); - Menu_ShowItem(proto->hMenuPicture, item->status != ID_STATUS_OFFLINE); + Menu_ShowItem(hMenuContactRequestAuth, item->subscription == SUB_NONE || item->subscription == SUB_FROM); + Menu_ShowItem(hMenuContactGrantAuth, item->subscription == SUB_NONE || item->subscription == SUB_TO); + Menu_ShowItem(hMenuContactMUC, item->status != ID_STATUS_OFFLINE); + Menu_ShowItem(hMenuContactVoice, item->status != ID_STATUS_OFFLINE && !TlenVoiceIsInUse(this)); + Menu_ShowItem(hMenuPicture, item->status != ID_STATUS_OFFLINE); return 0; } } } - Menu_ShowItem(proto->hMenuContactMUC, false); - Menu_ShowItem(proto->hMenuContactVoice, false); - Menu_ShowItem(proto->hMenuContactRequestAuth, false); - Menu_ShowItem(proto->hMenuContactGrantAuth, false); + Menu_ShowItem(hMenuContactMUC, false); + Menu_ShowItem(hMenuContactVoice, false); + Menu_ShowItem(hMenuContactRequestAuth, false); + Menu_ShowItem(hMenuContactGrantAuth, false); return 0; } -INT_PTR TlenContactMenuHandleRequestAuth(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::ContactMenuHandleRequestAuth(WPARAM wParam, LPARAM lParam) { - HANDLE hContact; - DBVARIANT dbv; - TlenProtocol *proto = (TlenProtocol *)ptr; - if ((hContact=(HANDLE) wParam) != NULL && proto->isOnline) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { - JabberSend(proto, "", dbv.pszVal); + HANDLE hContact = (HANDLE)wParam; + if (hContact != NULL && isOnline) { + DBVARIANT dbv; + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { + JabberSend(this, "", dbv.pszVal); db_free(&dbv); } } return 0; } -INT_PTR TlenContactMenuHandleGrantAuth(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::ContactMenuHandleGrantAuth(WPARAM wParam, LPARAM lParam) { - HANDLE hContact; - DBVARIANT dbv; - TlenProtocol *proto = (TlenProtocol *)ptr; - if ((hContact=(HANDLE) wParam) != NULL && proto->isOnline) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { - JabberSend(proto, "", dbv.pszVal); + HANDLE hContact = (HANDLE)wParam; + if (hContact != NULL && isOnline) { + DBVARIANT dbv; + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { + JabberSend(this, "", dbv.pszVal); db_free(&dbv); } } return 0; } -INT_PTR TlenContactMenuHandleSendPicture(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::ContactMenuHandleSendPicture(WPARAM wParam, LPARAM lParam) { - HANDLE hContact; - TlenProtocol *proto = (TlenProtocol *)ptr; - if ((hContact=(HANDLE) wParam) != NULL && proto->isOnline) { - SendPicture(proto, hContact); - } + HANDLE hContact = (HANDLE)wParam; + if (hContact != NULL && isOnline) + SendPicture(this, hContact); + return 0; } -INT_PTR TlenMenuHandleInbox(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::MenuHandleInbox(WPARAM wParam, LPARAM lParam) { char szFileName[ MAX_PATH ]; DBVARIANT dbv; @@ -189,20 +182,19 @@ INT_PTR TlenMenuHandleInbox(void *ptr, LPARAM wParam, LPARAM lParam) char *login = NULL, *password = NULL; char form[1024]; char cookie[1024]; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!db_get(NULL, proto->m_szModuleName, "LoginName", &dbv)) { + if (!db_get(NULL, m_szModuleName, "LoginName", &dbv)) { login = mir_strdup(dbv.pszVal); db_free(&dbv); } - if (db_get_b(NULL, proto->m_szModuleName, "SavePassword", TRUE) == TRUE) { - if (!db_get(NULL, proto->m_szModuleName, "Password", &dbv)) { + if (db_get_b(NULL, m_szModuleName, "SavePassword", TRUE) == TRUE) { + if (!db_get(NULL, m_szModuleName, "Password", &dbv)) { CallService(MS_DB_CRYPT_DECODESTRING, strlen(dbv.pszVal)+1, (LPARAM) dbv.pszVal); password = mir_strdup(dbv.pszVal); db_free(&dbv); } - } else if (proto->threadData != NULL && strlen(proto->threadData->password) > 0) { - password = mir_strdup(proto->threadData->password); } + else if (threadData != NULL && strlen(threadData->password) > 0) + password = mir_strdup(threadData->password); ZeroMemory(&cookie, sizeof(cookie)); if (login != NULL && password != NULL) { @@ -218,7 +210,7 @@ INT_PTR TlenMenuHandleInbox(void *ptr, LPARAM wParam, LPARAM lParam) req.pData = form; req.dataLength = (int)strlen(form); req.szUrl = "http://poczta.o2.pl/login.html"; - resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)proto->hNetlibUser, (LPARAM)&req); + resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&req); if (resp != NULL) { if (resp->resultCode/100 == 2 || resp->resultCode == 302) { int i; @@ -247,141 +239,133 @@ INT_PTR TlenMenuHandleInbox(void *ptr, LPARAM wParam, LPARAM lParam) return 0; } -int TlenOnModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::OnModulesLoaded(WPARAM wParam, LPARAM lParam) { char str[128]; - TlenProtocol *proto = (TlenProtocol *)ptr; /* Set all contacts to offline */ - for (HANDLE hContact = db_find_first(proto->m_szModuleName); hContact; hContact = db_find_next(hContact, proto->m_szModuleName)) - if (db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) - db_set_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE); + for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + if (db_get_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) + db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE); - TlenMUCInit(proto); + TlenMUCInit(this); mir_snprintf(str, SIZEOF(str), "%s", LPGEN("Incoming mail")); - SkinAddNewSoundEx("TlenMailNotify", proto->m_szModuleName, str); + SkinAddNewSoundEx("TlenMailNotify", m_szModuleName, str); mir_snprintf(str, SIZEOF(str), "%s", LPGEN("Alert")); - SkinAddNewSoundEx("TlenAlertNotify", proto->m_szModuleName, str); + SkinAddNewSoundEx("TlenAlertNotify", m_szModuleName, str); mir_snprintf(str, SIZEOF(str), "%s", LPGEN("Voice chat")); - SkinAddNewSoundEx("TlenVoiceNotify", proto->m_szModuleName, str); - - HookEventObj_Ex(ME_USERINFO_INITIALISE, proto, TlenUserInfoInit); + SkinAddNewSoundEx("TlenVoiceNotify", m_szModuleName, str); + HookProtoEvent(ME_USERINFO_INITIALISE, &TlenProtocol::UserInfoInit); return 0; } -int TlenPreShutdown(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::PreShutdown(WPARAM wParam, LPARAM lParam) { - TlenProtocol *proto = (TlenProtocol *)ptr; - JabberLog(proto, "TLEN TlenPreShutdown"); + JabberLog(this, "TLEN TlenPreShutdown"); return 0; } - -static void initMenuItems(TlenProtocol *proto) +void TlenProtocol::initMenuItems() { char text[_MAX_PATH]; + strncpy_s(text, sizeof(text), m_szModuleName, _TRUNCATE); + char *pSvcName = text + strlen(text); CLISTMENUITEM mi = { sizeof(mi) }, clmi = { sizeof(clmi) }; clmi.flags = CMIM_FLAGS | CMIF_GRAYED; - mi.pszContactOwner = proto->m_szModuleName; + mi.pszContactOwner = m_szModuleName; mi.popupPosition = 500090000; - strcpy(text, proto->m_szModuleName); + strcpy(text, m_szModuleName); mi.pszService = text; - mi.ptszName = proto->m_tszUserName; + mi.ptszName = m_tszUserName; mi.position = -1999901009; - mi.pszPopupName = (char *)-1; + mi.hParentMenu = HGENMENU_ROOT; mi.flags = CMIF_ROOTPOPUP | CMIF_TCHAR; mi.icolibItem = GetIconHandle(IDI_TLEN); - proto->hMenuRoot = Menu_AddMainMenuItem(&mi); + hMenuRoot = Menu_AddMainMenuItem(&mi); mi.flags = CMIF_CHILDPOPUP; - //mi.pszPopupName = (char *)proto->hMenuRoot; - mi.hParentMenu = (HGENMENU)proto->hMenuRoot; - - proto->hMenuChats = NULL; - if (ServiceExists(MS_MUCC_NEW_WINDOW)) - { - mir_snprintf(text, SIZEOF(text), "%s/MainMenuChats", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenMUCMenuHandleChats); + //mi.pszPopupName = (char *)hMenuRoot; + mi.hParentMenu = (HGENMENU)hMenuRoot; + + hMenuChats = NULL; + if ( ServiceExists(MS_MUCC_NEW_WINDOW)) { + strcpy(pSvcName, "/MainMenuChats"); + CreateProtoService(pSvcName, &TlenProtocol::MUCMenuHandleChats); mi.pszName = LPGEN("Tlen Chats"); mi.position = 2000050001; mi.icolibItem = GetIconHandle(IDI_CHATS); - mi.pszService = text; - proto->hMenuChats = Menu_AddMainMenuItem(&mi); - Menu_ModifyItem(proto->hMenuChats, &clmi); + hMenuChats = Menu_AddMainMenuItem(&mi); + Menu_ModifyItem(hMenuChats, &clmi); } // "Multi-User Conference" - mir_snprintf(text, SIZEOF(text), "%s/MainMenuMUC", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenMUCMenuHandleMUC); + strcpy(pSvcName, "/MainMenuMUC"); + CreateProtoService(pSvcName, &TlenProtocol::MUCMenuHandleMUC); mi.pszName = LPGEN("Multi-User Conference"); mi.position = 2000050002; mi.icolibItem = GetIconHandle(IDI_MUC); mi.pszService = text; - proto->hMenuMUC = Menu_AddMainMenuItem(&mi); - Menu_ModifyItem(proto->hMenuMUC, &clmi); + hMenuMUC = Menu_AddMainMenuItem(&mi); + Menu_ModifyItem(hMenuMUC, &clmi); - mir_snprintf(text, SIZEOF(text), "%s/MainMenuInbox", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenMenuHandleInbox); + strcpy(pSvcName, "/MainMenuInbox"); + CreateProtoService(pSvcName, &TlenProtocol::MenuHandleInbox); mi.pszName = LPGEN("Tlen Mail"); mi.position = 2000050003; mi.icolibItem = GetIconHandle(IDI_MAIL); mi.pszService = text; - proto->hMenuInbox = Menu_AddMainMenuItem(&mi); + hMenuInbox = Menu_AddMainMenuItem(&mi); mi.hParentMenu = NULL; // "Send picture" - mir_snprintf(text, SIZEOF(text), "%s/SendPicture", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenContactMenuHandleSendPicture); + strcpy(pSvcName, "/SendPicture"); + CreateProtoService(pSvcName, &TlenProtocol::ContactMenuHandleSendPicture); mi.pszName = LPGEN("Send picture"); mi.position = -2000019030; mi.icolibItem = GetIconHandle(IDI_IMAGE); - mi.pszService = text; - proto->hMenuPicture = Menu_AddContactMenuItem(&mi); + hMenuPicture = Menu_AddContactMenuItem(&mi); // "Invite to MUC" - mir_snprintf(text, SIZEOF(text), "%s/ContactMenuMUC", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenMUCContactMenuHandleMUC); + strcpy(pSvcName, "/ContactMenuMUC"); + CreateProtoService(pSvcName, &TlenProtocol::MUCContactMenuHandleMUC); mi.pszName = LPGEN("Multi-User Conference"); mi.position = -2000019020; mi.icolibItem = GetIconHandle(IDI_MUC); - mi.pszService = text; - proto->hMenuContactMUC = Menu_AddContactMenuItem(&mi); + hMenuContactMUC = Menu_AddContactMenuItem(&mi); // "Invite to voice chat" - mir_snprintf(text, SIZEOF(text), "%s/ContactMenuVoice", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenVoiceContactMenuHandleVoice); + strcpy(pSvcName, "/ContactMenuVoice"); + CreateProtoService(pSvcName, &TlenProtocol::VoiceContactMenuHandleVoice); mi.pszName = LPGEN("Voice Chat"); mi.position = -2000019010; mi.icolibItem = GetIconHandle(IDI_VOICE); - mi.pszService = text; - proto->hMenuContactVoice = Menu_AddContactMenuItem(&mi); + hMenuContactVoice = Menu_AddContactMenuItem(&mi); // "Request authorization" - mir_snprintf(text, SIZEOF(text), "%s/RequestAuth", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenContactMenuHandleRequestAuth); + strcpy(pSvcName, "/RequestAuth"); + CreateProtoService(pSvcName, &TlenProtocol::ContactMenuHandleRequestAuth); mi.pszName = LPGEN("Request authorization"); mi.position = -2000001001; mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST); - mi.pszService = text; - proto->hMenuContactRequestAuth = Menu_AddContactMenuItem(&mi); + hMenuContactRequestAuth = Menu_AddContactMenuItem(&mi); // "Grant authorization" - mir_snprintf(text, SIZEOF(text), "%s/GrantAuth", proto->m_szModuleName); - CreateServiceFunction_Ex(text, proto, TlenContactMenuHandleGrantAuth); + strcpy(pSvcName, "/GrantAuth"); + CreateProtoService(pSvcName, &TlenProtocol::ContactMenuHandleGrantAuth); mi.pszName = LPGEN("Grant authorization"); mi.position = -2000001000; mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_GRANT); - mi.pszService = text; - proto->hMenuContactGrantAuth = Menu_AddContactMenuItem(&mi); + hMenuContactGrantAuth = Menu_AddContactMenuItem(&mi); } -void uninitMenuItems(TlenProtocol *proto) { +void uninitMenuItems(TlenProtocol *proto) +{ CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)proto->hMenuChats, (LPARAM) 0); CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)proto->hMenuMUC, (LPARAM) 0); CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)proto->hMenuInbox, (LPARAM) 0); @@ -393,23 +377,13 @@ void uninitMenuItems(TlenProtocol *proto) { CallService(MS_CLIST_REMOVECONTACTMENUITEM, (WPARAM)proto->hMenuContactGrantAuth, (LPARAM) 0); } -TlenProtocol* tlenProtoInit( const char* pszProtoName, const TCHAR* tszUserName ) +TlenProtocol* tlenProtoInit(const char* pszProtoName, const TCHAR* tszUserName) { TlenProtocol* ppro = new TlenProtocol( pszProtoName, tszUserName ); - return ppro; } -int TlenSystemModulesLoaded(void *ptr, WPARAM wParam, LPARAM lParam) -{ - - TlenProtocol *proto = (TlenProtocol *)ptr; - initMenuItems(proto); - - return 0; -} - -static int tlenProtoUninit( TlenProtocol* ppro ) +static int tlenProtoUninit(TlenProtocol* ppro) { delete ppro; return 0; diff --git a/protocols/Tlen/src/tlen_muc.cpp b/protocols/Tlen/src/tlen_muc.cpp index 507a4fa6cc..fbf72e8ee6 100644 --- a/protocols/Tlen/src/tlen_muc.cpp +++ b/protocols/Tlen/src/tlen_muc.cpp @@ -68,7 +68,6 @@ static int stringToHex(const char *str) } static char *getDisplayName(TlenProtocol *proto, const char *id) { - CONTACTINFO ci; char jid[256]; HANDLE hContact; DBVARIANT dbv; @@ -76,8 +75,7 @@ static char *getDisplayName(TlenProtocol *proto, const char *id) mir_snprintf(jid, sizeof(jid), "%s@%s", id, dbv.pszVal); db_free(&dbv); if (((hContact=JabberHContactFromJID(proto, jid)) != NULL) || !strcmp(id, proto->threadData->username)) { - ZeroMemory(&ci, sizeof(ci)); - ci.cbSize = sizeof(ci); + CONTACTINFO ci = { sizeof(ci) }; ci.hContact = hContact; ci.szProto = (char *)proto->m_szModuleName; ci.dwFlag = CNF_DISPLAY; @@ -97,176 +95,172 @@ static char *getDisplayName(TlenProtocol *proto, const char *id) BOOL TlenMUCInit(TlenProtocol *proto) { - HookEventObj_Ex(ME_MUCC_EVENT, proto, TlenMUCHandleEvent); + proto->HookProtoEvent(ME_MUCC_EVENT, &TlenProtocol::MUCHandleEvent); return 0; } -static int TlenMUCHandleEvent(void *ptr, WPARAM wParam, LPARAM lParam) + +int TlenProtocol::MUCHandleEvent(WPARAM wParam, LPARAM lParam) { HANDLE hContact; int id; MUCCEVENT *mucce=(MUCCEVENT *) lParam; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!strcmp(mucce->pszModule, proto->m_szModuleName)) { + if (!strcmp(mucce->pszModule, m_szModuleName)) { switch (mucce->iType) { - case MUCC_EVENT_INVITE: - TlenMUCSendInvitation(proto, mucce->pszID, mucce->pszNick); - break; - case MUCC_EVENT_MESSAGE: - TlenMUCSendMessage(proto, mucce); - break; - case MUCC_EVENT_TOPIC: - TlenMUCSendTopic(proto, mucce); - break; - case MUCC_EVENT_LEAVE: - TlenMUCSendPresence(proto, mucce->pszID, NULL, ID_STATUS_OFFLINE); - break; - case MUCC_EVENT_QUERY_GROUPS: - TlenMUCSendQuery(proto, 1, mucce->pszID, 0); - break; - case MUCC_EVENT_QUERY_ROOMS: - TlenMUCSendQuery(proto, 2, mucce->pszID, mucce->dwData); - break; - case MUCC_EVENT_QUERY_SEARCH: - TlenMUCSendQuery(proto, 3, mucce->pszName, 0); + case MUCC_EVENT_INVITE: + TlenMUCSendInvitation(this, mucce->pszID, mucce->pszNick); + break; + case MUCC_EVENT_MESSAGE: + TlenMUCSendMessage(this, mucce); + break; + case MUCC_EVENT_TOPIC: + TlenMUCSendTopic(this, mucce); + break; + case MUCC_EVENT_LEAVE: + TlenMUCSendPresence(this, mucce->pszID, NULL, ID_STATUS_OFFLINE); + break; + case MUCC_EVENT_QUERY_GROUPS: + TlenMUCSendQuery(this, 1, mucce->pszID, 0); + break; + case MUCC_EVENT_QUERY_ROOMS: + TlenMUCSendQuery(this, 2, mucce->pszID, mucce->dwData); + break; + case MUCC_EVENT_QUERY_SEARCH: + TlenMUCSendQuery(this, 3, mucce->pszName, 0); + break; + case MUCC_EVENT_QUERY_USERS: + switch (mucce->dwFlags) { + case MUCC_EF_USER_OWNER: + id = 1; break; - case MUCC_EVENT_QUERY_USERS: - switch (mucce->dwFlags) { - case MUCC_EF_USER_OWNER: - id = 1; - break; - case MUCC_EF_USER_ADMIN: - id = 2; - break; - case MUCC_EF_USER_MEMBER: - id = 3; - break; - case MUCC_EF_USER_BANNED: - id = 4; - break; - case MUCC_EF_USER_MODERATOR: - id = 6; - break; - default: - id = 0; - } - TlenMUCSendQuery(proto, 4, mucce->pszID, id); + case MUCC_EF_USER_ADMIN: + id = 2; break; - case MUCC_EVENT_REGISTER_NICK: - TlenMUCSendQuery(proto, 6, mucce->pszNick, 0); + case MUCC_EF_USER_MEMBER: + id = 3; break; - case MUCC_EVENT_REMOVE_NICK: - TlenMUCSendQuery(proto, 6, mucce->pszNick, 1); + case MUCC_EF_USER_BANNED: + id = 4; break; - case MUCC_EVENT_REGISTER_ROOM: - id = JabberSerialNext(proto); - if (proto->isOnline) { - if (mucce->pszNick != NULL) { - JabberSend(proto, "

", id, mucce->dwFlags | 0x10, mucce->pszName, mucce->pszID); - } else { - JabberSend(proto, "

", id, mucce->dwFlags | 0x10, mucce->pszName, mucce->pszID); - } - } + case MUCC_EF_USER_MODERATOR: + id = 6; break; - case MUCC_EVENT_REMOVE_ROOM: - if (proto->isOnline) { - JabberSend(proto, "

", mucce->pszID); - JabberListRemove(proto, LIST_CHATROOM, mucce->pszID); + default: + id = 0; + } + TlenMUCSendQuery(this, 4, mucce->pszID, id); + break; + case MUCC_EVENT_REGISTER_NICK: + TlenMUCSendQuery(this, 6, mucce->pszNick, 0); + break; + case MUCC_EVENT_REMOVE_NICK: + TlenMUCSendQuery(this, 6, mucce->pszNick, 1); + break; + case MUCC_EVENT_REGISTER_ROOM: + id = JabberSerialNext(this); + if (isOnline) { + if (mucce->pszNick != NULL) + JabberSend(this, "

", id, mucce->dwFlags | 0x10, mucce->pszName, mucce->pszID); + else + JabberSend(this, "

", id, mucce->dwFlags | 0x10, mucce->pszName, mucce->pszID); + } + break; + case MUCC_EVENT_REMOVE_ROOM: + if (isOnline) { + JabberSend(this, "

", mucce->pszID); + JabberListRemove(this, LIST_CHATROOM, mucce->pszID); // TlenMUCSendPresence(mucce->pszID, NULL, ID_STATUS_OFFLINE); + } + break; + case MUCC_EVENT_KICK_BAN: + if (isOnline) { + char *nick; + nick = JabberResourceFromJID(mucce->pszUID); + if (!isSelf(this, mucce->pszID, nick)) { + char *reason = JabberTextEncode(mucce->pszText); + JabberSend(this, "

", mucce->pszID, nick, mucce->dwData, reason); + mir_free(reason); } - break; - case MUCC_EVENT_KICK_BAN: - if (proto->isOnline) { - char *nick; - nick = JabberResourceFromJID(mucce->pszUID); - if (!isSelf(proto, mucce->pszID, nick)) { - char *reason = JabberTextEncode(mucce->pszText); - JabberSend(proto, "

", mucce->pszID, nick, mucce->dwData, reason); - mir_free(reason); - } - mir_free(nick); + mir_free(nick); + } + break; + case MUCC_EVENT_UNBAN: + if (isOnline) { + char *nick; + nick = JabberResourceFromJID(mucce->pszUID); + if (!isSelf(this, mucce->pszID, nick)) { + JabberSend(this, "

", mucce->pszID, nick); } - break; - case MUCC_EVENT_UNBAN: - if (proto->isOnline) { - char *nick; - nick = JabberResourceFromJID(mucce->pszUID); - if (!isSelf(proto, mucce->pszID, nick)) { - JabberSend(proto, "

", mucce->pszID, nick); + mir_free(nick); + } + break; + case MUCC_EVENT_SET_USER_ROLE: + if (isOnline) { + char *nick; + nick = JabberResourceFromJID(mucce->pszUID); + if (!isSelf(this, mucce->pszID, nick)) { + if (mucce->dwFlags == MUCC_EF_USER_ADMIN) { + id = 2; + } else if (mucce->dwFlags == MUCC_EF_USER_MEMBER) { + id = 3; + } else { + id = 0; } - mir_free(nick); + JabberSend(this, "

", mucce->pszID, nick, id); } - break; - case MUCC_EVENT_SET_USER_ROLE: - if (proto->isOnline) { - char *nick; - nick = JabberResourceFromJID(mucce->pszUID); - if (!isSelf(proto, mucce->pszID, nick)) { - if (mucce->dwFlags == MUCC_EF_USER_ADMIN) { - id = 2; - } else if (mucce->dwFlags == MUCC_EF_USER_MEMBER) { - id = 3; - } else { - id = 0; - } - JabberSend(proto, "

", mucce->pszID, nick, id); + mir_free(nick); + } + break; + case MUCC_EVENT_QUERY_USER_NICKS: + TlenMUCSendQuery(this, 7, mucce->pszID, 0); + break; + case MUCC_EVENT_QUERY_USER_ROOMS: + TlenMUCSendQuery(this, 8, mucce->pszID, 0); + break; + case MUCC_EVENT_QUERY_CONTACTS: + TlenMUCQueryContacts(this, mucce->pszID); + break; + case MUCC_EVENT_JOIN: + if (isOnline) { + if (mucce->pszID == NULL || strlen(mucce->pszID) == 0) { + if (mucce->pszName == NULL || strlen(mucce->pszName) == 0) { // create a new chat room + id = JabberSerialNext(this); + JabberSend(this, "

", id); } - mir_free(nick); + else TlenMUCSendQuery(this, 3, mucce->pszName, 0); // find a chat room by name } - break; - case MUCC_EVENT_QUERY_USER_NICKS: - TlenMUCSendQuery(proto, 7, mucce->pszID, 0); - break; - case MUCC_EVENT_QUERY_USER_ROOMS: - TlenMUCSendQuery(proto, 8, mucce->pszID, 0); - break; - case MUCC_EVENT_QUERY_CONTACTS: - TlenMUCQueryContacts(proto, mucce->pszID); - break; - case MUCC_EVENT_JOIN: - if (proto->isOnline) { - if (mucce->pszID == NULL || strlen(mucce->pszID) == 0) { - if (mucce->pszName == NULL || strlen(mucce->pszName) == 0) { // create a new chat room - id = JabberSerialNext(proto); - JabberSend(proto, "

", id); - } else { // find a chat room by name - TlenMUCSendQuery(proto, 3, mucce->pszName, 0); - } - } else { // join existing chat room - if (!TlenMUCCreateWindow(proto, mucce->pszID, mucce->pszName, mucce->dwFlags, mucce->pszNick, NULL)) { - TlenMUCSendPresence(proto, mucce->pszID, mucce->pszNick, ID_STATUS_ONLINE); + else // join existing chat room + if (!TlenMUCCreateWindow(this, mucce->pszID, mucce->pszName, mucce->dwFlags, mucce->pszNick, NULL)) + TlenMUCSendPresence(this, mucce->pszID, mucce->pszNick, ID_STATUS_ONLINE); + } + break; + case MUCC_EVENT_START_PRIV: + if (isOnline) { + JABBER_LIST_ITEM *item = JabberListGetItemPtr(this, LIST_CHATROOM, mucce->pszID); + if (item != NULL) { + char *nick = JabberResourceFromJID(mucce->pszUID); + if (!isSelf(this, mucce->pszID, nick)) { + if (nick[0] == '~' || item->nick != NULL) { + char str[256]; + mir_snprintf(str, SIZEOF(str), "%s/%s", mucce->pszID, nick); + hContact = JabberDBCreateContact(this, str, nick, TRUE); //(char *)mucce->pszUID + db_set_b(hContact, m_szModuleName, "bChat", TRUE); + CallService(MS_MSG_SENDMESSAGE, (WPARAM) hContact, (LPARAM) NULL); } - } - } - break; - case MUCC_EVENT_START_PRIV: - if (proto->isOnline) { - JABBER_LIST_ITEM *item; - item = JabberListGetItemPtr(proto, LIST_CHATROOM, mucce->pszID); - if (item != NULL) { - char *nick; - nick = JabberResourceFromJID(mucce->pszUID); - if (!isSelf(proto, mucce->pszID, nick)) { - if (nick[0] == '~' || item->nick != NULL) { - char str[256]; - mir_snprintf(str, SIZEOF(str), "%s/%s", mucce->pszID, nick); - hContact = JabberDBCreateContact(proto, str, nick, TRUE); //(char *)mucce->pszUID - db_set_b(hContact, proto->m_szModuleName, "bChat", TRUE); + else { + DBVARIANT dbv; + if (!db_get(NULL, m_szModuleName, "LoginServer", &dbv)) { + char str[512]; + mir_snprintf(str, sizeof(str), "%s@%s", nick, dbv.pszVal); + db_free(&dbv); + hContact = JabberDBCreateContact(this, str, nick, TRUE); CallService(MS_MSG_SENDMESSAGE, (WPARAM) hContact, (LPARAM) NULL); - } else { - DBVARIANT dbv; - if (!db_get(NULL, proto->m_szModuleName, "LoginServer", &dbv)) { - char str[512]; - mir_snprintf(str, sizeof(str), "%s@%s", nick, dbv.pszVal); - db_free(&dbv); - hContact = JabberDBCreateContact(proto, str, nick, TRUE); - CallService(MS_MSG_SENDMESSAGE, (WPARAM) hContact, (LPARAM) NULL); - } } } - mir_free(nick); } + mir_free(nick); } - break; + } + break; } } return 0; @@ -1006,60 +1000,44 @@ static int TlenMUCQueryContacts(TlenProtocol *proto, const char *roomId) { return 1; } -INT_PTR TlenMUCMenuHandleMUC(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::MUCMenuHandleMUC(WPARAM wParam, LPARAM lParam) { - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!proto->isOnline) { + if (!isOnline) return 1; - } - JabberSend(proto, "

", JabberSerialNext(proto)); - /* - MUCCEVENT *mucce; - mucce = (MUCCEVENT *) mir_alloc (sizeof(MUCCEVENT)); - mucce->cbSize = sizeof(MUCCEVENT); - mucce->iType = MUCC_EVENT_JOIN; - mucce->dwFlags = 0; - mucce->pszModule = proto->m_szModuleName; - mucce->pszID = NULL; - mucce->pszName = NULL; - mucce->pszNick = NULL; - CallService(MS_MUCC_EVENT, 0, (LPARAM) mucce); - mir_free(mucce); - */ + + JabberSend(this, "

", JabberSerialNext(this)); return 0; } -INT_PTR TlenMUCMenuHandleChats(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::MUCMenuHandleChats(WPARAM wParam, LPARAM lParam) { - MUCCWINDOW mucw; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!proto->isOnline) { + if (!isOnline) return 1; - } + + MUCCWINDOW mucw; mucw.cbSize = sizeof(MUCCWINDOW); mucw.iType = MUCC_WINDOW_CHATLIST; - mucw.pszModule = proto->m_szModuleName; - mucw.pszModuleName = proto->m_szModuleName; + mucw.pszModule = m_szModuleName; + mucw.pszModuleName = m_szModuleName; CallService(MS_MUCC_NEW_WINDOW, 0, (LPARAM) &mucw); return 0; } -INT_PTR TlenMUCContactMenuHandleMUC(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::MUCContactMenuHandleMUC(WPARAM wParam, LPARAM lParam) { HANDLE hContact; DBVARIANT dbv; JABBER_LIST_ITEM *item; - TlenProtocol *proto = (TlenProtocol *)ptr; - if (!proto->isOnline) { + if (!isOnline) return 1; - } - if ((hContact=(HANDLE) wParam) != NULL && proto->isOnline) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { + + if ((hContact=(HANDLE) wParam) != NULL && isOnline) { + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { char serialId[32]; - mir_snprintf(serialId, SIZEOF(serialId), JABBER_IQID"%d", JabberSerialNext(proto)); - item = JabberListAdd(proto, LIST_INVITATIONS, serialId); + mir_snprintf(serialId, SIZEOF(serialId), JABBER_IQID"%d", JabberSerialNext(this)); + item = JabberListAdd(this, LIST_INVITATIONS, serialId); item->nick = mir_strdup(dbv.pszVal); - JabberSend(proto, "

", serialId); + JabberSend(this, "

", serialId); db_free(&dbv); } } diff --git a/protocols/Tlen/src/tlen_muc.h b/protocols/Tlen/src/tlen_muc.h index 8409315ecd..2e4b0995d1 100644 --- a/protocols/Tlen/src/tlen_muc.h +++ b/protocols/Tlen/src/tlen_muc.h @@ -32,9 +32,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define USER_FLAGS_KICKED 0x80 extern BOOL TlenMUCInit(TlenProtocol *proto); -extern INT_PTR TlenMUCMenuHandleMUC(void *ptr, LPARAM wParam, LPARAM lParam); -extern INT_PTR TlenMUCMenuHandleChats(void *ptr, LPARAM wParam, LPARAM lParam); -extern INT_PTR TlenMUCContactMenuHandleMUC(void *ptr, LPARAM wParam, LPARAM lParam); extern int TlenMUCCreateWindow(TlenProtocol *proto, const char *roomID, const char *roomName, int roomFlags, const char *nick, const char *iqId); extern int TlenMUCRecvInvitation(TlenProtocol *proto, const char *roomJid, const char *roomName, const char *from, const char *reason); extern int TlenMUCRecvPresence(TlenProtocol *proto, const char *from, int status, int flags, const char *kick); diff --git a/protocols/Tlen/src/tlen_userinfo.cpp b/protocols/Tlen/src/tlen_userinfo.cpp index 933841fd3f..8361bbee92 100644 --- a/protocols/Tlen/src/tlen_userinfo.cpp +++ b/protocols/Tlen/src/tlen_userinfo.cpp @@ -127,33 +127,28 @@ static void FetchCombo(HWND hwndDlg, UINT idCtrl, char *fieldName, char **str, i } } - -int TlenUserInfoInit(void *ptr, WPARAM wParam, LPARAM lParam) +int TlenProtocol::UserInfoInit(WPARAM wParam, LPARAM lParam) { - char *szProto; - HANDLE hContact; - OPTIONSDIALOGPAGE odp = {0}; - TlenProtocol *proto = (TlenProtocol *)ptr; - - if (!CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM) proto->m_szModuleName)) + if (!CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM)m_szModuleName)) return 0; - hContact = (HANDLE) lParam; - szProto = GetContactProto(hContact); - if ((szProto != NULL && !strcmp(szProto, proto->m_szModuleName)) || !lParam) { - odp.cbSize = sizeof(odp); + + HANDLE hContact = (HANDLE) lParam; + char *szProto = GetContactProto(hContact); + if ((szProto != NULL && !strcmp(szProto, m_szModuleName)) || !lParam) { + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.hInstance = hInst; odp.flags = ODPF_TCHAR; odp.pfnDlgProc = TlenUserInfoDlgProc; odp.position = -2000000000; odp.pszTemplate = ((HANDLE)lParam != NULL) ? MAKEINTRESOURCEA(IDD_USER_INFO):MAKEINTRESOURCEA(IDD_USER_VCARD); - odp.ptszTitle = (hContact != NULL) ? LPGENT("Account") : proto->m_tszUserName; - odp.dwInitParam = (LPARAM)proto; + odp.ptszTitle = (hContact != NULL) ? LPGENT("Account") : m_tszUserName; + odp.dwInitParam = (LPARAM)this; UserInfo_AddPage(wParam, &odp); } - if (!lParam && proto->isOnline) { + if (!lParam && isOnline) { CCSDATA ccs = {0}; - proto->GetInfo(0, (LPARAM) &ccs); + GetInfo(0, (LPARAM) &ccs); } return 0; } diff --git a/protocols/Tlen/src/tlen_voice.cpp b/protocols/Tlen/src/tlen_voice.cpp index ccf735ead5..2c81755c6d 100644 --- a/protocols/Tlen/src/tlen_voice.cpp +++ b/protocols/Tlen/src/tlen_voice.cpp @@ -697,26 +697,23 @@ int TlenVoiceCancelAll(TlenProtocol *proto) return 0; } -INT_PTR TlenVoiceContactMenuHandleVoice(void *ptr, LPARAM wParam, LPARAM lParam) +int TlenProtocol::VoiceContactMenuHandleVoice(WPARAM wParam, LPARAM lParam) { HANDLE hContact; DBVARIANT dbv; JABBER_LIST_ITEM *item; TLEN_FILE_TRANSFER *ft; - TlenProtocol *proto =(TlenProtocol *)ptr; - if (!proto->isOnline) { + if (!isOnline) return 1; - } + if ((hContact=(HANDLE) wParam) != NULL) { - if (!db_get(hContact, proto->m_szModuleName, "jid", &dbv)) { + if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { char serialId[32]; - mir_snprintf(serialId, SIZEOF(serialId), "%d", JabberSerialNext(proto)); - if ((item = JabberListAdd(proto, LIST_VOICE, serialId)) != NULL) { - ft = TlenFileCreateFT(proto, dbv.pszVal); + mir_snprintf(serialId, SIZEOF(serialId), "%d", JabberSerialNext(this)); + if ((item = JabberListAdd(this, LIST_VOICE, serialId)) != NULL) { + ft = TlenFileCreateFT(this, dbv.pszVal); ft->iqId = mir_strdup(serialId); item->ft = ft; -// JabberSend(ft->proto, "", ft->jid); -// Sleep(5000); TlenVoiceStart(ft, 2); JabberSend(ft->proto, "", ft->jid, serialId); } diff --git a/protocols/Tlen/src/tlen_voice.h b/protocols/Tlen/src/tlen_voice.h index 0018bb6e17..cbd71aa1f1 100644 --- a/protocols/Tlen/src/tlen_voice.h +++ b/protocols/Tlen/src/tlen_voice.h @@ -57,14 +57,15 @@ typedef struct TLEN_VOICE_CONTROL_STRUCT { } TLEN_VOICE_CONTROL; -extern void __cdecl TlenVoiceSendingThread(TLEN_FILE_TRANSFER *ft); -extern void __cdecl TlenVoiceReceiveThread(TLEN_FILE_TRANSFER *ft); -extern int TlenVoiceIsInUse(TlenProtocol *proto); -extern INT_PTR TlenVoiceContactMenuHandleVoice(void *ptr, LPARAM wParam, LPARAM lParam); -extern int TlenVoiceCancelAll(TlenProtocol *proto); -extern int TlenVoiceStart(TLEN_FILE_TRANSFER *ft, int mode) ; -extern int TlenVoiceAccept(TlenProtocol *proto, const char *id, const char *from); -extern int TlenVoiceBuildInDeviceList(TlenProtocol *proto, HWND hWnd); -extern int TlenVoiceBuildOutDeviceList(TlenProtocol *proto, HWND hWnd); +void __cdecl TlenVoiceSendingThread(TLEN_FILE_TRANSFER *ft); +void __cdecl TlenVoiceReceiveThread(TLEN_FILE_TRANSFER *ft); + +int TlenVoiceStart(TLEN_FILE_TRANSFER *ft, int mode) ; +int TlenVoiceAccept(TlenProtocol *proto, const char *id, const char *from); +int TlenVoiceIsInUse(TlenProtocol *proto); +int TlenVoiceCancelAll(TlenProtocol *proto); +int TlenVoiceBuildInDeviceList(TlenProtocol *proto, HWND hWnd); +int TlenVoiceBuildOutDeviceList(TlenProtocol *proto, HWND hWnd); + #endif -- cgit v1.2.3