View | Details | Raw Unified | Return to bug 131744
Collapse All | Expand All

(-)patch-compat.c (-3 / +140 lines)
Lines 1-9 Link Here
1
--- compat.c.orig	Tue Jul 20 10:55:02 2004
1
--- compat.c.orig	2007-12-31 16:20:14.000000000 +0900
2
+++ compat.c	Tue Jul 20 10:55:55 2004
2
+++ compat.c	2009-01-13 00:45:21.000000000 +0900
3
@@ -2,7 +2,7 @@
4
    +----------------------------------------------------------------------+
5
    | PHP Version 5                                                        |
6
    +----------------------------------------------------------------------+
7
-   | Copyright (c) 1997-2008 The PHP Group                                |
8
+   | Copyright (c) 1997-2009 The PHP Group                                |
9
    +----------------------------------------------------------------------+
10
    | This source file is subject to version 3.01 of the PHP license,      |
11
    | that is bundled with this package in the file LICENSE, and is        |
3
@@ -16,6 +16,10 @@
12
@@ -16,6 +16,10 @@
4
    +----------------------------------------------------------------------+
13
    +----------------------------------------------------------------------+
5
  */
14
  */
6
 
15
7
+#ifdef HAVE_CONFIG_H
16
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
17
+#include "config.h"
9
+#endif
18
+#endif
Lines 11-13 Link Here
11
 #include "php.h"
20
 #include "php.h"
12
 #if defined(HAVE_LIBXML) && defined(HAVE_XML) && !defined(HAVE_LIBEXPAT)
21
 #if defined(HAVE_LIBXML) && defined(HAVE_XML) && !defined(HAVE_LIBEXPAT)
13
 #include "expat_compat.h"
22
 #include "expat_compat.h"
23
@@ -40,7 +44,7 @@
24
 			/* Use libxml functions otherwise its memory deallocation is screwed up */
25
 			*qualified = xmlStrdup(URI);
26
 			*qualified = xmlStrncat(*qualified, parser->_ns_seperator, 1);
27
-			*qualified = xmlStrncat(*qualified, name, strlen(name));
28
+			*qualified = xmlStrncat(*qualified, name, xmlStrlen(name));
29
 	} else {
30
 		*qualified = xmlStrdup(name);
31
 	}
32
@@ -104,7 +108,66 @@
33
 		y = 0;
34
 	}
35
 	
36
-	if (parser->h_start_element == NULL && parser->h_default == NULL) {
37
+	if (parser->h_start_element == NULL) {
38
+	 	if (parser->h_default) {
39
+
40
+			if (prefix) {
41
+				qualified_name = xmlStrncatNew((xmlChar *)"<", prefix, xmlStrlen(prefix));
42
+				qualified_name = xmlStrncat(qualified_name, (xmlChar *)":", 1);
43
+				qualified_name = xmlStrncat(qualified_name, name, xmlStrlen(name));
44
+			} else {
45
+				qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
46
+			}
47
+			
48
+			if (namespaces) {
49
+				int i, j;
50
+				for (i = 0,j = 0;j < nb_namespaces;j++) {
51
+					int ns_len;
52
+					char *ns_string, *ns_prefix, *ns_url;
53
+					
54
+					ns_prefix = (char *) namespaces[i++];
55
+					ns_url = (char *) namespaces[i++];
56
+					
57
+					if (ns_prefix) {
58
+						ns_len = spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url);
59
+					} else {
60
+						ns_len = spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url);
61
+					}
62
+					qualified_name = xmlStrncat(qualified_name, (xmlChar *)ns_string, ns_len);
63
+					
64
+					efree(ns_string);
65
+				}
66
+			}
67
+			
68
+			if (attributes) {
69
+				for (i = 0; i < nb_attributes; i += 1) {
70
+					int att_len;
71
+					char *att_string, *att_name, *att_value, *att_prefix, *att_valueend;
72
+
73
+					att_name = (char *) attributes[y++];
74
+					att_prefix = (char *)attributes[y++];
75
+					y++;
76
+					att_value = (char *)attributes[y++];
77
+					att_valueend = (char *)attributes[y++];
78
+
79
+					if (att_prefix) {
80
+						att_len = spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name);
81
+					} else {
82
+						att_len = spprintf(&att_string, 0, " %s=\"", att_name);
83
+					}
84
+
85
+					qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
86
+					qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_value, att_valueend - att_value);
87
+					qualified_name = xmlStrncat(qualified_name, (xmlChar *)"\"", 1);
88
+					
89
+					efree(att_string);
90
+				}
91
+
92
+			}
93
+			qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
94
+			parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
95
+			xmlFree(qualified_name);
96
+		}
97
 		return;
98
 	}
99
 	_qualify_namespace(parser, name, URI, &qualified_name);
100
@@ -178,6 +241,18 @@
101
 	XML_Parser  parser = (XML_Parser) user;
102
 
103
 	if (parser->h_end_element == NULL) {
104
+		if (parser->h_default) {
105
+			char *end_element;
106
+			int end_element_len;
107
+
108
+			if (prefix) {
109
+				end_element_len = spprintf(&end_element, 0, "</%s:%s>", (char *) prefix, (char *)name);
110
+			} else {
111
+				end_element_len = spprintf(&end_element, 0, "</%s>", (char *)name);
112
+			}
113
+			parser->h_default(parser->user, (const XML_Char *) end_element, end_element_len);
114
+			efree(end_element);
115
+		}
116
 		return;
117
 	}
118
 
119
@@ -212,7 +287,7 @@
120
 		if (parser->h_default) {
121
 			char    *full_pi;
122
 			spprintf(&full_pi, 0, "<?%s %s?>", (char *)target, (char *)data);
123
-			parser->h_default(parser->user, (const XML_Char *) full_pi, xmlStrlen(full_pi));
124
+			parser->h_default(parser->user, (const XML_Char *) full_pi, strlen(full_pi));
125
 			efree(full_pi);
126
 		}
127
 		return;
128
@@ -411,6 +486,10 @@
129
 	parser->parser->charset = XML_CHAR_ENCODING_NONE;
130
 #endif
131
 
132
+#if LIBXML_VERSION >= 20703
133
+	xmlCtxtUseOptions(parser->parser, XML_PARSE_OLDSAX);
134
+#endif
135
+
136
 	parser->parser->replaceEntities = 1;
137
 	parser->parser->wellFormed = 0;
138
 	if (sep != NULL) {
139
@@ -545,10 +624,10 @@
140
 
141
 static const XML_Char *const error_mapping[] = {
142
 	"No error",
143
-	"Internal error",
144
 	"No memory",
145
 	"Invalid document start",
146
 	"Empty document",
147
+	"Not well-formed (invalid token)",
148
 	"Invalid document end",
149
 	"Invalid hexadecimal character reference",
150
 	"Invalid decimal character reference",

Return to bug 131744