summaryrefslogtreecommitdiff
path: root/otr/dllmain.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-04-26 07:57:15 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-04-26 07:57:15 +0000
commite68198eeb9354cff251ace01418abdb6c8dff828 (patch)
treebccd457bd050781eb76a19a11e7fac6ab148b14f /otr/dllmain.cpp
parent7e7cfeab8b7debc69e136071dbab0cc9120968b8 (diff)
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
Diffstat (limited to 'otr/dllmain.cpp')
-rw-r--r--otr/dllmain.cpp86
1 files changed, 61 insertions, 25 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;
}