From 88af13c85590cc3a2229c36ddf5612e876d05f0e Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 23 Apr 2011 14:01:51 -0500 Subject: [PATCH 08/18] Command to turn encryption on/off --- src/core/rosters.h | 1 + src/core/xmpp-commands.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) --- a/src/core/rosters.h +++ b/src/core/rosters.h @@ -31,6 +31,7 @@ char *status; char *composing_id; char *pgp_keyid; + int pgp_encrypt; } XMPP_ROSTER_RESOURCE_REC; typedef struct _XMPP_ROSTER_USER_REC { --- a/src/core/xmpp-commands.c +++ b/src/core/xmpp-commands.c @@ -534,6 +534,32 @@ g_free(recoded); } +/* SYNTAX: XMPPPGP */ +static void +cmd_xmpppgp(const char *data, XMPP_SERVER_REC *server, WI_ITEM_REC *item) +{ + if(IS_QUERY(item)) { + XMPP_ROSTER_USER_REC *user = rosters_find_user(server->roster, \ + QUERY(item)->name, NULL, NULL); + XMPP_ROSTER_RESOURCE_REC *res; + if(!user) goto error; + res = rosters_find_resource(user->resources, \ + xmpp_extract_resource(QUERY(item)->name)); + if(!res) goto error; + + if(res->pgp_keyid && strcmp(data, "on") == 0) { + res->pgp_encrypt = 1; + } else if(strcmp(data, "off") == 0) { + res->pgp_encrypt = 0; + } else { + res->pgp_keyid = malloc(9); + strcpy(res->pgp_keyid, data); + } + } +error: + return; +} + char * xmpp_get_dest(const char *cmd_dest, XMPP_SERVER_REC *server, WI_ITEM_REC *item) { @@ -579,6 +605,7 @@ command_bind_xmpp("presence unsubscribe", NULL, (SIGNAL_FUNC)cmd_presence_unsubscribe); command_bind_xmpp("me", NULL, (SIGNAL_FUNC)cmd_me); + command_bind_xmpp("xmpppgp", NULL, (SIGNAL_FUNC)cmd_xmpppgp); settings_add_str("xmpp", "xmpp_default_away_mode", "away"); } @@ -603,4 +630,5 @@ command_unbind("presence unsubscribe", (SIGNAL_FUNC)cmd_presence_unsubscribe); command_unbind("me", (SIGNAL_FUNC)cmd_me); + command_unbind("xmpppgp", (SIGNAL_FUNC)cmd_xmpppgp); }