@@ -2101,146 +2101,6 @@ PHP_METHOD(DOMNode, lookupNamespaceURI)
21012101}
21022102/* }}} end dom_node_lookup_namespace_uri */
21032103
2104- /* Allocate, track and prepend a temporary nsDef entry for C14N.
2105- * Returns the new xmlNsPtr for the caller to fill in href/prefix/_private,
2106- * or NULL on allocation failure. */
2107- static xmlNsPtr dom_alloc_ns_decl (HashTable * links , xmlNodePtr node )
2108- {
2109- xmlNsPtr ns = xmlMalloc (sizeof (* ns ));
2110- if (!ns ) {
2111- return NULL ;
2112- }
2113-
2114- zval * zv = zend_hash_index_lookup (links , (zend_ulong ) node );
2115- if (Z_ISNULL_P (zv )) {
2116- ZVAL_LONG (zv , 1 );
2117- } else {
2118- Z_LVAL_P (zv )++ ;
2119- }
2120-
2121- memset (ns , 0 , sizeof (* ns ));
2122- ns -> type = XML_LOCAL_NAMESPACE ;
2123- ns -> next = node -> nsDef ;
2124- node -> nsDef = ns ;
2125-
2126- return ns ;
2127- }
2128-
2129- /* Mint a temporary nsDef entry so C14N finds namespaces that live on node->ns
2130- * but have no matching xmlns attribute (typical for createElementNS). */
2131- static void dom_add_synthetic_ns_decl (HashTable * links , xmlNodePtr node , xmlNsPtr src_ns )
2132- {
2133- xmlNsPtr ns = dom_alloc_ns_decl (links , node );
2134- if (!ns ) {
2135- return ;
2136- }
2137-
2138- ns -> href = xmlStrdup (src_ns -> href );
2139- ns -> prefix = src_ns -> prefix ? xmlStrdup (src_ns -> prefix ) : NULL ;
2140- }
2141-
2142- /* Same, but for attribute namespaces, which may collide by prefix with the
2143- * element's own ns or with a sibling attribute's ns. */
2144- static void dom_add_synthetic_ns_decl_for_attr (HashTable * links , xmlNodePtr node , xmlNsPtr src_ns )
2145- {
2146- for (xmlNsPtr existing = node -> nsDef ; existing ; existing = existing -> next ) {
2147- if (xmlStrEqual (existing -> prefix , src_ns -> prefix )) {
2148- return ;
2149- }
2150- }
2151-
2152- dom_add_synthetic_ns_decl (links , node , src_ns );
2153- }
2154-
2155- static void dom_relink_ns_decls_element (HashTable * links , xmlNodePtr node )
2156- {
2157- if (node -> type == XML_ELEMENT_NODE ) {
2158- for (xmlAttrPtr attr = node -> properties ; attr ; attr = attr -> next ) {
2159- if (php_dom_ns_is_fast ((const xmlNode * ) attr , php_dom_ns_is_xmlns_magic_token )) {
2160- xmlNsPtr ns = dom_alloc_ns_decl (links , node );
2161- if (!ns ) {
2162- return ;
2163- }
2164-
2165- bool should_free ;
2166- xmlChar * attr_value = php_libxml_attr_value (attr , & should_free );
2167-
2168- ns -> href = should_free ? attr_value : xmlStrdup (attr_value );
2169- ns -> prefix = attr -> ns -> prefix ? xmlStrdup (attr -> name ) : NULL ;
2170- ns -> _private = attr ;
2171- if (attr -> prev ) {
2172- attr -> prev -> next = attr -> next ;
2173- } else {
2174- node -> properties = attr -> next ;
2175- }
2176- if (attr -> next ) {
2177- attr -> next -> prev = attr -> prev ;
2178- }
2179- }
2180- }
2181-
2182- /* The default namespace is handled separately from the other namespaces in C14N.
2183- * The default namespace is explicitly looked up while the other namespaces are
2184- * deduplicated and compared to a list of visible namespaces. */
2185- if (node -> ns && !node -> ns -> prefix ) {
2186- /* Workaround for the behaviour where the xmlSearchNs() call inside c14n.c
2187- * can return the current namespace. */
2188- zend_hash_index_add_new_ptr (links , (zend_ulong ) node | 1 , node -> ns );
2189- node -> ns = xmlSearchNs (node -> doc , node , NULL );
2190- } else if (node -> ns ) {
2191- dom_add_synthetic_ns_decl (links , node , node -> ns );
2192- }
2193-
2194- for (xmlAttrPtr attr = node -> properties ; attr ; attr = attr -> next ) {
2195- if (attr -> ns && !php_dom_ns_is_fast ((const xmlNode * ) attr , php_dom_ns_is_xmlns_magic_token )) {
2196- dom_add_synthetic_ns_decl_for_attr (links , node , attr -> ns );
2197- }
2198- }
2199- }
2200- }
2201-
2202- static void dom_relink_ns_decls (HashTable * links , xmlNodePtr root )
2203- {
2204- dom_relink_ns_decls_element (links , root );
2205-
2206- xmlNodePtr base = root ;
2207- xmlNodePtr node = base -> children ;
2208- while (node != NULL ) {
2209- dom_relink_ns_decls_element (links , node );
2210- node = php_dom_next_in_tree_order (node , base );
2211- }
2212- }
2213-
2214- static void dom_unlink_ns_decls (HashTable * links )
2215- {
2216- ZEND_HASH_MAP_FOREACH_NUM_KEY_VAL (links , zend_ulong h , zval * data ) {
2217- if (h & 1 ) {
2218- xmlNodePtr node = (xmlNodePtr ) (h ^ 1 );
2219- node -> ns = Z_PTR_P (data );
2220- } else {
2221- xmlNodePtr node = (xmlNodePtr ) h ;
2222- while (Z_LVAL_P (data )-- > 0 ) {
2223- xmlNsPtr ns = node -> nsDef ;
2224- node -> nsDef = ns -> next ;
2225-
2226- xmlAttrPtr attr = ns -> _private ;
2227- if (attr ) {
2228- if (attr -> prev ) {
2229- attr -> prev -> next = attr ;
2230- } else {
2231- node -> properties = attr ;
2232- }
2233- if (attr -> next ) {
2234- attr -> next -> prev = attr ;
2235- }
2236- }
2237-
2238- xmlFreeNs (ns );
2239- }
2240- }
2241- } ZEND_HASH_FOREACH_END ();
2242- }
2243-
22442104static int dom_canonicalize_node_parent_lookup_cb (void * user_data , xmlNodePtr node , xmlNodePtr parent )
22452105{
22462106 xmlNodePtr root = user_data ;
0 commit comments