xref: /PHP-7.3/ext/dom/entityreference.c (revision 8d3f8ca1)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Christian Stocker <chregu@php.net>                          |
16    |          Rob Richards <rrichards@php.net>                            |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "php.h"
25 #if HAVE_LIBXML && HAVE_DOM
26 #include "php_dom.h"
27 
28 /* {{{ arginfo */
29 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_entityreference_construct, 0, 0, 1)
30 	ZEND_ARG_INFO(0, name)
31 ZEND_END_ARG_INFO();
32 /* }}} */
33 
34 /*
35 * class DOMEntityReference extends DOMNode
36 *
37 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-11C98490
38 * Since:
39 */
40 
41 const zend_function_entry php_dom_entityreference_class_functions[] = {
42 	PHP_ME(domentityreference, __construct, arginfo_dom_entityreference_construct, ZEND_ACC_PUBLIC)
43 	PHP_FE_END
44 };
45 
46 /* {{{ proto DOMEntityReference::__construct(string name) */
PHP_METHOD(domentityreference,__construct)47 PHP_METHOD(domentityreference, __construct)
48 {
49 	zval *id = getThis();
50 	xmlNode *node;
51 	xmlNodePtr oldnode = NULL;
52 	dom_object *intern;
53 	char *name;
54 	size_t name_len, name_valid;
55 
56 	if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
57 		return;
58 	}
59 
60 	name_valid = xmlValidateName((xmlChar *) name, 0);
61 	if (name_valid != 0) {
62 		php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
63 		RETURN_FALSE;
64 	}
65 
66 	node = xmlNewReference(NULL, (xmlChar *) name);
67 
68 	if (!node) {
69 		php_dom_throw_error(INVALID_STATE_ERR, 1);
70 		RETURN_FALSE;
71 	}
72 
73 	intern = Z_DOMOBJ_P(id);
74 	if (intern != NULL) {
75 		oldnode = dom_object_get_node(intern);
76 		if (oldnode != NULL) {
77 			php_libxml_node_free_resource(oldnode );
78 		}
79 		php_libxml_increment_node_ptr((php_libxml_node_object *)intern, node, (void *)intern);
80 	}
81 }
82 /* }}} end DOMEntityReference::__construct */
83 
84 #endif
85 
86 /*
87  * Local variables:
88  * tab-width: 4
89  * c-basic-offset: 4
90  * End:
91  * vim600: noet sw=4 ts=4 fdm=marker
92  * vim<600: noet sw=4 ts=4
93  */
94