mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
parent
dace47e5d3
commit
d5e9ca649d
16
src/common.c
16
src/common.c
@ -37,6 +37,9 @@
|
|||||||
// and page size is at least 4KB
|
// and page size is at least 4KB
|
||||||
#define READ_BUF_SIZE 4088
|
#define READ_BUF_SIZE 4088
|
||||||
|
|
||||||
|
// for generating ids
|
||||||
|
static int unique_id = 0;
|
||||||
|
|
||||||
struct curl_data_t
|
struct curl_data_t
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
@ -394,6 +397,19 @@ xdg_get_data_home(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
get_unique_id(void)
|
||||||
|
{
|
||||||
|
char *result = NULL;
|
||||||
|
unique_id++;
|
||||||
|
GString *result_str = g_string_new("");
|
||||||
|
g_string_printf(result_str, "prof%d", unique_id);
|
||||||
|
result = result_str->str;
|
||||||
|
g_string_free(result_str, FALSE);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||||
{
|
{
|
||||||
|
@ -92,4 +92,6 @@ const char * string_from_resource_presence(resource_presence_t presence);
|
|||||||
resource_presence_t resource_presence_from_string(const char * const str);
|
resource_presence_t resource_presence_from_string(const char * const str);
|
||||||
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
|
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
|
||||||
|
|
||||||
|
char * get_unique_id(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -164,6 +164,22 @@ prof_handle_not_in_group(const char * const contact,
|
|||||||
ui_current_page_off();
|
ui_current_page_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prof_handle_group_add(const char * const contact,
|
||||||
|
const char * const group)
|
||||||
|
{
|
||||||
|
ui_group_added(contact, group);
|
||||||
|
ui_current_page_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prof_handle_group_remove(const char * const contact,
|
||||||
|
const char * const group)
|
||||||
|
{
|
||||||
|
ui_group_removed(contact, group);
|
||||||
|
ui_current_page_off();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
prof_handle_error_message(const char *from, const char *err_msg)
|
prof_handle_error_message(const char *from, const char *err_msg)
|
||||||
{
|
{
|
||||||
|
@ -84,5 +84,7 @@ void prof_handle_roster_add(const char * const barejid, const char * const name)
|
|||||||
void prof_handle_roster_remove(const char * const barejid);
|
void prof_handle_roster_remove(const char * const barejid);
|
||||||
void prof_handle_already_in_group(const char * const contact, const char * const group);
|
void prof_handle_already_in_group(const char * const contact, const char * const group);
|
||||||
void prof_handle_not_in_group(const char * const contact, const char * const group);
|
void prof_handle_not_in_group(const char * const contact, const char * const group);
|
||||||
|
void prof_handle_group_add(const char * const contact, const char * const group);
|
||||||
|
void prof_handle_group_remove(const char * const contact, const char * const group);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -467,6 +467,18 @@ ui_contact_not_in_group(const char * const contact, const char * const group)
|
|||||||
cons_show("%s is not currently in group %s", contact, group);
|
cons_show("%s is not currently in group %s", contact, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ui_group_added(const char * const contact, const char * const group)
|
||||||
|
{
|
||||||
|
cons_show("%s added to group %s", contact, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ui_group_removed(const char * const contact, const char * const group)
|
||||||
|
{
|
||||||
|
cons_show("%s removed from group %s", contact, group);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ui_contact_online(const char * const barejid, const char * const resource,
|
ui_contact_online(const char * const barejid, const char * const resource,
|
||||||
const char * const show, const char * const status, GDateTime *last_activity)
|
const char * const show, const char * const status, GDateTime *last_activity)
|
||||||
|
@ -116,6 +116,8 @@ void ui_roster_add(const char * const barejid, const char * const name);
|
|||||||
void ui_roster_remove(const char * const barejid);
|
void ui_roster_remove(const char * const barejid);
|
||||||
void ui_contact_already_in_group(const char * const contact, const char * const group);
|
void ui_contact_already_in_group(const char * const contact, const char * const group);
|
||||||
void ui_contact_not_in_group(const char * const contact, const char * const group);
|
void ui_contact_not_in_group(const char * const contact, const char * const group);
|
||||||
|
void ui_group_added(const char * const contact, const char * const group);
|
||||||
|
void ui_group_removed(const char * const contact, const char * const group);
|
||||||
|
|
||||||
// contact status functions
|
// contact status functions
|
||||||
void ui_status_room(const char * const contact);
|
void ui_status_room(const char * const contact);
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -55,12 +56,26 @@ static GHashTable *contacts;
|
|||||||
// nickname to jid map
|
// nickname to jid map
|
||||||
static GHashTable *name_to_barejid;
|
static GHashTable *name_to_barejid;
|
||||||
|
|
||||||
|
// callback data for group commands
|
||||||
|
typedef struct _group_data {
|
||||||
|
char *name;
|
||||||
|
char *group;
|
||||||
|
} GroupData;
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
static int _roster_handle_push(xmpp_conn_t * const conn,
|
static int _roster_handle_push(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
static int _roster_handle_result(xmpp_conn_t * const conn,
|
static int _roster_handle_result(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata);
|
xmpp_stanza_t * const stanza, void * const userdata);
|
||||||
|
|
||||||
|
// id handlers
|
||||||
|
static int
|
||||||
|
_group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
|
void * const userdata);
|
||||||
|
static int
|
||||||
|
_group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
|
void * const userdata);
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
static void _add_name_and_barejid(const char * const name,
|
static void _add_name_and_barejid(const char * const name,
|
||||||
const char * const barejid);
|
const char * const barejid);
|
||||||
@ -141,7 +156,7 @@ roster_add_new(const char * const barejid, const char * const name)
|
|||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid, name, NULL);
|
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, name, NULL);
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
@ -279,7 +294,7 @@ roster_change_name(const char * const barejid, const char * const new_name)
|
|||||||
|
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid, new_name,
|
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, NULL, barejid, new_name,
|
||||||
groups);
|
groups);
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
@ -312,13 +327,40 @@ roster_add_to_group(const char * const group, const char * const barejid)
|
|||||||
|
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid,
|
|
||||||
|
// add an id handler to handle the response
|
||||||
|
char *unique_id = get_unique_id();
|
||||||
|
GroupData *data = malloc(sizeof(GroupData));
|
||||||
|
data->group = strdup(group);
|
||||||
|
if (p_contact_name(contact) != NULL) {
|
||||||
|
data->name = strdup(p_contact_name(contact));
|
||||||
|
} else {
|
||||||
|
data->name = strdup(p_contact_barejid(contact));
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_id_handler_add(conn, _group_add_handler, unique_id, data);
|
||||||
|
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, barejid,
|
||||||
p_contact_name(contact), new_groups);
|
p_contact_name(contact), new_groups);
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
|
free(unique_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
|
void * const userdata)
|
||||||
|
{
|
||||||
|
if (userdata != NULL) {
|
||||||
|
GroupData *data = userdata;
|
||||||
|
prof_handle_group_add(data->name, data->group);
|
||||||
|
free(data->name);
|
||||||
|
free(data->group);
|
||||||
|
free(userdata);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
roster_remove_from_group(const char * const group, const char * const barejid)
|
roster_remove_from_group(const char * const group, const char * const barejid)
|
||||||
{
|
{
|
||||||
@ -345,14 +387,41 @@ roster_remove_from_group(const char * const group, const char * const barejid)
|
|||||||
|
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid,
|
|
||||||
|
// add an id handler to handle the response
|
||||||
|
char *unique_id = get_unique_id();
|
||||||
|
GroupData *data = malloc(sizeof(GroupData));
|
||||||
|
data->group = strdup(group);
|
||||||
|
if (p_contact_name(contact) != NULL) {
|
||||||
|
data->name = strdup(p_contact_name(contact));
|
||||||
|
} else {
|
||||||
|
data->name = strdup(p_contact_barejid(contact));
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_id_handler_add(conn, _group_remove_handler, unique_id, data);
|
||||||
|
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, unique_id, barejid,
|
||||||
p_contact_name(contact), new_groups);
|
p_contact_name(contact), new_groups);
|
||||||
xmpp_send(conn, iq);
|
xmpp_send(conn, iq);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
|
free(unique_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
|
void * const userdata)
|
||||||
|
{
|
||||||
|
if (userdata != NULL) {
|
||||||
|
GroupData *data = userdata;
|
||||||
|
prof_handle_group_remove(data->name, data->group);
|
||||||
|
free(data->name);
|
||||||
|
free(data->group);
|
||||||
|
free(userdata);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
roster_has_pending_subscriptions(void)
|
roster_has_pending_subscriptions(void)
|
||||||
{
|
{
|
||||||
|
@ -119,12 +119,15 @@ stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char * const barejid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *
|
xmpp_stanza_t *
|
||||||
stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const jid,
|
stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id,
|
||||||
const char * const handle, GSList *groups)
|
const char * const jid, const char * const handle, GSList *groups)
|
||||||
{
|
{
|
||||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||||
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
||||||
|
if (id != NULL) {
|
||||||
|
xmpp_stanza_set_id(iq, id);
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||||
|
@ -179,8 +179,8 @@ xmpp_stanza_t * stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char * const
|
|||||||
char * stanza_get_status(xmpp_stanza_t *stanza, char *def);
|
char * stanza_get_status(xmpp_stanza_t *stanza, char *def);
|
||||||
char * stanza_get_show(xmpp_stanza_t *stanza, char *def);
|
char * stanza_get_show(xmpp_stanza_t *stanza, char *def);
|
||||||
|
|
||||||
xmpp_stanza_t * stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const jid,
|
xmpp_stanza_t * stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id,
|
||||||
const char * const handle, GSList *groups);
|
const char * const jid, const char * const handle, GSList *groups);
|
||||||
xmpp_stanza_t * stanza_create_roster_remove_set(xmpp_ctx_t *ctx,
|
xmpp_stanza_t * stanza_create_roster_remove_set(xmpp_ctx_t *ctx,
|
||||||
const char * const barejid);
|
const char * const barejid);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user