mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add connection_get_disco_info()
This commit is contained in:
parent
137202e5dd
commit
31e6cc8e38
@ -209,6 +209,21 @@ connection_get_disco_items(void)
|
||||
return conn.disco_items;
|
||||
}
|
||||
|
||||
DiscoInfo*
|
||||
connection_get_disco_info(const char *const jid)
|
||||
{
|
||||
GSList *curr = conn.disco_items;
|
||||
while (curr) {
|
||||
DiscoInfo *disco_info = curr->data;
|
||||
if (g_strcmp0(disco_info->jid, jid) == 0) {
|
||||
return disco_info;
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GList*
|
||||
connection_get_available_resources(void)
|
||||
{
|
||||
@ -360,7 +375,7 @@ static void
|
||||
_disco_item_destroy(DiscoInfo *info)
|
||||
{
|
||||
if (info) {
|
||||
free(info->item);
|
||||
free(info->jid);
|
||||
if (info->features) {
|
||||
g_hash_table_destroy(info->features);
|
||||
}
|
||||
@ -392,14 +407,14 @@ connection_supports(const char *const feature)
|
||||
}
|
||||
|
||||
char*
|
||||
connection_item_for_feature(const char *const feature)
|
||||
connection_jid_for_feature(const char *const feature)
|
||||
{
|
||||
DiscoInfo *disco_info;
|
||||
GSList *curr = conn.disco_items;
|
||||
while (curr) {
|
||||
disco_info = curr->data;
|
||||
if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
|
||||
return disco_info->item;
|
||||
return disco_info->jid;
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@ -414,10 +429,10 @@ connection_set_disco_items(GSList *items)
|
||||
while (curr) {
|
||||
DiscoItem *item = curr->data;
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = strdup(item->jid);
|
||||
info->jid = 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);
|
||||
iq_disco_info_request_onconnect(info->jid);
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@ -438,7 +453,7 @@ _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status
|
||||
jid_destroy(my_jid);
|
||||
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = strdup(conn.domain);
|
||||
info->jid = strdup(conn.domain);
|
||||
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);
|
||||
|
||||
|
@ -58,7 +58,8 @@ xmpp_conn_t* connection_get_conn(void);
|
||||
xmpp_ctx_t* connection_get_ctx(void);
|
||||
char *connection_get_domain(void);
|
||||
GSList* connection_get_disco_items(void);
|
||||
char* connection_item_for_feature(const char *const feature);
|
||||
char* connection_jid_for_feature(const char *const feature);
|
||||
DiscoInfo* connection_get_disco_info(const char *const jid);
|
||||
|
||||
void connection_add_available_resource(Resource *resource);
|
||||
void connection_remove_available_resource(const char *const resource);
|
||||
|
@ -309,15 +309,15 @@ iq_disable_carbons(void)
|
||||
void
|
||||
iq_http_upload_request(HTTPUpload *upload)
|
||||
{
|
||||
char *item = connection_item_for_feature(STANZA_NS_HTTP_UPLOAD);
|
||||
if (item == NULL) {
|
||||
char *jid = connection_jid_for_feature(STANZA_NS_HTTP_UPLOAD);
|
||||
if (jid == NULL) {
|
||||
cons_show_error("XEP-0363 HTTP File Upload is not supported by the server");
|
||||
return;
|
||||
}
|
||||
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
char *id = create_unique_id("http_upload_request");
|
||||
xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, item, upload);
|
||||
xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, jid, upload);
|
||||
iq_id_handler_add(id, _http_upload_response_id_handler, upload);
|
||||
free(id);
|
||||
|
||||
@ -1903,26 +1903,13 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
|
||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||
|
||||
if (query) {
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
|
||||
GSList *curr = connection_get_disco_items();
|
||||
if (curr == NULL) {
|
||||
DiscoInfo *disco_info = connection_get_disco_info(from);
|
||||
if (disco_info == NULL) {
|
||||
log_error("No matching disco item found for %s", from);
|
||||
return 1;
|
||||
}
|
||||
|
||||
DiscoInfo *disco_info;
|
||||
while (curr) {
|
||||
disco_info = curr->data;
|
||||
if (g_strcmp0(disco_info->item, from) == 0) {
|
||||
break;
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
if (!curr) {
|
||||
log_error("No matching disco item found for %s", from);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
while (child) {
|
||||
const char *stanza_name = xmpp_stanza_get_name(child);
|
||||
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
|
||||
|
@ -106,7 +106,7 @@ typedef struct disco_identity_t {
|
||||
} DiscoIdentity;
|
||||
|
||||
typedef struct disco_info_t {
|
||||
char *item;
|
||||
char *jid;
|
||||
GHashTable *features;
|
||||
} DiscoInfo;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user