Changeset 0e4c3dd


Ignore:
Timestamp:
2015-02-21T06:18:21Z (6 years ago)
Author:
dequis <dx@…>
Children:
89db90e
Parents:
59c1fe7
Message:

Add hipchat support to the jabber module

Location:
protocols/jabber
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/Makefile

    r59c1fe7 r0e4c3dd  
    1313
    1414# [SH] Program variables
    15 objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o s5bytestream.o sasl.o si.o
     15objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o s5bytestream.o sasl.o si.o hipchat.o
    1616
    1717LFLAGS += -r
  • protocols/jabber/iq.c

    r59c1fe7 r0e4c3dd  
    2727static xt_status jabber_parse_roster(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
    2828static xt_status jabber_iq_display_vcard(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
    29 static int jabber_iq_disco_server(struct im_connection *ic);
    3029
    3130xt_status jabber_pkt_iq(struct xt_node *node, gpointer data)
     
    861860                                                 struct xt_node *node, struct xt_node *orig);
    862861
    863 static int jabber_iq_disco_server(struct im_connection *ic)
     862int jabber_iq_disco_server(struct im_connection *ic)
    864863{
    865864        struct xt_node *node, *iq;
  • protocols/jabber/jabber.h

    r59c1fe7 r0e4c3dd  
    250250#define XMLNS_IBB          "http://jabber.org/protocol/ibb"                      /* XEP-0047 */
    251251
     252/* Hipchat protocol extensions*/
     253#define XMLNS_HIPCHAT         "http://hipchat.com"
     254#define XMLNS_HIPCHAT_PROFILE "http://hipchat.com/protocol/profile"
     255#define XMLNS_HIPCHAT_MUC     "http://hipchat.com/protocol/muc#room"
     256
    252257/* jabber.c */
    253258void jabber_connect(struct im_connection *ic);
     
    259264int jabber_get_roster(struct im_connection *ic);
    260265int jabber_get_vcard(struct im_connection *ic, char *bare_jid);
     266int jabber_iq_disco_muc(struct im_connection *ic, char *muc_server);
    261267int jabber_add_to_roster(struct im_connection *ic, const char *handle, const char *name, const char *group);
    262268int jabber_remove_from_roster(struct im_connection *ic, char *handle);
     
    264270xt_status jabber_iq_query_server(struct im_connection *ic, char *jid, char *xmlns);
    265271void jabber_iq_version_send(struct im_connection *ic, struct jabber_buddy *bud, void *data);
     272int jabber_iq_disco_server(struct im_connection *ic);
    266273
    267274/* si.c */
     
    357364void jabber_chat_invite(struct groupchat *c, char *who, char *message);
    358365
     366/* hipchat.c */
     367int jabber_get_hipchat_profile(struct im_connection *ic);
     368xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
     369xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node);
     370xt_status jabber_parse_muc_list(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
     371
    359372#endif
  • protocols/jabber/sasl.c

    r59c1fe7 r0e4c3dd  
    5555        char *s;
    5656        int sup_plain = 0, sup_digest = 0, sup_gtalk = 0, sup_fb = 0;
    57         int want_oauth = FALSE;
     57        int want_oauth = FALSE, want_hipchat = FALSE;
    5858        GString *mechs;
    5959
     
    7575
    7676        want_oauth = set_getbool(&ic->acc->set, "oauth");
     77        want_hipchat = (jd->subproto == JSUB_HIPCHAT);
    7778
    7879        mechs = g_string_new("");
     
    111112
    112113        reply = xt_new_node("auth", NULL, NULL);
    113         xt_add_attr(reply, "xmlns", XMLNS_SASL);
     114        if (!want_hipchat) {
     115                xt_add_attr(reply, "xmlns", XMLNS_SASL);
     116        } else {
     117                xt_add_attr(reply, "xmlns", XMLNS_HIPCHAT);
     118        }
    114119
    115120        if (sup_gtalk && want_oauth) {
     
    143148        } else if (sup_plain) {
    144149                int len;
    145 
    146                 xt_add_attr(reply, "mechanism", "PLAIN");
     150                GString *gs;
     151                char *username;
     152
     153                if (!want_hipchat) {
     154                        xt_add_attr(reply, "mechanism", "PLAIN");
     155                        username = jd->username;
     156                } else {
     157                        username = jd->me;
     158                }
     159
     160                /* set an arbitrary initial size to avoid reallocations */
     161                gs = g_string_sized_new(128);
    147162
    148163                /* With SASL PLAIN in XMPP, the text should be b64(\0user\0pass) */
    149                 len = strlen(jd->username) + strlen(ic->acc->pass) + 2;
    150                 s = g_malloc(len + 1);
    151                 s[0] = 0;
    152                 strcpy(s + 1, jd->username);
    153                 strcpy(s + 2 + strlen(jd->username), ic->acc->pass);
     164                g_string_append_c(gs, '\0');
     165                g_string_append(gs, username);
     166                g_string_append_c(gs, '\0');
     167                g_string_append(gs, ic->acc->pass);
     168                if (want_hipchat) {
     169                        /* Hipchat's variation adds \0resource at the end */
     170                        g_string_append_c(gs, '\0');
     171                        g_string_append(gs, set_getstr(&ic->acc->set, "resource"));
     172                }
     173
     174                len = gs->len;
     175                s = g_string_free(gs, FALSE);
     176
    154177                reply->text = base64_encode((unsigned char *) s, len);
    155178                reply->text_len = strlen(reply->text);
     
    397420                imcb_log(ic, "Authentication finished");
    398421                jd->flags |= JFLAG_AUTHENTICATED | JFLAG_STREAM_RESTART;
     422
     423                if (jd->subproto == JSUB_HIPCHAT) {
     424                        return hipchat_handle_success(ic, node);
     425                }
    399426        } else if (strcmp(node->name, "failure") == 0) {
    400427                imcb_error(ic, "Authentication failure");
Note: See TracChangeset for help on using the changeset viewer.