about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c31
-rw-r--r--src/xmpp/stanza.c5
-rw-r--r--src/xmpp/stanza.h2
-rw-r--r--src/xmpp/xmpp.h1
4 files changed, 33 insertions, 6 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index d18abd62..0f69f4ff 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -71,10 +71,10 @@ message_send(const char * const msg, const char * const recipient)
     if (prefs_get_boolean(PREF_STATES) && chat_session_get_recipient_supports(recipient)) {
         chat_session_set_active(recipient);
         message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
-            msg, STANZA_NAME_ACTIVE);
+            msg, STANZA_NAME_ACTIVE, NULL);
     } else {
         message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
-            msg, NULL);
+            msg, NULL, NULL);
     }
 
     xmpp_send(conn, message);
@@ -87,7 +87,19 @@ message_send_groupchat(const char * const msg, const char * const recipient)
     xmpp_conn_t * const conn = connection_get_conn();
     xmpp_ctx_t * const ctx = connection_get_ctx();
     xmpp_stanza_t *message = stanza_create_message(ctx, recipient,
-        STANZA_TYPE_GROUPCHAT, msg, NULL);
+        STANZA_TYPE_GROUPCHAT, msg, NULL, NULL);
+
+    xmpp_send(conn, message);
+    xmpp_stanza_release(message);
+}
+
+void
+message_send_duck(const char * const query)
+{
+    xmpp_conn_t * const conn = connection_get_conn();
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    xmpp_stanza_t *message = stanza_create_message(ctx, "im@ddg.gg",
+        STANZA_TYPE_CHAT, query, NULL, NULL);
 
     xmpp_send(conn, message);
     xmpp_stanza_release(message);
@@ -293,8 +305,19 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
     Jid *jid = jid_create(from);
 
+    // handle ddg searches
+    if (strcmp(jid->barejid, "im@ddg.gg") == 0) {
+        xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
+        if (body != NULL) {
+            char *message = xmpp_stanza_get_text(body);
+            prof_handle_duck_result(message);
+        }
+
+        jid_destroy(jid);
+        return 1;
+
     // private message from chat room use full jid (room/nick)
-    if (muc_room_is_active(jid)) {
+    } else if (muc_room_is_active(jid)) {
         // determine if the notifications happened whilst offline
         GTimeVal tv_stamp;
         gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 68232382..528f2055 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -55,7 +55,7 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
 xmpp_stanza_t *
 stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
     const char * const type, const char * const message,
-    const char * const state)
+    const char * const state, const char * const id)
 {
     char *encoded_xml = encode_xml(message);
 
@@ -65,6 +65,9 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
     xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
     xmpp_stanza_set_type(msg, type);
     xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);
+    if (id != NULL) {
+        xmpp_stanza_set_id(msg, id);
+    }
 
     body = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(body, STANZA_NAME_BODY);
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 3aa0cf6f..8fb21deb 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -116,7 +116,7 @@ xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
 
 xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx,
     const char * const recipient, const char * const type,
-    const char * const message, const char * const state);
+    const char * const message, const char * const state, const char * const id);
 
 xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
     const char * const full_room_jid);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 03b6ad85..c65fdfd9 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -99,6 +99,7 @@ void message_send_paused(const char * const recipient);
 void message_send_gone(const char * const recipient);
 void message_send_invite(const char * const room, const char * const contact,
     const char * const reason);
+void message_send_duck(const char * const query);
 
 // presence functions
 void presence_subscription(const char * const jid, const jabber_subscr_t action);