]> Pileus Git - ~andy/lamechat/commitdiff
Add vCard support
authorAndy Spencer <andy753421@gmail.com>
Fri, 27 Oct 2017 06:10:57 +0000 (06:10 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 27 Oct 2017 06:56:11 +0000 (06:56 +0000)
xmpp.c

diff --git a/xmpp.c b/xmpp.c
index 218570327329864a726b1bcea1769c8f34c53c31..9b7b963f4ea3cb3c52cb48462d018df10423e10d 100644 (file)
--- a/xmpp.c
+++ b/xmpp.c
@@ -56,6 +56,7 @@ typedef enum {
        XMPP_SEND_JOIN,
        XMPP_READY,
        XMPP_IN_IQ,
+       XMPP_IN_VCARD,
        XMPP_IN_MESSAGE,
        XMPP_IN_PRESENCE,
 } xmpp_state_t;
@@ -76,6 +77,7 @@ typedef struct {
        int             timeout;
        const char     *host;
        int             port;
+       const char     *srv;
        const char     *muc;
        const char     *nick;
        const char     *jid;
@@ -172,10 +174,10 @@ static xmpp_channel_t *find_dest(xmpp_server_t *srv,
        split_jid(jid, jid_usr, jid_srv, NULL);
        snprintf(dest, JID_LEN, "%s@%s", jid_usr,
                 jid_srv[0] ? jid_srv  :
-                is_muc     ? srv->muc : srv->host);
+                is_muc     ? srv->muc : srv->srv);
 
        /* Server channels */
-       if (match(jid, srv->host))
+       if (match(jid, srv->srv))
                return &srv->system;
 
        /* Find existing channels */
@@ -338,7 +340,7 @@ static void xmpp_run(xmpp_server_t *srv, int idle,
                    " xml:lang='en'"
                    " xmlns='jabber:client'"
                    " xmlns:stream='http://etherx.jabber.org/streams'>",
-                   srv->jid, srv->host)) {
+                   srv->jid, srv->srv)) {
                        debug("xmpp: stream -> features");
                        srv->state = XMPP_RECV_FEATURES;
                }
@@ -426,7 +428,7 @@ static void xmpp_run(xmpp_server_t *srv, int idle,
                    "<iq id='session' type='set' to='%s'>"
                    "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>"
                    "</iq>",
-                   srv->host)) {
+                   srv->srv)) {
                        debug("xmpp: session -> presence");
                        srv->state = XMPP_SEND_PRESENCE;
                }
@@ -487,9 +489,7 @@ static void xmpp_run(xmpp_server_t *srv, int idle,
                                srv->msg_chan->channel.name);
                }
        }
-       if (srv->state == XMPP_IN_IQ ||
-           srv->state == XMPP_IN_MESSAGE ||
-           srv->state == XMPP_IN_PRESENCE) {
+       if (srv->state > XMPP_READY) {
                if (srv->msg_chan && srv->msg_chan != &srv->system)
                        chan = srv->msg_chan;
        }
@@ -538,6 +538,23 @@ static void xmpp_run(xmpp_server_t *srv, int idle,
                }
        }
 
+       /* vCards */
+       if (srv->state == XMPP_IN_IQ) {
+               if (match(start, "vCard")) {
+                       if (chan)
+                               chan_notice(chan, "vCard for %s", chan->dest);
+                       srv->state = XMPP_IN_VCARD;
+               }
+       }
+       if (srv->state == XMPP_IN_VCARD) {
+               if (end && chan && data) {
+                       chan_notice(chan, "%-12s -- %s", end, data);
+               }
+               if (match(end, "vCard")) {
+                       srv->state = XMPP_IN_IQ;
+               }
+       }
+
        /* Messages */
        if (srv->state == XMPP_IN_MESSAGE) {
                if (match(start, "delay")) {
@@ -632,6 +649,8 @@ void xmpp_init(void)
 
                if (!srv->port)
                        srv->port = 5222;
+               if (!srv->srv)
+                       srv->srv = strcopy(srv->host);
                if (!srv->jid)
                        error("jid is required");
                if (!srv->timeout)
@@ -678,6 +697,8 @@ void xmpp_config(server_t *server, channel_t *channel,
                        srv->host = get_string(value);
                else if (match(key, "port"))
                        srv->port = get_number(value);
+               else if (match(key, "srv"))
+                       srv->srv = get_string(value);
                else if (match(key, "muc"))
                        srv->muc = get_string(value);
                else if (match(key, "nick"))
@@ -712,14 +733,14 @@ void xmpp_send(channel_t *channel, const char *text)
                                "<iq id='items' type='get' from='%s' to='%s'>"
                                "<query xmlns='http://jabber.org/protocol/disco#items'/>"
                                "</iq>",
-                               srv->jid, arg ?: srv->host);
+                               srv->jid, arg ?: srv->srv);
                }
                else if (prefix(text, "/info", &arg)) {
                        net_print(&srv->net,
                                "<iq id='info' type='get' from='%s' to='%s'>"
                                "<query xmlns='http://jabber.org/protocol/disco#info'/>"
                                "</iq>",
-                               srv->jid, arg ?: srv->host);
+                               srv->jid, arg ?: srv->srv);
                }
                else if (prefix(text, "/names", &arg)) {
                        if (arg)
@@ -766,6 +787,16 @@ void xmpp_send(channel_t *channel, const char *text)
                        chan = find_dest(srv, arg, 0);
                        chan_notice(chan, "User: %s", arg);
                }
+               else if (prefix(text, "/vcard", &arg)) {
+                       if (arg)
+                               chan = find_dest(srv, arg, 0);
+                       if (chan)
+                               net_print(&srv->net,
+                                       "<iq id='vcard' type='get' from='%s' to='%s'>"
+                                       "<vCard xmlns='vcard-temp'/>"
+                                       "</iq>",
+                                       srv->jid, chan->dest);
+               }
                else {
                        chan_notice(chan, "Unknown command %s", text);
                }