about summary refs log tree commit diff stats
path: root/src/otr
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-04-29 22:59:44 +0100
committerJames Booth <boothj5@gmail.com>2015-04-29 22:59:44 +0100
commit665c34414d7534016fb8136cffbadd35793dec7b (patch)
tree0fc82d254101cfa66a0a53edf061db7f3d958762 /src/otr
parent0df8b8beff8aeeae072beee8fc3ed69f9d132fb2 (diff)
downloadprofani-tty-665c34414d7534016fb8136cffbadd35793dec7b.tar.gz
Return result on OTR message sending
Diffstat (limited to 'src/otr')
-rw-r--r--src/otr/otr.c18
-rw-r--r--src/otr/otr.h10
2 files changed, 24 insertions, 4 deletions
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 7507cd56..46ad491c 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -313,7 +313,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con
     otr_free_message(decrypted);
 }
 
-void
+prof_otrsendres_t
 otr_on_message_send(const char * const barejid, const char * const message)
 {
     char *id = NULL;
@@ -328,11 +328,11 @@ otr_on_message_send(const char * const barejid, const char * const message)
             ui_outgoing_chat_msg(barejid, message, id);
             otr_free_message(encrypted);
         } else {
-            cons_show_error("Failed to encrypt and send message.");
+            return PROF_OTRENCFAIL;
         }
 
     } else if (policy == PROF_OTRPOLICY_ALWAYS) {
-        cons_show_error("Failed to send message. OTR policy set to: always");
+        return PROF_OTRPOLICYFAIL;
 
     } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
         char *otr_tagged_msg = otr_tag_message(message);
@@ -348,6 +348,8 @@ otr_on_message_send(const char * const barejid, const char * const message)
     }
 
     free(id);
+
+    return PROF_OTRSUCCESS;
 }
 
 void
@@ -741,6 +743,16 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea
     }
 }
 
+char*
+otr_senderror_str(prof_otrsendres_t res)
+{
+    switch (res) {
+    case PROF_OTRENCFAIL:    return "Failed to encrypt and send message.";
+    case PROF_OTRPOLICYFAIL: return "Failed to send message. OTR policy set to: always";
+    default:                 return "Unknown OTR error.";
+    }
+}
+
 void
 otr_free_message(char *message)
 {
diff --git a/src/otr/otr.h b/src/otr/otr.h
index 8e1d22df..6f1103df 100644
--- a/src/otr/otr.h
+++ b/src/otr/otr.h
@@ -46,6 +46,12 @@ typedef enum {
     PROF_OTRPOLICY_ALWAYS
 } prof_otrpolicy_t;
 
+typedef enum {
+    PROF_OTRENCFAIL,
+    PROF_OTRPOLICYFAIL,
+    PROF_OTRSUCCESS
+} prof_otrsendres_t;
+
 OtrlUserState otr_userstate(void);
 OtrlMessageAppOps* otr_messageops(void);
 GHashTable* otr_smpinitators(void);
@@ -58,7 +64,7 @@ void otr_poll(void);
 void otr_on_connect(ProfAccount *account);
 
 void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message);
-void otr_on_message_send(const char * const barejid, const char * const message);
+prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message);
 
 void otr_keygen(ProfAccount *account);
 
@@ -88,4 +94,6 @@ void otr_free_message(char *message);
 
 prof_otrpolicy_t otr_get_policy(const char * const recipient);
 
+char* otr_senderror_str(prof_otrsendres_t res);
+
 #endif