Mercurial > pidgin.yaz
annotate libpurple/protocols/jabber/parser.c @ 24776:90bee5eed3ec
Updated Arabic translation from Khaled Hosny. Closes #7430.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 18 Dec 2008 09:16:50 +0000 |
parents | 7cf760f3560e |
children | f5c0cdaef99a |
rev | line source |
---|---|
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /* |
15823 | 2 * purple - Jabber XML parser stuff |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
5 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
9 * (at your option) any later version. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15823
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
19 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
21 #include "internal.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
22 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
23 #include <libxml/parser.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
24 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
25 #include "connection.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 #include "debug.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 #include "jabber.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
28 #include "parser.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
29 #include "util.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
30 #include "xmlnode.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
31 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 static void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
33 jabber_parser_element_start_libxml(void *user_data, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
34 const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
35 int nb_namespaces, const xmlChar **namespaces, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
36 int nb_attributes, int nb_defaulted, const xmlChar **attributes) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
37 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
38 JabberStream *js = user_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
39 xmlnode *node; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 if(!element_name) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 } else if(!xmlStrcmp(element_name, (xmlChar*) "stream")) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
45 js->protocol_version = JABBER_PROTO_0_9; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
46 for(i=0; i < nb_attributes * 5; i += 5) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 int attrib_len = attributes[i+4] - attributes[i+3]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 char *attrib = g_malloc(attrib_len + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
49 memcpy(attrib, attributes[i+3], attrib_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
50 attrib[attrib_len] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
51 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 if(!xmlStrcmp(attributes[i], (xmlChar*) "version") |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 && !strcmp(attrib, "1.0")) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 js->protocol_version = JABBER_PROTO_1_0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 g_free(attrib); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 } else if(!xmlStrcmp(attributes[i], (xmlChar*) "id")) { |
15635
baec42670246
Patch from MatsMattsson (Adium Trac #6429) which fixes a leak of attrib for any attribute that isn't 'id' or 'version'.
Evan Schoenberg <evan.s@dreskin.net>
parents:
15498
diff
changeset
|
57 g_free(js->stream_id); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 js->stream_id = attrib; |
15635
baec42670246
Patch from MatsMattsson (Adium Trac #6429) which fixes a leak of attrib for any attribute that isn't 'id' or 'version'.
Evan Schoenberg <evan.s@dreskin.net>
parents:
15498
diff
changeset
|
59 } else { |
baec42670246
Patch from MatsMattsson (Adium Trac #6429) which fixes a leak of attrib for any attribute that isn't 'id' or 'version'.
Evan Schoenberg <evan.s@dreskin.net>
parents:
15498
diff
changeset
|
60 g_free(attrib); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
61 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 if(js->protocol_version == JABBER_PROTO_0_9) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
64 js->auth_type = JABBER_AUTH_IQ_AUTH; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
65 |
17606
108f3b42976f
Introduced an additional connection stage to the jabber connection progress in order to be able to tell in the application, whether SSL/TLS is enabled, so it can display a lock icon next to the connection.
Andreas Monitzer <pidgin@monitzer.com>
parents:
17603
diff
changeset
|
66 if(js->state == JABBER_STREAM_INITIALIZING || js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION) |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
68 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
69 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
70 if(js->current) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
71 node = xmlnode_new_child(js->current, (const char*) element_name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
72 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 node = xmlnode_new((const char*) element_name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
74 xmlnode_set_namespace(node, (const char*) namespace); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
75 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
76 for(i=0; i < nb_attributes * 5; i+=5) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
77 char *txt; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
78 int attrib_len = attributes[i+4] - attributes[i+3]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
79 char *attrib = g_malloc(attrib_len + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
80 char *attrib_ns = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
81 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
82 if (attributes[i+2]) { |
20332
3a9709bfde65
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
19696
diff
changeset
|
83 attrib_ns = g_strdup((char*)attributes[i+2]); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
84 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
85 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
86 memcpy(attrib, attributes[i+3], attrib_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
87 attrib[attrib_len] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
88 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
89 txt = attrib; |
15823 | 90 attrib = purple_unescape_html(txt); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 g_free(txt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
92 xmlnode_set_attrib_with_namespace(node, (const char*) attributes[i], attrib_ns, attrib); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
93 g_free(attrib); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
94 g_free(attrib_ns); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
95 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
96 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
97 js->current = node; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
98 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
99 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
100 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 static void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
102 jabber_parser_element_end_libxml(void *user_data, const xmlChar *element_name, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
103 const xmlChar *prefix, const xmlChar *namespace) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
104 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
105 JabberStream *js = user_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
106 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
107 if(!js->current) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
108 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
109 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
110 if(js->current->parent) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
111 if(!xmlStrcmp((xmlChar*) js->current->name, element_name)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
112 js->current = js->current->parent; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
113 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
114 xmlnode *packet = js->current; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
115 js->current = NULL; |
17621
bbd92ee894f2
Fixed a bug in the XMPP parser involving event handlers that replace the xmlnode packet. This caused double frees in this situation. The replacing function must free the xmlnode, since multiple event handlers could do this, and the intermediate xml trees would leak otherwise.
Andreas Monitzer <pidgin@monitzer.com>
parents:
17606
diff
changeset
|
116 jabber_process_packet(js, &packet); |
24425
7cf760f3560e
Don't try to free NULL xmlnodes stolen by jabber-receiving-xmlnode handlers
Will Thompson <will.thompson@collabora.co.uk>
parents:
24419
diff
changeset
|
117 if (packet != NULL) |
7cf760f3560e
Don't try to free NULL xmlnodes stolen by jabber-receiving-xmlnode handlers
Will Thompson <will.thompson@collabora.co.uk>
parents:
24419
diff
changeset
|
118 xmlnode_free(packet); |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 static void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
123 jabber_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
124 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
125 JabberStream *js = user_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
126 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
127 if(!js->current) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
128 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
129 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
130 if(!text || !text_len) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
131 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
132 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
133 xmlnode_insert_data(js->current, (const char*) text, text_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
134 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
135 |
23426
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
136 static void |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
137 jabber_parser_structured_error_handler(void *user_data, xmlErrorPtr error) |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
138 { |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
139 JabberStream *js = user_data; |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
140 |
24416
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
141 if (error->level == XML_ERR_WARNING && error->message != NULL |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
142 && strcmp(error->message, "xmlns: URI vcard-temp is not absolute\n") == 0) |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
143 /* |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
144 * This message happens when parsing vcards, and is normal, so don't |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
145 * bother logging it because people scare easily. |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
146 */ |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
147 return; |
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
148 |
23426
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
149 purple_debug_error("jabber", "XML parser error for JabberStream %p: " |
24416
e2f5a4a091b5
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <mark@kingant.net>
parents:
23884
diff
changeset
|
150 "Domain %i, code %i, level %i: %s", |
23426
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
151 js, |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
152 error->domain, error->code, error->level, |
24419
8de8ca65e1d9
I know Mark was trying to save newlines, but I had one to spare.
Richard Laager <rlaager@wiktel.com>
parents:
24416
diff
changeset
|
153 (error->message ? error->message : "(null)\n")); |
23426
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
154 } |
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
155 |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
156 static xmlSAXHandler jabber_parser_libxml = { |
22914
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
157 NULL, /*internalSubset*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
158 NULL, /*isStandalone*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
159 NULL, /*hasInternalSubset*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
160 NULL, /*hasExternalSubset*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
161 NULL, /*resolveEntity*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
162 NULL, /*getEntity*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
163 NULL, /*entityDecl*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
164 NULL, /*notationDecl*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
165 NULL, /*attributeDecl*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
166 NULL, /*elementDecl*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
167 NULL, /*unparsedEntityDecl*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
168 NULL, /*setDocumentLocator*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
169 NULL, /*startDocument*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
170 NULL, /*endDocument*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
171 NULL, /*startElement*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
172 NULL, /*endElement*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
173 NULL, /*reference*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
174 jabber_parser_element_text_libxml, /*characters*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
175 NULL, /*ignorableWhitespace*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
176 NULL, /*processingInstruction*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
177 NULL, /*comment*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
178 NULL, /*warning*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
179 NULL, /*error*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
180 NULL, /*fatalError*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
181 NULL, /*getParameterEntity*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
182 NULL, /*cdataBlock*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
183 NULL, /*externalSubset*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
184 XML_SAX2_MAGIC, /*initialized*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
185 NULL, /*_private*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
186 jabber_parser_element_start_libxml, /*startElementNs*/ |
ada1640fa260
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
21358
diff
changeset
|
187 jabber_parser_element_end_libxml, /*endElementNs*/ |
23426
1b3aea146613
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evan.s@dreskin.net>
parents:
22914
diff
changeset
|
188 jabber_parser_structured_error_handler /*serror*/ |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
189 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
190 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
191 void |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
192 jabber_parser_setup(JabberStream *js) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
193 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
194 /* This seems backwards, but it makes sense. The libxml code creates |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
195 * the parser context when you try to use it (this way, it can figure |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
196 * out the encoding at creation time. So, setting up the parser is |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
197 * just a matter of destroying any current parser. */ |
17603
7a3a66c6530a
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <pidgin@monitzer.com>
parents:
15823
diff
changeset
|
198 jabber_parser_free(js); |
7a3a66c6530a
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <pidgin@monitzer.com>
parents:
15823
diff
changeset
|
199 } |
7a3a66c6530a
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <pidgin@monitzer.com>
parents:
15823
diff
changeset
|
200 |
7a3a66c6530a
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <pidgin@monitzer.com>
parents:
15823
diff
changeset
|
201 void jabber_parser_free(JabberStream *js) { |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
202 if (js->context) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
203 xmlParseChunk(js->context, NULL,0,1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
204 xmlFreeParserCtxt(js->context); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
205 js->context = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
206 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
207 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
208 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
209 void jabber_parser_process(JabberStream *js, const char *buf, int len) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
210 { |
23427
0eca6c183d60
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evan.s@dreskin.net>
parents:
23426
diff
changeset
|
211 int ret; |
0eca6c183d60
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evan.s@dreskin.net>
parents:
23426
diff
changeset
|
212 |
23429 | 213 if (js->context == NULL) { |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
214 /* libxml inconsistently starts parsing on creating the |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
215 * parser, so do a ParseChunk right afterwards to force it. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
216 js->context = xmlCreatePushParserCtxt(&jabber_parser_libxml, js, buf, len, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
217 xmlParseChunk(js->context, "", 0, 0); |
23427
0eca6c183d60
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evan.s@dreskin.net>
parents:
23426
diff
changeset
|
218 } else if ((ret = xmlParseChunk(js->context, buf, len, 0)) != XML_ERR_OK) { |
23884
08c50482d5a2
Only disconnect xmpp connections during xml parsing if the error is an
Stu Tomlinson <stu@nosnilmot.com>
parents:
23429
diff
changeset
|
219 xmlError *err = xmlCtxtGetLastError(js->context); |
23427
0eca6c183d60
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evan.s@dreskin.net>
parents:
23426
diff
changeset
|
220 |
23884
08c50482d5a2
Only disconnect xmpp connections during xml parsing if the error is an
Stu Tomlinson <stu@nosnilmot.com>
parents:
23429
diff
changeset
|
221 purple_debug_error("jabber", "xmlParseChunk returned error %i\n", ret); |
08c50482d5a2
Only disconnect xmpp connections during xml parsing if the error is an
Stu Tomlinson <stu@nosnilmot.com>
parents:
23429
diff
changeset
|
222 |
08c50482d5a2
Only disconnect xmpp connections during xml parsing if the error is an
Stu Tomlinson <stu@nosnilmot.com>
parents:
23429
diff
changeset
|
223 if (err->level == XML_ERR_FATAL) { |
23428
ce361cc8e43b
Drop and then recover from XML messages which trigger invalid character
Evan Schoenberg <evan.s@dreskin.net>
parents:
23427
diff
changeset
|
224 purple_connection_error_reason (js->gc, |
ce361cc8e43b
Drop and then recover from XML messages which trigger invalid character
Evan Schoenberg <evan.s@dreskin.net>
parents:
23427
diff
changeset
|
225 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
ce361cc8e43b
Drop and then recover from XML messages which trigger invalid character
Evan Schoenberg <evan.s@dreskin.net>
parents:
23427
diff
changeset
|
226 _("XML Parse error")); |
ce361cc8e43b
Drop and then recover from XML messages which trigger invalid character
Evan Schoenberg <evan.s@dreskin.net>
parents:
23427
diff
changeset
|
227 } |
15374
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
228 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
229 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
230 |