~ubuntu-branches/ubuntu/jaunty/irssi-plugin-xmpp/jaunty

« back to all changes in this revision

Viewing changes to src/core/xmpp-xep.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2008-06-23 16:03:33 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080623160333-3wwbzgtzwznjjvrf
Tags: 0.13+cvs20080610-1
* New CVS snapshot:
  - New features and bugfixes.
  - Fix ignoring of messages without a type attribute (Closes: #477989).
* Depend on irssi >=0.8.12 (Closes: #469923).
* Add FAQ and MUC to documentation files (Closes: #485595).
* debian/rules: install help files in irssi help directory.
* debian/rules: Remove useless "make -n" command in build-stamp rule.
* Bump Standards-Version to 3.8.0 (no changes needed). 
* debian/control: Add "Enhances: irssi".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: xmpp-xep.c,v 1.2 2008/01/07 07:29:13 errtu Exp $
 
2
 * $Id: xmpp-xep.c,v 1.6 2008/04/05 20:50:45 errtu Exp $
3
3
 *
4
4
 * Copyright (C) 2007 Colin DIDIER
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
 
7
 * it under the terms of the GNU General Public License version 2 as
 
8
 * published by the Free Software Foundation.
10
9
 *
11
10
 * This program is distributed in the hope that it will be useful,
12
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44
43
{
45
44
        LmMessage *msg;
46
45
        LmMessageNode *child;
47
 
        XMPP_ROSTER_USER_REC *user;
48
46
        XMPP_ROSTER_RESOURCE_REC *resource;
49
 
        char *dest_recoded, *jid, *res;
 
47
        char *dest_recoded;
50
48
        const char *id;
51
49
 
52
50
        g_return_if_fail(IS_XMPP_SERVER(server));
62
60
 
63
61
        lm_message_node_add_child(child, "composing", NULL);
64
62
 
65
 
        jid = xmpp_strip_resource(full_jid);
66
 
        res = xmpp_extract_resource(full_jid);
67
 
 
68
 
        if (jid == NULL || res == NULL)
69
 
                goto out;
70
 
        
71
 
        user = xmpp_rosters_find_user(server->roster, jid, NULL);
72
 
        if (user == NULL)
73
 
                goto out;
74
 
 
75
 
        resource = xmpp_rosters_find_resource(user, res);
 
63
        xmpp_rosters_find_user(server->roster, full_jid, NULL, &resource);
76
64
        if (resource != NULL) {
77
65
                id = lm_message_node_get_attribute(msg->node, "id");
78
66
                lm_message_node_add_child(child, "id", id);
80
68
                resource->composing_id = g_strdup(id);
81
69
        }
82
70
 
83
 
out:
84
71
        lm_send(server, msg, NULL);
85
72
        lm_message_unref(msg);
86
 
 
87
 
        g_free(jid);
88
 
        g_free(res);
89
73
}
90
74
 
91
75
void
93
77
{
94
78
        LmMessage *msg;
95
79
        LmMessageNode *child;
96
 
        XMPP_ROSTER_USER_REC *user;
97
80
        XMPP_ROSTER_RESOURCE_REC *resource;
98
 
        char *full_jid_recoded, *jid, *res;
 
81
        char *full_jid_recoded;
99
82
 
100
83
        g_return_if_fail(IS_XMPP_SERVER(server));
101
84
        g_return_if_fail(full_jid != NULL);
109
92
        child = lm_message_node_add_child(msg->node, "x", NULL);
110
93
        lm_message_node_set_attribute(child, XMLNS, XMLNS_EVENT);
111
94
 
112
 
        jid = xmpp_strip_resource(full_jid);
113
 
        res = xmpp_extract_resource(full_jid);
114
 
 
115
 
        if (jid == NULL || res == NULL)
116
 
                goto out;
117
 
        
118
 
        user = xmpp_rosters_find_user(server->roster, jid, NULL);
119
 
        if (user == NULL)
120
 
                goto out;
121
 
 
122
 
        resource = xmpp_rosters_find_resource(user, res);
 
95
        xmpp_rosters_find_user(server->roster, full_jid, NULL, &resource);
123
96
        if (resource != NULL && resource->composing_id != NULL) {
124
97
                lm_message_node_add_child(child, "id", resource->composing_id);
125
98
                g_free_and_null(resource->composing_id);
126
99
        }
127
100
 
128
 
out:
129
101
        lm_send(server, msg, NULL);
130
102
        lm_message_unref(msg);
131
 
 
132
 
        g_free(jid);
133
 
        g_free(res);
134
103
}
135
104
 
136
105
 
232
201
                if (child->value == NULL)
233
202
                        continue;
234
203
 
235
 
                if (name == NULL && strcmp(child->value, "name") == 0)
 
204
                if (name == NULL && strcmp(child->name, "name") == 0)
236
205
                        name = xmpp_recode_in(child->value);
237
206
                else if (version == NULL
238
 
                    && strcmp(child->value, "version") == 0)
 
207
                    && strcmp(child->name, "version") == 0)
239
208
                        version = xmpp_recode_in(child->value);
240
 
                else if (os  == NULL && strcmp(child->value, "os") == 0)
 
209
                else if (os  == NULL && strcmp(child->name, "os") == 0)
241
210
                        os = xmpp_recode_in(child->value);
242
211
        }
243
212
 
244
 
        signal_emit("xmpp version", 2, server, jid, name, version, os);
 
213
        signal_emit("xmpp version", 5, server, jid, name, version, os);
245
214
 
246
215
        g_free(name);
247
216
        g_free(version);
258
227
    LmMessageNode *node)
259
228
{
260
229
        LmMessageNode *child, *subchild;
 
230
        GHashTable *ht;
261
231
        const char *adressing;
262
232
        char *value;
263
233
 
264
 
        signal_emit("xmpp begin of vcard", 2, server, jid);
 
234
        ht = g_hash_table_new_full(g_str_hash, g_str_equal,
 
235
            NULL, g_free);
265
236
 
266
237
        child = node->children;
267
 
        while(child != NULL) {
 
238
        while (child != NULL) {
268
239
 
269
240
                /* ignore avatar */
270
241
                if (g_ascii_strcasecmp(child->name, "PHOTO") == 0)
273
244
                if (child->value != NULL) {
274
245
                        value = xmpp_recode_in(child->value);
275
246
                        g_strstrip(value);
276
 
 
277
 
                        signal_emit("xmpp vcard value", 4, server, jid,
278
 
                             child->name, value);
279
 
 
280
 
                        g_free(value);
 
247
                        g_hash_table_insert(ht, child->name, value);
 
248
 
281
249
                        goto next;
282
250
                }
283
251
 
284
252
                /* find the adressing type indicator */
285
253
                subchild = child->children;
286
254
                adressing = NULL;
287
 
                while(subchild != NULL && adressing == NULL) {
 
255
                while (subchild != NULL && adressing == NULL) {
288
256
                        if (subchild->value == NULL && (
289
257
                            g_ascii_strcasecmp(subchild->name , "HOME") == 0 ||
290
258
                            g_ascii_strcasecmp(subchild->name , "WORK") == 0))
294
262
                }
295
263
 
296
264
                subchild = child->children;
297
 
                while(subchild != NULL) {
 
265
                while (subchild != NULL) {
298
266
                        
299
267
                        if (subchild->value != NULL) {
300
268
                                value = xmpp_recode_in(subchild->value);
301
 
                                g_strstrip(value);
302
269
 
303
 
                                signal_emit("xmpp vcard subvalue", 6, server,
304
 
                                    jid, child->name, adressing,
305
 
                                    subchild->name, value);
 
270
                                /* TODO sub... */
306
271
 
307
272
                                g_free(value);
308
273
                        }
314
279
                child = child->next;
315
280
        }
316
281
 
317
 
        signal_emit("xmpp end of vcard", 2, server, jid);
 
282
        signal_emit("xmpp vcard", 3, server, jid, ht);
 
283
        
 
284
        g_hash_table_destroy(ht);
318
285
}