Changeset 40cfbc5 for protocols


Ignore:
Timestamp:
2015-04-28T13:47:48Z (10 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
70ec7ab, 9ed8175
Parents:
1493c4b
git-author:
dequis <dx@…> (21-02-15 06:18:21)
git-committer:
dequis <dx@…> (28-04-15 13:47:48)
Message:

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.

Location:
protocols/jabber
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/Makefile

    r1493c4b r40cfbc5  
    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

    r1493c4b r40cfbc5  
    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)
     
    374373static xt_status jabber_parse_roster(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
    375374{
     375        struct jabber_data *jd = ic->proto_data;
    376376        struct xt_node *query, *c;
    377377        int initial = (orig != NULL);
     
    388388                char *name = xt_find_attr(c, "name");
    389389                char *sub = xt_find_attr(c, "subscription");
     390                char *mention_name = xt_find_attr(c, "mention_name");
    390391
    391392                if (jid && sub) {
     
    396397                                if (name) {
    397398                                        imcb_rename_buddy(ic, jid, name);
     399                                }
     400
     401                                /* This could also be used to set the full name as nick for fb/gtalk,
     402                                 * but i'm keeping the old (ugly?) default behavior just to be safe */
     403                                if (mention_name && (jd->flags & JFLAG_HIPCHAT)) {
     404                                        imcb_buddy_nick_hint(ic, jid, mention_name);
    398405                                }
    399406                        } else if (strcmp(sub, "remove") == 0) {
     
    855862                                                 struct xt_node *node, struct xt_node *orig);
    856863
    857 static int jabber_iq_disco_server(struct im_connection *ic)
     864int jabber_iq_disco_server(struct im_connection *ic)
    858865{
    859866        struct xt_node *node, *iq;
  • protocols/jabber/jabber.h

    r1493c4b r40cfbc5  
    236236#define XMLNS_IBB          "http://jabber.org/protocol/ibb"                      /* XEP-0047 */
    237237
     238/* Hipchat protocol extensions*/
     239#define XMLNS_HIPCHAT         "http://hipchat.com"
     240#define XMLNS_HIPCHAT_PROFILE "http://hipchat.com/protocol/profile"
     241
    238242/* jabber.c */
    239243void jabber_connect(struct im_connection *ic);
     
    250254xt_status jabber_iq_query_server(struct im_connection *ic, char *jid, char *xmlns);
    251255void jabber_iq_version_send(struct im_connection *ic, struct jabber_buddy *bud, void *data);
     256int jabber_iq_disco_server(struct im_connection *ic);
    252257
    253258/* si.c */
     
    342347void jabber_chat_invite(struct groupchat *c, char *who, char *message);
    343348
     349/* hipchat.c */
     350int jabber_get_hipchat_profile(struct im_connection *ic);
     351xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
     352xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node);
     353
    344354#endif
  • protocols/jabber/sasl.c

    r1493c4b r40cfbc5  
    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->flags & JFLAG_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->flags & JFLAG_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.