Added autocomplete for /software command

This commit is contained in:
James Booth
2013-02-17 02:10:56 +00:00
parent 44d2f8da7a
commit bced3d4b36
11 changed files with 163 additions and 1 deletions

View File

@@ -30,6 +30,7 @@
#include "common.h"
#include "contact_list.h"
#include "log.h"
#include "profanity.h"
#include "xmpp/capabilities.h"
#include "xmpp/connection.h"
#include "xmpp/iq.h"
@@ -52,6 +53,8 @@ static int _iq_handle_discoinfo_get(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _iq_handle_version_result(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
void
iq_add_handlers(void)
@@ -64,6 +67,7 @@ iq_add_handlers(void)
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(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);
}
@@ -77,6 +81,16 @@ iq_roster_request(void)
xmpp_stanza_release(iq);
}
void
iq_send_software_version(const char * const fulljid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_software_version_iq(ctx, fulljid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
static int
_iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
@@ -160,6 +174,44 @@ _iq_handle_roster_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
}
static int
_iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
const char *jid = xmpp_stanza_get_attribute(stanza, "from");
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query == NULL) {
return 1;
}
char *ns = xmpp_stanza_get_ns(query);
if (g_strcmp0(ns, STANZA_NS_VERSION) != 0) {
return 1;
}
char *name_str = NULL;
char *version_str = NULL;
char *os_str = NULL;
xmpp_stanza_t *name = xmpp_stanza_get_child_by_name(query, "name");
xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version");
xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os");
if (name != NULL) {
name_str = xmpp_stanza_get_text(name);
}
if (version != NULL) {
version_str = xmpp_stanza_get_text(version);
}
if (os != NULL) {
os_str = xmpp_stanza_get_text(os);
}
prof_handle_version_result(jid, name_str, version_str, os_str);
return 1;
}
static int
_iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)

View File

@@ -139,6 +139,25 @@ stanza_create_presence(xmpp_ctx_t * const ctx)
return presence;
}
xmpp_stanza_t *
stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char * const fulljid)
{
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
xmpp_stanza_set_id(iq, "sv");
xmpp_stanza_set_attribute(iq, "to", fulljid);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, STANZA_NS_VERSION);
xmpp_stanza_add_child(iq, query);
xmpp_stanza_release(query);
return iq;
}
xmpp_stanza_t *
stanza_create_roster_iq(xmpp_ctx_t *ctx)
{

View File

@@ -162,5 +162,6 @@ void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence
const char * const status);
const char * stanza_get_presence_string_from_type(resource_presence_t presence_type);
xmpp_stanza_t * stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char * const fulljid);
#endif

View File

@@ -88,6 +88,9 @@ void presence_leave_chat_room(const char * const room_jid);
void presence_update(resource_presence_t status, const char * const msg,
int idle);
// iq functions
void iq_send_software_version(const char * const fulljid);
// caps functions
Capabilities* caps_get(const char * const caps_str);
void caps_close(void);