source: protocols/jabber/hipchat.c @ ec8b369

Last change on this file since ec8b369 was b8c336b, checked in by dequis <dx@…>, at 2015-05-09T19:50:30Z

Merge branch 'develop' into feat/hip-cat

Conflicts:

protocols/jabber/hipchat.c
protocols/jabber/iq.c
protocols/jabber/jabber.h

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Jabber module - HipChat specific functions                               *
5*                                                                           *
6*  Copyright 2015 Xamarin Inc                                               *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24#include "jabber.h"
25
26xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node)
27{
28        struct jabber_data *jd = ic->proto_data;
29        char *sep, *jid, *muc_host;
30
31        jid = xt_find_attr(node, "jid");
32        muc_host = xt_find_attr(node, "muc_host");
33
34        sep = strchr(jid, '/');
35        if (sep) {
36                *sep = '\0';
37        }
38
39        jabber_set_me(ic, jid);
40        imcb_log(ic, "Setting Hipchat JID to %s", jid);
41
42        if (sep) {
43                *sep = '/';
44        }
45
46        /* Hipchat's auth doesn't expect a restart here */
47        jd->flags &= ~JFLAG_STREAM_RESTART;
48
49        if (!jabber_get_roster(ic) ||
50            !jabber_iq_disco_server(ic) ||
51            !jabber_get_hipchat_profile(ic) ||
52            !jabber_iq_disco_muc(ic, muc_host)) {
53                return XT_ABORT;
54        }
55
56        return XT_HANDLED;
57}
58
59int jabber_get_hipchat_profile(struct im_connection *ic)
60{
61        struct jabber_data *jd = ic->proto_data;
62        struct xt_node *node;
63        int st;
64
65        imcb_log(ic, "Fetching hipchat profile for %s", jd->me);
66
67        node = xt_new_node("query", NULL, NULL);
68        xt_add_attr(node, "xmlns", XMLNS_HIPCHAT_PROFILE);
69        node = jabber_make_packet("iq", "get", jd->me, node);
70
71        jabber_cache_add(ic, node, jabber_parse_hipchat_profile);
72        st = jabber_write_packet(ic, node);
73
74        return st;
75}
76
77xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
78{
79        struct xt_node *query, *name_node;
80
81        if (!(query = xt_find_node(node->children, "query"))) {
82                imcb_log(ic, "Warning: Received NULL profile packet");
83                return XT_ABORT;
84        }
85
86        name_node = xt_find_node(query->children, "name");
87        if (!name_node) {
88                imcb_log(ic, "Warning: Can't find real name in profile. Joining groupchats will not be possible.");
89                return XT_ABORT;
90        }
91
92        set_setstr(&ic->acc->set, "display_name", name_node->text);
93        return XT_HANDLED;
94
95}
96
97int jabber_iq_disco_muc(struct im_connection *ic, char *muc_server)
98{
99        struct xt_node *node;
100        int st;
101
102        imcb_log(ic, "Fetching MUC list");
103
104        node = xt_new_node("query", NULL, NULL);
105        xt_add_attr(node, "xmlns", XMLNS_DISCO_ITEMS);
106        node = jabber_make_packet("iq", "get", muc_server, node);
107
108        jabber_cache_add(ic, node, jabber_parse_muc_list);
109        st = jabber_write_packet(ic, node);
110
111        return st;
112}
113
114xt_status jabber_parse_muc_list(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
115{
116        struct xt_node *query, *c;
117
118        if (!(query = xt_find_node(node->children, "query"))) {
119                imcb_log(ic, "Warning: Received NULL MUC list packet");
120                return XT_HANDLED;
121        }
122
123        c = query->children;
124        while ((c = xt_find_node(c, "item"))) {
125                struct xt_node *c2;
126                char *topic = NULL;
127                char *jid = xt_find_attr(c, "jid");
128                char *name = xt_find_attr(c, "name");
129
130                imcb_log(ic, "Debug: adding MUC to channel list: %s - '%s'", jid, name);
131
132                if ((c2 = xt_find_node_by_attr(c->children, "x", "xmlns", XMLNS_HIPCHAT_MUC)) &&
133                    (c2 = xt_find_node(c2->children, "topic"))) {
134                        topic = c2->text;
135                }
136
137                imcb_chat_placeholder_new(ic, jid, name, topic);
138                c = c->next;
139        }
140        return XT_HANDLED;
141
142}
Note: See TracBrowser for help on using the repository browser.