Move logic to connection_set_disco_items
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
#include "event/server_events.h"
|
#include "event/server_events.h"
|
||||||
#include "xmpp/connection.h"
|
#include "xmpp/connection.h"
|
||||||
#include "xmpp/session.h"
|
#include "xmpp/session.h"
|
||||||
|
#include "xmpp/iq.h"
|
||||||
|
|
||||||
typedef struct prof_conn_t {
|
typedef struct prof_conn_t {
|
||||||
xmpp_log_t *xmpp_log;
|
xmpp_log_t *xmpp_log;
|
||||||
@@ -291,12 +292,6 @@ connection_set_presence_msg(const char *const message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
connection_set_disco_items(GSList *disco_items)
|
|
||||||
{
|
|
||||||
conn.disco_items = disco_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
connection_free_domain(void)
|
connection_free_domain(void)
|
||||||
{
|
{
|
||||||
@@ -396,6 +391,22 @@ connection_supports(const char *const feature)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
connection_set_disco_items(GSList *items)
|
||||||
|
{
|
||||||
|
GSList *curr = items;
|
||||||
|
while (curr) {
|
||||||
|
DiscoItem *item = curr->data;
|
||||||
|
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||||
|
info->item = strdup(item->jid);
|
||||||
|
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||||
|
conn.disco_items = g_slist_append(conn.disco_items, info);
|
||||||
|
iq_disco_info_request_onconnect(info->item);
|
||||||
|
|
||||||
|
curr = g_slist_next(curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status, const int error,
|
_connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status, const int error,
|
||||||
xmpp_stream_error_t *const stream_error, void *const userdata)
|
xmpp_stream_error_t *const stream_error, void *const userdata)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void connection_set_status(jabber_conn_status_t status);
|
|||||||
void connection_set_presence_msg(const char *const message);
|
void connection_set_presence_msg(const char *const message);
|
||||||
void connection_set_priority(const int priority);
|
void connection_set_priority(const int priority);
|
||||||
void connection_set_priority(int priority);
|
void connection_set_priority(int priority);
|
||||||
void connection_set_disco_items(GSList *disco_items);
|
void connection_set_disco_items(GSList *items);
|
||||||
|
|
||||||
void connection_free_conn(void);
|
void connection_free_conn(void);
|
||||||
void connection_free_ctx(void);
|
void connection_free_ctx(void);
|
||||||
|
|||||||
@@ -2015,32 +2015,42 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
|
|||||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
GSList *items = NULL;
|
GSList *items = NULL;
|
||||||
|
|
||||||
if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0) || (g_strcmp0(id, "discoitemsreq_onconnect") == 0)) {
|
if ((g_strcmp0(id, "confreq") != 0) &&
|
||||||
log_debug("Response to query: %s", id);
|
(g_strcmp0(id, "discoitemsreq") != 0) &&
|
||||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
(g_strcmp0(id, "discoitemsreq_onconnect") != 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (query) {
|
log_debug("Response to query: %s", id);
|
||||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
|
||||||
while (child) {
|
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||||
const char *stanza_name = xmpp_stanza_get_name(child);
|
if (query == NULL) {
|
||||||
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
|
return;
|
||||||
const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
}
|
||||||
if (item_jid) {
|
|
||||||
DiscoItem *item = malloc(sizeof(struct disco_item_t));
|
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||||
item->jid = strdup(item_jid);
|
if (child == NULL) {
|
||||||
const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
return;
|
||||||
if (item_name) {
|
}
|
||||||
item->name = strdup(item_name);
|
|
||||||
} else {
|
while (child) {
|
||||||
item->name = NULL;
|
const char *stanza_name = xmpp_stanza_get_name(child);
|
||||||
}
|
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
|
||||||
items = g_slist_append(items, item);
|
const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
||||||
}
|
if (item_jid) {
|
||||||
|
DiscoItem *item = malloc(sizeof(struct disco_item_t));
|
||||||
|
item->jid = strdup(item_jid);
|
||||||
|
const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
||||||
|
if (item_name) {
|
||||||
|
item->name = strdup(item_name);
|
||||||
|
} else {
|
||||||
|
item->name = NULL;
|
||||||
}
|
}
|
||||||
|
items = g_slist_append(items, item);
|
||||||
child = xmpp_stanza_get_next(child);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
child = xmpp_stanza_get_next(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(id, "confreq") == 0) {
|
if (g_strcmp0(id, "confreq") == 0) {
|
||||||
@@ -2048,18 +2058,7 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
|
|||||||
} else if (g_strcmp0(id, "discoitemsreq") == 0) {
|
} else if (g_strcmp0(id, "discoitemsreq") == 0) {
|
||||||
cons_show_disco_items(items, from);
|
cons_show_disco_items(items, from);
|
||||||
} else if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
|
} else if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
|
||||||
GSList *res_items = items;
|
connection_set_disco_items(items);
|
||||||
if (res_items && (g_slist_length(res_items) > 0)) {
|
|
||||||
while (res_items) {
|
|
||||||
DiscoItem *item = res_items->data;
|
|
||||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
|
||||||
info->item = strdup(item->jid);
|
|
||||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
|
||||||
connection_set_disco_items(g_slist_append(connection_get_disco_items(), info));
|
|
||||||
iq_disco_info_request_onconnect(info->item);
|
|
||||||
res_items = g_slist_next(res_items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
|
g_slist_free_full(items, (GDestroyNotify)_item_destroy);
|
||||||
|
|||||||
Reference in New Issue
Block a user