Wed, 29 Apr 2009 20:57:53 +0000
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Feed a fake </stream:stream> to the XMPP parser to silence warnings.
Upgrading to TLS and disconnecting should no longer emit
'Extra content at the end of the document'
References #8830.
*** Plucked rev ca9f6d5b (darkrain42@pidgin.im):
Add xmlnode and bonjour structured error handlers.
Various libraries may set global structured error handlers and libxml2
prefers those to a per-context normal error handler. This causes us to
break badly.
References #8830.
*** Plucked rev 34f4897e (darkrain42@pidgin.im):
xmlCtxtGetLastError may return NULL, especially with other misbehaving
libraries in our address space.
References #8136.
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber XML parser stuff |
| 7014 | 3 | * |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 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. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 19 | * |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | ||
| 13808 | 23 | #include <libxml/parser.h> |
| 24 | ||
| 7014 | 25 | #include "connection.h" |
| 13808 | 26 | #include "debug.h" |
| 7014 | 27 | #include "jabber.h" |
| 28 | #include "parser.h" | |
| 15159 | 29 | #include "util.h" |
| 7014 | 30 | #include "xmlnode.h" |
| 31 | ||
| 13808 | 32 | static void |
| 33 | jabber_parser_element_start_libxml(void *user_data, | |
| 34 | const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, | |
| 35 | int nb_namespaces, const xmlChar **namespaces, | |
| 36 | int nb_attributes, int nb_defaulted, const xmlChar **attributes) | |
| 37 | { | |
| 38 | JabberStream *js = user_data; | |
| 39 | xmlnode *node; | |
|
25288
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
40 | int i, j; |
| 13808 | 41 | |
| 42 | if(!element_name) { | |
| 43 | return; | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
44 | } else if(!xmlStrcmp(element_name, (xmlChar*) "stream")) { |
| 13808 | 45 | js->protocol_version = JABBER_PROTO_0_9; |
| 46 | for(i=0; i < nb_attributes * 5; i += 5) { | |
| 47 | int attrib_len = attributes[i+4] - attributes[i+3]; | |
| 48 | char *attrib = g_malloc(attrib_len + 1); | |
| 49 | memcpy(attrib, attributes[i+3], attrib_len); | |
| 50 | attrib[attrib_len] = '\0'; | |
|
14498
ede839a78714
[gaim-migrate @ 17150]
Mark Doliner <markdoliner@pidgin.im>
parents:
14476
diff
changeset
|
51 | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
52 | if(!xmlStrcmp(attributes[i], (xmlChar*) "version") |
| 13808 | 53 | && !strcmp(attrib, "1.0")) { |
| 54 | js->protocol_version = JABBER_PROTO_1_0; | |
|
14685
7622a9ca1794
[gaim-migrate @ 17352]
Daniel Atallah <datallah@pidgin.im>
parents:
14538
diff
changeset
|
55 | g_free(attrib); |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
56 | } else if(!xmlStrcmp(attributes[i], (xmlChar*) "id")) { |
|
15698
bcec3cb58d30
Patch from MatsMattsson (Adium Trac #6429) which fixes a leak of attrib for any attribute that isn't 'id' or 'version'.
Evan Schoenberg <evands@pidgin.im>
parents:
15558
diff
changeset
|
57 | g_free(js->stream_id); |
|
14685
7622a9ca1794
[gaim-migrate @ 17352]
Daniel Atallah <datallah@pidgin.im>
parents:
14538
diff
changeset
|
58 | js->stream_id = attrib; |
|
15698
bcec3cb58d30
Patch from MatsMattsson (Adium Trac #6429) which fixes a leak of attrib for any attribute that isn't 'id' or 'version'.
Evan Schoenberg <evands@pidgin.im>
parents:
15558
diff
changeset
|
59 | } else { |
|
25288
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
60 | g_free(attrib); |
| 13808 | 61 | } |
| 62 | } | |
| 63 | if(js->protocol_version == JABBER_PROTO_0_9) | |
| 64 | js->auth_type = JABBER_AUTH_IQ_AUTH; | |
| 65 | ||
|
17813
c5cc8ebf62c0
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 <am@adiumx.com>
parents:
17810
diff
changeset
|
66 | if(js->state == JABBER_STREAM_INITIALIZING || js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION) |
| 13808 | 67 | jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); |
| 68 | } else { | |
| 69 | ||
| 70 | if(js->current) | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
71 | node = xmlnode_new_child(js->current, (const char*) element_name); |
| 13808 | 72 | else |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
73 | node = xmlnode_new((const char*) element_name); |
|
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
74 | xmlnode_set_namespace(node, (const char*) namespace); |
|
25288
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
75 | xmlnode_set_prefix(node, (const char *)prefix); |
| 13808 | 76 | |
|
25288
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
77 | if (nb_namespaces != 0) { |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
78 | node->namespace_map = g_hash_table_new_full( |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
79 | g_str_hash, g_str_equal, g_free, g_free); |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
80 | |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
81 | for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) { |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
82 | const char *key = (const char *)namespaces[j]; |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
83 | const char *val = (const char *)namespaces[j + 1]; |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
84 | g_hash_table_insert(node->namespace_map, |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
85 | g_strdup(key ? key : ""), g_strdup(val ? val : "")); |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
86 | } |
|
2cd805f52348
Don't ignore XML namespace and prefix information when parsing incoming XMPP
Michal Witkowski <neuro@o2.pl>
parents:
24738
diff
changeset
|
87 | } |
| 13808 | 88 | for(i=0; i < nb_attributes * 5; i+=5) { |
|
25620
fb9118dea0ed
Don't set an attribute prefix on the node, and remove an unnecessary call
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25365
diff
changeset
|
89 | const char *attrib_ns = (const char *)attributes[i+2]; |
| 15158 | 90 | char *txt; |
| 13808 | 91 | int attrib_len = attributes[i+4] - attributes[i+3]; |
| 92 | char *attrib = g_malloc(attrib_len + 1); | |
| 15265 | 93 | |
| 13808 | 94 | memcpy(attrib, attributes[i+3], attrib_len); |
| 95 | attrib[attrib_len] = '\0'; | |
| 15265 | 96 | |
| 15158 | 97 | txt = attrib; |
| 15884 | 98 | attrib = purple_unescape_html(txt); |
| 15158 | 99 | g_free(txt); |
| 15265 | 100 | xmlnode_set_attrib_with_namespace(node, (const char*) attributes[i], attrib_ns, attrib); |
| 13808 | 101 | g_free(attrib); |
| 102 | } | |
| 103 | ||
| 104 | js->current = node; | |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 108 | static void | |
|
14498
ede839a78714
[gaim-migrate @ 17150]
Mark Doliner <markdoliner@pidgin.im>
parents:
14476
diff
changeset
|
109 | jabber_parser_element_end_libxml(void *user_data, const xmlChar *element_name, |
| 13808 | 110 | const xmlChar *prefix, const xmlChar *namespace) |
| 111 | { | |
| 112 | JabberStream *js = user_data; | |
| 113 | ||
| 114 | if(!js->current) | |
| 115 | return; | |
| 116 | ||
| 117 | if(js->current->parent) { | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
118 | if(!xmlStrcmp((xmlChar*) js->current->name, element_name)) |
| 13808 | 119 | js->current = js->current->parent; |
| 120 | } else { | |
| 121 | xmlnode *packet = js->current; | |
| 122 | js->current = NULL; | |
|
17828
6957bf9d7330
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 <am@adiumx.com>
parents:
17813
diff
changeset
|
123 | jabber_process_packet(js, &packet); |
|
24738
b642b5aa2a42
Don't try to free NULL xmlnodes stolen by jabber-receiving-xmlnode handlers
Will Thompson <resiak@pidgin.im>
parents:
24706
diff
changeset
|
124 | if (packet != NULL) |
|
b642b5aa2a42
Don't try to free NULL xmlnodes stolen by jabber-receiving-xmlnode handlers
Will Thompson <resiak@pidgin.im>
parents:
24706
diff
changeset
|
125 | xmlnode_free(packet); |
| 13808 | 126 | } |
| 127 | } | |
| 128 | ||
| 129 | static void | |
| 130 | jabber_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) | |
| 131 | { | |
| 132 | JabberStream *js = user_data; | |
| 133 | ||
| 134 | if(!js->current) | |
| 135 | return; | |
| 136 | ||
| 137 | if(!text || !text_len) | |
| 138 | return; | |
| 139 | ||
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14685
diff
changeset
|
140 | xmlnode_insert_data(js->current, (const char*) text, text_len); |
| 13808 | 141 | } |
| 142 | ||
|
23567
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
143 | static void |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
144 | jabber_parser_structured_error_handler(void *user_data, xmlErrorPtr error) |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
145 | { |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
146 | JabberStream *js = user_data; |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
147 | |
|
24703
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
148 | if (error->level == XML_ERR_WARNING && error->message != NULL |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
149 | && strcmp(error->message, "xmlns: URI vcard-temp is not absolute\n") == 0) |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
150 | /* |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
151 | * This message happens when parsing vcards, and is normal, so don't |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
152 | * bother logging it because people scare easily. |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
153 | */ |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
154 | return; |
|
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
155 | |
|
23567
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
156 | purple_debug_error("jabber", "XML parser error for JabberStream %p: " |
|
24703
26998f3425f7
Don't log an error when parsing vcard data. Also, these messages
Mark Doliner <markdoliner@pidgin.im>
parents:
24149
diff
changeset
|
157 | "Domain %i, code %i, level %i: %s", |
|
23567
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
158 | js, |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
159 | error->domain, error->code, error->level, |
|
24706
9fbd313398fe
I know Mark was trying to save newlines, but I had one to spare.
Richard Laager <rlaager@pidgin.im>
parents:
24703
diff
changeset
|
160 | (error->message ? error->message : "(null)\n")); |
|
23567
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
161 | } |
|
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
162 | |
| 13808 | 163 | static xmlSAXHandler jabber_parser_libxml = { |
|
23077
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
164 | NULL, /*internalSubset*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
165 | NULL, /*isStandalone*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
166 | NULL, /*hasInternalSubset*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
167 | NULL, /*hasExternalSubset*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
168 | NULL, /*resolveEntity*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
169 | NULL, /*getEntity*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
170 | NULL, /*entityDecl*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
171 | NULL, /*notationDecl*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
172 | NULL, /*attributeDecl*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
173 | NULL, /*elementDecl*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
174 | NULL, /*unparsedEntityDecl*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
175 | NULL, /*setDocumentLocator*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
176 | NULL, /*startDocument*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
177 | NULL, /*endDocument*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
178 | NULL, /*startElement*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
179 | NULL, /*endElement*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
180 | NULL, /*reference*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
181 | jabber_parser_element_text_libxml, /*characters*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
182 | NULL, /*ignorableWhitespace*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
183 | NULL, /*processingInstruction*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
184 | NULL, /*comment*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
185 | NULL, /*warning*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
186 | NULL, /*error*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
187 | NULL, /*fatalError*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
188 | NULL, /*getParameterEntity*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
189 | NULL, /*cdataBlock*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
190 | NULL, /*externalSubset*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
191 | XML_SAX2_MAGIC, /*initialized*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
192 | NULL, /*_private*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
193 | jabber_parser_element_start_libxml, /*startElementNs*/ |
|
431e35debb40
Using named elements in a struct initialization doesn't work in MSVC.
Daniel Atallah <datallah@pidgin.im>
parents:
21279
diff
changeset
|
194 | jabber_parser_element_end_libxml, /*endElementNs*/ |
|
23567
9189d89be26f
Added a structured error handler callback to the xmlSAXHandler struct.
Evan Schoenberg <evands@pidgin.im>
parents:
23077
diff
changeset
|
195 | jabber_parser_structured_error_handler /*serror*/ |
| 13808 | 196 | }; |
| 7014 | 197 | |
| 198 | void | |
| 199 | jabber_parser_setup(JabberStream *js) | |
| 200 | { | |
| 14538 | 201 | /* This seems backwards, but it makes sense. The libxml code creates |
| 202 | * the parser context when you try to use it (this way, it can figure | |
| 203 | * out the encoding at creation time. So, setting up the parser is | |
| 204 | * just a matter of destroying any current parser. */ | |
|
17810
c8d4297080cb
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
205 | jabber_parser_free(js); |
|
c8d4297080cb
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
206 | } |
|
c8d4297080cb
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
207 | |
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
208 | void |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
209 | jabber_parser_close_stream(JabberStream *js) |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
210 | { |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
211 | xmlParseChunk(js->context, "</stream:stream>", 16 /* length */, 0); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
212 | } |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
213 | |
|
17810
c8d4297080cb
Fixed a leak: The XML parser was never cleaned up on disconnect.
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
214 | void jabber_parser_free(JabberStream *js) { |
| 13808 | 215 | if (js->context) { |
| 216 | xmlParseChunk(js->context, NULL,0,1); | |
| 217 | xmlFreeParserCtxt(js->context); | |
| 218 | js->context = NULL; | |
| 219 | } | |
| 7014 | 220 | } |
| 221 | ||
| 222 | void jabber_parser_process(JabberStream *js, const char *buf, int len) | |
| 223 | { | |
|
23568
bd3e623fa265
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evands@pidgin.im>
parents:
23567
diff
changeset
|
224 | int ret; |
|
bd3e623fa265
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evands@pidgin.im>
parents:
23567
diff
changeset
|
225 | |
| 23570 | 226 | if (js->context == NULL) { |
| 14538 | 227 | /* libxml inconsistently starts parsing on creating the |
| 228 | * parser, so do a ParseChunk right afterwards to force it. */ | |
| 13808 | 229 | js->context = xmlCreatePushParserCtxt(&jabber_parser_libxml, js, buf, len, NULL); |
| 14700 | 230 | xmlParseChunk(js->context, "", 0, 0); |
|
23568
bd3e623fa265
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evands@pidgin.im>
parents:
23567
diff
changeset
|
231 | } else if ((ret = xmlParseChunk(js->context, buf, len, 0)) != XML_ERR_OK) { |
|
24149
7ee629835390
Only disconnect xmpp connections during xml parsing if the error is an
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
23570
diff
changeset
|
232 | xmlError *err = xmlCtxtGetLastError(js->context); |
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
233 | /* |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
234 | * libxml2 uses a global setting to determine whether or not to store |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
235 | * warnings. Other libraries may set this, which causes err to be |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
236 | * NULL. See #8136 for details. |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
237 | */ |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
238 | xmlErrorLevel level = XML_ERR_WARNING; |
|
23568
bd3e623fa265
xmlParseChunk() never returns less than 0. It retusn an error code from
Evan Schoenberg <evands@pidgin.im>
parents:
23567
diff
changeset
|
239 | |
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
240 | if (err) |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
241 | level = err->level; |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
242 | |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25620
diff
changeset
|
243 | switch (level) { |
|
25365
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
244 | case XML_ERR_NONE: |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
245 | purple_debug_info("jabber", "xmlParseChunk returned info %i\n", ret); |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
246 | break; |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
247 | case XML_ERR_WARNING: |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
248 | purple_debug_warning("jabber", "xmlParseChunk returned warning %i\n", ret); |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
249 | break; |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
250 | case XML_ERR_ERROR: |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
251 | purple_debug_error("jabber", "xmlParseChunk returned error %i\n", ret); |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
252 | break; |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
253 | case XML_ERR_FATAL: |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
254 | purple_debug_error("jabber", "xmlParseChunk returned fatal %i\n", ret); |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
255 | purple_connection_error_reason (js->gc, |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
256 | PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
257 | _("XML Parse error")); |
|
e941a99c74b3
Make XML parsing error levels match libxml2's levels, making less important
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
25288
diff
changeset
|
258 | break; |
|
23569
b76c41ef45d4
Drop and then recover from XML messages which trigger invalid character
Evan Schoenberg <evands@pidgin.im>
parents:
23568
diff
changeset
|
259 | } |
| 13808 | 260 | } |
| 7014 | 261 | } |
| 262 |