diff --git a/NEWS b/NEWS index f12b03661b720..0c97be34dd59d 100644 --- a/NEWS +++ b/NEWS @@ -1750,6 +1750,9 @@ PHP NEWS . Fixed bug #75453 (Incorrect reflection for ibase_[p]connect). (villfa) . Fixed bug #76443 (php+php_interbase.dll crash on module_shutdown). (Kalle) +- SOAP: + . Fixed bug #80672 (Null Dereference in SoapClient). (CVE-2021-21702) (cmb, Stas) + - intl: . Fixed bug #75317 (UConverter::setDestinationEncoding changes source instead diff --git a/NEWS.orig b/NEWS.orig new file mode 100644 index 0000000000000..f12b03661b720 --- /dev/null +++ b/NEWS.orig @@ -0,0 +1,1962 @@ +PHP NEWS +||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +11 Jun 2020, PHP 7.4.7 + +- Core: + . Fixed bug #79599 (coredump in set_error_handler). (Laruence) + . Fixed bug #79566 (Private SHM is not private on Windows). (cmb) + . Fixed bug #79489 (.user.ini does not inherit). (cmb) + . Fixed bug #79600 (Regression in 7.4.6 when yielding an array based + generator). (Nikita) + . Fixed bug #79657 ("yield from" hangs when invalid value encountered). + (Nikita) + +- FFI: + . Fixed bug #79571 (FFI: var_dumping unions may segfault). (cmb) + +- GD: + . Fixed bug #79615 (Wrong GIF header written in GD GIFEncode). (sageptr, cmb) + +- Opcache: + . Fixed bug #79588 (Boolean opcache settings ignore on/off values). (cmb) + . Fixed bug #79548 (Preloading segfault with inherited method using static + variable). (Nikita) + . Fixed bug #79603 (RTD collision with opcache). (Nikita) + +- Standard: + . Fixed bug #79561 (dns_get_record() fails with DNS_ALL). (cmb) + +14 May 2020, PHP 7.4.6 + +- Core: + . Fixed bug #79536 (zend_clear_exception prevent exception's destructor to be + called). (Laruence) + . Fixed bug #78434 (Generator yields no items after valid() call). (Nikita) + . Fixed bug #79477 (casting object into array creates references). (Nikita) + . Fixed bug #79514 (Memory leaks while including unexistent file). (cmb, + Nikita) + +- DOM: + . Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes). + (cmb) + +- EXIF: + . Fixed bug #79336 (ext/exif/tests/bug79046.phpt fails on Big endian arch). + (Nikita) + +- FCGI: + . Fixed bug #79491 (Search for .user.ini extends up to root dir). (cmb) + +- MBString: + . Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported). + (Girgias) + +- OpenSSL: + . Fixed bug #79497 (stream_socket_client() throws an unknown error sometimes + with <1s timeout). (Joe Cai) + +- PCRE: + . Upgraded to PCRE2 10.34. (cmb) + +- Phar: + . Fixed bug #79503 (Memory leak on duplicate metadata). (cmb) + +- SimpleXML: + . Fixed bug #79528 (Different object of the same xml between 7.4.5 and + 7.4.4). (cmb) + +- SPL: + . Fixed bug #69264 (__debugInfo() ignored while extending SPL classes). (cmb) + . Fixed bug #67369 (ArrayObject serialization drops the iterator class). + (Alex Dowad) + +- Standard: + . Fixed bug #79468 (SIGSEGV when closing stream handle with a stream filter + appended). (dinosaur) + . Fixed bug #79447 (Serializing uninitialized typed properties with __sleep + should not throw). (nicolas-grekas) + +16 Apr 2020, PHP 7.4.5 + +- Core: + . Fixed bug #79364 (When copy empty array, next key is unspecified). (cmb) + . Fixed bug #78210 (Invalid pointer address). (cmb, Nikita) + +- CURL: + . Fixed bug #79199 (curl_copy_handle() memory leak). (cmb) + +- Date: + . Fixed bug #79396 (DateTime hour incorrect during DST jump forward). (Nate + Brunette) + . Fixed bug #74940 (DateTimeZone loose comparison always true). (cmb) + +- FPM: + . Implement request #77062 (Allow numeric [UG]ID in FPM listen.{owner,group}) + (Andre Nathan) + +- Iconv: + . Fixed bug #79200 (Some iconv functions cut Windows-1258). (cmb) + +- OPcache: + . Fixed bug #79412 (Opcache chokes and uses 100% CPU on specific script). + (Dmitry) + +- Session: + . Fixed bug #79413 (session_create_id() fails for active sessions). (cmb) + +- Shmop: + . Fixed bug #79427 (Integer Overflow in shmop_open()). (cmb) + +- SimpleXML: + . Fixed bug #61597 (SXE properties may lack attributes and content). (cmb) + +- SOAP: + . Fixed bug #79357 (SOAP request segfaults when any request parameter is + missing). (Nikita) + +- Spl: + . Fixed bug #75673 (SplStack::unserialize() behavior). (cmb) + . Fixed bug #79393 (Null coalescing operator failing with SplFixedArray). + (cmb) + +- Standard: + . Fixed bug #79330 (shell_exec() silently truncates after a null byte). (stas) + . Fixed bug #79465 (OOB Read in urldecode()). (CVE-2020-7067) (stas) + . Fixed bug #79410 (system() swallows last chunk if it is exactly 4095 bytes + without newline). (Christian Schneider) + +- Zip: + . Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi) + . Fixed bug #79424 (php_zip_glob uses gl_pathc after call to globfree). + (Max Rees) + +19 Mar 2020, PHP 7.4.4 + +- Core: + . Fixed bug #79244 (php crashes during parsing INI file). (Laruence) + . Fixed bug #63206 (restore_error_handler does not restore previous errors + mask). (Mark Plomer) + +- COM: + . Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location). + (cmb) + . Fixed bug #79242 (COM error constants don't match com_exception codes on + x86). (cmb) + . Fixed bug #79247 (Garbage collecting variant objects segfaults). (cmb) + . Fixed bug #79248 (Traversing empty VT_ARRAY throws com_exception). (cmb) + . Fixed bug #79299 (com_print_typeinfo prints duplicate variables). (Litiano + Moura) + . Fixed bug #79332 (php_istreams are never freed). (cmb) + . Fixed bug #79333 (com_print_typeinfo() leaks memory). (cmb) + +- CURL: + . Fixed bug #79019 (Copied cURL handles upload empty file). (cmb) + . Fixed bug #79013 (Content-Length missing when posting a curlFile with + curl). (cmb) + +- DOM: + . Fixed bug #77569: (Write Access Violation in DomImplementation). (Nikita, + cmb) + . Fixed bug #79271 (DOMDocumentType::$childNodes is NULL). (cmb) + +- Enchant: + . Fixed bug #79311 (enchant_dict_suggest() fails on big endian architecture). + (cmb) + +- EXIF: + . Fixed bug #79282 (Use-of-uninitialized-value in exif). (CVE-2020-7064) + (Nikita) + +- Fileinfo: + . Fixed bug #79283 (Segfault in libmagic patch contains a buffer + overflow). (cmb) + +- FPM: + . Fixed bug #77653 (operator displayed instead of the real error message). + (Jakub Zelenka) + . Fixed bug #79014 (PHP-FPM & Primary script unknown). (Jakub Zelenka) + +- MBstring: + . Fixed bug #79371 (mb_strtolower (UTF-32LE): stack-buffer-overflow at + php_unicode_tolower_full). (CVE-2020-7065) (cmb) + +- MySQLi: + . Fixed bug #64032 (mysqli reports different client_version). (cmb) + +- MySQLnd: + . Implemented FR #79275 (Support auth_plugin_caching_sha2_password on + Windows). (cmb) + +- Opcache: + . Fixed bug #79252 (preloading causes php-fpm to segfault during exit). + (Nikita) + +- PCRE: + . Fixed bug #79188 (Memory corruption in preg_replace/preg_replace_callback + and unicode). (Nikita) + . Fixed bug #79241 (Segmentation fault on preg_match()). (Nikita) + . Fixed bug #79257 (Duplicate named groups (?J) prefer last alternative even + if not matched). (Nikita) + +- PDO_ODBC: + . Fixed bug #79038 (PDOStatement::nextRowset() leaks column values). (cmb) + +- Reflection: + . Fixed bug #79062 (Property with heredoc default value returns false for + getDocComment). (Nikita) + +- SQLite3: + . Fixed bug #79294 (::columnType() may fail after SQLite3Stmt::reset()). (cmb) + +- Standard: + . Fixed bug #79329 (get_headers() silently truncates after a null byte). + (CVE-2020-7066) (cmb) + . Fixed bug #79254 (getenv() w/o arguments not showing changes). (cmb) + . Fixed bug #79265 (Improper injection of Host header when using fopen for + http requests). (Miguel Xavier Penha Neto) + +- Zip: + . Fixed bug #79315 (ZipArchive::addFile doesn't honor start/length + parameters). (Remi) + +20 Feb 2020, PHP 7.4.3 + +- Core: + . Fixed bug #79146 (cscript can fail to run on some systems). (clarodeus) + . Fixed bug #79155 (Property nullability lost when using multiple property + definition). (Nikita) + . Fixed bug #78323 (Code 0 is returned on invalid options). (Ivan Mikheykin) + . Fixed bug #78989 (Delayed variance check involving trait segfaults). + (Nikita) + . Fixed bug #79174 (cookie values with spaces fail to round-trip). (cmb) + . Fixed bug #76047 (Use-after-free when accessing already destructed + backtrace arguments). (Nikita) + +- CURL: + . Fixed bug #79078 (Hypothetical use-after-free in curl_multi_add_handle()). + (cmb) + +- FFI: + . Fixed bug #79096 (FFI Struct Segfault). (cmb) + +- IMAP: + . Fixed bug #79112 (IMAP extension can't find OpenSSL libraries at configure + time). (Nikita) + +- Intl: + . Fixed bug #79212 (NumberFormatter::format() may detect wrong type). (cmb) + +- Libxml: + . Fixed bug #79191 (Error in SoapClient ctor disables DOMDocument::save()). + (Nikita, cmb) + +- MBString: + . Fixed bug #79149 (SEGV in mb_convert_encoding with non-string encodings). + (cmb) + +- MySQLi: + . Fixed bug #78666 (Properties may emit a warning on var_dump()). (kocsismate) + +- MySQLnd: + . Fixed bug #79084 (mysqlnd may fetch wrong column indexes with MYSQLI_BOTH). + (cmb) + . Fixed bug #79011 (MySQL caching_sha2_password Access denied for password + with more than 20 chars). (Nikita) + +- Opcache: + . Fixed bug #79114 (Eval class during preload causes class to be only half + available). (Laruence) + . Fixed bug #79128 (Preloading segfaults if preload_user is used). (Nikita) + . Fixed bug #79193 (Incorrect type inference for self::$field =& $field). + (Nikita) + +- OpenSSL: + . Fixed bug #79145 (openssl memory leak). (cmb, Nikita) + +- Phar: + . Fixed bug #79082 (Files added to tar with Phar::buildFromIterator have + all-access permissions). (CVE-2020-7063) (stas) + . Fixed bug #79171 (heap-buffer-overflow in phar_extract_file). + (CVE-2020-7061) (cmb) + . Fixed bug #76584 (PharFileInfo::decompress not working). (cmb) + +- Reflection: + . Fixed bug #79115 (ReflectionClass::isCloneable call reflected class + __destruct). (Nikita) + +- Session: + . Fixed bug #79221 (Null Pointer Dereference in PHP Session Upload Progress). + (CVE-2020-7062) (stas) + +- Standard: + . Fixed bug #78902 (Memory leak when using stream_filter_append). (liudaixiao) + . Fixed bug #78969 (PASSWORD_DEFAULT should match PASSWORD_BCRYPT instead of being null). (kocsismate) + +- Testing: + . Fixed bug #78090 (bug45161.phpt takes forever to finish). (cmb) + +- XSL: + . Fixed bug #70078 (XSL callbacks with nodes as parameter leak memory). (cmb) + +- Zip: + . Add ZipArchive::CM_LZMA2 and ZipArchive::CM_XZ constants (since libzip 1.6.0). (Remi) + . Add ZipArchive::RDONLY (since libzip 1.0.0). (Remi) + . Add ZipArchive::ER_* missing constants. (Remi) + . Add ZipArchive::LIBZIP_VERSION constant. (Remi) + . Fixed bug #73119 (Wrong return for ZipArchive::addEmptyDir Method). (Remi) + +23 Jan 2020, PHP 7.4.2 + +- Core: + . Preloading support on Windows has been disabled. (Nikita) + . Fixed bug #79022 (class_exists returns True for classes that are not ready + to be used). (Laruence) + . Fixed bug #78929 (plus signs in cookie values are converted to spaces). + (Alexey Kachalin) + . Fixed bug #78973 (Destructor during CV freeing causes segfault if opline + never saved). (Nikita) + . Fixed bug #78776 (Abstract method implementation from trait does not check + "static"). (Nikita) + . Fixed bug #78999 (Cycle leak when using function result as temporary). + (Dmitry) + . Fixed bug #79008 (General performance regression with PHP 7.4 on Windows). + (cmb) + . Fixed bug #79002 (Serializing uninitialized typed properties with __sleep + makes unserialize throw). (Nikita) + +- CURL: + . Fixed bug #79033 (Curl timeout error with specific url and post). (cmb) + . Fixed bug #79063 (curl openssl does not respect PKG_CONFIG_PATH). (Nikita) + +- Date: + . Fixed bug #79015 (undefined-behavior in php_date.c). (cmb) + +- DBA: + . Fixed bug #78808 ([LMDB] MDB_MAP_FULL: Environment mapsize limit reached). + (cmb) + +- Exif: + . Fixed bug #79046 (NaN to int cast undefined behavior in exif). (Nikita) + +- Fileinfo: + . Fixed bug #74170 (locale information change after mime_content_type). + (Sergei Turchanov) + +- GD: + . Fixed bug #79067 (gdTransformAffineCopy() may use unitialized values). (cmb) + . Fixed bug #79068 (gdTransformAffineCopy() changes interpolation method). + (cmb) + +- Libxml: + . Fixed bug #79029 (Use After Free's in XMLReader / XMLWriter). (Laruence) + +- OPcache: + . Fixed bug #78961 (erroneous optimization of re-assigned $GLOBALS). (Dmitry) + . Fixed bug #78950 (Preloading trait method with static variables). (Nikita) + . Fixed bug #78903 (Conflict in RTD key for closures results in crash). + (Nikita) + . Fixed bug #78986 (Opcache segfaults when inheriting ctor from immutable + into mutable class). (Nikita) + . Fixed bug #79040 (Warning Opcode handlers are unusable due to ASLR). (cmb) + . Fixed bug #79055 (Typed property become unknown with OPcache file cache). + (Nikita) + +- Pcntl: + . Fixed bug #78402 (Converting null to string in error message is bad DX). + (SATŌ Kentarō) + +- PDO_PgSQL: + . Fixed bug #78983 (pdo_pgsql config.w32 cannot find libpq-fe.h). (SATŌ + Kentarō) + . Fixed bug #78980 (pgsqlGetNotify() overlooks dead connection). (SATŌ + Kentarō) + . Fixed bug #78982 (pdo_pgsql returns dead persistent connection). (SATŌ + Kentarō) + +- Session: + . Fixed bug #79031 (Session unserialization problem). (Nikita) + +- Shmop: + . Fixed bug #78538 (shmop memory leak). (cmb) + +- Sqlite3: + . Fixed bug #79056 (sqlite does not respect PKG_CONFIG_PATH during + compilation). (Nikita) + +- Spl: + . Fixed bug #78976 (SplFileObject::fputcsv returns -1 on failure). (cmb) + +- Standard: + . Fixed bug #79000 (Non-blocking socket stream reports EAGAIN as error). + (Nikita) + . Fixed bug #54298 (Using empty additional_headers adding extraneous CRLF). + (cmb) + +18 Dec 2019, PHP 7.4.1 + +- Core: + . Fixed bug #78810 (RW fetches do not throw "uninitialized property" + exception). (Nikita) + . Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value). + (Antony Dovgal, Dmitry) + . Fixed bug #78296 (is_file fails to detect file). (cmb) + . Fixed bug #78883 (fgets(STDIN) fails on Windows). (cmb) + . Fixed bug #78898 (call_user_func(['parent', ...]) fails while other + succeed). (Nikita) + . Fixed bug #78904 (Uninitialized property triggers __get()). (Nikita) + . Fixed bug #78926 (Segmentation fault on Symfony cache:clear). (Nikita) + +- GD: + . Fixed bug #78849 (GD build broken with -D SIGNED_COMPARE_SLOW). (cmb) + . Fixed bug #78923 (Artifacts when convoluting image with transparency). + (wilson chen) + +- FPM: + . Fixed bug #76601 (Partially working php-fpm ater incomplete reload). + (Maksim Nikulin) + . Fixed bug #78889 (php-fpm service fails to start). (Jakub Zelenka) + . Fixed bug #78916 (php-fpm 7.4.0 don't send mail via mail()). + (Jakub Zelenka) + +- Intl: + . Implemented FR #78912 (INTL Support for accounting format). (cmb) + +- Mysqlnd: + . Fixed bug #78823 (ZLIB_LIBS not added to EXTRA_LIBS). (Arjen de Korte) + +- OPcache: + . Fixed $x = (bool)$x; with opcache (should emit undeclared variable notice). + (Tyson Andre) + . Fixed bug #78935 (Preloading removes classes that have dependencies). + (Nikita, Dmitry) + +- PCRE: + . Fixed bug #78853 (preg_match() may return integer > 1). (cmb) + +- Reflection: + . Fixed bug #78895 (Reflection detects abstract non-static class as abstract + static. IS_IMPLICIT_ABSTRACT is not longer used). (Dmitry) + +- Standard: + . Fixed bug #77638 (var_export'ing certain class instances segfaults). (cmb) + . Fixed bug #78840 (imploding $GLOBALS crashes). (cmb) + . Fixed bug #78833 (Integer overflow in pack causes out-of-bound access). + (cmb) + . Fixed bug #78814 (strip_tags allows / in tag name => whitelist bypass). + (cmb) + +28 Nov 2019, PHP 7.4.0 + +- Core: + . Implemented RFC: Deprecate curly brace syntax for accessing array elements + and string offsets. + https://wiki.php.net/rfc/deprecate_curly_braces_array_access (Andrey Gromov) + . Implemented RFC: Deprecations for PHP 7.4. + https://wiki.php.net/rfc/deprecations_php_7_4 (Kalle, Nikita) + . Fixed bug #52752 (Crash when lexing). (Nikita) + . Fixed bug #60677 (CGI doesn't properly validate shebang line contains #!). + (Nikita) + . Fixed bug #71030 (Self-assignment in list() may have inconsistent behavior). + (Nikita) + . Fixed bug #72530 (Use After Free in GC with Certain Destructors). (Nikita) + . Fixed bug #75921 (Inconsistent: No warning in some cases when stdObj is + created on the fly). (David Walker) + . Implemented FR #76148 (Add array_key_exists() to the list of specially + compiled functions). (Majkl578) + . Fixed bug #76430 (__METHOD__ inconsistent outside of method). + (Ryan McCullagh, Nikita) + . Fixed bug #76451 (Aliases during inheritance type checks affected by + opcache). (Nikita) + . Implemented FR #77230 (Support custom CFLAGS and LDFLAGS from environment). + (cmb) + . Fixed bug #77345 (Stack Overflow caused by circular reference in garbage + collection). (Alexandru Patranescu, Nikita, Dmitry) + . Fixed bug #77812 (Interactive mode does not support PHP 7.3-style heredoc). + (cmb, Nikita) + . Fixed bug #77877 (call_user_func() passes $this to static methods). + (Dmitry) + . Fixed bug #78066 (PHP eats the first byte of a program that comes from + process substitution). (Nikita) + . Fixed bug #78151 (Segfault caused by indirect expressions in PHP 7.4a1). + (Nikita) + . Fixed bug #78154 (SEND_VAR_NO_REF does not always send reference). (Nikita) + . Fixed bug #78182 (Segmentation fault during by-reference property + assignment). (Nikita) + . Fixed bug #78212 (Segfault in built-in webserver). (cmb) + . Fixed bug #78220 (Can't access OneDrive folder). (cmb, ab) + . Fixed bug #78226 (Unexpected __set behavior with typed properties). (Nikita) + . Fixed bug #78239 (Deprecation notice during string conversion converted to + exception hangs). (Nikita) + . Fixed bug #78335 (Static properties/variables containing cycles report as + leak). (Nikita) + . Fixed bug #78340 (Include of stream wrapper not reading whole file). + (Nikita) + . Fixed bug #78344 (Segmentation fault on zend_check_protected). (Nikita) + . Fixed bug #78356 (Array returned from ArrayAccess is incorrectly unpacked + as argument). (Nikita) + . Fixed bug #78379 (Cast to object confuses GC, causes crash). (Dmitry) + . Fixed bug #78386 (fstat mode has unexpected value on PHP 7.4). (cmb) + . Fixed bug #78396 (Second file_put_contents in Shutdown hangs script). + (Nikita) + . Fixed bug #78406 (Broken file includes with user-defined stream filters). + (Nikita) + . Fixed bug #78438 (Corruption when __unserializing deeply nested structures). + (cmb, Nikita) + . Fixed bug #78441 (Parse error due to heredoc identifier followed by digit). + (cmb) + . Fixed bug #78454 (Consecutive numeric separators cause OOM error). + (Theodore Brown) + . Fixed bug #78460 (PEAR installation failure). (Peter Kokot, L. Declercq) + . Fixed bug #78531 (Crash when using undefined variable as object). (Dmitry) + . Fixed bug #78535 (auto_detect_line_endings value not parsed as bool). + (bugreportuser) + . Fixed bug #78604 (token_get_all() does not properly tokenize FOOstat modifies $dbc->affected_rows). + (Derick) + . Fixed bug #76809 (SSL settings aren't respected when persistent connections + are used). (fabiomsouto) + . Fixed bug #78179 (MariaDB server version incorrectly detected). (cmb) + . Fixed bug #78213 (Empty row pocket). (cmb) + +- MySQLnd: + . Fixed connect_attr issues and added the _server_host connection attribute. + (Qianqian Bu) + . Fixed bug #60594 (mysqlnd exposes 160 lines of stats in phpinfo). (PeeHaa) + +- ODBC: + . Fixed bug #78473 (odbc_close() closes arbitrary resources). (cmb) + +- Opcache: + . Implemented preloading RFC: https://wiki.php.net/rfc/preload. (Dmitry) + . Add opcache.preload_user INI directive. (Dmitry) + . Added new INI directive opcache.cache_id (Windows only). (cmb) + . Fixed bug #78106 (Path resolution fails if opcache disabled during request). + (Nikita) + . Fixed bug #78175 (Preloading segfaults at preload time and at runtime). + (Dmitry) + . Fixed bug #78202 (Opcache stats for cache hits are capped at 32bit NUM). + (cmb) + . Fixed bug #78271 (Invalid result of if-else). (Nikita) + . Fixed bug #78341 (Failure to detect smart branch in DFA pass). (Nikita) + . Fixed bug #78376 (Incorrect preloading of constant static properties). + (Dmitry) + . Fixed bug #78429 (opcache_compile_file(__FILE__); segfaults). (cmb) + . Fixed bug #78512 (Cannot make preload work). (Dmitry) + . Fixed bug #78514 (Preloading segfaults with inherited typed property). + (Nikita) + . Fixed bug #78654 (Incorrectly computed opcache checksum on files with + non-ascii characters). (mhagstrand) + +- OpenSSL: + . Added TLS 1.3 support to streams including new tlsv1.3 stream. + (Codarren Velvindron, Jakub Zelenka) + . Added openssl_x509_verify function. (Ben Scholzen) + . openssl_random_pseudo_bytes() now throws in error conditions. + (Sammy Kaye Powers) + . Changed the default config path (Windows only). (cmb) + . Fixed bug #78231 (Segmentation fault upon stream_socket_accept of exported + socket-to-stream). (Nikita) + . Fixed bug #78391 (Assertion failure in openssl_random_pseudo_bytes). + (Nikita) + . Fixed bug #78775 (TLS issues from HTTP request affecting other encrypted + connections). (Nikita) + +- Pcntl: + . Fixed bug #77335 (PHP is preventing SIGALRM from specifying SA_RESTART). + (Nikita) + +- PCRE: + . Implemented FR #77094 (Support flags in preg_replace_callback). (Nikita) + . Fixed bug #72685 (Repeated UTF-8 validation of same string in UTF-8 mode). + (Nikita) + . Fixed bug #73948 (Preg_match_all should return NULLs on trailing optional + capture groups). + . Fixed bug #78338 (Array cross-border reading in PCRE). (cmb) + . Fixed bug #78349 (Bundled pcre2 library missing LICENCE file). (Peter Kokot) + +- PDO: + . Implemented FR #71885 (Allow escaping question mark placeholders). + https://wiki.php.net/rfc/pdo_escape_placeholders (Matteo) + . Fixed bug #77849 (Disable cloning of PDO handle/connection objects). + (camporter) + . Implemented FR #78033 (PDO - support username & password specified in + DSN). (sjon) + +- PDO_Firebird: + . Implemented FR #65690 (PDO_Firebird should also support dialect 1). + (Simonov Denis) + . Implemented FR #77863 (PDO firebird support type Boolean in input + parameters). (Simonov Denis) + +- PDO_MySQL: + . Fixed bug #41997 (SP call yields additional empty result set). (cmb) + . Fixed bug #78623 (Regression caused by "SP call yields additional empty + result set"). (cmb) + +- PDO_OCI: + . Support Oracle Database tracing attributes ACTION, MODULE, + CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter) + . Implemented FR #76908 (PDO_OCI getColumnMeta() not implemented). + (Valentin Collet, Chris Jones, Remi) + +- PDO_SQLite: + . Implemented sqlite_stmt_readonly in PDO_SQLite. (BohwaZ) + . Raised requirements to SQLite 3.5.0. (cmb) + . Fixed bug #78192 (SegFault when reuse statement after schema has changed). + (Vincent Quatrevieux) + . Fixed bug #78348 (Remove -lrt from pdo_sqlite.so). (Peter Kokot) + +- Phar: + . Fixed bug #77919 (Potential UAF in Phar RSHUTDOWN). (cmb) + +- phpdbg: + . Fixed bug #76596 (phpdbg support for display_errors=stderr). (kabel) + . Fixed bug #76801 (too many open files). (alekitto) + . Fixed bug #77800 (phpdbg segfaults on listing some conditional breakpoints). + (krakjoe) + . Fixed bug #77805 (phpdbg build fails when readline is shared). (krakjoe) + +- Recode: + . Unbundled the recode extension. (cmb) + +- Reflection: + . Fixed bug #76737 (Unserialized reflection objects are broken, they + shouldn't be serializable). (Nikita) + . Fixed bug #78263 (\ReflectionReference::fromArrayElement() returns null + while item is a reference). (Nikita) + . Fixed bug #78410 (Cannot "manually" unserialize class that is final and + extends an internal one). (Nikita) + . Fixed bug #78697 (ReflectionClass::implementsInterface - inaccurate error + message with traits). (villfa) + . Fixed bug #78774 (ReflectionNamedType on Typed Properties Crash). (Nikita) + +- Session: + . Fixed bug #78624 (session_gc return value for user defined session + handlers). (bshaffer) + +- SimpleXML: + . Implemented FR #65215 (SimpleXMLElement could register as implementing + Countable). (LeSuisse) + . Fixed bug #75245 (Don't set content of elements with only whitespaces). + (eriklundin) + +- Sockets: + . Fixed bug #67619 (Validate length on socket_write). (thiagooak) + . Fixed bug #78665 (Multicasting may leak memory). (cmb) + +- sodium: + . Fixed bug #77646 (sign_detached() strings not terminated). (Frank) + . Fixed bug #78510 (Partially uninitialized buffer returned by + sodium_crypto_generichash_init()). (Frank Denis, cmb) + . Fixed bug #78516 (password_hash(): Memory cost is not in allowed range). + (cmb, Nikita) + +- SPL: + . Fixed bug #77518 (SeekableIterator::seek() should accept 'int' typehint as + documented). (Nikita) + . Fixed bug #78409 (Segfault when creating instance of ArrayIterator without + constructor). (Nikita) + . Fixed bug #78436 (Missing addref in SplPriorityQueue EXTR_BOTH mode). + (Nikita) + . Fixed bug #78456 (Segfault when serializing SplDoublyLinkedList). (Nikita) + +- SQLite3: + . Unbundled libsqlite. (cmb) + . Raised requirements to SQLite 3.7.4. (cmb) + . Forbid (un)serialization of SQLite3, SQLite3Stmt and SQLite3Result. (cmb) + . Added support for the SQLite @name notation. (cmb, BohwaZ) + . Added SQLite3Stmt::getSQL() to retrieve the SQL of the statement. (Bohwaz) + . Implement FR ##70950 (Make SQLite3 Online Backup API available). (BohwaZ) + +- Standard: + . Implemented password hashing registry RFC: + https://wiki.php.net/rfc/password_registry. (Sara) + . Implemented RFC where password_hash() has argon2i(d) implementations from + ext/sodium when PHP is built without libargon: + https://wiki.php.net/rfc/sodium.argon.hash (Sara) + . Implemented FR #38301 (field enclosure behavior in fputcsv). (cmb) + . Implemented FR #51496 (fgetcsv should take empty string as an escape). (cmb) + . Fixed bug #73535 (php_sockop_write() returns 0 on error, can be used to + trigger Denial of Service). (Nikita) + . Fixed bug #74764 (Bindto IPv6 works with file_get_contents but fails with + stream_socket_client). (Ville Hukkamäki) + . Fixed bug #76859 (stream_get_line skips data if used with data-generating + filter). (kkopachev) + . Implemented FR #77377 (No way to handle CTRL+C in Windows). (Anatol) + . Fixed bug #77930 (stream_copy_to_stream should use mmap more often). + (Nikita) + . Implemented FR #78177 (Make proc_open accept command array). (Nikita) + . Fixed bug #78208 (password_needs_rehash() with an unknown algo should always + return true). (Sara) + . Fixed bug #78241 (touch() does not handle dates after 2038 in PHP 64-bit). (cmb) + . Fixed bug #78282 (atime and mtime mismatch). (cmb) + . Fixed bug #78326 (improper memory deallocation on stream_get_contents() + with fixed length buffer). (Albert Casademont) + . Fixed bug #78346 (strip_tags no longer handling nested php tags). (cmb) + . Fixed bug #78506 (Error in a php_user_filter::filter() is not reported). + (Nikita) + . Fixed bug #78549 (Stack overflow due to nested serialized input). (Nikita) + . Fixed bug #78759 (array_search in $GLOBALS). (Nikita) + +- Testing: + . Fixed bug #78684 (PCRE bug72463_2 test is sending emails on Linux). (cmb) + +- Tidy: + . Added TIDY_TAG_* constants for HTML5 elements. (cmb) + . Fixed bug #76736 (wrong reflection for tidy_get_head, tidy_get_html, + tidy_get_root, and tidy_getopt) (tandre) + +- WDDX: + . Deprecated and unbundled the WDDX extension. (cmb) + +- Zip: + . Fixed bug #78641 (addGlob can modify given remove_path value). (cmb) + +21 Nov 2019, PHP 7.3.12 + +- Core: + . Fixed bug #78658 (Memory corruption using Closure::bindTo). (Nikita) + . Fixed bug #78656 (Parse errors classified as highest log-level). (Erik + Lundin) + . Fixed bug #78752 (Segfault if GC triggered while generator stack frame is + being destroyed). (Nikita) + . Fixed bug #78689 (Closure::fromCallable() doesn't handle + [Closure, '__invoke']). (Nikita) + +- COM: + . Fixed bug #78694 (Appending to a variant array causes segfault). (cmb) + +- Date: + . Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin) + . Fixed bug #78751 (Serialising DatePeriod converts DateTimeImmutable). (cmb) + +- Iconv: + . Fixed bug #78642 (Wrong libiconv version displayed). (gedas at martynas, + cmb). + +- OpCache: + . Fixed bug #78654 (Incorrectly computed opcache checksum on files with + non-ascii characters). (mhagstrand) + . Fixed bug #78747 (OpCache corrupts custom extension result). (Nikita) + +- OpenSSL: + . Fixed bug #78775 (TLS issues from HTTP request affecting other encrypted + connections). (Nikita) + +- Reflection: + . Fixed bug #78697 (ReflectionClass::ImplementsInterface - inaccurate error + message with traits). (villfa) + +- Sockets: + . Fixed bug #78665 (Multicasting may leak memory). (cmb) + +24 Oct 2019, PHP 7.3.11 + +- Core: + . Fixed bug #78535 (auto_detect_line_endings value not parsed as bool). + (bugreportuser) + . Fixed bug #78620 (Out of memory error). (cmb, Nikita) + +- Exif : + . Fixed bug #78442 ('Illegal component' on exif_read_data since PHP7) + (Kalle) + +- FPM: + . Fixed bug #78599 (env_path_info underflow in fpm_main.c can lead to RCE). + (CVE-2019-11043) (Jakub Zelenka) + . Fixed bug #78413 (request_terminate_timeout does not take effect after + fastcgi_finish_request). (Sergei Turchanov) + +- MBString: + . Fixed bug #78633 (Heap buffer overflow (read) in mb_eregi). (cmb) + . Fixed bug #78579 (mb_decode_numericentity: args number inconsistency). + (cmb) + . Fixed bug #78609 (mb_check_encoding() no longer supports stringable + objects). (cmb) + +- MySQLi: + . Fixed bug #76809 (SSL settings aren't respected when persistent connections + are used). (fabiomsouto) + +- Mysqlnd: + . Fixed bug #78525 (Memory leak in pdo when reusing native prepared + statements). (Nikita) + +- PCRE: + . Fixed bug #78272 (calling preg_match() before pcntl_fork() will freeze + child process). (Nikita) + +- PDO_MySQL: + . Fixed bug #78623 (Regression caused by "SP call yields additional empty + result set"). (cmb) + +- Session: + . Fixed bug #78624 (session_gc return value for user defined session + handlers). (bshaffer) + +- Standard: + . Fixed bug #76342 (file_get_contents waits twice specified timeout). + (Thomas Calvet) + . Fixed bug #78612 (strtr leaks memory when integer keys are used and the + subject string shorter). (Nikita) + . Fixed bug #76859 (stream_get_line skips data if used with data-generating + filter). (kkopachev) + +- Zip: + . Fixed bug #78641 (addGlob can modify given remove_path value). (cmb) + +26 Sep 2019, PHP 7.3.10 + +- Core: + . Fixed bug #78220 (Can't access OneDrive folder). (cmb, ab) + . Fixed bug #77922 (Double release of doc comment on inherited shadow + property). (Nikita) + . Fixed bug #78441 (Parse error due to heredoc identifier followed by digit). + (cmb) + . Fixed bug #77812 (Interactive mode does not support PHP 7.3-style heredoc). + (cmb, Nikita) + +- FastCGI: + . Fixed bug #78469 (FastCGI on_accept hook is not called when using named + pipes on Windows). (Sergei Turchanov) + +- FPM: + . Fixed bug #78334 (fpm log prefix message includes wrong stdout/stderr + notation). (Tsuyoshi Sadakata) + +- Intl: + . Ensure IDNA2003 rules are used with idn_to_ascii() and idn_to_utf8() + when requested. (Sara) + +- MBString: + . Fixed bug #78559 (Heap buffer overflow in mb_eregi). (cmb) + +- MySQLnd: + . Fixed connect_attr issues and added the _server_host connection attribute. + (Qianqian Bu) + +- ODBC: + . Fixed bug #78473 (odbc_close() closes arbitrary resources). (cmb) + +- PDO_MySQL: + . Fixed bug #41997 (SP call yields additional empty result set). (cmb) + +- sodium: + . Fixed bug #78510 (Partially uninitialized buffer returned by + sodium_crypto_generichash_init()). (Frank Denis, cmb) + +29 Aug 2019, PHP 7.3.9 + +- Core: + . Fixed bug #78363 (Buffer overflow in zendparse). (Nikita) + . Fixed bug #78379 (Cast to object confuses GC, causes crash). (Dmitry) + . Fixed bug #78412 (Generator incorrectly reports non-releasable $this as GC + child). (Nikita) + +- Curl: + . Fixed bug #77946 (Bad cURL resources returned by curl_multi_info_read()). + (Abyr Valg) + +- Exif: + . Fixed bug #78333 (Exif crash (bus error) due to wrong alignment and + invalid cast). (Nikita) + +- FPM: + . Fixed bug #77185 (Use-after-free in FPM master event handling). + (Maksim Nikulin) + +- Iconv: + . Fixed bug #78342 (Bus error in configure test for iconv //IGNORE). (Rainer + Jung) + +- LiteSpeed: + . Updated to LiteSpeed SAPI V7.5 (Fixed clean shutdown). (George Wang) + +- MBString: + . Fixed bug #78380 (Oniguruma 6.9.3 fixes CVEs). (CVE-2019-13224) (Stas) + +- MySQLnd: + . Fixed bug #78179 (MariaDB server version incorrectly detected). (cmb) + . Fixed bug #78213 (Empty row pocket). (cmb) + +- Opcache: + . Fixed bug #77191 (Assertion failure in dce_live_ranges() when silencing is + used). (Nikita) + +- Standard: + . Fixed bug #69100 (Bus error from stream_copy_to_stream (file -> SSL stream) + with invalid length). (Nikita) + . Fixed bug #78282 (atime and mtime mismatch). (cmb) + . Fixed bug #78326 (improper memory deallocation on stream_get_contents() + with fixed length buffer). (Albert Casademont) + . Fixed bug #78346 (strip_tags no longer handling nested php tags). (cmb) + +01 Aug 2019, PHP 7.3.8 + +- Core: + . Added syslog.filter=raw option. (Erik Lundin) + . Fixed bug #78212 (Segfault in built-in webserver). (cmb) + +- Date: + . Fixed bug #69044 (discrepency between time and microtime). (krakjoe) + . Updated timelib to 2018.02. (Derick) + +- EXIF: + . Fixed bug #78256 (heap-buffer-overflow on exif_process_user_comment). + (CVE-2019-11042) (Stas) + . Fixed bug #78222 (heap-buffer-overflow on exif_scan_thumbnail). + (CVE-2019-11041) (Stas) + +- FTP: + . Fixed bug #78039 (FTP with SSL memory leak). (Nikita) + +- Libxml: + . Fixed bug #78279 (libxml_disable_entity_loader settings is shared between + requests (cgi-fcgi)). (Nikita) + +- LiteSpeed: + . Updated to LiteSpeed SAPI V7.4.3 (increased response header count limit from + 100 to 1000, added crash handler to cleanly shutdown PHP request, added + CloudLinux mod_lsapi mode). (George Wang) + . Fixed bug #76058 (After "POST data can't be buffered", using php://input + makes huge tmp files). (George Wang) + +- Openssl: + . Fixed bug #78231 (Segmentation fault upon stream_socket_accept of exported + socket-to-stream). (Nikita) + +- Opcache: + . Fixed bug #78189 (file cache strips last character of uname hash). (cmb) + . Fixed bug #78202 (Opcache stats for cache hits are capped at 32bit NUM). + (cmb) + . Fixed bug #78271 (Invalid result of if-else). (Nikita) + . Fixed bug #78291 (opcache_get_configuration doesn't list all directives). + (Andrew Collington) + . Fixed bug #78341 (Failure to detect smart branch in DFA pass). (Nikita) + +- PCRE: + . Fixed bug #78197 (PCRE2 version check in configure fails for "##.##-xxx" + version strings). (pgnet, Peter Kokot) + . Fixed bug #78338 (Array cross-border reading in PCRE). (cmb) + +- PDO_Sqlite: + . Fixed bug #78192 (SegFault when reuse statement after schema has changed). + (Vincent Quatrevieux) + +- Phar: + . Fixed bug #77919 (Potential UAF in Phar RSHUTDOWN). (cmb) + +- Phpdbg: + . Fixed bug #78297 (Include unexistent file memory leak). (Nikita) + +- SQLite: + . Upgraded to SQLite 3.28.0. (cmb) + +- Standard: + . Fixed bug #78241 (touch() does not handle dates after 2038 in PHP 64-bit). (cmb) + . Fixed bug #78269 (password_hash uses weak options for argon2). (Remi) + +04 Jul 2019, PHP 7.3.7 + +- Core: + . Fixed bug #76980 (Interface gets skipped if autoloader throws an exception). + (Nikita) + +- DOM: + . Fixed bug #78025 (segfault when accessing properties of DOMDocumentType). + (cmb) + +- MySQLi: + . Fixed bug #77956 (When mysqli.allow_local_infile = Off, use a meaningful + error message). (Sjon Hortensius) + . Fixed bug #38546 (bindParam incorrect processing of bool types). + (camporter) + +- MySQLnd: + . Fixed bug #77955 (Random segmentation fault in mysqlnd from php-fpm). + (Nikita) + +- Opcache: + . Fixed bug #78015 (Incorrect evaluation of expressions involving partials + arrays in SCCP). (Nikita) + . Fixed bug #78106 (Path resolution fails if opcache disabled during request). + (Nikita) + +- OpenSSL: + . Fixed bug #78079 (openssl_encrypt_ccm.phpt fails with OpenSSL 1.1.1c). + (Jakub Zelenka) + +- phpdbg: + . Fixed bug #78050 (SegFault phpdbg + opcache on include file twice). + (Nikita) + +- Sockets: + . Fixed bug #78038 (Socket_select fails when resource array contains + references). (Nikita) + +- Sodium: + . Fixed bug #78114 (segfault when calling sodium_* functions from eval). (cmb) + +- Standard: + . Fixed bug #77135 (Extract with EXTR_SKIP should skip $this). + (Craig Duncan, Dmitry) + . Fixed bug #77937 (preg_match failed). (cmb, Anatol) + +- Zip: + . Fixed bug #76345 (zip.h not found). (Michael Maroszek) + +30 May 2019, PHP 7.3.6 + +- cURL: + . Implemented FR #72189 (Add missing CURL_VERSION_* constants). (Javier + Spagnoletti) + +- Date: + . Fixed bug #77909 (DatePeriod::__construct() with invalid recurrence count + value). (Ignace Nyamagana Butera) + +- EXIF: + . Fixed bug #77988 (heap-buffer-overflow on php_jpg_get16). + (CVE-2019-11040) (Stas) + +- FPM: + . Fixed bug #77934 (php-fpm kill -USR2 not working). (Jakub Zelenka) + . Fixed bug #77921 (static.php.net doesn't work anymore). (Peter Kokot) + +- GD: + . Fixed bug #77943 (imageantialias($image, false); does not work). (cmb) + . Fixed bug #77973 (Uninitialized read in gdImageCreateFromXbm). + (CVE-2019-11038) (cmb) + +- Iconv: + . Fixed bug #78069 (Out-of-bounds read in iconv.c:_php_iconv_mime_decode() + due to integer overflow). (CVE-2019-11039). (maris dot adam) + +- JSON: + . Fixed bug #77843 (Use after free with json serializer). (Nikita) + +- Opcache: + . Fixed possible crashes, because of inconsistent PCRE cache and opcache + SHM reset. (Alexey Kalinin, Dmitry) + +- PDO_MySQL: + . Fixed bug #77944 (Wrong meta pdo_type for bigint on LLP64). (cmb) + +- Reflection: + . Fixed bug #75186 (Inconsistent reflection of Closure:::__invoke()). (Nikita) + +- Session: + . Fixed bug #77911 (Wrong warning for session.sid_bits_per_character). (cmb) + +- SOAP: + . Fixed bug #77945 (Segmentation fault when constructing SoapClient with + WSDL_CACHE_BOTH). (Nikita) + +- SPL: + . Fixed bug #77024 (SplFileObject::__toString() may return array). (Craig + Duncan) + +- SQLite: + . Fixed bug #77967 (Bypassing open_basedir restrictions via file uris). (Stas) + +- Standard: + . Fixed bug #77931 (Warning for array_map mentions wrong type). (Nikita) + . Fixed bug #78003 (strip_tags output change since PHP 7.3). (cmb) + +02 May 2019, PHP 7.3.5 + +- Core: + . Fixed bug #77903 (ArrayIterator stops iterating after offsetSet call). + (Nikita) + +- CLI: + . Fixed bug #77794 (Incorrect Date header format in built-in server). + (kelunik) + +- EXIF + . Fixed bug #77950 (Heap-buffer-overflow in _estrndup via exif_process_IFD_TAG). + (CVE-2019-11036) (Stas) + +- Interbase: + . Fixed bug #72175 (Impossibility of creating multiple connections to + Interbase with php 7.x). (Nikita) + +- Intl: + . Fixed bug #77895 (IntlDateFormatter::create fails in strict mode if $locale + = null). (Nikita) + +- LDAP: + . Fixed bug #77869 (Core dump when using server controls) (mcmic) + +- Mail + . Fixed bug #77821 (Potential heap corruption in TSendMail()). (cmb) + +- mbstring: + . Implemented FR #72777 (Implement regex stack limits for mbregex functions). + (Yasuo Ohgaki, Stas) + +- MySQLi: + . Fixed bug #77773 (Unbuffered queries leak memory - MySQLi / mysqlnd). + (Nikita) + +- PCRE: + . Fixed bug #77827 (preg_match does not ignore \r in regex flags). (requinix, + cmb) + +- PDO: + . Fixed bug #77849 (Disable cloning of PDO handle/connection objects). + (camporter) + +- phpdbg: + . Fixed bug #76801 (too many open files). (alekitto) + . Fixed bug #77800 (phpdbg segfaults on listing some conditional breakpoints). + (krakjoe) + . Fixed bug #77805 (phpdbg build fails when readline is shared). (krakjoe) + +- Reflection: + . Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita) + . Fixed bug #77882 (Different behavior: always calls destructor). (Nikita) + +- Standard: + . Fixed bug #77793 (Segmentation fault in extract() when overwriting + reference with itself). (Nikita) + . Fixed bug #77844 (Crash due to null pointer in parse_ini_string with + INI_SCANNER_TYPED). (Nikita) + . Fixed bug #77853 (Inconsistent substr_compare behaviour with empty + haystack). (Nikita) + +04 Apr 2019, PHP 7.3.4 + +- Core: + . Fixed bug #77738 (Nullptr deref in zend_compile_expr). (Laruence) + . Fixed bug #77660 (Segmentation fault on break 2147483648). (Laruence) + . Fixed bug #77652 (Anonymous classes can lose their interface information). + (Nikita) + . Fixed bug #77345 (Stack Overflow caused by circular reference in garbage + collection). (Alexandru Patranescu, Nikita, Dmitry) + . Fixed bug #76956 (Wrong value for 'syslog.filter' documented in php.ini). + (cmb) + +- Apache2Handler: + . Fixed bug #77648 (BOM in sapi/apache2handler/php_functions.c). (cmb) + +- Bcmath: + . Fixed bug #77742 (bcpow() implementation related to gcc compiler + optimization). (Nikita) + +- CLI Server: + . Fixed bug #77722 (Incorrect IP set to $_SERVER['REMOTE_ADDR'] on the + localhost). (Nikita) + +- COM: + . Fixed bug #77578 (Crash when php unload). (cmb) + +- EXIF: + . Fixed bug #77753 (Heap-buffer-overflow in php_ifd_get32s). (CVE-2019-11034) + (Stas) + . Fixed bug #77831 (Heap-buffer-overflow in exif_iif_add_value). + (CVE-2019-11035) (Stas) + +- FPM: + . Fixed bug #77677 (FPM fails to build on AIX due to missing WCOREDUMP). + (Kevin Adler) + +- GD: + . Fixed bug #77700 (Writing truecolor images as GIF ignores interlace flag). + (cmb) + +- MySQLi: + . Fixed bug #77597 (mysqli_fetch_field hangs scripts). (Nikita) + +- Opcache: + . Fixed bug #77743 (Incorrect pi node insertion for jmpznz with identical + successors). (Nikita) + +- PCRE: + . Fixed bug #76127 (preg_split does not raise an error on invalid UTF-8). + (Nikita) + +- Phar: + . Fixed bug #77697 (Crash on Big_Endian platform). (Laruence) + +- phpdbg: + . Fixed bug #77767 (phpdbg break cmd aliases listed in help do not match + actual aliases). (Miriam Lauter) + +- sodium: + . Fixed bug #77646 (sign_detached() strings not terminated). (Frank) + +- SQLite3: + . Added sqlite3.defensive INI directive. (BohwaZ) + +- Standard: + . Fixed bug #77664 (Segmentation fault when using undefined constant in + custom wrapper). (Laruence) + . Fixed bug #77669 (Crash in extract() when overwriting extracted array). + (Nikita) + . Fixed bug #76717 (var_export() does not create a parsable value for + PHP_INT_MIN). (Nikita) + . Fixed bug #77765 (FTP stream wrapper should set the directory as + executable). (Vlad Temian) + +07 Mar 2019, PHP 7.3.3 + +- Core: + . Fixed bug #77589 (Core dump using parse_ini_string with numeric sections). + (Laruence) + . Fixed bug #77329 (Buffer Overflow via overly long Error Messages). + (Dmitry) + . Fixed bug #77494 (Disabling class causes segfault on member access). + (Dmitry) + . Fixed bug #77498 (Custom extension Segmentation fault when declare static + property). (Nikita) + . Fixed bug #77530 (PHP crashes when parsing `(2)::class`). (Ekin) + . Fixed bug #77546 (iptcembed broken function). (gdegoulet) + . Fixed bug #77630 (rename() across the device may allow unwanted access + during processing). (Stas) + +- COM: + . Fixed bug #77621 (Already defined constants are not properly reported). + (cmb) + . Fixed bug #77626 (Persistence confusion in php_com_import_typelib()). (cmb) + +- EXIF: + . Fixed bug #77509 (Uninitialized read in exif_process_IFD_in_TIFF). (Stas) + . Fixed bug #77540 (Invalid Read on exif_process_SOFn). (Stas) + . Fixed bug #77563 (Uninitialized read in exif_process_IFD_in_MAKERNOTE). (Stas) + . Fixed bug #77659 (Uninitialized read in exif_process_IFD_in_MAKERNOTE). (Stas) + +- Mbstring: + . Fixed bug #77514 (mb_ereg_replace() with trailing backslash adds null byte). + (Nikita) + +- MySQL + . Disabled LOCAL INFILE by default, can be enabled using php.ini directive + mysqli.allow_local_infile for mysqli, or PDO::MYSQL_ATTR_LOCAL_INFILE + attribute for pdo_mysql. (Darek Slusarczyk) + +- OpenSSL: + . Fixed bug #77390 (feof might hang on TLS streams in case of fragmented TLS + records). (Abyl Valg, Jakub Zelenka) + +- PDO_OCI: + . Support Oracle Database tracing attributes ACTION, MODULE, + CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter) + +- PHAR: + . Fixed bug #77396 (Null Pointer Dereference in phar_create_or_parse_filename). + (bishop) + . Fixed bug #77586 (phar_tar_writeheaders_int() buffer overflow). (bishop) + +- phpdbg: + . Fixed bug #76596 (phpdbg support for display_errors=stderr). (kabel) + +- SPL: + . Fixed bug #51068 (DirectoryIterator glob:// don't support current path + relative queries). (Ahmed Abdou) + . Fixed bug #77431 (openFile() silently truncates after a null byte). (cmb) + +- Standard: + . Fixed bug #77552 (Unintialized php_stream_statbuf in stat functions). + (John Stevenson) + . Fixed bug #77612 (setcookie() sets incorrect SameSite header if all of its + options filled). (Nikita) + +07 Feb 2019, PHP 7.3.2 + +- Core: + . Fixed bug #77369 (memcpy with negative length via crafted DNS response). (Stas) + . Fixed bug #77387 (Recursion detection broken when printing GLOBALS). + (Laruence) + . Fixed bug #77376 ("undefined function" message no longer includes + namespace). (Laruence) + . Fixed bug #77357 (base64_encode / base64_decode doest not work on nested + VM). (Nikita) + . Fixed bug #77339 (__callStatic may get incorrect arguments). (Dmitry) + . Fixed bug #77317 (__DIR__, __FILE__, realpath() reveal physical path for + subst virtual drive). (Anatol) + . Fixed bug #77263 (Segfault when using 2 RecursiveFilterIterator). (Dmitry) + . Fixed bug #77447 (PHP 7.3 built with ASAN crashes in + zend_cpu_supports_avx2). (Nikita) + . Fixed bug #77484 (Zend engine crashes when calling realpath in invalid + working dir). (Anatol) + +- Curl: + . Fixed bug #76675 (Segfault with H2 server push). (Pedro Magalhães) + +- Fileinfo: + . Fixed bug #77346 (webm files incorrectly detected as + application/octet-stream). (Anatol) + +- FPM: + . Fixed bug #77430 (php-fpm crashes with Main process exited, code=dumped, + status=11/SEGV). (Jakub Zelenka) + +- GD: + . Fixed bug #73281 (imagescale(…, IMG_BILINEAR_FIXED) can cause black border). + (cmb) + . Fixed bug #73614 (gdImageFilledArc() doesn't properly draw pies). (cmb) + . Fixed bug #77272 (imagescale() may return image resource on failure). (cmb) + . Fixed bug #77391 (1bpp BMPs may fail to be loaded). (Romain Déoux, cmb) + . Fixed bug #77479 (imagewbmp() segfaults with very large images). (cmb) + +- ldap: + . Fixed bug #77440 (ldap_bind using ldaps or ldap_start_tls()=exception in + libcrypto-1_1-x64.dll). (Anatol) + +- Mbstring: + . Fixed bug #77428 (mb_ereg_replace() doesn't replace a substitution + variable). (Nikita) + . Fixed bug #77454 (mb_scrub() silently truncates after a null byte). + (64796c6e69 at gmail dot com) + +- MySQLnd: + . Fixed bug #77308 (Unbuffered queries memory leak). (Dmitry) + . Fixed bug #75684 (In mysqlnd_ext_plugin.h the plugin methods family has + no external visibility). (Anatol) + +- Opcache: + . Fixed bug #77266 (Assertion failed in dce_live_ranges). (Laruence) + . Fixed bug #77257 (value of variable assigned in a switch() construct gets + lost). (Nikita) + . Fixed bug #77434 (php-fpm workers are segfaulting in zend_gc_addre). + (Nikita) + . Fixed bug #77361 (configure fails on 64-bit AIX when opcache enabled). + (Kevin Adler) + . Fixed bug #77287 (Opcache literal compaction is incompatible with EXT + opcodes). (Nikita) + +- PCRE: + . Fixed bug #77338 (get_browser with empty string). (Nikita) + +- PDO: + . Fixed bug #77273 (array_walk_recursive corrupts value types leading to PDO + failure). (Nikita) + +- PDO MySQL: + . Fixed bug #77289 (PDO MySQL segfaults with persistent connection). + (Lauri Kenttä) + +- SOAP: + . Fixed bug #77410 (Segmentation Fault when executing method with an empty + parameter). (Nikita) + +- Sockets: + . Fixed bug #76839 (socket_recvfrom may return an invalid 'from' address + on MacOS). (Michael Meyer) + +- SPL: + . Fixed bug #77298 (segfault occurs when add property to unserialized empty + ArrayObject). (jhdxr) + +- Standard: + . Fixed bug #77395 (segfault about array_multisort). (Laruence) + . Fixed bug #77439 (parse_str segfaults when inserting item into existing + array). (Nikita) + +10 Jan 2019, PHP 7.3.1 + +- Core: + . Fixed bug #76654 (Build failure on Mac OS X on 32-bit Intel). (Ryandesign) + . Fixed bug #71041 (zend_signal_startup() needs ZEND_API). + (Valentin V. Bartenev) + . Fixed bug #76046 (PHP generates "FE_FREE" opcode on the wrong line). + (Nikita) + . Fixed bug #77291 (magic methods inherited from a trait may be ignored). + (cmb) + +- CURL: + . Fixed bug #77264 (curl_getinfo returning microseconds, not seconds). + (Pierrick) + +- COM: + . Fixed bug #77177 (Serializing or unserializing COM objects crashes). (cmb) + +- Exif: + . Fixed bug #77184 (Unsigned rational numbers are written out as signed + rationals). (Colin Basnett) + +- GD: + . Fixed bug #77195 (Incorrect error handling of imagecreatefromjpeg()). (cmb) + . Fixed bug #77198 (auto cropping has insufficient precision). (cmb) + . Fixed bug #77200 (imagecropauto(…, GD_CROP_SIDES) crops left but not right). + (cmb) + . Fixed bug #77269 (efree() on uninitialized Heap data in imagescale leads to + use-after-free). (cmb) + . Fixed bug #77270 (imagecolormatch Out Of Bounds Write on Heap). (cmb) + +- MBString: + . Fixed bug #77367 (Negative size parameter in mb_split). (Stas) + . Fixed bug #77370 (Buffer overflow on mb regex functions - fetch_token). + (Stas) + . Fixed bug #77371 (heap buffer overflow in mb regex functions + - compile_string_node). (Stas) + . Fixed bug #77381 (heap buffer overflow in multibyte match_at). (Stas) + . Fixed bug #77382 (heap buffer overflow due to incorrect length in + expand_case_fold_string). (Stas) + . Fixed bug #77385 (buffer overflow in fetch_token). (Stas) + . Fixed bug #77394 (Buffer overflow in multibyte case folding - unicode). + (Stas) + . Fixed bug #77418 (Heap overflow in utf32be_mbc_to_code). (Stas) + +- OCI8: + . Fixed bug #76804 (oci_pconnect with OCI_CRED_EXT not working). (KoenigsKind) + . Added oci_set_call_timeout() for call timeouts. + . Added oci_set_db_operation() for the DBOP end-to-end-tracing attribute. + +- Opcache: + . Fixed bug #77215 (CFG assertion failure on multiple finalizing switch + frees in one block). (Nikita) + . Fixed bug #77275 (OPcache optimization problem for ArrayAccess->offsetGet). + (Nikita) + +- PCRE: + . Fixed bug #77193 (Infinite loop in preg_replace_callback). (Anatol) + +- PDO: + . Handle invalid index passed to PDOStatement::fetchColumn() as error. (Sergei + Morozov) + +- Phar: + . Fixed bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext). (Stas) + +- Soap: + . Fixed bug #77088 (Segfault when using SoapClient with null options). + (Laruence) + +- Sockets: + . Fixed bug #77136 (Unsupported IPV6_RECVPKTINFO constants on macOS). + (Mizunashi Mana) + +- Sodium: + . Fixed bug #77297 (SodiumException segfaults on PHP 7.3). (Nikita, Scott) + +- SPL: + . Fixed bug #77359 (spl_autoload causes segfault). (Lauri Kenttä) + . Fixed bug #77360 (class_uses causes segfault). (Lauri Kenttä) + +- SQLite3: + . Fixed bug #77051 (Issue with re-binding on SQLite3). (BohwaZ) + +- Xmlrpc: + . Fixed bug #77242 (heap out of bounds read in xmlrpc_decode()). (cmb) + . Fixed bug #77380 (Global out of bounds read in xmlrpc base64 code). (Stas) + +06 Dec 2018, PHP 7.3.0 + +- Core: + . Improved PHP GC. (Dmitry, Nikita) + . Redesigned the old ext_skel program written in PHP, run: + 'php ext_skel.php' for all options. This means there are no dependencies, + thus making it work on Windows out of the box. (Kalle) + . Removed support for BeOS. (Kalle) + . Add PHP_VERSION to phpinfo() . (github/MattJeevas) + . Add net_get_interfaces(). (Sara, Joe, Anatol) + . Added gc_status(). (Benjamin Eberlei) + . Implemented flexible heredoc and nowdoc syntax, per + RFC https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes. + (Thomas Punt) + . Added support for references in list() and array destructuring, per + RFC https://wiki.php.net/rfc/list_reference_assignment. + (David Walker) + . Improved effectiveness of ZEND_SECURE_ZERO for NetBSD and systems + without native similar feature. (devnexen) + . Added syslog.facility and syslog.ident INI entries for customizing syslog + logging. (Philip Prindeville) + . Fixed bug #75683 (Memory leak in zend_register_functions() in ZTS mode). + (Dmitry) + . Fixed bug #75031 (support append mode in temp/memory streams). (adsr) + . Fixed bug #74860 (Uncaught exceptions not being formatted properly when + error_log set to "syslog"). (Philip Prindeville) + . Fixed bug #75220 (Segfault when calling is_callable on parent). + (andrewnester) + . Fixed bug #69954 (broken links and unused config items in distributed ini + files). (petk) + . Fixed bug #74922 (Composed class has fatal error with duplicate, equal const + properties). (pmmaga) + . Fixed bug #63911 (identical trait methods raise errors during composition). + (pmmaga) + . Fixed bug #75677 (Clang ignores fastcall calling convention on variadic + function). (Li-Wen Hsu) + . Fixed bug #54043 (Remove inconsitency of internal exceptions and user + defined exceptions). (Nikita) + . Fixed bug #53033 (Mathematical operations convert objects to integers). + (Nikita) + . Fixed bug #73108 (Internal class cast handler uses integer instead of + float). (Nikita) + . Fixed bug #75765 (Fatal error instead of Error exception when base class is + not found). (Timur Ibragimov) + . Fixed bug #76198 (Wording: "iterable" is not a scalar type). (Levi Morrison) + . Fixed bug #76137 (config.guess/config.sub do not recognize RISC-V). (cmb) + . Fixed bug #76427 (Segfault in zend_objects_store_put). (Laruence) + . Fixed bug #76422 (ftruncate fails on files > 2GB). (Anatol) + . Fixed bug #76509 (Inherited static properties can be desynchronized from + their parent by ref). (Nikita) + . Fixed bug #76439 (Changed behaviour in unclosed HereDoc). (Nikita, tpunt) + . Fixed bug #63217 (Constant numeric strings become integers when used as + ArrayAccess offset). (Rudi Theunissen, Dmitry) + . Fixed bug #33502 (Some nullary functions don't check the number of + arguments). (cmb) + . Fixed bug #76392 (Error relocating sapi/cli/php: unsupported relocation + type 37). (Peter Kokot) + . The declaration and use of case-insensitive constants has been deprecated. + (Nikita) + . Added syslog.filter INI entry for syslog filtering. (Philip Prindeville) + . Fixed bug #76667 (Segfault with divide-assign op and __get + __set). + (Laruence) + . Fixed bug #76030 (RE2C_FLAGS rarely honoured) (Cristian Rodríguez) + . Fixed broken zend_read_static_property (Laruence) + . Fixed bug #76773 (Traits used on the parent are ignored for child classes). + (daverandom) + . Fixed bug #76767 (‘asm’ operand has impossible constraints in zend_operators.h). + (ondrej) + . Fixed bug #76752 (Crash in ZEND_COALESCE_SPEC_TMP_HANDLER - assertion in + _get_zval_ptr_tmp failed). (Laruence) + . Fixed bug #76820 (Z_COPYABLE invalid definition). (mvdwerve, cmb) + . Fixed bug #76510 (file_exists() stopped working for phar://). (cmb) + . Fixed bug #76869 (Incorrect bypassing protected method accessibilty check). + (Dmitry) + . Fixed bug #72635 (Undefined class used by class constant in constexpr + generates fatal error). (Nikita) + . Fixed bug #76947 (file_put_contents() blocks the directory of the file + (__DIR__)). (Anatol) + . Fixed bug #76979 (define() error message does not mention resources as + valid values). (Michael Moravec) + . Fixed bug #76825 (Undefined symbols ___cpuid_count). (Laruence, cmb) + . Fixed bug #77110 (undefined symbol zend_string_equal_val in C++ build). + (Remi) + +- BCMath: + . Implemented FR #67855 (No way to get current scale in use). (Chris Wright, + cmb) + . Fixed bug #66364 (BCMath bcmul ignores scale parameter). (cmb) + . Fixed bug #75164 (split_bc_num() is pointless). (cmb) + . Fixed bug #75169 (BCMath errors/warnings bypass PHP's error handling). (cmb) + +- CLI: + . Fixed bug #44217 (Output after stdout/stderr closed cause immediate exit + with status 0). (Robert Lu) + . Fixed bug #77111 (php-win.exe corrupts unicode symbols from cli + parameters). (Anatol) + +- cURL: + . Expose curl constants from curl 7.50 to 7.61. (Pierrick) + . Fixed bug #74125 (Fixed finding CURL on systems with multiarch support). + (cebe) + +- Date: + . Implemented FR #74668: Add DateTime::createFromImmutable() method. + (majkl578, Rican7) + . Fixed bug #75222 (DateInterval microseconds property always 0). (jhdxr) + . Fixed bug #68406 (calling var_dump on a DateTimeZone object modifies it). + (jhdxr) + . Fixed bug #76131 (mismatch arginfo for date_create). (carusogabriel) + . Updated timelib to 2018.01RC1 to address several bugs: + . Fixed bug #75577 (DateTime::createFromFormat does not accept 'v' format + specifier). (Derick) + . Fixed bug #75642 (Wrap around behaviour for microseconds is not working). + (Derick) + +- DBA: + . Fixed bug #75264 (compiler warnings emitted). (petk) + +- DOM: + . Fixed bug #76285 (DOMDocument::formatOutput attribute sometimes ignored). + (Andrew Nester, Laruence, Anatol) + +- Fileinfo: + . Fixed bug #77095 (slowness regression in 7.2/7.3 (compared to 7.1)). + (Anatol) + +- Filter: + . Added the 'add_slashes' sanitization mode (FILTER_SANITIZE_ADD_SLASHES). + (Kalle) + +- FPM: + . Added fpm_get_status function. (Till Backhaus) + . Fixed bug #62596 (getallheaders() missing with PHP-FPM). (Remi) + . Fixed bug #69031 (Long messages into stdout/stderr are truncated + incorrectly) - added new log related FPM configuration options: + log_limit, log_buffering and decorate_workers_output. (Jakub Zelenka) + +- ftp: + . Fixed bug #77151 (ftp_close(): SSL_read on shutdown). (Remi) + +- GD: + . Added support for WebP in imagecreatefromstring(). (Andreas Treichel, cmb) + +- GMP: + . Export internal structures and accessor helpers for GMP object. (Sara) + . Added gmp_binomial(n, k). (Nikita) + . Added gmp_lcm(a, b). (Nikita) + . Added gmp_perfect_power(a). (Nikita) + . Added gmp_kronecker(a, b). (Nikita) + +- iconv: + . Fixed bug #53891 (iconv_mime_encode() fails to Q-encode UTF-8 string). (cmb) + . Fixed bug #77147 (Fixing 60494 ignored ICONV_MIME_DECODE_CONTINUE_ON_ERROR). + (cmb) + +- IMAP: + . Fixed bug #77020 (null pointer dereference in imap_mail). (cmb) + . Fixed bug #77153 (imap_open allows to run arbitrary shell commands via + mailbox parameter). (Stas) + +- Interbase: + . Fixed bug #75453 (Incorrect reflection for ibase_[p]connect). (villfa) + . Fixed bug #76443 (php+php_interbase.dll crash on module_shutdown). (Kalle) + + +- intl: + . Fixed bug #75317 (UConverter::setDestinationEncoding changes source instead + of destination). (andrewnester) + . Fixed bug #76829 (Incorrect validation of domain on idn_to_utf8() + function). (Anatol) + +- JSON: + . Added JSON_THROW_ON_ERROR flag. (Andrea) + +- LDAP: + . Added ldap_exop_refresh helper for EXOP REFRESH operation with dds overlay. + (Come) + . Added full support for sending and parsing ldap controls. (Come) + . Fixed bug #49876 (Fix LDAP path lookup on 64-bit distros). (dzuelke) + +- libxml2: + . Fixed bug #75871 (use pkg-config where available). (pmmaga) + +- litespeed: + . Fixed bug #75248 (Binary directory doesn't get created when building + only litespeed SAPI). (petk) + . Fixed bug #75251 (Missing program prefix and suffix). (petk) + +- MBstring: + . Updated to Oniguruma 6.9.0. (cmb) + . Fixed bug #65544 (mb title case conversion-first word in quotation isn't + capitalized). (Nikita) + . Fixed bug #71298 (MB_CASE_TITLE misbehaves with curled apostrophe/quote). + (Nikita) + . Fixed bug #73528 (Crash in zif_mb_send_mail). (Nikita) + . Fixed bug #74929 (mbstring functions version 7.1.1 are slow compared to 5.3 + on Windows). (Nikita) + . Fixed bug #76319 (mb_strtolower with invalid UTF-8 causes segmentation + fault). (Nikita) + . Fixed bug #76574 (use of undeclared identifiers INT_MAX and LONG_MAX). (cmb) + . Fixed bug #76594 (Bus Error due to unaligned access in zend_ini.c + OnUpdateLong). (cmb, Nikita) + . Fixed bug #76706 (mbstring.http_output_conv_mimetypes is ignored). (cmb) + . Fixed bug #76958 (Broken UTF7-IMAP conversion). (Nikita) + . Fixed bug #77025 (mb_strpos throws Unknown encoding or conversion error). + (Nikita) + . Fixed bug #77165 (mb_check_encoding crashes when argument given an empty + array). (Nikita) + +- Mysqlnd: + . Fixed bug #76386 (Prepared Statement formatter truncates fractional seconds + from date/time column). (Victor Csiky) + +- ODBC: + . Removed support for ODBCRouter. (Kalle) + . Removed support for Birdstep. (Kalle) + . Fixed bug #77079 (odbc_fetch_object has incorrect type signature). + (Jon Allen) + +- Opcache: + . Fixed bug #76466 (Loop variable confusion). (Dmitry, Laruence, Nikita) + . Fixed bug #76463 (var has array key type but not value type). (Laruence) + . Fixed bug #76446 (zend_variables.c:73: zend_string_destroy: Assertion + `!(zval_gc_flags((str)->gc)). (Nikita, Laruence) + . Fixed bug #76711 (OPcache enabled triggers false-positive "Illegal string + offset"). (Dmitry) + . Fixed bug #77058 (Type inference in opcache causes side effects). (Nikita) + . Fixed bug #77092 (array_diff_key() - segmentation fault). (Nikita) + +- OpenSSL: + . Added openssl_pkey_derive function. (Jim Zubov) + . Add min_proto_version and max_proto_version ssl stream options as well as + related constants for possible TLS protocol values. (Jakub Zelenka) + +- PCRE: + . Implemented https://wiki.php.net/rfc/pcre2-migration. (Anatol, Dmitry) + . Upgrade PCRE2 to 10.32. (Anatol) + . Fixed bug #75355 (preg_quote() does not quote # control character). + (Michael Moravec) + . Fixed bug #76512 (\w no longer includes unicode characters). (cmb) + . Fixed bug #76514 (Regression in preg_match makes it fail with + PREG_JIT_STACKLIMIT_ERROR). (Anatol) + . Fixed bug #76909 (preg_match difference between 7.3 and < 7.3). (Anatol) + +- PDO_DBlib: + . Implemented FR #69592 (allow 0-column rowsets to be skipped automatically). + (fandrieu) + . Expose TDS version as \PDO::DBLIB_ATTR_TDS_VERSION attribute on \PDO + instance. (fandrieu) + . Treat DATETIME2 columns like DATETIME. (fandrieu) + . Fixed bug #74243 (allow locales.conf to drive datetime format). (fandrieu) + +- PDO_Firebird: + . Fixed bug #74462 (PDO_Firebird returns only NULLs for results with boolean + for FIREBIRD >= 3.0). (Dorin Marcoci) + +- PDO_OCI: + . Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized + before PHP-FPM sets it up). (Ingmar Runge) + +- PDO SQLite + . Add support for additional open flags + +- pgsql: + . Added new error constants for pg_result_error(): PGSQL_DIAG_SCHEMA_NAME, + PGSQL_DIAG_TABLE_NAME, PGSQL_DIAG_COLUMN_NAME, PGSQL_DIAG_DATATYPE_NAME, + PGSQL_DIAG_CONSTRAINT_NAME and PGSQL_DIAG_SEVERITY_NONLOCALIZED. (Kalle) + . Fixed bug #77047 (pg_convert has a broken regex for the 'TIME WITHOUT + TIMEZONE' data type). (Andy Gajetzki) + +- phar: + . Fixed bug #74991 (include_path has a 4096 char limit in some cases). + (bwbroersma) + . Fixed bug #65414 (deal with leading slash when adding files correctly). + (bishopb) + +- readline: + . Added completion_append_character and completion_suppress_append options + to readline_info() if linked against libreadline. (krageon) + +- Session: + . Fixed bug #74941 (session fails to start after having headers sent). + (morozov) + +- SimpleXML: + . Fixed bug #54973 (SimpleXML casts integers wrong). (Nikita) + . Fixed bug #76712 (Assignment of empty string creates extraneous text node). + (cmb) + +- Sockets: + . Fixed bug #67619 (Validate length on socket_write). (thiagooak) + +- SOAP: + . Fixed bug #75464 (Wrong reflection on SoapClient::__setSoapHeaders). + (villfa) + . Fixed bug #70469 (SoapClient generates E_ERROR even if exceptions=1 is + used). (Anton Artamonov) + . Fixed bug #50675 (SoapClient can't handle object references correctly). + (Cameron Porter) + . Fixed bug #76348 (WSDL_CACHE_MEMORY causes Segmentation fault). (cmb) + . Fixed bug #77141 (Signedness issue in SOAP when precision=-1). (cmb) + +- SPL: + . Fixed bug #74977 (Appending AppendIterator leads to segfault). + (Andrew Nester) + . Fixed bug #75173 (incorrect behavior of AppendIterator::append in foreach + loop). (jhdxr) + . Fixed bug #74372 (autoloading file with syntax error uses next autoloader, + may hide parse error). (Nikita) + . Fixed bug #75878 (RecursiveTreeIterator::setPostfix has wrong signature). + (cmb) + . Fixed bug #74519 (strange behavior of AppendIterator). (jhdxr) + . Fixed bug #76131 (mismatch arginfo for splarray constructor). + (carusogabriel) + +- SQLite3: + . Updated bundled libsqlite to 3.24.0. (cmb) + +- Standard: + . Added is_countable() function. (Gabriel Caruso) + . Added support for the SameSite cookie directive, including an alternative + signature for setcookie(), setrawcookie() and session_set_cookie_params(). + (Frederik Bosch, pmmaga) + . Remove superfluous warnings from inet_ntop()/inet_pton(). (daverandom) + . Fixed bug #75916 (DNS_CAA record results contain garbage). (Mike, + Philip Sharp) + . Fixed unserialize(), to disable creation of unsupported data structures + through manually crafted strings. (Dmitry) + . Fixed bug #75409 (accept EFAULT in addition to ENOSYS as indicator + that getrandom() is missing). (sarciszewski) + . Fixed bug #74719 (fopen() should accept NULL as context). (Alexander Holman) + . Fixed bug #69948 (path/domain are not sanitized in setcookie). (cmb) + . Fixed bug #75996 (incorrect url in header for mt_rand). (tatarbj) + . Added hrtime() function, to get high resolution time. (welting) + . Fixed bug #48016 (stdClass::__setState is not defined although var_export() + uses it). (Andrea) + . Fixed bug #76136 (stream_socket_get_name should enclose IPv6 in brackets). + (seliver) + . Fixed bug #76688 (Disallow excessive parameters after options array). + (pmmaga) + . Fixed bug #76713 (Segmentation fault caused by property corruption). + (Laruence) + . Fixed bug #76755 (setcookie does not accept "double" type for expire time). + (Laruence) + . Fixed bug #76674 (improve array_* failure messages exposing what was passed + instead of an array). (carusogabriel) + . Fixed bug #76803 (ftruncate changes file pointer). (Anatol) + . Fixed bug #76818 (Memory corruption and segfault). (Remi) + . Fixed bug #77081 (ftruncate() changes seek pointer in c mode). (cmb, Anatol) + +- Testing: + . Implemented FR #62055 (Make run-tests.php support --CGI-- sections). (cmb) + +- Tidy: + . Support using tidyp instead of tidy. (devnexen) + . Fixed bug #74707 (Tidy has incorrect ReflectionFunction param counts for + functions taking tidy). (Gabriel Caruso) + . Fixed arginfo for tidy::__construct(). (Tyson Andre) + +- Tokenizer: + . Fixed bug #76437 (token_get_all with TOKEN_PARSE flag fails to recognise + close tag). (Laruence) + . Fixed bug #75218 (Change remaining uncatchable fatal errors for parsing + into ParseError). (Nikita) + . Fixed bug #76538 (token_get_all with TOKEN_PARSE flag fails to recognise + close tag with newline). (Nikita) + . Fixed bug #76991 (Incorrect tokenization of multiple invalid flexible + heredoc strings). (Nikita) + +- XML: + . Fixed bug #71592 (External entity processing never fails). (cmb) + +- Zlib: + . Added zlib/level context option for compress.zlib wrapper. (Sara) diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index b9a91c900e7e4..04b964a287507 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -771,7 +771,8 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - zend_uchar * const buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len); + size_t total_packet_size = packet->auth_data_len + MYSQLND_HEADER_SIZE; + zend_uchar * const buffer = pfc->cmd_buffer.length >= total_packet_size? pfc->cmd_buffer.buffer : mnd_emalloc(total_packet_size); zend_uchar * p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */ DBG_ENTER("php_mysqlnd_change_auth_response_write"); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 82fbd3bb20a76..d4dd8f090a01e 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -315,6 +315,8 @@ void sdl_restore_uri_credentials(sdlCtx *ctx) ctx->context = NULL; } +#define SAFE_STR(a) ((a)?a:"") + static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) { sdlPtr tmpsdl = ctx->sdl; @@ -376,7 +378,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) if (node_is_equal_ex(trav2, "schema", XSD_NAMESPACE)) { load_schema(ctx, trav2); } else if (is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav2->name)); } trav2 = trav2->next; } @@ -437,7 +439,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) soap_error0(E_ERROR, "Parsing WSDL: <service> has no name attribute"); } } else if (!node_is_equal(trav,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } trav = trav->next; } @@ -547,7 +549,7 @@ static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xml } smart_str_free(&key); } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } trav = trav->next; } @@ -649,7 +651,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap } smart_str_free(&key); } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } trav = trav->next; } @@ -681,14 +683,14 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) sdlParamPtr param; if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", SAFE_STR(trav->name)); } if (node_is_equal(trav,"documentation")) { trav = trav->next; continue; } if (!node_is_equal(trav,"part")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } part = trav; param = emalloc(sizeof(sdlParam)); @@ -697,7 +699,7 @@ static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) name = get_attribute(part->properties, "name"); if (name == NULL) { - soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", message->name); + soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", SAFE_STR(message->name)); } param->paramName = estrdup((char*)name->children->content); @@ -768,7 +770,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) continue; } if (!node_is_equal(trav,"port")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } port = trav; @@ -807,7 +809,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) } } if (trav2 != address && is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav2->name)); } trav2 = trav2->next; } @@ -909,7 +911,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) continue; } if (!node_is_equal(trav2,"operation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav2->name)); } operation = trav2; @@ -928,7 +930,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) !node_is_equal(trav3,"output") && !node_is_equal(trav3,"fault") && !node_is_equal(trav3,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav3->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav3->name)); } trav3 = trav3->next; } @@ -1106,7 +1108,7 @@ static sdlPtr load_wsdl(zval *this_ptr, char *struri) } } } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { - soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", SAFE_STR(trav->name)); } trav = trav->next; } diff --git a/ext/soap/php_sdl.c.orig b/ext/soap/php_sdl.c.orig new file mode 100644 index 0000000000000..82fbd3bb20a76 --- /dev/null +++ b/ext/soap/php_sdl.c.orig @@ -0,0 +1,3672 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Brad Lafountain <rodif_bl@yahoo.com> | + | Shane Caraveo <shane@caraveo.com> | + | Dmitry Stogov <dmitry@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "php_soap.h" +#include "ext/libxml/php_libxml.h" +#include "libxml/uri.h" + +#include "ext/standard/md5.h" +#include "zend_virtual_cwd.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#ifndef O_BINARY +# define O_BINARY 0 +#endif + +static void delete_fault(zval *zv); +static void delete_fault_persistent(zval *zv); +static void delete_binding(zval *zv); +static void delete_binding_persistent(zval *zv); +static void delete_function(zval *zv); +static void delete_function_persistent(zval *zv); +static void delete_parameter(zval *zv); +static void delete_parameter_persistent(zval *zv); +static void delete_header(zval *header); +static void delete_header_int(sdlSoapBindingFunctionHeaderPtr hdr); +static void delete_header_persistent(zval *zv); +static void delete_document(zval *zv); + +encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *type) +{ + encodePtr enc = NULL; + xmlNsPtr nsptr; + char *ns, *cptype; + + parse_namespace(type, &cptype, &ns); + nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns)); + if (nsptr != NULL) { + enc = get_encoder(sdl, (char*)nsptr->href, cptype); + if (enc == NULL) { + enc = get_encoder_ex(sdl, cptype, strlen(cptype)); + } + } else { + enc = get_encoder_ex(sdl, (char*)type, xmlStrlen(type)); + } + efree(cptype); + if (ns) {efree(ns);} + return enc; +} + +static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type) +{ + sdlTypePtr ret = NULL; + + if (sdl->elements) { + xmlNsPtr nsptr; + char *ns, *cptype; + sdlTypePtr sdl_type; + + parse_namespace(type, &cptype, &ns); + nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns)); + if (nsptr != NULL) { + int ns_len = xmlStrlen(nsptr->href); + int type_len = strlen(cptype); + int len = ns_len + type_len + 1; + char *nscat = emalloc(len + 1); + + memcpy(nscat, nsptr->href, ns_len); + nscat[ns_len] = ':'; + memcpy(nscat+ns_len+1, cptype, type_len); + nscat[len] = '\0'; + + if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, nscat, len)) != NULL) { + ret = sdl_type; + } else if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, (char*)type, type_len)) != NULL) { + ret = sdl_type; + } + efree(nscat); + } else { + if ((sdl_type = zend_hash_str_find_ptr(sdl->elements, (char*)type, xmlStrlen(type))) != NULL) { + ret = sdl_type; + } + } + + efree(cptype); + if (ns) {efree(ns);} + } + return ret; +} + +encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type) +{ + encodePtr enc = NULL; + char *nscat; + int ns_len = ns ? strlen(ns) : 0; + int type_len = strlen(type); + int len = ns_len + type_len + 1; + + nscat = emalloc(len + 1); + if (ns) { + memcpy(nscat, ns, ns_len); + } + nscat[ns_len] = ':'; + memcpy(nscat+ns_len+1, type, type_len); + nscat[len] = '\0'; + + enc = get_encoder_ex(sdl, nscat, len); + + if (enc == NULL && + ((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 && + memcmp(ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) || + (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 && + memcmp(ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) { + char *enc_nscat; + int enc_ns_len; + int enc_len; + + enc_ns_len = sizeof(XSD_NAMESPACE)-1; + enc_len = enc_ns_len + type_len + 1; + enc_nscat = emalloc(enc_len + 1); + memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1); + enc_nscat[enc_ns_len] = ':'; + memcpy(enc_nscat+enc_ns_len+1, type, type_len); + enc_nscat[enc_len] = '\0'; + + enc = get_encoder_ex(NULL, enc_nscat, enc_len); + efree(enc_nscat); + if (enc && sdl) { + encodePtr new_enc = pemalloc(sizeof(encode), sdl->is_persistent); + memcpy(new_enc, enc, sizeof(encode)); + if (sdl->is_persistent) { + new_enc->details.ns = zend_strndup(ns, ns_len); + new_enc->details.type_str = strdup(new_enc->details.type_str); + } else { + new_enc->details.ns = estrndup(ns, ns_len); + new_enc->details.type_str = estrdup(new_enc->details.type_str); + } + if (sdl->encoders == NULL) { + sdl->encoders = pemalloc(sizeof(HashTable), sdl->is_persistent); + zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, sdl->is_persistent); + } + zend_hash_str_update_ptr(sdl->encoders, nscat, len, new_enc); + enc = new_enc; + } + } + efree(nscat); + return enc; +} + +encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len) +{ + encodePtr enc; + + if ((enc = zend_hash_str_find_ptr(&SOAP_GLOBAL(defEnc), (char*)nscat, len)) != NULL) { + return enc; + } else if (sdl && sdl->encoders && (enc = zend_hash_str_find_ptr(sdl->encoders, (char*)nscat, len)) != NULL) { + return enc; + } + return NULL; +} + +sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type) +{ + sdlBindingPtr binding; + + if (sdl == NULL) { + return NULL; + } + + ZEND_HASH_FOREACH_PTR(sdl->bindings, binding) { + if (binding->bindingType == type) { + return binding; + } + } ZEND_HASH_FOREACH_END(); + return NULL; +} + +sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns) +{ + sdlBindingPtr binding; + smart_str key = {0}; + + smart_str_appends(&key, ns); + smart_str_appendc(&key, ':'); + smart_str_appends(&key, name); + smart_str_0(&key); + + binding = zend_hash_find_ptr(sdl->bindings, key.s); + + smart_str_free(&key); + return binding; +} + +static int is_wsdl_element(xmlNodePtr node) +{ + if (node->ns && strcmp((char*)node->ns->href, WSDL_NAMESPACE) != 0) { + xmlAttrPtr attr; + if ((attr = get_attribute_ex(node->properties, "required", WSDL_NAMESPACE)) != NULL && + attr->children && attr->children->content && + (strcmp((char*)attr->children->content, "1") == 0 || + strcmp((char*)attr->children->content, "true") == 0)) { + soap_error1(E_ERROR, "Parsing WSDL: Unknown required WSDL extension '%s'", node->ns->href); + } + return 0; + } + return 1; +} + +void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) +{ + char *s; + size_t l1, l2; + zval context; + zval *header = NULL; + + /* check if we load xsd from the same server */ + s = strstr(ctx->sdl->source, "://"); + if (!s) return; + s = strchr(s+3, '/'); + l1 = s ? (size_t)(s - ctx->sdl->source) : strlen(ctx->sdl->source); + s = strstr((char*)uri, "://"); + if (!s) return; + s = strchr(s+3, '/'); + l2 = s ? (size_t)(s - (char*)uri) : strlen((char*)uri); + if (l1 != l2) { + /* check for http://...:80/ */ + if (l1 > 11 && + ctx->sdl->source[4] == ':' && + ctx->sdl->source[l1-3] == ':' && + ctx->sdl->source[l1-2] == '8' && + ctx->sdl->source[l1-1] == '0') { + l1 -= 3; + } + if (l2 > 11 && + uri[4] == ':' && + uri[l2-3] == ':' && + uri[l2-2] == '8' && + uri[l2-1] == '0') { + l2 -= 3; + } + /* check for https://...:443/ */ + if (l1 > 13 && + ctx->sdl->source[4] == 's' && + ctx->sdl->source[l1-4] == ':' && + ctx->sdl->source[l1-3] == '4' && + ctx->sdl->source[l1-2] == '4' && + ctx->sdl->source[l1-1] == '3') { + l1 -= 4; + } + if (l2 > 13 && + uri[4] == 's' && + uri[l2-4] == ':' && + uri[l2-3] == '4' && + uri[l2-2] == '4' && + uri[l2-1] == '3') { + l2 -= 4; + } + } + if (l1 != l2 || memcmp(ctx->sdl->source, uri, l1) != 0) { + /* another server. clear authentication credentals */ + php_libxml_switch_context(NULL, &context); + php_libxml_switch_context(&context, NULL); + if (Z_TYPE(context) != IS_UNDEF) { + zval *context_ptr = &context; + ctx->context = php_stream_context_from_zval(context_ptr, 1); + + if (ctx->context && + (header = php_stream_context_get_option(ctx->context, "http", "header")) != NULL) { + s = strstr(Z_STRVAL_P(header), "Authorization: Basic"); + if (s && (s == Z_STRVAL_P(header) || *(s-1) == '\n' || *(s-1) == '\r')) { + char *rest = strstr(s, "\r\n"); + if (rest) { + zval new_header; + + rest += 2; + ZVAL_NEW_STR(&new_header, zend_string_alloc(Z_STRLEN_P(header) - (rest - s), 0)); + memcpy(Z_STRVAL(new_header), Z_STRVAL_P(header), s - Z_STRVAL_P(header)); + memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_P(header)), rest, Z_STRLEN_P(header) - (rest - Z_STRVAL_P(header)) + 1); + ZVAL_COPY(&ctx->old_header, header); + php_stream_context_set_option(ctx->context, "http", "header", &new_header); + zval_ptr_dtor(&new_header); + } + } + } + } + } +} + +void sdl_restore_uri_credentials(sdlCtx *ctx) +{ + if (Z_TYPE(ctx->old_header) != IS_UNDEF) { + php_stream_context_set_option(ctx->context, "http", "header", &ctx->old_header); + zval_ptr_dtor(&ctx->old_header); + ZVAL_UNDEF(&ctx->old_header); + } + ctx->context = NULL; +} + +static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) +{ + sdlPtr tmpsdl = ctx->sdl; + xmlDocPtr wsdl; + xmlNodePtr root, definitions, trav; + xmlAttrPtr targetNamespace; + + if (zend_hash_str_exists(&ctx->docs, struri, strlen(struri))) { + return; + } + + sdl_set_uri_credentials(ctx, struri); + wsdl = soap_xmlParseFile(struri); + sdl_restore_uri_credentials(ctx); + + if (!wsdl) { + xmlErrorPtr xmlErrorPtr = xmlGetLastError(); + + if (xmlErrorPtr) { + soap_error2(E_ERROR, "Parsing WSDL: Couldn't load from '%s' : %s", struri, xmlErrorPtr->message); + } else { + soap_error1(E_ERROR, "Parsing WSDL: Couldn't load from '%s'", struri); + } + } + + zend_hash_str_add_ptr(&ctx->docs, struri, strlen(struri), wsdl); + + root = wsdl->children; + definitions = get_node_ex(root, "definitions", WSDL_NAMESPACE); + if (!definitions) { + if (include) { + xmlNodePtr schema = get_node_ex(root, "schema", XSD_NAMESPACE); + if (schema) { + load_schema(ctx, schema); + return; + } + } + soap_error1(E_ERROR, "Parsing WSDL: Couldn't find <definitions> in '%s'", struri); + } + + if (!include) { + targetNamespace = get_attribute(definitions->properties, "targetNamespace"); + if (targetNamespace) { + tmpsdl->target_ns = estrdup((char*)targetNamespace->children->content); + } + } + + trav = definitions->children; + while (trav != NULL) { + if (!is_wsdl_element(trav)) { + trav = trav->next; + continue; + } + if (node_is_equal(trav,"types")) { + /* TODO: Only one "types" is allowed */ + xmlNodePtr trav2 = trav->children; + + while (trav2 != NULL) { + if (node_is_equal_ex(trav2, "schema", XSD_NAMESPACE)) { + load_schema(ctx, trav2); + } else if (is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + } + trav2 = trav2->next; + } + } else if (node_is_equal(trav,"import")) { + /* TODO: namespace ??? */ + xmlAttrPtr tmp = get_attribute(trav->properties, "location"); + if (tmp) { + xmlChar *uri; + xmlChar *base = xmlNodeGetBase(trav->doc, trav); + + if (base == NULL) { + uri = xmlBuildURI(tmp->children->content, trav->doc->URL); + } else { + uri = xmlBuildURI(tmp->children->content, base); + xmlFree(base); + } + load_wsdl_ex(this_ptr, (char*)uri, ctx, 1); + xmlFree(uri); + } + + } else if (node_is_equal(trav,"message")) { + xmlAttrPtr name = get_attribute(trav->properties, "name"); + if (name && name->children && name->children->content) { + if (zend_hash_str_add_ptr(&ctx->messages, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: <message> '%s' already defined", name->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: <message> has no name attribute"); + } + + } else if (node_is_equal(trav,"portType")) { + xmlAttrPtr name = get_attribute(trav->properties, "name"); + if (name && name->children && name->children->content) { + if (zend_hash_str_add_ptr(&ctx->portTypes, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: <portType> '%s' already defined", name->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: <portType> has no name attribute"); + } + + } else if (node_is_equal(trav,"binding")) { + xmlAttrPtr name = get_attribute(trav->properties, "name"); + if (name && name->children && name->children->content) { + if (zend_hash_str_add_ptr(&ctx->bindings, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: <binding> '%s' already defined", name->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: <binding> has no name attribute"); + } + + } else if (node_is_equal(trav,"service")) { + xmlAttrPtr name = get_attribute(trav->properties, "name"); + if (name && name->children && name->children->content) { + if (zend_hash_str_add_ptr(&ctx->services, (char*)name->children->content, xmlStrlen(name->children->content), trav) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: <service> '%s' already defined", name->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: <service> has no name attribute"); + } + } else if (!node_is_equal(trav,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + trav = trav->next; + } +} + +static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xmlNodePtr header, char* wsdl_soap_namespace, int fault) +{ + xmlAttrPtr tmp; + xmlNodePtr message, part; + char *ctype; + sdlSoapBindingFunctionHeaderPtr h; + + tmp = get_attribute(header->properties, "message"); + if (!tmp) { + soap_error0(E_ERROR, "Parsing WSDL: Missing message attribute for <header>"); + } + + ctype = strrchr((char*)tmp->children->content,':'); + if (ctype == NULL) { + ctype = (char*)tmp->children->content; + } else { + ++ctype; + } + if ((message = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype))) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", tmp->children->content); + } + + tmp = get_attribute(header->properties, "part"); + if (!tmp) { + soap_error0(E_ERROR, "Parsing WSDL: Missing part attribute for <header>"); + } + part = get_node_with_attribute_ex(message->children, "part", WSDL_NAMESPACE, "name", (char*)tmp->children->content, NULL); + if (!part) { + soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", tmp->children->content); + } + + h = emalloc(sizeof(sdlSoapBindingFunctionHeader)); + memset(h, 0, sizeof(sdlSoapBindingFunctionHeader)); + h->name = estrdup((char*)tmp->children->content); + + tmp = get_attribute(header->properties, "use"); + if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) { + h->use = SOAP_ENCODED; + } else { + h->use = SOAP_LITERAL; + } + + tmp = get_attribute(header->properties, "namespace"); + if (tmp) { + h->ns = estrdup((char*)tmp->children->content); + } + + if (h->use == SOAP_ENCODED) { + tmp = get_attribute(header->properties, "encodingStyle"); + if (tmp) { + if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { + h->encodingStyle = SOAP_ENCODING_1_1; + } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { + h->encodingStyle = SOAP_ENCODING_1_2; + } else { + soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle"); + } + } + + tmp = get_attribute(part->properties, "type"); + if (tmp != NULL) { + h->encode = get_encoder_from_prefix(ctx->sdl, part, tmp->children->content); + } else { + tmp = get_attribute(part->properties, "element"); + if (tmp != NULL) { + h->element = get_element(ctx->sdl, part, tmp->children->content); + if (h->element) { + h->encode = h->element->encode; + if (!h->ns && h->element->namens) { + h->ns = estrdup(h->element->namens); + } + if (h->element->name) { + efree(h->name); + h->name = estrdup(h->element->name); + } + } + } + } + if (!fault) { + xmlNodePtr trav = header->children; + while (trav != NULL) { + if (node_is_equal_ex(trav, "headerfault", wsdl_soap_namespace)) { + sdlSoapBindingFunctionHeaderPtr hf = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 1); + smart_str key = {0}; + + if (h->headerfaults == NULL) { + h->headerfaults = emalloc(sizeof(HashTable)); + zend_hash_init(h->headerfaults, 0, NULL, delete_header, 0); + } + + if (hf->ns) { + smart_str_appends(&key,hf->ns); + smart_str_appendc(&key,':'); + } + smart_str_appends(&key,hf->name); + smart_str_0(&key); + if (zend_hash_add_ptr(h->headerfaults, key.s, hf) == NULL) { + delete_header_int(hf); + } + smart_str_free(&key); + } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + trav = trav->next; + } + } + return h; +} + +static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params) +{ + xmlNodePtr body, trav; + xmlAttrPtr tmp; + + trav = node->children; + while (trav != NULL) { + if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) { + body = trav; + + tmp = get_attribute(body->properties, "use"); + if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) { + binding->use = SOAP_LITERAL; + } else { + binding->use = SOAP_ENCODED; + } + + tmp = get_attribute(body->properties, "namespace"); + if (tmp) { + binding->ns = estrdup((char*)tmp->children->content); + } + + tmp = get_attribute(body->properties, "parts"); + if (tmp) { + HashTable ht; + char *parts = (char*)tmp->children->content; + + /* Delete all parts those are not in the "parts" attribute */ + zend_hash_init(&ht, 0, NULL, delete_parameter, 0); + while (*parts) { + sdlParamPtr param; + int found = 0; + char *end; + + while (*parts == ' ') ++parts; + if (*parts == '\0') break; + end = strchr(parts, ' '); + if (end) *end = '\0'; + ZEND_HASH_FOREACH_PTR(params, param) { + if (param->paramName && + strcmp(parts, param->paramName) == 0) { + sdlParamPtr x_param; + x_param = emalloc(sizeof(sdlParam)); + *x_param = *param; + param->paramName = NULL; + zend_hash_next_index_insert_ptr(&ht, x_param); + found = 1; + break; + } + } ZEND_HASH_FOREACH_END(); + if (!found) { + soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", parts); + } + parts += strlen(parts); + if (end) *end = ' '; + } + zend_hash_destroy(params); + *params = ht; + } + + if (binding->use == SOAP_ENCODED) { + tmp = get_attribute(body->properties, "encodingStyle"); + if (tmp) { + if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { + binding->encodingStyle = SOAP_ENCODING_1_1; + } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { + binding->encodingStyle = SOAP_ENCODING_1_2; + } else { + soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle"); + } + } + } else if (node_is_equal_ex(trav, "header", wsdl_soap_namespace)) { + sdlSoapBindingFunctionHeaderPtr h = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 0); + smart_str key = {0}; + + if (binding->headers == NULL) { + binding->headers = emalloc(sizeof(HashTable)); + zend_hash_init(binding->headers, 0, NULL, delete_header, 0); + } + + if (h->ns) { + smart_str_appends(&key,h->ns); + smart_str_appendc(&key,':'); + } + smart_str_appends(&key,h->name); + smart_str_0(&key); + if (zend_hash_add_ptr(binding->headers, key.s, h) == NULL) { + delete_header_int(h); + } + smart_str_free(&key); + } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + trav = trav->next; + } +} + +static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name) +{ + xmlNodePtr trav, part, message = NULL, tmp; + HashTable* parameters = NULL; + char *ctype; + + ctype = strrchr((char*)message_name,':'); + if (ctype == NULL) { + ctype = (char*)message_name; + } else { + ++ctype; + } + if ((tmp = zend_hash_str_find_ptr(&ctx->messages, ctype, strlen(ctype))) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", message_name); + } + message = tmp; + + parameters = emalloc(sizeof(HashTable)); + zend_hash_init(parameters, 0, NULL, delete_parameter, 0); + + trav = message->children; + while (trav != NULL) { + xmlAttrPtr element, type, name; + sdlParamPtr param; + + if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", trav->name); + } + if (node_is_equal(trav,"documentation")) { + trav = trav->next; + continue; + } + if (!node_is_equal(trav,"part")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + part = trav; + param = emalloc(sizeof(sdlParam)); + memset(param,0,sizeof(sdlParam)); + param->order = 0; + + name = get_attribute(part->properties, "name"); + if (name == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", message->name); + } + + param->paramName = estrdup((char*)name->children->content); + + type = get_attribute(part->properties, "type"); + if (type != NULL) { + param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content); + } else { + element = get_attribute(part->properties, "element"); + if (element != NULL) { + param->element = get_element(ctx->sdl, part, element->children->content); + if (param->element) { + param->encode = param->element->encode; + } + } + } + + zend_hash_next_index_insert_ptr(parameters, param); + + trav = trav->next; + } + return parameters; +} + +static sdlPtr load_wsdl(zval *this_ptr, char *struri) +{ + sdlCtx ctx; + int i,n; + + memset(&ctx,0,sizeof(ctx)); + ctx.sdl = emalloc(sizeof(sdl)); + memset(ctx.sdl, 0, sizeof(sdl)); + ctx.sdl->source = estrdup(struri); + zend_hash_init(&ctx.sdl->functions, 0, NULL, delete_function, 0); + + zend_hash_init(&ctx.docs, 0, NULL, delete_document, 0); + zend_hash_init(&ctx.messages, 0, NULL, NULL, 0); + zend_hash_init(&ctx.bindings, 0, NULL, NULL, 0); + zend_hash_init(&ctx.portTypes, 0, NULL, NULL, 0); + zend_hash_init(&ctx.services, 0, NULL, NULL, 0); + + load_wsdl_ex(this_ptr, struri, &ctx, 0); + zend_try { + + schema_pass2(&ctx); + + n = zend_hash_num_elements(&ctx.services); + if (n > 0) { + zend_hash_internal_pointer_reset(&ctx.services); + for (i = 0; i < n; i++) { + xmlNodePtr service, tmp; + xmlNodePtr trav, port; + int has_soap_port = 0; + + service = tmp = zend_hash_get_current_data_ptr(&ctx.services); + + trav = service->children; + while (trav != NULL) { + xmlAttrPtr type, name, bindingAttr, location; + xmlNodePtr portType, operation; + xmlNodePtr address, binding, trav2; + char *ctype; + sdlBindingPtr tmpbinding; + char *wsdl_soap_namespace = NULL; + + if (!is_wsdl_element(trav) || node_is_equal(trav,"documentation")) { + trav = trav->next; + continue; + } + if (!node_is_equal(trav,"port")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + + port = trav; + + tmpbinding = emalloc(sizeof(sdlBinding)); + memset(tmpbinding, 0, sizeof(sdlBinding)); + + bindingAttr = get_attribute(port->properties, "binding"); + if (bindingAttr == NULL) { + soap_error0(E_ERROR, "Parsing WSDL: No binding associated with <port>"); + } + + /* find address and figure out binding type */ + address = NULL; + trav2 = port->children; + while (trav2 != NULL) { + if (node_is_equal(trav2,"address") && trav2->ns) { + if (!strncmp((char*)trav2->ns->href, WSDL_SOAP11_NAMESPACE, sizeof(WSDL_SOAP11_NAMESPACE))) { + address = trav2; + wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE; + tmpbinding->bindingType = BINDING_SOAP; + } else if (!strncmp((char*)trav2->ns->href, WSDL_SOAP12_NAMESPACE, sizeof(WSDL_SOAP12_NAMESPACE))) { + address = trav2; + wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE; + tmpbinding->bindingType = BINDING_SOAP; + } else if (!strncmp((char*)trav2->ns->href, RPC_SOAP12_NAMESPACE, sizeof(RPC_SOAP12_NAMESPACE))) { + address = trav2; + wsdl_soap_namespace = RPC_SOAP12_NAMESPACE; + tmpbinding->bindingType = BINDING_SOAP; + } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP11_NAMESPACE, sizeof(WSDL_HTTP11_NAMESPACE))) { + address = trav2; + tmpbinding->bindingType = BINDING_HTTP; + } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP12_NAMESPACE, sizeof(WSDL_HTTP12_NAMESPACE))) { + address = trav2; + tmpbinding->bindingType = BINDING_HTTP; + } + } + if (trav2 != address && is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + } + trav2 = trav2->next; + } + if (!address || tmpbinding->bindingType == BINDING_HTTP) { + if (has_soap_port || trav->next || i < n-1) { + efree(tmpbinding); + trav = trav->next; + continue; + } else if (!address) { + soap_error0(E_ERROR, "Parsing WSDL: No address associated with <port>"); + } + } + has_soap_port = 1; + + location = get_attribute(address->properties, "location"); + if (!location) { + soap_error0(E_ERROR, "Parsing WSDL: No location associated with <port>"); + } + + tmpbinding->location = estrdup((char*)location->children->content); + + ctype = strrchr((char*)bindingAttr->children->content,':'); + if (ctype == NULL) { + ctype = (char*)bindingAttr->children->content; + } else { + ++ctype; + } + if ((tmp = zend_hash_str_find_ptr(&ctx.bindings, ctype, strlen(ctype))) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: No <binding> element with name '%s'", ctype); + } + binding = tmp; + + if (tmpbinding->bindingType == BINDING_SOAP) { + sdlSoapBindingPtr soapBinding; + xmlNodePtr soapBindingNode; + xmlAttrPtr tmp; + + soapBinding = emalloc(sizeof(sdlSoapBinding)); + memset(soapBinding, 0, sizeof(sdlSoapBinding)); + soapBinding->style = SOAP_DOCUMENT; + + soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace); + if (soapBindingNode) { + tmp = get_attribute(soapBindingNode->properties, "style"); + if (tmp && !strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) { + soapBinding->style = SOAP_RPC; + } + + tmp = get_attribute(soapBindingNode->properties, "transport"); + if (tmp) { + if (strncmp((char*)tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) { + soapBinding->transport = SOAP_TRANSPORT_HTTP; + } else { + /* try the next binding */ + efree(soapBinding); + efree(tmpbinding->location); + efree(tmpbinding); + trav = trav->next; + continue; + } + } + } + tmpbinding->bindingAttributes = (void *)soapBinding; + } + + name = get_attribute(binding->properties, "name"); + if (name == NULL) { + soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <binding>"); + } + tmpbinding->name = estrdup((char*)name->children->content); + + type = get_attribute(binding->properties, "type"); + if (type == NULL) { + soap_error0(E_ERROR, "Parsing WSDL: Missing 'type' attribute for <binding>"); + } + + ctype = strrchr((char*)type->children->content,':'); + if (ctype == NULL) { + ctype = (char*)type->children->content; + } else { + ++ctype; + } + if ((tmp = zend_hash_str_find_ptr(&ctx.portTypes, ctype, strlen(ctype))) == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing <portType> with name '%s'", name->children->content); + } + portType = tmp; + + trav2 = binding->children; + while (trav2 != NULL) { + sdlFunctionPtr function; + xmlNodePtr input, output, fault, portTypeOperation, trav3; + xmlAttrPtr op_name, paramOrder; + + if ((tmpbinding->bindingType == BINDING_SOAP && + node_is_equal_ex(trav2, "binding", wsdl_soap_namespace)) || + !is_wsdl_element(trav2) || + node_is_equal(trav2,"documentation")) { + trav2 = trav2->next; + continue; + } + if (!node_is_equal(trav2,"operation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name); + } + + operation = trav2; + + op_name = get_attribute(operation->properties, "name"); + if (op_name == NULL) { + soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <operation>"); + } + + trav3 = operation->children; + while (trav3 != NULL) { + if (tmpbinding->bindingType == BINDING_SOAP && + node_is_equal_ex(trav3, "operation", wsdl_soap_namespace)) { + } else if (is_wsdl_element(trav3) && + !node_is_equal(trav3,"input") && + !node_is_equal(trav3,"output") && + !node_is_equal(trav3,"fault") && + !node_is_equal(trav3,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav3->name); + } + trav3 = trav3->next; + } + + portTypeOperation = get_node_with_attribute_ex(portType->children, "operation", WSDL_NAMESPACE, "name", (char*)op_name->children->content, NULL); + if (portTypeOperation == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing <portType>/<operation> with name '%s'", op_name->children->content); + } + + function = emalloc(sizeof(sdlFunction)); + memset(function, 0, sizeof(sdlFunction)); + function->functionName = estrdup((char*)op_name->children->content); + + if (tmpbinding->bindingType == BINDING_SOAP) { + sdlSoapBindingFunctionPtr soapFunctionBinding; + sdlSoapBindingPtr soapBinding; + xmlNodePtr soapOperation; + xmlAttrPtr tmp; + + soapFunctionBinding = emalloc(sizeof(sdlSoapBindingFunction)); + memset(soapFunctionBinding, 0, sizeof(sdlSoapBindingFunction)); + soapBinding = (sdlSoapBindingPtr)tmpbinding->bindingAttributes; + soapFunctionBinding->style = soapBinding->style; + + soapOperation = get_node_ex(operation->children, "operation", wsdl_soap_namespace); + if (soapOperation) { + tmp = get_attribute(soapOperation->properties, "soapAction"); + if (tmp) { + soapFunctionBinding->soapAction = estrdup((char*)tmp->children->content); + } + + tmp = get_attribute(soapOperation->properties, "style"); + if (tmp) { + if (!strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) { + soapFunctionBinding->style = SOAP_RPC; + } else { + soapFunctionBinding->style = SOAP_DOCUMENT; + } + } else { + soapFunctionBinding->style = soapBinding->style; + } + } + + function->bindingAttributes = (void *)soapFunctionBinding; + } + + input = get_node_ex(portTypeOperation->children, "input", WSDL_NAMESPACE); + if (input != NULL) { + xmlAttrPtr message; + + message = get_attribute(input->properties, "message"); + if (message == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing name for <input> of '%s'", op_name->children->content); + } + function->requestParameters = wsdl_message(&ctx, message->children->content); + +/* FIXME + xmlAttrPtr name = get_attribute(input->properties, "name"); + if (name != NULL) { + function->requestName = estrdup(name->children->content); + } else { +*/ + { + function->requestName = estrdup(function->functionName); + } + + if (tmpbinding->bindingType == BINDING_SOAP) { + input = get_node_ex(operation->children, "input", WSDL_NAMESPACE); + if (input != NULL) { + sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes; + wsdl_soap_binding_body(&ctx, input, wsdl_soap_namespace, &soapFunctionBinding->input, function->requestParameters); + } + } + } + + output = get_node_ex(portTypeOperation->children, "output", WSDL_NAMESPACE); + if (output != NULL) { + xmlAttrPtr message; + + message = get_attribute(output->properties, "message"); + if (message == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content); + } + function->responseParameters = wsdl_message(&ctx, message->children->content); + +/* FIXME + xmlAttrPtr name = get_attribute(output->properties, "name"); + if (name != NULL) { + function->responseName = estrdup(name->children->content); + } else if (input == NULL) { + function->responseName = estrdup(function->functionName); + } else { +*/ + { + int len = strlen(function->functionName); + function->responseName = emalloc(len + sizeof("Response")); + memcpy(function->responseName, function->functionName, len); + memcpy(function->responseName+len, "Response", sizeof("Response")); + } + + if (tmpbinding->bindingType == BINDING_SOAP) { + output = get_node_ex(operation->children, "output", WSDL_NAMESPACE); + if (output != NULL) { + sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes; + wsdl_soap_binding_body(&ctx, output, wsdl_soap_namespace, &soapFunctionBinding->output, function->responseParameters); + } + } + } + + paramOrder = get_attribute(portTypeOperation->properties, "parameterOrder"); + if (paramOrder) { + /* FIXME: */ + } + + fault = portTypeOperation->children; + while (fault != NULL) { + if (node_is_equal_ex(fault, "fault", WSDL_NAMESPACE)) { + xmlAttrPtr message, name; + sdlFaultPtr f; + + name = get_attribute(fault->properties, "name"); + if (name == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing name for <fault> of '%s'", op_name->children->content); + } + message = get_attribute(fault->properties, "message"); + if (message == NULL) { + soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content); + } + + f = emalloc(sizeof(sdlFault)); + memset(f, 0, sizeof(sdlFault)); + + f->name = estrdup((char*)name->children->content); + f->details = wsdl_message(&ctx, message->children->content); + if (f->details == NULL || zend_hash_num_elements(f->details) > 1) { + soap_error1(E_ERROR, "Parsing WSDL: The fault message '%s' must have a single part", message->children->content); + } + + if (tmpbinding->bindingType == BINDING_SOAP) { + xmlNodePtr soap_fault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL); + if (soap_fault != NULL) { + xmlNodePtr trav = soap_fault->children; + while (trav != NULL) { + if (node_is_equal_ex(trav, "fault", wsdl_soap_namespace)) { + xmlAttrPtr tmp; + sdlSoapBindingFunctionFaultPtr binding; + + binding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault)); + memset(f->bindingAttributes, 0, sizeof(sdlSoapBindingFunctionFault)); + + tmp = get_attribute(trav->properties, "use"); + if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) { + binding->use = SOAP_ENCODED; + } else { + binding->use = SOAP_LITERAL; + } + + tmp = get_attribute(trav->properties, "namespace"); + if (tmp) { + binding->ns = estrdup((char*)tmp->children->content); + } + + if (binding->use == SOAP_ENCODED) { + tmp = get_attribute(trav->properties, "encodingStyle"); + if (tmp) { + if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) { + binding->encodingStyle = SOAP_ENCODING_1_1; + } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) { + binding->encodingStyle = SOAP_ENCODING_1_2; + } else { + soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle"); + } + } + } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) { + soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name); + } + trav = trav->next; + } + } + } + if (function->faults == NULL) { + function->faults = emalloc(sizeof(HashTable)); + zend_hash_init(function->faults, 0, NULL, delete_fault, 0); + } + if (zend_hash_str_add_ptr(function->faults, f->name, strlen(f->name), f) == NULL) { + soap_error2(E_ERROR, "Parsing WSDL: <fault> with name '%s' already defined in '%s'", f->name, op_name->children->content); + } + } + fault = fault->next; + } + + function->binding = tmpbinding; + + { + char *tmp = estrdup(function->functionName); + int len = strlen(tmp); + + if (zend_hash_str_add_ptr(&ctx.sdl->functions, php_strtolower(tmp, len), len, function) == NULL) { + zend_hash_next_index_insert_ptr(&ctx.sdl->functions, function); + } + efree(tmp); + if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) { + if (ctx.sdl->requests == NULL) { + ctx.sdl->requests = emalloc(sizeof(HashTable)); + zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 0); + } + tmp = estrdup(function->requestName); + len = strlen(tmp); + zend_hash_str_add_ptr(ctx.sdl->requests, php_strtolower(tmp, len), len, function); + efree(tmp); + } + } + trav2 = trav2->next; + } + + if (!ctx.sdl->bindings) { + ctx.sdl->bindings = emalloc(sizeof(HashTable)); + zend_hash_init(ctx.sdl->bindings, 0, NULL, delete_binding, 0); + } + + if (!zend_hash_str_add_ptr(ctx.sdl->bindings, tmpbinding->name, strlen(tmpbinding->name), tmpbinding)) { + zend_hash_next_index_insert_ptr(ctx.sdl->bindings, tmpbinding); + } + trav= trav->next; + } + + zend_hash_move_forward(&ctx.services); + } + } else { + soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service"); + } + + if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) { + soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL."); + } + + } zend_catch { + /* Avoid persistent memory leak. */ + zend_hash_destroy(&ctx.docs); + zend_bailout(); + } zend_end_try(); + + zend_hash_destroy(&ctx.messages); + zend_hash_destroy(&ctx.bindings); + zend_hash_destroy(&ctx.portTypes); + zend_hash_destroy(&ctx.services); + zend_hash_destroy(&ctx.docs); + + return ctx.sdl; +} + +#define WSDL_CACHE_VERSION 0x10 + +#define WSDL_CACHE_GET(ret,type,buf) memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type); +#define WSDL_CACHE_GET_INT(ret,buf) ret = ((unsigned char)(*buf)[0])|((unsigned char)(*buf)[1]<<8)|((unsigned char)(*buf)[2]<<16)|((unsigned)(*buf)[3]<<24); *buf += 4; +#define WSDL_CACHE_GET_1(ret,type,buf) ret = (type)(**buf); (*buf)++; +#define WSDL_CACHE_GET_N(ret,n,buf) memcpy(ret,*buf,n); *buf += n; +#define WSDL_CACHE_SKIP(n,buf) *buf += n; + +#define WSDL_CACHE_PUT_INT(val,buf) smart_str_appendc(buf,(char)(val & 0xff)); \ + smart_str_appendc(buf,(char)((val >> 8) & 0xff)); \ + smart_str_appendc(buf,(char)((val >> 16) & 0xff)); \ + smart_str_appendc(buf,(char)((val >> 24) & 0xff)); +#define WSDL_CACHE_PUT_1(val,buf) smart_str_appendc(buf,val); +#define WSDL_CACHE_PUT_N(val,n,buf) smart_str_appendl(buf,(char*)val,n); + +#define WSDL_NO_STRING_MARKER 0x7fffffff + +static char* sdl_deserialize_string(char **in) +{ + char *s; + int len; + + WSDL_CACHE_GET_INT(len, in); + if (len == WSDL_NO_STRING_MARKER) { + return NULL; + } else { + s = emalloc(len+1); + WSDL_CACHE_GET_N(s, len, in); + s[len] = '\0'; + return s; + } +} + +static void sdl_deserialize_key(HashTable* ht, void* data, char **in) +{ + int len; + + WSDL_CACHE_GET_INT(len, in); + if (len == WSDL_NO_STRING_MARKER) { + zend_hash_next_index_insert_ptr(ht, data); + } else { + zend_hash_str_add_ptr(ht, *in, len, data); + WSDL_CACHE_SKIP(len, in); + } +} + +static void sdl_deserialize_attribute(sdlAttributePtr attr, encodePtr *encoders, char **in) +{ + int i; + + attr->name = sdl_deserialize_string(in); + attr->namens = sdl_deserialize_string(in); + attr->ref = sdl_deserialize_string(in); + attr->def = sdl_deserialize_string(in); + attr->fixed = sdl_deserialize_string(in); + WSDL_CACHE_GET_1(attr->form, sdlForm, in); + WSDL_CACHE_GET_1(attr->use, sdlUse, in); + WSDL_CACHE_GET_INT(i, in); + attr->encode = encoders[i]; + WSDL_CACHE_GET_INT(i, in); + if (i > 0) { + attr->extraAttributes = emalloc(sizeof(HashTable)); + zend_hash_init(attr->extraAttributes, i, NULL, delete_extra_attribute, 0); + while (i > 0) { + sdlExtraAttributePtr x = emalloc(sizeof(sdlExtraAttribute)); + sdl_deserialize_key(attr->extraAttributes, x, in); + x->ns = sdl_deserialize_string(in); + x->val = sdl_deserialize_string(in); + --i; + } + } +} + +static sdlRestrictionIntPtr sdl_deserialize_resriction_int(char **in) +{ + if (**in == 1) { + sdlRestrictionIntPtr x = emalloc(sizeof(sdlRestrictionInt)); + WSDL_CACHE_SKIP(1, in); + WSDL_CACHE_GET_INT(x->value, in); + WSDL_CACHE_GET_1(x->fixed, char, in); + return x; + } else { + WSDL_CACHE_SKIP(1, in); + return NULL; + } +} + +static sdlRestrictionCharPtr sdl_deserialize_resriction_char(char **in) +{ + if (**in == 1) { + sdlRestrictionCharPtr x = emalloc(sizeof(sdlRestrictionChar)); + WSDL_CACHE_SKIP(1, in); + x->value = sdl_deserialize_string(in); + WSDL_CACHE_GET_1(x->fixed, char, in); + return x; + } else { + WSDL_CACHE_SKIP(1, in); + return NULL; + } +} + +static sdlContentModelPtr sdl_deserialize_model(sdlTypePtr *types, sdlTypePtr *elements, char **in) +{ + int i; + sdlContentModelPtr model = emalloc(sizeof(sdlContentModel)); + + WSDL_CACHE_GET_1(model->kind, sdlContentKind, in); + WSDL_CACHE_GET_INT(model->min_occurs, in); + WSDL_CACHE_GET_INT(model->max_occurs, in); + switch (model->kind) { + case XSD_CONTENT_ELEMENT: + WSDL_CACHE_GET_INT(i, in); + model->u.element = elements[i]; + break; + case XSD_CONTENT_SEQUENCE: + case XSD_CONTENT_ALL: + case XSD_CONTENT_CHOICE: + WSDL_CACHE_GET_INT(i, in); + model->u.content = emalloc(sizeof(HashTable)); + zend_hash_init(model->u.content, i, NULL, delete_model, 0); + while (i > 0) { + sdlContentModelPtr x = sdl_deserialize_model(types, elements, in); + zend_hash_next_index_insert_ptr(model->u.content, x); + i--; + } + break; + case XSD_CONTENT_GROUP_REF: + model->u.group_ref = sdl_deserialize_string(in); + break; + case XSD_CONTENT_GROUP: + WSDL_CACHE_GET_INT(i, in); + model->u.group = types[i]; + break; + default: + break; + } + return model; +} + +static void sdl_deserialize_type(sdlTypePtr type, sdlTypePtr *types, encodePtr *encoders, char **in) +{ + int i; + sdlTypePtr *elements = NULL; + + WSDL_CACHE_GET_1(type->kind, sdlTypeKind, in); + type->name = sdl_deserialize_string(in); + type->namens = sdl_deserialize_string(in); + type->def = sdl_deserialize_string(in); + type->fixed = sdl_deserialize_string(in); + type->ref = sdl_deserialize_string(in); + WSDL_CACHE_GET_1(type->nillable, char, in); + WSDL_CACHE_GET_1(type->form, sdlForm, in); + + WSDL_CACHE_GET_INT(i, in); + type->encode = encoders[i]; + + if (**in == 1) { + WSDL_CACHE_SKIP(1, in); + type->restrictions = emalloc(sizeof(sdlRestrictions)); + /*memset(type->restrictions, 0, sizeof(sdlRestrictions));*/ + type->restrictions->minExclusive = sdl_deserialize_resriction_int(in); + type->restrictions->minInclusive = sdl_deserialize_resriction_int(in); + type->restrictions->maxExclusive = sdl_deserialize_resriction_int(in); + type->restrictions->maxInclusive = sdl_deserialize_resriction_int(in); + type->restrictions->totalDigits = sdl_deserialize_resriction_int(in); + type->restrictions->fractionDigits = sdl_deserialize_resriction_int(in); + type->restrictions->length = sdl_deserialize_resriction_int(in); + type->restrictions->minLength = sdl_deserialize_resriction_int(in); + type->restrictions->maxLength = sdl_deserialize_resriction_int(in); + type->restrictions->whiteSpace = sdl_deserialize_resriction_char(in); + type->restrictions->pattern = sdl_deserialize_resriction_char(in); + WSDL_CACHE_GET_INT(i, in); + if (i > 0) { + type->restrictions->enumeration = emalloc(sizeof(HashTable)); + zend_hash_init(type->restrictions->enumeration, i, NULL, delete_restriction_var_char, 0); + while (i > 0) { + sdlRestrictionCharPtr x = sdl_deserialize_resriction_char(in); + sdl_deserialize_key(type->restrictions->enumeration, x, in); + --i; + } + } else { + type->restrictions->enumeration = NULL; + } + } else { + WSDL_CACHE_SKIP(1, in); + } + + WSDL_CACHE_GET_INT(i, in); + if (i > 0) { + elements = safe_emalloc((i+1), sizeof(sdlTypePtr), 0); + elements[0] = NULL; + type->elements = emalloc(sizeof(HashTable)); + zend_hash_init(type->elements, i, NULL, delete_type, 0); + while (i > 0) { + sdlTypePtr t = emalloc(sizeof(sdlType)); + memset(t, 0, sizeof(sdlType)); + sdl_deserialize_key(type->elements, t, in); + sdl_deserialize_type(t, types, encoders, in); + elements[i] = t; + --i; + } + } + + WSDL_CACHE_GET_INT(i, in); + if (i > 0) { + type->attributes = emalloc(sizeof(HashTable)); + zend_hash_init(type->attributes, i, NULL, delete_attribute, 0); + while (i > 0) { + sdlAttributePtr attr = emalloc(sizeof(sdlAttribute)); + memset(attr, 0, sizeof(sdlAttribute)); + sdl_deserialize_key(type->attributes, attr, in); + sdl_deserialize_attribute(attr, encoders, in); + --i; + } + } + + if (**in != 0) { + WSDL_CACHE_SKIP(1, in); + type->model = sdl_deserialize_model(types, elements, in); + } else { + WSDL_CACHE_SKIP(1, in); + } + if (elements != NULL) { + efree(elements); + } +} + +static void sdl_deserialize_encoder(encodePtr enc, sdlTypePtr *types, char **in) +{ + int i; + + WSDL_CACHE_GET_INT(enc->details.type, in); + enc->details.type_str = sdl_deserialize_string(in); + enc->details.ns = sdl_deserialize_string(in); + WSDL_CACHE_GET_INT(i, in); + enc->details.sdl_type = types[i]; + enc->to_xml = sdl_guess_convert_xml; + enc->to_zval = sdl_guess_convert_zval; + + if (enc->details.sdl_type == NULL) { + int ns_len = strlen(enc->details.ns); + int type_len = strlen(enc->details.type_str); + + if (((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 && + memcmp(enc->details.ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) || + (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 && + memcmp(enc->details.ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) { + char *enc_nscat; + int enc_ns_len; + int enc_len; + encodePtr real_enc; + + enc_ns_len = sizeof(XSD_NAMESPACE)-1; + enc_len = enc_ns_len + type_len + 1; + enc_nscat = emalloc(enc_len + 1); + memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1); + enc_nscat[enc_ns_len] = ':'; + memcpy(enc_nscat+enc_ns_len+1, enc->details.type_str, type_len); + enc_nscat[enc_len] = '\0'; + + real_enc = get_encoder_ex(NULL, enc_nscat, enc_len); + efree(enc_nscat); + if (real_enc) { + enc->to_zval = real_enc->to_zval; + enc->to_xml = real_enc->to_xml; + } + } + } +} + +static void sdl_deserialize_soap_body(sdlSoapBindingFunctionBodyPtr body, encodePtr *encoders, sdlTypePtr *types, char **in) +{ + int i, j, n; + + WSDL_CACHE_GET_1(body->use, sdlEncodingUse, in); + if (body->use == SOAP_ENCODED) { + WSDL_CACHE_GET_1(body->encodingStyle, sdlRpcEncodingStyle, in); + } else { + body->encodingStyle = SOAP_ENCODING_DEFAULT; + } + body->ns = sdl_deserialize_string(in); + WSDL_CACHE_GET_INT(i, in); + if (i > 0) { + body->headers = emalloc(sizeof(HashTable)); + zend_hash_init(body->headers, i, NULL, delete_header, 0); + while (i > 0) { + sdlSoapBindingFunctionHeaderPtr tmp = emalloc(sizeof(sdlSoapBindingFunctionHeader)); + memset(tmp, 0, sizeof(sdlSoapBindingFunctionHeader)); + sdl_deserialize_key(body->headers, tmp, in); + WSDL_CACHE_GET_1(tmp->use, sdlEncodingUse, in); + if (tmp->use == SOAP_ENCODED) { + WSDL_CACHE_GET_1(tmp->encodingStyle, sdlRpcEncodingStyle, in); + } else { + tmp->encodingStyle = SOAP_ENCODING_DEFAULT; + } + tmp->name = sdl_deserialize_string(in); + tmp->ns = sdl_deserialize_string(in); + WSDL_CACHE_GET_INT(n, in); + tmp->encode = encoders[n]; + WSDL_CACHE_GET_INT(n, in); + tmp->element = types[n]; + --i; + WSDL_CACHE_GET_INT(j, in); + if (j > 0) { + tmp->headerfaults = emalloc(sizeof(HashTable)); + zend_hash_init(tmp->headerfaults, i, NULL, delete_header, 0); + while (j > 0) { + sdlSoapBindingFunctionHeaderPtr tmp2 = emalloc(sizeof(sdlSoapBindingFunctionHeader)); + memset(tmp2, 0, sizeof(sdlSoapBindingFunctionHeader)); + sdl_deserialize_key(tmp->headerfaults, tmp2, in); + WSDL_CACHE_GET_1(tmp2->use, sdlEncodingUse, in); + if (tmp2->use == SOAP_ENCODED) { + WSDL_CACHE_GET_1(tmp2->encodingStyle, sdlRpcEncodingStyle, in); + } else { + tmp2->encodingStyle = SOAP_ENCODING_DEFAULT; + } + tmp2->name = sdl_deserialize_string(in); + tmp2->ns = sdl_deserialize_string(in); + WSDL_CACHE_GET_INT(n, in); + tmp2->encode = encoders[n]; + WSDL_CACHE_GET_INT(n, in); + tmp2->element = types[n]; + --j; + } + } + } + } +} + +static HashTable* sdl_deserialize_parameters(encodePtr *encoders, sdlTypePtr *types, char **in) +{ + int i, n; + HashTable *ht; + + WSDL_CACHE_GET_INT(i, in); + if (i == 0) {return NULL;} + ht = emalloc(sizeof(HashTable)); + zend_hash_init(ht, i, NULL, delete_parameter, 0); + while (i > 0) { + sdlParamPtr param = emalloc(sizeof(sdlParam)); + sdl_deserialize_key(ht, param, in); + param->paramName = sdl_deserialize_string(in); + WSDL_CACHE_GET_INT(param->order, in); + WSDL_CACHE_GET_INT(n, in); + param->encode = encoders[n]; + WSDL_CACHE_GET_INT(n, in); + param->element = types[n]; + --i; + } + return ht; +} + +static sdlPtr get_sdl_from_cache(const char *fn, const char *uri, time_t t, time_t *cached) +{ + sdlPtr sdl; + time_t old_t; + int i, num_groups, num_types, num_elements, num_encoders, num_bindings, num_func; + sdlFunctionPtr *functions = NULL; + sdlBindingPtr *bindings; + sdlTypePtr *types; + encodePtr *encoders; + const encode *enc; + + int f; + struct stat st; + char *in, *buf; + + f = open(fn, O_RDONLY|O_BINARY); + if (f < 0) { + return NULL; + } + if (fstat(f, &st) != 0) { + close(f); + return NULL; + } + buf = in = emalloc(st.st_size); + if (read(f, in, st.st_size) != st.st_size) { + close(f); + efree(in); + return NULL; + } + close(f); + + if (strncmp(in,"wsdl",4) != 0 || in[4] != WSDL_CACHE_VERSION || in[5] != '\0') { + unlink(fn); + efree(buf); + return NULL; + } + in += 6; + + WSDL_CACHE_GET(old_t, time_t, &in); + if (old_t < t) { + unlink(fn); + efree(buf); + return NULL; + } + *cached = old_t; + + WSDL_CACHE_GET_INT(i, &in); + if (i == 0 && strncmp(in, uri, i) != 0) { + unlink(fn); + efree(buf); + return NULL; + } + WSDL_CACHE_SKIP(i, &in); + + sdl = emalloc(sizeof(*sdl)); + memset(sdl, 0, sizeof(*sdl)); + + sdl->source = sdl_deserialize_string(&in); + sdl->target_ns = sdl_deserialize_string(&in); + + WSDL_CACHE_GET_INT(num_groups, &in); + WSDL_CACHE_GET_INT(num_types, &in); + WSDL_CACHE_GET_INT(num_elements, &in); + WSDL_CACHE_GET_INT(num_encoders, &in); + + i = num_groups+num_types+num_elements; + types = safe_emalloc((i+1), sizeof(sdlTypePtr), 0); + types[0] = NULL; + while (i > 0) { + types[i] = emalloc(sizeof(sdlType)); + memset(types[i], 0, sizeof(sdlType)); + i--; + } + + i = num_encoders; + enc = defaultEncoding; + while (enc->details.type != END_KNOWN_TYPES) { + i++; enc++; + } + encoders = safe_emalloc((i+1), sizeof(encodePtr), 0); + i = num_encoders; + encoders[0] = NULL; + while (i > 0) { + encoders[i] = emalloc(sizeof(encode)); + memset(encoders[i], 0, sizeof(encode)); + i--; + } + i = num_encoders; + enc = defaultEncoding; + while (enc->details.type != END_KNOWN_TYPES) { + encoders[++i] = (encodePtr)enc++; + } + + i = 1; + if (num_groups > 0) { + sdl->groups = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->groups, num_groups, NULL, delete_type, 0); + while (i < num_groups+1) { + sdl_deserialize_key(sdl->groups, types[i], &in); + sdl_deserialize_type(types[i], types, encoders, &in); + i++; + } + } + + if (num_types > 0) { + sdl->types = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->types, num_types, NULL, delete_type, 0); + while (i < num_groups+num_types+1) { + sdl_deserialize_key(sdl->types, types[i], &in); + sdl_deserialize_type(types[i], types, encoders, &in); + i++; + } + } + + if (num_elements > 0) { + sdl->elements = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->elements, num_elements, NULL, delete_type, 0); + while (i < num_groups+num_types+num_elements+1) { + sdl_deserialize_key(sdl->elements, types[i], &in); + sdl_deserialize_type(types[i], types, encoders, &in); + i++; + } + } + + i = 1; + if (num_encoders > 0) { + sdl->encoders = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->encoders, num_encoders, NULL, delete_encoder, 0); + while (i < num_encoders+1) { + sdl_deserialize_key(sdl->encoders, encoders[i], &in); + sdl_deserialize_encoder(encoders[i], types, &in); + i++; + } + } + + /* deserialize bindings */ + WSDL_CACHE_GET_INT(num_bindings, &in); + bindings = safe_emalloc(num_bindings, sizeof(sdlBindingPtr), 0); + if (num_bindings > 0) { + sdl->bindings = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->bindings, num_bindings, NULL, delete_binding, 0); + for (i = 0; i < num_bindings; i++) { + sdlBindingPtr binding = emalloc(sizeof(sdlBinding)); + memset(binding, 0, sizeof(sdlBinding)); + sdl_deserialize_key(sdl->bindings, binding, &in); + binding->name = sdl_deserialize_string(&in); + binding->location = sdl_deserialize_string(&in); + WSDL_CACHE_GET_1(binding->bindingType,sdlBindingType,&in); + if (binding->bindingType == BINDING_SOAP && *in != 0) { + sdlSoapBindingPtr soap_binding = binding->bindingAttributes = emalloc(sizeof(sdlSoapBinding)); + WSDL_CACHE_GET_1(soap_binding->style,sdlEncodingStyle,&in); + WSDL_CACHE_GET_1(soap_binding->transport,sdlTransport,&in); + } else { + WSDL_CACHE_SKIP(1,&in); + } + bindings[i] = binding; + } + } + + /* deserialize functions */ + WSDL_CACHE_GET_INT(num_func, &in); + zend_hash_init(&sdl->functions, num_func, NULL, delete_function, 0); + if (num_func > 0) { + functions = safe_emalloc(num_func, sizeof(sdlFunctionPtr), 0); + for (i = 0; i < num_func; i++) { + int binding_num, num_faults; + sdlFunctionPtr func = emalloc(sizeof(sdlFunction)); + sdl_deserialize_key(&sdl->functions, func, &in); + func->functionName = sdl_deserialize_string(&in); + func->requestName = sdl_deserialize_string(&in); + func->responseName = sdl_deserialize_string(&in); + + WSDL_CACHE_GET_INT(binding_num, &in); + if (binding_num == 0) { + func->binding = NULL; + } else { + func->binding = bindings[binding_num-1]; + } + if (func->binding && func->binding->bindingType == BINDING_SOAP && *in != 0) { + sdlSoapBindingFunctionPtr binding = func->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunction)); + memset(binding, 0, sizeof(sdlSoapBindingFunction)); + WSDL_CACHE_GET_1(binding->style,sdlEncodingStyle,&in); + binding->soapAction = sdl_deserialize_string(&in); + sdl_deserialize_soap_body(&binding->input, encoders, types, &in); + sdl_deserialize_soap_body(&binding->output, encoders, types, &in); + } else { + WSDL_CACHE_SKIP(1, &in); + func->bindingAttributes = NULL; + } + + func->requestParameters = sdl_deserialize_parameters(encoders, types, &in); + func->responseParameters = sdl_deserialize_parameters(encoders, types, &in); + + WSDL_CACHE_GET_INT(num_faults, &in); + if (num_faults > 0) { + int j; + + func->faults = emalloc(sizeof(HashTable)); + zend_hash_init(func->faults, num_faults, NULL, delete_fault, 0); + + for (j = 0; j < num_faults; j++) { + sdlFaultPtr fault = emalloc(sizeof(sdlFault)); + + sdl_deserialize_key(func->faults, fault, &in); + fault->name =sdl_deserialize_string(&in); + fault->details =sdl_deserialize_parameters(encoders, types, &in); + if (*in != 0) { + sdlSoapBindingFunctionFaultPtr binding = fault->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault)); + memset(binding, 0, sizeof(sdlSoapBindingFunctionFault)); + WSDL_CACHE_GET_1(binding->use,sdlEncodingUse,&in); + if (binding->use == SOAP_ENCODED) { + WSDL_CACHE_GET_1(binding->encodingStyle, sdlRpcEncodingStyle, &in); + } else { + binding->encodingStyle = SOAP_ENCODING_DEFAULT; + } + binding->ns = sdl_deserialize_string(&in); + } else { + WSDL_CACHE_SKIP(1, &in); + fault->bindingAttributes = NULL; + } + } + } else { + func->faults = NULL; + } + functions[i] = func; + } + } + + /* deserialize requests */ + WSDL_CACHE_GET_INT(i, &in); + if (i > 0) { + sdl->requests = emalloc(sizeof(HashTable)); + zend_hash_init(sdl->requests, i, NULL, NULL, 0); + while (i > 0) { + int function_num; + + WSDL_CACHE_GET_INT(function_num, &in); + sdl_deserialize_key(sdl->requests, functions[function_num-1], &in); + i--; + } + } + + if (functions) { + efree(functions); + } + efree(bindings); + efree(encoders); + efree(types); + efree(buf); + return sdl; +} + +static void sdl_serialize_string(const char *str, smart_str *out) +{ + if (str) { + int i = strlen(str); + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + WSDL_CACHE_PUT_N(str, i, out); + } + } else { + WSDL_CACHE_PUT_INT(WSDL_NO_STRING_MARKER, out); + } +} + +// TODO: refactor it +static void sdl_serialize_key(zend_string *key, smart_str *out) +{ + if (key) { + WSDL_CACHE_PUT_INT(ZSTR_LEN(key), out); + WSDL_CACHE_PUT_N(ZSTR_VAL(key), ZSTR_LEN(key), out); + } else { + WSDL_CACHE_PUT_INT(WSDL_NO_STRING_MARKER, out); + } +} + +static void sdl_serialize_encoder_ref(encodePtr enc, HashTable *tmp_encoders, smart_str *out) { + if (enc) { + zval *encoder_num; + if ((encoder_num = zend_hash_str_find(tmp_encoders, (char*)&enc, sizeof(enc))) != 0) { + WSDL_CACHE_PUT_INT(Z_LVAL_P(encoder_num), out); + } else { + WSDL_CACHE_PUT_INT(0, out); + } + } else { + WSDL_CACHE_PUT_INT(0, out); + } +} + +static void sdl_serialize_type_ref(sdlTypePtr type, HashTable *tmp_types, smart_str *out) { + if (type) { + zval *type_num; + if ((type_num = zend_hash_str_find(tmp_types, (char*)&type, sizeof(type))) != NULL) { + WSDL_CACHE_PUT_INT(Z_LVAL_P(type_num), out); + } else { + WSDL_CACHE_PUT_INT(0, out); + } + } else { + WSDL_CACHE_PUT_INT(0,out); + } +} + +static void sdl_serialize_attribute(sdlAttributePtr attr, HashTable *tmp_encoders, smart_str *out) +{ + int i; + + sdl_serialize_string(attr->name, out); + sdl_serialize_string(attr->namens, out); + sdl_serialize_string(attr->ref, out); + sdl_serialize_string(attr->def, out); + sdl_serialize_string(attr->fixed, out); + WSDL_CACHE_PUT_1(attr->form, out); + WSDL_CACHE_PUT_1(attr->use, out); + sdl_serialize_encoder_ref(attr->encode, tmp_encoders, out); + if (attr->extraAttributes) { + i = zend_hash_num_elements(attr->extraAttributes); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlExtraAttributePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_string(tmp->ns, out); + sdl_serialize_string(tmp->val, out); + } ZEND_HASH_FOREACH_END(); + } +} + +static void sdl_serialize_model(sdlContentModelPtr model, HashTable *tmp_types, HashTable *tmp_elements, smart_str *out) +{ + WSDL_CACHE_PUT_1(model->kind, out); + WSDL_CACHE_PUT_INT(model->min_occurs, out); + WSDL_CACHE_PUT_INT(model->max_occurs, out); + switch (model->kind) { + case XSD_CONTENT_ELEMENT: + sdl_serialize_type_ref(model->u.element, tmp_elements, out); + break; + case XSD_CONTENT_SEQUENCE: + case XSD_CONTENT_ALL: + case XSD_CONTENT_CHOICE: { + sdlContentModelPtr tmp; + int i = zend_hash_num_elements(model->u.content); + + WSDL_CACHE_PUT_INT(i, out); + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + sdl_serialize_model(tmp, tmp_types, tmp_elements, out); + } ZEND_HASH_FOREACH_END(); + } + break; + case XSD_CONTENT_GROUP_REF: + sdl_serialize_string(model->u.group_ref,out); + break; + case XSD_CONTENT_GROUP: + sdl_serialize_type_ref(model->u.group, tmp_types, out); + break; + default: + break; + } +} + +static void sdl_serialize_resriction_int(sdlRestrictionIntPtr x, smart_str *out) +{ + if (x) { + WSDL_CACHE_PUT_1(1, out); + WSDL_CACHE_PUT_INT(x->value, out); + WSDL_CACHE_PUT_1(x->fixed, out); + } else { + WSDL_CACHE_PUT_1(0, out); + } +} + +static void sdl_serialize_resriction_char(sdlRestrictionCharPtr x, smart_str *out) +{ + if (x) { + WSDL_CACHE_PUT_1(1, out); + sdl_serialize_string(x->value, out); + WSDL_CACHE_PUT_1(x->fixed, out); + } else { + WSDL_CACHE_PUT_1(0, out); + } +} + +static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out) +{ + int i; + HashTable *tmp_elements = NULL; + + WSDL_CACHE_PUT_1(type->kind, out); + sdl_serialize_string(type->name, out); + sdl_serialize_string(type->namens, out); + sdl_serialize_string(type->def, out); + sdl_serialize_string(type->fixed, out); + sdl_serialize_string(type->ref, out); + WSDL_CACHE_PUT_1(type->nillable, out); + WSDL_CACHE_PUT_1(type->form, out); + sdl_serialize_encoder_ref(type->encode, tmp_encoders, out); + + if (type->restrictions) { + WSDL_CACHE_PUT_1(1, out); + sdl_serialize_resriction_int(type->restrictions->minExclusive,out); + sdl_serialize_resriction_int(type->restrictions->minInclusive,out); + sdl_serialize_resriction_int(type->restrictions->maxExclusive,out); + sdl_serialize_resriction_int(type->restrictions->maxInclusive,out); + sdl_serialize_resriction_int(type->restrictions->totalDigits,out); + sdl_serialize_resriction_int(type->restrictions->fractionDigits,out); + sdl_serialize_resriction_int(type->restrictions->length,out); + sdl_serialize_resriction_int(type->restrictions->minLength,out); + sdl_serialize_resriction_int(type->restrictions->maxLength,out); + sdl_serialize_resriction_char(type->restrictions->whiteSpace,out); + sdl_serialize_resriction_char(type->restrictions->pattern,out); + if (type->restrictions->enumeration) { + i = zend_hash_num_elements(type->restrictions->enumeration); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlRestrictionCharPtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { + sdl_serialize_resriction_char(tmp, out); + sdl_serialize_key(key, out); + } ZEND_HASH_FOREACH_END(); + } + } else { + WSDL_CACHE_PUT_1(0, out); + } + if (type->elements) { + i = zend_hash_num_elements(type->elements); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlTypePtr tmp; + zend_string *key; + zval zv; + + tmp_elements = emalloc(sizeof(HashTable)); + zend_hash_init(tmp_elements, i, NULL, NULL, 0); + + ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_type(tmp, tmp_encoders, tmp_types, out); + ZVAL_LONG(&zv, i); + zend_hash_str_add(tmp_elements, (char*)&tmp, sizeof(tmp), &zv); + i--; + } ZEND_HASH_FOREACH_END(); + } + + if (type->attributes) { + i = zend_hash_num_elements(type->attributes); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlAttributePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_attribute(tmp, tmp_encoders, out); + } ZEND_HASH_FOREACH_END(); + } + if (type->model) { + WSDL_CACHE_PUT_1(1, out); + sdl_serialize_model(type->model, tmp_types, tmp_elements, out); + } else { + WSDL_CACHE_PUT_1(0, out); + } + if (tmp_elements != NULL) { + zend_hash_destroy(tmp_elements); + efree(tmp_elements); + } +} + +static void sdl_serialize_encoder(encodePtr enc, HashTable *tmp_types, smart_str *out) +{ + WSDL_CACHE_PUT_INT(enc->details.type, out); + sdl_serialize_string(enc->details.type_str, out); + sdl_serialize_string(enc->details.ns, out); + sdl_serialize_type_ref(enc->details.sdl_type, tmp_types, out); +} + +static void sdl_serialize_parameters(HashTable *ht, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out) +{ + int i; + + if (ht) { + i = zend_hash_num_elements(ht); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlParamPtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(ht, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_string(tmp->paramName, out); + WSDL_CACHE_PUT_INT(tmp->order, out); + sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out); + sdl_serialize_type_ref(tmp->element, tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } +} + +static void sdl_serialize_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out) +{ + int i, j; + + WSDL_CACHE_PUT_1(body->use, out); + if (body->use == SOAP_ENCODED) { + WSDL_CACHE_PUT_1(body->encodingStyle, out); + } + sdl_serialize_string(body->ns, out); + if (body->headers) { + i = zend_hash_num_elements(body->headers); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlSoapBindingFunctionHeaderPtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp) { + sdl_serialize_key(key, out); + WSDL_CACHE_PUT_1(tmp->use, out); + if (tmp->use == SOAP_ENCODED) { + WSDL_CACHE_PUT_1(tmp->encodingStyle, out); + } + sdl_serialize_string(tmp->name, out); + sdl_serialize_string(tmp->ns, out); + sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out); + sdl_serialize_type_ref(tmp->element, tmp_types, out); + if (tmp->headerfaults) { + j = zend_hash_num_elements(tmp->headerfaults); + } else { + j = 0; + } + WSDL_CACHE_PUT_INT(j, out); + if (j > 0) { + sdlSoapBindingFunctionHeaderPtr tmp2; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp2) { + sdl_serialize_key(key, out); + WSDL_CACHE_PUT_1(tmp2->use, out); + if (tmp2->use == SOAP_ENCODED) { + WSDL_CACHE_PUT_1(tmp2->encodingStyle, out); + } + sdl_serialize_string(tmp2->name, out); + sdl_serialize_string(tmp2->ns, out); + sdl_serialize_encoder_ref(tmp2->encode, tmp_encoders, out); + sdl_serialize_type_ref(tmp2->element, tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } + } ZEND_HASH_FOREACH_END(); + } +} + +static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr sdl) +{ + smart_str buf = {0}; + smart_str *out = &buf; + int i; + int type_num = 1; + int encoder_num = 1; + int f; + const encode *enc; + HashTable tmp_types; + HashTable tmp_encoders; + HashTable tmp_bindings; + HashTable tmp_functions; + +#ifdef ZEND_WIN32 + f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE); +#else + f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE); +#endif + if (f < 0) {return;} + + zend_hash_init(&tmp_types, 0, NULL, NULL, 0); + zend_hash_init(&tmp_encoders, 0, NULL, NULL, 0); + zend_hash_init(&tmp_bindings, 0, NULL, NULL, 0); + zend_hash_init(&tmp_functions, 0, NULL, NULL, 0); + + WSDL_CACHE_PUT_N("wsdl", 4, out); + WSDL_CACHE_PUT_1(WSDL_CACHE_VERSION,out); + WSDL_CACHE_PUT_1(0,out); + WSDL_CACHE_PUT_N(&t, sizeof(t), out); + + sdl_serialize_string(uri, out); + sdl_serialize_string(sdl->source, out); + sdl_serialize_string(sdl->target_ns, out); + + if (sdl->groups) { + i = zend_hash_num_elements(sdl->groups); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlTypePtr tmp; + zval zv; + + ZEND_HASH_FOREACH_PTR(sdl->groups, tmp) { + ZVAL_LONG(&zv, type_num); + zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); + ++type_num; + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->types) { + i = zend_hash_num_elements(sdl->types); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlTypePtr tmp; + zval zv; + + ZEND_HASH_FOREACH_PTR(sdl->types, tmp) { + ZVAL_LONG(&zv, type_num); + zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); + ++type_num; + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->elements) { + i = zend_hash_num_elements(sdl->elements); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlTypePtr tmp; + zval zv; + + ZEND_HASH_FOREACH_PTR(sdl->elements, tmp) { + ZVAL_LONG(&zv, type_num); + zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); + ++type_num; + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->encoders) { + i = zend_hash_num_elements(sdl->encoders); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + encodePtr tmp; + zval zv; + + ZEND_HASH_FOREACH_PTR(sdl->encoders, tmp) { + ZVAL_LONG(&zv, encoder_num); + zend_hash_str_add(&tmp_encoders, (char*)&tmp, sizeof(tmp), &zv); + ++encoder_num; + } ZEND_HASH_FOREACH_END(); + } + enc = defaultEncoding; + while (enc->details.type != END_KNOWN_TYPES) { + zval zv; + + ZVAL_LONG(&zv, encoder_num); + zend_hash_str_add(&tmp_encoders, (char*)&enc, sizeof(encodePtr), &zv); + enc++; + ++encoder_num; + } + + if (sdl->groups) { + sdlTypePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->types) { + sdlTypePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->elements) { + sdlTypePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->encoders) { + encodePtr tmp; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_encoder(tmp, &tmp_types, out); + } ZEND_HASH_FOREACH_END(); + } + + /* serialize bindings */ + if (sdl->bindings) { + i = zend_hash_num_elements(sdl->bindings); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlBindingPtr tmp; + int binding_num = 1; + zval zv; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_string(tmp->name, out); + sdl_serialize_string(tmp->location, out); + WSDL_CACHE_PUT_1(tmp->bindingType,out); + if (tmp->bindingType == BINDING_SOAP && tmp->bindingAttributes != NULL) { + sdlSoapBindingPtr binding = (sdlSoapBindingPtr)tmp->bindingAttributes; + WSDL_CACHE_PUT_1(binding->style, out); + WSDL_CACHE_PUT_1(binding->transport, out); + } else { + WSDL_CACHE_PUT_1(0,out); + } + + ZVAL_LONG(&zv, binding_num); + zend_hash_str_add(&tmp_bindings, (char*)&tmp, sizeof(tmp), &zv); + binding_num++; + } ZEND_HASH_FOREACH_END(); + } + + /* serialize functions */ + i = zend_hash_num_elements(&sdl->functions); + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlFunctionPtr tmp; + zval *binding_num, zv; + int function_num = 1; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { + sdl_serialize_key(key, out); + sdl_serialize_string(tmp->functionName, out); + sdl_serialize_string(tmp->requestName, out); + sdl_serialize_string(tmp->responseName, out); + + if (tmp->binding) { + binding_num = zend_hash_str_find(&tmp_bindings,(char*)&tmp->binding, sizeof(tmp->binding)); + if (binding_num) { + WSDL_CACHE_PUT_INT(Z_LVAL_P(binding_num), out); + if (Z_LVAL_P(binding_num) >= 0) { + if (tmp->binding->bindingType == BINDING_SOAP && tmp->bindingAttributes != NULL) { + sdlSoapBindingFunctionPtr binding = (sdlSoapBindingFunctionPtr)tmp->bindingAttributes; + WSDL_CACHE_PUT_1(binding->style, out); + sdl_serialize_string(binding->soapAction, out); + sdl_serialize_soap_body(&binding->input, &tmp_encoders, &tmp_types, out); + sdl_serialize_soap_body(&binding->output, &tmp_encoders, &tmp_types, out); + } else { + WSDL_CACHE_PUT_1(0,out); + } + } + } + } + sdl_serialize_parameters(tmp->requestParameters, &tmp_encoders, &tmp_types, out); + sdl_serialize_parameters(tmp->responseParameters, &tmp_encoders, &tmp_types, out); + + if (tmp->faults) { + sdlFaultPtr fault; + zend_string *key; + + WSDL_CACHE_PUT_INT(zend_hash_num_elements(tmp->faults), out); + + ZEND_HASH_FOREACH_STR_KEY_PTR(tmp->faults, key, fault) { + sdl_serialize_key(key, out); + sdl_serialize_string(fault->name, out); + sdl_serialize_parameters(fault->details, &tmp_encoders, &tmp_types, out); + if (tmp->binding->bindingType == BINDING_SOAP && fault->bindingAttributes != NULL) { + sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes; + WSDL_CACHE_PUT_1(binding->use, out); + if (binding->use == SOAP_ENCODED) { + WSDL_CACHE_PUT_1(binding->encodingStyle, out); + } + sdl_serialize_string(binding->ns, out); + } else { + WSDL_CACHE_PUT_1(0, out); + } + } ZEND_HASH_FOREACH_END(); + } else { + WSDL_CACHE_PUT_INT(0, out); + } + + ZVAL_LONG(&zv, function_num); + zend_hash_str_add(&tmp_functions, (char*)&tmp, sizeof(tmp), &zv); + function_num++; + } ZEND_HASH_FOREACH_END(); + } + + /* serialize requests */ + if (sdl->requests) { + i = zend_hash_num_elements(sdl->requests); + } else { + i = 0; + } + WSDL_CACHE_PUT_INT(i, out); + if (i > 0) { + sdlFunctionPtr tmp; + zval *function_num; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->requests, key, tmp) { + function_num = zend_hash_str_find(&tmp_functions, (char*)&tmp, sizeof(tmp)); + WSDL_CACHE_PUT_INT(Z_LVAL_P(function_num), out); + sdl_serialize_key(key, out); + } ZEND_HASH_FOREACH_END(); + } + + php_ignore_value(write(f, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s))); + close(f); + smart_str_free(&buf); + zend_hash_destroy(&tmp_functions); + zend_hash_destroy(&tmp_bindings); + zend_hash_destroy(&tmp_encoders); + zend_hash_destroy(&tmp_types); +} + + +static void make_persistent_restriction_int(void *data) +{ + sdlRestrictionIntPtr *rest = (sdlRestrictionIntPtr *)data; + sdlRestrictionIntPtr prest = NULL; + + prest = malloc(sizeof(sdlRestrictionInt)); + *prest = **rest; + *rest = prest; +} + + +static void make_persistent_restriction_char_int(sdlRestrictionCharPtr *rest) +{ + sdlRestrictionCharPtr prest = NULL; + + prest = malloc(sizeof(sdlRestrictionChar)); + memset(prest, 0, sizeof(sdlRestrictionChar)); + prest->value = strdup((*rest)->value); + prest->fixed = (*rest)->fixed; + *rest = prest; +} + + +static void make_persistent_sdl_type_ref(sdlTypePtr *type, HashTable *ptr_map, HashTable *bp_types) +{ + sdlTypePtr tmp; + + if ((tmp = zend_hash_str_find_ptr(ptr_map, (char *)type, sizeof(sdlTypePtr))) != NULL) { + *type = tmp; + } else { + zend_hash_next_index_insert_ptr(bp_types, *type); + } +} + + +static void make_persistent_sdl_encoder_ref(encodePtr *enc, HashTable *ptr_map, HashTable *bp_encoders) +{ + encodePtr tmp; + + /* do not process defaultEncoding's here */ + if ((*enc) >= defaultEncoding && (*enc) < defaultEncoding + numDefaultEncodings) { + return; + } + + if ((tmp = zend_hash_str_find_ptr(ptr_map, (char *)enc, sizeof(encodePtr))) != NULL) { + *enc = tmp; + } else { + zend_hash_next_index_insert_ptr(bp_encoders, enc); + } +} + + +static HashTable* make_persistent_sdl_function_headers(HashTable *headers, HashTable *ptr_map) +{ + HashTable *pheaders; + sdlSoapBindingFunctionHeaderPtr tmp, pheader; + encodePtr penc; + sdlTypePtr ptype; + zend_string *key; + + pheaders = malloc(sizeof(HashTable)); + zend_hash_init(pheaders, zend_hash_num_elements(headers), NULL, delete_header_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, tmp) { + pheader = malloc(sizeof(sdlSoapBindingFunctionHeader)); + memset(pheader, 0, sizeof(sdlSoapBindingFunctionHeader)); + *pheader = *tmp; + + if (pheader->name) { + pheader->name = strdup(pheader->name); + } + if (pheader->ns) { + pheader->ns = strdup(pheader->ns); + } + + if (pheader->encode && pheader->encode->details.sdl_type) { + if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pheader->encode, sizeof(encodePtr))) == NULL) { + assert(0); + } + pheader->encode = penc; + } + if (pheader->element) { + if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pheader->element, sizeof(sdlTypePtr))) == NULL) { + assert(0); + } + pheader->element = ptype; + } + + if (pheader->headerfaults) { + pheader->headerfaults = make_persistent_sdl_function_headers(pheader->headerfaults, ptr_map); + } + + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(pheaders, ZSTR_VAL(key), ZSTR_LEN(key), pheader); + } else { + zend_hash_next_index_insert_ptr(pheaders, pheader); + } + } ZEND_HASH_FOREACH_END(); + + return pheaders; +} + + +static void make_persistent_sdl_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *ptr_map) +{ + if (body->ns) { + body->ns = strdup(body->ns); + } + + if (body->headers) { + body->headers = make_persistent_sdl_function_headers(body->headers, ptr_map); + } +} + + +static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *ptr_map) +{ + HashTable *pparams; + sdlParamPtr tmp, pparam; + sdlTypePtr ptype; + encodePtr penc; + zend_string *key; + + pparams = malloc(sizeof(HashTable)); + zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) { + pparam = malloc(sizeof(sdlParam)); + memset(pparam, 0, sizeof(sdlParam)); + *pparam = *tmp; + + if (pparam->paramName) { + pparam->paramName = strdup(pparam->paramName); + } + + if (pparam->encode && pparam->encode->details.sdl_type) { + if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->encode, sizeof(encodePtr))) == NULL) { + assert(0); + } + pparam->encode = penc; + } + if (pparam->element) { + if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->element, sizeof(sdlTypePtr))) == NULL) { + assert(0); + } + pparam->element = ptype; + } + + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(pparams, ZSTR_VAL(key), ZSTR_LEN(key), pparam); + } else { + zend_hash_next_index_insert_ptr(pparams, pparam); + } + } ZEND_HASH_FOREACH_END(); + + return pparams; +} + +static HashTable* make_persistent_sdl_function_faults(sdlFunctionPtr func, HashTable *faults, HashTable *ptr_map) +{ + HashTable *pfaults; + sdlFaultPtr tmp, pfault; + zend_string *key; + + pfaults = malloc(sizeof(HashTable)); + zend_hash_init(pfaults, zend_hash_num_elements(faults), NULL, delete_fault_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(faults, key, tmp) { + pfault = malloc(sizeof(sdlFault)); + memset(pfault, 0, sizeof(sdlFault)); + *pfault = *tmp; + + if (pfault->name) { + pfault->name = strdup(pfault->name); + } + if (pfault->details) { + pfault->details = make_persistent_sdl_parameters(pfault->details, ptr_map); + } + + if (func->binding->bindingType == BINDING_SOAP && pfault->bindingAttributes) { + sdlSoapBindingFunctionFaultPtr soap_binding; + + soap_binding = malloc(sizeof(sdlSoapBindingFunctionFault)); + memset(soap_binding, 0, sizeof(sdlSoapBindingFunctionFault)); + *soap_binding = *(sdlSoapBindingFunctionFaultPtr)pfault->bindingAttributes; + if (soap_binding->ns) { + soap_binding->ns = strdup(soap_binding->ns); + } + pfault->bindingAttributes = soap_binding; + } + + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(pfaults, ZSTR_VAL(key), ZSTR_LEN(key), pfault); + } else { + zend_hash_next_index_insert_ptr(pfaults, pfault); + } + + } ZEND_HASH_FOREACH_END(); + + return pfaults; +} + + +static sdlAttributePtr make_persistent_sdl_attribute(sdlAttributePtr attr, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders) +{ + sdlAttributePtr pattr; + zend_string *key; + + pattr = malloc(sizeof(sdlAttribute)); + memset(pattr, 0, sizeof(sdlAttribute)); + + *pattr = *attr; + + if (pattr->name) { + pattr->name = strdup(pattr->name); + } + if (pattr->namens) { + pattr->namens = strdup(pattr->namens); + } + if (pattr->ref) { + pattr->ref = strdup(pattr->ref); + } + if (pattr->def) { + pattr->def = strdup(pattr->def); + } + if (pattr->fixed) { + pattr->fixed = strdup(pattr->fixed); + } + + /* we do not want to process defaultEncoding's here */ + if (pattr->encode) { + make_persistent_sdl_encoder_ref(&pattr->encode, ptr_map, bp_encoders); + } + + if (pattr->extraAttributes) { + sdlExtraAttributePtr tmp, pextra; + + pattr->extraAttributes = malloc(sizeof(HashTable)); + zend_hash_init(pattr->extraAttributes, zend_hash_num_elements(attr->extraAttributes), NULL, delete_extra_attribute_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { + if (key) { + pextra = malloc(sizeof(sdlExtraAttribute)); + memset(pextra, 0, sizeof(sdlExtraAttribute)); + + if (tmp->ns) { + pextra->ns = strdup(tmp->ns); + } + if (tmp->val) { + pextra->val = strdup(tmp->val); + } + + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(pattr->extraAttributes, ZSTR_VAL(key), ZSTR_LEN(key), pextra); + } + } ZEND_HASH_FOREACH_END(); + } + + return pattr; +} + + +static sdlContentModelPtr make_persistent_sdl_model(sdlContentModelPtr model, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders) +{ + sdlContentModelPtr pmodel; + sdlContentModelPtr tmp, pcontent; + + pmodel = malloc(sizeof(sdlContentModel)); + memset(pmodel, 0, sizeof(sdlContentModel)); + *pmodel = *model; + + switch (pmodel->kind) { + case XSD_CONTENT_ELEMENT: + if (pmodel->u.element) { + make_persistent_sdl_type_ref(&pmodel->u.element, ptr_map, bp_types); + } + break; + + case XSD_CONTENT_SEQUENCE: + case XSD_CONTENT_ALL: + case XSD_CONTENT_CHOICE: + pmodel->u.content = malloc(sizeof(HashTable)); + zend_hash_init(pmodel->u.content, zend_hash_num_elements(model->u.content), NULL, delete_model_persistent, 1); + + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + pcontent = make_persistent_sdl_model(tmp, ptr_map, bp_types, bp_encoders); + zend_hash_next_index_insert_ptr(pmodel->u.content, pcontent); + } ZEND_HASH_FOREACH_END(); + break; + + case XSD_CONTENT_GROUP_REF: + if (pmodel->u.group_ref) { + pmodel->u.group_ref = strdup(pmodel->u.group_ref); + } + break; + + case XSD_CONTENT_GROUP: + if (pmodel->u.group) { + make_persistent_sdl_type_ref(&pmodel->u.group, ptr_map, bp_types); + } + break; + + default: + break; + } + + return pmodel; +} + + +static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders) +{ + zend_string *key; + sdlTypePtr ptype = NULL; + + ptype = malloc(sizeof(sdlType)); + memset(ptype, 0, sizeof(sdlType)); + + *ptype = *type; + + if (ptype->name) { + ptype->name = strdup(ptype->name); + } + if (ptype->namens) { + ptype->namens = strdup(ptype->namens); + } + if (ptype->def) { + ptype->def = strdup(ptype->def); + } + if (ptype->fixed) { + ptype->fixed = strdup(ptype->fixed); + } + if (ptype->ref) { + ptype->ref = strdup(ptype->ref); + } + + /* we do not want to process defaultEncoding's here */ + if (ptype->encode) { + make_persistent_sdl_encoder_ref(&ptype->encode, ptr_map, bp_encoders); + } + + if (ptype->restrictions) { + ptype->restrictions = malloc(sizeof(sdlRestrictions)); + memset(ptype->restrictions, 0, sizeof(sdlRestrictions)); + *ptype->restrictions = *type->restrictions; + + if (ptype->restrictions->minExclusive) { + make_persistent_restriction_int(&ptype->restrictions->minExclusive); + } + if (ptype->restrictions->maxExclusive) { + make_persistent_restriction_int(&ptype->restrictions->maxExclusive); + } + if (ptype->restrictions->minInclusive) { + make_persistent_restriction_int(&ptype->restrictions->minInclusive); + } + if (ptype->restrictions->maxInclusive) { + make_persistent_restriction_int(&ptype->restrictions->maxInclusive); + } + if (ptype->restrictions->totalDigits) { + make_persistent_restriction_int(&ptype->restrictions->totalDigits); + } + if (ptype->restrictions->fractionDigits) { + make_persistent_restriction_int(&ptype->restrictions->fractionDigits); + } + if (ptype->restrictions->length) { + make_persistent_restriction_int(&ptype->restrictions->length); + } + if (ptype->restrictions->minLength) { + make_persistent_restriction_int(&ptype->restrictions->minLength); + } + if (ptype->restrictions->maxLength) { + make_persistent_restriction_int(&ptype->restrictions->maxLength); + } + if (ptype->restrictions->whiteSpace) { + make_persistent_restriction_char_int(&ptype->restrictions->whiteSpace); + } + if (ptype->restrictions->pattern) { + make_persistent_restriction_char_int(&ptype->restrictions->pattern); + } + + if (type->restrictions->enumeration) { + sdlRestrictionCharPtr tmp, penum; + ptype->restrictions->enumeration = malloc(sizeof(HashTable)); + zend_hash_init(ptype->restrictions->enumeration, zend_hash_num_elements(type->restrictions->enumeration), NULL, delete_restriction_var_char_persistent, 1); + ZEND_HASH_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { + penum = tmp; + make_persistent_restriction_char_int(&penum); + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(ptype->restrictions->enumeration, ZSTR_VAL(key), ZSTR_LEN(key), penum); + } ZEND_HASH_FOREACH_END(); + } + } + + if (ptype->elements) { + sdlTypePtr tmp, pelem; + + ptype->elements = malloc(sizeof(HashTable)); + zend_hash_init(ptype->elements, zend_hash_num_elements(type->elements), NULL, delete_type_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + pelem = make_persistent_sdl_type(tmp, ptr_map, bp_types, bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(ptype->elements, ZSTR_VAL(key), ZSTR_LEN(key), pelem); + } else { + zend_hash_next_index_insert_ptr(ptype->elements, pelem); + } + zend_hash_str_add_ptr(ptr_map, (char*)&tmp, sizeof(tmp), pelem); + } ZEND_HASH_FOREACH_END(); + } + + if (ptype->attributes) { + sdlAttributePtr tmp, pattr; + + ptype->attributes = malloc(sizeof(HashTable)); + zend_hash_init(ptype->attributes, zend_hash_num_elements(type->attributes), NULL, delete_attribute_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + pattr = make_persistent_sdl_attribute(tmp, ptr_map, bp_types, bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(ptype->attributes, ZSTR_VAL(key), ZSTR_LEN(key), pattr); + } else { + zend_hash_next_index_insert_ptr(ptype->attributes, pattr); + } + } ZEND_HASH_FOREACH_END(); + } + + if (type->model) { + ptype->model = make_persistent_sdl_model(ptype->model, ptr_map, bp_types, bp_encoders); + } + + return ptype; +} + +static encodePtr make_persistent_sdl_encoder(encodePtr enc, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders) +{ + encodePtr penc = NULL; + + penc = malloc(sizeof(encode)); + memset(penc, 0, sizeof(encode)); + + *penc = *enc; + + if (penc->details.type_str) { + penc->details.type_str = strdup(penc->details.type_str); + } + if (penc->details.ns) { + penc->details.ns = strdup(penc->details.ns); + } + + if (penc->details.sdl_type) { + make_persistent_sdl_type_ref(&penc->details.sdl_type, ptr_map, bp_types); + } + + return penc; +} + +static sdlBindingPtr make_persistent_sdl_binding(sdlBindingPtr bind, HashTable *ptr_map) +{ + sdlBindingPtr pbind = NULL; + + pbind = malloc(sizeof(sdlBinding)); + memset(pbind, 0, sizeof(sdlBinding)); + + *pbind = *bind; + + if (pbind->name) { + pbind->name = strdup(pbind->name); + } + if (pbind->location) { + pbind->location = strdup(pbind->location); + } + + if (pbind->bindingType == BINDING_SOAP && pbind->bindingAttributes) { + sdlSoapBindingPtr soap_binding; + + soap_binding = malloc(sizeof(sdlSoapBinding)); + memset(soap_binding, 0, sizeof(sdlSoapBinding)); + *soap_binding = *(sdlSoapBindingPtr)pbind->bindingAttributes; + pbind->bindingAttributes = soap_binding; + } + + return pbind; +} + +static sdlFunctionPtr make_persistent_sdl_function(sdlFunctionPtr func, HashTable *ptr_map) +{ + sdlFunctionPtr pfunc = NULL; + + pfunc = malloc(sizeof(sdlFunction)); + memset(pfunc, 0, sizeof(sdlFunction)); + + *pfunc = *func; + + if (pfunc->functionName) { + pfunc->functionName = strdup(pfunc->functionName); + } + if (pfunc->requestName) { + pfunc->requestName = strdup(pfunc->requestName); + } + if (pfunc->responseName) { + pfunc->responseName = strdup(pfunc->responseName); + } + + if (pfunc->binding) { + sdlBindingPtr tmp; + + if ((tmp = zend_hash_str_find_ptr(ptr_map, (char*)&pfunc->binding, sizeof(pfunc->binding))) == NULL) { + assert(0); + } + pfunc->binding = tmp; + + if (pfunc->binding->bindingType == BINDING_SOAP && pfunc->bindingAttributes) { + sdlSoapBindingFunctionPtr soap_binding; + + soap_binding = malloc(sizeof(sdlSoapBindingFunction)); + memset(soap_binding, 0, sizeof(sdlSoapBindingFunction)); + *soap_binding = *(sdlSoapBindingFunctionPtr)pfunc->bindingAttributes; + if (soap_binding->soapAction) { + soap_binding->soapAction = strdup(soap_binding->soapAction); + } + make_persistent_sdl_soap_body(&soap_binding->input, ptr_map); + make_persistent_sdl_soap_body(&soap_binding->output, ptr_map); + pfunc->bindingAttributes = soap_binding; + } + + if (pfunc->requestParameters) { + pfunc->requestParameters = make_persistent_sdl_parameters(pfunc->requestParameters, ptr_map); + } + if (pfunc->responseParameters) { + pfunc->responseParameters = make_persistent_sdl_parameters(pfunc->responseParameters, ptr_map); + } + if (pfunc->faults) { + pfunc->faults = make_persistent_sdl_function_faults(pfunc, pfunc->faults, ptr_map); + } + } + + return pfunc; +} + +static sdlPtr make_persistent_sdl(sdlPtr sdl) +{ + sdlPtr psdl = NULL; + HashTable ptr_map; + HashTable bp_types, bp_encoders; + zend_string *key; + + zend_hash_init(&bp_types, 0, NULL, NULL, 0); + zend_hash_init(&bp_encoders, 0, NULL, NULL, 0); + zend_hash_init(&ptr_map, 0, NULL, NULL, 0); + + psdl = malloc(sizeof(*sdl)); + memset(psdl, 0, sizeof(*sdl)); + + if (sdl->source) { + psdl->source = strdup(sdl->source); + } + if (sdl->target_ns) { + psdl->target_ns = strdup(sdl->target_ns); + } + + if (sdl->groups) { + sdlTypePtr tmp; + sdlTypePtr ptype; + + psdl->groups = malloc(sizeof(HashTable)); + zend_hash_init(psdl->groups, zend_hash_num_elements(sdl->groups), NULL, delete_type_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { + ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->groups, ZSTR_VAL(key), ZSTR_LEN(key), ptype); + } else { + zend_hash_next_index_insert_ptr(psdl->groups, ptype); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->types) { + sdlTypePtr tmp; + sdlTypePtr ptype; + + psdl->types = malloc(sizeof(HashTable)); + zend_hash_init(psdl->types, zend_hash_num_elements(sdl->types), NULL, delete_type_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->types, ZSTR_VAL(key), ZSTR_LEN(key), ptype); + } else { + zend_hash_next_index_insert_ptr(psdl->types, ptype); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->elements) { + sdlTypePtr tmp; + sdlTypePtr ptype; + + psdl->elements = malloc(sizeof(HashTable)); + zend_hash_init(psdl->elements, zend_hash_num_elements(sdl->elements), NULL, delete_type_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { + ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->elements, ZSTR_VAL(key), ZSTR_LEN(key), ptype); + } else { + zend_hash_next_index_insert_ptr(psdl->elements, ptype); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->encoders) { + encodePtr tmp; + encodePtr penc; + + psdl->encoders = malloc(sizeof(HashTable)); + zend_hash_init(psdl->encoders, zend_hash_num_elements(sdl->encoders), NULL, delete_encoder_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + penc = make_persistent_sdl_encoder(tmp, &ptr_map, &bp_types, &bp_encoders); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->encoders, ZSTR_VAL(key), ZSTR_LEN(key), penc); + } else { + zend_hash_next_index_insert_ptr(psdl->encoders, penc); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), penc); + } ZEND_HASH_FOREACH_END(); + } + + /* do backpatching here */ + if (zend_hash_num_elements(&bp_types)) { + sdlTypePtr *tmp, ptype = NULL; + + ZEND_HASH_FOREACH_PTR(&bp_types, tmp) { + if ((ptype = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { + assert(0); + } + *tmp = ptype; + } ZEND_HASH_FOREACH_END(); + } + if (zend_hash_num_elements(&bp_encoders)) { + encodePtr *tmp, penc = NULL; + + ZEND_HASH_FOREACH_PTR(&bp_encoders, tmp) { + if ((penc = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { + assert(0); + } + *tmp = penc; + } ZEND_HASH_FOREACH_END(); + } + + + if (sdl->bindings) { + sdlBindingPtr tmp; + sdlBindingPtr pbind; + + psdl->bindings = malloc(sizeof(HashTable)); + zend_hash_init(psdl->bindings, zend_hash_num_elements(sdl->bindings), NULL, delete_binding_persistent, 1); + + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { + pbind = make_persistent_sdl_binding(tmp, &ptr_map); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->bindings, ZSTR_VAL(key), ZSTR_LEN(key), pbind); + } else { + zend_hash_next_index_insert_ptr(psdl->bindings, pbind); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), pbind); + } ZEND_HASH_FOREACH_END(); + } + + zend_hash_init(&psdl->functions, zend_hash_num_elements(&sdl->functions), NULL, delete_function_persistent, 1); + if (zend_hash_num_elements(&sdl->functions)) { + sdlFunctionPtr tmp; + sdlFunctionPtr pfunc; + + ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { + pfunc = make_persistent_sdl_function(tmp, &ptr_map); + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(&psdl->functions, ZSTR_VAL(key), ZSTR_LEN(key), pfunc); + } else { + zend_hash_next_index_insert_ptr(&psdl->functions, pfunc); + } + zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), pfunc); + } ZEND_HASH_FOREACH_END(); + } + + if (sdl->requests) { + zval *zv; + sdlFunctionPtr tmp; + sdlFunctionPtr preq; + + psdl->requests = malloc(sizeof(HashTable)); + zend_hash_init(psdl->requests, zend_hash_num_elements(sdl->requests), NULL, NULL, 1); + + ZEND_HASH_FOREACH_STR_KEY_VAL(sdl->requests, key, zv) { + tmp = Z_PTR_P(zv); + if ((preq = zend_hash_str_find_ptr(&ptr_map, (char*)&tmp, sizeof(tmp))) == NULL) { + assert(0); + } + Z_PTR_P(zv) = preq; + if (key) { + /* We have to duplicate key emalloc->malloc */ + zend_hash_str_add_ptr(psdl->requests, ZSTR_VAL(key), ZSTR_LEN(key), preq); + } + } ZEND_HASH_FOREACH_END(); + } + + zend_hash_destroy(&ptr_map); + zend_hash_destroy(&bp_encoders); + zend_hash_destroy(&bp_types); + + return psdl; +} + +typedef struct _sdl_cache_bucket { + sdlPtr sdl; + time_t time; +} sdl_cache_bucket; + +static void delete_psdl_int(sdl_cache_bucket *p) +{ + sdlPtr tmp = p->sdl; + + zend_hash_destroy(&tmp->functions); + if (tmp->source) { + free(tmp->source); + } + if (tmp->target_ns) { + free(tmp->target_ns); + } + if (tmp->elements) { + zend_hash_destroy(tmp->elements); + free(tmp->elements); + } + if (tmp->encoders) { + zend_hash_destroy(tmp->encoders); + free(tmp->encoders); + } + if (tmp->types) { + zend_hash_destroy(tmp->types); + free(tmp->types); + } + if (tmp->groups) { + zend_hash_destroy(tmp->groups); + free(tmp->groups); + } + if (tmp->bindings) { + zend_hash_destroy(tmp->bindings); + free(tmp->bindings); + } + if (tmp->requests) { + zend_hash_destroy(tmp->requests); + free(tmp->requests); + } + free(tmp); +} + +static void delete_psdl(zval *zv) +{ + delete_psdl_int(Z_PTR_P(zv)); + free(Z_PTR_P(zv)); +} + +sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) +{ + char fn[MAXPATHLEN]; + sdlPtr sdl = NULL; + char* old_error_code = SOAP_GLOBAL(error_code); + size_t uri_len = 0; + php_stream_context *context=NULL; + zval *tmp, *proxy_host, *proxy_port, orig_context, new_context; + smart_str headers = {0}; + char* key = NULL; + time_t t = time(0); + zend_bool has_proxy_authorization = 0; + zend_bool has_authorization = 0; + + ZVAL_UNDEF(&orig_context); + ZVAL_UNDEF(&new_context); + if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) { + uri_len = strlen(uri); + } else if (VCWD_REALPATH(uri, fn) == NULL) { + cache_wsdl = WSDL_CACHE_NONE; + } else { + uri = fn; + uri_len = strlen(uri); + } + + if ((cache_wsdl & WSDL_CACHE_MEMORY) && SOAP_GLOBAL(mem_cache)) { + sdl_cache_bucket *p; + + if (NULL != (p = zend_hash_str_find_ptr(SOAP_GLOBAL(mem_cache), uri, uri_len))) { + if (p->time < t - SOAP_GLOBAL(cache_ttl)) { + /* in-memory cache entry is expired */ + zend_hash_str_del(&EG(persistent_list), uri, uri_len); + } else { + return p->sdl; + } + } + } + + if ((cache_wsdl & WSDL_CACHE_DISK) && (uri_len < MAXPATHLEN)) { + time_t t = time(0); + char md5str[33]; + PHP_MD5_CTX context; + unsigned char digest[16]; + int len = strlen(SOAP_GLOBAL(cache_dir)); + time_t cached; + char *user = php_get_current_user(); + int user_len = user ? strlen(user) + 1 : 0; + + md5str[0] = '\0'; + PHP_MD5Init(&context); + PHP_MD5Update(&context, (unsigned char*)uri, uri_len); + PHP_MD5Final(digest, &context); + make_digest(md5str, digest); + key = emalloc(len+sizeof("/wsdl-")-1+user_len+2+sizeof(md5str)); + memcpy(key,SOAP_GLOBAL(cache_dir),len); + memcpy(key+len,"/wsdl-",sizeof("/wsdl-")-1); + len += sizeof("/wsdl-")-1; + if (user_len) { + memcpy(key+len, user, user_len-1); + len += user_len-1; + key[len++] = '-'; + } + if (WSDL_CACHE_VERSION <= 0x9f) { + key[len++] = (WSDL_CACHE_VERSION >> 8) + '0'; + } else { + key[len++] = (WSDL_CACHE_VERSION >> 8) - 10 + 'a'; + } + if ((WSDL_CACHE_VERSION & 0xf) <= 0x9) { + key[len++] = (WSDL_CACHE_VERSION & 0xf) + '0'; + } else { + key[len++] = (WSDL_CACHE_VERSION & 0xf) - 10 + 'a'; + } + memcpy(key+len,md5str,sizeof(md5str)); + + if ((sdl = get_sdl_from_cache(key, uri, t-SOAP_GLOBAL(cache_ttl), &cached)) != NULL) { + t = cached; + efree(key); + goto cache_in_memory; + } + } + + if (NULL != (tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), + "_stream_context", sizeof("_stream_context")-1))) { + context = php_stream_context_from_zval(tmp, 0); + } else { + context = php_stream_context_alloc(); + } + + if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent")-1)) != NULL && + Z_TYPE_P(tmp) == IS_STRING && Z_STRLEN_P(tmp) > 0) { + smart_str_appends(&headers, "User-Agent: "); + smart_str_appends(&headers, Z_STRVAL_P(tmp)); + smart_str_appends(&headers, "\r\n"); + } + + if ((proxy_host = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_host", sizeof("_proxy_host")-1)) != NULL && + Z_TYPE_P(proxy_host) == IS_STRING && + (proxy_port = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_proxy_port", sizeof("_proxy_port")-1)) != NULL && + Z_TYPE_P(proxy_port) == IS_LONG) { + zval str_proxy; + smart_str proxy = {0}; + smart_str_appends(&proxy,"tcp://"); + smart_str_appends(&proxy,Z_STRVAL_P(proxy_host)); + smart_str_appends(&proxy,":"); + smart_str_append_long(&proxy,Z_LVAL_P(proxy_port)); + smart_str_0(&proxy); + ZVAL_NEW_STR(&str_proxy, proxy.s); + + if (!context) { + context = php_stream_context_alloc(); + } + php_stream_context_set_option(context, "http", "proxy", &str_proxy); + zval_ptr_dtor(&str_proxy); + + if (uri_len < sizeof("https://")-1 || + strncasecmp(uri, "https://", sizeof("https://")-1) != 0) { + ZVAL_TRUE(&str_proxy); + php_stream_context_set_option(context, "http", "request_fulluri", &str_proxy); + } + + has_proxy_authorization = proxy_authentication(this_ptr, &headers); + } + + has_authorization = basic_authentication(this_ptr, &headers); + + /* Use HTTP/1.1 with "Connection: close" by default */ + if ((tmp = php_stream_context_get_option(context, "http", "protocol_version")) == NULL) { + zval http_version; + + ZVAL_DOUBLE(&http_version, 1.1); + php_stream_context_set_option(context, "http", "protocol_version", &http_version); + smart_str_appendl(&headers, "Connection: close\r\n", sizeof("Connection: close\r\n")-1); + } + + if (headers.s && ZSTR_LEN(headers.s) > 0) { + zval str_headers; + + if (!context) { + context = php_stream_context_alloc(); + } else { + http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers); + } + + smart_str_0(&headers); + ZVAL_NEW_STR(&str_headers, headers.s); + php_stream_context_set_option(context, "http", "header", &str_headers); + zval_ptr_dtor(&str_headers); + } + + if (context) { + php_stream_context_to_zval(context, &new_context); + php_libxml_switch_context(&new_context, &orig_context); + } + + SOAP_GLOBAL(error_code) = "WSDL"; + + sdl = load_wsdl(this_ptr, uri); + if (sdl) { + sdl->is_persistent = 0; + } + + SOAP_GLOBAL(error_code) = old_error_code; + + if (context) { + php_libxml_switch_context(&orig_context, NULL); + zval_ptr_dtor(&new_context); + } + + if ((cache_wsdl & WSDL_CACHE_DISK) && key) { + if (sdl) { + add_sdl_to_cache(key, uri, t, sdl); + } + efree(key); + } + +cache_in_memory: + if (cache_wsdl & WSDL_CACHE_MEMORY) { + if (sdl) { + sdlPtr psdl; + sdl_cache_bucket p; + + if (SOAP_GLOBAL(mem_cache) == NULL) { + SOAP_GLOBAL(mem_cache) = malloc(sizeof(HashTable)); + zend_hash_init(SOAP_GLOBAL(mem_cache), 0, NULL, delete_psdl, 1); + } else if (SOAP_GLOBAL(cache_limit) > 0 && + SOAP_GLOBAL(cache_limit) <= (zend_long)zend_hash_num_elements(SOAP_GLOBAL(mem_cache))) { + /* in-memory cache overflow */ + sdl_cache_bucket *q; + time_t latest = t; + zend_string *latest_key = NULL, *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(SOAP_GLOBAL(mem_cache), key, q) { + if (q->time < latest) { + latest = q->time; + latest_key = key; + } + } ZEND_HASH_FOREACH_END(); + if (latest_key) { + zend_hash_del(SOAP_GLOBAL(mem_cache), latest_key); + } else { + return sdl; + } + } + + psdl = make_persistent_sdl(sdl); + psdl->is_persistent = 1; + p.time = t; + p.sdl = psdl; + + zend_hash_str_update_mem(SOAP_GLOBAL(mem_cache), uri, + uri_len, &p, sizeof(sdl_cache_bucket)); + /* remove non-persitent sdl structure */ + delete_sdl_impl(sdl); + /* and replace it with persistent one */ + sdl = psdl; + } + } + + return sdl; +} + +/* Deletes */ +void delete_sdl_impl(void *handle) +{ + sdlPtr tmp = (sdlPtr)handle; + + zend_hash_destroy(&tmp->functions); + if (tmp->source) { + efree(tmp->source); + } + if (tmp->target_ns) { + efree(tmp->target_ns); + } + if (tmp->elements) { + zend_hash_destroy(tmp->elements); + efree(tmp->elements); + } + if (tmp->encoders) { + zend_hash_destroy(tmp->encoders); + efree(tmp->encoders); + } + if (tmp->types) { + zend_hash_destroy(tmp->types); + efree(tmp->types); + } + if (tmp->groups) { + zend_hash_destroy(tmp->groups); + efree(tmp->groups); + } + if (tmp->bindings) { + zend_hash_destroy(tmp->bindings); + efree(tmp->bindings); + } + if (tmp->requests) { + zend_hash_destroy(tmp->requests); + efree(tmp->requests); + } + efree(tmp); +} + +void delete_sdl(void *handle) +{ + sdlPtr tmp = (sdlPtr)handle; + + if (!tmp->is_persistent) { + delete_sdl_impl(tmp); + } +} + +static void delete_binding(zval *zv) +{ + sdlBindingPtr binding = Z_PTR_P(zv); + + if (binding->location) { + efree(binding->location); + } + if (binding->name) { + efree(binding->name); + } + + if (binding->bindingType == BINDING_SOAP) { + sdlSoapBindingPtr soapBind = binding->bindingAttributes; + if (soapBind) { + efree(soapBind); + } + } + efree(binding); +} + +static void delete_binding_persistent(zval *zv) +{ + sdlBindingPtr binding = Z_PTR_P(zv); + + if (binding->location) { + free(binding->location); + } + if (binding->name) { + free(binding->name); + } + + if (binding->bindingType == BINDING_SOAP) { + sdlSoapBindingPtr soapBind = binding->bindingAttributes; + if (soapBind) { + free(soapBind); + } + } + free(binding); +} + +static void delete_sdl_soap_binding_function_body(sdlSoapBindingFunctionBody body) +{ + if (body.ns) { + efree(body.ns); + } + if (body.headers) { + zend_hash_destroy(body.headers); + efree(body.headers); + } +} + +static void delete_sdl_soap_binding_function_body_persistent(sdlSoapBindingFunctionBody body) +{ + if (body.ns) { + free(body.ns); + } + if (body.headers) { + zend_hash_destroy(body.headers); + free(body.headers); + } +} + +static void delete_function(zval *zv) +{ + sdlFunctionPtr function = Z_PTR_P(zv); + + if (function->functionName) { + efree(function->functionName); + } + if (function->requestName) { + efree(function->requestName); + } + if (function->responseName) { + efree(function->responseName); + } + if (function->requestParameters) { + zend_hash_destroy(function->requestParameters); + efree(function->requestParameters); + } + if (function->responseParameters) { + zend_hash_destroy(function->responseParameters); + efree(function->responseParameters); + } + if (function->faults) { + zend_hash_destroy(function->faults); + efree(function->faults); + } + + if (function->bindingAttributes && + function->binding && function->binding->bindingType == BINDING_SOAP) { + sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes; + if (soapFunction->soapAction) { + efree(soapFunction->soapAction); + } + delete_sdl_soap_binding_function_body(soapFunction->input); + delete_sdl_soap_binding_function_body(soapFunction->output); + efree(soapFunction); + } + efree(function); +} + +static void delete_function_persistent(zval *zv) +{ + sdlFunctionPtr function = Z_PTR_P(zv); + + if (function->functionName) { + free(function->functionName); + } + if (function->requestName) { + free(function->requestName); + } + if (function->responseName) { + free(function->responseName); + } + if (function->requestParameters) { + zend_hash_destroy(function->requestParameters); + free(function->requestParameters); + } + if (function->responseParameters) { + zend_hash_destroy(function->responseParameters); + free(function->responseParameters); + } + if (function->faults) { + zend_hash_destroy(function->faults); + free(function->faults); + } + + if (function->bindingAttributes && + function->binding && function->binding->bindingType == BINDING_SOAP) { + sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes; + if (soapFunction->soapAction) { + free(soapFunction->soapAction); + } + delete_sdl_soap_binding_function_body_persistent(soapFunction->input); + delete_sdl_soap_binding_function_body_persistent(soapFunction->output); + free(soapFunction); + } + free(function); +} + +static void delete_parameter(zval *zv) +{ + sdlParamPtr param = Z_PTR_P(zv); + if (param->paramName) { + efree(param->paramName); + } + efree(param); +} + +static void delete_parameter_persistent(zval *zv) +{ + sdlParamPtr param = Z_PTR_P(zv); + if (param->paramName) { + free(param->paramName); + } + free(param); +} + +static void delete_header_int(sdlSoapBindingFunctionHeaderPtr hdr) +{ + if (hdr->name) { + efree(hdr->name); + } + if (hdr->ns) { + efree(hdr->ns); + } + if (hdr->headerfaults) { + zend_hash_destroy(hdr->headerfaults); + efree(hdr->headerfaults); + } + efree(hdr); +} + +static void delete_header(zval *zv) +{ + delete_header_int(Z_PTR_P(zv)); +} + +static void delete_header_persistent(zval *zv) +{ + sdlSoapBindingFunctionHeaderPtr hdr = Z_PTR_P(zv); + if (hdr->name) { + free(hdr->name); + } + if (hdr->ns) { + free(hdr->ns); + } + if (hdr->headerfaults) { + zend_hash_destroy(hdr->headerfaults); + free(hdr->headerfaults); + } + free(hdr); +} + +static void delete_fault(zval *zv) +{ + sdlFaultPtr fault = Z_PTR_P(zv); + if (fault->name) { + efree(fault->name); + } + if (fault->details) { + zend_hash_destroy(fault->details); + efree(fault->details); + } + if (fault->bindingAttributes) { + sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes; + + if (binding->ns) { + efree(binding->ns); + } + efree(fault->bindingAttributes); + } + efree(fault); +} + +static void delete_fault_persistent(zval *zv) +{ + sdlFaultPtr fault = Z_PTR_P(zv); + if (fault->name) { + free(fault->name); + } + if (fault->details) { + zend_hash_destroy(fault->details); + free(fault->details); + } + if (fault->bindingAttributes) { + sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes; + + if (binding->ns) { + free(binding->ns); + } + free(fault->bindingAttributes); + } + free(fault); +} + +static void delete_document(zval *zv) +{ + xmlDocPtr doc = Z_PTR_P(zv); + xmlFreeDoc(doc); +} diff --git a/ext/soap/php_xml.c b/ext/soap/php_xml.c index b60603017957b..18a266179b7d2 100644 --- a/ext/soap/php_xml.c +++ b/ext/soap/php_xml.c @@ -199,7 +199,7 @@ xmlNsPtr node_find_ns(xmlNodePtr node) int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns) { - if (name == NULL || strcmp((char*)node->name, name) == 0) { + if (name == NULL || ((node->name) && strcmp((char*)node->name, name) == 0)) { if (ns) { xmlNsPtr nsPtr = attr_find_ns(node); if (nsPtr) { @@ -215,7 +215,7 @@ int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns) int node_is_equal_ex(xmlNodePtr node, char *name, char *ns) { - if (name == NULL || strcmp((char*)node->name, name) == 0) { + if (name == NULL || ((node->name) && strcmp((char*)node->name, name) == 0)) { if (ns) { xmlNsPtr nsPtr = node_find_ns(node); if (nsPtr) { diff --git a/ext/soap/php_xml.c.orig b/ext/soap/php_xml.c.orig new file mode 100644 index 0000000000000..b60603017957b --- /dev/null +++ b/ext/soap/php_xml.c.orig @@ -0,0 +1,325 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Brad Lafountain <rodif_bl@yahoo.com> | + | Shane Caraveo <shane@caraveo.com> | + | Dmitry Stogov <dmitry@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "php_soap.h" +#include "ext/libxml/php_libxml.h" +#include "libxml/parser.h" +#include "libxml/parserInternals.h" + +/* Channel libxml file io layer through the PHP streams subsystem. + * This allows use of ftps:// and https:// urls */ + +static int is_blank(const xmlChar* str) +{ + while (*str != '\0') { + if (*str != ' ' && *str != 0x9 && *str != 0xa && *str != 0xd) { + return 0; + } + str++; + } + return 1; +} + +/* removes all empty text, comments and other insignoficant nodes */ +static void cleanup_xml_node(xmlNodePtr node) +{ + xmlNodePtr trav; + xmlNodePtr del = NULL; + + trav = node->children; + while (trav != NULL) { + if (del != NULL) { + xmlUnlinkNode(del); + xmlFreeNode(del); + del = NULL; + } + if (trav->type == XML_TEXT_NODE) { + if (is_blank(trav->content)) { + del = trav; + } + } else if ((trav->type != XML_ELEMENT_NODE) && + (trav->type != XML_CDATA_SECTION_NODE)) { + del = trav; + } else if (trav->children != NULL) { + cleanup_xml_node(trav); + } + trav = trav->next; + } + if (del != NULL) { + xmlUnlinkNode(del); + xmlFreeNode(del); + } +} + +static void soap_ignorableWhitespace(void *ctx, const xmlChar *ch, int len) +{ +} + +static void soap_Comment(void *ctx, const xmlChar *value) +{ +} + +xmlDocPtr soap_xmlParseFile(const char *filename) +{ + xmlParserCtxtPtr ctxt = NULL; + xmlDocPtr ret; + zend_bool old_allow_url_fopen; + +/* + xmlInitParser(); +*/ + + old_allow_url_fopen = PG(allow_url_fopen); + PG(allow_url_fopen) = 1; + ctxt = xmlCreateFileParserCtxt(filename); + PG(allow_url_fopen) = old_allow_url_fopen; + if (ctxt) { + zend_bool old; + + ctxt->keepBlanks = 0; + ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace; + ctxt->sax->comment = soap_Comment; + ctxt->sax->warning = NULL; + ctxt->sax->error = NULL; + /*ctxt->sax->fatalError = NULL;*/ + ctxt->options |= XML_PARSE_HUGE; + old = php_libxml_disable_entity_loader(1); + xmlParseDocument(ctxt); + php_libxml_disable_entity_loader(old); + if (ctxt->wellFormed) { + ret = ctxt->myDoc; + if (ret->URL == NULL && ctxt->directory != NULL) { + ret->URL = xmlCharStrdup(ctxt->directory); + } + } else { + ret = NULL; + xmlFreeDoc(ctxt->myDoc); + ctxt->myDoc = NULL; + } + xmlFreeParserCtxt(ctxt); + } else { + ret = NULL; + } + +/* + xmlCleanupParser(); +*/ + + if (ret) { + cleanup_xml_node((xmlNodePtr)ret); + } + return ret; +} + +xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size) +{ + xmlParserCtxtPtr ctxt = NULL; + xmlDocPtr ret; + + +/* + xmlInitParser(); +*/ + ctxt = xmlCreateMemoryParserCtxt(buf, buf_size); + if (ctxt) { + zend_bool old; + + ctxt->sax->ignorableWhitespace = soap_ignorableWhitespace; + ctxt->sax->comment = soap_Comment; + ctxt->sax->warning = NULL; + ctxt->sax->error = NULL; + /*ctxt->sax->fatalError = NULL;*/ + ctxt->options |= XML_PARSE_HUGE; + old = php_libxml_disable_entity_loader(1); + xmlParseDocument(ctxt); + php_libxml_disable_entity_loader(old); + if (ctxt->wellFormed) { + ret = ctxt->myDoc; + if (ret->URL == NULL && ctxt->directory != NULL) { + ret->URL = xmlCharStrdup(ctxt->directory); + } + } else { + ret = NULL; + xmlFreeDoc(ctxt->myDoc); + ctxt->myDoc = NULL; + } + xmlFreeParserCtxt(ctxt); + } else { + ret = NULL; + } + +/* + xmlCleanupParser(); +*/ + +/* + if (ret) { + cleanup_xml_node((xmlNodePtr)ret); + } +*/ + return ret; +} + +xmlNsPtr attr_find_ns(xmlAttrPtr node) +{ + if (node->ns) { + return node->ns; + } else if (node->parent->ns) { + return node->parent->ns; + } else { + return xmlSearchNs(node->doc, node->parent, NULL); + } +} + +xmlNsPtr node_find_ns(xmlNodePtr node) +{ + if (node->ns) { + return node->ns; + } else { + return xmlSearchNs(node->doc, node, NULL); + } +} + +int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns) +{ + if (name == NULL || strcmp((char*)node->name, name) == 0) { + if (ns) { + xmlNsPtr nsPtr = attr_find_ns(node); + if (nsPtr) { + return (strcmp((char*)nsPtr->href, ns) == 0); + } else { + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + +int node_is_equal_ex(xmlNodePtr node, char *name, char *ns) +{ + if (name == NULL || strcmp((char*)node->name, name) == 0) { + if (ns) { + xmlNsPtr nsPtr = node_find_ns(node); + if (nsPtr) { + return (strcmp((char*)nsPtr->href, ns) == 0); + } else { + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + + +xmlAttrPtr get_attribute_ex(xmlAttrPtr node, char *name, char *ns) +{ + while (node!=NULL) { + if (attr_is_equal_ex(node, name, ns)) { + return node; + } + node = node->next; + } + return NULL; +} + +xmlNodePtr get_node_ex(xmlNodePtr node, char *name, char *ns) +{ + while (node!=NULL) { + if (node_is_equal_ex(node, name, ns)) { + return node; + } + node = node->next; + } + return NULL; +} + +xmlNodePtr get_node_recurisve_ex(xmlNodePtr node, char *name, char *ns) +{ + while (node != NULL) { + if (node_is_equal_ex(node, name, ns)) { + return node; + } else if (node->children != NULL) { + xmlNodePtr tmp = get_node_recurisve_ex(node->children, name, ns); + if (tmp) { + return tmp; + } + } + node = node->next; + } + return NULL; +} + +xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns) +{ + xmlAttrPtr attr; + + while (node != NULL) { + if (name != NULL) { + node = get_node_ex(node, name, name_ns); + if (node==NULL) { + return NULL; + } + } + + attr = get_attribute_ex(node->properties, attribute, attr_ns); + if (attr != NULL && strcmp((char*)attr->children->content, value) == 0) { + return node; + } + node = node->next; + } + return NULL; +} + +xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns) +{ + while (node != NULL) { + if (node_is_equal_ex(node, name, name_ns)) { + xmlAttrPtr attr = get_attribute_ex(node->properties, attribute, attr_ns); + if (attr != NULL && strcmp((char*)attr->children->content, value) == 0) { + return node; + } + } + if (node->children != NULL) { + xmlNodePtr tmp = get_node_with_attribute_recursive_ex(node->children, name, name_ns, attribute, value, attr_ns); + if (tmp) { + return tmp; + } + } + node = node->next; + } + return NULL; +} + +int parse_namespace(const xmlChar *inval, char **value, char **namespace) +{ + char *found = strrchr((char*)inval, ':'); + + if (found != NULL && found != (char*)inval) { + (*namespace) = estrndup((char*)inval, found - (char*)inval); + (*value) = estrdup(++found); + } else { + (*value) = estrdup((char*)inval); + (*namespace) = NULL; + } + + return FALSE; +} diff --git a/ext/soap/tests/bug80672.phpt b/ext/soap/tests/bug80672.phpt new file mode 100644 index 0000000000000..71e2b1d84105e --- /dev/null +++ b/ext/soap/tests/bug80672.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #80672 Null Dereference in SoapClient +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +try { + $client = new SoapClient(__DIR__ . "/bug80672.xml"); + $query = $soap->query(array('sXML' => 'something')); +} catch(SoapFault $e) { + print $e->getMessage(); +} +?> +--EXPECTF-- +SOAP-ERROR: Parsing WSDL: Unexpected WSDL element <> \ No newline at end of file diff --git a/ext/soap/tests/bug80672.xml b/ext/soap/tests/bug80672.xml new file mode 100644 index 0000000000000..0fa185bf1ebba --- /dev/null +++ b/ext/soap/tests/bug80672.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<soap:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/"> +<![CDATA[test]]> +</soap:definitions>