diff options
author | James Booth <boothj5@gmail.com> | 2015-08-27 00:37:48 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-08-27 00:37:48 +0100 |
commit | 1484e94b355dc8f41d7285206b114a3e8251a1d9 (patch) | |
tree | f80b74bb994e849b11ae8c9aa6948bbe58555a24 /src | |
parent | ef52840d912f2f36948f6a13dba0328966f21e0c (diff) | |
download | profani-tty-1484e94b355dc8f41d7285206b114a3e8251a1d9.tar.gz |
Fixed OTR decryption check
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 2 | ||||
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/event/server_events.c | 2 | ||||
-rw-r--r-- | src/otr/otr.c | 28 | ||||
-rw-r--r-- | src/otr/otr.h | 4 |
5 files changed, 20 insertions, 18 deletions
diff --git a/src/common.c b/src/common.c index bd8b1742..fc701b8b 100644 --- a/src/common.c +++ b/src/common.c @@ -193,7 +193,7 @@ str_replace(const char *string, const char *substr, } gboolean -str_contains_str(char *searchstr, char *substr) +str_contains_str(const char * const searchstr, const char * const substr) { return g_strrstr(searchstr, substr) != NULL; } diff --git a/src/common.h b/src/common.h index 1e50a87a..a1e0226e 100644 --- a/src/common.h +++ b/src/common.h @@ -104,7 +104,7 @@ gboolean create_dir(char *name); gboolean mkdir_recursive(const char *dir); char * str_replace(const char *string, const char *substr, const char *replacement); -gboolean str_contains_str(char *searchstr, char *substr); +gboolean str_contains_str(const char * const searchstr, const char * const substr); int str_contains(const char str[], int size, char ch); gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg); int utf8_display_len(const char * const str); diff --git a/src/event/server_events.c b/src/event/server_events.c index 7fb2427c..ae85d32a 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -219,7 +219,7 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char gboolean decrypted = FALSE; char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); if (otr_res) { - if (decrypted && g_strrstr(otr_res, message) == NULL) { + if (decrypted) { ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR); } else { ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE); diff --git a/src/otr/otr.c b/src/otr/otr.c index 7953733d..7e68ecb3 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -274,7 +274,7 @@ otr_on_connect(ProfAccount *account) } char* -otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message, gboolean *was_decrypted) +otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message, gboolean *decrypted) { prof_otrpolicy_t policy = otr_get_policy(barejid); char *whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE); @@ -298,19 +298,19 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con } } - char *decrypted = otr_decrypt_message(barejid, message, was_decrypted); - if (!decrypted) { // internal OTR message + char *newmessage = otr_decrypt_message(barejid, message, decrypted); + if (!newmessage) { // internal OTR message return NULL; } - if (policy == PROF_OTRPOLICY_ALWAYS && *was_decrypted == FALSE && !whitespace_base) { + if (policy == PROF_OTRPOLICY_ALWAYS && *decrypted == FALSE && !whitespace_base) { char *otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session..."); char *id = message_send_chat_otr(barejid, otr_query_message); free(id); } - return decrypted; + return newmessage; } gboolean @@ -717,12 +717,12 @@ _otr_tlv_free(OtrlTLV *tlvs) } char * -otr_decrypt_message(const char * const from, const char * const message, gboolean *was_decrypted) +otr_decrypt_message(const char * const from, const char * const message, gboolean *decrypted) { - char *decrypted = NULL; + char *newmessage = NULL; OtrlTLV *tlvs = NULL; - int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &decrypted, &tlvs); + int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &newmessage, &tlvs); // internal libotr message if (result == 1) { @@ -743,16 +743,18 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea return NULL; - // message was decrypted, return to user - } else if (decrypted) { + // message was processed, return to user + } else if (newmessage) { _otr_tlv_free(tlvs); - *was_decrypted = TRUE; - return decrypted; + if (g_str_has_prefix(message, "?OTR:")) { + *decrypted = TRUE; + } + return newmessage; // normal non OTR message } else { _otr_tlv_free(tlvs); - *was_decrypted = FALSE; + *decrypted = FALSE; return strdup(message); } } diff --git a/src/otr/otr.h b/src/otr/otr.h index 45abdc20..cd11709f 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -58,7 +58,7 @@ char* otr_start_query(void); void otr_poll(void); void otr_on_connect(ProfAccount *account); -char* otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message, gboolean *was_decrypted); +char* otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message, gboolean *decrypted); gboolean otr_on_message_send(ProfChatWin *chatwin, const char * const message); void otr_keygen(ProfAccount *account); @@ -83,7 +83,7 @@ char * otr_get_their_fingerprint(const char * const recipient); char * otr_encrypt_message(const char * const to, const char * const message); char * otr_decrypt_message(const char * const from, const char * const message, - gboolean *was_decrypted); + gboolean *decrypted); void otr_free_message(char *message); |