about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-08-20 18:51:19 +0100
committerJames Booth <boothj5@gmail.com>2016-08-20 18:51:19 +0100
commit45048e3ac8bb342b63aaac323f76d0fa3c472720 (patch)
tree145ebeff668173538c275931628b8774ec965c32 /src/xmpp
parent24c3eff428010e08bdf2beee763f9c6a59d6a68f (diff)
downloadprofani-tty-45048e3ac8bb342b63aaac323f76d0fa3c472720.tar.gz
Replace stanza_create_message with libstrophe convenience functions
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c29
-rw-r--r--src/xmpp/stanza.c23
-rw-r--r--src/xmpp/stanza.h3
3 files changed, 21 insertions, 34 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 407b7485..e9fc8297 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -141,7 +141,8 @@ message_send_chat(const char *const barejid, const char *const msg, const char *
     char *jid = chat_session_get_jid(barejid);
     char *id = create_unique_id("msg");
 
-    xmpp_stanza_t *message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
+    xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
+    xmpp_message_set_body(message, msg);
     free(jid);
 
     if (state) {
@@ -179,7 +180,8 @@ message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean
         Jid *jidp = jid_create(jid);
         char *encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
         if (encrypted) {
-            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, "This message is encrypted.");
+            message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
+            xmpp_message_set_body(message, "This message is encrypted.");
             xmpp_stanza_t *x = xmpp_stanza_new(ctx);
             xmpp_stanza_set_name(x, STANZA_NAME_X);
             xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED);
@@ -191,15 +193,18 @@ message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean
             xmpp_stanza_release(x);
             free(encrypted);
         } else {
-            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
+            message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
+            xmpp_message_set_body(message, msg);
         }
         jid_destroy(jidp);
     } else {
-        message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
+        message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
+        xmpp_message_set_body(message, msg);
     }
     account_free(account);
 #else
-    message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
+    message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
+    xmpp_message_set_body(message, msg);
 #endif
     free(jid);
 
@@ -226,7 +231,9 @@ message_send_chat_otr(const char *const barejid, const char *const msg, gboolean
     char *jid = chat_session_get_jid(barejid);
     char *id = create_unique_id("msg");
 
-    xmpp_stanza_t *message = stanza_create_message(ctx, id, barejid, STANZA_TYPE_CHAT, msg);
+    xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, barejid, id);
+    xmpp_message_set_body(message, msg);
+
     free(jid);
 
     if (state) {
@@ -252,7 +259,10 @@ message_send_private(const char *const fulljid, const char *const msg, const cha
 {
     xmpp_ctx_t * const ctx = connection_get_ctx();
     char *id = create_unique_id("prv");
-    xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg);
+
+    xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
+    xmpp_message_set_body(message, msg);
+
     free(id);
 
     if (oob_url) {
@@ -268,7 +278,10 @@ message_send_groupchat(const char *const roomjid, const char *const msg, const c
 {
     xmpp_ctx_t * const ctx = connection_get_ctx();
     char *id = create_unique_id("muc");
-    xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg);
+
+    xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, roomjid, id);
+    xmpp_message_set_body(message, msg);
+
     free(id);
 
     if (oob_url) {
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 1844cfd5..7b7396fe 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -443,29 +443,6 @@ stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *cons
 }
 
 xmpp_stanza_t*
-stanza_create_message(xmpp_ctx_t *ctx, char *id, const char *const recipient,
-    const char *const type, const char *const message)
-{
-    xmpp_stanza_t *msg = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
-    xmpp_stanza_set_type(msg, type);
-    xmpp_stanza_set_to(msg, recipient);
-    xmpp_stanza_set_id(msg, id);
-
-    xmpp_stanza_t *body = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(body, STANZA_NAME_BODY);
-
-    xmpp_stanza_t *text = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_text(text, message);
-    xmpp_stanza_add_child(body, text);
-    xmpp_stanza_release(text);
-    xmpp_stanza_add_child(msg, body);
-    xmpp_stanza_release(body);
-
-    return msg;
-}
-
-xmpp_stanza_t*
 stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char *const barejid)
 {
     xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 806ba615..5a11f3c1 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -228,9 +228,6 @@ xmpp_stanza_t* stanza_attach_hints_no_store(xmpp_ctx_t *ctx, xmpp_stanza_t *stan
 xmpp_stanza_t* stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
 xmpp_stanza_t* stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url);
 
-xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, char *id,
-    const char *const recipient, const char *const type, const char *const message);
-
 xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *const ctx,
     const char *const full_room_jid, const char *const passwd);