source: protocols/jabber/hipchat.c @ bef322e

Last change on this file since bef322e was 40cfbc5, checked in by dequis <dx@…>, at 2015-04-28T13:47:48Z

hipchat: Basic implementation: Auth, profile and mention names

This is enough to log in with their usernames, make 'chat add' based
groupchat joins slightly more smooth, and see mention names as nicks.

All the MUC list stuff is left out intentionally since that's not as
stable as I wish.

  • Property mode set to 100644
File size: 3.3 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;
30
31        jid = xt_find_attr(node, "jid");
32
33        sep = strchr(jid, '/');
34        if (sep) {
35                *sep = '\0';
36        }
37
38        jabber_set_me(ic, jid);
39        imcb_log(ic, "Setting Hipchat JID to %s", jid);
40
41        if (sep) {
42                *sep = '/';
43        }
44
45        /* Hipchat's auth doesn't expect a restart here */
46        jd->flags &= ~JFLAG_STREAM_RESTART;
47
48        if (!jabber_get_roster(ic) ||
49            !jabber_iq_disco_server(ic) ||
50            !jabber_get_hipchat_profile(ic)) {
51                return XT_ABORT;
52        }
53
54        return XT_HANDLED;
55}
56
57int jabber_get_hipchat_profile(struct im_connection *ic)
58{
59        struct jabber_data *jd = ic->proto_data;
60        struct xt_node *node;
61        int st;
62
63        imcb_log(ic, "Fetching hipchat profile for %s", jd->me);
64
65        node = xt_new_node("query", NULL, NULL);
66        xt_add_attr(node, "xmlns", XMLNS_HIPCHAT_PROFILE);
67        node = jabber_make_packet("iq", "get", jd->me, node);
68
69        jabber_cache_add(ic, node, jabber_parse_hipchat_profile);
70        st = jabber_write_packet(ic, node);
71
72        return st;
73}
74
75xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
76{
77        struct xt_node *query, *name_node;
78
79        if (!(query = xt_find_node(node->children, "query"))) {
80                imcb_log(ic, "Warning: Received NULL profile packet");
81                return XT_ABORT;
82        }
83
84        name_node = xt_find_node(query->children, "name");
85        if (!name_node) {
86                imcb_log(ic, "Warning: Can't find real name in profile. Joining groupchats will not be possible.");
87                return XT_ABORT;
88        }
89
90        set_setstr(&ic->acc->set, "display_name", name_node->text);
91        return XT_HANDLED;
92
93}
Note: See TracBrowser for help on using the repository browser.