aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-12-06 00:03:49 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2010-12-06 00:03:49 +0000
commitd88c92a40438e0ac8e897beb3ead44c4404050b3 (patch)
tree8dd4e41d7490e49501386e57cb281463b9bce7b1 /protocols/jabber
parenta429907207d5b8b05463c72a9b8c880ba03ad921 (diff)
First bits of CTCP support to contacts. (Try /CTCP VERSION on a Jabber
contact.)
Diffstat (limited to 'protocols/jabber')
-rw-r--r--protocols/jabber/iq.c48
-rw-r--r--protocols/jabber/jabber.c33
-rw-r--r--protocols/jabber/jabber.h1
3 files changed, 82 insertions, 0 deletions
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c
index 82c90d39..a9b69788 100644
--- a/protocols/jabber/iq.c
+++ b/protocols/jabber/iq.c
@@ -793,3 +793,51 @@ xt_status jabber_iq_parse_server_features( struct im_connection *ic, struct xt_n
return XT_HANDLED;
}
+
+static xt_status jabber_iq_version_response( struct im_connection *ic,
+ struct xt_node *node, struct xt_node *orig );
+
+void jabber_iq_version_send( struct im_connection *ic, struct jabber_buddy *bud, void *data )
+{
+ struct xt_node *node, *query;
+
+ node = xt_new_node( "query", NULL, NULL );
+ xt_add_attr( node, "xmlns", XMLNS_VERSION );
+ query = jabber_make_packet( "iq", "get", bud->full_jid, node );
+ jabber_cache_add( ic, query, jabber_iq_version_response );
+
+ jabber_write_packet( ic, query );
+}
+
+static xt_status jabber_iq_version_response( struct im_connection *ic,
+ struct xt_node *node, struct xt_node *orig )
+{
+ struct xt_node *query;
+ GString *rets;
+ char *s;
+ char *ret[2] = {};
+ bee_user_t *bu;
+ struct jabber_buddy *bud = NULL;
+
+ if( ( s = xt_find_attr( node, "from" ) ) &&
+ ( bud = jabber_buddy_by_jid( ic, s, 0 ) ) &&
+ ( query = xt_find_node( node->children, "query" ) ) &&
+ ( bu = bee_user_by_handle( ic->bee, ic, bud->bare_jid ) ) )
+ {
+ rets = g_string_new( "Resource " );
+ g_string_append( rets, bud->resource );
+ }
+ else
+ return XT_HANDLED;
+
+ for( query = query->children; query; query = query->next )
+ if( query->text_len > 0 )
+ g_string_append_printf( rets, " %s: %s,", query->name, query->text );
+
+ g_string_truncate( rets, rets->len - 1 );
+ ret[0] = rets->str;
+ imcb_buddy_action_response( bu, "VERSION", ret, NULL );
+ g_string_free( rets, TRUE );
+
+ return XT_HANDLED;
+}
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index 2655d89e..e5bc3c14 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -563,6 +563,37 @@ void jabber_chat_free_settings( account_t *acc, set_t **head )
set_del( head, "password" );
}
+GList *jabber_buddy_action_list( bee_user_t *bu )
+{
+ static GList *ret = NULL;
+
+ if( ret == NULL )
+ {
+ struct buddy_action ba[2] = {
+ { "VERSION", "Get client (version) information" },
+ };
+
+ ret = g_list_prepend( ret, ba + 0 );
+ }
+
+ return ret;
+}
+
+void *jabber_buddy_action( struct bee_user *bu, const char *action, char * const args[], void *data )
+{
+ if( g_strcasecmp( action, "VERSION" ) == 0 )
+ {
+ struct jabber_buddy *bud;
+
+ if( ( bud = jabber_buddy_by_ext_jid( bu->ic, bu->handle, 0 ) ) == NULL )
+ bud = jabber_buddy_by_jid( bu->ic, bu->handle, GET_BUDDY_FIRST );
+ for( ; bud; bud = bud->next )
+ jabber_iq_version_send( bu->ic, bud, data );
+ }
+
+ return NULL;
+}
+
void jabber_initmodule()
{
struct prpl *ret = g_new0( struct prpl, 1 );
@@ -590,6 +621,8 @@ void jabber_initmodule()
ret->send_typing = jabber_send_typing;
ret->handle_cmp = g_strcasecmp;
ret->transfer_request = jabber_si_transfer_request;
+ ret->buddy_action_list = jabber_buddy_action_list;
+ ret->buddy_action = jabber_buddy_action;
register_protocol( ret );
}
diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h
index 1523e096..ff46e12f 100644
--- a/protocols/jabber/jabber.h
+++ b/protocols/jabber/jabber.h
@@ -240,6 +240,7 @@ int jabber_add_to_roster( struct im_connection *ic, const char *handle, const ch
int jabber_remove_from_roster( struct im_connection *ic, char *handle );
xt_status jabber_iq_query_features( struct im_connection *ic, char *bare_jid );
xt_status jabber_iq_query_server( struct im_connection *ic, char *jid, char *xmlns );
+void jabber_iq_version_send( struct im_connection *ic, struct jabber_buddy *bud, void *data );
/* si.c */
int jabber_si_handle_request( struct im_connection *ic, struct xt_node *node, struct xt_node *sinode );