source: protocols/jabber/hipchat.c @ b3ebb3a

Last change on this file since b3ebb3a was 830864d, checked in by dequis <dx@…>, at 2015-03-15T09:31:18Z

WIP placeholder channels with hipchat implementation

i was going to clean this up and split in two commits but uhhh...
maybe some other day, i'm tired now

not very tested and i'm not 100% happy about the design, but sucks way
less than what i had in the hip-cat branch

feedback still appreciated.

this adds channels to the channel list without creating groupchats for
them, allowing users to /join them. what the hip-cat branch did before
but with proper api and hopefully less dumb behavior

it still 'leaks' them intentionally, just like it did before, but now it
prevents saving them to the xml so yay

also slightly improved channel name generation, refactored
bee_irc_chat_name_hint into three or four functions, and so on

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[0e4c3dd]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                return XT_ABORT;
51        }
52        if (!jabber_iq_disco_server(ic)) {
53                return XT_ABORT;
54        }
55        if (!jabber_get_hipchat_profile(ic)) {
56                return XT_ABORT;
57        }
58        if (!jabber_iq_disco_muc(ic, muc_host)) {
59                return XT_ABORT;
60        }
61
62        return XT_HANDLED;
63}
64
65int jabber_get_hipchat_profile(struct im_connection *ic)
66{
67        struct jabber_data *jd = ic->proto_data;
68        struct xt_node *node;
69        int st;
70
71        imcb_log(ic, "Fetching hipchat profile for %s", jd->me);
72
73        node = xt_new_node("query", NULL, NULL);
74        xt_add_attr(node, "xmlns", XMLNS_HIPCHAT_PROFILE);
75        node = jabber_make_packet("iq", "get", jd->me, node);
76
77        jabber_cache_add(ic, node, jabber_parse_hipchat_profile);
78        st = jabber_write_packet(ic, node);
79
80        return st;
81}
82
83xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
84{
85        struct xt_node *query, *name_node;
86
87        //char *name;
88
89        if (!(query = xt_find_node(node->children, "query"))) {
90                imcb_log(ic, "Warning: Received NULL profile packet");
91                return XT_ABORT;
92        }
93
94        name_node = xt_find_node(query->children, "name");
95        if (!name_node) {
96                imcb_log(ic, "Warning: Can't find real name in profile. Joining groupchats will not be possible.");
97                return XT_ABORT;
98        }
99
100        set_setstr(&ic->acc->set, "display_name", name_node->text);
101        return XT_HANDLED;
102
103}
104
105int jabber_iq_disco_muc(struct im_connection *ic, char *muc_server)
106{
107        struct xt_node *node;
108        int st;
109
110        imcb_log(ic, "Fetching MUC list");
111
112        node = xt_new_node("query", NULL, NULL);
113        xt_add_attr(node, "xmlns", XMLNS_DISCO_ITEMS);
114        node = jabber_make_packet("iq", "get", muc_server, node);
115
116        jabber_cache_add(ic, node, jabber_parse_muc_list);
117        st = jabber_write_packet(ic, node);
118
119        return st;
120}
121
122xt_status jabber_parse_muc_list(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
123{
124        struct xt_node *query, *c;
125
126        if (!(query = xt_find_node(node->children, "query"))) {
127                imcb_log(ic, "Warning: Received NULL MUC list packet");
128                return XT_HANDLED;
129        }
130
131        c = query->children;
132        while ((c = xt_find_node(c, "item"))) {
133                struct xt_node *c2;
134                char *topic = NULL;
135                char *jid = xt_find_attr(c, "jid");
136                char *name = xt_find_attr(c, "name");
137
138                imcb_log(ic, "Debug: adding MUC to channel list: %s - '%s'", jid, name);
139
[c0e4c22]140                if ((c2 = xt_find_node_by_attr(c->children, "x", "xmlns", XMLNS_HIPCHAT_MUC)) &&
141                    (c2 = xt_find_node(c2->children, "topic"))) {
142                        topic = c2->text;
[0e4c3dd]143                }
144
[830864d]145                imcb_chat_placeholder_new(ic, jid, name, topic);
[0e4c3dd]146                c = c->next;
147        }
148        return XT_HANDLED;
149
150}
Note: See TracBrowser for help on using the repository browser.