From e68198eeb9354cff251ace01418abdb6c8dff828 Mon Sep 17 00:00:00 2001 From: sje Date: Thu, 26 Apr 2007 07:57:15 +0000 Subject: attempt to send termination message when proto 'Status' db setting changes to offline (UNTESTED) git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@155 4f64403b-2f21-0410-a795-97e2b3489a10 --- otr/dllmain.cpp | 86 +++++++++++++++++++++++++++++++++++++++---------------- otr/otr.mdsp | 35 ++++++++++++++++++---- otr/otr_private.h | 4 +-- 3 files changed, 93 insertions(+), 32 deletions(-) diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp index 42aa052..7780324 100644 --- a/otr/dllmain.cpp +++ b/otr/dllmain.cpp @@ -483,38 +483,73 @@ void Disconnect(ConnContext *context) { /// Miranda filter plugin stuff ////////////////////////////////////////////////// +// if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol +// (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) +int StatusModeChange(WPARAM wParam, LPARAM lParam) { + int status = (int)wParam; + const char *proto = (char *)lParam; + HANDLE hContact; + + lib_cs_lock(); + if(status == ID_STATUS_OFFLINE) { + ConnContext *context = otr_user_state->context_root; + while(context) { + if(context->msgstate == OTRL_MSGSTATE_ENCRYPTED && (proto == 0 || strcmp(proto, context->protocol) == 0)) { + hContact = context->app_data; + + char *uproto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + char *uname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); + otrl_message_disconnect(otr_user_state, &ops, hContact, MODULE, uproto, uname); + //otrl_context_force_finished(context); + + SetEncryptionStatus(hContact, false); + + } + context = context->next; + } + } + lib_cs_unlock(); + + return 0; +} + int SettingChanged(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; - // only care about contacts - if(!hContact) return 0; - - // to which this filter is attached - if(!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULE)) + // only care about contacts to which this filter is attached + if(hContact && !CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULE)) return 0; // and who are changing status to offline if(strcmp(cws->szSetting, "Status") == 0 && cws->value.type != DBVT_DELETED && cws->value.wVal == ID_STATUS_OFFLINE) { - char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - char *uname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); - if(!proto || !uname) return 0; // error - just bail - - lib_cs_lock(); - ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0); + if(!hContact) { + // if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol + const char *proto = cws->szModule; + StatusModeChange((WPARAM)ID_STATUS_OFFLINE, (LPARAM)proto); + return 0; + } else { + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + char *uname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); + if(!proto || !uname) return 0; // error - just bail - if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { - otrl_message_disconnect(otr_user_state, &ops, hContact, MODULE, proto, uname); + lib_cs_lock(); + ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0); - // removed - don't need a popup everytime an OTR user goes offline! - //char buff[512]; - //mir_snprintf(buff, 512, Translate("User '%s' ended encrypted session"), uname); - //ShowPopup(Translate("OTR Information"), buff, 0); - - // opdata is hContact - SetEncryptionStatus(hContact, false); + if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { + //otrl_message_disconnect(otr_user_state, &ops, hContact, MODULE, proto, uname); + otrl_context_force_finished(context); + + // removed - don't need a popup everytime an OTR user goes offline! + //char buff[512]; + //mir_snprintf(buff, 512, Translate("User '%s' ended encrypted session"), uname); + //ShowPopup(Translate("OTR Information"), buff, 0); + + // opdata is hContact + SetEncryptionStatus(hContact, false); + } + lib_cs_unlock(); } - lib_cs_unlock(); } return 0; @@ -1005,10 +1040,6 @@ int StopOTR(WPARAM wParam, LPARAM lParam) { return 0; } -/////////////////////////////////////////////// -/////// Send OTR termination message to all active contexts when going offline -//////////////////////////////////////////////// -// TODO /////////////////////////////////////////////// /////// Plugin init and deinit @@ -1137,6 +1168,11 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { // hook setting changed to monitor status HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged); + // hook status mode changes to terminate sessions when we go offline + // (this would be hooked as the ME_CLIST_STATUSMODECHANGE handler except that event is sent *after* the proto goes offline) + // (instead, it's called from the SettingChanged handler for protocol status db setting changes) + //HookEvent(ME_CLIST_STATUSMODECHANGE, StatusModeChange); + return 0; } diff --git a/otr/otr.mdsp b/otr/otr.mdsp index cd54fdb..8d98d03 100644 --- a/otr/otr.mdsp +++ b/otr/otr.mdsp @@ -98,13 +98,38 @@ extraResourceOptions= 1=otr_private.rc 2=resource.rc [Other] +1=libotr\src\auth.c +2=libotr\src\auth.h +3=libotr\src\b64.c +4=libotr\src\b64.h +5=libotr\src\context.c +6=libotr\src\context.h +7=libotr\src\dh.c +8=libotr\src\dh.h +9=libotr\src\mem.c +10=libotr\src\mem.h +11=libotr\src\message.c +12=libotr\src\message.h +13=libotr\src\privkey-t.h +14=libotr\src\privkey.c +15=libotr\src\privkey.h +16=libotr\src\proto.c +17=libotr\src\proto.h +18=libotr\src\serial.h +19=libotr\src\tests.c +20=libotr\src\tlv.c +21=libotr\src\tlv.h +22=libotr\src\userstate.c +23=libotr\src\userstate.h +24=libotr\src\version.h [History] +dllmain.cpp,41476 utils.cpp,6882 common.h,2043 -otr_private.h,149 -libotr\src\context.h,6545 -libotr\src\context.c,1586 +libotr\src\context.h,6666 +libotr\src\context.c,0 libotr\src\message.h,6083 libotr\src\proto.h,5014 -libotr\src\userstate.h,0 -dllmain.cpp,35209 +libotr\src\userstate.h,1038 +libotr\src\message.c,36329 +otr_private.h,171 diff --git a/otr/otr_private.h b/otr/otr_private.h index ceb5b03..544012c 100644 --- a/otr/otr_private.h +++ b/otr/otr_private.h @@ -4,8 +4,8 @@ /* VERSION DEFINITIONS */ #define VER_MAJOR 0 #define VER_MINOR 5 -#define VER_RELEASE 0 -#define VER_BUILD 0 +#define VER_RELEASE 1 +#define VER_BUILD 1 #define __STRINGIZE(x) #x #define VER_STRING __STRINGIZE( VER_MAJOR.VER_MINOR.VER_RELEASE.VER_BUILD ) -- cgit v1.2.3