Ignore:
Timestamp:
2015-05-04T21:58:50Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
5726a0d
Parents:
531eabd (diff), 5ca1416 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Catch up with master.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/sasl.c

    r531eabd rb1dc403  
    4242        "https://www.facebook.com/dialog/oauth",
    4343        "https://graph.facebook.com/oauth/access_token",
    44         "http://www.bitlbee.org/main.php/Facebook/oauth2.html",
     44        "https://www.bitlbee.org/main.php/Facebook/oauth2.html",
    4545        "offline_access,xmpp_login",
    4646        "126828914005625",
     
    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.