diff --git a/src/xmpp/blocking.c b/src/xmpp/blocking.c index a5a920e4..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; } @@ -239,7 +233,7 @@ _block_add_result_handler(xmpp_stanza_t *const stanza, void *const userdata) { char *jid = (char*)userdata; - const char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); + const char *type = xmpp_stanza_get_type(stanza); if (type == NULL) { log_info("Block response received for %s with no type attribute.", jid); free(jid); @@ -263,7 +257,7 @@ _block_remove_result_handler(xmpp_stanza_t *const stanza, void *const userdata) { char *jid = (char*)userdata; - const char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); + const char *type = xmpp_stanza_get_type(stanza); if (type == NULL) { log_info("Unblock response received for %s with no type attribute.", jid); free(jid); 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/form.c b/src/xmpp/form.c index 3619f95b..25f1bb7b 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -67,7 +67,7 @@ _is_valid_form_element(xmpp_stanza_t *stanza) return FALSE; } - const char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); + const char *type = xmpp_stanza_get_type(stanza); if ((g_strcmp0(type, "form") != 0) && (g_strcmp0(type, "submit") != 0) && (g_strcmp0(type, "cancel") != 0) && diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 345eefae..260c062e 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -673,7 +673,7 @@ iq_send_ping(const char *const target) static void _error_handler(xmpp_stanza_t *const stanza) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); char *error_msg = stanza_get_error_message(stanza); if (id) { @@ -690,7 +690,7 @@ _error_handler(xmpp_stanza_t *const stanza) static int _caps_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); const char *type = xmpp_stanza_get_type(stanza); @@ -705,7 +705,7 @@ _caps_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata) log_info("Capabilities response handler fired"); } - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { log_info("No from attribute"); return 0; @@ -764,7 +764,7 @@ static int _caps_response_for_jid_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { char *jid = (char *)userdata; - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); const char *type = xmpp_stanza_get_type(stanza); @@ -780,7 +780,7 @@ _caps_response_for_jid_id_handler(xmpp_stanza_t *const stanza, void *const userd log_info("Capabilities response handler fired"); } - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { log_info("No from attribute"); free(jid); @@ -821,7 +821,7 @@ _caps_response_for_jid_id_handler(xmpp_stanza_t *const stanza, void *const userd static int _caps_response_legacy_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); char *expected_node = (char *)userdata; @@ -838,7 +838,7 @@ _caps_response_legacy_id_handler(xmpp_stanza_t *const stanza, void *const userda log_info("Capabilities response handler fired"); } - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { log_info("No from attribute"); free(expected_node); @@ -925,7 +925,7 @@ _disable_carbons_id_handler(xmpp_stanza_t *const stanza, void *const userdata) static int _manual_pong_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); const char *type = xmpp_stanza_get_type(stanza); GDateTime *sent = (GDateTime *)userdata; @@ -1053,7 +1053,7 @@ _version_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) } const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (g_strcmp0(type, STANZA_TYPE_RESULT) != 0) { if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { @@ -1068,7 +1068,7 @@ _version_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) return 0; } - const char *jid = xmpp_stanza_get_attribute(stanza, "from"); + const char *jid = xmpp_stanza_get_from(stanza); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { @@ -1144,9 +1144,9 @@ static void _ping_get_handler(xmpp_stanza_t *const stanza) { xmpp_ctx_t * const ctx = connection_get_ctx(); - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - const char *to = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TO); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *id = xmpp_stanza_get_id(stanza); + const char *to = xmpp_stanza_get_to(stanza); + const char *from = xmpp_stanza_get_from(stanza); if (id) { log_debug("IQ ping get handler fired, id: %s.", id); @@ -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_set_attribute(pong, STANZA_ATTR_TO, from); - xmpp_stanza_set_attribute(pong, STANZA_ATTR_FROM, to); - xmpp_stanza_set_attribute(pong, STANZA_ATTR_TYPE, STANZA_TYPE_RESULT); - - if (id) { - xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id); - } + xmpp_stanza_t *pong = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id); + xmpp_stanza_set_to(pong, from); + xmpp_stanza_set_from(pong, to); iq_send_stanza(pong); xmpp_stanza_release(pong); @@ -1176,8 +1170,8 @@ static void _version_get_handler(xmpp_stanza_t *const stanza) { xmpp_ctx_t * const ctx = connection_get_ctx(); - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *id = xmpp_stanza_get_id(stanza); + const char *from = xmpp_stanza_get_from(stanza); if (id) { log_debug("IQ version get handler fired, id: %s.", id); @@ -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_set_attribute(response, STANZA_ATTR_TO, from); - xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); + xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id); + xmpp_stanza_set_to(response, from); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -1241,8 +1230,8 @@ static void _disco_items_get_handler(xmpp_stanza_t *const stanza) { xmpp_ctx_t * const ctx = connection_get_ctx(); - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *id = xmpp_stanza_get_id(stanza); + const char *from = xmpp_stanza_get_from(stanza); if (id) { log_debug("IQ disco items get handler fired, id: %s.", id); @@ -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_set_attribute(response, STANZA_ATTR_TO, from); - xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); + xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza)); + xmpp_stanza_set_to(response, from); + 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); @@ -1271,7 +1258,7 @@ static void _last_activity_get_handler(xmpp_stanza_t *const stanza) { xmpp_ctx_t *ctx = connection_get_ctx(); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { return; @@ -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_set_attribute(response, STANZA_ATTR_TO, from); - xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); + xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza)); + xmpp_stanza_set_to(response, from); 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_set_attribute(response, STANZA_ATTR_TO, from); - xmpp_stanza_set_type(response, STANZA_TYPE_ERROR); + xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_ERROR, xmpp_stanza_get_id(stanza)); + xmpp_stanza_set_to(response, from); xmpp_stanza_t *error = xmpp_stanza_new(ctx); xmpp_stanza_set_name(error, STANZA_NAME_ERROR); @@ -1330,12 +1311,12 @@ static void _disco_info_get_handler(xmpp_stanza_t *const stanza) { xmpp_ctx_t * const ctx = connection_get_ctx(); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); xmpp_stanza_t *incoming_query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); const char *node_str = xmpp_stanza_get_attribute(incoming_query, STANZA_ATTR_NODE); - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); if (id) { log_debug("IQ disco info get handler fired, id: %s.", id); @@ -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_set_attribute(response, STANZA_ATTR_TO, from); - xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); + xmpp_stanza_t *response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, xmpp_stanza_get_id(stanza)); + xmpp_stanza_set_to(response, from); + xmpp_stanza_t *query = stanza_create_caps_query_element(ctx); if (node_str) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str); @@ -1364,7 +1343,7 @@ _disco_info_get_handler(xmpp_stanza_t *const stanza) static int _destroy_room_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); if (id) { log_debug("IQ destroy room result handler fired, id: %s.", id); @@ -1372,7 +1351,7 @@ _destroy_room_result_id_handler(xmpp_stanza_t *const stanza, void *const userdat log_debug("IQ destroy room result handler fired."); } - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (from == NULL) { log_error("No from attribute for IQ destroy room result"); } else { @@ -1385,9 +1364,9 @@ _destroy_room_result_id_handler(xmpp_stanza_t *const stanza, void *const userdat static int _room_config_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (id) { log_debug("IQ room config handler fired, id: %s.", id); @@ -1423,7 +1402,7 @@ _room_config_id_handler(xmpp_stanza_t *const stanza, void *const userdata) return 0; } - const char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE); + const char *form_type = xmpp_stanza_get_type(x); if (g_strcmp0(form_type, "form") != 0) { log_warning("x element not of type 'form' parsing room config response"); ui_handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); @@ -1440,9 +1419,9 @@ _room_config_id_handler(xmpp_stanza_t *const stanza, void *const userdata) static int _room_affiliation_set_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); ProfPrivilegeSet *affiliation_set = (ProfPrivilegeSet*)userdata; if (id) { @@ -1472,9 +1451,9 @@ _room_affiliation_set_result_id_handler(xmpp_stanza_t *const stanza, void *const static int _room_role_set_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); ProfPrivilegeSet *role_set = (ProfPrivilegeSet*)userdata; if (id) { @@ -1504,9 +1483,9 @@ _room_role_set_result_id_handler(xmpp_stanza_t *const stanza, void *const userda static int _room_affiliation_list_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); char *affiliation = (char *)userdata; if (id) { @@ -1558,9 +1537,9 @@ _room_affiliation_list_result_id_handler(xmpp_stanza_t *const stanza, void *cons static int _room_role_list_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); char *role = (char *)userdata; if (id) { @@ -1611,9 +1590,9 @@ _room_role_list_result_id_handler(xmpp_stanza_t *const stanza, void *const userd static int _room_config_submit_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (id) { log_debug("IQ room config submit handler fired, id: %s.", id); @@ -1637,9 +1616,9 @@ _room_config_submit_id_handler(xmpp_stanza_t *const stanza, void *const userdata static int _room_kick_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); const char *type = xmpp_stanza_get_type(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); char *nick = (char *)userdata; if (id) { @@ -1717,7 +1696,7 @@ _room_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); - const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); + const char *type = xmpp_stanza_get_type(child); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); if (name || category || type) { @@ -1765,7 +1744,7 @@ _room_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata static int _last_activity_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { cons_show_error("Invalid last activity response received."); log_info("Received last activity response with no from attribute."); @@ -1819,7 +1798,7 @@ _last_activity_response_id_handler(xmpp_stanza_t *const stanza, void *const user static int _disco_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); const char *type = xmpp_stanza_get_type(stanza); if (from) { @@ -1855,7 +1834,7 @@ _disco_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdat } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); - const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); + const char *type = xmpp_stanza_get_type(child); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); if (name || category || type) { @@ -1896,7 +1875,7 @@ _disco_info_response_id_handler(xmpp_stanza_t *const stanza, void *const userdat static int _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *const userdata) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); const char *type = xmpp_stanza_get_type(stanza); if (from) { @@ -1946,7 +1925,7 @@ static int _http_upload_response_id_handler(xmpp_stanza_t *const stanza, void *const userdata) { HTTPUpload *upload = (HTTPUpload *)userdata; - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); const char *type = xmpp_stanza_get_type(stanza); if (from) { @@ -2000,8 +1979,8 @@ static void _disco_items_result_handler(xmpp_stanza_t *const stanza) { log_debug("Received disco#items response"); - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *id = xmpp_stanza_get_id(stanza); + const char *from = xmpp_stanza_get_from(stanza); GSList *items = NULL; if ((g_strcmp0(id, "confreq") != 0) && diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 60c63178..bb7b6d18 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) { @@ -353,11 +366,11 @@ static void _handle_error(xmpp_stanza_t *const stanza) { const char *id = xmpp_stanza_get_id(stanza); - const char *jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *jid = xmpp_stanza_get_from(stanza); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); const char *type = NULL; if (error_stanza) { - type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); + type = xmpp_stanza_get_type(error_stanza); } // stanza_get_error never returns NULL @@ -402,7 +415,7 @@ _handel_muc_user(xmpp_stanza_t *const stanza) { xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - const char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *room = xmpp_stanza_get_from(stanza); if (!room) { log_warning("Message received with no from attribute, ignoring"); @@ -415,7 +428,7 @@ _handel_muc_user(xmpp_stanza_t *const stanza) return; } - const char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM); + const char *invitor_jid = xmpp_stanza_get_from(invite); if (!invitor_jid) { log_warning("Chat room invite received with no from attribute"); return; @@ -454,7 +467,7 @@ _handle_conference(xmpp_stanza_t *const stanza) { xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { log_warning("Message received with no from attribute, ignoring"); return; @@ -483,7 +496,7 @@ static void _handle_captcha(xmpp_stanza_t *const stanza) { xmpp_ctx_t *ctx = connection_get_ctx(); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { log_warning("Message received with no from attribute, ignoring"); @@ -491,12 +504,7 @@ _handle_captcha(xmpp_stanza_t *const stanza) } // XEP-0158 - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (!body) { - return; - } - - char *message = xmpp_stanza_get_text(body); + char *message = xmpp_message_get_body(stanza); if (!message) { return; } @@ -510,7 +518,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza) { xmpp_ctx_t *ctx = connection_get_ctx(); char *message = NULL; - const char *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *room_jid = xmpp_stanza_get_from(stanza); Jid *jid = jid_create(room_jid); // handle room subject @@ -526,13 +534,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza) // handle room broadcasts if (!jid->resourcepart) { - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (!body) { - jid_destroy(jid); - return; - } - - message = xmpp_stanza_get_text(body); + message = xmpp_message_get_body(stanza); if (!message) { jid_destroy(jid); return; @@ -558,15 +560,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza) return; } - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - - // check for and deal with message - if (!body) { - jid_destroy(jid); - return; - } - - message = xmpp_stanza_get_text(body); + message = xmpp_message_get_body(stanza); if (!message) { jid_destroy(jid); return; @@ -589,17 +583,15 @@ void _message_send_receipt(const char *const fulljid, const char *const message_id) { xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); + char *id = create_unique_id("receipt"); - xmpp_stanza_set_id(message, id); + xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, fulljid, id); free(id); - xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, fulljid); xmpp_stanza_t *receipt = xmpp_stanza_new(ctx); xmpp_stanza_set_name(receipt, "received"); xmpp_stanza_set_ns(receipt, STANZA_NS_RECEIPTS); - xmpp_stanza_set_attribute(receipt, STANZA_ATTR_ID, message_id); + xmpp_stanza_set_id(receipt, message_id); xmpp_stanza_add_child(message, receipt); xmpp_stanza_release(receipt); @@ -617,12 +609,12 @@ _handle_receipt_received(xmpp_stanza_t *const stanza) return; } - const char *id = xmpp_stanza_get_attribute(receipt, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(receipt); if (!id) { return; } - const char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *fulljid = xmpp_stanza_get_from(stanza); if (!fulljid) { return; } @@ -654,7 +646,7 @@ _receipt_request_handler(xmpp_stanza_t *const stanza) return; } - const gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const gchar *from = xmpp_stanza_get_from(stanza); Jid *jid = jid_create(from); _message_send_receipt(jid->fulljid, id); jid_destroy(jid); @@ -663,12 +655,7 @@ _receipt_request_handler(xmpp_stanza_t *const stanza) void _private_chat_handler(xmpp_stanza_t *const stanza, const char *const fulljid) { - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (!body) { - return; - } - - char *message = xmpp_stanza_get_text(body); + char *message = xmpp_message_get_body(stanza); if (!message) { return; } @@ -700,8 +687,8 @@ _handle_carbons(xmpp_stanza_t *const stanza) xmpp_ctx_t *ctx = connection_get_ctx(); - const gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); - const gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + const gchar *to = xmpp_stanza_get_to(message); + const gchar *from = xmpp_stanza_get_from(message); // happens when receive a carbon of a self sent message if (!to) to = from; @@ -711,28 +698,25 @@ _handle_carbons(xmpp_stanza_t *const stanza) Jid *my_jid = jid_create(connection_get_fulljid()); // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body) { - char *message_txt = xmpp_stanza_get_text(body); - if (message_txt) { - // check for pgp encrypted message - char *enc_message = NULL; - xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED); - if (x) { - enc_message = xmpp_stanza_get_text(x); - } - - // if we are the recipient, treat as standard incoming message - if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message); - - // else treat as a sent message - } else { - sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message); - } - xmpp_free(ctx, message_txt); - xmpp_free(ctx, enc_message); + char *message_txt = xmpp_message_get_body(message); + if (message_txt) { + // check for pgp encrypted message + char *enc_message = NULL; + xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED); + if (x) { + enc_message = xmpp_stanza_get_text(x); } + + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message); + + // else treat as a sent message + } else { + sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message); + } + xmpp_free(ctx, message_txt); + xmpp_free(ctx, enc_message); } jid_destroy(jid_from); @@ -776,7 +760,7 @@ _handle_chat(xmpp_stanza_t *const stanza) return; } - const gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const gchar *from = xmpp_stanza_get_from(stanza); Jid *jid = jid_create(from); // private message from chat room use full jid (room/nick) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 00d50039..31fc6cde 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -172,12 +172,11 @@ presence_subscription(const char *const jid, const jabber_subscr_t action) break; } - xmpp_stanza_t *presence = xmpp_stanza_new(ctx); + xmpp_stanza_t *presence = xmpp_presence_new(ctx); char *id = create_unique_id("sub"); xmpp_stanza_set_id(presence, id); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_type(presence, type); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, jidp->barejid); + xmpp_stanza_set_to(presence, jidp->barejid); _send_presence_stanza(presence); xmpp_stanza_release(presence); @@ -258,7 +257,7 @@ presence_send(const resource_presence_t presence_type, const char *const msg, co connection_set_presence_msg(msg); connection_set_priority(pri); - xmpp_stanza_t *presence = stanza_create_presence(ctx); + xmpp_stanza_t *presence = xmpp_presence_new(ctx); char *id = create_unique_id("presence"); xmpp_stanza_set_id(presence, id); stanza_attach_show(ctx, presence, show); @@ -310,7 +309,7 @@ _send_room_presence(xmpp_stanza_t *presence) if (nick) { char *full_room_jid = create_fulljid(room, nick); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); + xmpp_stanza_set_to(presence, full_room_jid); log_debug("Sending presence to room: %s", full_room_jid); _send_presence_stanza(presence); free(full_room_jid); @@ -397,7 +396,7 @@ static void _presence_error_handler(xmpp_stanza_t *const stanza) { const char *id = xmpp_stanza_get_id(stanza); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); const char *xmlns = NULL; @@ -406,7 +405,7 @@ _presence_error_handler(xmpp_stanza_t *const stanza) } const char *type = NULL; if (error_stanza) { - type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); + type = xmpp_stanza_get_type(error_stanza); } // handle MUC join errors @@ -467,7 +466,7 @@ _presence_error_handler(xmpp_stanza_t *const stanza) static void _unsubscribed_handler(xmpp_stanza_t *const stanza) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); Jid *from_jid = jid_create(from); log_debug("Unsubscribed presence handler fired for %s", from); @@ -480,7 +479,7 @@ _unsubscribed_handler(xmpp_stanza_t *const stanza) static void _subscribed_handler(xmpp_stanza_t *const stanza) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); Jid *from_jid = jid_create(from); log_debug("Subscribed presence handler fired for %s", from); @@ -493,7 +492,7 @@ _subscribed_handler(xmpp_stanza_t *const stanza) static void _subscribe_handler(xmpp_stanza_t *const stanza) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); log_debug("Subscribe presence handler fired for %s", from); Jid *from_jid = jid_create(from); @@ -514,7 +513,7 @@ _unavailable_handler(xmpp_stanza_t *const stanza) xmpp_conn_t *conn = connection_get_conn(); const char *jid = xmpp_conn_get_jid(conn); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); log_debug("Unavailable presence handler fired for %s", from); Jid *my_jid = jid_create(jid); @@ -615,7 +614,7 @@ _available_handler(xmpp_stanza_t *const stanza) log_warning("Available presence handler fired with no from attribute."); break; case STANZA_PARSE_ERROR_INVALID_FROM: - from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + from = xmpp_stanza_get_from(stanza); log_warning("Available presence handler fired with invalid from attribute: %s", from); break; default: @@ -684,8 +683,8 @@ _muc_user_handler(xmpp_stanza_t *const stanza) { inp_nonblocking(TRUE); - const char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *type = xmpp_stanza_get_type(stanza); + const char *from = xmpp_stanza_get_from(stanza); // handler still fires if error if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 7955aef3..c7725b43 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -218,7 +218,7 @@ roster_set_handler(xmpp_stanza_t *const stanza) // if from attribute exists and it is not current users barejid, ignore push Jid *my_jid = jid_create(connection_get_fulljid()); - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (from && (strcmp(from, my_jid->barejid) != 0)) { jid_destroy(my_jid); return; @@ -276,7 +276,7 @@ roster_set_handler(xmpp_stanza_t *const stanza) void roster_result_handler(xmpp_stanza_t *const stanza) { - const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + const char *id = xmpp_stanza_get_id(stanza); if (g_strcmp0(id, "roster") != 0) { return; diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index c88df237..bf4e44e1 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); @@ -185,13 +178,13 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char *const jid, xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_ns(x, STANZA_NS_DATA); - xmpp_stanza_set_attribute(x, STANZA_ATTR_TYPE, "submit"); + xmpp_stanza_set_type(x, "submit"); xmpp_stanza_add_child(publish_options, x); xmpp_stanza_t *form_type = xmpp_stanza_new(ctx); xmpp_stanza_set_name(form_type, STANZA_NAME_FIELD); xmpp_stanza_set_attribute(form_type, STANZA_ATTR_VAR, "FORM_TYPE"); - xmpp_stanza_set_attribute(form_type, STANZA_ATTR_TYPE, "hidden"); + xmpp_stanza_set_type(form_type, "hidden"); xmpp_stanza_t *form_type_value = xmpp_stanza_new(ctx); xmpp_stanza_set_name(form_type_value, STANZA_NAME_VALUE); xmpp_stanza_t *form_type_value_text = xmpp_stanza_new(ctx); @@ -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_set_attribute(iq, STANZA_ATTR_TO, jid); - xmpp_stanza_set_id(iq, id); + xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); + xmpp_stanza_set_to(iq, jid); 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); @@ -319,12 +307,9 @@ stanza_disable_carbons(xmpp_ctx_t *ctx) xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, const char *const fulljid, const char *const state) { - xmpp_stanza_t *msg = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); - xmpp_stanza_set_type(msg, STANZA_TYPE_CHAT); - xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, fulljid); - _stanza_add_unique_id(msg, NULL); - + char *id = create_unique_id(NULL); + xmpp_stanza_t *msg = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id); + free(id); xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx); xmpp_stanza_set_name(chat_state, state); @@ -338,10 +323,7 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char *const fulljid, const char xmpp_stanza_t* stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char *const room, const char *const subject) { - xmpp_stanza_t *msg = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); - xmpp_stanza_set_type(msg, STANZA_TYPE_GROUPCHAT); - xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, room); + xmpp_stanza_t *msg = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, room, NULL); xmpp_stanza_t *subject_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(subject_st, STANZA_NAME_SUBJECT); @@ -442,36 +424,12 @@ stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *cons return stanza; } -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_attribute(msg, STANZA_ATTR_TO, 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); - 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); @@ -495,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); @@ -540,10 +493,9 @@ xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char *const room, const char *const contact, const char *const reason, const char *const password) { - xmpp_stanza_t *message = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); - xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, contact); - _stanza_add_unique_id(message, NULL); + char *id = create_unique_id(NULL); + xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, contact, id); + free(id); xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); @@ -567,10 +519,9 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char *const room, const char *const contact, const char *const reason) { - xmpp_stanza_t *message = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); - xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, room); - _stanza_add_unique_id(message, NULL); + char *id = create_unique_id(NULL); + xmpp_stanza_t *message = xmpp_message_new(ctx, NULL, room, id); + free(id); xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_set_name(x, STANZA_NAME_X); @@ -578,7 +529,7 @@ stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char *const room, xmpp_stanza_t *invite = xmpp_stanza_new(ctx); xmpp_stanza_set_name(invite, STANZA_NAME_INVITE); - xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact); + xmpp_stanza_set_to(invite, contact); if (reason) { xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx); @@ -603,9 +554,8 @@ xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *const ctx, const char *const full_room_jid, const char *const passwd) { - xmpp_stanza_t *presence = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); + xmpp_stanza_t *presence = xmpp_presence_new(ctx); + xmpp_stanza_set_to(presence, full_room_jid); _stanza_add_unique_id(presence, "join"); xmpp_stanza_t *x = xmpp_stanza_new(ctx); @@ -633,10 +583,9 @@ xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx, const char *const full_room_jid) { - xmpp_stanza_t *presence = xmpp_stanza_new(ctx); + xmpp_stanza_t *presence = xmpp_presence_new(ctx); _stanza_add_unique_id(presence, "sub"); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); + xmpp_stanza_set_to(presence, full_room_jid); return presence; } @@ -649,10 +598,9 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char *const room, g_string_append(full_jid, "/"); g_string_append(full_jid, nick); - xmpp_stanza_t *presence = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); + xmpp_stanza_t *presence = xmpp_presence_new(ctx); xmpp_stanza_set_type(presence, STANZA_TYPE_UNAVAILABLE); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_jid->str); + xmpp_stanza_set_to(presence, full_jid->str); _stanza_add_unique_id(presence, "leave"); g_string_free(full_jid, TRUE); @@ -663,11 +611,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room_jid); - _stanza_add_unique_id(iq, "room"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -690,11 +637,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room_jid); - _stanza_add_unique_id(iq, "room"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -715,11 +661,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room_jid); - _stanza_add_unique_id(iq, "room"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -734,11 +679,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room_jid); - _stanza_add_unique_id(iq, "room"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -761,11 +705,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "affiliation_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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -786,11 +729,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "role_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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -812,11 +754,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "affiliation_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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -851,11 +792,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "role_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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -890,11 +830,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "room_kick"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -925,23 +864,13 @@ stanza_create_room_kick_iq(xmpp_ctx_t *const ctx, const char *const room, const return iq; } -xmpp_stanza_t* -stanza_create_presence(xmpp_ctx_t *const ctx) -{ - xmpp_stanza_t *presence = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); - - return presence; -} - 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"); - xmpp_stanza_set_attribute(iq, "to", fulljid); + 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); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -956,10 +885,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); @@ -975,11 +901,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_set_attribute(iq, STANZA_ATTR_TO, to); - xmpp_stanza_set_id(iq, id); + xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); + xmpp_stanza_set_to(iq, to); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -998,11 +921,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_set_attribute(iq, STANZA_ATTR_TO, jid); - xmpp_stanza_set_id(iq, id); + xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); + xmpp_stanza_set_to(iq, jid); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -1017,11 +937,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_set_attribute(iq, STANZA_ATTR_TO, to); - xmpp_stanza_set_id(iq, id); + xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, id); + xmpp_stanza_set_to(iq, to); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -1036,11 +953,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); - xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room); - _stanza_add_unique_id(iq, "roomconf_submit"); + 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); xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); @@ -1066,7 +982,7 @@ stanza_create_caps_query_element(xmpp_ctx_t *ctx) xmpp_stanza_t *identity = xmpp_stanza_new(ctx); xmpp_stanza_set_name(identity, "identity"); xmpp_stanza_set_attribute(identity, "category", "client"); - xmpp_stanza_set_attribute(identity, "type", "console"); + xmpp_stanza_set_type(identity, "console"); GString *name_str = g_string_new("Profanity "); g_string_append(name_str, PACKAGE_VERSION); @@ -1114,13 +1030,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_attribute(iq, STANZA_ATTR_TO, 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); @@ -1145,7 +1060,7 @@ stanza_create_caps_sha1_from_query(xmpp_stanza_t *const query) while (child) { if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_IDENTITY) == 0) { const char *category = xmpp_stanza_get_attribute(child, "category"); - const char *type = xmpp_stanza_get_attribute(child, "type"); + const char *type = xmpp_stanza_get_type(child); const char *lang = xmpp_stanza_get_attribute(child, "xml:lang"); const char *name = xmpp_stanza_get_attribute(child, "name"); @@ -1398,7 +1313,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t *const stanza, } // check if 'from' attribute identifies this user - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (from) { Jid *from_jid = jid_create(from); if (muc_active(from_jid->barejid)) { @@ -1825,7 +1740,7 @@ stanza_create_caps_from_query_element(xmpp_stanza_t *query) const char *name = NULL; if (found) { category = xmpp_stanza_get_attribute(found, "category"); - type = xmpp_stanza_get_attribute(found, "type"); + type = xmpp_stanza_get_type(found); name = xmpp_stanza_get_attribute(found, "name"); } @@ -2062,7 +1977,7 @@ stanza_free_presence(XMPPPresence *presence) XMPPPresence* stanza_parse_presence(xmpp_stanza_t *stanza, int *err) { - const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + const char *from = xmpp_stanza_get_from(stanza); if (!from) { *err = STANZA_PARSE_ERROR_NO_FROM; return NULL; diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 806ba615..5bc1ff74 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); @@ -240,8 +237,6 @@ xmpp_stanza_t* stanza_create_room_newnick_presence(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char *const room, const char *const nick); -xmpp_stanza_t* stanza_create_presence(xmpp_ctx_t *const ctx); - xmpp_stanza_t* stanza_create_roster_iq(xmpp_ctx_t *ctx); xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t *ctx, const char *const target); xmpp_stanza_t* stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char *const id,