Changeset 399d65a for protocols


Ignore:
Timestamp:
2016-10-17T02:46:33Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
4466e3e
Parents:
2906268
Message:

jabber: Implement chat list command

Also applies to hipchat.

Location:
protocols/jabber
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r2906268 r399d65a  
    10591059        return XT_HANDLED;
    10601060}
     1061
     1062xt_status jabber_iq_disco_muc_response(struct im_connection *ic, struct xt_node *node, struct xt_node *orig);
     1063
     1064int jabber_iq_disco_muc(struct im_connection *ic, const char *muc_server)
     1065{
     1066        struct xt_node *node;
     1067        int st;
     1068
     1069        node = xt_new_node("query", NULL, NULL);
     1070        xt_add_attr(node, "xmlns", XMLNS_DISCO_ITEMS);
     1071        node = jabber_make_packet("iq", "get", (char *) muc_server, node);
     1072
     1073        jabber_cache_add(ic, node, jabber_iq_disco_muc_response);
     1074        st = jabber_write_packet(ic, node);
     1075
     1076        return st;
     1077}
     1078
     1079xt_status jabber_iq_disco_muc_response(struct im_connection *ic, struct xt_node *node, struct xt_node *orig)
     1080{
     1081        struct xt_node *query, *c;
     1082        struct jabber_error *err;
     1083        GSList *rooms =  NULL;
     1084
     1085        if ((err = jabber_error_parse(xt_find_node(node->children, "error"), XMLNS_STANZA_ERROR))) {
     1086                imcb_error(ic, "The server replied with an error: %s%s%s",
     1087                           err->code, err->text ? ": " : "", err->text ? err->text : "");
     1088                jabber_error_free(err);
     1089                return XT_HANDLED;
     1090        }
     1091
     1092        if (!(query = xt_find_node(node->children, "query"))) {
     1093                imcb_error(ic, "Received incomplete MUC list reply");
     1094                return XT_HANDLED;
     1095        }
     1096
     1097        c = query->children;
     1098        while ((c = xt_find_node(c, "item"))) {
     1099                char *jid = xt_find_attr(c, "jid");
     1100
     1101                if (!jid || !strchr(jid, '@')) {
     1102                        c = c->next;
     1103                        continue;
     1104                }
     1105
     1106                bee_chat_info_t *ci = g_new(bee_chat_info_t, 1);
     1107                ci->title = g_strdup(xt_find_attr(c, "jid"));
     1108                ci->topic = g_strdup(xt_find_attr(c, "name"));
     1109                rooms = g_slist_prepend(rooms, ci);
     1110
     1111                c = c->next;
     1112        }
     1113
     1114        imcb_chat_list_free(ic);
     1115        ic->chatlist = g_slist_reverse(rooms);
     1116        imcb_chat_list_finish(ic);
     1117
     1118        return XT_HANDLED;
     1119}
  • protocols/jabber/jabber.c

    r2906268 r399d65a  
    321321        struct jabber_data *jd = ic->proto_data;
    322322
     323        imcb_chat_list_free(ic);
     324
    323325        while (jd->filetransfers) {
    324326                imcb_file_canceled(ic, (( struct jabber_transfer *) jd->filetransfers->data)->ft, "Logging out");
     
    593595}
    594596
     597static void jabber_chat_list_(struct im_connection *ic, const char *server)
     598{
     599        struct jabber_data *jd = ic->proto_data;
     600
     601        if (server && *server) {
     602                jabber_iq_disco_muc(ic, server);
     603        } else if (jd->muc_host && *jd->muc_host) {
     604                jabber_iq_disco_muc(ic, jd->muc_host);
     605        } else {
     606                /* throw an error here, don't query conference.[server] directly.
     607                 * for things like jabber.org it gets you 18000 results of garbage */
     608                imcb_error(ic, "Please specify a server name such as `conference.%s'", jd->server);
     609        }
     610}
     611
    595612static void jabber_chat_msg_(struct groupchat *c, char *message, int flags)
    596613{
     
    768785        ret->chat_join = jabber_chat_join_;
    769786        ret->chat_with = jabber_chat_with_;
     787        ret->chat_list = jabber_chat_list_;
    770788        ret->chat_add_settings = jabber_chat_add_settings;
    771789        ret->chat_free_settings = jabber_chat_free_settings;
  • protocols/jabber/jabber.h

    r2906268 r399d65a  
    263263void jabber_iq_version_send(struct im_connection *ic, struct jabber_buddy *bud, void *data);
    264264int jabber_iq_disco_server(struct im_connection *ic);
     265int jabber_iq_disco_muc(struct im_connection *ic, const char *muc_server);
    265266
    266267/* si.c */
Note: See TracChangeset for help on using the changeset viewer.