123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "php.h"
- #if HAVE_LIBXML && HAVE_DOM
- #include "php_dom.h"
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_get_feature, 0, 0, 2)
- ZEND_ARG_INFO(0, feature)
- ZEND_ARG_INFO(0, version)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_has_feature, 0, 0, 0)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_create_documenttype, 0, 0, 3)
- ZEND_ARG_INFO(0, qualifiedName)
- ZEND_ARG_INFO(0, publicId)
- ZEND_ARG_INFO(0, systemId)
- ZEND_END_ARG_INFO();
- ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_implementation_create_document, 0, 0, 3)
- ZEND_ARG_INFO(0, namespaceURI)
- ZEND_ARG_INFO(0, qualifiedName)
- ZEND_ARG_OBJ_INFO(0, docType, DOMDocumentType, 0)
- ZEND_END_ARG_INFO();
- const zend_function_entry php_dom_domimplementation_class_functions[] = {
- PHP_ME(domimplementation, getFeature, arginfo_dom_implementation_get_feature, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_ME(domimplementation, hasFeature, arginfo_dom_implementation_has_feature, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_ME(domimplementation, createDocumentType, arginfo_dom_implementation_create_documenttype, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_ME(domimplementation, createDocument, arginfo_dom_implementation_create_document, ZEND_ACC_PUBLIC|ZEND_ACC_ALLOW_STATIC)
- PHP_FE_END
- };
- PHP_METHOD(domimplementation, hasFeature)
- {
- int feature_len, version_len;
- char *feature, *version;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &feature, &feature_len, &version, &version_len) == FAILURE) {
- return;
- }
- if (dom_has_feature(feature, version)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
- PHP_METHOD(domimplementation, createDocumentType)
- {
- xmlDtd *doctype;
- int ret, name_len = 0, publicid_len = 0, systemid_len = 0;
- char *name = NULL, *publicid = NULL, *systemid = NULL;
- xmlChar *pch1 = NULL, *pch2 = NULL, *localname = NULL;
- xmlURIPtr uri;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &name, &name_len, &publicid, &publicid_len, &systemid, &systemid_len) == FAILURE) {
- return;
- }
- if (name_len == 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "qualifiedName is required");
- RETURN_FALSE;
- }
- if (publicid_len > 0)
- pch1 = publicid;
- if (systemid_len > 0)
- pch2 = systemid;
- uri = xmlParseURI(name);
- if (uri != NULL && uri->opaque != NULL) {
- localname = xmlStrdup(uri->opaque);
- if (xmlStrchr(localname, (xmlChar) ':') != NULL) {
- php_dom_throw_error(NAMESPACE_ERR, 1 TSRMLS_CC);
- xmlFreeURI(uri);
- xmlFree(localname);
- RETURN_FALSE;
- }
- } else {
- localname = xmlStrdup(name);
- }
-
- if (uri) {
- xmlFreeURI(uri);
- }
- doctype = xmlCreateIntSubset(NULL, localname, pch1, pch2);
- xmlFree(localname);
- if (doctype == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create DocumentType");
- RETURN_FALSE;
- }
- DOM_RET_OBJ((xmlNodePtr) doctype, &ret, NULL);
- }
- PHP_METHOD(domimplementation, createDocument)
- {
- zval *node = NULL;
- xmlDoc *docp;
- xmlNode *nodep;
- xmlDtdPtr doctype = NULL;
- xmlNsPtr nsptr = NULL;
- int ret, uri_len = 0, name_len = 0, errorcode = 0;
- char *uri = NULL, *name = NULL;
- char *prefix = NULL, *localname = NULL;
- dom_object *doctobj;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssO", &uri, &uri_len, &name, &name_len, &node, dom_documenttype_class_entry) == FAILURE) {
- return;
- }
- if (node != NULL) {
- DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
- if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid DocumentType object");
- RETURN_FALSE;
- }
- if (doctype->doc != NULL) {
- php_dom_throw_error(WRONG_DOCUMENT_ERR, 1 TSRMLS_CC);
- RETURN_FALSE;
- }
- } else {
- doctobj = NULL;
- }
- if (name_len > 0) {
- errorcode = dom_check_qname(name, &localname, &prefix, 1, name_len);
- if (errorcode == 0 && uri_len > 0 && ((nsptr = xmlNewNs(NULL, uri, prefix)) == NULL)) {
- errorcode = NAMESPACE_ERR;
- }
- }
- if (prefix != NULL) {
- xmlFree(prefix);
- }
- if (errorcode != 0) {
- if (localname != NULL) {
- xmlFree(localname);
- }
- php_dom_throw_error(errorcode, 1 TSRMLS_CC);
- RETURN_FALSE;
- }
-
- docp = xmlNewDoc(NULL);
- if (!docp) {
- if (localname != NULL) {
- xmlFree(localname);
- }
- RETURN_FALSE;
- }
- if (doctype != NULL) {
- docp->intSubset = doctype;
- doctype->parent = docp;
- doctype->doc = docp;
- docp->children = (xmlNodePtr) doctype;
- docp->last = (xmlNodePtr) doctype;
- }
- if (localname != NULL) {
- nodep = xmlNewDocNode (docp, nsptr, localname, NULL);
- if (!nodep) {
- if (doctype != NULL) {
- docp->intSubset = NULL;
- doctype->parent = NULL;
- doctype->doc = NULL;
- docp->children = NULL;
- docp->last = NULL;
- }
- xmlFreeDoc(docp);
- xmlFree(localname);
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected Error");
- RETURN_FALSE;
- }
- nodep->nsDef = nsptr;
- xmlDocSetRootElement(docp, nodep);
- xmlFree(localname);
- }
- DOM_RET_OBJ((xmlNodePtr) docp, &ret, NULL);
- if (doctobj != NULL) {
- doctobj->document = ((dom_object *)((php_libxml_node_ptr *)docp->_private)->_private)->document;
- php_libxml_increment_doc_ref((php_libxml_node_object *)doctobj, docp TSRMLS_CC);
- }
- }
- PHP_METHOD(domimplementation, getFeature)
- {
- DOM_NOT_IMPLEMENTED();
- }
- #endif
|