diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-05-17 22:51:32 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-05-17 22:51:32 +0000 |
commit | 7a2e5720ff22302dc2aaf923c2638f6569ed865f (patch) | |
tree | 63d2e2ee5912c36782c74c6ec2d90e2736a4ea90 | |
parent | 3f003cfd5b287775987d84450a0c00e0a12dfe57 (diff) |
show 'stop otr' menu item for finished sessions
unhook settingchanged
properly switch to finished state on reception of disconnected tlv
show messages (honouring 'option inline') for start/stop session
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@173 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r-- | otr/dllmain.cpp | 76 | ||||
-rw-r--r-- | otr/menu.cpp | 5 | ||||
-rw-r--r-- | otr/otr.mdsp | 30 | ||||
-rw-r--r-- | otr/otr_private.h | 4 |
4 files changed, 79 insertions, 36 deletions
diff --git a/otr/dllmain.cpp b/otr/dllmain.cpp index 7b67140..0d8c585 100644 --- a/otr/dllmain.cpp +++ b/otr/dllmain.cpp @@ -17,7 +17,7 @@ PLUGINLINK *pluginLink; HANDLE mainThread;
DWORD mainThreadId;
-HANDLE hEventDbEventAdded, hEventDbEventAddedFilter, hEventWindow, hEventIconPressed;
+HANDLE hEventDbEventAdded, hEventDbEventAddedFilter, hEventWindow, hEventIconPressed, hSettingChanged;
CRITICAL_SECTION lib_cs;
@@ -139,12 +139,19 @@ void ShowMessageInline(const HANDLE hContact, const char *msg) { // set SRMM icon status, if applicable
void SetEncryptionStatus(HANDLE hContact, bool encrypted) {
+ //char dbg_msg[2048];
+ //dbg_msg[0] = 0;
+
+ //strcat(dbg_msg, "Set encyption status: ");
+ //strcat(dbg_msg, (encrypted ? "true" : "false"));
+
char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
bool chat_room = (proto && DBGetContactSettingByte(hContact, proto, "ChatRoom", 0));
if(!chat_room) DBWriteContactSettingByte(hContact, MODULE, "Encrypted", (encrypted ? 1 : 0));
if(ServiceExists(MS_MSG_MODIFYICON)) {
+ //strcat(dbg_msg, "\nchanging icon");
StatusIconData sid = {0};
sid.cbSize = sizeof(sid);
sid.szModule = MODULE;
@@ -154,10 +161,13 @@ void SetEncryptionStatus(HANDLE hContact, bool encrypted) { if(!chat_room && ServiceExists(MS_MC_GETMETACONTACT)) {
HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)hContact, 0);
- if(hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0))
+ if(hContact == (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hMeta, 0)) {
+ //strcat(dbg_msg, "\nrecursing for meta");
SetEncryptionStatus(hMeta, encrypted);
+ }
}
}
+ //PUShowMessage(dbg_msg, SM_NOTIFY);
}
///////////////////////////////////////////////
@@ -486,6 +496,9 @@ void Disconnect(ConnContext *context) { // 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) {
+
+ if(Miranda_Terminated()) return 0;
+
int status = (int)wParam;
const char *proto = (char *)lParam;
HANDLE hContact;
@@ -499,7 +512,9 @@ int StatusModeChange(WPARAM wParam, LPARAM lParam) { 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);
+ if(uproto && uname)
+ otrl_message_disconnect(otr_user_state, &ops, hContact, MODULE, uproto, uname);
+
//otrl_context_force_finished(context);
SetEncryptionStatus(hContact, false);
@@ -524,7 +539,7 @@ int SettingChanged(WPARAM wParam, LPARAM lParam) { // and who are changing status to offline
if(strcmp(cws->szSetting, "Status") == 0 && cws->value.type != DBVT_DELETED && cws->value.wVal == ID_STATUS_OFFLINE) {
if(!hContact) {
- // if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol
+ // if it's a protocol going offline, attempt to send terminate session to all contacts of that protocol with active OTR sessions
const char *proto = cws->szModule;
StatusModeChange((WPARAM)ID_STATUS_OFFLINE, (LPARAM)proto);
return 0;
@@ -538,6 +553,9 @@ int SettingChanged(WPARAM wParam, LPARAM lParam) { if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
//otrl_message_disconnect(otr_user_state, &ops, hContact, MODULE, proto, uname);
+ //SetEncryptionStatus(hContact, false);
+
+ // FINISHED is not 'unencrypted', for e.g. srmm icon (still need to be able to 'stop OTR')
otrl_context_force_finished(context);
// removed - don't need a popup everytime an OTR user goes offline!
@@ -546,7 +564,6 @@ int SettingChanged(WPARAM wParam, LPARAM lParam) { //ShowPopup(Translate("OTR Information"), buff, 0);
// opdata is hContact
- SetEncryptionStatus(hContact, false);
}
lib_cs_unlock();
}
@@ -762,17 +779,14 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){ tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
- lib_cs_lock();
- otrl_message_disconnect(otr_user_state, &ops, 0, MODULE, proto, uname);
- lib_cs_unlock();
- //MessageBox(0, Translate("User ended encrypted session"), Translate("OTR Information"), MB_OK);
- char buff[512];
- mir_snprintf(buff, 512, Translate("User '%s' ended encrypted session"), uname);
- ShowPopup(Translate("OTR Information"), buff, 0);
- if(tlvs) otrl_tlv_free(tlvs); // do we need these? (can be used to tell that the other side has terminated encrypted connection)
-
- SetEncryptionStatus(ccs->hContact, false);
-
+ char buff[256];
+ mir_snprintf(buff, 256, Translate("'%s' has terminated the OTR session"), uname);
+ //MessageBox(0, buff, Translate("OTR Information"), MB_OK);
+ if(options.msg_inline)
+ ShowMessageInline(ccs->hContact, buff);
+ else
+ ShowPopup(Translate("OTR Information"), buff, 0);
+
return 1;
}
@@ -811,7 +825,7 @@ int RecvMessage(WPARAM wParam,LPARAM lParam){ // it may not be encrypted however (e.g. tagged plaintext with tags stripped)
ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0);
- bool encrypted = context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED;
+ bool encrypted = context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT;
if(options.prefix_messages && encrypted) {
tMsgBodyLen += strlen(MESSAGE_PREFIX);
@@ -892,7 +906,7 @@ int OnDatabaseEventPreAdd(WPARAM wParam, LPARAM lParam) { }
ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0);
- bool encrypted = context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED;
+ bool encrypted = context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT;
if(!encrypted) return 0;
@@ -1038,6 +1052,14 @@ int StopOTR(WPARAM wParam, LPARAM lParam) { SetEncryptionStatus(hContact, false);
+ char buff[256];
+ mir_snprintf(buff, 256, Translate("OTR session terminated"), uname);
+ //MessageBox(0, buff, Translate("OTR Information"), MB_OK);
+ if(options.msg_inline)
+ ShowMessageInline(hContact, buff);
+ else
+ ShowPopup(Translate("OTR Information"), buff, 0);
+
return 0;
}
@@ -1052,20 +1074,23 @@ int WindowEvent(WPARAM wParam, LPARAM lParam) { if(mwd->uType != MSG_WINDOW_EVT_OPEN) return 0;
if(!ServiceExists(MS_MSG_MODIFYICON)) return 0;
- if(!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)mwd->hContact, (LPARAM)MODULE))
+ HANDLE hContact = mwd->hContact, hTemp;
+ if(ServiceExists(MS_MC_GETMOSTONLINECONTACT) && (hTemp = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0)) != 0)
+ hContact = hTemp;
+
+ if(!CallService(MS_PROTO_ISPROTOONCONTACT, (WPARAM)hContact, (LPARAM)MODULE))
return 0;
- char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)mwd->hContact, 0);
- char *uname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)mwd->hContact, 0);
+ 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);
-
- bool encrypted = (context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED);
+ bool encrypted = (context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT);
lib_cs_unlock();
- SetEncryptionStatus(mwd->hContact, encrypted);
+ SetEncryptionStatus(hContact, encrypted);
return 0;
}
@@ -1167,7 +1192,7 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { HookEvent(ME_OPT_INITIALISE, OptInit);
// hook setting changed to monitor status
- HookEvent(ME_DB_CONTACT_SETTINGCHANGED, SettingChanged);
+ hSettingChanged = 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)
@@ -1247,6 +1272,7 @@ extern "C" DLLIMPORT int Load(PLUGINLINK *link) { }
extern "C" DLLIMPORT int Unload(void) {
+ UnhookEvent(hSettingChanged);
UnhookEvent(hEventWindow);
UnhookEvent(hEventDbEventAddedFilter);
UnhookEvent(hEventDbEventAdded);
diff --git a/otr/menu.cpp b/otr/menu.cpp index 88c385d..026f0fe 100644 --- a/otr/menu.cpp +++ b/otr/menu.cpp @@ -7,8 +7,7 @@ HANDLE hMenuBuildEvent, hStartItem, hStopItem; void FixMenuIcons() {
// fix menu icons
- CLISTMENUITEM menu;
- ZeroMemory(&menu,sizeof(menu));
+ CLISTMENUITEM menu = {0};
menu.cbSize=sizeof(menu);
menu.flags = CMIM_ICON;
@@ -51,7 +50,7 @@ int PrebuildContactMenu(WPARAM wParam, LPARAM lParam) { {
ConnContext *context = otrl_context_find(otr_user_state, uname, MODULE, proto, FALSE, 0, 0, 0);
- bool encrypted = context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED;
+ bool encrypted = context && context->msgstate != OTRL_MSGSTATE_PLAINTEXT;
if(encrypted) {
CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hStopItem, (LPARAM)&mi);
mi.flags |= CMIF_HIDDEN;
diff --git a/otr/otr.mdsp b/otr/otr.mdsp index f9a0e47..ee9e587 100644 --- a/otr/otr.mdsp +++ b/otr/otr.mdsp @@ -121,15 +121,33 @@ extraResourceOptions= 22=libotr\src\userstate.c
23=libotr\src\userstate.h
24=libotr\src\version.h
+25=..\..\include\m_protocols.h
+26=..\..\include\m_protosvc.h
+27=..\..\include\m_message.h
+28=..\..\include\m_popup.h
+29=..\..\include\m_metacontacts.h
[History]
+menu.cpp,3112
+..\..\include\m_metacontacts.h,1769
+..\..\include\m_popup.h,11116
+..\..\include\m_message.h,1619
+..\..\include\m_protocols.h,7232
+options.cpp,10862
+libotr\src\auth.h,6007
..\..\include\m_icolib.h,0
utils.cpp,7128
common.h,2043
-libotr\src\context.h,6666
-libotr\src\context.c,0
-libotr\src\message.h,6083
+libotr\src\context.h,4987
+libotr\src\context.c,10303
+libotr\src\message.h,2451
libotr\src\proto.h,5014
-libotr\src\userstate.h,1038
-libotr\src\message.c,36329
+libotr\src\userstate.h,1679
+libotr\src\message.c,29281
otr_private.h,149
-dllmain.cpp,43274
+libotr\src\auth.c,0
+libotr\src\privkey.c,0
+libotr\src\proto.c,0
+libotr\src\tests.c,0
+libotr\src\tlv.c,0
+libotr\src\userstate.c,0
+dllmain.cpp,17513
diff --git a/otr/otr_private.h b/otr/otr_private.h index d1a464f..b6bf23d 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 1
-#define VER_BUILD 3
+#define VER_RELEASE 2
+#define VER_BUILD 0
#define __STRINGIZE(x) #x
#define VER_STRING __STRINGIZE( VER_MAJOR.VER_MINOR.VER_RELEASE.VER_BUILD )
|