Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4675 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44737 invoked by uid 1010); 4 Oct 2003 21:12:21 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 44712 invoked from network); 4 Oct 2003 21:12:21 -0000 Received: from unknown (HELO nycsmtp3out.rdc-nyc.rr.com) (24.29.99.224) by pb1.pair.com with SMTP; 4 Oct 2003 21:12:21 -0000 Received: from trachtenberg.com (66-108-187-246.nyc.rr.com [66.108.187.246]) by nycsmtp3out.rdc-nyc.rr.com (8.12.10/Road Runner SMTP Server 1.0) with ESMTP id h94LCKgt008875 for ; Sat, 4 Oct 2003 17:12:20 -0400 (EDT) Date: Sat, 4 Oct 2003 17:12:19 -0400 Mime-Version: 1.0 (Apple Message framework v552) Content-Type: multipart/mixed; boundary=Apple-Mail-5--1052089927 To: internals@lists.php.net Message-ID: <706356A2-F6AF-11D7-9942-003065FB1208@trachtenberg.com> X-Mailer: Apple Mail (2.552) Subject: SimpleXML schema validate patch From: adam@trachtenberg.com (Adam Trachtenberg) --Apple-Mail-5--1052089927 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Here is a patch against the latest CVS for SimpleXML to fix its schema validation support. It does the following: 1) Includes all the correct libxml2 schema header files. 2) Determines whether schema support is available. 3) Avoids refreeing the parser. 4) Inverts valid / invalid logic to work correctly. Please apply. -adam PS: Let me know if I generated the patch incorrectly. -- adam trachtenberg adam@trachtenberg.com --Apple-Mail-5--1052089927 Content-Disposition: attachment; filename=simplexml_schema_patch.txt Content-Transfer-Encoding: 7bit Content-Type: text/plain; x-unix-mode=0644; x-mac-type=54455854; name="simplexml_schema_patch.txt" Index: php_simplexml.h =================================================================== RCS file: /repository/php-src/ext/simplexml/php_simplexml.h,v retrieving revision 1.6 diff -u -u -r1.6 php_simplexml.h --- php_simplexml.h 14 Jun 2003 18:15:50 -0000 1.6 +++ php_simplexml.h 4 Oct 2003 21:01:10 -0000 @@ -44,6 +44,7 @@ #include #include #include +#include PHP_MINIT_FUNCTION(simplexml); PHP_MSHUTDOWN_FUNCTION(simplexml); Index: simplexml.c =================================================================== RCS file: /repository/php-src/ext/simplexml/simplexml.c,v retrieving revision 1.60 diff -u -u -r1.60 simplexml.c --- simplexml.c 2 Oct 2003 19:45:05 -0000 1.60 +++ simplexml.c 4 Oct 2003 21:01:10 -0000 @@ -573,7 +573,7 @@ #define SCHEMA_BLOB 1 #define SCHEMA_OBJECT 2 -#ifdef xmlSchemaParserCtxtPtr +#ifdef LIBXML_SCHEMAS_ENABLED /* {{{ simplexml_ce_schema_validate_file() */ @@ -585,7 +585,7 @@ xmlSchemaParserCtxtPtr parser; xmlSchemaPtr sptr; xmlSchemaValidCtxtPtr vptr; - int is_valid; + int is_invalid; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) { return; @@ -598,26 +598,24 @@ convert_to_string_ex(&source); parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source)); sptr = xmlSchemaParse(parser); - xmlSchemaFreeParserCtxt(parser); break; case SCHEMA_BLOB: convert_to_string_ex(&source); parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source)); sptr = xmlSchemaParse(parser); - xmlSchemaFreeParserCtxt(parser); break; } vptr = xmlSchemaNewValidCtxt(sptr); - is_valid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr); + is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr); xmlSchemaFree(sptr); xmlSchemaFreeValidCtxt(vptr); xmlSchemaFreeParserCtxt(parser); - if (is_valid) { - RETURN_TRUE; - } else { + if (is_invalid) { RETURN_FALSE; + } else { + RETURN_TRUE; } } /* }}} */ @@ -695,7 +693,7 @@ { if (!strcmp(method, "xsearch")) { simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU); -#ifdef xmlSchemaParserCtxtPtr +#ifdef LIBXML_SCHEMAS_ENABLED } else if (!strcmp(method, "validate_schema_file")) { simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE); } else if (!strcmp(method, "validate_schema_buffer")) { --Apple-Mail-5--1052089927--