mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Move disco info struct to connection
This commit is contained in:
parent
9596591610
commit
6ce8edc194
@ -2991,7 +2991,7 @@ cmd_blocked(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!session_service_supports(XMPP_FEATURE_BLOCKING)) {
|
||||
if (!connection_supports(XMPP_FEATURE_BLOCKING)) {
|
||||
cons_show("Blocking not supported by server.");
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ typedef struct prof_conn_t {
|
||||
int priority;
|
||||
char *domain;
|
||||
GHashTable *available_resources;
|
||||
GSList *disco_items;
|
||||
} ProfConnection;
|
||||
|
||||
static ProfConnection conn;
|
||||
@ -82,6 +83,7 @@ void connection_init(void)
|
||||
conn.xmpp_conn = NULL;
|
||||
conn.xmpp_ctx = NULL;
|
||||
conn.domain = NULL;
|
||||
conn.disco_items = NULL;
|
||||
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
|
||||
}
|
||||
|
||||
@ -199,6 +201,12 @@ connection_get_fulljid(void)
|
||||
return xmpp_conn_get_jid(conn.xmpp_conn);
|
||||
}
|
||||
|
||||
GSList*
|
||||
connection_get_disco_items(void)
|
||||
{
|
||||
return conn.disco_items;
|
||||
}
|
||||
|
||||
GList*
|
||||
connection_get_available_resources(void)
|
||||
{
|
||||
@ -282,6 +290,12 @@ connection_set_presence_msg(const char *const message)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
connection_set_disco_items(GSList *disco_items)
|
||||
{
|
||||
conn.disco_items = disco_items;
|
||||
}
|
||||
|
||||
void
|
||||
connection_free_domain(void)
|
||||
{
|
||||
@ -352,6 +366,50 @@ connection_send_stanza(const char *const stanza)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
connection_disco_on_login(void)
|
||||
{
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = 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);
|
||||
}
|
||||
|
||||
void
|
||||
_disco_item_destroy(DiscoInfo *info)
|
||||
{
|
||||
if (info) {
|
||||
free(info->item);
|
||||
if (info->features) {
|
||||
g_hash_table_destroy(info->features);
|
||||
}
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
connection_disco_items_free(void)
|
||||
{
|
||||
g_slist_free_full(conn.disco_items, (GDestroyNotify)_disco_item_destroy);
|
||||
conn.disco_items = NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
connection_supports(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 TRUE;
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_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)
|
||||
|
@ -41,14 +41,14 @@ void connection_init(void);
|
||||
|
||||
jabber_conn_status_t connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
|
||||
const char *const tls_policy);
|
||||
|
||||
char *connection_get_domain(void);
|
||||
void connection_disco_on_login(void);
|
||||
|
||||
void connection_set_status(jabber_conn_status_t status);
|
||||
void connection_set_presence_msg(const char *const message);
|
||||
void connection_set_priority(const int priority);
|
||||
void connection_set_domain(char *domain);
|
||||
void connection_set_priority(int priority);
|
||||
void connection_set_disco_items(GSList *disco_items);
|
||||
|
||||
void connection_free_conn(void);
|
||||
void connection_free_ctx(void);
|
||||
@ -58,6 +58,9 @@ void connection_free_log(void);
|
||||
|
||||
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);
|
||||
|
||||
void connection_add_available_resource(Resource *resource);
|
||||
void connection_remove_available_resource(const char *const resource);
|
||||
void connection_remove_all_available_resources(void);
|
||||
|
@ -309,7 +309,7 @@ iq_disable_carbons(void)
|
||||
void
|
||||
iq_http_upload_request(HTTPUpload *upload)
|
||||
{
|
||||
GSList *disco_items = session_get_disco_items();
|
||||
GSList *disco_items = connection_get_disco_items();
|
||||
DiscoInfo *disco_info;
|
||||
if (disco_items && (g_slist_length(disco_items) > 0)) {
|
||||
while (disco_items) {
|
||||
@ -1920,7 +1920,7 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
|
||||
if (query) {
|
||||
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
|
||||
|
||||
GSList *disco_items = session_get_disco_items();
|
||||
GSList *disco_items = connection_get_disco_items();
|
||||
DiscoInfo *disco_info;
|
||||
if (disco_items && (g_slist_length(disco_items) > 0)) {
|
||||
while (disco_items) {
|
||||
@ -2055,7 +2055,7 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
|
||||
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);
|
||||
session_set_disco_items(g_slist_append(session_get_disco_items(), info));
|
||||
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);
|
||||
}
|
||||
|
@ -66,8 +66,6 @@
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
static GSList *disco_items;
|
||||
|
||||
// for auto reconnect
|
||||
static struct {
|
||||
char *name;
|
||||
@ -91,8 +89,6 @@ static void _session_free_saved_account(void);
|
||||
static void _session_free_saved_details(void);
|
||||
static void _session_free_session_data(void);
|
||||
|
||||
static void _session_info_destroy(DiscoInfo *info);
|
||||
|
||||
void
|
||||
session_init(void)
|
||||
{
|
||||
@ -100,7 +96,6 @@ session_init(void)
|
||||
connection_init();
|
||||
presence_sub_requests_init();
|
||||
caps_init();
|
||||
disco_items = NULL;
|
||||
xmpp_initialize();
|
||||
}
|
||||
|
||||
@ -273,33 +268,6 @@ session_process_events(int millis)
|
||||
}
|
||||
}
|
||||
|
||||
GSList*
|
||||
session_get_disco_items(void)
|
||||
{
|
||||
return (disco_items);
|
||||
}
|
||||
|
||||
gboolean
|
||||
session_service_supports(const char *const feature)
|
||||
{
|
||||
DiscoInfo *disco_info;
|
||||
while (disco_items) {
|
||||
disco_info = disco_items->data;
|
||||
if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
|
||||
return TRUE;
|
||||
}
|
||||
disco_items = g_slist_next(disco_items);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
session_set_disco_items(GSList *_disco_items)
|
||||
{
|
||||
disco_items = _disco_items;
|
||||
}
|
||||
|
||||
char*
|
||||
session_get_account_name(void)
|
||||
{
|
||||
@ -342,11 +310,8 @@ session_login_success(gboolean secured)
|
||||
blocking_request();
|
||||
|
||||
// items discovery
|
||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
||||
info->item = strdup(connection_get_domain());
|
||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
disco_items = g_slist_append(disco_items, info);
|
||||
iq_disco_info_request_onconnect(info->item);
|
||||
connection_disco_on_login();
|
||||
iq_disco_info_request_onconnect(connection_get_domain());
|
||||
iq_disco_items_request_onconnect(connection_get_domain());
|
||||
|
||||
if (prefs_get_boolean(PREF_CARBONS)){
|
||||
@ -392,18 +357,6 @@ session_lost_connection(void)
|
||||
_session_free_session_data();
|
||||
}
|
||||
|
||||
static void
|
||||
_session_info_destroy(DiscoInfo *info)
|
||||
{
|
||||
if (info) {
|
||||
free(info->item);
|
||||
if (info->features) {
|
||||
g_hash_table_destroy(info->features);
|
||||
}
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_session_reconnect(void)
|
||||
{
|
||||
@ -441,8 +394,6 @@ _session_free_saved_details(void)
|
||||
static void
|
||||
_session_free_session_data(void)
|
||||
{
|
||||
g_slist_free_full(disco_items, (GDestroyNotify)_session_info_destroy);
|
||||
disco_items = NULL;
|
||||
connection_remove_all_available_resources();
|
||||
chat_sessions_clear();
|
||||
presence_clear_sub_requests();
|
||||
|
@ -49,8 +49,6 @@
|
||||
void session_login_success(gboolean secured);
|
||||
void session_login_failed(void);
|
||||
void session_lost_connection(void);
|
||||
GSList* session_get_disco_items(void);
|
||||
void session_set_disco_items(GSList *_disco_items);
|
||||
void session_autoping_fail(void);
|
||||
|
||||
#endif
|
||||
|
@ -119,7 +119,6 @@ void session_shutdown(void);
|
||||
void session_process_events(int millis);
|
||||
char* session_get_account_name(void);
|
||||
|
||||
gboolean session_service_supports(const char *const feature);
|
||||
|
||||
jabber_conn_status_t connection_get_status(void);
|
||||
char *connection_get_presence_msg(void);
|
||||
@ -132,6 +131,7 @@ TLSCertificate* connection_get_tls_peer_cert(void);
|
||||
gboolean connection_is_secured(void);
|
||||
gboolean connection_send_stanza(const char *const stanza);
|
||||
GList* connection_get_available_resources(void);
|
||||
gboolean connection_supports(const char *const feature);
|
||||
|
||||
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url);
|
||||
char* message_send_chat_otr(const char *const barejid, const char *const msg);
|
||||
|
@ -83,7 +83,7 @@ connection_send_stanza(const char *const stanza)
|
||||
}
|
||||
|
||||
gboolean
|
||||
session_service_supports(const char *const feature)
|
||||
connection_supports(const char *const feature)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user