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: 61 100 61.0 %
Date: 2014-10-14 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:39 +0000 (7 days ago)

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