Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/hipchat.c

    r9c8dbc7 r40cfbc5  
    4242                *sep = '/';
    4343        }
    44 
    45         jd->muc_host = g_strdup(xt_find_attr(node, "muc_host"));
    4644
    4745        /* Hipchat's auth doesn't expect a restart here */
     
    9492
    9593}
    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 }
Note: See TracChangeset for help on using the changeset viewer.