56
56
* - Weird things happen with <![CDATA[]]> sections.
57
57
*/
58
58
59
+ ZEND_BEGIN_MODULE_GLOBALS (xml )
60
+ XML_Char * default_encoding ;
61
+ ZEND_END_MODULE_GLOBALS (xml )
62
+
59
63
ZEND_DECLARE_MODULE_GLOBALS (xml )
60
64
65
+ #define XML (v ) ZEND_MODULE_GLOBALS_ACCESSOR (xml , v )
66
+
67
+ typedef struct {
68
+ int case_folding ;
69
+ XML_Parser parser ;
70
+ XML_Char * target_encoding ;
71
+
72
+ zval index ;
73
+ zval startElementHandler ;
74
+ zval endElementHandler ;
75
+ zval characterDataHandler ;
76
+ zval processingInstructionHandler ;
77
+ zval defaultHandler ;
78
+ zval unparsedEntityDeclHandler ;
79
+ zval notationDeclHandler ;
80
+ zval externalEntityRefHandler ;
81
+ zval unknownEncodingHandler ;
82
+ zval startNamespaceDeclHandler ;
83
+ zval endNamespaceDeclHandler ;
84
+
85
+ zend_function * startElementPtr ;
86
+ zend_function * endElementPtr ;
87
+ zend_function * characterDataPtr ;
88
+ zend_function * processingInstructionPtr ;
89
+ zend_function * defaultPtr ;
90
+ zend_function * unparsedEntityDeclPtr ;
91
+ zend_function * notationDeclPtr ;
92
+ zend_function * externalEntityRefPtr ;
93
+ zend_function * unknownEncodingPtr ;
94
+ zend_function * startNamespaceDeclPtr ;
95
+ zend_function * endNamespaceDeclPtr ;
96
+
97
+ zval object ;
98
+
99
+ zval data ;
100
+ zval info ;
101
+ int level ;
102
+ int toffset ;
103
+ int curtag ;
104
+ zval * ctag ;
105
+ char * * ltags ;
106
+ int lastwasopen ;
107
+ int skipwhite ;
108
+ int isparsing ;
109
+
110
+ XML_Char * baseURI ;
111
+ } xml_parser ;
112
+
113
+
114
+ typedef struct {
115
+ XML_Char * name ;
116
+ char (* decoding_function )(unsigned short );
117
+ unsigned short (* encoding_function )(unsigned char );
118
+ } xml_encoding ;
119
+
120
+
121
+ enum php_xml_option {
122
+ PHP_XML_OPTION_CASE_FOLDING = 1 ,
123
+ PHP_XML_OPTION_TARGET_ENCODING ,
124
+ PHP_XML_OPTION_SKIP_TAGSTART ,
125
+ PHP_XML_OPTION_SKIP_WHITE
126
+ };
127
+
61
128
/* {{{ dynamically loadable module stuff */
62
129
#ifdef COMPILE_DL_XML
63
130
#ifdef ZTS
@@ -67,6 +134,7 @@ ZEND_GET_MODULE(xml)
67
134
#endif /* COMPILE_DL_XML */
68
135
/* }}} */
69
136
137
+ #define XML_MAXLEVEL 255 /* XXX this should be dynamic */
70
138
71
139
#define SKIP_TAGSTART (str ) ((str) + (parser->toffset > (int)strlen(str) ? strlen(str) : parser->toffset))
72
140
@@ -76,6 +144,30 @@ PHP_MINIT_FUNCTION(xml);
76
144
PHP_MINFO_FUNCTION (xml );
77
145
static PHP_GINIT_FUNCTION (xml );
78
146
147
+ PHP_FUNCTION (xml_parser_create );
148
+ PHP_FUNCTION (xml_parser_create_ns );
149
+ PHP_FUNCTION (xml_set_object );
150
+ PHP_FUNCTION (xml_set_element_handler );
151
+ PHP_FUNCTION (xml_set_character_data_handler );
152
+ PHP_FUNCTION (xml_set_processing_instruction_handler );
153
+ PHP_FUNCTION (xml_set_default_handler );
154
+ PHP_FUNCTION (xml_set_unparsed_entity_decl_handler );
155
+ PHP_FUNCTION (xml_set_notation_decl_handler );
156
+ PHP_FUNCTION (xml_set_external_entity_ref_handler );
157
+ PHP_FUNCTION (xml_set_start_namespace_decl_handler );
158
+ PHP_FUNCTION (xml_set_end_namespace_decl_handler );
159
+ PHP_FUNCTION (xml_parse );
160
+ PHP_FUNCTION (xml_get_error_code );
161
+ PHP_FUNCTION (xml_error_string );
162
+ PHP_FUNCTION (xml_get_current_line_number );
163
+ PHP_FUNCTION (xml_get_current_column_number );
164
+ PHP_FUNCTION (xml_get_current_byte_index );
165
+ PHP_FUNCTION (xml_parser_free );
166
+ PHP_FUNCTION (xml_parser_set_option );
167
+ PHP_FUNCTION (xml_parser_get_option );
168
+ PHP_FUNCTION (xml_parse_into_struct );
169
+
170
+ static zend_string * xml_utf8_decode (const XML_Char * , size_t , const XML_Char * );
79
171
static void xml_parser_dtor (zend_resource * rsrc );
80
172
static void xml_set_handler (zval * , zval * );
81
173
inline static unsigned short xml_encode_iso_8859_1 (unsigned char );
@@ -549,59 +641,8 @@ static const xml_encoding *xml_get_encoding(const XML_Char *name)
549
641
}
550
642
/* }}} */
551
643
552
- /* {{{ xml_utf8_encode() */
553
- PHP_XML_API zend_string * xml_utf8_encode (const char * s , size_t len , const XML_Char * encoding )
554
- {
555
- size_t pos = len ;
556
- zend_string * str ;
557
- unsigned int c ;
558
- unsigned short (* encoder )(unsigned char ) = NULL ;
559
- const xml_encoding * enc = xml_get_encoding (encoding );
560
-
561
- if (enc ) {
562
- encoder = enc -> encoding_function ;
563
- } else {
564
- /* If the target encoding was unknown, fail */
565
- return NULL ;
566
- }
567
- if (encoder == NULL ) {
568
- /* If no encoder function was specified, return the data as-is.
569
- */
570
- str = zend_string_init (s , len , 0 );
571
- return str ;
572
- }
573
- /* This is the theoretical max (will never get beyond len * 2 as long
574
- * as we are converting from single-byte characters, though) */
575
- str = zend_string_safe_alloc (len , 4 , 0 , 0 );
576
- ZSTR_LEN (str ) = 0 ;
577
- while (pos > 0 ) {
578
- c = encoder ? encoder ((unsigned char )(* s )) : (unsigned short )(* s );
579
- if (c < 0x80 ) {
580
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (char ) c ;
581
- } else if (c < 0x800 ) {
582
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xc0 | (c >> 6 ));
583
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0x80 | (c & 0x3f ));
584
- } else if (c < 0x10000 ) {
585
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xe0 | (c >> 12 ));
586
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xc0 | ((c >> 6 ) & 0x3f ));
587
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0x80 | (c & 0x3f ));
588
- } else if (c < 0x200000 ) {
589
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xf0 | (c >> 18 ));
590
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xe0 | ((c >> 12 ) & 0x3f ));
591
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0xc0 | ((c >> 6 ) & 0x3f ));
592
- ZSTR_VAL (str )[ZSTR_LEN (str )++ ] = (0x80 | (c & 0x3f ));
593
- }
594
- pos -- ;
595
- s ++ ;
596
- }
597
- ZSTR_VAL (str )[ZSTR_LEN (str )] = '\0' ;
598
- str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
599
- return str ;
600
- }
601
- /* }}} */
602
-
603
644
/* {{{ xml_utf8_decode() */
604
- PHP_XML_API zend_string * xml_utf8_decode (const XML_Char * s , size_t len , const XML_Char * encoding )
645
+ static zend_string * xml_utf8_decode (const XML_Char * s , size_t len , const XML_Char * encoding )
605
646
{
606
647
size_t pos = 0 ;
607
648
unsigned int c ;
@@ -655,19 +696,6 @@ static int _xml_xmlcharlen(const XML_Char *s)
655
696
}
656
697
/* }}} */
657
698
658
- /* {{{ _xml_zval_strdup() */
659
- PHP_XML_API char * _xml_zval_strdup (zval * val )
660
- {
661
- if (Z_TYPE_P (val ) == IS_STRING ) {
662
- char * buf = emalloc (Z_STRLEN_P (val ) + 1 );
663
- memcpy (buf , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
664
- buf [Z_STRLEN_P (val )] = '\0' ;
665
- return buf ;
666
- }
667
- return NULL ;
668
- }
669
- /* }}} */
670
-
671
699
/* {{{ _xml_add_to_info() */
672
700
static void _xml_add_to_info (xml_parser * parser ,char * name )
673
701
{
0 commit comments