about summary refs log tree commit diff stats
path: root/src/otr/otrlibv4.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/otr/otrlibv4.c')
-rw-r--r--src/otr/otrlibv4.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c
index c55d2972..d9e7ce01 100644
--- a/src/otr/otrlibv4.c
+++ b/src/otr/otrlibv4.c
@@ -25,6 +25,12 @@
 #include <libotr/message.h>
 
 #include "ui/ui.h"
+#include "log.h"
+#include "otr/otr.h"
+#include "otr/otrlib.h"
+
+static GTimer *timer;
+static unsigned int current_interval;
 
 OtrlPolicy
 otrlib_policy(void)
@@ -32,6 +38,27 @@ otrlib_policy(void)
     return OTRL_POLICY_ALLOW_V1 | OTRL_POLICY_ALLOW_V2;
 }
 
+void
+otrlib_init_timer(void)
+{
+    OtrlUserState user_state = otr_userstate();
+    timer = g_timer_new();
+    current_interval = otrl_message_poll_get_default_interval(user_state);
+}
+
+void
+otrlib_poll(void)
+{
+    gdouble elapsed = g_timer_elapsed(timer, NULL);
+
+    if (current_interval != 0 && elapsed > current_interval) {
+        OtrlUserState user_state = otr_userstate();
+        OtrlMessageAppOps *ops = otr_messageops();
+        otrl_message_poll(user_state, ops, NULL);
+        g_timer_start(timer);
+    }
+}
+
 char *
 otrlib_start_query(void)
 {
@@ -64,6 +91,12 @@ cb_otr_error_message_free(void *opdata, const char *err_msg)
 }
 
 static void
+cb_timer_control(void *opdata, unsigned int interval)
+{
+    current_interval = interval; 
+}
+
+static void
 cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
     ConnContext *context, const char *message,
     gcry_error_t err)
@@ -77,12 +110,70 @@ cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
     }
 }
 
+static void
+cb_handle_smp_event(void *opdata, OtrlSMPEvent smp_event,
+    ConnContext *context, unsigned short progress_percent,
+    char *question)
+{
+    NextExpectedSMP nextMsg = context->smstate->nextExpected;
+    OtrlUserState user_state = otr_userstate();
+    OtrlMessageAppOps *ops = otr_messageops();
+    GHashTable *smp_initiators = otr_smpinitators();
+
+    switch(smp_event)
+    {
+        case OTRL_SMPEVENT_ASK_FOR_SECRET:
+            ui_smp_recipient_initiated(context->username);
+            g_hash_table_insert(smp_initiators, strdup(context->username), strdup(context->username));
+            break;
+
+        case OTRL_SMPEVENT_SUCCESS:
+            ui_smp_successful(context->username);
+            ui_trust(context->username);
+            break;
+            
+        case OTRL_SMPEVENT_FAILURE:
+            if (nextMsg == OTRL_SMP_EXPECT3) {
+                ui_smp_unsuccessful_sender(context->username);
+                ui_untrust(context->username);
+            } else if (nextMsg == OTRL_SMP_EXPECT4) {
+                ui_smp_unsuccessful_receiver(context->username);
+                ui_untrust(context->username);
+            }
+            break;
+
+        case OTRL_SMPEVENT_ERROR:
+            otrl_message_abort_smp(user_state, ops, NULL, context);
+            break;
+
+        case OTRL_SMPEVENT_CHEATED:
+            otrl_message_abort_smp(user_state, ops, NULL, context);
+            break;
+
+        case OTRL_SMPEVENT_ABORT:
+            ui_smp_aborted(context->username);
+            ui_untrust(context->username);
+            break;
+
+        case OTRL_SMPEVENT_ASK_FOR_ANSWER:
+            break;
+
+        case OTRL_SMPEVENT_IN_PROGRESS:
+            break;
+
+        default:
+            break;
+    }
+}
+
 void
 otrlib_init_ops(OtrlMessageAppOps *ops)
 {
     ops->otr_error_message = cb_otr_error_message;
     ops->otr_error_message_free = cb_otr_error_message_free;
     ops->handle_msg_event = cb_handle_msg_event;
+    ops->handle_smp_event = cb_handle_smp_event;
+    ops->timer_control = cb_timer_control;
 }
 
 ConnContext *
@@ -145,3 +236,8 @@ otrlib_decrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *j
         NULL,
         NULL);
 }
+
+void
+otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext *context, OtrlTLV *tlvs, GHashTable *smp_initiators)
+{
+}