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 20:20:38 +0100
committerJames Booth <boothj5@gmail.com>2016-08-20 20:20:38 +0100
commit27263508c769474f26010ba638872a027d229020 (patch)
treea95709ab582a116cc3f2363c4a7e7dab4bb08ebe /src/xmpp
parentd61abd35776e2dd448ce9a0cd6576d6ef2c0336e (diff)
downloadprofani-tty-27263508c769474f26010ba638872a027d229020.tar.gz
Use libstrophe xmpp_iq_new convenience function
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/blocking.c14
-rw-r--r--src/xmpp/bookmark.c5
-rw-r--r--src/xmpp/iq.c37
-rw-r--r--src/xmpp/stanza.c156
4 files changed, 70 insertions, 142 deletions
diff --git a/src/xmpp/blocking.c b/src/xmpp/blocking.c
index 3c1b4707..f00bb429 100644
--- a/src/xmpp/blocking.c
+++ b/src/xmpp/blocking.c
@@ -116,11 +116,8 @@ blocked_add(char *jid)
 
     xmpp_ctx_t *ctx = connection_get_ctx();
 
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
     char *id = create_unique_id("block");
-    xmpp_stanza_set_id(iq, id);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
 
     xmpp_stanza_t *block = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(block, STANZA_NAME_BLOCK);
@@ -137,10 +134,10 @@ blocked_add(char *jid)
     xmpp_stanza_release(block);
 
     iq_id_handler_add(id, _block_add_result_handler, free, strdup(jid));
+    free(id);
 
     iq_send_stanza(iq);
     xmpp_stanza_release(iq);
-    free(id);
 
     return TRUE;
 }
@@ -155,11 +152,8 @@ blocked_remove(char *jid)
 
     xmpp_ctx_t *ctx = connection_get_ctx();
 
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
     char *id = create_unique_id("unblock");
-    xmpp_stanza_set_id(iq, id);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
 
     xmpp_stanza_t *block = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(block, STANZA_NAME_UNBLOCK);
@@ -176,10 +170,10 @@ blocked_remove(char *jid)
     xmpp_stanza_release(block);
 
     iq_id_handler_add(id, _block_remove_result_handler, free, strdup(jid));
+    free(id);
 
     iq_send_stanza(iq);
     xmpp_stanza_release(iq);
-    free(id);
 
     return TRUE;
 }
diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c
index f6a41553..bc48ee33 100644
--- a/src/xmpp/bookmark.c
+++ b/src/xmpp/bookmark.c
@@ -406,12 +406,9 @@ _send_bookmarks(void)
 {
     xmpp_ctx_t *ctx = connection_get_ctx();
 
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
     char *id = create_unique_id("bookmarks_update");
-    xmpp_stanza_set_id(iq, id);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
     free(id);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 3863e209..260c062e 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -1158,15 +1158,9 @@ _ping_get_handler(xmpp_stanza_t *const stanza)
         return;
     }
 
-    xmpp_stanza_t *pong = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(pong, STANZA_NAME_IQ);
+    xmpp_stanza_t *pong = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id);
     xmpp_stanza_set_to(pong, from);
     xmpp_stanza_set_from(pong, to);
-    xmpp_stanza_set_type(pong, STANZA_TYPE_RESULT);
-
-    if (id) {
-        xmpp_stanza_set_id(pong, id);
-    }
 
     iq_send_stanza(pong);
     xmpp_stanza_release(pong);
@@ -1186,13 +1180,8 @@ _version_get_handler(xmpp_stanza_t *const stanza)
     }
 
     if (from) {
-        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
-        if (id) {
-            xmpp_stanza_set_id(response, id);
-        }
+        xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id);
         xmpp_stanza_set_to(response, from);
-        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
 
         xmpp_stanza_t *query = xmpp_stanza_new(ctx);
         xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -1251,11 +1240,9 @@ _disco_items_get_handler(xmpp_stanza_t *const stanza)
     }
 
     if (from) {
-        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
-        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
+        xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza));
         xmpp_stanza_set_to(response, from);
-        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
+
         xmpp_stanza_t *query = xmpp_stanza_new(ctx);
         xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
         xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
@@ -1282,11 +1269,8 @@ _last_activity_get_handler(xmpp_stanza_t *const stanza)
         char str[50];
         sprintf(str, "%d", idls_secs);
 
-        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
-        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
+        xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza));
         xmpp_stanza_set_to(response, from);
-        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
 
         xmpp_stanza_t *query = xmpp_stanza_new(ctx);
         xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -1300,11 +1284,8 @@ _last_activity_get_handler(xmpp_stanza_t *const stanza)
 
         xmpp_stanza_release(response);
     } else {
-        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
-        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
+        xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_ERROR, xmpp_stanza_get_id(stanza));
         xmpp_stanza_set_to(response, from);
-        xmpp_stanza_set_type(response, STANZA_TYPE_ERROR);
 
         xmpp_stanza_t *error = xmpp_stanza_new(ctx);
         xmpp_stanza_set_name(error, STANZA_NAME_ERROR);
@@ -1344,11 +1325,9 @@ _disco_info_get_handler(xmpp_stanza_t *const stanza)
     }
 
     if (from) {
-        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
-        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
+        xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza));
         xmpp_stanza_set_to(response, from);
-        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
+
         xmpp_stanza_t *query = stanza_create_caps_query_element(ctx);
         if (node_str) {
             xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 557ad26f..4dd8c526 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -72,9 +72,7 @@ static char* _stanza_text_to_str(xmpp_stanza_t *stanza);
 xmpp_stanza_t*
 stanza_create_bookmarks_pubsub_request(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, NULL);
 
     xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
@@ -96,9 +94,7 @@ stanza_create_bookmarks_pubsub_request(xmpp_ctx_t *ctx)
 xmpp_stanza_t*
 stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, NULL);
     xmpp_stanza_set_ns(iq, "jabber:client");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
@@ -120,9 +116,7 @@ stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx)
 xmpp_stanza_t*
 stanza_create_blocked_list_request(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, NULL);
 
     xmpp_stanza_t *blocklist = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(blocklist, STANZA_NAME_BLOCKLIST);
@@ -139,10 +133,9 @@ xmpp_stanza_t*
 stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char *const jid,
     const gboolean autojoin, const char *const nick)
 {
-    xmpp_stanza_t *stanza = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(stanza, STANZA_NAME_IQ);
-    _stanza_add_unique_id(stanza, "bookmark_add");
-    xmpp_stanza_set_type(stanza, STANZA_TYPE_SET);
+    char *id = create_unique_id("bookmark_add");
+    xmpp_stanza_t *stanza = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
 
     xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
@@ -230,11 +223,8 @@ xmpp_stanza_t*
 stanza_create_http_upload_request(xmpp_ctx_t *ctx, const char *const id,
     const char *const jid, HTTPUpload *upload)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
     xmpp_stanza_set_to(iq, jid);
-    xmpp_stanza_set_id(iq, id);
 
     xmpp_stanza_t *request = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(request, STANZA_NAME_REQUEST);
@@ -283,10 +273,9 @@ stanza_create_http_upload_request(xmpp_ctx_t *ctx, const char *const id,
 xmpp_stanza_t*
 stanza_enable_carbons(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
-    _stanza_add_unique_id(iq, "carbons");
+    char *id = create_unique_id("carbons");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
 
     xmpp_stanza_t *carbons_enable = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(carbons_enable, STANZA_NAME_ENABLE);
@@ -301,10 +290,9 @@ stanza_enable_carbons(xmpp_ctx_t *ctx)
 xmpp_stanza_t*
 stanza_disable_carbons(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
-    _stanza_add_unique_id(iq, "carbons");
+    char *id = create_unique_id("carbons");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
 
     xmpp_stanza_t *carbons_disable = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(carbons_disable, STANZA_NAME_DISABLE);
@@ -439,10 +427,9 @@ stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *cons
 xmpp_stanza_t*
 stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char *const barejid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
-    _stanza_add_unique_id(iq, "roster");
+    char *id = create_unique_id("roster");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -466,12 +453,7 @@ xmpp_stanza_t*
 stanza_create_roster_set(xmpp_ctx_t *ctx, const char *const id,
     const char *const jid, const char *const handle, GSList *groups)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
-    if (id) {
-        xmpp_stanza_set_id(iq, id);
-    }
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -632,11 +614,10 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char *const room,
 xmpp_stanza_t*
 stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx, const char *const room_jid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("room");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room_jid);
-    _stanza_add_unique_id(iq, "room");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -659,11 +640,10 @@ stanza_create_instant_room_request_iq(xmpp_ctx_t *ctx, const char *const room_ji
 xmpp_stanza_t*
 stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx, const char *const room_jid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("room");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room_jid);
-    _stanza_add_unique_id(iq, "room");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -684,11 +664,10 @@ stanza_create_instant_room_destroy_iq(xmpp_ctx_t *ctx, const char *const room_ji
 xmpp_stanza_t*
 stanza_create_room_config_request_iq(xmpp_ctx_t *ctx, const char *const room_jid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    char *id = create_unique_id("room");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room_jid);
-    _stanza_add_unique_id(iq, "room");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -703,11 +682,10 @@ stanza_create_room_config_request_iq(xmpp_ctx_t *ctx, const char *const room_jid
 xmpp_stanza_t*
 stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char *const room_jid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("room");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room_jid);
-    _stanza_add_unique_id(iq, "room");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -730,11 +708,10 @@ stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx, const char *const room_jid)
 xmpp_stanza_t*
 stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char *const room, const char *const affiliation)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    char *id = create_unique_id("affiliation_get");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "affiliation_get");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -755,11 +732,10 @@ stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const char *const room,
 xmpp_stanza_t*
 stanza_create_room_role_list_iq(xmpp_ctx_t *ctx, const char *const room, const char *const role)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    char *id = create_unique_id("role_get");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "role_get");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -781,11 +757,10 @@ xmpp_stanza_t*
 stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char *const room, const char *const jid,
     const char *const affiliation, const char *const reason)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("affiliation_set");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "affiliation_set");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -820,11 +795,10 @@ xmpp_stanza_t*
 stanza_create_room_role_set_iq(xmpp_ctx_t *const ctx, const char *const room, const char *const nick,
     const char *const role, const char *const reason)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("role_set");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "role_set");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -859,11 +833,10 @@ xmpp_stanza_t*
 stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *const room, const char *const nick,
     const char *const reason)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("room_kick");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "room_kick");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -906,10 +879,9 @@ stanza_create_presence(xmpp_ctx_t *const ctx)
 xmpp_stanza_t*
 stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char *const fulljid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
-    _stanza_add_unique_id(iq, "sv");
+    char *id = create_unique_id("sv");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
+    free(id);
     xmpp_stanza_set_to(iq, fulljid);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
@@ -925,10 +897,7 @@ stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char *const fulljid)
 xmpp_stanza_t*
 stanza_create_roster_iq(xmpp_ctx_t *ctx)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
-    xmpp_stanza_set_id(iq, "roster");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, "roster");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -944,11 +913,8 @@ xmpp_stanza_t*
 stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char *const id, const char *const to,
     const char *const node)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
     xmpp_stanza_set_to(iq, to);
-    xmpp_stanza_set_id(iq, id);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -967,11 +933,8 @@ xmpp_stanza_t*
 stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id,
     const char *const jid)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
     xmpp_stanza_set_to(iq, jid);
-    xmpp_stanza_set_id(iq, id);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -986,11 +949,8 @@ stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id,
 xmpp_stanza_t*
 stanza_create_last_activity_iq(xmpp_ctx_t *ctx, const char *const id, const char *const to)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
     xmpp_stanza_set_to(iq, to);
-    xmpp_stanza_set_id(iq, id);
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -1005,11 +965,10 @@ stanza_create_last_activity_iq(xmpp_ctx_t *ctx, const char *const id, const char
 xmpp_stanza_t*
 stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, DataForm *form)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
+    char *id = create_unique_id("roomconf_submit");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
     xmpp_stanza_set_to(iq, room);
-    _stanza_add_unique_id(iq, "roomconf_submit");
 
     xmpp_stanza_t *query = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
@@ -1083,13 +1042,12 @@ stanza_contains_chat_state(xmpp_stanza_t *stanza)
 xmpp_stanza_t*
 stanza_create_ping_iq(xmpp_ctx_t *ctx, const char *const target)
 {
-    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
-    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
+    char *id = create_unique_id("ping");
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id);
+    free(id);
     if (target) {
         xmpp_stanza_set_to(iq, target);
     }
-    _stanza_add_unique_id(iq, "ping");
 
     xmpp_stanza_t *ping = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(ping, STANZA_NAME_PING);