PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/dom - domimplementation.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 60 100 60.0 %
Date: 2019-05-06 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 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_implementation_get_feature, 0, 0, 2)
      30             :         ZEND_ARG_INFO(0, feature)
      31             :         ZEND_ARG_INFO(0, version)
      32             : ZEND_END_ARG_INFO();
      33             : 
      34             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_has_feature, 0, 0, 0)
      35             : ZEND_END_ARG_INFO();
      36             : 
      37             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_create_documenttype, 0, 0, 3)
      38             :         ZEND_ARG_INFO(0, qualifiedName)
      39             :         ZEND_ARG_INFO(0, publicId)
      40             :         ZEND_ARG_INFO(0, systemId)
      41             : ZEND_END_ARG_INFO();
      42             : 
      43             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_create_document, 0, 0, 3)
      44             :         ZEND_ARG_INFO(0, namespaceURI)
      45             :         ZEND_ARG_INFO(0, qualifiedName)
      46             :         ZEND_ARG_OBJ_INFO(0, docType, DOMDocumentType, 0)
      47             : ZEND_END_ARG_INFO();
      48             : /* }}} */
      49             : 
      50             : /*
      51             : * class DOMImplementation
      52             : *
      53             : * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-102161490
      54             : * Since:
      55             : */
      56             : 
      57             : const zend_function_entry php_dom_domimplementation_class_functions[] = {
      58             :         PHP_ME(domimplementation, getFeature, arginfo_dom_implementation_get_feature, ZEND_ACC_PUBLIC)
      59             :         PHP_ME(domimplementation, hasFeature, arginfo_dom_implementation_has_feature, ZEND_ACC_PUBLIC)
      60             :         PHP_ME(domimplementation, createDocumentType, arginfo_dom_implementation_create_documenttype, ZEND_ACC_PUBLIC)
      61             :         PHP_ME(domimplementation, createDocument, arginfo_dom_implementation_create_document, ZEND_ACC_PUBLIC)
      62             :         PHP_FE_END
      63             : };
      64             : 
      65             : /* {{{ proto bool dom_domimplementation_has_feature(string feature, string version);
      66             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-5CED94D7
      67             : Since:
      68             : */
      69           2 : PHP_METHOD(domimplementation, hasFeature)
      70             : {
      71             :         size_t feature_len, version_len;
      72             :         char *feature, *version;
      73             : 
      74           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &feature, &feature_len, &version, &version_len) == FAILURE) {
      75           0 :                 return;
      76             :         }
      77             : 
      78           2 :         if (dom_has_feature(feature, version)) {
      79           2 :                 RETURN_TRUE;
      80             :         } else {
      81           0 :                 RETURN_FALSE;
      82             :         }
      83             : }
      84             : /* }}} end dom_domimplementation_has_feature */
      85             : 
      86             : /* {{{ proto DOMDocumentType dom_domimplementation_create_document_type(string qualifiedName, string publicId, string systemId);
      87             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocType
      88             : Since: DOM Level 2
      89             : */
      90           1 : PHP_METHOD(domimplementation, createDocumentType)
      91             : {
      92             :         xmlDtd *doctype;
      93             :         int ret;
      94           1 :         size_t name_len = 0, publicid_len = 0, systemid_len = 0;
      95           1 :         char *name = NULL, *publicid = NULL, *systemid = NULL;
      96           1 :         xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
      97             :         xmlURIPtr uri;
      98             : 
      99           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
     100           0 :                 return;
     101             :         }
     102             : 
     103           1 :         if (name_len == 0) {
     104           0 :                 php_error_docref(NULL, E_WARNING, "qualifiedName is required");
     105           0 :                 RETURN_FALSE;
     106             :         }
     107             : 
     108           1 :         if (publicid_len > 0) {
     109           1 :                 pch1 = (xmlChar *) publicid;
     110             :         }
     111           1 :         if (systemid_len > 0) {
     112           1 :                 pch2 = (xmlChar *) systemid;
     113             :         }
     114             : 
     115           1 :         uri = xmlParseURI(name);
     116           1 :         if (uri != NULL && uri->opaque != NULL) {
     117           0 :                 localname = xmlStrdup((xmlChar *) uri->opaque);
     118           0 :                 if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
     119           0 :                         php_dom_throw_error(NAMESPACE_ERR, 1);
     120           0 :                         xmlFreeURI(uri);
     121           0 :                         xmlFree(localname);
     122           0 :                         RETURN_FALSE;
     123             :                 }
     124             :         } else {
     125           1 :                 localname = xmlStrdup((xmlChar *) name);
     126             :         }
     127             : 
     128             :         /* TODO: Test that localname has no invalid chars
     129             :         php_dom_throw_error(INVALID_CHARACTER_ERR,);
     130             :         */
     131             : 
     132           1 :         if (uri) {
     133           1 :                 xmlFreeURI(uri);
     134             :         }
     135             : 
     136           1 :         doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
     137           1 :         xmlFree(localname);
     138             : 
     139           1 :         if (doctype == NULL) {
     140           0 :                 php_error_docref(NULL, E_WARNING, "Unable to create DocumentType");
     141           0 :                 RETURN_FALSE;
     142             :         }
     143             : 
     144           1 :         DOM_RET_OBJ((xmlNodePtr) doctype, &ret, NULL);
     145             : }
     146             : /* }}} end dom_domimplementation_create_document_type */
     147             : 
     148             : /* {{{ proto DOMDocument dom_domimplementation_create_document(string namespaceURI, string qualifiedName, DOMDocumentType doctype);
     149             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#Level-2-Core-DOM-createDocument
     150             : Since: DOM Level 2
     151             : */
     152           2 : PHP_METHOD(domimplementation, createDocument)
     153             : {
     154           2 :         zval *node = NULL;
     155             :         xmlDoc *docp;
     156             :         xmlNode *nodep;
     157           2 :         xmlDtdPtr doctype = NULL;
     158           2 :         xmlNsPtr nsptr = NULL;
     159           2 :         int ret, errorcode = 0;
     160           2 :         size_t uri_len = 0, name_len = 0;
     161           2 :         char *uri = NULL, *name = NULL;
     162           2 :         char *prefix = NULL, *localname = NULL;
     163             :         dom_object *doctobj;
     164             : 
     165           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssO", &uri, &uri_len, &name, &name_len, &node, dom_documenttype_class_entry) == FAILURE) {
     166           0 :                 return;
     167             :         }
     168             : 
     169           2 :         if (node != NULL) {
     170           1 :                 DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
     171           1 :                 if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
     172           0 :                         php_error_docref(NULL, E_WARNING, "Invalid DocumentType object");
     173           0 :                         RETURN_FALSE;
     174             :                 }
     175           1 :                 if (doctype->doc != NULL) {
     176           0 :                         php_dom_throw_error(WRONG_DOCUMENT_ERR, 1);
     177           0 :                         RETURN_FALSE;
     178             :                 }
     179             :         } else {
     180           1 :                 doctobj = NULL;
     181             :         }
     182             : 
     183           2 :         if (name_len > 0) {
     184           2 :                 errorcode = dom_check_qname(name, &localname, &prefix, 1, name_len);
     185           2 :                 if (errorcode == 0 && uri_len > 0
     186           0 :                         && ((nsptr = xmlNewNs(NULL, (xmlChar *) uri, (xmlChar *) prefix)) == NULL)
     187             :                 ) {
     188           0 :                         errorcode = NAMESPACE_ERR;
     189             :                 }
     190             :         }
     191             : 
     192           2 :         if (prefix != NULL) {
     193           0 :                 xmlFree(prefix);
     194             :         }
     195             : 
     196           2 :         if (errorcode != 0) {
     197           0 :                 if (localname != NULL) {
     198           0 :                         xmlFree(localname);
     199             :                 }
     200           0 :                 php_dom_throw_error(errorcode, 1);
     201           0 :                 RETURN_FALSE;
     202             :         }
     203             : 
     204             :         /* currently letting libxml2 set the version string */
     205           2 :         docp = xmlNewDoc(NULL);
     206           2 :         if (!docp) {
     207           0 :                 if (localname != NULL) {
     208           0 :                         xmlFree(localname);
     209             :                 }
     210           0 :                 RETURN_FALSE;
     211             :         }
     212             : 
     213           2 :         if (doctype != NULL) {
     214           1 :                 docp->intSubset = doctype;
     215           1 :                 doctype->parent = docp;
     216           1 :                 doctype->doc = docp;
     217           1 :                 docp->children = (xmlNodePtr) doctype;
     218           1 :                 docp->last = (xmlNodePtr) doctype;
     219             :         }
     220             : 
     221           2 :         if (localname != NULL) {
     222           2 :                 nodep = xmlNewDocNode(docp, nsptr, (xmlChar *) localname, NULL);
     223           2 :                 if (!nodep) {
     224           0 :                         if (doctype != NULL) {
     225           0 :                                 docp->intSubset = NULL;
     226           0 :                                 doctype->parent = NULL;
     227           0 :                                 doctype->doc = NULL;
     228           0 :                                 docp->children = NULL;
     229           0 :                                 docp->last = NULL;
     230             :                         }
     231           0 :                         xmlFreeDoc(docp);
     232           0 :                         xmlFree(localname);
     233             :                         /* Need some type of error here */
     234           0 :                         php_error_docref(NULL, E_WARNING, "Unexpected Error");
     235           0 :                         RETURN_FALSE;
     236             :                 }
     237             : 
     238           2 :                 nodep->nsDef = nsptr;
     239             : 
     240           2 :                 xmlDocSetRootElement(docp, nodep);
     241           2 :                 xmlFree(localname);
     242             :         }
     243             : 
     244           2 :         DOM_RET_OBJ((xmlNodePtr) docp, &ret, NULL);
     245             : 
     246           2 :         if (doctobj != NULL) {
     247           1 :                 doctobj->document = ((dom_object *)((php_libxml_node_ptr *)docp->_private)->_private)->document;
     248           1 :                 php_libxml_increment_doc_ref((php_libxml_node_object *)doctobj, docp);
     249             :         }
     250             : }
     251             : /* }}} end dom_domimplementation_create_document */
     252             : 
     253             : /* {{{ proto DOMNode dom_domimplementation_get_feature(string feature, string version);
     254             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#DOMImplementation3-getFeature
     255             : Since: DOM Level 3
     256             : */
     257           0 : PHP_METHOD(domimplementation, getFeature)
     258             : {
     259           0 :  DOM_NOT_IMPLEMENTED();
     260             : }
     261             : /* }}} end dom_domimplementation_get_feature */
     262             : 
     263             : #endif

Generated by: LCOV version 1.10

Generated at Mon, 06 May 2019 17:58:13 +0000 (998 days ago)

Copyright © 2005-2022 The PHP Group
All rights reserved.