processinginstruction.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #if HAVE_LIBXML && HAVE_DOM
  24. #include "php_dom.h"
  25. /* {{{ arginfo */
  26. ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_processinginstruction_construct, 0, 0, 1)
  27. ZEND_ARG_INFO(0, name)
  28. ZEND_ARG_INFO(0, value)
  29. ZEND_END_ARG_INFO();
  30. /* }}} */
  31. /*
  32. * class DOMProcessingInstruction extends DOMNode
  33. *
  34. * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
  35. * Since:
  36. */
  37. const zend_function_entry php_dom_processinginstruction_class_functions[] = {
  38. PHP_ME(domprocessinginstruction, __construct, arginfo_dom_processinginstruction_construct, ZEND_ACC_PUBLIC)
  39. PHP_FE_END
  40. };
  41. /* {{{ proto DOMProcessingInstruction::__construct(string name, [string value]); */
  42. PHP_METHOD(domprocessinginstruction, __construct)
  43. {
  44. zval *id = getThis();
  45. xmlNodePtr nodep = NULL, oldnode = NULL;
  46. dom_object *intern;
  47. char *name, *value = NULL;
  48. size_t name_len, value_len;
  49. int name_valid;
  50. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
  51. return;
  52. }
  53. name_valid = xmlValidateName((xmlChar *) name, 0);
  54. if (name_valid != 0) {
  55. php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
  56. RETURN_FALSE;
  57. }
  58. nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
  59. if (!nodep) {
  60. php_dom_throw_error(INVALID_STATE_ERR, 1);
  61. RETURN_FALSE;
  62. }
  63. intern = Z_DOMOBJ_P(id);
  64. oldnode = dom_object_get_node(intern);
  65. if (oldnode != NULL) {
  66. php_libxml_node_free_resource(oldnode );
  67. }
  68. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
  69. }
  70. /* }}} end DOMProcessingInstruction::__construct */
  71. /* {{{ target string
  72. readonly=yes
  73. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
  74. Since:
  75. */
  76. int dom_processinginstruction_target_read(dom_object *obj, zval *retval)
  77. {
  78. xmlNodePtr nodep = dom_object_get_node(obj);
  79. if (nodep == NULL) {
  80. php_dom_throw_error(INVALID_STATE_ERR, 0);
  81. return FAILURE;
  82. }
  83. ZVAL_STRING(retval, (char *) (nodep->name));
  84. return SUCCESS;
  85. }
  86. /* }}} */
  87. /* {{{ data string
  88. readonly=no
  89. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
  90. Since:
  91. */
  92. int dom_processinginstruction_data_read(dom_object *obj, zval *retval)
  93. {
  94. xmlNodePtr nodep;
  95. xmlChar *content;
  96. nodep = dom_object_get_node(obj);
  97. if (nodep == NULL) {
  98. php_dom_throw_error(INVALID_STATE_ERR, 0);
  99. return FAILURE;
  100. }
  101. if ((content = xmlNodeGetContent(nodep)) != NULL) {
  102. ZVAL_STRING(retval, (char *) content);
  103. xmlFree(content);
  104. } else {
  105. ZVAL_EMPTY_STRING(retval);
  106. }
  107. return SUCCESS;
  108. }
  109. int dom_processinginstruction_data_write(dom_object *obj, zval *newval)
  110. {
  111. xmlNode *nodep = dom_object_get_node(obj);
  112. zend_string *str;
  113. if (nodep == NULL) {
  114. php_dom_throw_error(INVALID_STATE_ERR, 0);
  115. return FAILURE;
  116. }
  117. str = zval_get_string(newval);
  118. xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
  119. zend_string_release_ex(str, 0);
  120. return SUCCESS;
  121. }
  122. /* }}} */
  123. #endif
  124. /*
  125. * Local variables:
  126. * tab-width: 4
  127. * c-basic-offset: 4
  128. * End:
  129. * vim600: noet sw=4 ts=4 fdm=marker
  130. * vim<600: noet sw=4 ts=4
  131. */