From 69f97cd8725b1b1cde94844396bf041b1daf5224 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Mon, 29 Jun 2015 10:27:49 -0400 Subject: [PATCH] Add "to" field to message Distinguish which user received a message. Possibly useful if multiple sessions are logged in or someone directly messages the bot. --- examples/bot.sh | 2 +- examples/ssh-over-xmpp | 2 +- src/xmppipe.c | 10 +++++++++- src/xmppipe.h | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/bot.sh b/examples/bot.sh index 513a4b8..2bed1ba 100755 --- a/examples/bot.sh +++ b/examples/bot.sh @@ -35,7 +35,7 @@ bot() { elif [ "$1" = "m" ]; then USER="$(decode ${3#*%2F})" IFS=$OFS - MSG="$(decode $4)" + MSG="$(decode ${!#})" case $MSG in *"has set the subject to:"*) ;; "sudo make me a sandwich") diff --git a/examples/ssh-over-xmpp b/examples/ssh-over-xmpp index 2e4a5c8..b152a45 100755 --- a/examples/ssh-over-xmpp +++ b/examples/ssh-over-xmpp @@ -30,7 +30,7 @@ decode() { OFS=$IFS IFS=: set -- $line - [ "$1" = "m" ] && printf '%b' "${4//%/\\x}" + [ "$1" = "m" ] && printf '%b' "${!#//%/\\x}" IFS=$OFS done } diff --git a/src/xmppipe.c b/src/xmppipe.c index 322be03..00fc26c 100644 --- a/src/xmppipe.c +++ b/src/xmppipe.c @@ -916,9 +916,11 @@ handle_message(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *message = NULL; char *type = NULL; char *from = NULL; + char *to = NULL; char *etype = NULL; char *efrom = NULL; + char *eto = NULL; char *emessage = NULL; if (xmpp_stanza_get_child_by_name(stanza, "delay")) @@ -928,6 +930,10 @@ handle_message(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (!from) return 1; + to = xmpp_stanza_get_attribute(stanza, "to"); + if (!to) + return 1; + type = xmpp_stanza_get_type(stanza); if (!type) return 1; @@ -963,13 +969,15 @@ handle_message(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, etype = xmppipe_fmt(type); efrom = xmppipe_fmt(from); + eto = xmppipe_fmt(to); - (void)printf("m:%s:%s:%s\n", etype, efrom, emessage); + (void)printf("m:%s:%s:%s:%s\n", etype, efrom, eto, emessage); state->interval = 0; free(message); free(etype); free(efrom); + free(eto); free(emessage); return 1; diff --git a/src/xmppipe.h b/src/xmppipe.h index 308d1b2..d6e3bb7 100644 --- a/src/xmppipe.h +++ b/src/xmppipe.h @@ -21,7 +21,7 @@ #include -#define XMPPIPE_VERSION "0.6.1" +#define XMPPIPE_VERSION "0.7.0" #define XMPPIPE_STREQ(a,b) !strcmp((a),(b)) #define XMPPIPE_STRNEQ(a,b) strcmp((a),(b))