Ignore:
Timestamp:
2015-08-26T05:58:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
b6a3fbf
Parents:
0605498
Message:

jabber: Improvements to the MUC part reason handling

  • Look for a status message right inside <presence> (seen with ejabberd as a result of a s2s connection error)
  • Check status codes in a while loop, skipping unknown ones (such as 110, which means "Inform user that presence refers to itself")
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/conference.c

    r0605498 r3c23681  
    332332                if ((bud->flags & JBFLAG_IS_CHATROOM) && bud->ext_jid) {
    333333                        char *reason = NULL;
     334                        char *status = NULL;
     335                        char *status_text = NULL;
    334336                       
    335337                        if ((c = xt_find_node_by_attr(node->children, "x", "xmlns", XMLNS_MUC_USER))) {
    336                                 struct xt_node *c2;
    337                                 char *status = NULL;
    338                                
    339                                 if ((c2 = xt_find_node(c->children, "status"))) {
    340                                         status = xt_find_attr(c2, "code");
    341                                         if (g_strcmp0(status, "301") == 0) {
     338                                struct xt_node *c2 = c->children;
     339
     340                                while ((c2 = xt_find_node(c2, "status"))) {
     341                                        char *code = xt_find_attr(c2, "code");
     342                                        if (g_strcmp0(code, "301") == 0) {
    342343                                                status = "Banned";
    343                                         } else if (g_strcmp0(status, "303") == 0) {
     344                                                break;
     345                                        } else if (g_strcmp0(code, "303") == 0) {
    344346                                                /* This could be handled in a cleverer way,
    345347                                                 * but let's just show a literal part/join for now */
    346348                                                status = "Changing nicks";
    347                                         } else if (g_strcmp0(status, "307") == 0) {
     349                                                break;
     350                                        } else if (g_strcmp0(code, "307") == 0) {
    348351                                                status = "Kicked";
     352                                                break;
    349353                                        }
     354                                        c2 = c2->next;
    350355                                }
    351356
     357                                /* Sometimes the status message is in presence/x/item/reason */
    352358                                if ((c2 = xt_find_path(c, "item/reason")) && c2->text && c2->text_len) {
    353                                         if (status) {
    354                                                 reason = g_strdup_printf("%s: %s", status, c2->text);
    355                                         } else {
    356                                                 reason = g_strdup(c2->text);
    357                                         }
    358                                 } else {
    359                                         reason = g_strdup(status);
     359                                        status_text = c2->text;
    360360                                }
     361                        }
     362
     363                        /* Sometimes the status message is right inside <presence> */
     364                        if ((c = xt_find_node(node->children, "status")) && c->text && c->text_len) {
     365                                status_text = c->text;
     366                        }
     367
     368                        if (status_text && status) {
     369                                reason = g_strdup_printf("%s: %s", status, status_text);
     370                        } else {
     371                                reason = g_strdup(status_text ? : status);
    361372                        }
    362373
Note: See TracChangeset for help on using the changeset viewer.