- Timestamp:
- 2015-11-23T17:49:09Z (9 years ago)
- Branches:
- master
- Children:
- ad9ac5d
- Parents:
- c34247d
- Location:
- protocols/jabber
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/hipchat.c
rc34247d r9c8dbc7 42 42 *sep = '/'; 43 43 } 44 45 jd->muc_host = g_strdup(xt_find_attr(node, "muc_host")); 44 46 45 47 /* Hipchat's auth doesn't expect a restart here */ … … 92 94 93 95 } 96 97 /* Returns a newly allocated string that tries to match the "slug" part of the JID using an 98 * approximation of the method used by the server. This might fail in some rare conditions 99 * (old JIDs generated a different way, locale settings unicode, etc) */ 100 char *hipchat_make_channel_slug(const char *name) 101 { 102 char *lower; 103 char *new = g_malloc(strlen(name) + 1); 104 int i = 0; 105 106 do { 107 if (*name == ' ') { 108 new[i++] = '_'; 109 } else if (*name && !strchr("\"&'/:<>@", *name)) { 110 new[i++] = *name; 111 } 112 } while (*(name++)); 113 114 new[i] = '\0'; 115 116 lower = g_utf8_strdown(new, -1); 117 g_free(new); 118 119 return lower; 120 } 121 122 char *hipchat_guess_channel_name(struct im_connection *ic, const char *name) 123 { 124 struct jabber_data *jd = ic->proto_data; 125 char *slug, *retval, *underscore; 126 127 if (!(underscore = strchr(jd->username, '_')) || !jd->muc_host) { 128 return NULL; 129 } 130 131 slug = hipchat_make_channel_slug(name); 132 133 /* Get the organization ID from the username, before the underscore */ 134 *underscore = '\0'; 135 136 retval = g_strdup_printf("%s_%s@%s", jd->username, slug, jd->muc_host); 137 138 *underscore = '_'; 139 140 g_free(slug); 141 142 return retval; 143 } -
protocols/jabber/jabber.c
rc34247d r9c8dbc7 371 371 g_free(jd->internal_jid); 372 372 g_free(jd->gmail_tid); 373 g_free(jd->muc_host); 373 374 g_free(jd->username); 374 375 g_free(jd->me); … … 533 534 } 534 535 536 if (jd->flags & JFLAG_HIPCHAT && jd->muc_host && !g_str_has_suffix(room, jd->muc_host)) { 537 char *guessed_name = hipchat_guess_channel_name(ic, room); 538 if (guessed_name) { 539 set_setstr(sets, "room", guessed_name); 540 g_free(guessed_name); 541 542 /* call this same function again with the fixed name */ 543 return jabber_chat_join_(ic, set_getstr(sets, "room"), nick, password, sets); 544 } 545 } 546 535 547 if (strchr(room, '@') == NULL) { 536 548 imcb_error(ic, "%s is not a valid Jabber room name. Maybe you mean %s@conference.%s?", … … 539 551 imcb_error(ic, "Already present in chat `%s'", room); 540 552 } else { 553 /* jabber_chat_join without the underscore is the conference.c one */ 541 554 return jabber_chat_join(ic, room, final_nick, set_getstr(sets, "password")); 542 555 } -
protocols/jabber/jabber.h
rc34247d r9c8dbc7 113 113 GSList *streamhosts; 114 114 int have_streamhosts; 115 116 char *muc_host; 115 117 }; 116 118 … … 358 360 xt_status jabber_parse_hipchat_profile(struct im_connection *ic, struct xt_node *node, struct xt_node *orig); 359 361 xt_status hipchat_handle_success(struct im_connection *ic, struct xt_node *node); 362 char *hipchat_make_channel_slug(const char *name); 363 char *hipchat_guess_channel_name(struct im_connection *ic, const char *name); 360 364 361 365 #endif
Note: See TracChangeset
for help on using the changeset viewer.