processinginstruction.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include "php.h"
  21. #if defined(HAVE_LIBXML) && defined(HAVE_DOM)
  22. #include "php_dom.h"
  23. /*
  24. * class DOMProcessingInstruction extends DOMNode
  25. *
  26. * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1004215813
  27. * Since:
  28. */
  29. /* {{{ */
  30. PHP_METHOD(DOMProcessingInstruction, __construct)
  31. {
  32. xmlNodePtr nodep = NULL, oldnode = NULL;
  33. dom_object *intern;
  34. char *name, *value = NULL;
  35. size_t name_len, value_len;
  36. int name_valid;
  37. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
  38. RETURN_THROWS();
  39. }
  40. name_valid = xmlValidateName((xmlChar *) name, 0);
  41. if (name_valid != 0) {
  42. php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
  43. RETURN_THROWS();
  44. }
  45. nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
  46. if (!nodep) {
  47. php_dom_throw_error(INVALID_STATE_ERR, 1);
  48. RETURN_THROWS();
  49. }
  50. intern = Z_DOMOBJ_P(ZEND_THIS);
  51. oldnode = dom_object_get_node(intern);
  52. if (oldnode != NULL) {
  53. php_libxml_node_free_resource(oldnode );
  54. }
  55. php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
  56. }
  57. /* }}} end DOMProcessingInstruction::__construct */
  58. /* {{{ target string
  59. readonly=yes
  60. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1478689192
  61. Since:
  62. */
  63. int dom_processinginstruction_target_read(dom_object *obj, zval *retval)
  64. {
  65. xmlNodePtr nodep = dom_object_get_node(obj);
  66. if (nodep == NULL) {
  67. php_dom_throw_error(INVALID_STATE_ERR, 1);
  68. return FAILURE;
  69. }
  70. ZVAL_STRING(retval, (char *) (nodep->name));
  71. return SUCCESS;
  72. }
  73. /* }}} */
  74. /* {{{ data string
  75. readonly=no
  76. URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-837822393
  77. Since:
  78. */
  79. int dom_processinginstruction_data_read(dom_object *obj, zval *retval)
  80. {
  81. xmlNodePtr nodep;
  82. xmlChar *content;
  83. nodep = dom_object_get_node(obj);
  84. if (nodep == NULL) {
  85. php_dom_throw_error(INVALID_STATE_ERR, 1);
  86. return FAILURE;
  87. }
  88. if ((content = xmlNodeGetContent(nodep)) != NULL) {
  89. ZVAL_STRING(retval, (char *) content);
  90. xmlFree(content);
  91. } else {
  92. ZVAL_EMPTY_STRING(retval);
  93. }
  94. return SUCCESS;
  95. }
  96. int dom_processinginstruction_data_write(dom_object *obj, zval *newval)
  97. {
  98. xmlNode *nodep = dom_object_get_node(obj);
  99. zend_string *str;
  100. if (nodep == NULL) {
  101. php_dom_throw_error(INVALID_STATE_ERR, 1);
  102. return FAILURE;
  103. }
  104. str = zval_try_get_string(newval);
  105. if (UNEXPECTED(!str)) {
  106. return FAILURE;
  107. }
  108. xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
  109. zend_string_release_ex(str, 0);
  110. return SUCCESS;
  111. }
  112. /* }}} */
  113. #endif