1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-01-25 23:33:16 +00:00
commit 4a233856ff
8 changed files with 126 additions and 91 deletions

View File

@ -372,14 +372,18 @@ xdg_get_data_home(void)
}
char *
get_unique_id(void)
generate_unique_id(char *prefix)
{
static unsigned long unique_id;
char *result = NULL;
GString *result_str = g_string_new("");
unique_id++;
g_string_printf(result_str, "prof%lu", unique_id);
if (prefix != NULL) {
g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id);
} else {
g_string_printf(result_str, "prof_%lu", unique_id);
}
result = result_str->str;
g_string_free(result_str, FALSE);

View File

@ -88,7 +88,7 @@ const char * string_from_resource_presence(resource_presence_t presence);
resource_presence_t resource_presence_from_string(const char * const str);
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
char * get_unique_id(void);
char * generate_unique_id(char *prefix);
int cmp_win_num(gconstpointer a, gconstpointer b);
int get_next_available_win_num(GList *used);

View File

@ -37,10 +37,7 @@ bookmark_request(void)
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_stanza_t *iq;
id = get_unique_id();
if (!id) {
return;
}
id = strdup("bookmark_init_request");
autojoin_count = 0;
if (bookmark_ac != NULL) {

View File

@ -349,8 +349,7 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
gchar *err_msg = NULL;
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
xmpp_stanza_t *text_stanza =
xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT);
xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT);
if (error_stanza == NULL) {
log_debug("error message without <error/> received");
@ -494,7 +493,6 @@ _connection_handler(xmpp_conn_t * const conn,
chat_sessions_init();
xmpp_handler_add(conn, connection_error_handler, NULL, NULL, STANZA_TYPE_ERROR, ctx);
roster_add_handlers();
message_add_handlers();
presence_add_handlers();

View File

@ -44,21 +44,21 @@
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx)
static int _iq_handle_error(xmpp_conn_t * const conn,
static int _error_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_ping_get(xmpp_conn_t * const conn,
static int _ping_get_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_version_get(xmpp_conn_t * const conn,
static int _version_get_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_discoinfo_get(xmpp_conn_t * const conn,
static int _disco_info_get_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn,
static int _disco_info_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_version_result(xmpp_conn_t * const conn,
static int _version_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_discoitems_result(xmpp_conn_t * const conn,
static int _disco_items_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_discoitems_get(xmpp_conn_t * const conn,
static int _disco_items_get_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
void
@ -66,14 +66,19 @@ iq_add_handlers(void)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, STANZA_TYPE_ERROR, _iq_handle_error);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _iq_handle_discoinfo_get);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_RESULT, _iq_handle_discoinfo_result);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _iq_handle_discoitems_result);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _iq_handle_discoitems_get);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _iq_handle_version_get);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _iq_handle_version_result);
HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _iq_handle_ping_get);
HANDLE(NULL, STANZA_TYPE_ERROR, _error_handler);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _disco_info_get_handler);
HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_RESULT, _disco_info_result_handler);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _disco_items_get_handler);
HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _disco_items_result_handler);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _version_get_handler);
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler);
HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler);
}
static void
@ -117,7 +122,7 @@ _iq_send_software_version(const char * const fulljid)
}
static int
_iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
@ -132,7 +137,7 @@ _iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
static int
_iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
const char *jid = xmpp_stanza_get_attribute(stanza, "from");
@ -182,7 +187,7 @@ _iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza
}
static int
_iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
@ -211,7 +216,7 @@ _iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
static int
_iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
@ -273,7 +278,7 @@ _iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
static int
_iq_handle_discoitems_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
@ -299,7 +304,7 @@ _iq_handle_discoitems_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza
static int
_iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
@ -350,7 +355,7 @@ _item_destroy(DiscoItem *item)
}
static int
_iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_disco_info_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
log_debug("Recieved diso#info response");
@ -518,7 +523,7 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
}
static int
_iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{

View File

@ -40,11 +40,15 @@
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx)
static int _groupchat_message_handler(xmpp_conn_t * const conn,
static int _groupchat_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _chat_message_handler(xmpp_conn_t * const conn,
static int _chat_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _conference_message_handler(xmpp_conn_t * const conn,
static int _muc_user_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _conference_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _captcha_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
void
@ -53,9 +57,12 @@ message_add_handlers(void)
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_message_handler);
HANDLE(NULL, STANZA_TYPE_CHAT, _chat_message_handler);
HANDLE(NULL, NULL, _conference_message_handler);
HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler);
HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_handler);
HANDLE(NULL, STANZA_TYPE_CHAT, _chat_handler);
HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler);
HANDLE(STANZA_NS_CONFERENCE, NULL, _conference_handler);
HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler);
}
static void
@ -180,32 +187,23 @@ _message_send_gone(const char * const recipient)
}
static int
_conference_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_stanza_t *x_muc = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
xmpp_stanza_t *x_groupchat = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *room = NULL;
xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *invitor = NULL;
char *reason = NULL;
if (from == NULL) {
if (room == NULL) {
log_warning("Message received with no from attribute, ignoring");
return 1;
}
// XEP-0045
if (x_muc != NULL) {
room = from;
xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(x_muc, STANZA_NAME_INVITE);
if (invite == NULL) {
return 1;
}
xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE);
if (invite != NULL) {
char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM);
if (invitor_jid == NULL) {
log_warning("Chat room invite received with no from attribute");
@ -228,35 +226,67 @@ _conference_message_handler(xmpp_conn_t * const conn,
if (reason != NULL) {
xmpp_free(ctx, reason);
}
}
return 1;
}
static int
_conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *room = NULL;
char *invitor = NULL;
char *reason = NULL;
if (from == NULL) {
log_warning("Message received with no from attribute, ignoring");
return 1;
}
// XEP-0429
} else if (x_groupchat != NULL) {
room = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_JID);
if (room == NULL) {
return 1;
}
room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID);
if (room == NULL) {
return 1;
}
Jid *jidp = jid_create(from);
if (jidp == NULL) {
return 1;
}
invitor = jidp->barejid;
Jid *jidp = jid_create(from);
if (jidp == NULL) {
return 1;
}
invitor = jidp->barejid;
reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON);
reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON);
handle_room_invite(INVITE_DIRECT, invitor, room, reason);
handle_room_invite(INVITE_DIRECT, invitor, room, reason);
jid_destroy(jidp);
jid_destroy(jidp);
return 1;
}
static int
_captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (from == NULL) {
log_warning("Message received with no from attribute, ignoring");
return 1;
}
// XEP-0158
} else if (captcha != NULL) {
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body != NULL) {
char *message = xmpp_stanza_get_text(body);
if (message != NULL) {
handle_room_broadcast(from, message);
xmpp_free(ctx, message);
}
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body != NULL) {
char *message = xmpp_stanza_get_text(body);
if (message != NULL) {
handle_room_broadcast(from, message);
xmpp_free(ctx, message);
}
}
@ -264,7 +294,7 @@ _conference_message_handler(xmpp_conn_t * const conn,
}
static int
_groupchat_message_handler(xmpp_conn_t * const conn,
_groupchat_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
@ -341,7 +371,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
}
static int
_chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();

View File

@ -53,8 +53,7 @@ static int _unsubscribed_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _available_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _room_presence_handler(xmpp_conn_t * const conn,
static int _muc_user_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static char* _get_caps_key(xmpp_stanza_t * const stanza);
@ -73,7 +72,8 @@ presence_add_handlers(void)
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(STANZA_NS_MUC_USER, NULL, _room_presence_handler);
HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler);
HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler);
HANDLE(NULL, STANZA_TYPE_UNAVAILABLE, _unavailable_handler);
HANDLE(NULL, STANZA_TYPE_SUBSCRIBE, _subscribe_handler);
HANDLE(NULL, STANZA_TYPE_SUBSCRIBED, _subscribed_handler);
@ -588,7 +588,7 @@ _get_caps_key(xmpp_stanza_t * const stanza)
}
static int
_room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
// handler still fires if error

View File

@ -48,9 +48,9 @@ typedef struct _group_data {
} GroupData;
// event handlers
static int _roster_handle_push(xmpp_conn_t * const conn,
static int _roster_set_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _roster_handle_result(xmpp_conn_t * const conn,
static int _roster_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
// id handlers
@ -69,8 +69,9 @@ roster_add_handlers(void)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(STANZA_TYPE_SET, _roster_handle_push);
HANDLE(STANZA_TYPE_RESULT, _roster_handle_result);
HANDLE(STANZA_TYPE_SET, _roster_set_handler);
HANDLE(STANZA_TYPE_RESULT, _roster_result_handler);
}
void
@ -126,7 +127,7 @@ _roster_send_add_to_group(const char * const group, PContact contact)
new_groups = g_slist_append(new_groups, strdup(group));
// add an id handler to handle the response
char *unique_id = get_unique_id();
char *unique_id = generate_unique_id(NULL);
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
@ -175,7 +176,7 @@ _roster_send_remove_from_group(const char * const group, PContact contact)
xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response
char *unique_id = get_unique_id();
char *unique_id = generate_unique_id(NULL);
GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group);
if (p_contact_name(contact) != NULL) {
@ -207,7 +208,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
static int
_roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_stanza_t *query =
@ -271,7 +272,7 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
static int
_roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
_roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);