xref: /PHP-8.1/ext/dom/comment.c (revision 08c4db7f)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Authors: Christian Stocker <chregu@php.net>                          |
14    |          Rob Richards <rrichards@php.net>                            |
15    +----------------------------------------------------------------------+
16 */
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "php.h"
23 #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
24 #include "php_dom.h"
25 
26 /*
27 * class DOMComment extends DOMCharacterData
28 *
29 * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1728279322
30 * Since:
31 */
32 
33 /* {{{ */
PHP_METHOD(DOMComment,__construct)34 PHP_METHOD(DOMComment, __construct)
35 {
36 	xmlNodePtr nodep = NULL, oldnode = NULL;
37 	dom_object *intern;
38 	char *value = NULL;
39 	size_t value_len;
40 
41 	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
42 		RETURN_THROWS();
43 	}
44 
45 	nodep = xmlNewComment((xmlChar *) value);
46 
47 	if (!nodep) {
48 		php_dom_throw_error(INVALID_STATE_ERR, 1);
49 		RETURN_THROWS();
50 	}
51 
52 	intern = Z_DOMOBJ_P(ZEND_THIS);
53 	oldnode = dom_object_get_node(intern);
54 	if (oldnode != NULL) {
55 		php_libxml_node_decrement_resource((php_libxml_node_object *)intern);
56 	}
57 	php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)nodep, (void *)intern);
58 }
59 /* }}} end DOMComment::__construct */
60 
61 #endif
62