# HG changeset patch # User Mikael Berthe # Date 1134736453 -3600 # Node ID d3a8b43bf9e78a4e073d5165a208e32bec078b30 # Parent a61a257ec38b72f4d78f91296ae4fab9f14b0a03 Add "/authorization" command diff -r a61a257ec38b -r d3a8b43bf9e7 mcabber/src/commands.c --- a/mcabber/src/commands.c Fri Dec 16 12:09:46 2005 +0100 +++ b/mcabber/src/commands.c Fri Dec 16 13:34:13 2005 +0100 @@ -53,6 +53,7 @@ static void do_disconnect(char *arg); static void do_rawxml(char *arg); static void do_room(char *arg); +static void do_authorization(char *arg); // Global variable for the commands list static GSList *Commands; @@ -80,6 +81,8 @@ { cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add); cmd_add("alias", "Add an alias", 0, 0, &do_alias); + cmd_add("authorization", "Manage subscription authorizations", + COMPL_AUTH, COMPL_JID, &do_authorization); cmd_add("bind", "Add an key binding", 0, 0, &do_bind); cmd_add("buffer", "Manipulate current buddy's buffer (chat window)", COMPL_BUFFER, 0, &do_buffer); @@ -98,14 +101,12 @@ cmd_add("quit", "Exit the software", 0, 0, NULL); cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); - //cmd_add("request_auth"); cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, &do_roster); cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say); cmd_add("say_to", "Say something to a specific buddy", COMPL_JID, 0, &do_say_to); //cmd_add("search"); - //cmd_add("send_auth"); cmd_add("set", "Set/query an option value", 0, 0, &do_set); cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status); cmd_add("status_to", "Show or set your status for one recipient", @@ -171,6 +172,11 @@ compl_add_category_word(COMPL_ROOM, "topic"); compl_add_category_word(COMPL_ROOM, "unlock"); compl_add_category_word(COMPL_ROOM, "whois"); + + // Authorization category + compl_add_category_word(COMPL_AUTH, "allow"); + compl_add_category_word(COMPL_AUTH, "cancel"); + compl_add_category_word(COMPL_AUTH, "request"); } // expandalias(line) @@ -1628,6 +1634,76 @@ free_arg_lst(paramlst); } +static void do_authorization(char *arg) +{ + char **paramlst; + char *subcmd; + + if (!jb_getonline()) { + scr_LogPrint(LPRINT_NORMAL, "You are not connected"); + return; + } + + paramlst = split_arg(arg, 2, 0); // subcmd, [jid] + subcmd = *paramlst; + arg = *(paramlst+1); + + if (!subcmd || !*subcmd) { + scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); + free_arg_lst(paramlst); + return; + } + + // Use the provided jid, if it looks valid + if (arg) { + if (!*arg) { + // If no jid is provided, we use the current selected buddy + arg = NULL; + } else { + if (check_jid_syntax(arg)) { + scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", arg); + free_arg_lst(paramlst); + return; + } + } + } + + if (!arg) { // Use the current selected buddy's jid + gpointer bud; + guint type; + + if (!current_buddy) return; + bud = BUDDATA(current_buddy); + + arg = (char*)buddy_getjid(bud); + type = buddy_gettype(bud); + + if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) { + scr_LogPrint(LPRINT_NORMAL, "Invalid buddy"); + return; + } + } + + if (!strcasecmp(subcmd, "allow")) { + jb_subscr_send_auth(arg); + scr_LogPrint(LPRINT_LOGNORM, + "<%s> is allowed to receive your presence updates", arg); + } else if (!strcasecmp(subcmd, "cancel")) { + jb_subscr_cancel_auth(arg); + scr_LogPrint(LPRINT_LOGNORM, + "<%s> is no more allowed to receive your presence updates", + arg); + } else if (!strcasecmp(subcmd, "request")) { + jb_subscr_request_auth(arg); + scr_LogPrint(LPRINT_LOGNORM, + "Sent presence notification request to <%s>", arg); + } else { + scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); + } + + free_arg_lst(paramlst); +} + static void do_connect(char *arg) { mcabber_connect(); diff -r a61a257ec38b -r d3a8b43bf9e7 mcabber/src/compl.h --- a/mcabber/src/compl.h Fri Dec 16 12:09:46 2005 +0100 +++ b/mcabber/src/compl.h Fri Dec 16 13:34:13 2005 +0100 @@ -16,6 +16,7 @@ #define COMPL_MULTILINE (1<<11) #define COMPL_ROOM (1<<12) #define COMPL_RESOURCE (1<<13) +#define COMPL_AUTH (1<<14) void compl_add_category_word(guint, const char *command); void compl_del_category_word(guint categ, const char *word); diff -r a61a257ec38b -r d3a8b43bf9e7 mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Fri Dec 16 12:09:46 2005 +0100 +++ b/mcabber/src/jabglue.c Fri Dec 16 13:34:13 2005 +0100 @@ -410,6 +410,45 @@ jb_reset_keepalive(); } +// jb_subscr_send_auth(jid) +// Allow jid to receive our presence updates +void jb_subscr_send_auth(const char *jid) +{ + xmlnode x; + char *utf8_jid = to_utf8(jid); + + x = jutil_presnew(JPACKET__SUBSCRIBED, utf8_jid, NULL); + jab_send(jc, x); + xmlnode_free(x); + g_free(utf8_jid); +} + +// jb_subscr_cancel_auth(jid) +// Cancel jid's subscription to our presence updates +void jb_subscr_cancel_auth(const char *jid) +{ + xmlnode x; + char *utf8_jid = to_utf8(jid); + + x = jutil_presnew(JPACKET__UNSUBSCRIBED, utf8_jid, NULL); + jab_send(jc, x); + xmlnode_free(x); + g_free(utf8_jid); +} + +// jb_subscr_request_auth(jid) +// Request a subscription to jid's presence updates +void jb_subscr_request_auth(const char *jid) +{ + xmlnode x; + char *utf8_jid = to_utf8(jid); + + x = jutil_presnew(JPACKET__SUBSCRIBE, utf8_jid, NULL); + jab_send(jc, x); + xmlnode_free(x); + g_free(utf8_jid); +} + // Note: the caller should check the jid is correct void jb_addbuddy(const char *jid, const char *name, const char *group) { @@ -445,9 +484,7 @@ jab_send(jc, x); xmlnode_free(x); - x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, NULL); - jab_send(jc, x); - xmlnode_free(x); + jb_subscr_request_auth(cleanjid); roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending); g_free(cleanjid); @@ -1240,7 +1277,6 @@ static void handle_packet_s10n(jconn conn, char *type, char *from, xmlnode xmldata) { - xmlnode x; char *r; char *buf; @@ -1252,10 +1288,14 @@ int isagent; isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; + msg = xmlnode_get_tag_data(xmldata, "status"); - msg = xmlnode_get_tag_data(xmldata, "status"); - scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " - "to your network presence updates", from); + buf = g_strdup_printf("<%s> wants to subscribe to your presence updates", + from); + scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); + scr_LogPrint(LPRINT_LOGNORM, "%s", buf); + g_free(buf); + if (msg) { char *msg_noutf8 = from_utf8(msg); if (msg_noutf8) { @@ -1270,17 +1310,15 @@ } // FIXME We accept everybody... - x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); - jab_send(jc, x); - xmlnode_free(x); - buf = g_strdup_printf("<%s> has subscribed to your presence updates", from); + jb_subscr_send_auth(from); + buf = g_strdup_printf("<%s> is allowed to receive your presence updates", + from); scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); + scr_LogPrint(LPRINT_LOGNORM, "%s", buf); g_free(buf); } else if (!strcmp(type, "unsubscribe")) { /* The sender is unsubscribing from our presence */ - x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); - jab_send(jc, x); - xmlnode_free(x); + jb_subscr_cancel_auth(from); buf = g_strdup_printf("<%s> is unsubscribing from your " "presence updates", from); scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); diff -r a61a257ec38b -r d3a8b43bf9e7 mcabber/src/jabglue.h --- a/mcabber/src/jabglue.h Fri Dec 16 12:09:46 2005 +0100 +++ b/mcabber/src/jabglue.h Fri Dec 16 13:34:13 2005 +0100 @@ -33,6 +33,9 @@ inline unsigned char jb_getonline(void); void jb_disconnect(void); void jb_main(); +void jb_subscr_send_auth(const char *jid); +void jb_subscr_cancel_auth(const char *jid); +void jb_subscr_request_auth(const char *jid); void jb_addbuddy(const char *jid, const char *name, const char *group); void jb_delbuddy(const char *jid); void jb_updatebuddy(const char *jid, const char *name, const char *group);