summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-05-21 16:11:58 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-05-21 16:11:58 +0000
commit48266e479d1fcf5153b29c612866845990fccad8 (patch)
treec8cbc908cd3c5f08731e5e8d7eaac6b568007d09 /plugins/MirOTR/src
parentebdb556f152734035846f120eb8112f88ef91281 (diff)
war against atavisms continues
- everything that goes to PSS_MESSAGE should be sent as utf8 string; - thus PREF_UNICODE & PREF_UTF support discontinued, these constants are removed; - support for PREF_UNICODE & PREF_UTF in protocols also removed; - PREF_UNICODE used in file transfers (PROTOFILERECVT) replaced with PRFF_UNICODE / PRFF_TCHAR git-svn-id: http://svn.miranda-ng.org/main/trunk@13734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/src')
-rw-r--r--plugins/MirOTR/src/otr.cpp2
-rw-r--r--plugins/MirOTR/src/svcs_proto.cpp152
-rw-r--r--plugins/MirOTR/src/utils.cpp4
3 files changed, 61 insertions, 97 deletions
diff --git a/plugins/MirOTR/src/otr.cpp b/plugins/MirOTR/src/otr.cpp
index 09d912adf8..e8f0bcbe22 100644
--- a/plugins/MirOTR/src/otr.cpp
+++ b/plugins/MirOTR/src/otr.cpp
@@ -133,7 +133,7 @@ extern "C" {
DEBUGOUT_T("OTR_GUI_INJECT_MESSAGE\n");
MCONTACT hContact = (MCONTACT)opdata;
if (db_get_w(hContact, protocol, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
- CallContactService(hContact, PSS_MESSAGE, PREF_UTF | PREF_BYPASS_OTR, (LPARAM)message);
+ CallContactService(hContact, PSS_MESSAGE, PREF_BYPASS_OTR, (LPARAM)message);
}
/* When the list of ConnContexts changes (including a change in
diff --git a/plugins/MirOTR/src/svcs_proto.cpp b/plugins/MirOTR/src/svcs_proto.cpp
index 1d89651585..22b428145e 100644
--- a/plugins/MirOTR/src/svcs_proto.cpp
+++ b/plugins/MirOTR/src/svcs_proto.cpp
@@ -21,44 +21,26 @@ INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){
return 1; // error
const char *oldmessage = (const char *)ccs->lParam;
- char *oldmessage_utf = NULL;
-
- //MessageBox(0, "Send message - converting to UTF-8", "msg", MB_OK);
-
- if(ccs->wParam & PREF_UTF) {
- oldmessage_utf = (char*)oldmessage;
- }
- else if(ccs->wParam & PREF_UNICODE) {
- oldmessage_utf = mir_utf8encodeW((wchar_t*)&oldmessage[strlen(oldmessage)+1]);
- }
- else {
- oldmessage_utf = mir_utf8encode(oldmessage);
- }
- if (!oldmessage_utf) return 1;
+ if (!oldmessage)
+ return 1;
// don't filter OTR messages being sent (OTR messages should only happen *after* the otrl_message_sending call below)
- if(strncmp(oldmessage_utf, "?OTR", 4) == 0) {
+ if(strncmp(oldmessage, "?OTR", 4) == 0) {
DEBUGOUT_T("OTR message without PREF_BYPASS_OTR\n");
- if (!(ccs->wParam & PREF_UTF))
- mir_free(oldmessage_utf);
return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
}
char *tmpencode = NULL;
ConnContext *context = otrl_context_find_miranda(otr_user_state, ccs->hContact);
if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0) && otr_context_get_trust(context) >= TRUST_UNVERIFIED) {
- tmpencode = encode_html_entities_utf8(oldmessage_utf);
- if (tmpencode != NULL) {
- if (!(ccs->wParam & PREF_UTF)) mir_free(oldmessage_utf);
- oldmessage_utf = tmpencode;
- }
+ tmpencode = encode_html_entities_utf8(oldmessage);
+ if (tmpencode != NULL)
+ oldmessage = tmpencode;
}
char *newmessage = NULL;
char *username = contact_get_id(ccs->hContact);
- gcry_error_t err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, proto, proto, username, OTRL_INSTAG_BEST, oldmessage_utf, NULL, &newmessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, add_appdata, (void*)ccs->hContact);
- if (tmpencode!= NULL || !(ccs->wParam & PREF_UTF))
- mir_free(oldmessage_utf);
+ gcry_error_t err = otrl_message_sending(otr_user_state, &ops, (void*)ccs->hContact, proto, proto, username, OTRL_INSTAG_BEST, oldmessage, NULL, &newmessage, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, add_appdata, (void*)ccs->hContact);
mir_free(username);
if (err) { /* Be *sure* not to send out plaintext */
@@ -66,35 +48,30 @@ INT_PTR SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){
ShowError(TranslateT(LANG_ENCRYPTION_ERROR));
otrl_message_free(newmessage);
return 1;
- } else if (newmessage) {
- if(!newmessage[0]){
- otrl_message_free(newmessage);
- return 1; // skip empty messages (OTR might prevent us sending unencrypted messages by replacing them with empty ones)
- }
- WPARAM oldflags = ccs->wParam;
- if(ccs->wParam & (PREF_UTF|PREF_UNICODE)) {
- ccs->lParam = (LPARAM)newmessage;
- ccs->wParam &= ~PREF_UNICODE;
- ccs->wParam |= PREF_UTF;
- } else {
- mir_utf8decode(newmessage, NULL);
- ccs->lParam = (LPARAM)newmessage;
- }
- INT_PTR ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-
- DEBUGOUTA("OTR - sending raw message: '");
- DEBUGOUTA((const char*)ccs->lParam);
- DEBUGOUTA("'\n");
+ }
+
+ if (newmessage == NULL)
+ return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+
+ if(!newmessage[0]){
otrl_message_free(newmessage);
-
- // reset to original values
- ccs->lParam = (LPARAM)oldmessage;
- ccs->wParam = oldflags;
- return ret;
+ return 1; // skip empty messages (OTR might prevent us sending unencrypted messages by replacing them with empty ones)
}
- return CallService(MS_PROTO_CHAINSEND, wParam, lParam);
-}
+ WPARAM oldflags = ccs->wParam;
+ ccs->lParam = (LPARAM)newmessage;
+ INT_PTR ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
+
+ DEBUGOUTA("OTR - sending raw message: '");
+ DEBUGOUTA((const char*)ccs->lParam);
+ DEBUGOUTA("'\n");
+ otrl_message_free(newmessage);
+
+ // reset to original values
+ ccs->lParam = (LPARAM)oldmessage;
+ ccs->wParam = oldflags;
+ return ret;
+}
INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam)
{
@@ -116,17 +93,9 @@ INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam)
return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
char *oldmessage = pre->szMessage;
- char *oldmessage_utf = NULL;
// convert oldmessage to utf-8
- if(pre->flags & PREF_UTF) {
- oldmessage_utf = oldmessage;
- } else if(pre->flags & PREF_UNICODE) {
- oldmessage_utf = mir_utf8encodeW((wchar_t*)(&oldmessage[strlen(oldmessage)+1]));
- } else {
- oldmessage_utf = mir_utf8encode(oldmessage);
- }
- if (!oldmessage_utf) return 1;
-
+ if (!oldmessage)
+ return 1;
ConnContext* context=NULL;
char *uname = contact_get_id(ccs->hContact);
@@ -135,12 +104,9 @@ INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam)
lib_cs_lock();
int ignore_msg = otrl_message_receiving(otr_user_state, &ops, (void*)ccs->hContact,
- proto, proto, uname, oldmessage_utf,
+ proto, proto, uname, oldmessage,
&newmessage, &tlvs, &context, add_appdata, (void*)ccs->hContact);
mir_free(uname);
-
- if ( !(pre->flags & PREF_UTF))
- mir_free(oldmessage_utf);
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv && !Miranda_Terminated()) {
@@ -156,38 +122,36 @@ INT_PTR SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam)
if (newmessage)
otrl_message_free(newmessage);
return 1; // discard internal protocol messages
- } else if (newmessage) {
- DWORD oldflags = pre->flags;
- pre->flags &= ~PREF_UNICODE;
- pre->flags |= PREF_UTF; // just use UTF, so we do not have to recode the message
+ }
+ if (newmessage == NULL)
+ return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
+
+ DWORD oldflags = pre->flags;
- typedef void (*msg_free_t)(void*);
- msg_free_t msg_free = (msg_free_t)otrl_message_free;
- if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0)) {
- char* tmp = striphtml(newmessage);
- msg_free(newmessage);
- newmessage = tmp;
- msg_free = mir_free;
- }
- if (options.prefix_messages) {
- size_t len = (strlen(options.prefix)+strlen(newmessage)+1)*sizeof(char);
- char* tmp = (char*)mir_alloc( len );
- strcpy(tmp, options.prefix);
- strcat(tmp, newmessage);
- msg_free(newmessage);
- newmessage = tmp;
- msg_free = mir_free;
- }
- pre->szMessage = newmessage;
- BOOL ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
-/// @todo (White-Tiger#1#03/23/15): why are we doing this?
- pre->flags = oldflags;
- pre->szMessage = oldmessage;
+ typedef void (*msg_free_t)(void*);
+ msg_free_t msg_free = (msg_free_t)otrl_message_free;
+ if (db_get_b(ccs->hContact, MODULENAME, "HTMLConv", 0)) {
+ char* tmp = striphtml(newmessage);
msg_free(newmessage);
- return ret;
+ newmessage = tmp;
+ msg_free = mir_free;
}
- return CallService(MS_PROTO_CHAINRECV, wParam, lParam);
-
+ if (options.prefix_messages) {
+ size_t len = (strlen(options.prefix)+strlen(newmessage)+1)*sizeof(char);
+ char* tmp = (char*)mir_alloc( len );
+ strcpy(tmp, options.prefix);
+ strcat(tmp, newmessage);
+ msg_free(newmessage);
+ newmessage = tmp;
+ msg_free = mir_free;
+ }
+ pre->szMessage = newmessage;
+ BOOL ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
+/// @todo (White-Tiger#1#03/23/15): why are we doing this?
+ pre->flags = oldflags;
+ pre->szMessage = oldmessage;
+ msg_free(newmessage);
+ return ret;
}
/* Abort the SMP protocol. Used when malformed or unexpected messages
diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp
index 2cb11f610f..997abd82e6 100644
--- a/plugins/MirOTR/src/utils.cpp
+++ b/plugins/MirOTR/src/utils.cpp
@@ -321,7 +321,7 @@ void ShowMessageInline(const MCONTACT hContact, const TCHAR *msg) {
pre.timestamp = time(0);
char *utf = mir_utf8encodeT(buff);
pre.szMessage = utf;
- pre.flags = PREF_UTF|PREF_BYPASS_OTR;
+ pre.flags = PREF_BYPASS_OTR;
ProtoChainRecvMsg(hContact, &pre);
mir_free(utf);
@@ -334,7 +334,7 @@ void ShowMessageInlineUtf(const MCONTACT hContact, const char *msg) {
PROTORECVEVENT pre = {0};
pre.timestamp = time(0);
pre.szMessage = buff;
- pre.flags = PREF_UTF|PREF_BYPASS_OTR;
+ pre.flags = PREF_BYPASS_OTR;
ProtoChainRecvMsg(hContact, &pre);
}