lcov_data
*~
*.phar
+!travis/*.phar
vendor/
+/php_http_api.h
+/php_http_buffer.h
+/php_http_client.h
+/php_http_client_curl.h
+/php_http_client_request.h
+/php_http_client_response.h
+/php_http_cookie.h
+/php_http_curl.h
+/php_http_encoding.h
+/php_http_env.h
+/php_http_env_request.h
+/php_http_env_response.h
+/php_http_etag.h
+/php_http_exception.h
+/php_http_filter.h
+/php_http_header.h
+/php_http_header_parser.h
+/php_http_info.h
+/php_http_message.h
+/php_http_message_body.h
+/php_http_message_parser.h
+/php_http_misc.h
+/php_http_negotiate.h
+/php_http_object.h
+/php_http_options.h
+/php_http_params.h
+/php_http_querystring.h
+/php_http_response_codes.h
+/php_http_url.h
+/php_http_utf8.h
+/php_http_version.h
+/tests/helper/server.log
- libevent-dev
env:
- - PHP=5.4 enable_debug=no enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=no enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=no enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=yes enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=yes enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=yes enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=no enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=no enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=no enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=yes enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=yes enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=yes enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.4 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.5 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
- - PHP=5.6 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes
+ - PHP=7.0 enable_debug=no enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=no enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=yes enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=no enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=no enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=no enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=yes enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=yes enable_json=no enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=no enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=no enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=no enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=7.0 enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=yes enable_json=yes enable_hash=yes enable_iconv=yes enable_phar=yes enable_posix=yes
before_script:
- make -f travis/pecl/Makefile php
- - make -f travis/pecl/Makefile pecl PECL=raphf:raphf:1.1.1
- - make -f travis/pecl/Makefile pecl PECL=propro:propro:1.0.2
- - make -f travis/pecl/Makefile ext PECL=http
+ - make -f travis/pecl/Makefile pharext/raphf-master pharext/propro-master
script:
+ - make -f travis/pecl/Makefile ext PECL=http
- make -f travis/pecl/Makefile test
after_script:
# ext-http
-[![Build Status](https://travis-ci.org/m6w6/ext-http.svg?branch=v2.5.x)](https://travis-ci.org/m6w6/ext-http)
+[![Build Status](https://travis-ci.org/m6w6/ext-http.svg?branch=master)](https://travis-ci.org/m6w6/ext-http)
[![Join the chat at https://gitter.im/m6w6/ext-http](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/m6w6/ext-http)
+>>>>>>> v2.5.x
Extended HTTP support. Again.
PHP_ADD_MAKEFILE_FRAGMENT
AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
+ if $HTTP_HAVE_A_REQUEST_LIB; then
+ AC_DEFINE([PHP_HTTP_HAVE_CLIENT], [1], [Have HTTP client support])
+ fi
fi
</lead>
<date>2015-12-07</date>
<version>
- <release>2.5.6dev</release>
- <api>2.5.0</api>
+ <release>3.0.0RC1</release>
+ <api>3.0.0</api>
</version>
<stability>
- <release>stable</release>
+ <release>beta</release>
<api>stable</api>
</stability>
<license uri="http://copyfree.org/content/standard/licenses/2bsd/license.txt">BSD-2-Clause</license>
<notes><![CDATA[
-*
+PHP7 compatible release based on the 2.5.x series with the following backwards incompatible changes:
+- removed http\Url::FROM_ENV from the default flags of the http\Url constructor, use http\Env\Url instead
+
]]></notes>
<contents>
<dir name="/">
<dependencies>
<required>
<php>
- <min>5.3.0</min>
- <max>7.0.0</max>
- <exclude>7.0.0</exclude>
+ <min>7.0.0</min>
</php>
<pearinstaller>
<min>1.4.1</min>
<package>
<name>raphf</name>
<channel>pecl.php.net</channel>
- <min>1.1.0</min>
- <max>2.0.0dev</max>
- <exclude>2.0.0dev</exclude>
+ <min>2.0.0dev</min>
<providesextension>raphf</providesextension>
</package>
<package>
<name>propro</name>
<channel>pecl.php.net</channel>
- <min>1.0.0</min>
- <max>2.0.0dev</max>
- <exclude>2.0.0dev</exclude>
+ <min>2.0.0dev</min>
<providesextension>propro</providesextension>
</package>
</required>
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_PECL_HTTP_VERSION "2.5.6dev"
+#define PHP_PECL_HTTP_VERSION "3.0.0RC1"
extern zend_module_entry http_module_entry;
#define phpext_http_ptr &http_module_entry
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
+
#!/usr/bin/env php
<?php
-// $Id: gen_curlinfo.php 323304 2012-02-17 21:13:24Z mike $
error_reporting(0);
$templates = array(
'STRING' =>
' if (CURLE_OK == curl_easy_getinfo(ch, %s, &c)) {
- add_assoc_string_ex(&array, "%s", sizeof("%2$s"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
}
',
'DOUBLE' =>
' if (CURLE_OK == curl_easy_getinfo(ch, %s, &d)) {
- add_assoc_double_ex(&array, "%s", sizeof("%2$s"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
}
',
'LONG' =>
' if (CURLE_OK == curl_easy_getinfo(ch, %s, &l)) {
- add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
}
',
'SLIST' =>
' if (CURLE_OK == curl_easy_getinfo(ch, %s, &s)) {
- MAKE_STD_ZVAL(subarray);
- array_init(subarray);
+ array_init(&tmp);
for (p = s; p; p = p->next) {
if (p->data) {
- add_next_index_string(subarray, p->data, 1);
+ add_next_index_string(&tmp, p->data);
}
}
- add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
+ zend_hash_str_update(info, "%s", lenof("%2$s"), &tmp);
curl_slist_free_all(s);
}
',
$gen = include "./travis/pecl/gen-matrix.php";
$env = $gen([
- "PHP" => ["5.4", "5.5", "5.6"],
+ "PHP" => ["7.0", "master"],
"enable_debug",
"enable_maintainer_zts",
"enable_json",
"enable_hash" => ["yes"],
- "enable_iconv" => ["yes"]
+ "enable_iconv" => ["yes"],
+ "enable_phar" => ["yes"],
+ "enable_posix" => ["yes"]
]);
foreach ($env as $e) {
printf(" - %s\n", $e);
before_script:
- make -f travis/pecl/Makefile php
- - make -f travis/pecl/Makefile pecl PECL=raphf:raphf:1.1.1
- - make -f travis/pecl/Makefile pecl PECL=propro:propro:1.0.2
+ - make -f travis/pecl/Makefile pecl PECL=raphf:raphf:2.0.0
+ - make -f travis/pecl/Makefile pecl PECL=propro:propro:2.0.0
- make -f travis/pecl/Makefile ext PECL=http
script:
}
#if 0
-static inline void php_http_globals_init(zend_php_http_globals *G TSRMLS_DC)
+static inline void php_http_globals_init(zend_php_http_globals *G)
{
}
-static inline void php_http_globals_free(zend_php_http_globals *G TSRMLS_DC)
+static inline void php_http_globals_free(zend_php_http_globals *G)
{
}
#endif
-#if ZTS && PHP_DEBUG && !HAVE_GCOV
-zend_php_http_globals *php_http_globals(void)
-{
- TSRMLS_FETCH();
- return PHP_HTTP_G;
-}
-#endif
-
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals)
PHP_INI_END()
REGISTER_INI_ENTRIES();
if (0
+ || SUCCESS != PHP_MINIT_CALL(http_object)
|| SUCCESS != PHP_MINIT_CALL(http_exception)
|| SUCCESS != PHP_MINIT_CALL(http_cookie)
|| SUCCESS != PHP_MINIT_CALL(http_encoding)
#include <php.h>
#include <SAPI.h>
-#include <ext/raphf/php_raphf.h>
-#include <ext/propro/php_propro.h>
+#include <ext/raphf/php_raphf_api.h>
+#include <ext/propro/php_propro_api.h>
#include <ext/standard/php_string.h>
#include <ext/spl/spl_iterators.h>
#include <ext/date/php_date.h>
ZEND_BEGIN_MODULE_GLOBALS(php_http)
struct php_http_env_globals env;
+#ifdef PHP_HTTP_HAVE_CLIENT
+ struct {
+#ifdef PHP_HTTP_HAVE_CURL
+ struct php_http_client_curl_globals curl;
+#endif
+ } client;
+#endif
ZEND_END_MODULE_GLOBALS(php_http)
ZEND_EXTERN_MODULE_GLOBALS(php_http);
#ifdef ZTS
# include "TSRM/TSRM.h"
-# define PHP_HTTP_G ((zend_php_http_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(php_http_globals_id)])
+# define PHP_HTTP_G ((zend_php_http_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(php_http_globals_id)])
# undef TSRMLS_FETCH_FROM_CTX
-# define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = ((ctx)?(ctx):ts_resource_ex(0, NULL))
+# define TSRMLS_FETCH_FROM_CTX(ctx) ERROR
#else
# define PHP_HTTP_G (&php_http_globals)
#endif
#include <php.h>
#include "php_http_buffer.h"
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, int flags)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(
+ php_http_buffer_t *buf, size_t chunk_size, unsigned flags)
{
if (!buf) {
buf = pemalloc(sizeof(*buf), flags & PHP_HTTP_BUFFER_INIT_PERSISTENT);
if (buf) {
buf->size = (chunk_size) ? chunk_size : PHP_HTTP_BUFFER_DEFAULT_SIZE;
buf->pmem = (flags & PHP_HTTP_BUFFER_INIT_PERSISTENT) ? 1 : 0;
- buf->data = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ? pemalloc(buf->size, buf->pmem) : NULL;
+ buf->data = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ?
+ pemalloc(buf->size, buf->pmem) : NULL;
buf->free = (flags & PHP_HTTP_BUFFER_INIT_PREALLOC) ? buf->size : 0;
buf->used = 0;
}
return buf;
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_buffer_t *buf, const char *string, size_t length)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(
+ php_http_buffer_t *buf, const char *str, size_t len)
{
if ((buf = php_http_buffer_init(buf))) {
- if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, string, length)) {
+ if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, str, len)) {
pefree(buf, buf->pmem);
buf = NULL;
}
return buf;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, size_t len, size_t override_size, int allow_error)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(
+ php_http_buffer_t *buf, size_t len, size_t override_size,
+ zend_bool allow_error)
{
char *ptr = NULL;
#if 0
}
if (allow_error) {
- ptr = perealloc_recoverable(buf->data, buf->used + buf->free + size, buf->pmem);
+ ptr = perealloc_recoverable(buf->data,
+ buf->used + buf->free + size, buf->pmem);
} else {
ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem);
}
return 0;
}
-PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account)
+PHP_HTTP_BUFFER_API char *php_http_buffer_account(
+ php_http_buffer_t *buf, size_t to_account)
{
assert(to_account <= buf->free);
return buf->used;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf, const char *append, size_t append_len)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf,
+ const char *append, size_t append_len)
{
- if (buf->free < append_len && PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, append_len)) {
+ if ( buf->free < append_len &&
+ PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, append_len)
+ ) {
return PHP_HTTP_BUFFER_NOMEM;
}
memcpy(buf->data + buf->used, append, append_len);
return append_len;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf, const char *format, ...)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf,
+ const char *format, ...)
{
va_list argv;
char *append;
return append_len;
}
-PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf, char **into, size_t *len)
+PHP_HTTP_BUFFER_API char *php_http_buffer_data(const php_http_buffer_t *buf,
+ char **into, size_t *len)
{
char *copy = ecalloc(1, buf->used + 1);
memcpy(copy, buf->data, buf->used);
return copy;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_cut(php_http_buffer_t *buf, size_t offset, size_t length)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_cut(php_http_buffer_t *buf,
+ size_t offset, size_t length)
{
if (offset > buf->used) {
return 0;
if (offset + length > buf->used) {
length = buf->used - offset;
}
- memmove(buf->data + offset, buf->data + offset + length, buf->used - length - offset);
+ memmove(buf->data + offset, buf->data + offset + length,
+ buf->used - length - offset);
buf->used -= length;
buf->free += length;
return length;
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_fix(php_http_buffer_t *buf)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_fix(
+ php_http_buffer_t *buf)
{
- if (buf->free < 1 && PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize_ex(buf, 1, 1, 0)) {
+ if ( buf->free < 1 &&
+ PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize_ex(buf, 1, 1, 0)
+ ) {
return NULL;
}
buf->data[buf->used] = '\0';
}
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, const char *data, size_t data_len, char **chunk, size_t chunk_size)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s,
+ const char *data, size_t data_len, char **chunk, size_t chunk_size)
{
php_http_buffer_t *storage;
*chunk = NULL;
if (!*s) {
- *s = php_http_buffer_init_ex(NULL, chunk_size << 1, chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
+ *s = php_http_buffer_init_ex(NULL, chunk_size << 1,
+ chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
}
storage = *s;
return 0;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_len, php_http_buffer_pass_func_t passout, void *opaque TSRMLS_DC)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s,
+ const char *data, size_t data_len, size_t chunk_len,
+ php_http_buffer_pass_func_t passout, void *opaque)
{
char *chunk = NULL;
size_t passed = 0, got = 0;
while ((got = php_http_buffer_chunk_buffer(s, data, data_len, &chunk, chunk_len))) {
- if (PHP_HTTP_BUFFER_PASS0 == passout(opaque, chunk, got TSRMLS_CC)) {
+ if (PHP_HTTP_BUFFER_PASS0 == passout(opaque, chunk, got)) {
PTR_SET(chunk, NULL);
return PHP_HTTP_BUFFER_PASS0;
}
return passed;
}
-PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC)
+PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size,
+ php_http_buffer_pass_func_t passin, void *passin_arg,
+ php_http_buffer_pass_func_t passon, void *passon_arg)
{
- size_t passed_on = 0, passed_in = php_http_buffer_chunked_input(s, chunk_size, passin, passin_arg TSRMLS_CC);
+ size_t passed_on = 0, passed_in;
+
+ passed_in = php_http_buffer_chunked_input(s, chunk_size, passin, passin_arg);
if (passed_in == PHP_HTTP_BUFFER_PASS0) {
return passed_in;
}
if (passed_in || (*s)->used) {
- passed_on = passon(passon_arg, (*s)->data, (*s)->used TSRMLS_CC);
+ passed_on = passon(passon_arg, (*s)->data, (*s)->used);
if (passed_on == PHP_HTTP_BUFFER_PASS0) {
return passed_on;
return passed_on - passed_in;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque TSRMLS_DC)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s,
+ size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque)
{
php_http_buffer_t *str;
size_t passed;
if (!*s) {
- *s = php_http_buffer_init_ex(NULL, chunk_size, chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
+ *s = php_http_buffer_init_ex(NULL, chunk_size,
+ chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
}
str = *s;
php_http_buffer_resize(str, chunk_size);
- passed = passin(opaque, str->data + str->used, chunk_size TSRMLS_CC);
+ passed = passin(opaque, str->data + str->used, chunk_size);
if (passed != PHP_HTTP_BUFFER_PASS0) {
str->used += passed;
#ifdef PHP_HTTP_BUFFER_EXTENDED
-PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left, php_http_buffer_t *right)
+PHP_HTTP_BUFFER_API int php_http_buffer_cmp(php_http_buffer_t *left,
+ php_http_buffer_t *right)
{
if (left->used > right->used) {
return -1;
}
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy(const php_http_buffer_t *from, php_http_buffer_t *to)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_copy(
+ const php_http_buffer_t *from, php_http_buffer_t *to)
{
int free_to = !to;
return to;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf, const char *insert, size_t insert_len, size_t offset)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_insert(php_http_buffer_t *buf,
+ const char *insert, size_t insert_len, size_t offset)
{
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, insert_len)) {
return PHP_HTTP_BUFFER_NOMEM;
return insert_len;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf, size_t offset, const char *format, ...)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_insertf(php_http_buffer_t *buf,
+ size_t offset, const char *format, ...)
{
va_list argv;
char *insert;
return insert_len;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf, const char *prepend, size_t prepend_len)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_prepend(php_http_buffer_t *buf,
+ const char *prepend, size_t prepend_len)
{
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_resize(buf, prepend_len)) {
return PHP_HTTP_BUFFER_NOMEM;
return prepend_len;
}
-PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf, const char *format, ...)
+PHP_HTTP_BUFFER_API size_t php_http_buffer_prependf(php_http_buffer_t *buf,
+ const char *format, ...)
{
va_list argv;
char *prepend;
return prepend_len;
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub(const php_http_buffer_t *buf, size_t offset, size_t length)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_sub(
+ const php_http_buffer_t *buf, size_t offset, size_t length)
{
if (offset >= buf->used) {
return NULL;
} else {
- size_t need = 1 + ((length + offset) > buf->used ? (buf->used - offset) : (length - offset));
- php_http_buffer_t *sub = php_http_buffer_init_ex(NULL, need, PHP_HTTP_BUFFER_INIT_PREALLOC | (buf->pmem ? PHP_HTTP_BUFFER_INIT_PERSISTENT:0));
+ php_http_buffer_t *sub;
+ size_t need = 1 + ((length + offset) > buf->used ?
+ (buf->used - offset) : (length - offset));
+ unsigned flags = buf->pmem ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0;
+
+ sub = php_http_buffer_init_ex(NULL, need,
+ PHP_HTTP_BUFFER_INIT_PREALLOC | flags);
+
if (sub) {
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(sub, buf->data + offset, need)) {
php_http_buffer_free(&sub);
}
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right(const php_http_buffer_t *buf, size_t length)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_right(
+ const php_http_buffer_t *buf, size_t length)
{
if (length < buf->used) {
return php_http_buffer_sub(buf, buf->used - length, length);
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va(php_http_buffer_t *buf, unsigned argc, va_list argv)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_va(
+ php_http_buffer_t *buf, unsigned argc, va_list argv)
{
unsigned i = 0;
buf = php_http_buffer_init(buf);
return buf;
}
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex(php_http_buffer_t *buf, unsigned argc, ...)
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_merge_ex(
+ php_http_buffer_t *buf, unsigned argc, ...)
{
va_list argv;
php_http_buffer_t *ret;
PTR = SET; \
}
#endif
-#ifndef TSRMLS_D
-# define TSRMLS_D
-# define TSRMLS_DC
-# define TSRMLS_CC
-# define TSRMLS_C
-#endif
#ifdef PHP_ATTRIBUTE_FORMAT
# define PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(f, a, b) PHP_ATTRIBUTE_FORMAT(f, a, b)
#else
case PHP_HTTP_BUFFER_FREE_NOT: \
break; \
case PHP_HTTP_BUFFER_FREE_PTR: \
- pefree(STR, STR->pmem); break; \
+ pefree(STR, STR->pmem); \
break; \
case PHP_HTTP_BUFFER_FREE_VAL: \
php_http_buffer_dtor(STR); \
#define php_http_buffer_new() php_http_buffer_init(NULL)
#define php_http_buffer_init(b) php_http_buffer_init_ex(b, PHP_HTTP_BUFFER_DEFAULT_SIZE, 0)
#define php_http_buffer_clone(from, to) php_http_buffer_init_ex((to), (from)->size, (from)->pmem ? PHP_HTTP_BUFFER_INIT_PERSISTENT:0)
-PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, int flags);
+PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, unsigned flags);
/* create a php_http_buffer_t from a zval or c-string */
#define php_http_buffer_from_zval(z) php_http_buffer_from_string(Z_STRVAL(z), Z_STRLEN(z))
/* usually only called from within the internal functions */
#define php_http_buffer_resize(b, s) php_http_buffer_resize_ex((b), (s), 0, 0)
-PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, size_t len, size_t override_size, int allow_error);
+PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, size_t len, size_t override_size, zend_bool allow_error);
PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account);
/* append data to the php_http_buffer_t */
#define php_http_buffer_appends(b, a) php_http_buffer_append((b), (a), sizeof(a)-1)
#define php_http_buffer_appendl(b, a) php_http_buffer_append((b), (a), strlen(a))
+#define php_http_buffer_appendz(b, z) php_http_buffer_append((b), (z)->val, (z)->len)
PHP_HTTP_BUFFER_API size_t php_http_buffer_append(php_http_buffer_t *buf, const char *append, size_t append_len);
PHP_HTTP_BUFFER_API size_t php_http_buffer_appendf(php_http_buffer_t *buf, const char *format, ...) PHP_HTTP_BUFFER_ATTRIBUTE_FORMAT(printf, 2, 3);
/* stores data in a php_http_buffer_t until it reaches chunk_size */
PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, const char *data, size_t data_len, char **chunk, size_t chunk_size);
-typedef size_t (*php_http_buffer_pass_func_t)(void *opaque, char *, size_t TSRMLS_DC);
+typedef size_t (*php_http_buffer_pass_func_t)(void *opaque, char *, size_t);
-PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC);
+PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg);
/* wrapper around php_http_buffer_chunk_buffer, which passes available chunks to passthru() */
-PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_size, php_http_buffer_pass_func_t passout, void *opaque TSRMLS_DC);
+PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_output(php_http_buffer_t **s, const char *data, size_t data_len, size_t chunk_size, php_http_buffer_pass_func_t passout, void *opaque);
/* write chunks directly into php_http_buffer_t buffer */
-PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque TSRMLS_DC);
+PHP_HTTP_BUFFER_API size_t php_http_buffer_chunked_input(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *opaque);
# ifdef PHP_HTTP_BUFFER_EXTENDED
*/
static HashTable php_http_client_drivers;
+static void php_http_client_driver_hash_dtor(zval *pData)
+{
+ pefree(Z_PTR_P(pData), 1);
+}
+
ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver)
{
- return zend_hash_add(&php_http_client_drivers, driver->name_str, driver->name_len + 1, (void *) driver, sizeof(php_http_client_driver_t), NULL);
+ return zend_hash_add_mem(&php_http_client_drivers, driver->driver_name, (void *) driver, sizeof(php_http_client_driver_t))
+ ? SUCCESS : FAILURE;
}
-ZEND_RESULT_CODE php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver)
+php_http_client_driver_t *php_http_client_driver_get(zend_string *name)
{
+ zval *ztmp;
php_http_client_driver_t *tmp;
- if ((name_str && SUCCESS == zend_hash_find(&php_http_client_drivers, name_str, name_len + 1, (void *) &tmp))
- || (SUCCESS == zend_hash_get_current_data(&php_http_client_drivers, (void *) &tmp))) {
- *driver = *tmp;
- return SUCCESS;
+ if (name && (tmp = zend_hash_find_ptr(&php_http_client_drivers, name))) {
+ return tmp;
}
- return FAILURE;
+ if ((ztmp = zend_hash_get_current_data(&php_http_client_drivers))) {
+ return Z_PTR_P(ztmp);
+ }
+ return NULL;
}
-static int apply_driver_list(void *p, void *arg TSRMLS_DC)
+static int apply_driver_list(zval *p, void *arg)
{
- php_http_client_driver_t *d = p;
- zval *zname;
+ php_http_client_driver_t *d = Z_PTR_P(p);
+ zval zname;
- MAKE_STD_ZVAL(zname);
- ZVAL_STRINGL(zname, d->name_str, d->name_len, 1);
+ ZVAL_STR_COPY(&zname, d->driver_name);
- zend_hash_next_index_insert(arg, &zname, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(arg, &zname);
return ZEND_HASH_APPLY_KEEP;
}
-void php_http_client_driver_list(HashTable *ht TSRMLS_DC)
+void php_http_client_driver_list(HashTable *ht)
+{
+ zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht);
+}
+
+static zend_class_entry *php_http_client_class_entry;
+zend_class_entry *php_http_client_get_class_entry(void)
{
- zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht TSRMLS_CC);
+ return php_http_client_class_entry;
}
-void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite TSRMLS_DC)
+void php_http_client_options_set_subr(zval *instance, char *key, size_t len, zval *opts, int overwrite)
{
if (overwrite || (opts && zend_hash_num_elements(Z_ARRVAL_P(opts)))) {
- zend_class_entry *this_ce = Z_OBJCE_P(getThis());
- zval *old_opts, *new_opts, **entry = NULL;
+ zend_class_entry *this_ce = Z_OBJCE_P(instance);
+ zval old_opts_tmp, *old_opts, new_opts, *entry = NULL;
- MAKE_STD_ZVAL(new_opts);
- array_init(new_opts);
- old_opts = zend_read_property(this_ce, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ array_init(&new_opts);
+ old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp);
if (Z_TYPE_P(old_opts) == IS_ARRAY) {
- array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
+ array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL(new_opts));
}
if (overwrite) {
if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
Z_ADDREF_P(opts);
- zend_symtable_update(Z_ARRVAL_P(new_opts), key, len, (void *) &opts, sizeof(zval *), NULL);
+ zend_symtable_str_update(Z_ARRVAL(new_opts), key, len, opts);
} else {
- zend_symtable_del(Z_ARRVAL_P(new_opts), key, len);
+ zend_symtable_str_del(Z_ARRVAL(new_opts), key, len);
}
} else if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
- array_join(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry), 0, 0);
+ if ((entry = zend_symtable_str_find(Z_ARRVAL(new_opts), key, len))) {
+ array_join(Z_ARRVAL_P(opts), Z_ARRVAL_P(entry), 0, 0);
} else {
Z_ADDREF_P(opts);
- zend_symtable_update(Z_ARRVAL_P(new_opts), key, len, (void *) &opts, sizeof(zval *), NULL);
+ zend_symtable_str_update(Z_ARRVAL(new_opts), key, len, opts);
}
}
- zend_update_property(this_ce, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC);
+ zend_update_property(this_ce, instance, ZEND_STRL("options"), &new_opts);
zval_ptr_dtor(&new_opts);
}
}
-void php_http_client_options_set(zval *this_ptr, zval *opts TSRMLS_DC)
+void php_http_client_options_set(zval *instance, zval *opts)
{
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- HashPosition pos;
- zval *new_opts;
- zend_class_entry *this_ce = Z_OBJCE_P(getThis());
- zend_bool is_client = instanceof_function(this_ce, php_http_client_class_entry TSRMLS_CC);
+ php_http_arrkey_t key;
+ zval new_opts;
+ zend_class_entry *this_ce = Z_OBJCE_P(instance);
+ zend_bool is_client = instanceof_function(this_ce, php_http_client_class_entry);
- MAKE_STD_ZVAL(new_opts);
- array_init(new_opts);
+ array_init(&new_opts);
if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
- zend_update_property(this_ce, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC);
+ zend_update_property(this_ce, instance, ZEND_STRL("options"), &new_opts);
zval_ptr_dtor(&new_opts);
} else {
- zval *old_opts, *add_opts, **opt;
+ zval old_opts_tmp, *old_opts, add_opts, *opt;
- MAKE_STD_ZVAL(add_opts);
- array_init(add_opts);
+ array_init(&add_opts);
/* some options need extra attention -- thus cannot use array_merge() directly */
- FOREACH_KEYVAL(pos, opts, key, opt) {
- if (key.type == HASH_KEY_IS_STRING) {
-#define KEYMATCH(k, s) ((sizeof(s)==k.len) && !strcasecmp(k.str, s))
- if (Z_TYPE_PP(opt) == IS_ARRAY && (KEYMATCH(key, "ssl") || KEYMATCH(key, "cookies"))) {
- php_http_client_options_set_subr(getThis(), key.str, key.len, *opt, 0 TSRMLS_CC);
- } else if (is_client && (KEYMATCH(key, "recordHistory") || KEYMATCH(key, "responseMessageClass"))) {
- zend_update_property(this_ce, getThis(), key.str, key.len-1, *opt TSRMLS_CC);
- } else if (Z_TYPE_PP(opt) == IS_NULL) {
- old_opts = zend_read_property(this_ce, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(opts), key.h, key.key, opt)
+ {
+ if (key.key) {
+ if (Z_TYPE_P(opt) == IS_ARRAY && (zend_string_equals_literal(key.key, "ssl") || zend_string_equals_literal(key.key, "cookies"))) {
+ php_http_client_options_set_subr(instance, key.key->val, key.key->len, opt, 0);
+ } else if (is_client && (zend_string_equals_literal(key.key, "recordHistory") || zend_string_equals_literal(key.key, "responseMessageClass"))) {
+ zend_update_property(this_ce, instance, key.key->val, key.key->len, opt);
+ } else if (Z_TYPE_P(opt) == IS_NULL) {
+ old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp);
if (Z_TYPE_P(old_opts) == IS_ARRAY) {
- zend_symtable_del(Z_ARRVAL_P(old_opts), key.str, key.len);
+ zend_symtable_del(Z_ARRVAL_P(old_opts), key.key);
}
} else {
- Z_ADDREF_P(*opt);
- add_assoc_zval_ex(add_opts, key.str, key.len, *opt);
+ Z_TRY_ADDREF_P(opt);
+ add_assoc_zval_ex(&add_opts, key.key->val, key.key->len, opt);
}
}
}
+ ZEND_HASH_FOREACH_END();
- old_opts = zend_read_property(this_ce, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp);
if (Z_TYPE_P(old_opts) == IS_ARRAY) {
- array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
+ array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL(new_opts));
}
- array_join(Z_ARRVAL_P(add_opts), Z_ARRVAL_P(new_opts), 0, 0);
- zend_update_property(this_ce, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC);
+ array_join(Z_ARRVAL(add_opts), Z_ARRVAL(new_opts), 0, 0);
+ zend_update_property(this_ce, instance, ZEND_STRL("options"), &new_opts);
zval_ptr_dtor(&new_opts);
zval_ptr_dtor(&add_opts);
}
}
-void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value TSRMLS_DC)
+void php_http_client_options_get_subr(zval *instance, char *key, size_t len, zval *return_value)
{
- zend_class_entry *this_ce = Z_OBJCE_P(getThis());
- zval **options, *opts = zend_read_property(this_ce, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ zend_class_entry *this_ce = Z_OBJCE_P(instance);
+ zval *options, opts_tmp, *opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &opts_tmp);
- if ((Z_TYPE_P(opts) == IS_ARRAY) && (SUCCESS == zend_symtable_find(Z_ARRVAL_P(opts), key, len, (void *) &options))) {
- RETVAL_ZVAL(*options, 1, 0);
+ if ((Z_TYPE_P(opts) == IS_ARRAY) && (options = zend_symtable_str_find(Z_ARRVAL_P(opts), key, len))) {
+ RETVAL_ZVAL(options, 1, 0);
}
}
}
}
-php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC)
+php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg)
{
php_http_client_t *free_h = NULL;
}
zend_llist_init(&h->requests, sizeof(php_http_client_enqueue_t), queue_dtor, 0);
zend_llist_init(&h->responses, sizeof(void *), NULL, 0);
- TSRMLS_SET_CTX(h->ts);
if (h->ops->init) {
if (!(h = h->ops->init(h, init_arg))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize client");
- if (free_h) {
- efree(free_h);
- }
+ php_error_docref(NULL, E_WARNING, "Could not initialize client");
+ PTR_FREE(free_h);
}
}
ZEND_RESULT_CODE php_http_client_enqueue(php_http_client_t *h, php_http_client_enqueue_t *enqueue)
{
- TSRMLS_FETCH_FROM_CTX(h->ts);
-
if (h->ops->enqueue) {
if (php_http_client_enqueued(h, enqueue->request, NULL)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to enqueue request; request already in queue");
+ php_error_docref(NULL, E_WARNING, "Failed to enqueue request; request already in queue");
return FAILURE;
}
return h->ops->enqueue(h, enqueue);
ZEND_RESULT_CODE php_http_client_dequeue(php_http_client_t *h, php_http_message_t *request)
{
- TSRMLS_FETCH_FROM_CTX(h->ts);
-
if (h->ops->dequeue) {
php_http_client_enqueue_t *enqueue = php_http_client_enqueued(h, request, NULL);
if (!enqueue) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to dequeue request; request not in queue");
+ php_error_docref(NULL, E_WARNING, "Failed to dequeue request; request not in queue");
return FAILURE;
}
return h->ops->dequeue(h, enqueue);
return FAILURE;
}
-zend_class_entry *php_http_client_class_entry;
static zend_object_handlers php_http_client_object_handlers;
-void php_http_client_object_free(void *object TSRMLS_DC)
+void php_http_client_object_free(zend_object *object)
{
- php_http_client_object_t *o = (php_http_client_object_t *) object;
+ php_http_client_object_t *o = PHP_HTTP_OBJ(object, NULL);
php_http_client_free(&o->client);
php_http_object_method_dtor(&o->notify);
php_http_object_method_free(&o->update);
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
}
-zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_client_t *client, php_http_client_object_t **ptr TSRMLS_DC)
+php_http_client_object_t *php_http_client_object_new_ex(zend_class_entry *ce, php_http_client_t *client)
{
php_http_client_object_t *o;
- o = ecalloc(1, sizeof(php_http_client_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
o->client = client;
- if (ptr) {
- *ptr = o;
- }
-
- o->zv.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_client_object_handlers;
+ o->zo.handlers = &php_http_client_object_handlers;
- return o->zv;
+ return o;
}
-zend_object_value php_http_client_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_client_object_new(zend_class_entry *ce)
{
- return php_http_client_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_client_object_new_ex(ce, NULL)->zo;
}
-static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response TSRMLS_DC)
+static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response)
{
- zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC);
- php_http_message_t *zipped = php_http_message_zip(response, request);
- zend_object_value ov = php_http_message_object_new_ex(php_http_message_class_entry, zipped, NULL TSRMLS_CC);
+ zval new_hist, old_hist_tmp, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0, &old_hist_tmp);
+ php_http_message_t *req_copy = php_http_message_copy(request, NULL);
+ php_http_message_t *res_copy = php_http_message_copy(response, NULL);
+ php_http_message_t *zipped = php_http_message_zip(res_copy, req_copy);
+ php_http_message_object_t *obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), zipped);
- MAKE_STD_ZVAL(new_hist);
- ZVAL_OBJVAL(new_hist, ov, 0);
+ ZVAL_OBJ(&new_hist, &obj->zo);
if (Z_TYPE_P(old_hist) == IS_OBJECT) {
- php_http_message_object_prepend(new_hist, old_hist, 1 TSRMLS_CC);
+ php_http_message_object_prepend(&new_hist, old_hist, 1);
}
- zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), new_hist TSRMLS_CC);
+ zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), &new_hist);
zval_ptr_dtor(&new_hist);
}
zval zclient;
php_http_message_t *msg;
php_http_client_progress_state_t *progress;
- TSRMLS_FETCH_FROM_CTX(client->ts);
- INIT_PZVAL(&zclient);
- ZVAL_OBJVAL(&zclient, ((php_http_client_object_t*) arg)->zv, 0);
+ ZVAL_OBJ(&zclient, &((php_http_client_object_t*) arg)->zo);
if ((msg = *response)) {
php_http_message_object_t *msg_obj;
- zval *info, *zresponse, *zrequest;
+ zval info, zresponse, zrequest, rec_hist_tmp;
HashTable *info_ht;
/* ensure the message is of type response (could be uninitialized in case of early error, like DNS) */
php_http_message_set_type(msg, PHP_HTTP_RESPONSE);
- if (z_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
- handle_history(&zclient, e->request, *response TSRMLS_CC);
+ if (zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0, &rec_hist_tmp))) {
+ handle_history(&zclient, e->request, *response);
}
/* hard detach, redirects etc. are in the history */
php_http_message_free(&msg->parent);
*response = NULL;
- MAKE_STD_ZVAL(zresponse);
- ZVAL_OBJVAL(zresponse, php_http_message_object_new_ex(php_http_client_response_class_entry, msg, &msg_obj TSRMLS_CC), 0);
-
- MAKE_STD_ZVAL(zrequest);
- ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1);
+ msg_obj = php_http_message_object_new_ex(php_http_get_client_response_class_entry(), msg);
+ ZVAL_OBJ(&zresponse, &msg_obj->zo);
+ ZVAL_OBJECT(&zrequest, &((php_http_message_object_t *) e->opaque)->zo, 1);
- php_http_message_object_prepend(zresponse, zrequest, 1 TSRMLS_CC);
+ php_http_message_object_prepend(&zresponse, &zrequest, 1);
- MAKE_STD_ZVAL(info);
- object_init(info);
- info_ht = HASH_OF(info);
+ object_init(&info);
+ info_ht = HASH_OF(&info);
php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &info_ht);
- zend_update_property(php_http_client_response_class_entry, zresponse, ZEND_STRL("transferInfo"), info TSRMLS_CC);
+ zend_update_property(php_http_get_client_response_class_entry(), &zresponse, ZEND_STRL("transferInfo"), &info);
zval_ptr_dtor(&info);
- zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
+ Z_ADDREF(zresponse);
zend_llist_add_element(&client->responses, &msg_obj);
if (e->closure.fci.size) {
- zval *retval = NULL;
+ zval retval;
zend_error_handling zeh;
- zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 1, &zresponse);
- zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
- zend_fcall_info_call(&e->closure.fci, &e->closure.fcc, &retval, NULL TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
- zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 0);
+ ZVAL_UNDEF(&retval);
+ zend_fcall_info_argn(&e->closure.fci, 1, &zresponse);
+ zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
+ zend_fcall_info_call(&e->closure.fci, &e->closure.fcc, &retval, NULL);
+ zend_restore_error_handling(&zeh);
+ zend_fcall_info_argn(&e->closure.fci, 0);
- if (retval) {
- if (Z_TYPE_P(retval) == IS_BOOL) {
- dequeue = Z_BVAL_P(retval);
- }
- zval_ptr_dtor(&retval);
+ if (Z_TYPE(retval) == IS_TRUE) {
+ dequeue = 1;
}
+ zval_ptr_dtor(&retval);
}
zval_ptr_dtor(&zresponse);
static void handle_progress(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *progress)
{
- zval *zrequest, *zprogress, *zclient, **args[2];
+ zval zclient, args[2];
php_http_client_object_t *client_obj = arg;
zend_error_handling zeh;
- TSRMLS_FETCH_FROM_CTX(client->ts);
-
- MAKE_STD_ZVAL(zclient);
- ZVAL_OBJVAL(zclient, client_obj->zv, 1);
-
- MAKE_STD_ZVAL(zrequest);
- ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1);
- args[0] = &zrequest;
-
- MAKE_STD_ZVAL(zprogress);
- object_init(zprogress);
- add_property_bool(zprogress, "started", progress->started);
- add_property_bool(zprogress, "finished", progress->finished);
- add_property_string(zprogress, "info", STR_PTR(progress->info), 1);
- add_property_double(zprogress, "dltotal", progress->dl.total);
- add_property_double(zprogress, "dlnow", progress->dl.now);
- add_property_double(zprogress, "ultotal", progress->ul.total);
- add_property_double(zprogress, "ulnow", progress->ul.now);
- args[1] = &zprogress;
-
- zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
- php_http_object_method_call(&client_obj->notify, zclient, NULL, 2, args TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ ZVAL_OBJECT(&zclient, &client_obj->zo, 1);
+ ZVAL_OBJECT(&args[0], &((php_http_message_object_t *) e->opaque)->zo, 1);
+ object_init(&args[1]);
+ add_property_bool(&args[1], "started", progress->started);
+ add_property_bool(&args[1], "finished", progress->finished);
+ add_property_string(&args[1], "info", STR_PTR(progress->info));
+ add_property_double(&args[1], "dltotal", progress->dl.total);
+ add_property_double(&args[1], "dlnow", progress->dl.now);
+ add_property_double(&args[1], "ultotal", progress->ul.total);
+ add_property_double(&args[1], "ulnow", progress->ul.now);
+
+ zend_replace_error_handling(EH_NORMAL, NULL, &zeh);
+ php_http_object_method_call(&client_obj->notify, &zclient, NULL, 2, args);
+ zend_restore_error_handling(&zeh);
zval_ptr_dtor(&zclient);
- zval_ptr_dtor(&zrequest);
- zval_ptr_dtor(&zprogress);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&args[1]);
}
static void response_dtor(void *data)
{
php_http_message_object_t *msg_obj = *(php_http_message_object_t **) data;
- TSRMLS_FETCH_FROM_CTX(msg_obj->message->ts);
- zend_objects_store_del_ref_by_handle_ex(msg_obj->zv.handle, msg_obj->zv.handlers TSRMLS_CC);
+ zend_objects_store_del(&msg_obj->zo);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, __construct)
{
- char *driver_str = NULL, *persistent_handle_str = NULL;
- int driver_len = 0, persistent_handle_len = 0;
- php_http_client_driver_t driver;
+ zend_string *driver_name = NULL, *persistent_handle_name = NULL;
+ php_http_client_driver_t *driver;
php_resource_factory_t *rf = NULL;
php_http_client_object_t *obj;
- zval *os;
+ zval os;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|S!S!", &driver_name, &persistent_handle_name), invalid_arg, return);
- if (SUCCESS != php_http_client_driver_get(driver_str, driver_len, &driver)) {
- php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_str);
+ if (!zend_hash_num_elements(&php_http_client_drivers)) {
+ php_http_throw(unexpected_val, "No http\\Client drivers available", NULL);
+ return;
+ }
+ if (!(driver = php_http_client_driver_get(driver_name))) {
+ php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_name ? driver_name->val : "default");
return;
}
- MAKE_STD_ZVAL(os);
- object_init_ex(os, spl_ce_SplObjectStorage);
- zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), os TSRMLS_CC);
+ object_init_ex(&os, spl_ce_SplObjectStorage);
+ zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), &os);
zval_ptr_dtor(&os);
- if (persistent_handle_len) {
- char *name_str;
- size_t name_len;
+ if (persistent_handle_name) {
php_persistent_handle_factory_t *pf;
- name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver.name_str);
- php_http_pretty_key(name_str + sizeof("http\\Client"), driver.name_len, 1, 1);
-
- if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL TSRMLS_CC))) {
+ if ((pf = php_persistent_handle_concede(NULL, driver->client_name, persistent_handle_name, NULL, NULL))) {
rf = php_persistent_handle_resource_factory_init(NULL, pf);
}
-
- efree(name_str);
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
- php_http_expect(obj->client = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC), runtime, return);
+ php_http_expect(obj->client = php_http_client_init(NULL, driver->client_ops, rf, NULL), runtime, return);
- php_http_object_method_init(&obj->notify, getThis(), ZEND_STRL("notify") TSRMLS_CC);
+ php_http_object_method_init(&obj->notify, getThis(), ZEND_STRL("notify"));
obj->client->callback.response.func = handle_response;
obj->client->callback.response.arg = obj;
php_http_client_object_t *obj;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
obj->iterator = 0;
php_http_client_reset(obj->client);
RETVAL_ZVAL(getThis(), 1, 0);
}
-static HashTable *combined_options(zval *client, zval *request TSRMLS_DC)
+static HashTable *combined_options(zval *client, zval *request)
{
HashTable *options;
- int num_options = 0;
- zval *z_roptions = NULL, *z_coptions = zend_read_property(php_http_client_class_entry, client, ZEND_STRL("options"), 0 TSRMLS_CC);
+ unsigned num_options = 0;
+ zval z_roptions, z_options_tmp, *z_coptions = zend_read_property(php_http_client_class_entry, client, ZEND_STRL("options"), 0, &z_options_tmp);
if (Z_TYPE_P(z_coptions) == IS_ARRAY) {
num_options = zend_hash_num_elements(Z_ARRVAL_P(z_coptions));
}
- zend_call_method_with_0_params(&request, NULL, NULL, "getOptions", &z_roptions);
- if (z_roptions && Z_TYPE_P(z_roptions) == IS_ARRAY) {
- int num = zend_hash_num_elements(Z_ARRVAL_P(z_roptions));
+ ZVAL_UNDEF(&z_roptions);
+ zend_call_method_with_0_params(request, NULL, NULL, "getOptions", &z_roptions);
+ if (Z_TYPE(z_roptions) == IS_ARRAY) {
+ unsigned num = zend_hash_num_elements(Z_ARRVAL(z_roptions));
if (num > num_options) {
num_options = num;
}
if (Z_TYPE_P(z_coptions) == IS_ARRAY) {
array_copy(Z_ARRVAL_P(z_coptions), options);
}
- if (z_roptions) {
- if (Z_TYPE_P(z_roptions) == IS_ARRAY) {
- array_join(Z_ARRVAL_P(z_roptions), options, 0, 0);
- }
- zval_ptr_dtor(&z_roptions);
+ if (Z_TYPE(z_roptions) == IS_ARRAY) {
+ array_join(Z_ARRVAL(z_roptions), options, 0, 0);
}
+ zval_ptr_dtor(&z_roptions);
+
return options;
}
static void msg_queue_dtor(php_http_client_enqueue_t *e)
{
php_http_message_object_t *msg_obj = e->opaque;
- TSRMLS_FETCH_FROM_CTX(msg_obj->message->ts);
- zend_objects_store_del_ref_by_handle_ex(msg_obj->zv.handle, msg_obj->zv.handlers TSRMLS_CC);
+ zend_objects_store_del(&msg_obj->zo);
zend_hash_destroy(e->options);
FREE_HASHTABLE(e->options);
if (e->closure.fci.size) {
zval_ptr_dtor(&e->closure.fci.function_name);
- if (e->closure.fci.object_ptr) {
- zval_ptr_dtor(&e->closure.fci.object_ptr);
+ if (e->closure.fci.object) {
+ zend_objects_store_del(e->closure.fci.object);
}
}
}
php_http_message_object_t *msg_obj;
php_http_client_enqueue_t q;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_get_client_request_class_entry(), &fci, &fcc), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ msg_obj = PHP_HTTP_OBJ(NULL, request);
if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
php_http_throw(bad_method_call, "Failed to enqueue request; request already in queue", NULL);
}
q.request = msg_obj->message;
- q.options = combined_options(getThis(), request TSRMLS_CC);
+ q.options = combined_options(getThis(), request);
q.dtor = msg_queue_dtor;
q.opaque = msg_obj;
q.closure.fci = fci;
q.closure.fcc = fcc;
if (fci.size) {
- Z_ADDREF_P(fci.function_name);
- if (fci.object_ptr) {
- Z_ADDREF_P(fci.object_ptr);
+ Z_TRY_ADDREF(fci.function_name);
+ if (fci.object) {
+ ++GC_REFCOUNT(fci.object);
}
}
- zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
+ Z_ADDREF_P(request);
php_http_expect(SUCCESS == php_http_client_enqueue(obj->client, &q), runtime,
msg_queue_dtor(&q);
php_http_client_object_t *obj;
php_http_message_object_t *msg_obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ msg_obj = PHP_HTTP_OBJ(NULL, request);
if (!php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
php_http_throw(bad_method_call, "Failed to dequeue request; request not in queue", NULL);
php_http_message_object_t *msg_obj;
php_http_client_enqueue_t q;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_get_client_request_class_entry(), &fci, &fcc), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ msg_obj = PHP_HTTP_OBJ(NULL, request);
if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
php_http_expect(SUCCESS == php_http_client_dequeue(obj->client, msg_obj->message), runtime, return);
}
q.request = msg_obj->message;
- q.options = combined_options(getThis(), request TSRMLS_CC);
+ q.options = combined_options(getThis(), request);
q.dtor = msg_queue_dtor;
q.opaque = msg_obj;
q.closure.fci = fci;
q.closure.fcc = fcc;
if (fci.size) {
- Z_ADDREF_P(fci.function_name);
- if (fci.object_ptr) {
- Z_ADDREF_P(fci.object_ptr);
+ Z_TRY_ADDREF(fci.function_name);
+ if (fci.object) {
+ ++GC_REFCOUNT(fci.object);
}
}
- zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
+ Z_ADDREF_P(request);
php_http_expect(SUCCESS == php_http_client_enqueue(obj->client, &q), runtime,
msg_queue_dtor(&q);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, count)
{
- long count_mode = -1;
+ zend_long count_mode = -1;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &count_mode)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &count_mode)) {
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
RETVAL_LONG(zend_llist_count(&obj->client->requests));
}
zval *zrequest = NULL;
php_http_client_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &zrequest, php_http_get_client_request_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
if (zrequest) {
/* lookup the response with the request */
zend_llist_element *el = NULL;
- php_http_message_object_t *req_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
+ php_http_message_object_t *req_obj = PHP_HTTP_OBJ(NULL, zrequest);
for (el = obj->client->responses.head; el; el = el->next) {
php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data;
if (response_obj->message->parent == req_obj->message) {
- RETURN_OBJVAL(response_obj->zv, 1);
+ RETURN_OBJECT(&response_obj->zo, 1);
}
}
/* pop off and go */
if (response_obj) {
- RETVAL_OBJVAL(response_obj->zv, 1);
+ RETVAL_OBJECT(&response_obj->zo, 1);
zend_llist_remove_tail(&obj->client->responses);
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, getHistory)
{
- zval *zhistory;
+ zval zhistory_tmp, *zhistory;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC);
+ zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0, &zhistory_tmp);
RETVAL_ZVAL(zhistory, 1, 0);
}
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_expect(SUCCESS == php_http_client_exec(obj->client), runtime, return);
static PHP_METHOD(HttpClient, once)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
RETURN_BOOL(0 < php_http_client_once(obj->client));
}
{
double timeout = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|d", &timeout)) {
struct timeval timeout_val;
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
timeout_val.tv_sec = (time_t) timeout;
timeout_val.tv_usec = PHP_HTTP_USEC(timeout) % PHP_HTTP_MCROSEC;
HashTable *settings = NULL;
php_http_client_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H!", &settings), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H!", &settings), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_expect(SUCCESS == php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_CONFIGURATION, settings), unexpected_val, return);
zend_bool enable = 1;
php_http_client_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &enable), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_expect(SUCCESS == php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING, &enable), unexpected_val, return);
zend_bool enable = 1;
php_http_client_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &enable), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_expect(SUCCESS == php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_USE_EVENTS, &enable), unexpected_val, return);
struct notify_arg {
php_http_object_method_t *cb;
- zval **args[3];
+ zval args[3];
int argc;
};
-static int notify(zend_object_iterator *iter, void *puser TSRMLS_DC)
+static int notify(zend_object_iterator *iter, void *puser)
{
- zval **observer = NULL;
+ zval *observer;
struct notify_arg *arg = puser;
- iter->funcs->get_current_data(iter, &observer TSRMLS_CC);
- if (observer) {
- return php_http_object_method_call(arg->cb, *observer, NULL, arg->argc, arg->args TSRMLS_CC);
+ if ((observer = iter->funcs->get_current_data(iter))) {
+ if (SUCCESS == php_http_object_method_call(arg->cb, observer, NULL, arg->argc, arg->args)) {
+ return ZEND_HASH_APPLY_KEEP;
+ }
}
- return FAILURE;
+ return ZEND_HASH_APPLY_STOP;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, notify)
{
- zval *request = NULL, *zprogress = NULL, *observers;
+ zval *request = NULL, *zprogress = NULL, observers_tmp, *observers;
php_http_client_object_t *client_obj;
struct notify_arg arg = {NULL};
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_class_entry, &zprogress), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O!o!", &request, php_http_get_client_request_class_entry(), &zprogress), invalid_arg, return);
- client_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+ client_obj = PHP_HTTP_OBJ(NULL, getThis());
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp);
if (Z_TYPE_P(observers) != IS_OBJECT) {
php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
if (client_obj->update) {
arg.cb = client_obj->update;
-
- Z_ADDREF_P(getThis());
- arg.args[0] = &getThis();
+ ZVAL_COPY(&arg.args[0], getThis());
arg.argc = 1;
if (request) {
- Z_ADDREF_P(request);
- arg.args[1] = &request;
+ ZVAL_COPY(&arg.args[1], request);
arg.argc += 1;
}
-
if (zprogress) {
- Z_ADDREF_P(zprogress);
- arg.args[2] = &zprogress;
+ ZVAL_COPY(&arg.args[2], zprogress);
arg.argc += 1;
}
- spl_iterator_apply(observers, notify, &arg TSRMLS_CC);
+ spl_iterator_apply(observers, notify, &arg);
- zval_ptr_dtor(&getThis());
+ zval_ptr_dtor(getThis());
if (request) {
- zval_ptr_dtor(&request);
+ zval_ptr_dtor(request);
}
if (zprogress) {
- zval_ptr_dtor(&zprogress);
+ zval_ptr_dtor(zprogress);
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, attach)
{
- zval *observers, *observer, *retval = NULL;
+ zval observers_tmp, *observers, *observer, retval;
php_http_client_object_t *client_obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &observer, spl_ce_SplObserver), invalid_arg, return);
- client_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+ client_obj = PHP_HTTP_OBJ(NULL, getThis());
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp);
if (Z_TYPE_P(observers) != IS_OBJECT) {
php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
}
if (!client_obj->update) {
- client_obj->update = php_http_object_method_init(NULL, observer, ZEND_STRL("update") TSRMLS_CC);
+ client_obj->update = php_http_object_method_init(NULL, observer, ZEND_STRL("update"));
}
- zend_call_method_with_1_params(&observers, NULL, NULL, "attach", &retval, observer);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ ZVAL_UNDEF(&retval);
+ zend_call_method_with_1_params(observers, NULL, NULL, "attach", &retval, observer);
+ zval_ptr_dtor(&retval);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, detach)
{
- zval *observers, *observer, *retval = NULL;
+ zval observers_tmp, *observers, *observer, retval;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &observer, spl_ce_SplObserver), invalid_arg, return);
- observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp);
if (Z_TYPE_P(observers) != IS_OBJECT) {
php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
return;
}
- zend_call_method_with_1_params(&observers, NULL, NULL, "detach", &retval, observer);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ ZVAL_UNDEF(&retval);
+ zend_call_method_with_1_params(observers, NULL, NULL, "detach", &retval, observer);
+ zval_ptr_dtor(&retval);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, getObservers)
{
- zval *observers;
+ zval observers_tmp, *observers;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp);
if (Z_TYPE_P(observers) != IS_OBJECT) {
php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
php_http_message_object_t *req_obj;
php_http_client_progress_state_t *progress;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- req_obj = zend_object_store_get_object(request TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ req_obj = PHP_HTTP_OBJ(NULL, request);
php_http_expect(SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, req_obj->message, &progress), unexpected_val, return);
object_init(return_value);
add_property_bool(return_value, "started", progress->started);
add_property_bool(return_value, "finished", progress->finished);
- add_property_string(return_value, "info", STR_PTR(progress->info), 1);
+ add_property_string(return_value, "info", STR_PTR(progress->info));
add_property_double(return_value, "dltotal", progress->dl.total);
add_property_double(return_value, "dlnow", progress->dl.now);
add_property_double(return_value, "ultotal", progress->ul.total);
php_http_client_object_t *obj;
php_http_message_object_t *req_obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &request, php_http_get_client_request_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- req_obj = zend_object_store_get_object(request TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ req_obj = PHP_HTTP_OBJ(NULL, request);
object_init(return_value);
info = HASH_OF(return_value);
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set(getThis(), opts TSRMLS_CC);
+ php_http_client_options_set(getThis(), opts);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, getOptions)
{
if (SUCCESS == zend_parse_parameters_none()) {
- zval *options = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ zval options_tmp, *options = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0, &options_tmp);
RETVAL_ZVAL(options, 1, 0);
}
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("ssl"), opts, 1);
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("ssl"), opts, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, getSslOptions)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_options_get_subr(getThis(), ZEND_STRS("ssl"), return_value TSRMLS_CC);
+ php_http_client_options_get_subr(getThis(), ZEND_STRL("ssl"), return_value);
}
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 1 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("cookies"), opts, 1);
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("cookies"), opts, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, getCookies)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_options_get_subr(getThis(), ZEND_STRS("cookies"), return_value TSRMLS_CC);
+ php_http_client_options_get_subr(getThis(), ZEND_STRL("cookies"), return_value);
}
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getAvailableDrivers, 0, 0, 0)
ZEND_END_ARG_INFO();
-static PHP_METHOD(HttpClient, getAvailableDrivers) {
+static PHP_METHOD(HttpClient, getAvailableDrivers)
+{
if (SUCCESS == zend_parse_parameters_none()) {
array_init(return_value);
- php_http_client_driver_list(Z_ARRVAL_P(return_value) TSRMLS_CC);
+ php_http_client_driver_list(Z_ARRVAL_P(return_value));
}
}
static PHP_METHOD(HttpClient, getAvailableOptions)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
array_init(return_value);
php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS, NULL, &Z_ARRVAL_P(return_value));
static PHP_METHOD(HttpClient, getAvailableConfiguration)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
array_init(return_value);
php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION, NULL, &Z_ARRVAL_P(return_value));
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Client", php_http_client_methods);
- php_http_client_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+ php_http_client_class_entry = zend_register_internal_class_ex(&ce, NULL);
php_http_client_class_entry->create_object = php_http_client_object_new;
- zend_class_implements(php_http_client_class_entry TSRMLS_CC, 2, spl_ce_SplSubject, spl_ce_Countable);
+ zend_class_implements(php_http_client_class_entry, 2, spl_ce_SplSubject, spl_ce_Countable);
memcpy(&php_http_client_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_client_object_handlers.offset = XtOffsetOf(php_http_client_object_t, zo);
+ php_http_client_object_handlers.free_obj = php_http_client_object_free;
php_http_client_object_handlers.clone_obj = NULL;
- zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE TSRMLS_CC);
- zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("history"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_bool(php_http_client_class_entry, ZEND_STRL("recordHistory"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE);
+ zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("history"), ZEND_ACC_PROTECTED);
+ zend_declare_property_bool(php_http_client_class_entry, ZEND_STRL("recordHistory"), 0, ZEND_ACC_PUBLIC);
- zend_hash_init(&php_http_client_drivers, 2, NULL, NULL, 1);
+ zend_hash_init(&php_http_client_drivers, 2, NULL, php_http_client_driver_hash_dtor, 1);
return SUCCESS;
}
} php_http_client_ops_t;
typedef struct php_http_client_driver {
- const char *name_str;
- size_t name_len;
+ zend_string *driver_name;
+ zend_string *client_name;
+ zend_string *request_name;
php_http_client_ops_t *client_ops;
} php_http_client_driver_t;
PHP_HTTP_API ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver);
+PHP_HTTP_API php_http_client_driver_t *php_http_client_driver_get(zend_string *name);
typedef struct php_http_client_progress_state {
struct {
zend_llist requests;
zend_llist responses;
-
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_client_t;
-PHP_HTTP_API zend_class_entry *php_http_client_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_client_get_class_entry();
typedef struct php_http_client_object {
- zend_object zo;
- zend_object_value zv;
php_http_client_t *client;
- long iterator;
php_http_object_method_t *update;
php_http_object_method_t notify;
+ long iterator;
+ zend_object zo;
} php_http_client_object_t;
-PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC);
+PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg);
PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, php_http_client_t *to);
PHP_HTTP_API void php_http_client_dtor(php_http_client_t *h);
PHP_HTTP_API void php_http_client_free(php_http_client_t **h);
php_http_buffer_t cookies;
php_http_buffer_t ranges;
- long redirects;
- unsigned range_request:1;
- unsigned encode_cookies:1;
-
struct {
uint count;
double delay;
} retry;
+ long redirects;
+ unsigned range_request:1;
+ unsigned encode_cookies:1;
+
} options;
} php_http_client_curl_handler_t;
return st;
}
-static void *php_http_curle_ctor(void *opaque, void *init_arg TSRMLS_DC)
+static void *php_http_curle_ctor(void *opaque, void *init_arg)
{
void *ch;
return NULL;
}
-static void *php_http_curle_copy(void *opaque, void *handle TSRMLS_DC)
+static void *php_http_curle_copy(void *opaque, void *handle)
{
void *ch;
return NULL;
}
-static void php_http_curle_dtor(void *opaque, void *handle TSRMLS_DC)
+static void php_http_curle_dtor(void *opaque, void *handle)
{
php_http_curle_storage_t *st = php_http_curle_get_storage(handle);
php_http_curle_dtor
};
-static void *php_http_curlm_ctor(void *opaque, void *init_arg TSRMLS_DC)
+static void *php_http_curlm_ctor(void *opaque, void *init_arg)
{
return curl_multi_init();
}
-static void php_http_curlm_dtor(void *opaque, void *handle TSRMLS_DC)
+static void php_http_curlm_dtor(void *opaque, void *handle)
{
curl_multi_cleanup(handle);
}
{
php_http_message_body_t *body = ctx;
- if (body && body->stream_id) {
+ if (body && body->res) {
php_stream *s = php_http_message_body_stream(body);
if (s) {
- TSRMLS_FETCH_FROM_CTX(body->ts);
return php_stream_read(s, data, len * n);
} else abort();
}
static int php_http_curle_seek_callback(void *userdata, curl_off_t offset, int origin)
{
php_http_message_body_t *body = userdata;
- TSRMLS_FETCH_FROM_CTX(body->ts);
if (!body) {
return 1;
static ZEND_RESULT_CODE php_http_curle_get_info(CURL *ch, HashTable *info)
{
- char *c;
- long l;
- double d;
- struct curl_slist *s, *p;
- zval *subarray, array;
- INIT_PZVAL_ARRAY(&array, info);
+ char *c = NULL;
+ long l = 0;
+ double d = 0;
+ struct curl_slist *s = NULL, *p = NULL;
+ zval tmp = {{0}};
/* BEGIN::CURLINFO */
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_EFFECTIVE_URL, &c)) {
- add_assoc_string_ex(&array, "effective_url", sizeof("effective_url"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "effective_url", lenof("effective_url"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_RESPONSE_CODE, &l)) {
- add_assoc_long_ex(&array, "response_code", sizeof("response_code"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "response_code", lenof("response_code"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_TOTAL_TIME, &d)) {
- add_assoc_double_ex(&array, "total_time", sizeof("total_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "total_time", lenof("total_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_NAMELOOKUP_TIME, &d)) {
- add_assoc_double_ex(&array, "namelookup_time", sizeof("namelookup_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "namelookup_time", lenof("namelookup_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONNECT_TIME, &d)) {
- add_assoc_double_ex(&array, "connect_time", sizeof("connect_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "connect_time", lenof("connect_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRETRANSFER_TIME, &d)) {
- add_assoc_double_ex(&array, "pretransfer_time", sizeof("pretransfer_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "pretransfer_time", lenof("pretransfer_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SIZE_UPLOAD, &d)) {
- add_assoc_double_ex(&array, "size_upload", sizeof("size_upload"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "size_upload", lenof("size_upload"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SIZE_DOWNLOAD, &d)) {
- add_assoc_double_ex(&array, "size_download", sizeof("size_download"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "size_download", lenof("size_download"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SPEED_DOWNLOAD, &d)) {
- add_assoc_double_ex(&array, "speed_download", sizeof("speed_download"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "speed_download", lenof("speed_download"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SPEED_UPLOAD, &d)) {
- add_assoc_double_ex(&array, "speed_upload", sizeof("speed_upload"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "speed_upload", lenof("speed_upload"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HEADER_SIZE, &l)) {
- add_assoc_long_ex(&array, "header_size", sizeof("header_size"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "header_size", lenof("header_size"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REQUEST_SIZE, &l)) {
- add_assoc_long_ex(&array, "request_size", sizeof("request_size"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "request_size", lenof("request_size"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SSL_VERIFYRESULT, &l)) {
- add_assoc_long_ex(&array, "ssl_verifyresult", sizeof("ssl_verifyresult"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "ssl_verifyresult", lenof("ssl_verifyresult"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_FILETIME, &l)) {
- add_assoc_long_ex(&array, "filetime", sizeof("filetime"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "filetime", lenof("filetime"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
- add_assoc_double_ex(&array, "content_length_download", sizeof("content_length_download"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "content_length_download", lenof("content_length_download"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_LENGTH_UPLOAD, &d)) {
- add_assoc_double_ex(&array, "content_length_upload", sizeof("content_length_upload"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "content_length_upload", lenof("content_length_upload"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_STARTTRANSFER_TIME, &d)) {
- add_assoc_double_ex(&array, "starttransfer_time", sizeof("starttransfer_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "starttransfer_time", lenof("starttransfer_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONTENT_TYPE, &c)) {
- add_assoc_string_ex(&array, "content_type", sizeof("content_type"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "content_type", lenof("content_type"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_TIME, &d)) {
- add_assoc_double_ex(&array, "redirect_time", sizeof("redirect_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "redirect_time", lenof("redirect_time"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_COUNT, &l)) {
- add_assoc_long_ex(&array, "redirect_count", sizeof("redirect_count"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "redirect_count", lenof("redirect_count"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HTTP_CONNECTCODE, &l)) {
- add_assoc_long_ex(&array, "connect_code", sizeof("connect_code"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "connect_code", lenof("connect_code"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_HTTPAUTH_AVAIL, &l)) {
- add_assoc_long_ex(&array, "httpauth_avail", sizeof("httpauth_avail"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "httpauth_avail", lenof("httpauth_avail"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PROXYAUTH_AVAIL, &l)) {
- add_assoc_long_ex(&array, "proxyauth_avail", sizeof("proxyauth_avail"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "proxyauth_avail", lenof("proxyauth_avail"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_OS_ERRNO, &l)) {
- add_assoc_long_ex(&array, "os_errno", sizeof("os_errno"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "os_errno", lenof("os_errno"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_NUM_CONNECTS, &l)) {
- add_assoc_long_ex(&array, "num_connects", sizeof("num_connects"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "num_connects", lenof("num_connects"), &tmp);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_SSL_ENGINES, &s)) {
- MAKE_STD_ZVAL(subarray);
- array_init(subarray);
+ array_init(&tmp);
for (p = s; p; p = p->next) {
if (p->data) {
- add_next_index_string(subarray, p->data, 1);
+ add_next_index_string(&tmp, p->data);
}
}
- add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
+ zend_hash_str_update(info, "ssl_engines", lenof("ssl_engines"), &tmp);
curl_slist_free_all(s);
}
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_REDIRECT_URL, &c)) {
- add_assoc_string_ex(&array, "redirect_url", sizeof("redirect_url"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "redirect_url", lenof("redirect_url"), &tmp);
}
#if PHP_HTTP_CURL_VERSION(7,19,0)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_IP, &c)) {
- add_assoc_string_ex(&array, "primary_ip", sizeof("primary_ip"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "primary_ip", lenof("primary_ip"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,19,0)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_APPCONNECT_TIME, &d)) {
- add_assoc_double_ex(&array, "appconnect_time", sizeof("appconnect_time"), d);
+ ZVAL_DOUBLE(&tmp, d);
+ zend_hash_str_update(info, "appconnect_time", lenof("appconnect_time"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,19,4)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CONDITION_UNMET, &l)) {
- add_assoc_long_ex(&array, "condition_unmet", sizeof("condition_unmet"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "condition_unmet", lenof("condition_unmet"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,21,0)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_PRIMARY_PORT, &l)) {
- add_assoc_long_ex(&array, "primary_port", sizeof("primary_port"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "primary_port", lenof("primary_port"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,21,0)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_IP, &c)) {
- add_assoc_string_ex(&array, "local_ip", sizeof("local_ip"), c ? c : "", 1);
+ ZVAL_STRING(&tmp, STR_PTR(c));
+ zend_hash_str_update(info, "local_ip", lenof("local_ip"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,21,0)
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_LOCAL_PORT, &l)) {
- add_assoc_long_ex(&array, "local_port", sizeof("local_port"), l);
+ ZVAL_LONG(&tmp, l);
+ zend_hash_str_update(info, "local_port", lenof("local_port"), &tmp);
}
#endif
#if PHP_HTTP_CURL_VERSION(7,34,0)
{
- zval *ti_array;
+ zval ti_array, subarray;
struct curl_tlssessioninfo *ti;
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_TLS_SESSION, &ti)) {
- const char *backend;
+ char *backend;
- MAKE_STD_ZVAL(subarray);
- ZVAL_NULL(subarray);
- MAKE_STD_ZVAL(ti_array);
- array_init(ti_array);
+ ZVAL_NULL(&subarray);
+ array_init(&ti_array);
switch (ti->backend) {
case CURLSSLBACKEND_NONE:
{
SSL_CTX *ctx = ti->internals;
- array_init(subarray);
- add_assoc_long_ex(subarray, ZEND_STRS("number"), SSL_CTX_sess_number(ctx));
- add_assoc_long_ex(subarray, ZEND_STRS("connect"), SSL_CTX_sess_connect(ctx));
- add_assoc_long_ex(subarray, ZEND_STRS("connect_good"), SSL_CTX_sess_connect_good(ctx));
- add_assoc_long_ex(subarray, ZEND_STRS("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx));
- add_assoc_long_ex(subarray, ZEND_STRS("hits"), SSL_CTX_sess_hits(ctx));
- add_assoc_long_ex(subarray, ZEND_STRS("cache_full"), SSL_CTX_sess_cache_full(ctx));
+ array_init(&subarray);
+ add_assoc_long_ex(&subarray, ZEND_STRL("number"), SSL_CTX_sess_number(ctx));
+ add_assoc_long_ex(&subarray, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx));
+ add_assoc_long_ex(&subarray, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx));
+ add_assoc_long_ex(&subarray, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx));
+ add_assoc_long_ex(&subarray, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx));
+ add_assoc_long_ex(&subarray, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx));
}
#endif
break;
gnutls_session_t sess = ti->internals;
char *desc;
- array_init(subarray);
+ array_init(&subarray);
if ((desc = gnutls_session_get_desc(sess))) {
- add_assoc_string_ex(subarray, ZEND_STRS("desc"), desc, 1);
+ add_assoc_string_ex(&subarray, ZEND_STRL("desc"), desc);
gnutls_free(desc);
}
- add_assoc_bool_ex(subarray, ZEND_STRS("resumed"), gnutls_session_is_resumed(sess));
+ add_assoc_bool_ex(&subarray, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess));
}
#endif
break;
default:
backend = "unknown";
}
- add_assoc_string_ex(ti_array, ZEND_STRS("backend"), estrdup(backend), 0);
- add_assoc_zval_ex(ti_array, ZEND_STRS("internals"), subarray);
- add_assoc_zval_ex(&array, "tls_session", sizeof("tls_session"), ti_array);
+ add_assoc_string_ex(&ti_array, ZEND_STRL("backend"), backend);
+ add_assoc_zval_ex(&ti_array, ZEND_STRL("internals"), &subarray);
+ zend_hash_str_update(info, "tls_session", lenof("tls_session"), &ti_array);
}
}
#endif
#if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
{
int i;
- zval *ci_array;
+ zval ci_array, subarray;
struct curl_certinfo *ci;
char *colon, *keyname;
if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_CERTINFO, &ci)) {
- MAKE_STD_ZVAL(ci_array);
- array_init(ci_array);
+ array_init(&ci_array);
for (i = 0; i < ci->num_of_certs; ++i) {
s = ci->certinfo[i];
- MAKE_STD_ZVAL(subarray);
- array_init(subarray);
+ array_init(&subarray);
for (p = s; p; p = p->next) {
if (p->data) {
if ((colon = strchr(p->data, ':'))) {
keyname = estrndup(p->data, colon - p->data);
- add_assoc_string_ex(subarray, keyname, colon - p->data + 1, colon + 1, 1);
+ add_assoc_string_ex(&subarray, keyname, colon - p->data, colon + 1);
efree(keyname);
} else {
- add_next_index_string(subarray, p->data, 1);
+ add_next_index_string(&subarray, p->data);
}
}
}
- add_next_index_zval(ci_array, subarray);
+ add_next_index_zval(&ci_array, &subarray);
}
- add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), ci_array);
+ zend_hash_str_update(info, "certinfo", lenof("certinfo"), &ci_array);
}
}
#endif
{
php_http_curle_storage_t *st = php_http_curle_get_storage(ch);
- add_assoc_long_ex(&array, "curlcode", sizeof("curlcode"), st->errorcode);
- add_assoc_string_ex(&array, "error", sizeof("error"), st->errorbuffer, 1);
+ ZVAL_LONG(&tmp, st->errorcode);
+ zend_hash_str_update(info, "curlcode", lenof("curlcode"), &tmp);
+ ZVAL_STRING(&tmp, st->errorbuffer);
+ zend_hash_str_update(info, "error", lenof("error"), &tmp);
}
return SUCCESS;
return handle == ((php_http_client_curl_handler_t *) e->opaque)->handle;
}
-static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_handler_t *h TSRMLS_DC)
+static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_handler_t *h)
{
php_http_message_t *response;
php_http_header_parser_t parser;
zval *zh;
- response = php_http_message_init(NULL, 0, h->response.body TSRMLS_CC);
- php_http_header_parser_init(&parser TSRMLS_CC);
+ response = php_http_message_init(NULL, 0, h->response.body);
+ php_http_header_parser_init(&parser);
while (h->response.headers.used) {
php_http_header_parser_state_t st = php_http_header_parser_parse(&parser,
&h->response.headers, PHP_HTTP_HEADER_PARSER_CLEANUP, &response->hdrs,
php_http_message_body_addref(h->response.body);
/* let's update the response headers */
- if ((zh = php_http_message_header(response, ZEND_STRL("Content-Length"), 1))) {
- zend_hash_update(&response->hdrs, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), &zh, sizeof(zval *), NULL);
+ if ((zh = php_http_message_header(response, ZEND_STRL("Content-Length")))) {
+ Z_TRY_ADDREF_P(zh);
+ zend_hash_str_update(&response->hdrs, "X-Original-Content-Length", lenof("X-Original-Content-Length"), zh);
}
- if ((zh = php_http_message_header(response, ZEND_STRL("Transfer-Encoding"), 0))) {
- zend_hash_update(&response->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &zh, sizeof(zval *), NULL);
- zend_hash_del(&response->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding"));
+ if ((zh = php_http_message_header(response, ZEND_STRL("Transfer-Encoding")))) {
+ Z_TRY_ADDREF_P(zh);
+ zend_hash_str_update(&response->hdrs, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), zh);
+ zend_hash_str_del(&response->hdrs, "Transfer-Encoding", lenof("Transfer-Encoding"));
}
- if ((zh = php_http_message_header(response, ZEND_STRL("Content-Range"), 0))) {
- zend_hash_update(&response->hdrs, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), &zh, sizeof(zval *), NULL);
- zend_hash_del(&response->hdrs, "Content-Range", sizeof("Content-Range"));
+ if ((zh = php_http_message_header(response, ZEND_STRL("Content-Range")))) {
+ Z_TRY_ADDREF_P(zh);
+ zend_hash_str_update(&response->hdrs, "X-Original-Content-Range", lenof("X-Original-Content-Range"), zh);
+ zend_hash_str_del(&response->hdrs, "Content-Range", lenof("Content-Range"));
}
- if ((zh = php_http_message_header(response, ZEND_STRL("Content-Encoding"), 0))) {
- zend_hash_update(&response->hdrs, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), &zh, sizeof(zval *), NULL);
- zend_hash_del(&response->hdrs, "Content-Encoding", sizeof("Content-Encoding"));
+ if ((zh = php_http_message_header(response, ZEND_STRL("Content-Encoding")))) {
+ Z_TRY_ADDREF_P(zh);
+ zend_hash_str_update(&response->hdrs, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), zh);
+ zend_hash_str_del(&response->hdrs, "Content-Encoding", lenof("Content-Encoding"));
}
php_http_message_update_headers(response);
php_http_curle_storage_t *st, *err = NULL;
php_http_client_enqueue_t *enqueue;
php_http_client_curl_t *curl = context->ctx;
- TSRMLS_FETCH_FROM_CTX(context->ts);
do {
CURLMsg *msg = curl_multi_info_read(curl->handle, &remaining);
if ((enqueue = php_http_client_enqueued(context, msg->easy_handle, compare_queue))) {
php_http_client_curl_handler_t *handler = enqueue->opaque;
- php_http_message_t *response = php_http_curlm_responseparser(handler TSRMLS_CC);
+ php_http_message_t *response = php_http_curlm_responseparser(handler);
if (response) {
context->callback.response.func(context->callback.response.arg, context, &handler->queue, &response);
int i = 0;
do {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s; %s (%s)", curl_easy_strerror(err[i].errorcode), err[i].errorbuffer, STR_PTR(err[i].url));
+ php_error_docref(NULL, E_WARNING, "%s; %s (%s)", curl_easy_strerror(err[i].errorcode), err[i].errorbuffer, STR_PTR(err[i].url));
if (err[i].url) {
efree(err[i].url);
}
#endif
if (curl->useevents) {
CURLMcode rc;
- TSRMLS_FETCH_FROM_CTX(context->ts);
/* ignore and use -1,0 on timeout */
(void) socket;
while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket_action(curl->handle, CURL_SOCKET_TIMEOUT, 0, &curl->unfinished)));
if (CURLM_OK != rc) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_multi_strerror(rc));
+ php_error_docref(NULL, E_WARNING, "%s", curl_multi_strerror(rc));
}
php_http_curlm_responsehandler(context);
#endif
if (curl->useevents) {
CURLMcode rc = CURLM_OK;
- TSRMLS_FETCH_FROM_CTX(context->ts);
while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket_action(curl->handle, socket, etoca(action), &curl->unfinished)));
if (CURLM_OK != rc) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_multi_strerror(rc));
+ php_error_docref(NULL, E_WARNING, "%s", curl_multi_strerror(rc));
}
php_http_curlm_responsehandler(context);
if (curl->useevents) {
int events = EV_PERSIST;
php_http_curlm_event_t *ev = assign_data;
- TSRMLS_FETCH_FROM_CTX(context->ts);
if (!ev) {
ev = ecalloc(1, sizeof(php_http_curlm_event_t));
return 0;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown socket action %d", action);
+ php_error_docref(NULL, E_WARNING, "Unknown socket action %d", action);
return -1;
}
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
- if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, Z_BVAL_P(val) ? 2 : 0)) {
+ if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, Z_TYPE_P(val) == IS_TRUE ? 2 : 0)) {
return FAILURE;
}
return SUCCESS;
if (storage->cookiestore) {
pefree(storage->cookiestore, 1);
}
- if (val && Z_STRLEN_P(val)) {
+ if (val && Z_TYPE_P(val) == IS_STRING && Z_STRLEN_P(val)) {
storage->cookiestore = pestrndup(Z_STRVAL_P(val), Z_STRLEN_P(val), 1);
} else {
storage->cookiestore = NULL;
{
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (val && Z_TYPE_P(val) != IS_NULL) {
+ HashTable *ht = HASH_OF(val);
+
if (curl->options.encode_cookies) {
- if (SUCCESS == php_http_url_encode_hash_ex(HASH_OF(val), &curl->options.cookies, ZEND_STRL(";"), ZEND_STRL("="), NULL, 0 TSRMLS_CC)) {
+ if (SUCCESS == php_http_url_encode_hash_ex(ht, &curl->options.cookies, ZEND_STRL(";"), ZEND_STRL("="), NULL, 0)) {
php_http_buffer_fix(&curl->options.cookies);
if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_COOKIE, curl->options.cookies.data)) {
return FAILURE;
return FAILURE;
}
} else {
- HashPosition pos;
- php_http_array_hashkey_t cookie_key = php_http_array_hashkey_init(0);
- zval **cookie_val;
+ php_http_arrkey_t cookie_key;
+ zval *cookie_val;
- FOREACH_KEYVAL(pos, val, cookie_key, cookie_val) {
- zval *zv = php_http_ztyp(IS_STRING, *cookie_val);
+ ZEND_HASH_FOREACH_KEY_VAL(ht, cookie_key.h, cookie_key.key, cookie_val)
+ {
+ zend_string *zs = zval_get_string(cookie_val);
- php_http_array_hashkey_stringify(&cookie_key);
- php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(zv));
- php_http_array_hashkey_stringfree(&cookie_key);
+ php_http_arrkey_stringify(&cookie_key, NULL);
+ php_http_buffer_appendf(&curl->options.cookies, "%s=%s; ", cookie_key.key->val, zs->val);
+ php_http_arrkey_dtor(&cookie_key);
- zval_ptr_dtor(&zv);
+ zend_string_release(zs);
}
+ ZEND_HASH_FOREACH_END();
php_http_buffer_fix(&curl->options.cookies);
if (curl->options.cookies.used) {
{
php_http_client_curl_handler_t *curl = userdata;
- curl->options.encode_cookies = Z_BVAL_P(val);
+ curl->options.encode_cookies = Z_TYPE_P(val) == IS_TRUE;
return SUCCESS;
}
{
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (Z_LVAL_P(val)) {
if (Z_LVAL_P(val) > 0) {
return FAILURE;
}
} else {
- if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_TIMEVALUE, (long) sapi_get_request_time(TSRMLS_C) + Z_LVAL_P(val))) {
+ if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_TIMEVALUE, (long) sapi_get_request_time() + Z_LVAL_P(val))) {
return FAILURE;
}
}
#if !PHP_HTTP_CURL_VERSION(7,21,6)
# define CURLOPT_ACCEPT_ENCODING CURLOPT_ENCODING
#endif
- if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_ACCEPT_ENCODING, Z_BVAL_P(val) ? "" : NULL)) {
+ if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_ACCEPT_ENCODING, Z_TYPE_P(val) == IS_TRUE ? "" : NULL)) {
return FAILURE;
}
return SUCCESS;
php_http_client_curl_handler_t *curl = userdata;
php_http_buffer_t header;
- if (Z_STRLEN_P(val)) {
+ if (val && Z_TYPE_P(val) == IS_STRING && Z_STRLEN_P(val)) {
zend_bool is_quoted = !((Z_STRVAL_P(val)[0] != '"') || (Z_STRVAL_P(val)[Z_STRLEN_P(val)-1] != '"'));
php_http_buffer_init(&header);
php_http_buffer_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", curl->options.range_request?"If-Match":"If-None-Match", Z_STRVAL_P(val));
{
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
php_http_buffer_reset(&curl->options.ranges);
if (val && Z_TYPE_P(val) != IS_NULL) {
- HashPosition pos;
- zval **rr, **rb, **re;
-
- FOREACH_VAL(pos, val, rr) {
- if (Z_TYPE_PP(rr) == IS_ARRAY) {
- if (2 == php_http_array_list(Z_ARRVAL_PP(rr) TSRMLS_CC, 2, &rb, &re)) {
- if ( ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) &&
- ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) {
- zval *rbl = php_http_ztyp(IS_LONG, *rb);
- zval *rel = php_http_ztyp(IS_LONG, *re);
-
- if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) {
- php_http_buffer_appendf(&curl->options.ranges, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel));
+ zval *rr, *rb, *re;
+ zend_long rbl, rel;
+ HashTable *ht = HASH_OF(val);
+
+ ZEND_HASH_FOREACH_VAL(ht, rr)
+ {
+ if (Z_TYPE_P(rr) == IS_ARRAY) {
+ if (2 == php_http_array_list(Z_ARRVAL_P(rr), 2, &rb, &re)) {
+ if ( ((Z_TYPE_P(rb) == IS_LONG) || ((Z_TYPE_P(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_P(rb), Z_STRLEN_P(rb), &rbl, NULL, 1))) &&
+ ((Z_TYPE_P(re) == IS_LONG) || ((Z_TYPE_P(re) == IS_STRING) && is_numeric_string(Z_STRVAL_P(re), Z_STRLEN_P(re), &rel, NULL, 1)))) {
+ if ((rbl >= 0) && (rel >= 0)) {
+ php_http_buffer_appendf(&curl->options.ranges, "%ld-%ld,", rbl, rel);
}
- zval_ptr_dtor(&rbl);
- zval_ptr_dtor(&rel);
}
}
}
}
+ ZEND_HASH_FOREACH_END();
if (curl->options.ranges.used) {
curl->options.range_request = 1;
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
long localport = 0, localportrange = 0;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (val && Z_TYPE_P(val) != IS_NULL) {
- zval **z_port_start, *zps_copy = NULL, **z_port_end, *zpe_copy = NULL;
+ zval *zps, *zpe;
- switch (php_http_array_list(Z_ARRVAL_P(val) TSRMLS_CC, 2, &z_port_start, &z_port_end)) {
+ switch (php_http_array_list(Z_ARRVAL_P(val), 2, &zps, &zpe)) {
case 2:
- zps_copy = php_http_ztyp(IS_LONG, *z_port_start);
- zpe_copy = php_http_ztyp(IS_LONG, *z_port_end);
- localportrange = labs(Z_LVAL_P(zps_copy)-Z_LVAL_P(zpe_copy))+1L;
+ localportrange = labs(zval_get_long(zps)-zval_get_long(zpe))+1L;
/* no break */
case 1:
- if (!zps_copy) {
- zps_copy = php_http_ztyp(IS_LONG, *z_port_start);
- }
- localport = (zpe_copy && Z_LVAL_P(zpe_copy) > 0) ? MIN(Z_LVAL_P(zps_copy), Z_LVAL_P(zpe_copy)) : Z_LVAL_P(zps_copy);
- zval_ptr_dtor(&zps_copy);
- if (zpe_copy) {
- zval_ptr_dtor(&zpe_copy);
- }
+ localport = (zval_get_long(zpe) > 0) ? MIN(zval_get_long(zps), zval_get_long(zpe)) : zval_get_long(zps);
break;
default:
break;
static ZEND_RESULT_CODE php_http_curle_option_set_proxyheader(php_http_option_t *opt, zval *val, void *userdata)
{
php_http_client_curl_handler_t *curl = userdata;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (val && Z_TYPE_P(val) != IS_NULL) {
- php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
- zval **header_val, *header_cpy;
- HashPosition pos;
+ php_http_arrkey_t header_key;
+ zval *header_val;
php_http_buffer_t header;
php_http_buffer_init(&header);
- FOREACH_KEYVAL(pos, val, header_key, header_val) {
- if (header_key.type == HASH_KEY_IS_STRING) {
- header_cpy = php_http_ztyp(IS_STRING, *header_val);
- php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val), header_key.h, header_key.key, header_val)
+ {
+ if (header_key.key) {
+ zend_string *zs = zval_get_string(header_val);
+
+ php_http_buffer_appendf(&header, "%s: %s", header_key.key->val, zs->val);
+ zend_string_release(zs);
+
php_http_buffer_fix(&header);
curl->options.proxyheaders = curl_slist_append(curl->options.proxyheaders, header.data);
php_http_buffer_reset(&header);
- zval_ptr_dtor(&header_cpy);
}
}
+ ZEND_HASH_FOREACH_END();
php_http_buffer_dtor(&header);
}
if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_PROXYHEADER, curl->options.proxyheaders)) {
{
php_http_client_curl_handler_t *curl = userdata;
CURL *ch = curl->handle;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (val && Z_TYPE_P(val) != IS_NULL) {
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- HashPosition pos;
- zval **data;
+ HashTable *ht = HASH_OF(val);
+ zval *data;
- FOREACH_KEYVAL(pos, val, key, data) {
- zval *cpy = php_http_ztyp(IS_STRING, *data);
- curl->options.resolve = curl_slist_append(curl->options.resolve, Z_STRVAL_P(cpy));
- zval_ptr_dtor(&cpy);
+ ZEND_HASH_FOREACH_VAL(ht, data)
+ {
+ zend_string *zs = zval_get_string(data);
+ curl->options.resolve = curl_slist_append(curl->options.resolve, zs->val);
+ zend_string_release(zs);
}
+ ZEND_HASH_FOREACH_END();
if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_RESOLVE, curl->options.resolve)) {
return FAILURE;
}
#endif
-static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
+static void php_http_curle_options_init(php_http_options_t *registry)
{
php_http_option_t *opt;
/* url options */
#if PHP_HTTP_CURL_VERSION(7,42,0)
- php_http_option_register(registry, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("path_as_is"), CURLOPT_PATH_AS_IS, _IS_BOOL);
#endif
/* proxy */
if ((opt = php_http_option_register(registry, ZEND_STRL("proxyauthtype"), CURLOPT_PROXYAUTH, IS_LONG))) {
Z_LVAL(opt->defval) = CURLAUTH_ANYSAFE;
}
- php_http_option_register(registry, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("proxytunnel"), CURLOPT_HTTPPROXYTUNNEL, _IS_BOOL);
#if PHP_HTTP_CURL_VERSION(7,19,4)
php_http_option_register(registry, ZEND_STRL("noproxy"), CURLOPT_NOPROXY, IS_STRING);
#endif
Z_LVAL(opt->defval) = 5;
}
*/
- php_http_option_register(registry, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT, IS_BOOL);
- php_http_option_register(registry, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("fresh_connect"), CURLOPT_FRESH_CONNECT, _IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("forbid_reuse"), CURLOPT_FORBID_REUSE, _IS_BOOL);
/* outgoing interface */
php_http_option_register(registry, ZEND_STRL("interface"), CURLOPT_INTERFACE, IS_STRING);
if ((opt = php_http_option_register(registry, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION, IS_LONG))) {
opt->setter = php_http_curle_option_set_redirect;
}
- php_http_option_register(registry, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH, _IS_BOOL);
#if PHP_HTTP_CURL_VERSION(7,19,1)
php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_LONG);
#endif
if ((opt = php_http_option_register(registry, ZEND_STRL("referer"), CURLOPT_REFERER, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
}
- if ((opt = php_http_option_register(registry, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("autoreferer"), CURLOPT_AUTOREFERER, _IS_BOOL))) {
ZVAL_BOOL(&opt->defval, 1);
}
/* useragent */
if ((opt = php_http_option_register(registry, ZEND_STRL("useragent"), CURLOPT_USERAGENT, IS_STRING))) {
/* don't check strlen, to allow sending no useragent at all */
- ZVAL_STRING(&opt->defval,
+ ZVAL_PSTRING(&opt->defval,
"PECL_HTTP/" PHP_PECL_HTTP_VERSION " "
"PHP/" PHP_VERSION " "
- "libcurl/" LIBCURL_VERSION
- , 0);
+ "libcurl/" LIBCURL_VERSION);
}
/* resume */
}
/* compression */
- if ((opt = php_http_option_register(registry, ZEND_STRL("compress"), 0, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("compress"), 0, _IS_BOOL))) {
opt->setter = php_http_curle_option_set_compress;
}
}
/* cookies */
- if ((opt = php_http_option_register(registry, ZEND_STRL("encodecookies"), 0, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("encodecookies"), 0, _IS_BOOL))) {
opt->setter = php_http_curle_option_set_encodecookies;
ZVAL_BOOL(&opt->defval, 1);
}
}
/* cookiesession, don't load session cookies from cookiestore */
- php_http_option_register(registry, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("cookiesession"), CURLOPT_COOKIESESSION, _IS_BOOL);
/* cookiestore, read initial cookies from that file and store cookies back into that file */
if ((opt = php_http_option_register(registry, ZEND_STRL("cookiestore"), 0, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
#endif
/* tcp */
- php_http_option_register(registry, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("tcp_nodelay"), CURLOPT_TCP_NODELAY, _IS_BOOL);
#if PHP_HTTP_CURL_VERSION(7,25,0)
- php_http_option_register(registry, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("tcp_keepalive"), CURLOPT_TCP_KEEPALIVE, _IS_BOOL);
if ((opt = php_http_option_register(registry, ZEND_STRL("tcp_keepidle"), CURLOPT_TCP_KEEPIDLE, IS_LONG))) {
Z_LVAL(opt->defval) = 60;
}
}
if ((opt = php_http_option_register(registry, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
- ZVAL_STRING(&opt->defval, "PEM", 0);
+ ZVAL_PSTRING(&opt->defval, "PEM");
}
if ((opt = php_http_option_register(registry, ZEND_STRL("key"), CURLOPT_SSLKEY, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
}
if ((opt = php_http_option_register(registry, ZEND_STRL("keytype"), CURLOPT_SSLKEYTYPE, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
- ZVAL_STRING(&opt->defval, "PEM", 0);
+ ZVAL_PSTRING(&opt->defval, "PEM");
}
if ((opt = php_http_option_register(registry, ZEND_STRL("keypasswd"), CURLOPT_SSLKEYPASSWD, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
}
php_http_option_register(registry, ZEND_STRL("engine"), CURLOPT_SSLENGINE, IS_STRING);
php_http_option_register(registry, ZEND_STRL("version"), CURLOPT_SSLVERSION, IS_LONG);
- if ((opt = php_http_option_register(registry, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("verifypeer"), CURLOPT_SSL_VERIFYPEER, _IS_BOOL))) {
ZVAL_BOOL(&opt->defval, 1);
}
- if ((opt = php_http_option_register(registry, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("verifyhost"), CURLOPT_SSL_VERIFYHOST, _IS_BOOL))) {
ZVAL_BOOL(&opt->defval, 1);
opt->setter = php_http_curle_option_set_ssl_verifyhost;
}
#if PHP_HTTP_CURL_VERSION(7,41,0)
- php_http_option_register(registry, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS, _IS_BOOL);
#endif
php_http_option_register(registry, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST, IS_STRING);
if ((opt = php_http_option_register(registry, ZEND_STRL("cainfo"), CURLOPT_CAINFO, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
#ifdef PHP_HTTP_CURL_CAINFO
- ZVAL_STRING(&opt->defval, PHP_HTTP_CURL_CAINFO, 0);
+ ZVAL_PSTRING(&opt->defval, PHP_HTTP_CURL_CAINFO);
#endif
}
if ((opt = php_http_option_register(registry, ZEND_STRL("capath"), CURLOPT_CAPATH, IS_STRING))) {
# endif
#endif
#if (PHP_HTTP_CURL_VERSION(7,19,1) && defined(PHP_HTTP_HAVE_OPENSSL)) || (PHP_HTTP_CURL_VERSION(7,34,0) && defined(PHP_HTTP_HAVE_NSS)) || (PHP_HTTP_CURL_VERSION(7,42,0) && defined(PHP_HTTP_HAVE_GNUTLS)) || (PHP_HTTP_CURL_VERSION(7,39,0) && defined(PHP_HTTP_HAVE_GSKIT))
- php_http_option_register(registry, ZEND_STRL("certinfo"), CURLOPT_CERTINFO, IS_BOOL);
+ if ((opt = php_http_option_register(registry, ZEND_STRL("certinfo"), CURLOPT_CERTINFO, _IS_BOOL))) {
+ ZVAL_FALSE(&opt->defval);
+ }
#endif
#if PHP_HTTP_CURL_VERSION(7,36,0)
- if ((opt = php_http_option_register(registry, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("enable_npn"), CURLOPT_SSL_ENABLE_NPN, _IS_BOOL))) {
ZVAL_BOOL(&opt->defval, 1);
}
- if ((opt = php_http_option_register(registry, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("enable_alpn"), CURLOPT_SSL_ENABLE_ALPN, _IS_BOOL))) {
ZVAL_BOOL(&opt->defval, 1);
}
#endif
}
#endif
#if PHP_HTTP_CURL_VERSION(7,42,0) && (defined(PHP_HTTP_HAVE_NSS) || defined(PHP_HTTP_HAVE_DARWINSSL))
- php_http_option_register(registry, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("falsestart"), CURLOPT_SSL_FALSESTART, _IS_BOOL);
#endif
}
}
zval *option;
if ((option = php_http_option_get(opt, options, NULL))) {
- option = php_http_ztyp(opt->type, option);
- zend_hash_quick_update(&curl->options.cache, opt->name.s, opt->name.l, opt->name.h, &option, sizeof(zval *), NULL);
+ zval zopt;
+
+ ZVAL_DUP(&zopt, option);
+ convert_to_explicit_type(&zopt, opt->type);
+ zend_hash_update(&curl->options.cache, opt->name, &zopt);
+ return zend_hash_find(&curl->options.cache, opt->name);
}
return option;
}
zval tmp;
CURLcode rc = CURLE_OK;
ZEND_RESULT_CODE rv = SUCCESS;
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
if (!val) {
val = &opt->defval;
}
switch (opt->type) {
- case IS_BOOL:
+ case _IS_BOOL:
if (opt->setter) {
rv = opt->setter(opt, val, curl);
- } else if (CURLE_OK != curl_easy_setopt(ch, opt->option, (long) Z_BVAL_P(val))) {
+ } else if (CURLE_OK != curl_easy_setopt(ch, opt->option, (long) (Z_TYPE_P(val) == IS_TRUE))) {
rv = FAILURE;
}
break;
case IS_STRING:
if (opt->setter) {
rv = opt->setter(opt, val, curl);
+ } else if (!val || Z_TYPE_P(val) == IS_NULL) {
+ if (CURLE_OK != (rc = curl_easy_setopt(ch, opt->option, NULL))) {
+ rv = FAILURE;
+ }
} else if ((opt->flags & PHP_HTTP_CURLE_OPTION_CHECK_STRLEN) && !Z_STRLEN_P(val)) {
if (CURLE_OK != (rc = curl_easy_setopt(ch, opt->option, NULL))) {
rv = FAILURE;
}
- } else if ((opt->flags & PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR) && Z_STRVAL_P(val) && SUCCESS != php_check_open_basedir(Z_STRVAL_P(val) TSRMLS_CC)) {
+ } else if ((opt->flags & PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR) && Z_STRVAL_P(val) && SUCCESS != php_check_open_basedir(Z_STRVAL_P(val))) {
if (CURLE_OK != (rc = curl_easy_setopt(ch, opt->option, NULL))) {
rv = FAILURE;
}
break;
}
if (rv != SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_easy_strerror(rc));
+ php_error_docref(NULL, E_NOTICE, "Could not set option %s (%s)", opt->name->val, curl_easy_strerror(rc));
}
return rv;
}
CURLM *ch = curl->handle;
HashTable tmp_ht;
char **bl = NULL;
- TSRMLS_FETCH_FROM_CTX(client->ts);
/* array of char *, ending with a NULL */
if (value && Z_TYPE_P(value) != IS_NULL) {
- zval **entry;
- HashPosition pos;
+ zval *entry;
HashTable *ht = HASH_OF(value);
int c = zend_hash_num_elements(ht);
char **ptr = ecalloc(c + 1, sizeof(char *));
zend_hash_init(&tmp_ht, c, NULL, ZVAL_PTR_DTOR, 0);
array_join(ht, &tmp_ht, 0, ARRAY_JOIN_STRINGIFY);
- FOREACH_HASH_VAL(pos, &tmp_ht, entry) {
- *ptr++ = Z_STRVAL_PP(entry);
+ ZEND_HASH_FOREACH_VAL(&tmp_ht, entry)
+ {
+ *ptr++ = Z_STRVAL_P(entry);
}
+ ZEND_HASH_FOREACH_END();
}
if (CURLM_OK != curl_multi_setopt(ch, opt->option, bl)) {
{
php_http_client_t *client = userdata;
- return php_http_curlm_use_eventloop(client, value && Z_BVAL_P(value));
+ return php_http_curlm_use_eventloop(client, value && Z_TYPE_P(value) == IS_TRUE);
}
#endif
-static void php_http_curlm_options_init(php_http_options_t *registry TSRMLS_DC)
+static void php_http_curlm_options_init(php_http_options_t *registry)
{
php_http_option_t *opt;
php_http_option_register(registry, ZEND_STRL("max_total_connections"), CURLMOPT_MAX_TOTAL_CONNECTIONS, IS_LONG);
#endif
/* enable/disable HTTP pipelining */
- php_http_option_register(registry, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("pipelining"), CURLMOPT_PIPELINING, _IS_BOOL);
/* chunk length threshold for pipelining */
#if PHP_HTTP_CURL_VERSION(7,30,0)
php_http_option_register(registry, ZEND_STRL("chunk_length_penalty_size"), CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, IS_LONG);
#endif
/* events */
#if PHP_HTTP_HAVE_EVENT
- if ((opt = php_http_option_register(registry, ZEND_STRL("use_eventloop"), 0, IS_BOOL))) {
+ if ((opt = php_http_option_register(registry, ZEND_STRL("use_eventloop"), 0, _IS_BOOL))) {
opt->setter = php_http_curlm_option_set_use_eventloop;
}
#endif
zval *orig = val;
CURLMcode rc = CURLM_UNKNOWN_OPTION;
ZEND_RESULT_CODE rv = SUCCESS;
- TSRMLS_FETCH_FROM_CTX(client->ts);
if (!val) {
val = &opt->defval;
} else if (opt->type && Z_TYPE_P(val) != opt->type && !(Z_TYPE_P(val) == IS_NULL && opt->type == IS_ARRAY)) {
- val = php_http_ztyp(opt->type, val);
+ zval zopt;
+
+ ZVAL_DUP(&zopt, val);
+ convert_to_explicit_type(&zopt, opt->type);
+
+ val = &zopt;
}
if (opt->setter) {
rv = opt->setter(opt, val, client);
} else {
switch (opt->type) {
- case IS_BOOL:
- if (CURLM_OK != (rc = curl_multi_setopt(ch, opt->option, (long) Z_BVAL_P(val)))) {
+ case _IS_BOOL:
+ if (CURLM_OK != (rc = curl_multi_setopt(ch, opt->option, (long) zend_is_true(val)))) {
rv = FAILURE;
}
break;
}
if (val && val != orig && val != &opt->defval) {
- zval_ptr_dtor(&val);
+ zval_ptr_dtor(val);
}
if (rv != SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_easy_strerror(rc));
+ php_error_docref(NULL, E_NOTICE, "Could not set option %s (%s)", opt->name->val, curl_easy_strerror(rc));
}
return rv;
}
{
void *handle;
php_http_client_curl_handler_t *handler;
- TSRMLS_FETCH_FROM_CTX(h->ts);
- if (!(handle = php_resource_factory_handle_ctor(rf, NULL TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize curl handle");
+ if (!(handle = php_resource_factory_handle_ctor(rf, NULL))) {
+ php_error_docref(NULL, E_WARNING, "Failed to initialize curl handle");
return NULL;
}
handler->rf = rf;
handler->client = h;
handler->handle = handle;
- handler->response.body = php_http_message_body_init(NULL, NULL TSRMLS_CC);
+ handler->response.body = php_http_message_body_init(NULL, NULL);
php_http_buffer_init(&handler->response.headers);
php_http_buffer_init(&handler->options.cookies);
php_http_buffer_init(&handler->options.ranges);
size_t body_size;
php_http_message_t *msg = enqueue->request;
php_http_curle_storage_t *storage = php_http_curle_get_storage(curl->handle);
- TSRMLS_FETCH_FROM_CTX(curl->client->ts);
/* request url */
if (!PHP_HTTP_INFO(msg).request.url) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot request empty URL");
+ php_error_docref(NULL, E_WARNING, "Cannot request empty URL");
return FAILURE;
}
storage->errorbuffer[0] = '\0';
/* request headers */
php_http_message_update_headers(msg);
if (zend_hash_num_elements(&msg->hdrs)) {
- php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
- zval **header_val, *header_cpy;
- HashPosition pos;
+ php_http_arrkey_t header_key;
+ zval *header_val;
+ zend_string *header_str;
php_http_buffer_t header;
#if !PHP_HTTP_CURL_VERSION(7,23,0)
- zval **ct = NULL;
-
- zend_hash_find(&msg->hdrs, ZEND_STRS("Content-Length"), (void *) &ct);
+ zval *ct = zend_hash_str_find(&msg->hdrs, ZEND_STRL("Content-Length"));
#endif
php_http_buffer_init(&header);
- FOREACH_HASH_KEYVAL(pos, &msg->hdrs, header_key, header_val) {
- if (header_key.type == HASH_KEY_IS_STRING) {
+ ZEND_HASH_FOREACH_KEY_VAL(&msg->hdrs, header_key.h, header_key.key, header_val)
+ {
+ if (header_key.key) {
#if !PHP_HTTP_CURL_VERSION(7,23,0)
/* avoid duplicate content-length header */
- if (ct && *ct == *header_val) {
+ if (ct && ct == header_val) {
continue;
}
#endif
- header_cpy = php_http_ztyp(IS_STRING, *header_val);
- php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
+ header_str = zval_get_string(header_val);
+ php_http_buffer_appendf(&header, "%s: %s", header_key.key->val, header_str->val);
php_http_buffer_fix(&header);
curl->options.headers = curl_slist_append(curl->options.headers, header.data);
php_http_buffer_reset(&header);
-
- zval_ptr_dtor(&header_cpy);
+ zend_string_release(header_str);
}
}
+ ZEND_HASH_FOREACH_END();
php_http_buffer_dtor(&header);
}
curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->options.headers);
curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, PHP_HTTP_INFO(msg).request.method);
}
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use empty request method");
+ php_error_docref(NULL, E_WARNING, "Cannot use empty request method");
return FAILURE;
}
static void php_http_client_curl_handler_dtor(php_http_client_curl_handler_t *handler)
{
- TSRMLS_FETCH_FROM_CTX(handler->client->ts);
-
php_http_client_curl_handler_clear(handler);
- php_resource_factory_handle_dtor(handler->rf, handler->handle TSRMLS_CC);
+ php_resource_factory_handle_dtor(handler->rf, handler->handle);
php_resource_factory_free(&handler->rf);
php_http_message_body_free(&handler->response.body);
php_http_buffer_dtor(&handler->options.cookies);
zend_hash_destroy(&handler->options.cache);
+#if PHP_HTTP_CURL_VERSION(7,21,3)
+ if (handler->options.resolve) {
+ curl_slist_free_all(handler->options.resolve);
+ handler->options.resolve = NULL;
+ }
+#endif
+
if (handler->options.headers) {
curl_slist_free_all(handler->options.headers);
handler->options.headers = NULL;
}
+ if (handler->options.proxyheaders) {
+ curl_slist_free_all(handler->options.proxyheaders);
+ handler->options.proxyheaders = NULL;
+ }
+
efree(handler);
}
static php_http_client_t *php_http_client_curl_init(php_http_client_t *h, void *handle)
{
php_http_client_curl_t *curl;
- TSRMLS_FETCH_FROM_CTX(h->ts);
- if (!handle && !(handle = php_resource_factory_handle_ctor(h->rf, NULL TSRMLS_CC))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize curl handle");
+ if (!handle && !(handle = php_resource_factory_handle_ctor(h->rf, NULL))) {
+ php_error_docref(NULL, E_WARNING, "Failed to initialize curl handle");
return NULL;
}
static void php_http_client_curl_dtor(php_http_client_t *h)
{
php_http_client_curl_t *curl = h->ctx;
- TSRMLS_FETCH_FROM_CTX(h->ts);
#if PHP_HTTP_HAVE_EVENT
if (curl->timeout) {
#endif
curl->unfinished = 0;
- php_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
+ php_resource_factory_handle_dtor(h->rf, curl->handle);
efree(curl);
h->ctx = NULL;
php_http_client_curl_handler_dtor(handler);
}
-static php_resource_factory_t *create_rf(php_http_client_t *h, php_http_client_enqueue_t *enqueue TSRMLS_DC)
+static php_resource_factory_t *create_rf(php_http_client_t *h, php_http_client_enqueue_t *enqueue)
{
php_persistent_handle_factory_t *pf = NULL;
php_resource_factory_t *rf = NULL;
php_http_url_t *url = enqueue->request->http.info.request.url;
if (!url || (!url->host && !url->path)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot request empty URL");
+ php_error_docref(NULL, E_WARNING, "Cannot request empty URL");
return NULL;
}
/* only if the client itself is setup for persistence */
if (php_resource_factory_is_persistent(h->rf)) {
+ zend_string *id;
char *id_str = NULL;
size_t id_len;
int port = url->port ? url->port : 80;
- zval **zport;
+ zval *zport;
- if (SUCCESS == zend_hash_find(enqueue->options, ZEND_STRS("port"), (void *) &zport)) {
- zval *zcpy = php_http_ztyp(IS_LONG, *zport);
+ if ((zport = zend_hash_str_find(enqueue->options, ZEND_STRL("port")))) {
+ zend_long lport = zval_get_long(zport);
- if (Z_LVAL_P(zcpy)) {
- port = Z_LVAL_P(zcpy);
+ if (lport > 0) {
+ port = lport;
}
- zval_ptr_dtor(&zcpy);
}
id_len = spprintf(&id_str, 0, "%s:%d", STR_PTR(url->host), port);
- pf = php_persistent_handle_concede(NULL, ZEND_STRL("http\\Client\\Curl\\Request"), id_str, id_len, NULL, NULL TSRMLS_CC);
- efree(id_str);
+ id = php_http_cs2zs(id_str, id_len);
+ pf = php_persistent_handle_concede(NULL, PHP_HTTP_G->client.curl.driver.request_name, id, NULL, NULL);
+ zend_string_release(id);
}
if (pf) {
php_http_client_curl_handler_t *handler;
php_http_client_progress_state_t *progress;
php_resource_factory_t *rf;
- TSRMLS_FETCH_FROM_CTX(h->ts);
- rf = create_rf(h, enqueue TSRMLS_CC);
+ rf = create_rf(h, enqueue);
if (!rf) {
return FAILURE;
}
return SUCCESS;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not enqueue request: %s", curl_multi_strerror(rs));
+ php_error_docref(NULL, E_WARNING, "Could not enqueue request: %s", curl_multi_strerror(rs));
return FAILURE;
}
}
CURLMcode rs;
php_http_client_curl_t *curl = h->ctx;
php_http_client_curl_handler_t *handler = enqueue->opaque;
- TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_client_curl_handler_clear(handler);
if (CURLM_OK == (rs = curl_multi_remove_handle(curl->handle, handler->handle))) {
zend_llist_del_element(&h->requests, handler->handle, (int (*)(void *, void *)) compare_queue);
return SUCCESS;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not dequeue request: %s", curl_multi_strerror(rs));
+ php_error_docref(NULL, E_WARNING, "Could not dequeue request: %s", curl_multi_strerror(rs));
}
return FAILURE;
{
#if PHP_HTTP_HAVE_EVENT
php_http_client_curl_t *curl = h->ctx;
-#endif
- TSRMLS_FETCH_FROM_CTX(h->ts);
-#if PHP_HTTP_HAVE_EVENT
if (curl->useevents) {
php_http_curlm_timeout_callback(CURL_SOCKET_TIMEOUT, /*EV_READ|EV_WRITE*/0, h);
do {
#endif
if (ev_rc < 0) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in event_base_dispatch()");
+ php_error_docref(NULL, E_ERROR, "Error in event_base_dispatch()");
return FAILURE;
}
} while (curl->unfinished && !EG(exception));
if (SUCCESS != php_http_client_curl_wait(h, NULL)) {
#ifdef PHP_WIN32
/* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "WinSock error: %d", WSAGetLastError());
+ php_error_docref(NULL, E_WARNING, "WinSock error: %d", WSAGetLastError());
#else
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
+ php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
#endif
return FAILURE;
}
return SUCCESS;
}
-static int apply_available_options(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+static int apply_available_options(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key)
{
- php_http_option_t *opt = pDest;
+ php_http_option_t *opt = Z_PTR_P(pDest);
HashTable *ht;
- zval *entry;
+ zval entry;
int c;
ht = va_arg(args, HashTable*);
- MAKE_STD_ZVAL(entry);
-
if ((c = zend_hash_num_elements(&opt->suboptions.options))) {
- array_init_size(entry, c);
- zend_hash_apply_with_arguments(&opt->suboptions.options TSRMLS_CC, apply_available_options, 1, Z_ARRVAL_P(entry));
+ array_init_size(&entry, c);
+ zend_hash_apply_with_arguments(&opt->suboptions.options, apply_available_options, 1, Z_ARRVAL(entry));
} else {
/* catch deliberate NULL options */
if (Z_TYPE(opt->defval) == IS_STRING && !Z_STRVAL(opt->defval)) {
- ZVAL_NULL(entry);
+ ZVAL_NULL(&entry);
} else {
- ZVAL_COPY_VALUE(entry, &opt->defval);
- zval_copy_ctor(entry);
+ ZVAL_ZVAL(&entry, &opt->defval, 1, 0);
}
}
- if (hash_key->nKeyLength) {
- zend_hash_quick_update(ht, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &entry, sizeof(zval *), NULL);
+ if (hash_key->key) {
+ zend_hash_update(ht, hash_key->key, &entry);
} else {
- zend_hash_index_update(ht, hash_key->h, (void *) &entry, sizeof(zval *), NULL);
+ zend_hash_index_update(ht, hash_key->h, &entry);
}
return ZEND_HASH_APPLY_KEEP;
static ZEND_RESULT_CODE php_http_client_curl_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg, void **res)
{
php_http_client_enqueue_t *enqueue;
- TSRMLS_FETCH_FROM_CTX(h->ts);
switch (opt) {
case PHP_HTTP_CLIENT_OPT_PROGRESS_INFO:
break;
case PHP_HTTP_CLIENT_OPT_AVAILABLE_OPTIONS:
- zend_hash_apply_with_arguments(&php_http_curle_options.options TSRMLS_CC, apply_available_options, 1, *(HashTable **) res);
+ zend_hash_apply_with_arguments(&php_http_curle_options.options, apply_available_options, 1, *(HashTable **) res);
break;
case PHP_HTTP_CLIENT_OPT_AVAILABLE_CONFIGURATION:
- zend_hash_apply_with_arguments(&php_http_curlm_options.options TSRMLS_CC, apply_available_options, 1, *(HashTable **) res);
+ zend_hash_apply_with_arguments(&php_http_curlm_options.options, apply_available_options, 1, *(HashTable **) res);
break;
default:
PHP_MINIT_FUNCTION(http_client_curl)
{
php_http_options_t *options;
- php_http_client_driver_t driver = {
- ZEND_STRL("curl"),
- &php_http_client_curl_ops
- };
- if (SUCCESS != php_http_client_driver_add(&driver)) {
+ PHP_HTTP_G->client.curl.driver.driver_name = zend_string_init(ZEND_STRL("curl"), 1);
+ PHP_HTTP_G->client.curl.driver.client_name = zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
+ PHP_HTTP_G->client.curl.driver.request_name = zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
+ PHP_HTTP_G->client.curl.driver.client_ops = &php_http_client_curl_ops;
+
+ if (SUCCESS != php_http_client_driver_add(&PHP_HTTP_G->client.curl.driver)) {
return FAILURE;
}
- if (SUCCESS != php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl"), &php_http_curlm_resource_factory_ops, NULL, NULL TSRMLS_CC)) {
+ if (SUCCESS != php_persistent_handle_provide(PHP_HTTP_G->client.curl.driver.client_name, &php_http_curlm_resource_factory_ops, NULL, NULL)) {
return FAILURE;
}
- if (SUCCESS != php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl\\Request"), &php_http_curle_resource_factory_ops, NULL, NULL TSRMLS_CC)) {
+ if (SUCCESS != php_persistent_handle_provide(PHP_HTTP_G->client.curl.driver.request_name, &php_http_curle_resource_factory_ops, NULL, NULL)) {
return FAILURE;
}
options->getter = php_http_curle_get_option;
options->setter = php_http_curle_set_option;
- php_http_curle_options_init(options TSRMLS_CC);
+ php_http_curle_options_init(options);
}
if ((options = php_http_options_init(&php_http_curlm_options, 1))) {
options->getter = php_http_option_get;
options->setter = php_http_curlm_set_option;
- php_http_curlm_options_init(options TSRMLS_CC);
+ php_http_curlm_options_init(options);
}
/*
PHP_MSHUTDOWN_FUNCTION(http_client_curl)
{
- php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl"), NULL, 0 TSRMLS_CC);
- php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl\\Request"), NULL, 0 TSRMLS_CC);
+ php_persistent_handle_cleanup(PHP_HTTP_G->client.curl.driver.client_name, NULL);
+ php_persistent_handle_cleanup(PHP_HTTP_G->client.curl.driver.request_name, NULL);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.client_name);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.request_name);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.driver_name);
php_http_options_dtor(&php_http_curle_options);
php_http_options_dtor(&php_http_curlm_options);
#if PHP_HTTP_HAVE_CURL
+struct php_http_client_curl_globals {
+ php_http_client_driver_t driver;
+};
+
PHP_MINIT_FUNCTION(http_client_curl);
PHP_MSHUTDOWN_FUNCTION(http_client_curl);
#endif /* PHP_HTTP_HAVE_CURL */
#include "php_http_api.h"
-void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite TSRMLS_DC);
-void php_http_client_options_set(zval *this_ptr, zval *opts TSRMLS_DC);
-void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value TSRMLS_DC);
+static zend_class_entry *php_http_client_request_class_entry;
+zend_class_entry *php_http_get_client_request_class_entry(void)
+{
+ return php_http_client_request_class_entry;
+}
+
+void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zval *opts, int overwrite);
+void php_http_client_options_set(zval *this_ptr, zval *opts);
+void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value);
#define PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj) \
do { \
if (!obj->message) { \
- obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC); \
+ obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL); \
} \
} while(0)
static PHP_METHOD(HttpClientRequest, __construct)
{
char *meth_str = NULL;
- int meth_len = 0;
+ size_t meth_len = 0;
zval *zheaders = NULL, *zbody = NULL, *zurl = NULL;
php_http_message_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!z!a!O!", &meth_str, &meth_len, &zurl, &zheaders, &zbody, php_http_message_body_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!z!a!O!", &meth_str, &meth_len, &zurl, &zheaders, &zbody, php_http_get_message_body_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->message) {
php_http_message_set_type(obj->message, PHP_HTTP_REQUEST);
} else {
- obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL);
}
if (zbody) {
- php_http_expect(SUCCESS == php_http_message_object_set_body(obj, zbody TSRMLS_CC), unexpected_val, return);
+ php_http_expect(SUCCESS == php_http_message_object_set_body(obj, zbody), unexpected_val, return);
}
if (meth_str && meth_len) {
PHP_HTTP_INFO(obj->message).request.method = estrndup(meth_str, meth_len);
}
if (zurl) {
- PHP_HTTP_INFO(obj->message).request.url = php_http_url_from_zval(zurl, ~0 TSRMLS_CC);
+ PHP_HTTP_INFO(obj->message).request.url = php_http_url_from_zval(zurl, ~0);
}
if (zheaders) {
array_copy(Z_ARRVAL_P(zheaders), &obj->message->hdrs);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClientRequest, setContentType)
{
- char *ct_str;
- int ct_len;
+ zend_string *ct_str;
php_http_message_object_t *obj;
- zval *zct;
+ zval zct;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ct_str, &ct_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &ct_str), invalid_arg, return);
- if (ct_len && !strchr(ct_str, '/')) {
- php_http_throw(unexpected_val, "Content type \"%s\" does not seem to contain a primary and a secondary part", ct_str);
+ if (ct_str->len && !strchr(ct_str->val, '/')) {
+ php_http_throw(unexpected_val, "Content type \"%s\" does not seem to contain a primary and a secondary part", ct_str->val);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
- MAKE_STD_ZVAL(zct);
- ZVAL_STRINGL(zct, ct_str, ct_len, 1);
- zend_hash_update(&obj->message->hdrs, "Content-Type", sizeof("Content-Type"), (void *) &zct, sizeof(void *), NULL);
+ ZVAL_STR_COPY(&zct, ct_str);
+ zend_hash_str_update(&obj->message->hdrs, "Content-Type", lenof("Content-Type"), &zct);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClientRequest, getContentType)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zval *zct;
PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
php_http_message_update_headers(obj->message);
- zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
+ zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"));
if (zct) {
- RETURN_ZVAL(zct, 0, 1);
+ RETURN_ZVAL(zct, 1, 0);
}
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClientRequest, setQuery)
{
- zval *qdata = NULL;
+ zval *qdata = NULL, arr, str;
php_http_message_object_t *obj;
php_http_url_t *old_url = NULL, new_url = {NULL};
- char empty[] = "";
unsigned flags = PHP_HTTP_URL_REPLACE;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata), invalid_arg, return);
-
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!", &qdata), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
+ ZVAL_NULL(&str);
if (qdata) {
- zval arr, str;
-
- INIT_PZVAL(&arr);
array_init(&arr);
- INIT_PZVAL(&str);
- ZVAL_NULL(&str);
- php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str TSRMLS_CC), bad_querystring,
+ php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str), bad_querystring,
zval_dtor(&arr);
return;
);
+
new_url.query = Z_STRVAL(str);
zval_dtor(&arr);
} else {
old_url = obj->message->http.info.request.url;
}
- obj->message->http.info.request.url = php_http_url_mod(old_url, &new_url, flags TSRMLS_CC);
+ obj->message->http.info.request.url = php_http_url_mod(old_url, &new_url, flags);
if (old_url) {
php_http_url_free(&old_url);
}
- if (new_url.query != &empty[0]) {
- PTR_FREE(new_url.query);
- }
+ zval_ptr_dtor(&str);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClientRequest, getQuery)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
if (obj->message->http.info.request.url && obj->message->http.info.request.url->query) {
- RETVAL_STRING(obj->message->http.info.request.url->query, 1);
+ RETVAL_STRING(obj->message->http.info.request.url->query);
}
}
}
php_http_message_object_t *obj;
php_http_url_t *old_url = NULL, new_url = {NULL};
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &qdata), invalid_arg, return);
-
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &qdata), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
- INIT_PZVAL(&arr);
array_init(&arr);
- INIT_PZVAL(&str);
ZVAL_NULL(&str);
- php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str TSRMLS_CC), bad_querystring,
+ php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str), bad_querystring,
zval_dtor(&arr);
return;
);
old_url = obj->message->http.info.request.url;
}
- obj->message->http.info.request.url = php_http_url_mod(old_url, &new_url, PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
+ obj->message->http.info.request.url = php_http_url_mod(old_url, &new_url, PHP_HTTP_URL_JOIN_QUERY);
if (old_url) {
php_http_url_free(&old_url);
}
- PTR_FREE(new_url.query);
+ zval_ptr_dtor(&str);
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set(getThis(), opts TSRMLS_CC);
+ php_http_client_options_set(getThis(), opts);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClientRequest, getOptions)
{
if (SUCCESS == zend_parse_parameters_none()) {
- zval *zoptions = zend_read_property(php_http_client_request_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
+ zval tmp, *zoptions = zend_read_property(php_http_client_request_class_entry, getThis(), ZEND_STRL("options"), 0, &tmp);
RETURN_ZVAL(zoptions, 1, 0);
}
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("ssl"), opts, 1);
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *opts = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|a!/", &opts), invalid_arg, return);
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+ php_http_client_options_set_subr(getThis(), ZEND_STRL("ssl"), opts, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClientRequest, getSslOptions)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_options_get_subr(getThis(), ZEND_STRS("ssl"), return_value TSRMLS_CC);
+ php_http_client_options_get_subr(getThis(), ZEND_STRL("ssl"), return_value);
}
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_client_request_class_entry;
-
PHP_MINIT_FUNCTION(http_client_request)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Request", php_http_client_request_methods);
- php_http_client_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
+ php_http_client_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry());
- zend_declare_property_null(php_http_client_request_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_client_request_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED);
return SUCCESS;
}
#ifndef PHP_HTTP_CLIENT_REQUEST_H
#define PHP_HTTP_CLIENT_REQUEST_H
-PHP_HTTP_API zend_class_entry *php_http_client_request_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_client_request_class_entry(void);
PHP_MINIT_FUNCTION(http_client_request);
#endif /* PHP_HTTP_CLIENT_REQUEST_H */
#include "php_http_api.h"
+static zend_class_entry *php_http_client_response_class_entry;
+zend_class_entry *php_http_get_client_response_class_entry(void)
+{
+ return php_http_client_response_class_entry;
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getCookies, 0, 0, 0)
ZEND_ARG_INFO(0, flags)
ZEND_ARG_INFO(0, allowed_extras)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClientResponse, getCookies)
{
- long flags = 0;
+ zend_long flags = 0;
zval *allowed_extras_array = NULL;
int i = 0;
char **allowed_extras = NULL;
- zval *header = NULL, **entry = NULL;
- HashPosition pos;
+ zval *header = NULL, *entry = NULL;
php_http_message_object_t *msg;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|la!/", &flags, &allowed_extras_array)) {
return;
}
- msg = zend_object_store_get_object(getThis() TSRMLS_CC);
+ msg = PHP_HTTP_OBJ(NULL, getThis());
array_init(return_value);
if (allowed_extras_array) {
+ /* FIXME: use zend_string** instead of char** */
allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
- FOREACH_VAL(pos, allowed_extras_array, entry) {
- zval *data = php_http_ztyp(IS_STRING, *entry);
- allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
- zval_ptr_dtor(&data);
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(allowed_extras_array), entry)
+ {
+ zend_string *zs = zval_get_string(entry);
+ allowed_extras[i++] = estrndup(zs->val, zs->len);
+ zend_string_release(zs);
}
+ ZEND_HASH_FOREACH_END();
}
- if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
+ if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie")))) {
php_http_cookie_list_t *list;
if (Z_TYPE_P(header) == IS_ARRAY) {
- zval **single_header;
+ zval *single_header;
- FOREACH_VAL(pos, header, single_header) {
- zval *data = php_http_ztyp(IS_STRING, *single_header);
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(header), single_header)
+ {
+ zend_string *zs = zval_get_string(single_header);
- if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
- zval *cookie;
+ if ((list = php_http_cookie_list_parse(NULL, zs->val, zs->len, flags, allowed_extras))) {
+ zval cookie;
- MAKE_STD_ZVAL(cookie);
- ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
- add_next_index_zval(return_value, cookie);
+ ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo);
+ add_next_index_zval(return_value, &cookie);
}
- zval_ptr_dtor(&data);
+ zend_string_release(zs);
}
+ ZEND_HASH_FOREACH_END();
} else {
- zval *data = php_http_ztyp(IS_STRING, header);
- if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) {
- zval *cookie;
+ zend_string *zs = zval_get_string(header);
- MAKE_STD_ZVAL(cookie);
- ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
- add_next_index_zval(return_value, cookie);
+ if ((list = php_http_cookie_list_parse(NULL, zs->val, zs->len, flags, allowed_extras))) {
+ zval cookie;
+
+ ZVAL_OBJ(&cookie, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo);
+ add_next_index_zval(return_value, &cookie);
}
- zval_ptr_dtor(&data);
+ zend_string_release(zs);
}
- zval_ptr_dtor(&header);
}
if (allowed_extras) {
static PHP_METHOD(HttpClientResponse, getTransferInfo)
{
char *info_name = NULL;
- int info_len = 0;
- zval *info;
+ size_t info_len = 0;
+ zval info_tmp, info_name_tmp, *info;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &info_name, &info_len), invalid_arg, return);
- info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
+ info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0, &info_tmp);
/* request completed? */
if (Z_TYPE_P(info) != IS_OBJECT) {
}
if (info_len && info_name) {
- info = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
+ info = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0, &info_name_tmp);
if (!info) {
php_http_throw(unexpected_val, "Could not find transfer info with name '%s'", info_name);
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_client_response_class_entry;
-
PHP_MINIT_FUNCTION(http_client_response)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Response", php_http_client_response_methods);
- php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
- zend_declare_property_null(php_http_client_response_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry());
+
+ zend_declare_property_null(php_http_client_response_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED);
return SUCCESS;
}
#ifndef PHP_HTTP_CLIENT_RESPONSE_H
#define PHP_HTTP_CLIENT_RESPONSE_H
-PHP_HTTP_API zend_class_entry *php_http_client_response_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_client_response_class_entry(void);
PHP_MINIT_FUNCTION(http_client_response);
#endif /* PHP_HTTP_CLIENT_RESPONSE_H */
#include "php_http_api.h"
-php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list)
{
if (!list) {
list = emalloc(sizeof(*list));
list->max_age = -1;
list->flags = 0;
- TSRMLS_SET_CTX(list->ts);
-
return list;
}
php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to)
{
- TSRMLS_FETCH_FROM_CTX(from->ts);
-
- to = php_http_cookie_list_init(to TSRMLS_CC);
+ to = php_http_cookie_list_init(to);
array_copy(&from->cookies, &to->cookies);
array_copy(&from->extras, &to->extras);
}
}
-const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zcookie)
+const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval *zcookie)
{
- zval **cookie;
- if ((SUCCESS != zend_symtable_find(&list->cookies, name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
+ zval *cookie = zend_symtable_str_find(&list->cookies, name, name_len);
+
+ if (!cookie || (Z_TYPE_P(cookie) != IS_STRING)) {
return NULL;
}
if (zcookie) {
*zcookie = *cookie;
}
- return Z_STRVAL_PP(cookie);
+ return Z_STRVAL_P(cookie);
}
-const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zextra)
+const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval *zextra)
{
- zval **extra;
+ zval *extra = zend_symtable_str_find(&list->extras, name, name_len);
- if ((SUCCESS != zend_symtable_find(&list->extras, name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) {
+ if (!extra || (Z_TYPE_P(extra) != IS_STRING)) {
return NULL;
}
if (zextra) {
*zextra = *extra;
}
- return Z_STRVAL_PP(extra);
+ return Z_STRVAL_P(extra);
}
void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
- zval *cookie_value;
+ zval cookie_value;
- MAKE_STD_ZVAL(cookie_value);
- ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
- zend_symtable_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
+ ZVAL_STRINGL(&cookie_value, value, value_len);
+ zend_symtable_str_update(&list->cookies, name, name_len, &cookie_value);
}
void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
- zval *cookie_value;
+ zval extra_value;
- MAKE_STD_ZVAL(cookie_value);
- ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
- zend_symtable_update(&list->extras, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
+ ZVAL_STRINGL(&extra_value, value, value_len);
+ zend_symtable_str_update(&list->extras, name, name_len, &extra_value);
}
-#define _KEY_IS(s) (key->len == sizeof(s) && !strncasecmp(key->str, (s), key->len))
-static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long flags, php_http_array_hashkey_t *key, zval *val)
+#define _KEY_IS(s) (key->key && key->key->len == sizeof(s)-1 && !strncasecmp(key->key->val, (s), key->key->len))
+static void add_entry(php_http_cookie_list_t *list, char **allowed_extras, long flags, zend_hash_key *key, zval *val)
{
- zval *arg = php_http_zsep(1, IS_STRING, val);
+ zval arg;
+
+ ZVAL_DUP(&arg, val);
+ convert_to_string(&arg);
if (!(flags & PHP_HTTP_COOKIE_PARSE_RAW)) {
- Z_STRLEN_P(arg) = php_raw_url_decode(Z_STRVAL_P(arg), Z_STRLEN_P(arg));
+ Z_STRLEN(arg) = php_raw_url_decode(Z_STRVAL(arg), Z_STRLEN(arg));
+ zend_string_forget_hash_val(Z_STR(arg));
}
if _KEY_IS("path") {
- PTR_SET(list->path, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
+ PTR_SET(list->path, estrndup(Z_STRVAL(arg), Z_STRLEN(arg)));
} else if _KEY_IS("domain") {
- PTR_SET(list->domain, estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg)));
+ PTR_SET(list->domain, estrndup(Z_STRVAL(arg), Z_STRLEN(arg)));
} else if _KEY_IS("expires") {
- char *date = estrndup(Z_STRVAL_P(arg), Z_STRLEN_P(arg));
+ char *date = estrndup(Z_STRVAL(arg), Z_STRLEN(arg));
list->expires = php_parse_date(date, NULL);
efree(date);
} else if _KEY_IS("max-age") {
- list->max_age = strtol(Z_STRVAL_P(arg), NULL, 10);
+ list->max_age = zval_get_long(val);
} else if _KEY_IS("secure") {
list->flags |= PHP_HTTP_COOKIE_SECURE;
} else if _KEY_IS("httpOnly") {
list->flags |= PHP_HTTP_COOKIE_HTTPONLY;
} else {
+ php_http_arrkey_t tmp = {0};
+
+ php_http_arrkey_stringify(&tmp, key);
+
/* check for extra */
if (allowed_extras) {
char **ae = allowed_extras;
-
- php_http_array_hashkey_stringify(key);
for (; *ae; ++ae) {
- if (!strncasecmp(key->str, *ae, key->len)) {
- if (key->type == HASH_KEY_IS_LONG) {
- zend_hash_index_update(&list->extras, key->num, (void *) &arg, sizeof(zval *), NULL);
- } else {
- zend_hash_update(&list->extras, key->str, key->len, (void *) &arg, sizeof(zval *), NULL);
- }
- php_http_array_hashkey_stringfree(key);
+ if (!strncasecmp(*ae, tmp.key->val, tmp.key->len)) {
+ zend_symtable_update(&list->extras, tmp.key, &arg);
+ php_http_arrkey_dtor(&tmp);
return;
}
}
- php_http_array_hashkey_stringfree(key);
}
/* cookie */
- if (key->type == HASH_KEY_IS_LONG) {
- zend_hash_index_update(&list->cookies, key->num, (void *) &arg, sizeof(zval *), NULL);
- } else {
- zend_hash_update(&list->cookies, key->str, key->len, (void *) &arg, sizeof(zval *), NULL);
- }
+ zend_symtable_update(&list->cookies, tmp.key, &arg);
+
+ php_http_arrkey_dtor(&tmp);
return;
}
+
zval_ptr_dtor(&arg);
}
-php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras)
{
php_http_params_opts_t opts;
HashTable params;
- HashPosition pos1, pos2;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **param, **val, **args, **arg;
+ zend_hash_key k, arg_k;
+ zval *param, *val, *args, *arg;
php_http_params_opts_default_get(&opts);
opts.input.str = estrndup(str, len);
opts.input.len = len;
opts.param = NULL;
zend_hash_init(¶ms, 10, NULL, ZVAL_PTR_DTOR, 0);
- php_http_params_parse(¶ms, &opts TSRMLS_CC);
+ php_http_params_parse(¶ms, &opts);
efree(opts.input.str);
- list = php_http_cookie_list_init(list TSRMLS_CC);
- FOREACH_HASH_KEYVAL(pos1, ¶ms, key, param) {
- if (Z_TYPE_PP(param) == IS_ARRAY) {
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(param), ZEND_STRS("value"), (void *) &val)) {
- add_entry(list, NULL, flags, &key, *val);
+ list = php_http_cookie_list_init(list);
+ ZEND_HASH_FOREACH_KEY_VAL(¶ms, k.h, k.key, param)
+ {
+ if (Z_TYPE_P(param) == IS_ARRAY) {
+ if ((val = zend_hash_str_find(Z_ARRVAL_P(param), ZEND_STRL("value")))) {
+ add_entry(list, NULL, flags, &k, val);
}
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(param), ZEND_STRS("arguments"), (void *) &args) && Z_TYPE_PP(args) == IS_ARRAY) {
- FOREACH_KEYVAL(pos2, *args, key, arg) {
- add_entry(list, allowed_extras, flags, &key, *arg);
+ if ((args = zend_hash_str_find(Z_ARRVAL_P(param), ZEND_STRL("arguments"))) && Z_TYPE_P(args) == IS_ARRAY) {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(args), arg_k.h, arg_k.key, arg)
+ {
+ add_entry(list, allowed_extras, flags, &arg_k, arg);
}
+ ZEND_HASH_FOREACH_END();
}
}
}
+ ZEND_HASH_FOREACH_END();
+
zend_hash_destroy(¶ms);
return list;
void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
{
- zval array, *cookies, *extras;
- TSRMLS_FETCH_FROM_CTX(list->ts);
-
- INIT_PZVAL_ARRAY(&array, HASH_OF(strct));
+ zval cookies, extras, tmp;
+ HashTable *ht = HASH_OF(strct);
- MAKE_STD_ZVAL(cookies);
- array_init(cookies);
- zend_hash_copy(Z_ARRVAL_P(cookies), &list->cookies, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- add_assoc_zval(&array, "cookies", cookies);
+ array_init_size(&cookies, zend_hash_num_elements(&list->cookies));
+ array_copy(&list->cookies, Z_ARRVAL(cookies));
+ zend_symtable_str_update(ht, ZEND_STRL("cookies"), &cookies);
- MAKE_STD_ZVAL(extras);
- array_init(extras);
- zend_hash_copy(Z_ARRVAL_P(extras), &list->extras, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- add_assoc_zval(&array, "extras", extras);
+ array_init_size(&extras, zend_hash_num_elements(&list->extras));
+ array_copy(&list->extras, Z_ARRVAL(extras));
+ zend_symtable_str_update(ht, ZEND_STRL("extras"), &extras);
- add_assoc_long(&array, "flags", list->flags);
- add_assoc_long(&array, "expires", (long) list->expires);
- add_assoc_long(&array, "max-age", (long) list->max_age);
- add_assoc_string(&array, "path", STR_PTR(list->path), 1);
- add_assoc_string(&array, "domain", STR_PTR(list->domain), 1);
+ ZVAL_LONG(&tmp, list->flags);
+ zend_symtable_str_update(ht, ZEND_STRL("flags"), &tmp);
+ ZVAL_LONG(&tmp, list->expires);
+ zend_symtable_str_update(ht, ZEND_STRL("expires"), &tmp);
+ ZVAL_LONG(&tmp, list->max_age);
+ zend_symtable_str_update(ht, ZEND_STRL("max-age"), &tmp);
+ ZVAL_STRING(&tmp, STR_PTR(list->path));
+ zend_symtable_str_update(ht, ZEND_STRL("path"), &tmp);
+ ZVAL_STRING(&tmp, STR_PTR(list->domain));
+ zend_symtable_str_update(ht, ZEND_STRL("domain"), &tmp);
}
-php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct)
{
- zval **tmp, *cpy;
- HashTable *ht = HASH_OF(strct);
-
- list = php_http_cookie_list_init(list TSRMLS_CC);
-
- if (SUCCESS == zend_hash_find(ht, "cookies", sizeof("cookies"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_ARRAY) {
- zend_hash_copy(&list->cookies, Z_ARRVAL_PP(tmp), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ zval *tmp;
+ HashTable *ht;
+
+ ht = HASH_OF(strct);
+ list = php_http_cookie_list_init(list);
+
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("cookies"))) && Z_TYPE_P(tmp) == IS_ARRAY){
+ array_copy(Z_ARRVAL_P(tmp), &list->cookies);
}
- if (SUCCESS == zend_hash_find(ht, "extras", sizeof("extras"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_ARRAY) {
- zend_hash_copy(&list->extras, Z_ARRVAL_PP(tmp), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("extras"))) && Z_TYPE_P(tmp) == IS_ARRAY){
+ array_copy(Z_ARRVAL_P(tmp), &list->extras);
}
- if (SUCCESS == zend_hash_find(ht, "flags", sizeof("flags"), (void *) &tmp)) {
- cpy = php_http_ztyp(IS_LONG, *tmp);
- list->flags = Z_LVAL_P(cpy);
- zval_ptr_dtor(&cpy);
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("flags")))) {
+ list->flags = zval_get_long(tmp);
}
- if (SUCCESS == zend_hash_find(ht, "expires", sizeof("expires"), (void *) &tmp)) {
- if (Z_TYPE_PP(tmp) == IS_LONG) {
- list->expires = Z_LVAL_PP(tmp);
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("expires")))) {
+ if (Z_TYPE_P(tmp) == IS_LONG) {
+ list->expires = Z_LVAL_P(tmp);
} else {
- long lval;
+ zend_long lval;
+ zend_string *lstr = zval_get_string(tmp);
- cpy = php_http_ztyp(IS_STRING, *tmp);
- if (IS_LONG == is_numeric_string(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), &lval, NULL, 0)) {
+ if (IS_LONG == is_numeric_string(lstr->val, lstr->len, &lval, NULL, 0)) {
list->expires = lval;
} else {
- list->expires = php_parse_date(Z_STRVAL_P(cpy), NULL);
+ list->expires = php_parse_date(lstr->val, NULL);
}
- zval_ptr_dtor(&cpy);
+ zend_string_release(lstr);
}
}
- if (SUCCESS == zend_hash_find(ht, "max-age", sizeof("max-age"), (void *) &tmp)) {
- if (Z_TYPE_PP(tmp) == IS_LONG) {
- list->max_age = Z_LVAL_PP(tmp);
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("max-age")))) {
+ if (Z_TYPE_P(tmp) == IS_LONG) {
+ list->max_age = Z_LVAL_P(tmp);
} else {
- long lval;
+ zend_long lval;
+ zend_string *lstr = zval_get_string(tmp);
- cpy = php_http_ztyp(IS_STRING, *tmp);
- if (IS_LONG == is_numeric_string(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), &lval, NULL, 0)) {
+ if (IS_LONG == is_numeric_string(lstr->val, lstr->len, &lval, NULL, 0)) {
list->max_age = lval;
}
- zval_ptr_dtor(&cpy);
+ zend_string_release(lstr);
}
}
- if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_STRING) {
- list->path = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("path")))) {
+ zend_string *str = zval_get_string(tmp);
+
+ list->path = estrndup(str->val, str->len);
+ zend_string_release(str);
}
- if (SUCCESS == zend_hash_find(ht, "domain", sizeof("domain"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_STRING) {
- list->domain = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
+ if ((tmp = zend_hash_str_find_ind(ht, ZEND_STRL("domain")))) {
+ zend_string *str = zval_get_string(tmp);
+
+ list->domain = estrndup(str->val, str->len);
+ zend_string_release(str);
}
return list;
static inline void append_encoded(php_http_buffer_t *buf, const char *key, size_t key_len, const char *val, size_t val_len)
{
- char *enc_str[2];
- int enc_len[2];
+ zend_string *enc_str[2];
- enc_str[0] = php_raw_url_encode(key, key_len, &enc_len[0]);
- enc_str[1] = php_raw_url_encode(val, val_len, &enc_len[1]);
+ enc_str[0] = php_raw_url_encode(key, key_len);
+ enc_str[1] = php_raw_url_encode(val, val_len);
- php_http_buffer_append(buf, enc_str[0], enc_len[0]);
+ php_http_buffer_append(buf, enc_str[0]->val, enc_str[0]->len);
php_http_buffer_appends(buf, "=");
- php_http_buffer_append(buf, enc_str[1], enc_len[1]);
+ php_http_buffer_append(buf, enc_str[1]->val, enc_str[1]->len);
php_http_buffer_appends(buf, "; ");
- efree(enc_str[0]);
- efree(enc_str[1]);
+ zend_string_release(enc_str[0]);
+ zend_string_release(enc_str[1]);
}
void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
{
php_http_buffer_t buf;
- zval **val;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- HashPosition pos;
- TSRMLS_FETCH_FROM_CTX(list->ts);
+ zend_hash_key key;
+ zval *val;
php_http_buffer_init(&buf);
-
- FOREACH_HASH_KEYVAL(pos, &list->cookies, key, val) {
- zval *tmp = php_http_ztyp(IS_STRING, *val);
- php_http_array_hashkey_stringify(&key);
- append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
- php_http_array_hashkey_stringfree(&key);
+ ZEND_HASH_FOREACH_KEY_VAL(&list->cookies, key.h, key.key, val)
+ {
+ zend_string *str = zval_get_string(val);
+ php_http_arrkey_t arrkey = {0};
- zval_ptr_dtor(&tmp);
+ php_http_arrkey_stringify(&arrkey, &key);
+ append_encoded(&buf, arrkey.key->val, arrkey.key->len, str->val, str->len);
+ php_http_arrkey_dtor(&arrkey);
+ zend_string_release(str);
}
+ ZEND_HASH_FOREACH_END();
if (list->domain && *list->domain) {
php_http_buffer_appendf(&buf, "domain=%s; ", list->domain);
php_http_buffer_appendf(&buf, "path=%s; ", list->path);
}
if (list->expires >= 0) {
- char *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), list->expires, 0 TSRMLS_CC);
- php_http_buffer_appendf(&buf, "expires=%s; ", date);
- efree(date);
+ zend_string *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), list->expires, 0);
+ php_http_buffer_appendf(&buf, "expires=%s; ", date->val);
+ zend_string_release(date);
}
if (list->max_age >= 0) {
php_http_buffer_appendf(&buf, "max-age=%ld; ", list->max_age);
}
- FOREACH_HASH_KEYVAL(pos, &list->extras, key, val) {
- zval *tmp = php_http_ztyp(IS_STRING, *val);
-
- php_http_array_hashkey_stringify(&key);
- append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
- php_http_array_hashkey_stringfree(&key);
-
- zval_ptr_dtor(&tmp);
+ ZEND_HASH_FOREACH_KEY_VAL(&list->extras, key.h, key.key, val)
+ {
+ zend_string *str = zval_get_string(val);
+ php_http_arrkey_t arrkey;
+
+ php_http_arrkey_stringify(&arrkey, &key);
+ append_encoded(&buf, arrkey.key->val, arrkey.key->len, str->val, str->len);
+ php_http_arrkey_dtor(&arrkey);
+ zend_string_release(str);
}
+ ZEND_HASH_FOREACH_END();
if (list->flags & PHP_HTTP_COOKIE_SECURE) {
php_http_buffer_appends(&buf, "secure; ");
}
+static zend_class_entry *php_http_cookie_class_entry;
+zend_class_entry *php_http_cookie_get_class_entry(void)
+{
+ return php_http_cookie_class_entry;
+}
static zend_object_handlers php_http_cookie_object_handlers;
-zend_object_value php_http_cookie_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_cookie_object_new(zend_class_entry *ce)
{
- return php_http_cookie_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_cookie_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_cookie_list_t *list, php_http_cookie_object_t **ptr TSRMLS_DC)
+php_http_cookie_object_t *php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_cookie_list_t *list)
{
php_http_cookie_object_t *o;
- o = ecalloc(sizeof(*o), 1);
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
+ if (!ce) {
+ ce = php_http_cookie_class_entry;
+ }
+
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
+ o->zo.handlers = &php_http_cookie_object_handlers;
if (list) {
o->list = list;
}
- if (ptr) {
- *ptr = o;
- }
-
- o->zv.handle = zend_objects_store_put(o, NULL, php_http_cookie_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_cookie_object_handlers;
-
- return o->zv;
+ return o;
}
#define PHP_HTTP_COOKIE_OBJECT_INIT(obj) \
do { \
if (!obj->list) { \
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC); \
+ obj->list = php_http_cookie_list_init(NULL); \
} \
} while(0)
-zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC)
+zend_object *php_http_cookie_object_clone(zval *obj)
{
- php_http_cookie_object_t *new_obj, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_object_value ov;
+ php_http_cookie_object_t *new_obj, *old_obj = PHP_HTTP_OBJ(NULL, obj);
PHP_HTTP_COOKIE_OBJECT_INIT(old_obj);
- ov = php_http_cookie_object_new_ex(old_obj->zo.ce, php_http_cookie_list_copy(old_obj->list, NULL), &new_obj TSRMLS_CC);
- zend_objects_clone_members((zend_object *) new_obj, ov, (zend_object *) old_obj, Z_OBJ_HANDLE_P(getThis()) TSRMLS_CC);
+ new_obj = php_http_cookie_object_new_ex(old_obj->zo.ce, php_http_cookie_list_copy(old_obj->list, NULL));
+ zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
- return ov;
+ return &new_obj->zo;
}
-void php_http_cookie_object_free(void *object TSRMLS_DC)
+void php_http_cookie_object_free(zend_object *object)
{
- php_http_cookie_object_t *obj = object;
+ php_http_cookie_object_t *obj = PHP_HTTP_OBJ(object, NULL);
php_http_cookie_list_free(&obj->list);
- zend_object_std_dtor((zend_object *) obj TSRMLS_CC);
- efree(obj);
+ zend_object_std_dtor(object);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie___construct, 0, 0, 0)
{
php_http_cookie_object_t *obj;
zval *zcookie = NULL;
- long flags = 0;
+ zend_long flags = 0;
char **ae = NULL;
HashTable *allowed_extras = NULL;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!lH", &zcookie, &flags, &allowed_extras), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!lH", &zcookie, &flags, &allowed_extras), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
- zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh);
if (zcookie) {
if (allowed_extras && zend_hash_num_elements(allowed_extras)) {
char **ae_ptr = safe_emalloc(zend_hash_num_elements(allowed_extras) + 1, sizeof(char *), 0);
- HashPosition pos;
- zval **val;
+ zval *val;
ae = ae_ptr;
- FOREACH_HASH_VAL(pos, allowed_extras, val) {
- zval *cpy = php_http_ztyp(IS_STRING, *val);
+ ZEND_HASH_FOREACH_VAL(allowed_extras, val)
+ {
+ zend_string *str = zval_get_string(val);
- *ae_ptr++ = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
+ *ae_ptr++ = estrndup(str->val, str->len);
+ zend_string_release(str);
}
+ ZEND_HASH_FOREACH_END();
*ae_ptr = NULL;
}
switch (Z_TYPE_P(zcookie)) {
case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry TSRMLS_CC)) {
- php_http_cookie_object_t *zco = zend_object_store_get_object(zcookie TSRMLS_CC);
+ if (instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry)) {
+ php_http_cookie_object_t *zco = PHP_HTTP_OBJ(NULL, zcookie);
if (zco->list) {
obj->list = php_http_cookie_list_copy(zco->list, NULL);
}
/* no break */
case IS_ARRAY:
- obj->list = php_http_cookie_list_from_struct(obj->list, zcookie TSRMLS_CC);
+ obj->list = php_http_cookie_list_from_struct(obj->list, zcookie);
break;
default: {
- zval *cpy = php_http_ztyp(IS_STRING, zcookie);
+ zend_string *str = zval_get_string(zcookie);
- obj->list = php_http_cookie_list_parse(obj->list, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), flags, ae TSRMLS_CC);
- zval_ptr_dtor(&cpy);
+ obj->list = php_http_cookie_list_parse(obj->list, str->val, str->len, flags, ae);
+ zend_string_release(str);
break;
}
}
efree(ae);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
}
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- array_init(return_value);
+ array_init_size(return_value, zend_hash_num_elements(&obj->list->cookies));
array_copy(&obj->list->cookies, Z_ARRVAL_P(return_value));
}
HashTable *cookies = NULL;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &cookies), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &cookies), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
array_copy_strings(cookies, &obj->list->cookies);
}
- RETVAL_ZVAL(getThis(), 1, 0);
+ RETURN_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookies, 0, 0, 1)
HashTable *cookies = NULL;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &cookies), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H", &cookies), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- array_init(return_value);
+ array_init_size(return_value, zend_hash_num_elements(&obj->list->extras));
array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
}
HashTable *extras = NULL;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &extras), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &extras), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
HashTable *extras = NULL;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &extras), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "H", &extras), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
static PHP_METHOD(HttpCookie, getCookie)
{
char *name_str;
- int name_len;
- zval *zvalue;
+ size_t name_len;
+ zval zvalue;
php_http_cookie_object_t *obj;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len)) {
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
if (php_http_cookie_list_get_cookie(obj->list, name_str, name_len, &zvalue)) {
- RETURN_ZVAL(zvalue, 1, 0);
+ RETURN_ZVAL(&zvalue, 1, 0);
}
}
static PHP_METHOD(HttpCookie, setCookie)
{
char *name_str, *value_str = NULL;
- int name_len, value_len = 0;
+ size_t name_len, value_len = 0;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
static PHP_METHOD(HttpCookie, addCookie)
{
char *name_str, *value_str;
- int name_len, value_len;
+ size_t name_len, value_len;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
static PHP_METHOD(HttpCookie, getExtra)
{
char *name_str;
- int name_len;
- zval *zvalue;
+ size_t name_len;
+ zval zvalue;
php_http_cookie_object_t *obj;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len)) {
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
if (php_http_cookie_list_get_extra(obj->list, name_str, name_len, &zvalue)) {
- RETURN_ZVAL(zvalue, 1, 0);
+ RETURN_ZVAL(&zvalue, 1, 0);
}
}
static PHP_METHOD(HttpCookie, setExtra)
{
char *name_str, *value_str = NULL;
- int name_len, value_len = 0;
+ size_t name_len, value_len = 0;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
static PHP_METHOD(HttpCookie, addExtra)
{
char *name_str, *value_str;
- int name_len, value_len;
+ size_t name_len, value_len;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
if (obj->list->domain) {
- RETURN_STRING(obj->list->domain, 1);
+ RETURN_STRING(obj->list->domain);
}
}
static PHP_METHOD(HttpCookie, setDomain)
{
char *domain_str = NULL;
- int domain_len = 0;
+ size_t domain_len = 0;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &domain_str, &domain_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &domain_str, &domain_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
if (obj->list->path) {
- RETURN_STRING(obj->list->path, 1);
+ RETURN_STRING(obj->list->path);
}
}
static PHP_METHOD(HttpCookie, setPath)
{
char *path_str = NULL;
- int path_len = 0;
+ size_t path_len = 0;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &path_str, &path_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &path_str, &path_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, setExpires)
{
- long ts = -1;
+ zend_long ts = -1;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ts), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, setMaxAge)
{
- long ts = -1;
+ zend_long ma = -1;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &ma), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- obj->list->max_age = ts;
+ obj->list->max_age = ma;
RETVAL_ZVAL(getThis(), 1, 0);
}
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, setFlags)
{
- long flags = 0;
+ zend_long flags = 0;
php_http_cookie_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
RETURN_EMPTY_STRING();
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
php_http_cookie_list_to_string(obj->list, &str, &len);
- RETURN_STRINGL(str, len, 0);
+ RETURN_NEW_STR(php_http_cs2zs(str, len));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_toArray, 0, 0, 0)
return;
}
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- array_init(return_value);
+ array_init_size(return_value, 8);
php_http_cookie_list_to_struct(obj->list, return_value);
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_cookie_class_entry;
-
PHP_MINIT_FUNCTION(http_cookie)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Cookie", php_http_cookie_methods);
- php_http_cookie_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_cookie_class_entry = zend_register_internal_class(&ce);
php_http_cookie_class_entry->create_object = php_http_cookie_object_new;
memcpy(&php_http_cookie_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_cookie_object_handlers.offset = XtOffsetOf(php_http_cookie_object_t, zo);
php_http_cookie_object_handlers.clone_obj = php_http_cookie_object_clone;
+ php_http_cookie_object_handlers.free_obj = php_http_cookie_object_free;
- zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_COOKIE_PARSE_RAW TSRMLS_CC);
- zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("SECURE"), PHP_HTTP_COOKIE_SECURE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("HTTPONLY"), PHP_HTTP_COOKIE_HTTPONLY TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_COOKIE_PARSE_RAW);
+ zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("SECURE"), PHP_HTTP_COOKIE_SECURE);
+ zend_declare_class_constant_long(php_http_cookie_class_entry, ZEND_STRL("HTTPONLY"), PHP_HTTP_COOKIE_HTTPONLY);
return SUCCESS;
}
char *domain;
time_t expires;
time_t max_age;
-
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_cookie_list_t;
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC);
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras TSRMLS_DC);
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list);
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras);
PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to);
PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list);
PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list);
-#define php_http_cookie_list_has_cookie(list, name, name_len) zend_symtable_exists(&(list)->cookies, (name), (name_len)+1)
-#define php_http_cookie_list_del_cookie(list, name, name_len) zend_symtable_del(&(list)->cookies, (name), (name_len)+1)
+#define php_http_cookie_list_has_cookie(list, name, name_len) zend_symtable_str_exists(&(list)->cookies, (name), (name_len))
+#define php_http_cookie_list_del_cookie(list, name, name_len) zend_symtable_str_del(&(list)->cookies, (name), (name_len))
PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **cookie);
+PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval *cookie);
-#define php_http_cookie_list_has_extra(list, name, name_len) zend_symtable_exists(&(list)->extras, (name), (name_len)+1)
-#define php_http_cookie_list_del_extra(list, name, name_len) zend_symtable_del(&(list)->extras, (name), (name_len)+1)
+#define php_http_cookie_list_has_extra(list, name, name_len) zend_symtable_str_exists(&(list)->extras, (name), (name_len))
+#define php_http_cookie_list_del_extra(list, name, name_len) zend_symtable_str_del(&(list)->extras, (name), (name_len))
PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len);
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **extra);
+PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval *extra);
PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len);
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC);
+PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct);
PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct);
-PHP_HTTP_API zend_class_entry *php_http_cookie_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_cookie_get_class_entry(void);
typedef struct php_http_cookie_object {
- zend_object zo;
- zend_object_value zv;
php_http_cookie_list_t *list;
+ zend_object zo;
} php_http_cookie_object_t;
-zend_object_value php_http_cookie_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_cookie_list_t *list, php_http_cookie_object_t **obj TSRMLS_DC);
-zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC);
-void php_http_cookie_object_free(void *object TSRMLS_DC);
+zend_object *php_http_cookie_object_new(zend_class_entry *ce);
+php_http_cookie_object_t *php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_cookie_list_t *list);
+zend_object *php_http_cookie_object_clone(zval *this_ptr);
+void php_http_cookie_object_free(zend_object *object);
PHP_MINIT_FUNCTION(http_cookie);
}
}
-const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len)
{
int eol_len = 0;
char *n_ptr = NULL;
* not encoded data and return a copy
*/
if (e_ptr == encoded) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Data does not seem to be chunked encoded");
+ php_error_docref(NULL, E_NOTICE, "Data does not seem to be chunked encoded");
memcpy(*decoded, encoded, encoded_len);
*decoded_len = encoded_len;
return encoded + encoded_len;
} else {
efree(*decoded);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
+ php_error_docref(NULL, E_WARNING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
return NULL;
}
}
/* there should be CRLF after the chunk size, but we'll ignore SP+ too */
if (*n_ptr && !eol_match(&n_ptr, &eol_len)) {
if (eol_len == 2) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
+ php_error_docref(NULL, E_WARNING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
+ php_error_docref(NULL, E_WARNING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
}
}
n_ptr += eol_len;
/* chunk size pretends more data than we actually got, so it's probably a truncated message */
if (chunk_len > (rest = encoded + encoded_len - n_ptr)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
+ php_error_docref(NULL, E_WARNING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
chunk_len = rest;
}
return status;
}
-ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len)
{
int status, level, wbits, strategy;
z_stream Z;
}
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not deflate data: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Could not deflate data: %s", zError(status));
return FAILURE;
}
-ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len)
{
z_stream Z;
int status, wbits = PHP_HTTP_WINDOW_BITS_ANY;
}
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not inflate data: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Could not inflate data: %s", zError(status));
return FAILURE;
}
-php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags TSRMLS_DC)
+php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags)
{
int freeme;
memset(s, 0, sizeof(*s));
s->flags = flags;
- TSRMLS_SET_CTX(s->ts);
if ((s->ops = ops)) {
php_http_encoding_stream_t *ss = s->ops->init(s);
php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to)
{
- TSRMLS_FETCH_FROM_CTX(from->ts);
-
if (from->ops->copy) {
int freeme;
php_http_encoding_stream_t *ns;
to->flags = from->flags;
to->ops = from->ops;
- TSRMLS_SET_CTX(to->ts);
if ((ns = to->ops->copy(from, to))) {
return ns;
ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s)
{
php_http_encoding_stream_t *ss;
+
if ((*s)->ops->dtor) {
(*s)->ops->dtor(*s);
}
{
int status, level, wbits, strategy, p = (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT);
z_streamp ctx = pecalloc(1, sizeof(z_stream), p);
- TSRMLS_FETCH_FROM_CTX(s->ts);
PHP_HTTP_DEFLATE_LEVEL_SET(s->flags, level);
PHP_HTTP_DEFLATE_WBITS_SET(s->flags, wbits);
status = Z_MEM_ERROR;
}
pefree(ctx, p);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize deflate encoding stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to initialize deflate encoding stream: %s", zError(status));
return NULL;
}
{
int status, wbits, p = (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT);
z_streamp ctx = pecalloc(1, sizeof(z_stream), p);
- TSRMLS_FETCH_FROM_CTX(s->ts);
PHP_HTTP_INFLATE_WBITS_SET(s->flags, wbits);
status = Z_MEM_ERROR;
}
pefree(ctx, p);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize inflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to initialize inflate stream: %s", zError(status));
return NULL;
}
{
int status, p = to->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT;
z_streamp from_ctx = from->ctx, to_ctx = pecalloc(1, sizeof(*to_ctx), p);
- TSRMLS_FETCH_FROM_CTX(from->ts);
if (Z_OK == (status = deflateCopy(to_ctx, from_ctx))) {
if ((to_ctx->opaque = php_http_buffer_init_ex(NULL, PHP_HTTP_DEFLATE_BUFFER_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0))) {
deflateEnd(to_ctx);
status = Z_MEM_ERROR;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy deflate encoding stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to copy deflate encoding stream: %s", zError(status));
return NULL;
}
{
int status, p = from->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT;
z_streamp from_ctx = from->ctx, to_ctx = pecalloc(1, sizeof(*to_ctx), p);
- TSRMLS_FETCH_FROM_CTX(from->ts);
if (Z_OK == (status = inflateCopy(to_ctx, from_ctx))) {
if ((to_ctx->opaque = php_http_buffer_init_ex(NULL, PHP_HTTP_DEFLATE_BUFFER_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0))) {
inflateEnd(to_ctx);
status = Z_MEM_ERROR;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to copy inflate encoding stream: %s", zError(status));
return NULL;
}
{
int p = from->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT;
struct dechunk_ctx *from_ctx = from->ctx, *to_ctx = pemalloc(sizeof(*to_ctx), p);
- TSRMLS_FETCH_FROM_CTX(from->ts);
if (php_http_buffer_init_ex(&to_ctx->buffer, PHP_HTTP_BUFFER_DEFAULT_SIZE, p ? PHP_HTTP_BUFFER_INIT_PERSISTENT : 0)) {
to_ctx->hexlen = from_ctx->hexlen;
return to;
}
pefree(to_ctx, p);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: out of memory");
+ php_error_docref(NULL, E_WARNING, "Failed to copy inflate encoding stream: out of memory");
return NULL;
}
{
int status;
z_streamp ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
/* append input to our buffer */
php_http_buffer_append(PHP_HTTP_BUFFER(ctx->opaque), data, data_len);
PTR_SET(*encoded, NULL);
*encoded_len = 0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update deflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to update deflate stream: %s", zError(status));
return FAILURE;
}
{
int status;
z_streamp ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
/* append input to buffer */
php_http_buffer_append(PHP_HTTP_BUFFER(ctx->opaque), data, data_len);
break;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update inflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to update inflate stream: %s", zError(status));
return FAILURE;
}
{
php_http_buffer_t tmp;
struct dechunk_ctx *ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
if (ctx->zeroed) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dechunk encoding stream has already reached the end of chunked input");
+ php_error_docref(NULL, E_WARNING, "Dechunk encoding stream has already reached the end of chunked input");
return FAILURE;
}
if ((PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) || !php_http_buffer_fix(&ctx->buffer)) {
/* if strtoul() stops at the beginning of the buffered data
there's something oddly wrong, i.e. bad input */
if (stop == ctx->buffer.data) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse chunk len from '%.*s'", (int) MIN(16, ctx->buffer.used), ctx->buffer.data);
+ php_error_docref(NULL, E_WARNING, "Failed to parse chunk len from '%.*s'", (int) MIN(16, ctx->buffer.used), ctx->buffer.data);
php_http_buffer_dtor(&tmp);
return FAILURE;
}
{
int status;
z_streamp ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
*encoded_len = PHP_HTTP_DEFLATE_BUFFER_SIZE;
*encoded = emalloc(*encoded_len);
PTR_SET(*encoded, NULL);
*encoded_len = 0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to flush deflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to flush deflate stream: %s", zError(status));
return FAILURE;
}
{
int status;
z_streamp ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
*encoded_len = PHP_HTTP_DEFLATE_BUFFER_SIZE;
*encoded = emalloc(*encoded_len);
PTR_SET(*encoded, NULL);
*encoded_len = 0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish deflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to finish deflate stream: %s", zError(status));
return FAILURE;
}
{
int status;
z_streamp ctx = s->ctx;
- TSRMLS_FETCH_FROM_CTX(s->ts);
if (!PHP_HTTP_BUFFER(ctx->opaque)->used) {
*decoded = NULL;
PTR_SET(*decoded, NULL);
*decoded_len = 0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish inflate stream: %s", zError(status));
+ php_error_docref(NULL, E_WARNING, "Failed to finish inflate stream: %s", zError(status));
return FAILURE;
}
static zend_object_handlers php_http_encoding_stream_object_handlers;
-zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_encoding_stream_object_new(zend_class_entry *ce)
{
- return php_http_encoding_stream_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_encoding_stream_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_encoding_stream_object_t **ptr TSRMLS_DC)
+php_http_encoding_stream_object_t *php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s)
{
php_http_encoding_stream_object_t *o;
- o = ecalloc(1, sizeof(*o));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
-
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
if (s) {
o->stream = s;
}
- o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_encoding_stream_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_encoding_stream_object_handlers;
+ o->zo.handlers = &php_http_encoding_stream_object_handlers;
- return o->zv;
+ return o;
}
-zend_object_value php_http_encoding_stream_object_clone(zval *this_ptr TSRMLS_DC)
+zend_object *php_http_encoding_stream_object_clone(zval *object)
{
- zend_object_value new_ov;
- php_http_encoding_stream_object_t *new_obj = NULL, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_encoding_stream_object_t *new_obj = NULL, *old_obj = PHP_HTTP_OBJ(NULL, object);
+ php_http_encoding_stream_t *cpy = php_http_encoding_stream_copy(old_obj->stream, NULL);
- new_ov = php_http_encoding_stream_object_new_ex(old_obj->zo.ce, php_http_encoding_stream_copy(old_obj->stream, NULL), &new_obj TSRMLS_CC);
- zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ new_obj = php_http_encoding_stream_object_new_ex(old_obj->zo.ce, cpy);
+ zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
- return new_ov;
+ return &new_obj->zo;
}
-void php_http_encoding_stream_object_free(void *object TSRMLS_DC)
+void php_http_encoding_stream_object_free(zend_object *object)
{
- php_http_encoding_stream_object_t *o = (php_http_encoding_stream_object_t *) object;
+ php_http_encoding_stream_object_t *o = PHP_HTTP_OBJ(object, NULL);
if (o->stream) {
php_http_encoding_stream_free(&o->stream);
}
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
+}
+
+static zend_class_entry *php_http_encoding_stream_class_entry;
+zend_class_entry *php_http_get_encoding_stream_class_entry(void)
+{
+ return php_http_encoding_stream_class_entry;
+}
+static zend_class_entry *php_http_deflate_stream_class_entry;
+zend_class_entry *php_http_get_deflate_stream_class_entry(void)
+{
+ return php_http_deflate_stream_class_entry;
+}
+static zend_class_entry *php_http_inflate_stream_class_entry;
+zend_class_entry *php_http_get_inflate_stream_class_entry(void)
+{
+ return php_http_inflate_stream_class_entry;
+}
+static zend_class_entry *php_http_dechunk_stream_class_entry;
+zend_class_entry *php_http_get_dechunk_stream_class_entry(void)
+{
+ return php_http_dechunk_stream_class_entry;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream___construct, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEncodingStream, __construct)
{
- long flags = 0;
+ zend_long flags = 0;
php_http_encoding_stream_object_t *obj;
php_http_encoding_stream_ops_t *ops;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->stream) {
php_http_throw(bad_method_call, "http\\Encoding\\Stream cannot be initialized twice", NULL);
return;
}
- if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry TSRMLS_CC)) {
+ if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry)) {
ops = &php_http_encoding_deflate_ops;
- } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry TSRMLS_CC)) {
+ } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry)) {
ops = &php_http_encoding_inflate_ops;
- } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) {
+ } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry)) {
ops = &php_http_encoding_dechunk_ops;
} else {
- php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name);
+ php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name->val);
return;
}
- php_http_expect(obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags TSRMLS_CC), runtime, return);
+ php_http_expect(obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags), runtime, return);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_update, 0, 0, 1)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEncodingStream, update)
{
- int data_len;
+ size_t data_len;
char *data_str;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_str, &data_len)) {
- php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data_str, &data_len)) {
+ php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->stream) {
+ char *encoded_str = NULL;
size_t encoded_len;
- char *encoded_str;
if (SUCCESS == php_http_encoding_stream_update(obj->stream, data_str, data_len, &encoded_str, &encoded_len)) {
- RETURN_STRINGL(encoded_str, encoded_len, 0);
+ if (encoded_str) {
+ RETURN_STR(php_http_cs2zs(encoded_str, encoded_len));
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
}
}
static PHP_METHOD(HttpEncodingStream, flush)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->stream) {
- char *encoded_str;
+ char *encoded_str = NULL;
size_t encoded_len;
if (SUCCESS == php_http_encoding_stream_flush(obj->stream, &encoded_str, &encoded_len)) {
if (encoded_str) {
- RETURN_STRINGL(encoded_str, encoded_len, 0);
+ RETURN_STR(php_http_cs2zs(encoded_str, encoded_len));
} else {
RETURN_EMPTY_STRING();
}
static PHP_METHOD(HttpEncodingStream, done)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->stream) {
RETURN_BOOL(php_http_encoding_stream_done(obj->stream));
static PHP_METHOD(HttpEncodingStream, finish)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_encoding_stream_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
if (obj->stream) {
- char *encoded_str;
+ char *encoded_str = NULL;
size_t encoded_len;
if (SUCCESS == php_http_encoding_stream_finish(obj->stream, &encoded_str, &encoded_len)) {
if (SUCCESS == php_http_encoding_stream_reset(&obj->stream)) {
if (encoded_str) {
- RETURN_STRINGL(encoded_str, encoded_len, 0);
+ RETURN_STR(php_http_cs2zs(encoded_str, encoded_len));
} else {
RETURN_EMPTY_STRING();
}
static PHP_METHOD(HttpDeflateStream, encode)
{
char *str;
- int len;
- long flags = 0;
+ size_t len;
+ zend_long flags = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &flags)) {
- char *enc_str;
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &len, &flags)) {
+ char *enc_str = NULL;
size_t enc_len;
- if (SUCCESS == php_http_encoding_deflate(flags, str, len, &enc_str, &enc_len TSRMLS_CC)) {
- RETURN_STRINGL(enc_str, enc_len, 0);
+ if (SUCCESS == php_http_encoding_deflate(flags, str, len, &enc_str, &enc_len)) {
+ if (enc_str) {
+ RETURN_STR(php_http_cs2zs(enc_str, enc_len));
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
}
RETURN_FALSE;
static PHP_METHOD(HttpInflateStream, decode)
{
char *str;
- int len;
+ size_t len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
- char *enc_str;
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len)) {
+ char *enc_str = NULL;
size_t enc_len;
- if (SUCCESS == php_http_encoding_inflate(str, len, &enc_str, &enc_len TSRMLS_CC)) {
- RETURN_STRINGL(enc_str, enc_len, 0);
+ if (SUCCESS == php_http_encoding_inflate(str, len, &enc_str, &enc_len)) {
+ if (enc_str) {
+ RETURN_STR(php_http_cs2zs(enc_str, enc_len));
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
}
RETURN_FALSE;
static PHP_METHOD(HttpDechunkStream, decode)
{
char *str;
- int len;
+ size_t len;
zval *zlen = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!", &str, &len, &zlen)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &str, &len, &zlen)) {
const char *end_ptr;
- char *enc_str;
+ char *enc_str = NULL;
size_t enc_len;
- if ((end_ptr = php_http_encoding_dechunk(str, len, &enc_str, &enc_len TSRMLS_CC))) {
+ if ((end_ptr = php_http_encoding_dechunk(str, len, &enc_str, &enc_len))) {
if (zlen) {
+ ZVAL_DEREF(zlen);
zval_dtor(zlen);
ZVAL_LONG(zlen, str + len - end_ptr);
}
- RETURN_STRINGL(enc_str, enc_len, 0);
+ if (enc_str) {
+ RETURN_STR(php_http_cs2zs(enc_str, enc_len));
+ } else {
+ RETURN_EMPTY_STRING();
+ }
}
}
RETURN_FALSE;
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_encoding_stream_class_entry;
-zend_class_entry *php_http_deflate_stream_class_entry;
-zend_class_entry *php_http_inflate_stream_class_entry;
-zend_class_entry *php_http_dechunk_stream_class_entry;
-
PHP_MINIT_FUNCTION(http_encoding)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Encoding", "Stream", php_http_encoding_stream_methods);
- php_http_encoding_stream_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_encoding_stream_class_entry = zend_register_internal_class(&ce);
php_http_encoding_stream_class_entry->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
php_http_encoding_stream_class_entry->create_object = php_http_encoding_stream_object_new;
memcpy(&php_http_encoding_stream_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_encoding_stream_object_handlers.offset = XtOffsetOf(php_http_encoding_stream_object_t, zo);
php_http_encoding_stream_object_handlers.clone_obj = php_http_encoding_stream_object_clone;
+ php_http_encoding_stream_object_handlers.free_obj = php_http_encoding_stream_object_free;
- zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_NONE"), PHP_HTTP_ENCODING_STREAM_FLUSH_NONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_SYNC"), PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC TSRMLS_CC);
- zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_FULL"), PHP_HTTP_ENCODING_STREAM_FLUSH_FULL TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_NONE"), PHP_HTTP_ENCODING_STREAM_FLUSH_NONE);
+ zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_SYNC"), PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC);
+ zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_FULL"), PHP_HTTP_ENCODING_STREAM_FLUSH_FULL);
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Deflate", php_http_deflate_stream_methods);
- php_http_deflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_GZIP"), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_ZLIB"), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_RAW"), PHP_HTTP_DEFLATE_TYPE_RAW TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_DEF"), PHP_HTTP_DEFLATE_LEVEL_DEF TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MIN"), PHP_HTTP_DEFLATE_LEVEL_MIN TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MAX"), PHP_HTTP_DEFLATE_LEVEL_MAX TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_DEF"), PHP_HTTP_DEFLATE_STRATEGY_DEF TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FILT"), PHP_HTTP_DEFLATE_STRATEGY_FILT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_HUFF"), PHP_HTTP_DEFLATE_STRATEGY_HUFF TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_RLE"), PHP_HTTP_DEFLATE_STRATEGY_RLE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FIXED"), PHP_HTTP_DEFLATE_STRATEGY_FIXED TSRMLS_CC);
+ php_http_deflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry);
+ php_http_deflate_stream_class_entry->create_object = php_http_encoding_stream_object_new;
+
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_GZIP"), PHP_HTTP_DEFLATE_TYPE_GZIP);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_ZLIB"), PHP_HTTP_DEFLATE_TYPE_ZLIB);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_RAW"), PHP_HTTP_DEFLATE_TYPE_RAW);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_DEF"), PHP_HTTP_DEFLATE_LEVEL_DEF);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MIN"), PHP_HTTP_DEFLATE_LEVEL_MIN);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("LEVEL_MAX"), PHP_HTTP_DEFLATE_LEVEL_MAX);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_DEF"), PHP_HTTP_DEFLATE_STRATEGY_DEF);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FILT"), PHP_HTTP_DEFLATE_STRATEGY_FILT);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_HUFF"), PHP_HTTP_DEFLATE_STRATEGY_HUFF);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_RLE"), PHP_HTTP_DEFLATE_STRATEGY_RLE);
+ zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FIXED"), PHP_HTTP_DEFLATE_STRATEGY_FIXED);
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Inflate", php_http_inflate_stream_methods);
- php_http_inflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC);
+ php_http_inflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry);
+ php_http_inflate_stream_class_entry->create_object = php_http_encoding_stream_object_new;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Dechunk", php_http_dechunk_stream_methods);
- php_http_dechunk_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC);
+ php_http_dechunk_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry);
+ php_http_dechunk_stream_class_entry->create_object = php_http_encoding_stream_object_new;
return SUCCESS;
}
unsigned flags;
void *ctx;
php_http_encoding_stream_ops_t *ops;
-#ifdef ZTS
- void ***ts;
-#endif
};
PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_deflate_ops(void);
PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_inflate_ops(void);
PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_dechunk_ops(void);
-PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags TSRMLS_DC);
+PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags);
PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to);
PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s);
PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_update(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len);
PHP_HTTP_API void php_http_encoding_stream_dtor(php_http_encoding_stream_t *s);
PHP_HTTP_API void php_http_encoding_stream_free(php_http_encoding_stream_t **s);
-PHP_HTTP_API const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC);
+PHP_HTTP_API const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len);
typedef struct php_http_encoding_stream_object {
- zend_object zo;
- zend_object_value zv;
php_http_encoding_stream_t *stream;
+ zend_object zo;
} php_http_encoding_stream_object_t;
-PHP_HTTP_API zend_class_entry *php_http_encoding_stream_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_encoding_stream_class_entry(void);
-zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_encoding_stream_object_t **ptr TSRMLS_DC);
-zend_object_value php_http_encoding_stream_object_clone(zval *object TSRMLS_DC);
-void php_http_encoding_stream_object_free(void *object TSRMLS_DC);
+zend_object *php_http_encoding_stream_object_new(zend_class_entry *ce);
+php_http_encoding_stream_object_t *php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s);
+zend_object *php_http_encoding_stream_object_clone(zval *object);
+void php_http_encoding_stream_object_free(zend_object *object);
-PHP_HTTP_API zend_class_entry *php_http_deflate_stream_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_inflate_stream_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_dechunk_stream_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_deflate_stream_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_inflate_stream_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_dechunk_stream_class_entry(void);
#endif
#include "php_http_api.h"
#include "php_variables.h"
+
PHP_RSHUTDOWN_FUNCTION(http_env)
{
if (PHP_HTTP_G->env.request.headers) {
}
if (PHP_HTTP_G->env.server_var) {
- zval_ptr_dtor(&PHP_HTTP_G->env.server_var);
+ zval_ptr_dtor(PHP_HTTP_G->env.server_var);
PHP_HTTP_G->env.server_var = NULL;
}
return SUCCESS;
}
-void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC)
+void php_http_env_get_request_headers(HashTable *headers)
{
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **hsv, **header;
- HashPosition pos;
+ php_http_arrkey_t key;
+ zval *hsv, *header;
if (!PHP_HTTP_G->env.request.headers) {
ALLOC_HASHTABLE(PHP_HTTP_G->env.request.headers);
- zend_hash_init(PHP_HTTP_G->env.request.headers, 0, NULL, ZVAL_PTR_DTOR, 0);
-
- zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
+ ZEND_INIT_SYMTABLE(PHP_HTTP_G->env.request.headers);
- if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv) && Z_TYPE_PP(hsv) == IS_ARRAY) {
- FOREACH_KEY(pos, *hsv, key) {
- if (key.type == HASH_KEY_IS_STRING && key.len > 6 && *key.str == 'H' && !strncmp(key.str, "HTTP_", 5)) {
- key.len -= 5;
- key.str = php_http_pretty_key(estrndup(key.str + 5, key.len - 1), key.len - 1, 1, 1);
+ if ((hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER")))) {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(hsv), key.h, key.key, header)
+ {
+ if (key.key && key.key->len > 5 && *key.key->val == 'H' && !strncmp(key.key->val, "HTTP_", 5)) {
+ size_t key_len = key.key->len - 5;
+ char *key_str = php_http_pretty_key(estrndup(&key.key->val[5], key_len), key_len, 1, 1);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
- Z_ADDREF_P(*header);
- zend_symtable_update(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
+ Z_TRY_ADDREF_P(header);
+ zend_symtable_str_update(PHP_HTTP_G->env.request.headers, key_str, key_len, header);
- efree(key.str);
- } else if (key.type == HASH_KEY_IS_STRING && key.len > 9 && *key.str == 'C' && !strncmp(key.str, "CONTENT_", 8)) {
- key.str = php_http_pretty_key(estrndup(key.str, key.len - 1), key.len - 1, 1, 1);
+ efree(key_str);
+ } else if (key.key && key.key->len > 8 && *key.key->val == 'C' && !strncmp(key.key->val, "CONTENT_", 8)) {
+ char *key_str = php_http_pretty_key(estrndup(key.key->val, key.key->len), key.key->len, 1, 1);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
- Z_ADDREF_P(*header);
- zend_symtable_update(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
+ Z_TRY_ADDREF_P(header);
+ zend_symtable_str_update(PHP_HTTP_G->env.request.headers, key_str, key.key->len, header);
- efree(key.str);
+ efree(key_str);
}
}
+ ZEND_HASH_FOREACH_END();
}
}
if (headers) {
- zend_hash_copy(headers, PHP_HTTP_G->env.request.headers, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ array_copy(PHP_HTTP_G->env.request.headers, headers);
}
}
-char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC)
+char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request)
{
HashTable *request_headers;
- zval **zvalue = NULL;
+ zval *zvalue = NULL;
char *val = NULL, *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
if (request) {
request_headers = &request->hdrs;
} else {
- php_http_env_get_request_headers(NULL TSRMLS_CC);
+ php_http_env_get_request_headers(NULL);
request_headers = PHP_HTTP_G->env.request.headers;
}
- if (SUCCESS == zend_symtable_find(request_headers, key, name_len + 1, (void *) &zvalue)) {
- zval *zcopy = php_http_ztyp(IS_STRING, *zvalue);
+ if ((zvalue = zend_symtable_str_find(request_headers, key, name_len))) {
+ zend_string *zs = zval_get_string(zvalue);
- val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
+ val = estrndup(zs->val, zs->len);
if (len) {
- *len = Z_STRLEN_P(zcopy);
+ *len = zs->len;
}
- zval_ptr_dtor(&zcopy);
+ zend_string_release(zs);
}
efree(key);
return val;
}
-int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC)
+zend_bool php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request)
{
HashTable *request_headers;
char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
- int got;
+ zend_bool got;
if (request) {
request_headers = &request->hdrs;
} else {
- php_http_env_get_request_headers(NULL TSRMLS_CC);
+ php_http_env_get_request_headers(NULL);
request_headers = PHP_HTTP_G->env.request.headers;
}
- got = zend_symtable_exists(request_headers, key, name_len + 1);
+ got = zend_symtable_str_exists(request_headers, key, name_len);
efree(key);
return got;
}
-zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC)
+zval *php_http_env_get_superglobal(const char *key, size_t key_len)
{
- zval **hsv;
+ zval *hsv;
+ zend_string *key_str = zend_string_init(key, key_len, 0);
- zend_is_auto_global(key, key_len TSRMLS_CC);
+ zend_is_auto_global(key_str);
+ hsv = zend_hash_find(&EG(symbol_table), key_str);
+ zend_string_release(key_str);
- if ((SUCCESS != zend_hash_find(&EG(symbol_table), key, key_len + 1, (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
+ if (Z_TYPE_P(hsv) != IS_ARRAY) {
return NULL;
}
- return *hsv;
+ return hsv;
}
-zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
+zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check)
{
- zval *hsv, **var;
- char *env;
+ zval *hsv, *var;
- /* if available, this is a lot faster than accessing $_SERVER */
+ /* if available, this is a lot faster than accessing $_SERVER * /
if (sapi_module.getenv) {
- if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) {
+ char *env;
+
+ if ((!(env = sapi_module.getenv((char *) key, key_len))) || (check && !*env)) {
return NULL;
}
if (PHP_HTTP_G->env.server_var) {
ZVAL_STRING(PHP_HTTP_G->env.server_var, env, 1);
return PHP_HTTP_G->env.server_var;
}
+ / * */
- if (!(hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER") TSRMLS_CC))) {
+ if (!(hsv = php_http_env_get_superglobal(ZEND_STRL("_SERVER")))) {
return NULL;
}
- if ((SUCCESS != zend_symtable_find(Z_ARRVAL_P(hsv), key, key_len + 1, (void *) &var))) {
+ if (!(var = zend_symtable_str_find(Z_ARRVAL_P(hsv), key, key_len))) {
return NULL;
}
- if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
+ if (check && !((Z_TYPE_P(var) == IS_STRING) && Z_STRVAL_P(var) && Z_STRLEN_P(var))) {
return NULL;
}
- return *var;
+ return var;
}
-php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
+php_http_message_body_t *php_http_env_get_request_body(void)
{
if (!PHP_HTTP_G->env.request.body) {
php_stream *s = php_stream_temp_new();
-#if PHP_VERSION_ID >= 50600
php_stream *input = php_stream_open_wrapper("php://input", "r", 0, NULL);
/* php://input does not support stat */
php_stream_copy_to_stream_ex(input, s, -1, NULL);
php_stream_close(input);
-#else
- if (SG(request_info).post_data || SG(request_info).raw_post_data) {
- /* php://input does not support seek() in PHP <= 5.5 */
- if (SG(request_info).raw_post_data) {
- php_stream_write(s, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length);
- } else {
- php_stream_write(s, SG(request_info).post_data, SG(request_info).post_data_length);
- }
- } else if (sapi_module.read_post && !SG(read_post_bytes)) {
- char *buf = emalloc(4096);
- int len;
- while (0 < (len = sapi_module.read_post(buf, 4096 TSRMLS_CC))) {
- SG(read_post_bytes) += len;
- php_stream_write(s, buf, len);
-
- if (len < 4096) {
- break;
- }
- }
- efree(buf);
- }
-#endif
php_stream_rewind(s);
- PHP_HTTP_G->env.request.body = php_http_message_body_init(NULL, s TSRMLS_CC);
+ PHP_HTTP_G->env.request.body = php_http_message_body_init(NULL, s);
}
return PHP_HTTP_G->env.request.body;
}
-const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC)
+const char *php_http_env_get_request_method(php_http_message_t *request)
{
const char *m;
return m ? m : "GET";
}
-php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request TSRMLS_DC)
+php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request)
{
- zval *zentry;
+ zval zentry;
char *range, *rp, c;
long begin = -1, end = -1, *ptr;
- if (!(range = php_http_env_get_request_header(ZEND_STRL("Range"), NULL, request TSRMLS_CC))) {
+ if (!(range = php_http_env_get_request_header(ZEND_STRL("Range"), NULL, request))) {
return PHP_HTTP_RANGE_NO;
}
if (strncmp(range, "bytes=", lenof("bytes="))) {
}
}
- MAKE_STD_ZVAL(zentry);
- array_init(zentry);
- add_index_long(zentry, 0, begin);
- add_index_long(zentry, 1, end);
- zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL);
+ array_init(&zentry);
+ add_index_long(&zentry, 0, begin);
+ add_index_long(&zentry, 1, end);
+ zend_hash_next_index_insert(ranges, &zentry);
begin = -1;
end = -1;
return PHP_HTTP_RANGE_OK;
}
-static void grab_headers(void *data, void *arg TSRMLS_DC)
+static void grab_headers(void *data, void *arg)
{
php_http_buffer_appendl(PHP_HTTP_BUFFER(arg), ((sapi_header_struct *)data)->header);
php_http_buffer_appends(PHP_HTTP_BUFFER(arg), PHP_HTTP_CRLF);
}
-ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
+static void grab_header(void *data, void *arg)
+{
+ struct {
+ char *name_str;
+ size_t name_len;
+ char *value_ptr;
+ } *args = arg;
+ sapi_header_struct *header = data;
+
+ if ( header->header_len > args->name_len
+ && header->header[args->name_len] == ':'
+ && !strncmp(header->header, args->name_str, args->name_len)
+ ) {
+ args->value_ptr = &header->header[args->name_len + 1];
+ while (PHP_HTTP_IS_CTYPE(space, *args->value_ptr)) {
+ ++args->value_ptr;
+ }
+ }
+}
+
+ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht)
{
ZEND_RESULT_CODE status;
php_http_buffer_t headers;
php_http_buffer_init(&headers);
- zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers TSRMLS_CC);
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers);
php_http_buffer_fix(&headers);
- status = php_http_header_parse(headers.data, headers.used, headers_ht, NULL, NULL TSRMLS_CC);
+ status = php_http_header_parse(headers.data, headers.used, headers_ht, NULL, NULL);
php_http_buffer_dtor(&headers);
return status;
}
-char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC)
+char *php_http_env_get_response_header(const char *name_str, size_t name_len)
{
- char *val = NULL;
- HashTable headers;
-
- zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
- if (SUCCESS == php_http_env_get_response_headers(&headers TSRMLS_CC)) {
- zval **zvalue;
- char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
-
- if (SUCCESS == zend_symtable_find(&headers, key, name_len + 1, (void *) &zvalue)) {
- zval *zcopy = php_http_ztyp(IS_STRING, *zvalue);
+ struct {
+ char *name_str;
+ size_t name_len;
+ char *value_ptr;
+ } args;
- val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
- zval_ptr_dtor(&zcopy);
- }
-
- efree(key);
- }
- zend_hash_destroy(&headers);
+ args.name_str = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
+ args.name_len = name_len;
+ args.value_ptr = NULL;
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_header, &args);
+ efree(args.name_str);
- return val;
+ return args.value_ptr ? estrdup(args.value_ptr) : NULL;
}
-long php_http_env_get_response_code(TSRMLS_D)
+long php_http_env_get_response_code(void)
{
long code = SG(sapi_headers).http_response_code;
return code ? code : 200;
}
-ZEND_RESULT_CODE php_http_env_set_response_code(long http_code TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_code(long http_code)
{
- return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) http_code TSRMLS_CC);
+ return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (zend_intptr_t) http_code);
}
-ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_status_line(long code, php_http_version_t *v)
{
sapi_header_line h = {NULL, 0, 0};
ZEND_RESULT_CODE ret;
h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
- ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h TSRMLS_CC);
+ ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h);
efree(h.line);
return ret;
}
-ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v)
{
- return php_http_env_set_response_status_line(php_http_env_get_response_code(TSRMLS_C), v TSRMLS_CC);
+ return php_http_env_set_response_status_line(php_http_env_get_response_code(), v);
}
-ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace)
{
sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code};
- ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+ ZEND_RESULT_CODE ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
+
efree(h.line);
return ret;
}
-ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv)
{
ZEND_RESULT_CODE ret = FAILURE;
sapi_header_line h = {NULL, 0, http_code};
if (h.line) {
if (h.line_len) {
- ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+ ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
}
efree(h.line);
}
return ret;
}
-ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...)
+ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace, const char *fmt, ...)
{
ZEND_RESULT_CODE ret;
va_list args;
va_start(args, fmt);
- ret = php_http_env_set_response_header_va(http_code, replace, fmt, args TSRMLS_CC);
+ ret = php_http_env_set_response_header_va(http_code, replace, fmt, args);
va_end(args);
return ret;
}
-ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC)
+ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace)
{
if (!value) {
sapi_header_line h = {(char *) name_str, name_len, http_code};
- return sapi_header_op(SAPI_HEADER_DELETE, (void *) &h TSRMLS_CC);
+ return sapi_header_op(SAPI_HEADER_DELETE, (void *) &h);
}
- if(Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
- HashPosition pos;
+ if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
int first = replace;
- zval **data_ptr;
+ zval *data_ptr;
+ HashTable *ht = HASH_OF(value);
- FOREACH_HASH_VAL(pos, HASH_OF(value), data_ptr) {
- if (SUCCESS != php_http_env_set_response_header_value(http_code, name_str, name_len, *data_ptr, first TSRMLS_CC)) {
+ ZEND_HASH_FOREACH_VAL_IND(ht, data_ptr)
+ {
+ if (SUCCESS != php_http_env_set_response_header_value(http_code, name_str, name_len, data_ptr, first)) {
return FAILURE;
}
first = 0;
}
+ ZEND_HASH_FOREACH_END();
return SUCCESS;
} else {
- zval *data = php_http_ztyp(IS_STRING, value);
+ zend_string *data = zval_get_string(value);
- if (!Z_STRLEN_P(data)) {
- zval_ptr_dtor(&data);
- return php_http_env_set_response_header_value(http_code, name_str, name_len, NULL, replace TSRMLS_CC);
+ if (!data->len) {
+ zend_string_release(data);
+ return php_http_env_set_response_header_value(http_code, name_str, name_len, NULL, replace);
} else {
sapi_header_line h;
ZEND_RESULT_CODE ret;
if (name_len > INT_MAX) {
- name_len = INT_MAX;
+ return FAILURE;
}
h.response_code = http_code;
- h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, Z_STRLEN_P(data), Z_STRVAL_P(data));
+ h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, data->len, data->val);
- ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
+ ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h);
- zval_ptr_dtor(&data);
+ zend_string_release(data);
PTR_FREE(h.line);
return ret;
static PHP_METHOD(HttpEnv, getRequestHeader)
{
char *header_name_str = NULL;
- int header_name_len = 0;
+ size_t header_name_len = 0;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
return;
}
if (header_name_str && header_name_len) {
size_t header_length;
- char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL TSRMLS_CC);
+ char *header_value = php_http_env_get_request_header(header_name_str, header_name_len, &header_length, NULL);
if (header_value) {
- RETURN_STRINGL(header_value, header_length, 0);
+ RETURN_STR(php_http_cs2zs(header_value, header_length));
}
} else {
array_init(return_value);
- php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
+ php_http_env_get_request_headers(Z_ARRVAL_P(return_value));
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, getRequestBody)
{
- zend_object_value ov;
php_http_message_body_t *body;
- zend_class_entry *class_entry = php_http_message_body_class_entry;
+ php_http_message_body_object_t *body_obj;
+ zend_class_entry *class_entry = php_http_get_message_body_class_entry();
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|C", &class_entry), invalid_arg, return);
- body = php_http_env_get_request_body(TSRMLS_C);
- if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body, NULL TSRMLS_CC)) {
+ body = php_http_env_get_request_body();
+ if (SUCCESS == php_http_new((void *) &body_obj, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_get_message_body_class_entry(), body)) {
php_http_message_body_addref(body);
- RETVAL_OBJVAL(ov, 0);
+ RETVAL_OBJ(&body_obj->zo);
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, getResponseStatusForCode)
{
- long code;
+ zend_long code;
const char *status;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code)) {
return;
}
if ((status = php_http_env_get_response_status_for_code(code))) {
- RETURN_STRING(status, 1);
+ RETURN_STRING(status);
}
}
}
array_init(return_value);
-#define PHP_HTTP_RESPONSE_CODE(code, status) add_index_string(return_value, code, status, 1);
+#define PHP_HTTP_RESPONSE_CODE(code, status) add_index_string(return_value, code, status);
#include "php_http_response_codes.h"
#undef PHP_HTTP_RESPONSE_CODE
}
static PHP_METHOD(HttpEnv, getResponseHeader)
{
char *header_name_str = NULL;
- int header_name_len = 0;
+ size_t header_name_len = 0;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
return;
}
if (header_name_str && header_name_len) {
- char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
+ char *header_value = php_http_env_get_response_header(header_name_str, header_name_len);
if (header_value) {
- RETURN_STRING(header_value, 0);
+ RETURN_STR(php_http_cs2zs(header_value, strlen(header_value)));
}
} else {
array_init(return_value);
- php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
+ php_http_env_get_response_headers(Z_ARRVAL_P(return_value));
}
}
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
+ RETURN_LONG(php_http_env_get_response_code());
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader, 0, 0, 1)
static PHP_METHOD(HttpEnv, setResponseHeader)
{
char *header_name_str;
- int header_name_len;
+ size_t header_name_len;
zval *header_value = NULL;
- long code = 0;
+ zend_long code = 0;
zend_bool replace_header = 1;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
return;
}
- RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
+ RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, setResponseCode)
{
- long code;
+ zend_long code;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code)) {
return;
}
- RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
+ RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateLanguage, 0, 0, 1)
HashTable *supported;
zval *rs_array = NULL;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
return;
}
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
HashTable *supported;
zval *rs_array = NULL;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
return;
}
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
HashTable *supported;
zval *rs_array = NULL;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
return;
}
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
HashTable *supported;
zval *rs_array = NULL;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
return;
}
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
HashTable *supported, *rs;
zval *rs_array = NULL;
char *value_str, *sep_str = NULL;
- int value_len, sep_len = 0;
+ size_t value_len, sep_len = 0;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
return;
}
-
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
- if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len TSRMLS_CC))) {
+ if ((rs = php_http_negotiate(value_str, value_len, supported, sep_str, sep_len))) {
PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
} else {
PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_env_class_entry;
+static zend_class_entry *php_http_env_class_entry;
+zend_class_entry *php_http_env_get_class_entry(void)
+{
+ return php_http_env_class_entry;
+}
PHP_MINIT_FUNCTION(http_env)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Env", php_http_env_methods);
- php_http_env_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_env_class_entry = zend_register_internal_class(&ce);
return SUCCESS;
}
PHP_HTTP_RANGE_ERR
} php_http_range_status_t;
-PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t entity_length, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC);
-PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D);
-PHP_HTTP_API const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC);
+PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t entity_length, php_http_message_t *request);
+PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers);
+PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request);
+PHP_HTTP_API zend_bool php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request);
+PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(void);
+PHP_HTTP_API const char *php_http_env_get_request_method(php_http_message_t *request);
typedef enum php_http_content_disposition {
PHP_HTTP_CONTENT_DISPOSITION_NONE,
PHP_HTTP_CACHE_MISS
} php_http_cache_status_t;
-PHP_HTTP_API long php_http_env_get_response_code(TSRMLS_D);
+PHP_HTTP_API long php_http_env_get_response_code(void);
PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC);
-PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_code(long http_code TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC);
-
-PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_len, zend_bool check TSRMLS_DC);
-#define php_http_env_got_server_var(v) (NULL != php_http_env_get_server_var((v), strlen(v), 1 TSRMLS_CC))
-PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC);
-
-PHP_HTTP_API zend_class_entry *php_http_env_class_entry;
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_get_response_headers(HashTable *headers_ht);
+PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_code(long http_code);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_protocol_version(php_http_version_t *v);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_format(long http_code, zend_bool replace, const char *fmt, ...);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv);
+
+PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_len, zend_bool check);
+PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len);
+
+static inline zend_bool php_http_env_got_server_var(const char *v)
+{
+ return NULL != php_http_env_get_server_var(v, strlen(v), 1);
+}
+
+
+PHP_HTTP_API zend_class_entry *php_http_env_get_class_entry(void);
PHP_MINIT_FUNCTION(http_env);
PHP_RSHUTDOWN_FUNCTION(http_env);
#include "php_http_api.h"
-static int grab_file(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int grab_file(zval *tmp_name, int argc, va_list argv, zend_hash_key *key)
{
- zval *zfiles, **name, **zname, **error, **zerror, **type, **ztype, **size, **zsize, **tmp_name = zpp;
+ zval *zfiles, *name, *zname, *error, *zerror, *type, *ztype, *size, *zsize;
zend_hash_key *file_key;
zfiles = (zval *) va_arg(argv, zval *);
file_key = (zend_hash_key *) va_arg(argv, zend_hash_key *);
- name = (zval **) va_arg(argv, zval **);
- size = (zval **) va_arg(argv, zval **);
- type = (zval **) va_arg(argv, zval **);
- error = (zval **) va_arg(argv, zval **);
-
- if (SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(name), key->h, (void *) &zname)
- && SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(size), key->h, (void *) &zsize)
- && SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(type), key->h, (void *) &ztype)
- && SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(error), key->h, (void *) &zerror)
+ name = (zval *) va_arg(argv, zval *);
+ size = (zval *) va_arg(argv, zval *);
+ type = (zval *) va_arg(argv, zval *);
+ error = (zval *) va_arg(argv, zval *);
+
+ if ((zname = zend_hash_index_find(Z_ARRVAL_P(name), key->h))
+ && (zsize = zend_hash_index_find(Z_ARRVAL_P(size), key->h))
+ && (ztype = zend_hash_index_find(Z_ARRVAL_P(type), key->h))
+ && (zerror = zend_hash_index_find(Z_ARRVAL_P(error), key->h))
) {
- zval *entry, **array;
-
- MAKE_STD_ZVAL(entry);
- array_init(entry);
-
- Z_ADDREF_PP(tmp_name);
- add_assoc_zval_ex(entry, ZEND_STRS("file"), *tmp_name);
- Z_ADDREF_PP(zname);
- add_assoc_zval_ex(entry, ZEND_STRS("name"), *zname);
- Z_ADDREF_PP(zsize);
- add_assoc_zval_ex(entry, ZEND_STRS("size"), *zsize);
- Z_ADDREF_PP(ztype);
- add_assoc_zval_ex(entry, ZEND_STRS("type"), *ztype);
- Z_ADDREF_PP(zerror);
- add_assoc_zval_ex(entry, ZEND_STRS("error"), *zerror);
-
- if (SUCCESS == zend_hash_quick_find(Z_ARRVAL_P(zfiles), file_key->arKey, file_key->nKeyLength, file_key->h, (void *) &array)) {
- add_next_index_zval(*array, entry);
+ zval entry, *array;
+
+ array_init(&entry);
+
+ Z_TRY_ADDREF_P(tmp_name);
+ add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp_name);
+ Z_TRY_ADDREF_P(zname);
+ add_assoc_zval_ex(&entry, ZEND_STRL("name"), zname);
+ Z_TRY_ADDREF_P(zsize);
+ add_assoc_zval_ex(&entry, ZEND_STRL("size"), zsize);
+ Z_TRY_ADDREF_P(ztype);
+ add_assoc_zval_ex(&entry, ZEND_STRL("type"), ztype);
+ Z_TRY_ADDREF_P(zerror);
+ add_assoc_zval_ex(&entry, ZEND_STRL("error"), zerror);
+
+ if (file_key->key && (array = zend_hash_find(Z_ARRVAL_P(zfiles), file_key->key))) {
+ add_next_index_zval(array, &entry);
+ } else if (!file_key->key && (array = zend_hash_index_find(Z_ARRVAL_P(zfiles), file_key->h))) {
+ add_next_index_zval(array, &entry);
} else {
- zval *tmp;
+ zval tmp;
- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
- add_next_index_zval(tmp, entry);
- zend_hash_quick_update(Z_ARRVAL_P(zfiles), file_key->arKey, file_key->nKeyLength, file_key->h, (void *) &tmp, sizeof(zval *), NULL);
+ array_init(&tmp);
+ add_next_index_zval(&tmp, &entry);
+ if (file_key->key) {
+ zend_hash_update(Z_ARRVAL_P(zfiles), file_key->key, &tmp);
+ } else {
+ zend_hash_index_update(Z_ARRVAL_P(zfiles), file_key->h, &tmp);
+ }
}
}
return ZEND_HASH_APPLY_KEEP;
}
-static int grab_files(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+static int grab_files(zval *val, int argc, va_list argv, zend_hash_key *key)
{
- zval *zfiles, **name, **tmp_name, **error, **type, **size, **val = zpp;
+ zval *zfiles, *name, *tmp_name, *error, *type, *size;
zfiles = (zval *) va_arg(argv, zval *);
- if (Z_TYPE_PP(val) == IS_ARRAY
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("tmp_name"), (void *) &tmp_name)
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("name"), (void *) &name)
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("size"), (void *) &size)
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("type"), (void *) &type)
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("error"), (void *) &error)
+ if ((Z_TYPE_P(val) == IS_ARRAY)
+ && (tmp_name = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))
+ && (name = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("name")))
+ && (size = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("size")))
+ && (type = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("type")))
+ && (error = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("error")))
) {
int count;
- if (Z_TYPE_PP(tmp_name) == IS_ARRAY && (count = zend_hash_num_elements(Z_ARRVAL_PP(tmp_name))) > 1) {
- if (count == zend_hash_num_elements(Z_ARRVAL_PP(name))
- && count == zend_hash_num_elements(Z_ARRVAL_PP(size))
- && count == zend_hash_num_elements(Z_ARRVAL_PP(type))
- && count == zend_hash_num_elements(Z_ARRVAL_PP(error))
+ if (Z_TYPE_P(tmp_name) == IS_ARRAY && (count = zend_hash_num_elements(Z_ARRVAL_P(tmp_name))) > 1) {
+ if (count == zend_hash_num_elements(Z_ARRVAL_P(name))
+ && count == zend_hash_num_elements(Z_ARRVAL_P(size))
+ && count == zend_hash_num_elements(Z_ARRVAL_P(type))
+ && count == zend_hash_num_elements(Z_ARRVAL_P(error))
) {
- zend_hash_apply_with_arguments(Z_ARRVAL_PP(tmp_name) TSRMLS_CC, grab_file, 6, zfiles, key, name, size, type, error);
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp_name), grab_file, 6, zfiles, key, name, size, type, error);
} else {
/* wat?! */
return ZEND_HASH_APPLY_STOP;
}
} else {
- zval *cpy, **tmp;
-
- MAKE_STD_ZVAL(cpy);
- MAKE_COPY_ZVAL(val, cpy);
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(cpy), ZEND_STRS("tmp_name"), (void *) &tmp)) {
- Z_ADDREF_PP(tmp);
- add_assoc_zval_ex(cpy, ZEND_STRS("file"), *tmp);
- zend_hash_del_key_or_index(Z_ARRVAL_P(cpy), ZEND_STRS("tmp_name"), 0, HASH_DEL_KEY);
+ zval *tmp, entry;
+
+ ZVAL_DUP(&entry, val);
+ if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("tmp_name")))) {
+ Z_ADDREF_P(tmp);
+ add_assoc_zval_ex(&entry, ZEND_STRL("file"), tmp);
+ zend_hash_str_del(Z_ARRVAL(entry), ZEND_STRL("tmp_name"));
}
- if (key->nKeyLength > 0) {
- zend_hash_quick_update(Z_ARRVAL_P(zfiles), key->arKey, key->nKeyLength, key->h, (void *) &cpy, sizeof(zval *), NULL);
+ if (key->key) {
+ zend_hash_update(Z_ARRVAL_P(zfiles), key->key, &entry);
} else {
- zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, (void *) &cpy, sizeof(zval *), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(zfiles), key->h, &entry);
}
}
}
#define PHP_HTTP_ENV_REQUEST_OBJECT_INIT(obj) \
do { \
if (!obj->message) { \
- obj->message = php_http_message_init_env(NULL, PHP_HTTP_REQUEST TSRMLS_CC); \
+ obj->message = php_http_message_init_env(NULL, PHP_HTTP_REQUEST); \
} \
} while(0)
+static zend_class_entry *php_http_env_request_class_entry;
+zend_class_entry *php_http_get_env_request_class_entry(void)
+{
+ return php_http_env_request_class_entry;
+}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest___construct, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvRequest, __construct)
{
php_http_message_object_t *obj;
- zval *zsg, *zqs;
+ zval *zsg, zqs;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
obj->body = NULL;
- php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC), unexpected_val, return);
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST), unexpected_val, return);
- zsg = php_http_env_get_superglobal(ZEND_STRL("_GET") TSRMLS_CC);
- MAKE_STD_ZVAL(zqs);
- object_init_ex(zqs, php_http_querystring_class_entry);
- php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
- zval_ptr_dtor(&zqs);
- return;
- );
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), zqs TSRMLS_CC);
+ zsg = php_http_env_get_superglobal(ZEND_STRL("_GET"));
+ object_init_ex(&zqs, php_http_querystring_get_class_entry());
+ php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), &zqs);
zval_ptr_dtor(&zqs);
- zsg = php_http_env_get_superglobal(ZEND_STRL("_POST") TSRMLS_CC);
- MAKE_STD_ZVAL(zqs);
- object_init_ex(zqs, php_http_querystring_class_entry);
- php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
- zval_ptr_dtor(&zqs);
- return;
- );
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), zqs TSRMLS_CC);
+ zsg = php_http_env_get_superglobal(ZEND_STRL("_POST"));
+ object_init_ex(&zqs, php_http_querystring_get_class_entry());
+ php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), &zqs);
zval_ptr_dtor(&zqs);
- zsg = php_http_env_get_superglobal(ZEND_STRL("_COOKIE") TSRMLS_CC);
- MAKE_STD_ZVAL(zqs);
- object_init_ex(zqs, php_http_querystring_class_entry);
- php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
- zval_ptr_dtor(&zqs);
- return;
- );
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), zqs TSRMLS_CC);
+ zsg = php_http_env_get_superglobal(ZEND_STRL("_COOKIE"));
+ object_init_ex(&zqs, php_http_querystring_get_class_entry());
+ php_http_expect(SUCCESS == php_http_querystring_ctor(&zqs, zsg), unexpected_val, return);
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), &zqs);
zval_ptr_dtor(&zqs);
- MAKE_STD_ZVAL(zqs);
- array_init(zqs);
- if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES") TSRMLS_CC))) {
- zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg) TSRMLS_CC, grab_files, 1, zqs);
+ array_init(&zqs);
+ if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES")))) {
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg), grab_files, 1, &zqs);
}
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), &zqs);
zval_ptr_dtor(&zqs);
}
do {\
zend_fcall_info fci; \
zend_fcall_info_cache fcc; \
- zval *rv = NULL, mn, ***args = ecalloc(sizeof(zval **), ZEND_NUM_ARGS()); \
- zval *qs = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL(prop), 0 TSRMLS_CC); \
+ zval rv, mn, *args = ecalloc(sizeof(zval), ZEND_NUM_ARGS()); \
+ zval *this_ptr = getThis(); \
+ zval qs_tmp, *qs = zend_read_property(Z_OBJCE_P(this_ptr), this_ptr, ZEND_STRL(prop), 0, &qs_tmp); \
\
- INIT_PZVAL(&mn); \
+ ZVAL_NULL(&rv); \
array_init(&mn); \
- Z_ADDREF_P(qs); \
+ Z_TRY_ADDREF_P(qs); \
add_next_index_zval(&mn, qs); \
- add_next_index_stringl(&mn, ZEND_STRL("get"), 1); \
- zend_fcall_info_init(&mn, 0, &fci, &fcc, NULL, NULL TSRMLS_CC); \
+ add_next_index_stringl(&mn, ZEND_STRL("get")); \
+ zend_fcall_info_init(&mn, 0, &fci, &fcc, NULL, NULL); \
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args); \
- zend_fcall_info_argp(&fci TSRMLS_CC, ZEND_NUM_ARGS(), args); \
- zend_fcall_info_call(&fci, &fcc, &rv, NULL TSRMLS_CC); \
+ zend_fcall_info_argp(&fci, ZEND_NUM_ARGS(), args); \
+ zend_fcall_info_call(&fci, &fcc, &rv, NULL); \
zend_fcall_info_args_clear(&fci, 1); \
efree(args); \
zval_dtor(&mn); \
- if (rv) { \
- RETVAL_ZVAL(rv, 0, 1); \
- } \
+ RETVAL_ZVAL(&rv, 0, 1); \
} while(0);
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getForm, 0, 0, 0)
if (ZEND_NUM_ARGS()) {
call_querystring_get("form");
} else {
- zval *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0 TSRMLS_CC);
+ zval zform_tmp, *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0, &zform_tmp);
RETURN_ZVAL(zform, 1, 0);
}
}
if (ZEND_NUM_ARGS()) {
call_querystring_get("query");
} else {
- zval *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0 TSRMLS_CC);
+ zval zquery_tmp, *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0, &zquery_tmp);
RETURN_ZVAL(zquery, 1, 0);
}
}
if (ZEND_NUM_ARGS()) {
call_querystring_get("cookie");
} else {
- zval *zcookie = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), 0 TSRMLS_CC);
+ zval zcookie_tmp, *zcookie = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("cookie"), 0, &zcookie_tmp);
RETURN_ZVAL(zcookie, 1, 0);
}
}
static PHP_METHOD(HttpEnvRequest, getFiles)
{
if (SUCCESS == zend_parse_parameters_none()) {
- zval *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0 TSRMLS_CC);
+ zval zfiles_tmp, *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0, &zfiles_tmp);
RETURN_ZVAL(zfiles, 1, 0);
}
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_env_request_class_entry;
-
PHP_MINIT_FUNCTION(http_env_request)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Request", php_http_env_request_methods);
- php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
+ php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry());
- zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("cookie"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("files"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("cookie"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("files"), ZEND_ACC_PROTECTED);
return SUCCESS;
}
#ifndef PHP_HTTP_ENV_REQUEST_H
#define PHP_HTTP_ENV_REQUEST_H
-PHP_HTTP_API zend_class_entry *php_http_env_request_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_env_request_class_entry(void);
PHP_MINIT_FUNCTION(http_env_request);
#endif
#include "php_http_api.h"
-static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len TSRMLS_DC)
+static void set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len)
{
if (Z_TYPE_P(options) == IS_OBJECT) {
if (value_ptr) {
switch (type) {
case IS_DOUBLE:
- zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr TSRMLS_CC);
+ zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr);
break;
case IS_LONG:
- zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(long *)value_ptr TSRMLS_CC);
+ zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(zend_long *)value_ptr);
break;
case IS_STRING:
- zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len TSRMLS_CC);
+ zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len);
break;
case IS_ARRAY:
case IS_OBJECT:
- zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr TSRMLS_CC);
+ zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr);
break;
}
} else {
- zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len TSRMLS_CC);
+ zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len);
}
} else {
convert_to_array(options);
if (value_ptr) {
switch (type) {
case IS_DOUBLE:
- add_assoc_double_ex(options, name_str, name_len + 1, *(double *)value_ptr);
+ add_assoc_double_ex(options, name_str, name_len, *(double *)value_ptr);
break;
case IS_LONG:
- add_assoc_long_ex(options, name_str, name_len + 1, *(long *)value_ptr);
+ add_assoc_long_ex(options, name_str, name_len, *(zend_long *)value_ptr);
break;
case IS_STRING: {
- char *value = estrndup(value_ptr, value_len);
- add_assoc_stringl_ex(options, name_str, name_len + 1, value, value_len, 0);
+ zend_string *value = zend_string_init(value_ptr, value_len, 0);
+ add_assoc_str_ex(options, name_str, name_len, value);
break;
case IS_ARRAY:
case IS_OBJECT:
Z_ADDREF_P(value_ptr);
- add_assoc_zval_ex(options, name_str, name_len + 1, value_ptr);
+ add_assoc_zval_ex(options, name_str, name_len, value_ptr);
break;
}
}
} else {
- add_assoc_null_ex(options, name_str, name_len + 1);
+ add_assoc_null_ex(options, name_str, name_len);
}
}
}
-static zval *get_option(zval *options, const char *name_str, size_t name_len TSRMLS_DC)
+static zval *get_option(zval *options, const char *name_str, size_t name_len, zval *tmp)
{
- zval *val, **valptr;
+ zval *val = NULL;
if (Z_TYPE_P(options) == IS_OBJECT) {
- val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0 TSRMLS_CC);
+ val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0, tmp);
+ } else if (Z_TYPE_P(options) == IS_ARRAY) {
+ val = zend_symtable_str_find(Z_ARRVAL_P(options), name_str, name_len);
} else {
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(options), name_str, name_len + 1, (void *) &valptr)) {
- val = *valptr;
- } else {
- val = NULL;
- }
+ abort();
}
if (val) {
- Z_ADDREF_P(val);
+ Z_TRY_ADDREF_P(val);
}
return val;
}
-static php_http_message_body_t *get_body(zval *options TSRMLS_DC)
+static php_http_message_body_t *get_body(zval *options)
{
- zval *zbody;
+ zval zbody_tmp, *zbody;
php_http_message_body_t *body = NULL;
- if ((zbody = get_option(options, ZEND_STRL("body") TSRMLS_CC))) {
- if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) {
- php_http_message_body_object_t *body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
+ if ((zbody = get_option(options, ZEND_STRL("body"), &zbody_tmp))) {
+ if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) {
+ php_http_message_body_object_t *body_obj = PHP_HTTP_OBJ(NULL, zbody);
body = body_obj->body;
}
- zval_ptr_dtor(&zbody);
+ Z_TRY_DELREF_P(zbody);
}
return body;
}
-static php_http_message_t *get_request(zval *options TSRMLS_DC)
+static php_http_message_t *get_request(zval *options)
{
- zval *zrequest;
+ zval zrequest_tmp, *zrequest;
php_http_message_t *request = NULL;
- if ((zrequest = get_option(options, ZEND_STRL("request") TSRMLS_CC))) {
- if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry TSRMLS_CC)) {
- php_http_message_object_t *request_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
+ if ((zrequest = get_option(options, ZEND_STRL("request"), &zrequest_tmp))) {
+ if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_get_class_entry())) {
+ php_http_message_object_t *request_obj = PHP_HTTP_OBJ(NULL, zrequest);
request = request_obj->message;
}
- zval_ptr_dtor(&zrequest);
+ Z_TRY_DELREF_P(zrequest);
}
return request;
}
-static void set_cookie(zval *options, zval *zcookie_new TSRMLS_DC)
+static void set_cookie(zval *options, zval *zcookie_new)
{
- HashPosition pos;
- zval *zcookies_set;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- php_http_cookie_object_t *obj = zend_object_store_get_object(zcookie_new TSRMLS_CC);
-
- zcookies_set = get_option(options, ZEND_STRL("cookies") TSRMLS_CC);
- if (!zcookies_set || Z_TYPE_P(zcookies_set) != IS_ARRAY) {
- if (zcookies_set) {
- zval_ptr_dtor(&zcookies_set);
- }
- MAKE_STD_ZVAL(zcookies_set);
- array_init_size(zcookies_set, zend_hash_num_elements(&obj->list->cookies));
- } else {
- SEPARATE_ZVAL(&zcookies_set);
+ zval tmp, zcookies_set_tmp, *zcookies_set;
+ php_http_arrkey_t key;
+ php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie_new);
+
+ array_init(&tmp);
+ zcookies_set = get_option(options, ZEND_STRL("cookies"), &zcookies_set_tmp);
+ if (zcookies_set && Z_TYPE_P(zcookies_set) == IS_ARRAY) {
+ array_copy(Z_ARRVAL_P(zcookies_set), Z_ARRVAL(tmp));
+ zval_ptr_dtor(zcookies_set);
}
- FOREACH_HASH_KEY(pos, &obj->list->cookies, key) {
+ ZEND_HASH_FOREACH_KEY(&obj->list->cookies, key.h, key.key)
+ {
Z_ADDREF_P(zcookie_new);
- if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_zval_ex(zcookies_set, key.str, key.len, zcookie_new);
+ if (key.key) {
+ add_assoc_zval_ex(&tmp, key.key->val, key.key->len, zcookie_new);
} else {
- add_index_zval(zcookies_set, key.num, zcookie_new);
+ add_index_zval(&tmp, key.h, zcookie_new);
}
}
+ ZEND_HASH_FOREACH_END();
- set_option(options, ZEND_STRL("cookies"), IS_ARRAY, zcookies_set, 0 TSRMLS_CC);
- zval_ptr_dtor(&zcookies_set);
+ set_option(options, ZEND_STRL("cookies"), IS_ARRAY, &tmp, 0);
+ zval_ptr_dtor(&tmp);
}
-php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
- int free_etag = 0;
- char *header = NULL, *etag;
+ char *header = NULL, *etag = NULL;
php_http_message_body_t *body;
- zval *zetag;
+ zval zetag_tmp, *zetag;
- if (!(body = get_body(options TSRMLS_CC))) {
+ if (!(body = get_body(options))) {
return ret;
}
- if ((zetag = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) {
- zval *zetag_copy = php_http_ztyp(IS_STRING, zetag);
- zval_ptr_dtor(&zetag);
- zetag = zetag_copy;
+ if ((zetag = get_option(options, ZEND_STRL("etag"), &zetag_tmp)) && Z_TYPE_P(zetag) != IS_NULL) {
+ zend_string *zs = zval_get_string(zetag);
+ etag = estrndup(zs->val, zs->len);
+ zend_string_release(zs);
+ zval_ptr_dtor(zetag);
}
- if (zetag && Z_STRLEN_P(zetag)) {
- etag = Z_STRVAL_P(zetag);
- } else if ((etag = php_http_message_body_etag(body))) {
- set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag) TSRMLS_CC);
- free_etag = 1;
+ if (!etag && (etag = php_http_message_body_etag(body))) {
+ set_option(options, ZEND_STRL("etag"), IS_STRING, etag, strlen(etag));
}
- if (zetag) {
- zval_ptr_dtor(&zetag);
- }
-
- if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) {
- ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD) ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS;
- }
-
- if (free_etag) {
- efree(etag);
+ if (etag && (header = php_http_env_get_request_header(header_str, header_len, NULL, request))) {
+ ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD) ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS;
}
+ PTR_FREE(etag);
PTR_FREE(header);
+
return ret;
}
-php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
char *header;
time_t ums, lm = 0;
php_http_message_body_t *body;
- zval *zlm;
+ zval zlm_tmp, *zlm;
- if (!(body = get_body(options TSRMLS_CC))) {
+ if (!(body = get_body(options))) {
return ret;
}
- if ((zlm = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) {
- zval *zlm_copy = php_http_ztyp(IS_LONG, zlm);
- zval_ptr_dtor(&zlm);
- zlm = zlm_copy;
+ if ((zlm = get_option(options, ZEND_STRL("lastModified"), &zlm_tmp))) {
+ lm = zval_get_long(zlm);
+ zval_ptr_dtor(zlm);
}
- if (zlm && Z_LVAL_P(zlm) > 0) {
- lm = Z_LVAL_P(zlm);
- } else {
+ if (lm <= 0) {
lm = php_http_message_body_mtime(body);
- set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0 TSRMLS_CC);
+ set_option(options, ZEND_STRL("lastModified"), IS_LONG, &lm, 0);
}
- if (zlm) {
- zval_ptr_dtor(&zlm);
- }
-
- if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request TSRMLS_CC))) {
+ if ((header = php_http_env_get_request_header(header_str, header_len, NULL, request))) {
ums = php_parse_date(header, NULL);
if (ums > 0 && ums >= lm) {
static zend_bool php_http_env_response_is_cacheable(php_http_env_response_t *r, php_http_message_t *request)
{
long status = r->ops->get_status(r);
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (status && status / 100 != 2) {
return 0;
}
- if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request TSRMLS_CC)) {
+ if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request)) {
return 0;
}
- if (-1 == php_http_select_str(php_http_env_get_request_method(request TSRMLS_CC), 2, "HEAD", "GET")) {
+ if (-1 == php_http_select_str(php_http_env_get_request_method(request), 2, "HEAD", "GET")) {
return 0;
}
return 1;
}
-static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
+static size_t output(void *context, char *buf, size_t len)
{
php_http_env_response_t *r = context;
return len;
}
-#define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
static ZEND_RESULT_CODE php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
{
size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (r->content.encoder) {
char *enc_str = NULL;
if (!enc_str) {
return SUCCESS;
}
- chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r);
PTR_FREE(enc_str);
} else {
- chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r);
}
return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE;
}
-php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
+static inline ZEND_RESULT_CODE php_http_env_response_send_done(php_http_env_response_t *r)
+{
+ return php_http_env_response_send_data(r, NULL, 0);
+}
+
+php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg)
{
zend_bool free_r;
r->buffer = php_http_buffer_init(NULL);
- Z_ADDREF_P(options);
- r->options = options;
-
- TSRMLS_SET_CTX(r->ts);
+ ZVAL_COPY(&r->options, options);
if (r->ops->init && (SUCCESS != r->ops->init(r, init_arg))) {
if (free_r) {
static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t *r, php_http_message_t *request)
{
ZEND_RESULT_CODE ret = SUCCESS;
- zval *zoption, *options = r->options;
- TSRMLS_FETCH_FROM_CTX(r->ts);
+ zval zoption_tmp, *zoption, *options = &r->options;
if (r->done) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
+ if ((zoption = get_option(options, ZEND_STRL("headers"), &zoption_tmp))) {
if (Z_TYPE_P(zoption) == IS_ARRAY) {
- php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+ php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r);
}
- zval_ptr_dtor(&zoption);
+ zval_ptr_dtor(zoption);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("responseCode"), &zoption_tmp))) {
+ zend_long rc = zval_get_long(zoption);
- zval_ptr_dtor(&zoption);
- if (Z_LVAL_P(zoption_copy) > 0) {
- ret = r->ops->set_status(r, Z_LVAL_P(zoption_copy));
+ zval_ptr_dtor(zoption);
+ if (rc > 0) {
+ ret = r->ops->set_status(r, rc);
}
- zval_ptr_dtor(&zoption_copy);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("httpVersion") TSRMLS_CC))) {
+ if ((zoption = get_option(options, ZEND_STRL("httpVersion"), &zoption_tmp))) {
php_http_version_t v;
- zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+ zend_string *zs = zval_get_string(zoption);
- zval_ptr_dtor(&zoption);
- if (Z_STRLEN_P(zoption_copy) && php_http_version_parse(&v, Z_STRVAL_P(zoption_copy) TSRMLS_CC)) {
+ zval_ptr_dtor(zoption);
+ if (zs->len && php_http_version_parse(&v, zs->val)) {
ret = r->ops->set_protocol_version(r, &v);
php_http_version_dtor(&v);
}
- zval_ptr_dtor(&zoption_copy);
+ zend_string_release(zs);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("cookies") TSRMLS_CC))) {
+ if ((zoption = get_option(options, ZEND_STRL("cookies"), &zoption_tmp))) {
if (Z_TYPE_P(zoption) == IS_ARRAY) {
- HashPosition pos;
- zval **zcookie;
+ zval *zcookie;
- FOREACH_VAL(pos, zoption, zcookie) {
- if (Z_TYPE_PP(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(zcookie), php_http_cookie_class_entry TSRMLS_CC)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(*zcookie TSRMLS_CC);
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zoption), zcookie)
+ {
+ if (Z_TYPE_P(zcookie) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_get_class_entry())) {
+ php_http_cookie_object_t *obj = PHP_HTTP_OBJ(NULL, zcookie);
char *str;
size_t len;
efree(str);
}
}
+ ZEND_HASH_FOREACH_END();
}
- zval_ptr_dtor(&zoption);
+ zval_ptr_dtor(zoption);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("contentType"), &zoption_tmp))) {
+ zend_string *zs = zval_get_string(zoption);
- zval_ptr_dtor(&zoption);
- if (Z_STRLEN_P(zoption_copy) && strchr(Z_STRVAL_P(zoption_copy), '/')) {
- if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
- r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
+ zval_ptr_dtor(zoption);
+ if (zs->len && strchr(zs->val, '/')) {
+ if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", zs->len, zs->val))) {
+ r->content.type = estrndup(zs->val, zs->len);
}
}
- zval_ptr_dtor(&zoption_copy);
+ zend_string_release(zs);
}
if (ret != SUCCESS) {
if (r->range.status == PHP_HTTP_RANGE_OK) {
if (zend_hash_num_elements(&r->range.values) == 1) {
- zval **range, **begin, **end;
+ zval *range, *begin, *end;
- if ( 1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
- && 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
+ if ( 1 == php_http_array_list(&r->range.values, 1, &range)
+ && 2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end)
) {
if (SUCCESS == (ret = r->ops->set_status(r, 206))) {
- ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length);
+ ret = r->ops->set_header(r, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_P(begin), Z_LVAL_P(end), r->content.length);
}
} else {
/* this should never happen */
ret = FAILURE;
}
} else {
- php_http_boundary(r->range.boundary, sizeof(r->range.boundary) TSRMLS_CC);
+ php_http_boundary(r->range.boundary, sizeof(r->range.boundary));
if (SUCCESS == (ret = r->ops->set_status(r, 206))) {
ret = r->ops->set_header(r, "Content-Type: multipart/byteranges; boundary=%s", r->range.boundary);
}
}
} else {
- if ((zoption = get_option(options, ZEND_STRL("cacheControl") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("cacheControl"), &zoption_tmp))) {
+ zend_string *zs = zval_get_string(zoption);
- zval_ptr_dtor(&zoption);
- if (Z_STRLEN_P(zoption_copy)) {
- ret = r->ops->set_header(r, "Cache-Control: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy));
+ zval_ptr_dtor(zoption);
+ if (zs->len) {
+ ret = r->ops->set_header(r, "Cache-Control: %.*s", zs->len, zs->val);
}
- zval_ptr_dtor(&zoption_copy);
+ zend_string_release(zs);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("contentDisposition") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_ARRAY, zoption);
- php_http_buffer_t buf;
+ if ((zoption = get_option(options, ZEND_STRL("contentDisposition"), &zoption_tmp))) {
+
+ if (Z_TYPE_P(zoption) == IS_ARRAY) {
+ php_http_buffer_t buf;
- php_http_buffer_init(&buf);
- if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption_copy), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC)) {
- if (buf.used) {
- ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data);
+ php_http_buffer_init(&buf);
+ if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT)) {
+ if (buf.used) {
+ ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data);
+ }
}
- }
- php_http_buffer_dtor(&buf);
- zval_ptr_dtor(&zoption_copy);
- zval_ptr_dtor(&zoption);
+ php_http_buffer_dtor(&buf);
+ }
+ zval_ptr_dtor(zoption);
}
if (ret != SUCCESS) {
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("contentEncoding") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("contentEncoding"), &zoption_tmp))) {
+ zend_long ce = zval_get_long(zoption);
zval zsupported;
HashTable *result = NULL;
- zval_ptr_dtor(&zoption);
- switch (Z_LVAL_P(zoption_copy)) {
+ zval_ptr_dtor(zoption);
+ switch (ce) {
case PHP_HTTP_CONTENT_ENCODING_GZIP:
- INIT_PZVAL(&zsupported);
array_init(&zsupported);
- add_next_index_stringl(&zsupported, ZEND_STRL("none"), 1);
- add_next_index_stringl(&zsupported, ZEND_STRL("gzip"), 1);
- add_next_index_stringl(&zsupported, ZEND_STRL("deflate"), 1);
+ add_next_index_stringl(&zsupported, ZEND_STRL("none"));
+ add_next_index_stringl(&zsupported, ZEND_STRL("gzip"));
+ add_next_index_stringl(&zsupported, ZEND_STRL("deflate"));
- if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request TSRMLS_CC))) {
- char *key_str = NULL;
- uint key_len = 0;
+ if ((result = php_http_negotiate_encoding(Z_ARRVAL(zsupported), request))) {
+ zend_string *key_str = NULL;
+ zend_ulong index = 0;
zend_hash_internal_pointer_reset(result);
- if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key_str, &key_len, NULL, 0, NULL)) {
- if (!strcmp(key_str, "gzip")) {
- if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC))) {
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key(result, &key_str, &index)) {
+ if (zend_string_equals_literal(key_str, "gzip")) {
+ if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP))) {
ret = FAILURE;
} else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: gzip"))) {
- r->content.encoding = estrndup(key_str, key_len - 1);
+ r->content.encoding = estrndup(key_str->val, key_str->len);
}
- } else if (!strcmp(key_str, "deflate")) {
- if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC))) {
+ } else if (zend_string_equals_literal(key_str, "deflate")) {
+ if (!(r->content.encoder = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB))) {
ret = FAILURE;
} else if (SUCCESS == (ret = r->ops->set_header(r, "Content-Encoding: deflate"))) {
- r->content.encoding = estrndup(key_str, key_len - 1);
+ r->content.encoding = estrndup(key_str->val, key_str->len);
}
} else {
ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding"));
ret = r->ops->del_header(r, ZEND_STRL("Content-Encoding"));
break;
}
- zval_ptr_dtor(&zoption_copy);
}
if (SUCCESS != ret) {
}
if (php_http_env_response_is_cacheable(r, request)) {
- switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request TSRMLS_CC)) {
+ switch (php_http_env_is_response_cached_by_etag(options, ZEND_STRL("If-None-Match"), request)) {
case PHP_HTTP_CACHE_MISS:
break;
case PHP_HTTP_CACHE_NO:
- if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request TSRMLS_CC)) {
+ if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(options, ZEND_STRL("If-Modified-Since"), request)) {
break;
}
/* no break */
break;
}
- if ((zoption = get_option(options, ZEND_STRL("etag") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("etag"), &zoption_tmp))) {
+ zend_string *zs = zval_get_string(zoption);
- zval_ptr_dtor(&zoption);
- if (*Z_STRVAL_P(zoption_copy) != '"' && strncmp(Z_STRVAL_P(zoption_copy), "W/\"", 3)) {
- ret = r->ops->set_header(r, "ETag: \"%s\"", Z_STRVAL_P(zoption_copy));
+ zval_ptr_dtor(zoption);
+ if (*zs->val != '"' && strncmp(zs->val, "W/\"", 3)) {
+ ret = r->ops->set_header(r, "ETag: \"%s\"", zs->val);
} else {
- ret = r->ops->set_header(r, "ETag: %s", Z_STRVAL_P(zoption_copy));
+ ret = r->ops->set_header(r, "ETag: %s", zs->val);
}
- zval_ptr_dtor(&zoption_copy);
+ zend_string_release(zs);
}
- if ((zoption = get_option(options, ZEND_STRL("lastModified") TSRMLS_CC))) {
- zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
+ if ((zoption = get_option(options, ZEND_STRL("lastModified"), &zoption_tmp))) {
+ zend_long lm = zval_get_long(zoption);
- zval_ptr_dtor(&zoption);
- if (Z_LVAL_P(zoption_copy)) {
- char *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), Z_LVAL_P(zoption_copy), 0 TSRMLS_CC);
+ zval_ptr_dtor(zoption);
+ if (lm) {
+ zend_string *date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), lm, 0);
if (date) {
- ret = r->ops->set_header(r, "Last-Modified: %s", date);
- efree(date);
+ ret = r->ops->set_header(r, "Last-Modified: %s", date->val);
+ zend_string_release(date);
}
}
- zval_ptr_dtor(&zoption_copy);
}
}
}
static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t *r)
{
ZEND_RESULT_CODE ret = SUCCESS;
- zval *zoption;
+ zval zoption_tmp, *zoption;
php_http_message_body_t *body;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (r->done) {
return ret;
}
- if ((body = get_body(r->options TSRMLS_CC))) {
- if ((zoption = get_option(r->options, ZEND_STRL("throttleDelay") TSRMLS_CC))) {
- if (Z_TYPE_P(zoption) == IS_DOUBLE) {
- r->throttle.delay = Z_DVAL_P(zoption);
- }
- zval_ptr_dtor(&zoption);
+ if ((body = get_body(&r->options))) {
+ if ((zoption = get_option(&r->options, ZEND_STRL("throttleDelay"), &zoption_tmp))) {
+ r->throttle.delay = zval_get_double(zoption);
+ zval_ptr_dtor(zoption);
}
- if ((zoption = get_option(r->options, ZEND_STRL("throttleChunk") TSRMLS_CC))) {
- if (Z_TYPE_P(zoption) == IS_LONG) {
- r->throttle.chunk = Z_LVAL_P(zoption);
- }
- zval_ptr_dtor(&zoption);
+ if ((zoption = get_option(&r->options, ZEND_STRL("throttleChunk"), &zoption_tmp))) {
+ r->throttle.chunk = zval_get_long(zoption);
+ zval_ptr_dtor(zoption);
}
if (r->range.status == PHP_HTTP_RANGE_OK) {
if (zend_hash_num_elements(&r->range.values) == 1) {
/* single range */
- zval **range, **begin, **end;
+ zval *range, *begin, *end;
- if ( 1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
- && 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
+ if ( 1 == php_http_array_list(&r->range.values, 1, &range)
+ && 2 == php_http_array_list(Z_ARRVAL_P(range), 2, &begin, &end)
) {
/* send chunk */
- ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1);
if (ret == SUCCESS) {
ret = php_http_env_response_send_done(r);
}
} else {
/* send multipart/byte-ranges message */
- HashPosition pos;
- zval **chunk;
+ zval *chunk;
- FOREACH_HASH_VAL(pos, &r->range.values, chunk) {
- zval **begin, **end;
+ ZEND_HASH_FOREACH_VAL(&r->range.values, chunk)
+ {
+ zval *begin, *end;
- if (2 == php_http_array_list(Z_ARRVAL_PP(chunk) TSRMLS_CC, 2, &begin, &end)) {
+ if (2 == php_http_array_list(Z_ARRVAL_P(chunk), 2, &begin, &end)) {
php_http_buffer_appendf(r->buffer,
PHP_HTTP_CRLF
"--%s" PHP_HTTP_CRLF
/* - */
r->range.boundary,
r->content.type ? r->content.type : "application/octet-stream",
- Z_LVAL_PP(begin),
- Z_LVAL_PP(end),
+ Z_LVAL_P(begin),
+ Z_LVAL_P(end),
r->content.length
);
- ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_P(begin), Z_LVAL_P(end) - Z_LVAL_P(begin) + 1);
}
}
+ ZEND_HASH_FOREACH_END();
if (ret == SUCCESS) {
php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
{
php_http_message_t *request;
php_http_message_body_t *body;
- TSRMLS_FETCH_FROM_CTX(r->ts);
- request = get_request(r->options TSRMLS_CC);
+ request = get_request(&r->options);
/* check for ranges */
- if ((body = get_body(r->options TSRMLS_CC))) {
+ if ((body = get_body(&r->options))) {
r->content.length = php_http_message_body_size(body);
if (SUCCESS != r->ops->set_header(r, "Accept-Ranges: bytes")) {
return FAILURE;
} else {
- zend_hash_init(&r->range.values, 0, NULL, ZVAL_PTR_DTOR, 0);
- r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request TSRMLS_CC);
+ ZEND_INIT_SYMTABLE_EX(&r->range.values, 0, 0);
+ r->range.status = php_http_env_get_request_ranges(&r->range.values, r->content.length, request);
switch (r->range.status) {
case PHP_HTTP_RANGE_NO:
break;
case PHP_HTTP_RANGE_ERR:
- if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request TSRMLS_CC)) {
+ if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request)) {
r->range.status = PHP_HTTP_RANGE_NO;
zend_hash_destroy(&r->range.values);
} else {
break;
case PHP_HTTP_RANGE_OK:
- if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC)
- || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Range"), request TSRMLS_CC)
+ if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Range"), request)
+ || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Range"), request)
) {
r->range.status = PHP_HTTP_RANGE_NO;
zend_hash_destroy(&r->range.values);
break;
}
- if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(r->options, ZEND_STRL("If-Match"), request TSRMLS_CC)
- || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("If-Unmodified-Since"), request TSRMLS_CC)
- || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(r->options, ZEND_STRL("Unless-Modified-Since"), request TSRMLS_CC)
+ if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(&r->options, ZEND_STRL("If-Match"), request)
+ || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("If-Unmodified-Since"), request)
+ || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(&r->options, ZEND_STRL("Unless-Modified-Since"), request)
) {
r->done = 1;
zend_hash_destroy(&r->range.values);
}
if (SUCCESS != php_http_env_response_send_head(r, request)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response headers");
+ php_error_docref(NULL, E_WARNING, "Failed to send response headers");
return FAILURE;
}
if (SUCCESS != php_http_env_response_send_body(r)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response body");
+ php_error_docref(NULL, E_WARNING, "Failed to send response body");
return FAILURE;
}
if (SUCCESS != r->ops->finish(r)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish response");
+ php_error_docref(NULL, E_WARNING, "Failed to finish response");
return FAILURE;
}
static long php_http_env_response_sapi_get_status(php_http_env_response_t *r)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
-
- return php_http_env_get_response_code(TSRMLS_C);
+ return php_http_env_get_response_code();
}
static ZEND_RESULT_CODE php_http_env_response_sapi_set_status(php_http_env_response_t *r, long http_code)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
-
- return php_http_env_set_response_code(http_code TSRMLS_CC);
+ return php_http_env_set_response_code(http_code);
}
static ZEND_RESULT_CODE php_http_env_response_sapi_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
- return php_http_env_set_response_protocol_version(v TSRMLS_CC);
+ return php_http_env_set_response_protocol_version(v);
}
static ZEND_RESULT_CODE php_http_env_response_sapi_set_header(php_http_env_response_t *r, const char *fmt, ...)
{
ZEND_RESULT_CODE ret;
va_list args;
- TSRMLS_FETCH_FROM_CTX(r->ts);
va_start(args, fmt);
- ret = php_http_env_set_response_header_va(0, 1, fmt, args TSRMLS_CC);
+ ret = php_http_env_set_response_header_va(0, 1, fmt, args);
va_end(args);
return ret;
{
ZEND_RESULT_CODE ret;
va_list args;
- TSRMLS_FETCH_FROM_CTX(r->ts);
va_start(args, fmt);
- ret = php_http_env_set_response_header_va(0, 0, fmt, args TSRMLS_CC);
+ ret = php_http_env_set_response_header_va(0, 0, fmt, args);
va_end(args);
return ret;
}
static ZEND_RESULT_CODE php_http_env_response_sapi_del_header(php_http_env_response_t *r, const char *header_str, size_t header_len)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
-
- return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1 TSRMLS_CC);
+ return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1);
}
static ZEND_RESULT_CODE php_http_env_response_sapi_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
-
if (0 < PHPWRITE(data_str, data_len)) {
return SUCCESS;
}
}
static ZEND_RESULT_CODE php_http_env_response_sapi_flush(php_http_env_response_t *r)
{
- TSRMLS_FETCH_FROM_CTX(r->ts);
-
-#if PHP_VERSION_ID >= 50400
- if (php_output_get_level(TSRMLS_C)) {
- php_output_flush_all(TSRMLS_C);
+ if (php_output_get_level()) {
+ php_output_flush_all();
}
- if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) {
- sapi_flush(TSRMLS_C);
+ if (!(php_output_get_status() & PHP_OUTPUT_IMPLICITFLUSH)) {
+ sapi_flush();
}
-#else
- php_end_ob_buffer(1, 1 TSRMLS_CC);
- sapi_flush(TSRMLS_C);
-#endif
return SUCCESS;
}
{
php_http_env_response_stream_ctx_t *ctx;
size_t buffer_size = 0x1000;
- TSRMLS_FETCH_FROM_CTX(r->ts);
ctx = ecalloc(1, sizeof(*ctx));
ctx->stream = init_arg;
- if (!ctx->stream || SUCCESS != zend_list_addref(ctx->stream->rsrc_id)) {
- efree(ctx);
- return FAILURE;
- }
+ ++GC_REFCOUNT(ctx->stream->res);
+ ZEND_INIT_SYMTABLE(&ctx->header);
+ php_http_version_init(&ctx->version, 1, 1);
php_stream_set_option(ctx->stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buffer_size);
- zend_hash_init(&ctx->header, 0, NULL, ZVAL_PTR_DTOR, 0);
- php_http_version_init(&ctx->version, 1, 1 TSRMLS_CC);
ctx->status_code = 200;
ctx->chunked = 1;
- ctx->request = get_request(r->options TSRMLS_CC);
+ ctx->request = get_request(&r->options);
/* there are some limitations regarding TE:chunked, see https://tools.ietf.org/html/rfc7230#section-3.3.1 */
if (ctx->request && ctx->request->http.version.major == 1 && ctx->request->http.version.minor == 0) {
static void php_http_env_response_stream_dtor(php_http_env_response_t *r)
{
php_http_env_response_stream_ctx_t *ctx = r->ctx;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (ctx->chunked_filter) {
- ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1 TSRMLS_CC);
+ ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1);
}
zend_hash_destroy(&ctx->header);
- zend_list_delete(ctx->stream->rsrc_id);
+ zend_list_delete(ctx->stream->res);
efree(ctx);
r->ctx = NULL;
}
-static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header, php_http_buffer_t *buf TSRMLS_DC)
+static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t *ctx, HashTable *header, php_http_buffer_t *buf)
{
- HashPosition pos;
- zval **val;
+ zval *val;
- FOREACH_HASH_VAL(pos, header, val) {
- if (Z_TYPE_PP(val) == IS_ARRAY) {
- php_http_env_response_stream_header(ctx, Z_ARRVAL_PP(val), buf TSRMLS_CC);
+ ZEND_HASH_FOREACH_VAL(header, val)
+ {
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ php_http_env_response_stream_header(ctx, Z_ARRVAL_P(val), buf);
} else {
- zval *tmp = php_http_ztyp(IS_STRING, *val);
+ zend_string *zs = zval_get_string(val);
if (ctx->chunked) {
/* disable chunked transfer encoding if we've got an explicit content-length */
- if (!strncasecmp(Z_STRVAL_P(tmp), "Content-Length:", lenof("Content-Length:"))) {
+ if (!strncasecmp(zs->val, "Content-Length:", lenof("Content-Length:"))) {
ctx->chunked = 0;
}
}
- php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ php_http_buffer_append(buf, zs->val, zs->len);
php_http_buffer_appends(buf, PHP_HTTP_CRLF);
- zval_ptr_dtor(&tmp);
+ zend_string_release(zs);
}
}
+ ZEND_HASH_FOREACH_END();
}
-static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx TSRMLS_DC)
+static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx)
{
php_http_buffer_t header_buf;
ctx->chunked = 0;
}
- php_http_env_response_stream_header(ctx, &ctx->header, &header_buf TSRMLS_CC);
+ php_http_env_response_stream_header(ctx, &ctx->header, &header_buf);
/* enable chunked transfer encoding */
if (ctx->chunked) {
php_http_buffer_appends(&header_buf, "Transfer-Encoding: chunked" PHP_HTTP_CRLF);
}
+
php_http_buffer_appends(&header_buf, PHP_HTTP_CRLF);
if (header_buf.used == php_stream_write(ctx->stream, header_buf.data, header_buf.used)) {
php_stream_flush(ctx->stream);
if (ctx->chunked) {
- ctx->chunked_filter = php_stream_filter_create("http.chunked_encode", NULL, 0 TSRMLS_CC);
+ ctx->chunked_filter = php_stream_filter_create("http.chunked_encode", NULL, 0);
php_stream_filter_append(&ctx->stream->writefilters, ctx->chunked_filter);
}
php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
char *header_end, *header_str = NULL;
size_t header_len = 0;
- zval *zheader, **zheader_ptr;
+ zval zheader, *zheader_ptr;
+ zend_string *header_key;
+ ZEND_RESULT_CODE rv;
if (stream_ctx->started || stream_ctx->finished) {
return FAILURE;
return FAILURE;
}
- *header_end = '\0';
+ header_key = zend_string_init(header_str, header_end - header_str, 0);
- if (!replace && (SUCCESS == zend_hash_find(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader_ptr))) {
- convert_to_array(*zheader_ptr);
- *header_end = ':';
- return add_next_index_stringl(*zheader_ptr, header_str, header_len, 0);
+ if (!replace && (zheader_ptr = zend_hash_find(&stream_ctx->header, header_key))) {
+ convert_to_array(zheader_ptr);
+ rv = add_next_index_str(zheader_ptr, php_http_cs2zs(header_str, header_len));
} else {
- MAKE_STD_ZVAL(zheader);
- ZVAL_STRINGL(zheader, header_str, header_len, 0);
+ ZVAL_STR(&zheader, php_http_cs2zs(header_str, header_len));
- if (SUCCESS != zend_hash_update(&stream_ctx->header, header_str, header_end - header_str + 1, (void *) &zheader, sizeof(zval *), NULL)) {
- zval_ptr_dtor(&zheader);
- return FAILURE;
- }
-
- *header_end = ':';
- return SUCCESS;
+ rv = zend_hash_update(&stream_ctx->header, header_key, &zheader)
+ ? SUCCESS : FAILURE;
}
+
+ zend_string_release(header_key);
+
+ return rv;
}
static ZEND_RESULT_CODE php_http_env_response_stream_set_header(php_http_env_response_t *r, const char *fmt, ...)
{
return FAILURE;
}
- zend_hash_del(&stream_ctx->header, header_str, header_len + 1);
+ zend_hash_str_del(&stream_ctx->header, header_str, header_len);
return SUCCESS;
}
static ZEND_RESULT_CODE php_http_env_response_stream_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
{
php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (stream_ctx->finished) {
return FAILURE;
}
if (!stream_ctx->started) {
- if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
return FAILURE;
}
}
static ZEND_RESULT_CODE php_http_env_response_stream_flush(php_http_env_response_t *r)
{
php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (stream_ctx->finished) {
return FAILURE;
}
if (!stream_ctx->started) {
- if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
return FAILURE;
}
}
static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_response_t *r)
{
php_http_env_response_stream_ctx_t *ctx = r->ctx;
- TSRMLS_FETCH_FROM_CTX(r->ts);
if (ctx->finished) {
return FAILURE;
}
if (!ctx->started) {
- if (SUCCESS != php_http_env_response_stream_start(ctx TSRMLS_CC)) {
+ if (SUCCESS != php_http_env_response_stream_start(ctx)) {
return FAILURE;
}
}
php_stream_flush(ctx->stream);
if (ctx->chunked && ctx->chunked_filter) {
php_stream_filter_flush(ctx->chunked_filter, 1);
- ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1 TSRMLS_CC);
+ ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1);
}
ctx->finished = 1;
#define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \
do { \
if (!obj->message) { \
- obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE TSRMLS_CC); \
+ obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE); \
} \
} while (0)
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
- php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return);
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE), unexpected_val, return);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1)
static PHP_METHOD(HttpEnvResponse, __invoke)
{
char *ob_str;
- int ob_len;
- long ob_flags = 0;
+ size_t ob_len;
+ zend_long ob_flags = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ob_str, &ob_len, &ob_flags)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &ob_str, &ob_len, &ob_flags)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
if (!obj->body) {
php_http_message_object_init_body_object(obj);
}
- php_http_message_body_append(obj->message->body, ob_str, ob_len);
-#if PHP_VERSION_ID >= 50400
+
if (ob_flags & PHP_OUTPUT_HANDLER_CLEAN) {
php_stream_truncate_set_size(php_http_message_body_stream(obj->message->body), 0);
+ } else {
+ php_http_message_body_append(obj->message->body, ob_str, ob_len);
}
RETURN_TRUE;
-#else
- RETURN_EMPTY_STRING();
-#endif
}
}
{
zval *env_req = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_get_class_entry()), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpEnvResponse, setContentType)
{
char *ct_str = NULL;
- int ct_len = 0;
+ size_t ct_len = 0;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &ct_str, &ct_len), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len);
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *zdisposition;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zdisposition), invalid_arg, return);
- zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
+ zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvResponse, setContentEncoding)
{
- long ce;
+ zend_long ce;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ce), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpEnvResponse, setCacheControl)
{
char *cc_str = NULL;
- int cc_len = 0;
+ size_t cc_len = 0;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &cc_str, &cc_len), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvResponse, setLastModified)
{
- long last_modified;
+ zend_long last_modified;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &last_modified), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpEnvResponse, isCachedByLastModified)
{
char *header_name_str = NULL;
- int header_name_len = 0;
+ size_t header_name_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
if (!header_name_str || !header_name_len) {
header_name_str = "If-Modified-Since";
header_name_len = lenof("If-Modified-Since");
}
- RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
+ RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis())));
}
}
static PHP_METHOD(HttpEnvResponse, setEtag)
{
char *etag_str = NULL;
- int etag_len = 0;
+ size_t etag_len = 0;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &etag_str, &etag_len), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpEnvResponse, isCachedByEtag)
{
char *header_name_str = NULL;
- int header_name_len = 0;
+ size_t header_name_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) {
if (!header_name_str || !header_name_len) {
header_name_str = "If-None-Match";
header_name_len = lenof("If-None-Match");
}
- RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
+ RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis())));
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvResponse, setThrottleRate)
{
- long chunk_size;
+ zend_long chunk_size;
double delay = 1;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|d", &chunk_size, &delay), invalid_arg, return);
- set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
- set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0);
+ set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvResponse, setCookie)
{
- zval *zcookie_new;
+ zval *zcookie_new, tmp;
+ zend_string *zs;
zend_error_handling zeh;
php_http_cookie_list_t *list = NULL;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcookie_new), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcookie_new), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh);
switch (Z_TYPE_P(zcookie_new)) {
case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_class_entry TSRMLS_CC)) {
+ if (instanceof_function(Z_OBJCE_P(zcookie_new), php_http_cookie_get_class_entry())) {
Z_ADDREF_P(zcookie_new);
break;
}
/* no break */
case IS_ARRAY:
- list = php_http_cookie_list_from_struct(NULL, zcookie_new TSRMLS_CC);
- MAKE_STD_ZVAL(zcookie_new);
- ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
+ list = php_http_cookie_list_from_struct(NULL, zcookie_new);
+ zcookie_new = &tmp;
+ ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0);
break;
default:
- zcookie_new = php_http_ztyp(IS_STRING, zcookie_new);
- list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(zcookie_new), Z_STRLEN_P(zcookie_new), 0, NULL TSRMLS_CC);
- zval_ptr_dtor(&zcookie_new);
- MAKE_STD_ZVAL(zcookie_new);
- ZVAL_OBJVAL(zcookie_new, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0);
+ zs = zval_get_string(zcookie_new);
+ list = php_http_cookie_list_parse(NULL, zs->val, zs->len, 0, NULL);
+ zend_string_release(zs);
+ zcookie_new = &tmp;
+ ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list)->zo, 0);
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
- set_cookie(getThis(), zcookie_new TSRMLS_CC);
- zval_ptr_dtor(&zcookie_new);
+ set_cookie(getThis(), zcookie_new);
+ zval_ptr_dtor(zcookie_new);
RETVAL_ZVAL(getThis(), 1, 0);
}
zval *zstream = NULL;
php_stream *s = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &zstream)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &zstream)) {
/* first flush the output layer to avoid conflicting headers and output;
* also, ob_start($thisEnvResponse) might have been called */
-#if PHP_VERSION_ID >= 50400
- php_output_end_all(TSRMLS_C);
-#else
- php_end_ob_buffers(1 TSRMLS_CC);
-#endif
+ php_output_end_all();
if (zstream) {
php_http_env_response_t *r;
- php_stream_from_zval(s, &zstream);
- r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC);
+ php_stream_from_zval(s, zstream);
+ r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s);
if (!r) {
RETURN_FALSE;
}
} else {
php_http_env_response_t r;
- if (!php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) {
+ if (!php_http_env_response_init(&r, getThis(), NULL, NULL)) {
RETURN_FALSE;
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_env_response_class_entry;
+static zend_class_entry *php_http_env_response_class_entry;
+zend_class_entry *php_http_get_env_response_class_entry(void)
+{
+ return php_http_env_response_class_entry;
+}
PHP_MINIT_FUNCTION(http_env_response)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods);
- php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO TSRMLS_CC);
- zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS TSRMLS_CC);
-
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED TSRMLS_CC);
- zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_get_class_entry());
+
+ zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE);
+ zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP);
+
+ zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO);
+ zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT);
+ zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS);
+
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("request"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED);
+ zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED);
return SUCCESS;
}
php_http_cookie_list_t *cookies;
php_http_buffer_t *buffer;
- zval *options;
+ zval options;
struct {
size_t chunk;
} content;
zend_bool done;
-
-#ifdef ZTS
- void ***ts;
-#endif
};
-PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *ops_ctx TSRMLS_DC);
+PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *ops_ctx);
PHP_HTTP_API ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r);
PHP_HTTP_API void php_http_env_response_dtor(php_http_env_response_t *r);
PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r);
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC);
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC);
+PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request);
+PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request);
-PHP_HTTP_API zend_class_entry *php_http_env_response_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_env_response_class_entry();
PHP_MINIT_FUNCTION(http_env_response);
#endif
#include <ext/standard/sha1.h>
#include <ext/standard/md5.h>
-php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC)
+php_http_etag_t *php_http_etag_init(const char *mode)
{
void *ctx;
php_http_etag_t *e;
e = emalloc(sizeof(*e));
e->ctx = ctx;
e->mode = estrdup(mode);
- TSRMLS_SET_CTX(e->ts);
return e;
}
typedef struct php_http_etag {
void *ctx;
char *mode;
-
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_etag_t;
-PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC);
+PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode);
PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len);
PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e);
#endif
#if PHP_HTTP_DBG_EXCEPTIONS
-static void php_http_exception_hook(zval *ex TSRMLS_DC)
+static void php_http_exception_hook(zval *ex)
{
if (ex) {
- zval *m = zend_read_property(Z_OBJCE_P(ex), ex, "message", lenof("message"), 0 TSRMLS_CC);
+ zval *m = zend_read_property(Z_OBJCE_P(ex), ex, "message", lenof("message"), 0);
fprintf(stderr, "*** Threw exception '%s'\n", Z_STRVAL_P(m));
} else {
fprintf(stderr, "*** Threw NULL exception\n");
}
#endif
-zend_class_entry *php_http_exception_interface_class_entry;
-zend_class_entry *php_http_exception_runtime_class_entry;
-zend_class_entry *php_http_exception_unexpected_val_class_entry;
-zend_class_entry *php_http_exception_bad_method_call_class_entry;
-zend_class_entry *php_http_exception_invalid_arg_class_entry;
-zend_class_entry *php_http_exception_bad_header_class_entry;
-zend_class_entry *php_http_exception_bad_url_class_entry;
-zend_class_entry *php_http_exception_bad_message_class_entry;
-zend_class_entry *php_http_exception_bad_conversion_class_entry;
-zend_class_entry *php_http_exception_bad_querystring_class_entry;
+static zend_class_entry *php_http_exception_interface_class_entry;
+zend_class_entry *php_http_get_exception_interface_class_entry(void)
+{
+ return php_http_exception_interface_class_entry;
+}
+static zend_class_entry *php_http_exception_runtime_class_entry;
+zend_class_entry *php_http_get_exception_runtime_class_entry(void)
+{
+ return php_http_exception_runtime_class_entry;
+}
+static zend_class_entry *php_http_exception_unexpected_val_class_entry;
+zend_class_entry *php_http_get_exception_unexpected_val_class_entry(void)
+{
+ return php_http_exception_unexpected_val_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_method_call_class_entry;
+zend_class_entry *php_http_get_exception_bad_method_call_class_entry(void)
+{
+ return php_http_exception_bad_method_call_class_entry;
+}
+static zend_class_entry *php_http_exception_invalid_arg_class_entry;
+zend_class_entry *php_http_get_exception_invalid_arg_class_entry(void)
+{
+ return php_http_exception_invalid_arg_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_header_class_entry;
+zend_class_entry *php_http_get_exception_bad_header_class_entry(void)
+{
+ return php_http_exception_bad_header_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_url_class_entry;
+zend_class_entry *php_http_get_exception_bad_url_class_entry(void)
+{
+ return php_http_exception_bad_url_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_message_class_entry;
+zend_class_entry *php_http_get_exception_bad_message_class_entry(void)
+{
+ return php_http_exception_bad_message_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_conversion_class_entry;
+zend_class_entry *php_http_get_exception_bad_conversion_class_entry(void)
+{
+ return php_http_exception_bad_conversion_class_entry;
+}
+static zend_class_entry *php_http_exception_bad_querystring_class_entry;
+zend_class_entry *php_http_get_exception_bad_querystring_class_entry(void)
+{
+ return php_http_exception_bad_querystring_class_entry;
+}
PHP_MINIT_FUNCTION(http_exception)
{
zend_class_entry *cep, ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Exception", NULL);
- php_http_exception_interface_class_entry = zend_register_internal_interface(&ce TSRMLS_CC);
+ php_http_exception_interface_class_entry = zend_register_internal_interface(&ce);
/*
* Would be great to only have a few exceptions and rather more identifying
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "RuntimeException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_runtime_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "UnexpectedValueException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_unexpected_val_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMethodCallException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_method_call_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "InvalidArgumentException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_invalid_arg_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadHeaderException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_header_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadUrlException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_url_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMessageException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_message_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadConversionException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_conversion_class_entry = cep;
memset(&ce, 0, sizeof(ce));
INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadQueryStringException", NULL);
- cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
- zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException);
+ zend_class_implements(cep, 1, php_http_exception_interface_class_entry);
php_http_exception_bad_querystring_class_entry = cep;
#if PHP_HTTP_DBG_EXCEPTIONS
/* short hand for zend_throw_exception_ex */
#define php_http_throw(e, fmt, ...) \
- zend_throw_exception_ex(php_http_exception_ ##e## _class_entry, 0 TSRMLS_CC, fmt, __VA_ARGS__)
+ zend_throw_exception_ex(php_http_get_exception_ ##e## _class_entry(), 0, fmt, __VA_ARGS__)
/* wrap a call with replaced zend_error_handling */
#define php_http_expect(test, e, fail) \
do { \
zend_error_handling __zeh; \
- zend_replace_error_handling(EH_THROW, php_http_exception_ ##e## _class_entry, &__zeh TSRMLS_CC); \
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_ ##e## _class_entry(), &__zeh); \
if (!(test)) { \
- zend_restore_error_handling(&__zeh TSRMLS_CC); \
+ zend_restore_error_handling(&__zeh); \
fail; \
} \
- zend_restore_error_handling(&__zeh TSRMLS_CC); \
+ zend_restore_error_handling(&__zeh); \
} while(0)
-PHP_HTTP_API zend_class_entry *php_http_exception_interface_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_runtime_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_unexpected_val_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_method_call_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_invalid_arg_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_header_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_url_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_message_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_conversion_class_entry;
-PHP_HTTP_API zend_class_entry *php_http_exception_bad_querystring_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_exception_interface_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_runtime_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_unexpected_val_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_method_call_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_invalid_arg_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_header_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_url_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_message_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_conversion_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_exception_bad_querystring_class_entry(void);
PHP_MINIT_FUNCTION(http_exception);
PHP_MINIT_FUNCTION(http_filter)
{
- php_stream_filter_register_factory("http.*", &php_http_filter_factory TSRMLS_CC);
+ php_stream_filter_register_factory("http.*", &php_http_filter_factory);
return SUCCESS;
}
php_stream_filter *this, \
php_stream_bucket_brigade *buckets_in, \
php_stream_bucket_brigade *buckets_out, \
- size_t *bytes_consumed, int flags \
- TSRMLS_DC
+ size_t *bytes_consumed, \
+ int flags
#define PHP_HTTP_FILTER_OP(filter) \
http_filter_op_ ##filter
#define PHP_HTTP_FILTER_OPS(filter) \
#define PHP_HTTP_FILTER_DTOR(filter) \
http_filter_ ##filter## _dtor
#define PHP_HTTP_FILTER_DESTRUCTOR(filter) \
- void PHP_HTTP_FILTER_DTOR(filter)(php_stream_filter *this TSRMLS_DC)
+ void PHP_HTTP_FILTER_DTOR(filter)(php_stream_filter *this)
#define PHP_HTTP_FILTER_FUNC(filter) \
http_filter_ ##filter
#define PHP_HTTP_FILTER_FUNCTION(filter) \
} \
memcpy(__data, data, length); \
\
- __buck = php_stream_bucket_new(stream, __data, length, 1, this->is_persistent TSRMLS_CC); \
+ __buck = php_stream_bucket_new(stream, __data, length, 1, this->is_persistent); \
if (!__buck) { \
pefree(__data, this->is_persistent); \
return PSFS_ERR_FATAL; \
} \
\
- php_stream_bucket_append(buckets_out, __buck TSRMLS_CC); \
+ php_stream_bucket_append(buckets_out, __buck); \
}
typedef struct _http_chunked_decode_filter_buffer_t {
{
int out_avail = 0;
php_stream_bucket *ptr, *nxt;
- PHP_HTTP_FILTER_BUFFER(chunked_decode) *buffer = (PHP_HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract);
+ PHP_HTTP_FILTER_BUFFER(chunked_decode) *buffer = Z_PTR(this->abstract);
if (bytes_consumed) {
*bytes_consumed = 0;
}
nxt = ptr->next;
- php_stream_bucket_unlink(ptr TSRMLS_CC);
- php_stream_bucket_delref(ptr TSRMLS_CC);
+ php_stream_bucket_unlink(ptr);
+ php_stream_bucket_delref(ptr);
}
if (!php_http_buffer_fix(PHP_HTTP_BUFFER(buffer))) {
php_http_buffer_cut(PHP_HTTP_BUFFER(buffer), 0, eolstr + eollen - PHP_HTTP_BUFFER(buffer)->data);
/* buffer->hexlen is 0 now or contains the size of the next chunk */
if (!buffer->hexlen) {
- php_stream_notify_info(stream->context, PHP_STREAM_NOTIFY_COMPLETED, NULL, 0);
+ php_stream_notify_info(PHP_STREAM_CONTEXT(stream), PHP_STREAM_NOTIFY_COMPLETED, NULL, 0);
break;
}
/* continue */
static PHP_HTTP_FILTER_DESTRUCTOR(chunked_decode)
{
- PHP_HTTP_FILTER_BUFFER(chunked_decode) *b = (PHP_HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract);
+ PHP_HTTP_FILTER_BUFFER(chunked_decode) *b = Z_PTR(this->abstract);
php_http_buffer_dtor(PHP_HTTP_BUFFER(b));
pefree(b, this->is_persistent);
#endif
nxt = ptr->next;
- php_stream_bucket_unlink(ptr TSRMLS_CC);
+ php_stream_bucket_unlink(ptr);
php_http_buffer_appendf(&buf, "%lx" PHP_HTTP_CRLF, (long unsigned int) ptr->buflen);
php_http_buffer_append(&buf, ptr->buf, ptr->buflen);
php_http_buffer_appends(&buf, PHP_HTTP_CRLF);
NEW_BUCKET(buf.data, buf.used);
/* reset */
php_http_buffer_reset(&buf);
- php_stream_bucket_delref(ptr TSRMLS_CC);
+ php_stream_bucket_delref(ptr);
}
/* free buffer */
static PHP_HTTP_FILTER_FUNCTION(zlib)
{
php_stream_bucket *ptr, *nxt;
- PHP_HTTP_FILTER_BUFFER(zlib) *buffer = (PHP_HTTP_FILTER_BUFFER(zlib) *) this->abstract;
+ PHP_HTTP_FILTER_BUFFER(zlib) *buffer = Z_PTR(this->abstract);
if (bytes_consumed) {
*bytes_consumed = 0;
#endif
nxt = ptr->next;
- php_stream_bucket_unlink(ptr TSRMLS_CC);
+ php_stream_bucket_unlink(ptr);
php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len);
#if DBG_FILTER
}
efree(encoded);
}
- php_stream_bucket_delref(ptr TSRMLS_CC);
+ php_stream_bucket_delref(ptr);
}
/* flush & close */
}
static PHP_HTTP_FILTER_DESTRUCTOR(zlib)
{
- PHP_HTTP_FILTER_BUFFER(zlib) *buffer = (PHP_HTTP_FILTER_BUFFER(zlib) *) this->abstract;
+ PHP_HTTP_FILTER_BUFFER(zlib) *buffer = Z_PTR(this->abstract);
php_http_encoding_stream_free(&buffer);
}
"http.inflate"
};
-static php_stream_filter *http_filter_create(const char *name, zval *params, int p TSRMLS_DC)
+static php_stream_filter *http_filter_create(const char *name, zval *params, int p)
{
- zval **tmp = ¶ms;
+ zval *tmp = params;
php_stream_filter *f = NULL;
int flags = p ? PHP_HTTP_ENCODING_STREAM_PERSISTENT : 0;
if (params) {
switch (Z_TYPE_P(params)) {
- case IS_ARRAY:
- case IS_OBJECT:
- if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) {
- break;
- }
- /* no break */
- default:
- {
- zval *num = php_http_ztyp(IS_LONG, *tmp);
-
- flags |= (Z_LVAL_P(num) & 0x0fffffff);
- zval_ptr_dtor(&num);
-
+ case IS_ARRAY:
+ case IS_OBJECT:
+ if (!(tmp = zend_hash_str_find_ind(HASH_OF(params), ZEND_STRL("flags")))) {
+ break;
}
+ /* no break */
+ default:
+ flags |= zval_get_long(tmp) & 0x0fffffff;
break;
}
}
if (!strcasecmp(name, "http.inflate")) {
PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL;
- if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags TSRMLS_CC))) {
+ if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), flags))) {
if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(inflate), b, p))) {
php_http_encoding_stream_free(&b);
}
if (!strcasecmp(name, "http.deflate")) {
PHP_HTTP_FILTER_BUFFER(zlib) *b = NULL;
- if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags TSRMLS_CC))) {
+ if ((b = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_deflate_ops(), flags))) {
if (!(f = php_stream_filter_alloc(&PHP_HTTP_FILTER_OP(deflate), b, p))) {
php_http_encoding_stream_free(&b);
}
#include "php_http_api.h"
-ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC)
+ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data)
{
php_http_header_parser_t ctx;
php_http_buffer_t buf;
php_http_header_parser_state_t rs;
if (!php_http_buffer_from_string_ex(&buf, header, length)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not allocate buffer");
+ php_error_docref(NULL, E_WARNING, "Could not allocate buffer");
return FAILURE;
}
- if (!php_http_header_parser_init(&ctx TSRMLS_CC)) {
+ if (!php_http_header_parser_init(&ctx)) {
php_http_buffer_dtor(&buf);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize header parser");
+ php_error_docref(NULL, E_WARNING, "Could not initialize header parser");
return FAILURE;
}
return rs == PHP_HTTP_HEADER_PARSER_STATE_FAILURE ? FAILURE : SUCCESS;
}
-void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC)
+void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg)
{
- HashPosition pos1, pos2;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **header, **single_header;
-
- FOREACH_HASH_KEYVAL(pos1, headers, key, header) {
- if (key.type == HASH_KEY_IS_STRING) {
- if (key.len == sizeof("Set-Cookie") && !strcasecmp(key.str, "Set-Cookie") && Z_TYPE_PP(header) == IS_ARRAY) {
- FOREACH_VAL(pos2, *header, single_header) {
- if (Z_TYPE_PP(single_header) == IS_ARRAY) {
- php_http_cookie_list_t *cookie = php_http_cookie_list_from_struct(NULL, *single_header TSRMLS_CC);
+ php_http_arrkey_t key;
+ zval *header, *single_header;
+
+ ZEND_HASH_FOREACH_KEY_VAL(headers, key.h, key.key, header)
+ {
+ if (key.key) {
+ if (zend_string_equals_literal(key.key, "Set-Cookie") && Z_TYPE_P(header) == IS_ARRAY) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(header), single_header)
+ {
+ if (Z_TYPE_P(single_header) == IS_ARRAY) {
+ php_http_cookie_list_t *cookie = php_http_cookie_list_from_struct(NULL, single_header);
if (cookie) {
char *buf;
efree(buf);
}
} else {
- zval *strval = php_http_header_value_to_string(*single_header TSRMLS_CC);
+ zend_string *zs = php_http_header_value_to_string(single_header);
- cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
+ cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", zs->val);
+ zend_string_release(zs);
}
}
+ ZEND_HASH_FOREACH_END();
} else {
- zval *strval = php_http_header_value_to_string(*header TSRMLS_CC);
+ zend_string *zs = php_http_header_value_to_string(header);
- cb(cb_arg, crlf ? "%s: %s" PHP_HTTP_CRLF : "%s: %s", key.str, Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
+ cb(cb_arg, crlf ? "%s: %s" PHP_HTTP_CRLF : "%s: %s", key.key->val, zs->val);
+ zend_string_release(zs);
}
}
}
+ ZEND_HASH_FOREACH_END();
}
-void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC)
+void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers)
{
- php_http_header_to_callback(headers, 1, (php_http_pass_format_callback_t) php_http_buffer_appendf, str TSRMLS_CC);
+ php_http_header_to_callback(headers, 1, (php_http_pass_format_callback_t) php_http_buffer_appendf, str);
}
-zval *php_http_header_value_to_string(zval *header TSRMLS_DC)
+zend_string *php_http_header_value_array_to_string(zval *header)
{
- zval *ret;
-
- if (Z_TYPE_P(header) == IS_BOOL) {
- MAKE_STD_ZVAL(ret);
- ZVAL_STRING(ret, Z_BVAL_P(header) ? "true" : "false", 1);
- } else if (Z_TYPE_P(header) == IS_ARRAY) {
- zval **val;
- HashPosition pos;
- php_http_buffer_t str;
-
- php_http_buffer_init(&str);
- MAKE_STD_ZVAL(ret);
- FOREACH_VAL(pos,header, val) {
- zval *strval = php_http_header_value_to_string(*val TSRMLS_CC);
-
- php_http_buffer_appendf(&str, str.used ? ", %s":"%s", Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
- }
- php_http_buffer_fix(&str);
- ZVAL_STRINGL(ret, str.data, str.used, 0);
- } else {
- ret = php_http_zsep(1, IS_STRING, header);
+ zval *val;
+ php_http_buffer_t str;
+
+ php_http_buffer_init(&str);
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(header), val)
+ {
+ zend_string *zs = php_http_header_value_to_string(val);
+
+ php_http_buffer_appendf(&str, str.used ? ", %s":"%s", zs->val);
+ zend_string_release(zs);
}
+ ZEND_HASH_FOREACH_END();
+ php_http_buffer_fix(&str);
- return ret;
+ return php_http_cs2zs(str.data, str.used);
+}
+
+zend_string *php_http_header_value_to_string(zval *header)
+{
+ switch (Z_TYPE_P(header)) {
+ case IS_TRUE:
+ return zend_string_init(ZEND_STRL("true"), 0);
+ case IS_FALSE:
+ return zend_string_init(ZEND_STRL("false"), 0);
+ case IS_ARRAY:
+ return php_http_header_value_array_to_string(header);
+ default:
+ return zval_get_string(header);
+ }
+}
+
+static zend_class_entry *php_http_header_class_entry;
+zend_class_entry *php_http_header_get_class_entry(void)
+{
+ return php_http_header_class_entry;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader___construct, 0, 0, 0)
PHP_METHOD(HttpHeader, __construct)
{
char *name_str = NULL, *value_str = NULL;
- int name_len = 0, value_len = 0;
+ size_t name_len = 0, value_len = 0;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
if (name_str && name_len) {
char *pretty_str = estrndup(name_str, name_len);
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len TSRMLS_CC);
+ zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len);
efree(pretty_str);
}
if (value_str && value_len) {
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("value"), value_str, value_len TSRMLS_CC);
+ zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("value"), value_str, value_len);
}
}
{
if (SUCCESS == zend_parse_parameters_none()) {
php_http_buffer_t buf;
- zval *zname, *zvalue;
+ zend_string *zs;
+ zval name_tmp, value_tmp;
php_http_buffer_init(&buf);
- zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
- php_http_buffer_append(&buf, Z_STRVAL_P(zname), Z_STRLEN_P(zname));
- zval_ptr_dtor(&zname);
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- if (Z_STRLEN_P(zvalue)) {
+ zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0, &name_tmp));
+ php_http_buffer_appendz(&buf, zs);
+ zend_string_release(zs);
+
+ zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp));
+ if (zs->len) {
php_http_buffer_appends(&buf, ": ");
- php_http_buffer_append(&buf, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue));
+ php_http_buffer_appendz(&buf, zs);
} else {
php_http_buffer_appends(&buf, ":");
}
- zval_ptr_dtor(&zvalue);
+ zend_string_release(zs);
- RETURN_PHP_HTTP_BUFFER_VAL(&buf);
+ RETURN_STR(php_http_cs2zs(buf.data, buf.used));
}
RETURN_EMPTY_STRING();
}
PHP_METHOD(HttpHeader, unserialize)
{
char *serialized_str;
- int serialized_len;
+ size_t serialized_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized_str, &serialized_len)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized_str, &serialized_len)) {
HashTable ht;
zend_hash_init(&ht, 1, NULL, ZVAL_PTR_DTOR, 0);
- if (SUCCESS == php_http_header_parse(serialized_str, serialized_len, &ht, NULL, NULL TSRMLS_CC)) {
+ if (SUCCESS == php_http_header_parse(serialized_str, serialized_len, &ht, NULL, NULL)) {
if (zend_hash_num_elements(&ht)) {
- zval **val, *cpy;
- char *str;
- uint len;
- ulong idx;
+ zend_string *zs, *key;
+ zend_ulong idx;
zend_hash_internal_pointer_reset(&ht);
- switch (zend_hash_get_current_key_ex(&ht, &str, &len, &idx, 0, NULL)) {
+ switch (zend_hash_get_current_key(&ht, &key, &idx)) {
case HASH_KEY_IS_STRING:
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), str, len - 1 TSRMLS_CC);
+ zend_update_property_str(php_http_header_class_entry, getThis(), ZEND_STRL("name"), key);
break;
case HASH_KEY_IS_LONG:
- zend_update_property_long(php_http_header_class_entry, getThis(), ZEND_STRL("name"), idx TSRMLS_CC);
+ zend_update_property_long(php_http_header_class_entry, getThis(), ZEND_STRL("name"), idx);
break;
default:
break;
}
- zend_hash_get_current_data(&ht, (void *) &val);
- cpy = php_http_zsep(1, IS_STRING, *val);
- zend_update_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), cpy TSRMLS_CC);
- zval_ptr_dtor(&cpy);
+ zs = zval_get_string(zend_hash_get_current_data(&ht));
+ zend_update_property_str(php_http_header_class_entry, getThis(), ZEND_STRL("value"), zs);
+ zend_string_release(zs);
}
}
zend_hash_destroy(&ht);
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, match)
{
- char *val_str;
- int val_len;
- long flags = PHP_HTTP_MATCH_LOOSE;
- zval *zvalue;
+ char *val_str = NULL;
+ size_t val_len = 0;
+ zend_long flags = PHP_HTTP_MATCH_LOOSE;
+ zend_string *zs;
+ zval value_tmp;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &val_str, &val_len, &flags)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &val_str, &val_len, &flags)) {
return;
}
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- RETVAL_BOOL(php_http_match(Z_STRVAL_P(zvalue), val_str, flags));
- zval_ptr_dtor(&zvalue);
+ zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp));
+ RETVAL_BOOL(php_http_match(zs->val, val_str, flags));
+ zend_string_release(zs);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_negotiate, 0, 0, 1)
PHP_METHOD(HttpHeader, negotiate)
{
HashTable *supported, *rs;
- zval *zname, *zvalue, *rs_array = NULL;
+ zval name_tmp, value_tmp, *rs_array = NULL;
+ zend_string *zs;
char *sep_str = NULL;
size_t sep_len = 0;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "H|z", &supported, &rs_array)) {
return;
}
if (rs_array) {
+ ZVAL_DEREF(rs_array);
zval_dtor(rs_array);
array_init(rs_array);
}
- zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
- if (!strcasecmp(Z_STRVAL_P(zname), "Accept")) {
+ zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0, &name_tmp));
+ if (zend_string_equals_literal(zs, "Accept")) {
sep_str = "/";
sep_len = 1;
- } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
+ } else if (zend_string_equals_literal(zs, "Accept-Language")) {
sep_str = "-";
sep_len = 1;
}
- zval_ptr_dtor(&zname);
+ zend_string_release(zs);
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- if ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
+ zs = zval_get_string(zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp));
+ if ((rs = php_http_negotiate(zs->val, zs->len, supported, sep_str, sep_len))) {
PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
} else {
PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
}
- zval_ptr_dtor(&zvalue);
+ zend_string_release(zs);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_getParams, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, getParams)
{
- zval zctor, *zparams_obj, **zargs = NULL;
+ zval value_tmp, zctor, zparams_obj, *zargs = NULL;
- INIT_PZVAL(&zctor);
- ZVAL_STRINGL(&zctor, "__construct", lenof("__construct"), 0);
+ ZVAL_STRINGL(&zctor, "__construct", lenof("__construct"));
- MAKE_STD_ZVAL(zparams_obj);
- object_init_ex(zparams_obj, php_http_params_class_entry);
+ object_init_ex(&zparams_obj, php_http_params_get_class_entry());
- zargs = (zval **) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval *));
- zargs[0] = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("value"), 0 TSRMLS_CC);
+ zargs = (zval *) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval));
+ ZVAL_COPY_VALUE(&zargs[0], zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0, &value_tmp));
if (ZEND_NUM_ARGS()) {
zend_get_parameters_array(ZEND_NUM_ARGS(), ZEND_NUM_ARGS(), &zargs[1]);
}
- if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs TSRMLS_CC)) {
- RETVAL_ZVAL(zparams_obj, 0, 1);
+ if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs)) {
+ RETVAL_ZVAL(&zparams_obj, 0, 1);
}
+ zval_ptr_dtor(&zctor);
if (zargs) {
efree(zargs);
}
PHP_METHOD(HttpHeader, parse)
{
char *header_str;
- int header_len;
+ size_t header_len;
zend_class_entry *ce = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C", &header_str, &header_len, &ce)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|C", &header_str, &header_len, &ce)) {
array_init(return_value);
- if (SUCCESS != php_http_header_parse(header_str, header_len, Z_ARRVAL_P(return_value), NULL, NULL TSRMLS_CC)) {
+ if (SUCCESS != php_http_header_parse(header_str, header_len, Z_ARRVAL_P(return_value), NULL, NULL)) {
zval_dtor(return_value);
RETURN_FALSE;
} else {
- if (ce && instanceof_function(ce, php_http_header_class_entry TSRMLS_CC)) {
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **val;
-
- FOREACH_KEYVAL(pos, return_value, key, val) {
- zval *zho, *zkey, *zvalue;
+ if (ce && instanceof_function(ce, php_http_header_class_entry)) {
+ php_http_arrkey_t key;
+ zval *val;
- Z_ADDREF_PP(val);
- zvalue = *val;
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(return_value), key.h, key.key, val)
+ {
+ zval zkey, zho;
- MAKE_STD_ZVAL(zkey);
- if (key.type == HASH_KEY_IS_LONG) {
- ZVAL_LONG(zkey, key.num);
+ if (key.key) {
+ ZVAL_STR_COPY(&zkey, key.key);
} else {
- ZVAL_STRINGL(zkey, key.str, key.len - 1, 1);
+ ZVAL_LONG(&zkey, key.h);
}
- MAKE_STD_ZVAL(zho);
- object_init_ex(zho, ce);
- zend_call_method_with_2_params(&zho, ce, NULL, "__construct", NULL, zkey, zvalue);
+ object_init_ex(&zho, ce);
+ Z_TRY_ADDREF_P(val);
+ zend_call_method_with_2_params(&zho, ce, NULL, "__construct", NULL, &zkey, val);
+ zval_ptr_dtor(val);
+ zval_ptr_dtor(&zkey);
- if (key.type == HASH_KEY_IS_LONG) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), key.num, (void *) &zho, sizeof(zval *), NULL);
+ if (key.key) {
+ add_assoc_zval_ex(return_value, key.key->val, key.key->len, &zho);
} else {
- zend_hash_update(Z_ARRVAL_P(return_value), key.str, key.len, (void *) &zho, sizeof(zval *), NULL);
+ add_index_zval(return_value, key.h, &zho);
}
-
- zval_ptr_dtor(&zvalue);
- zval_ptr_dtor(&zkey);
}
+ ZEND_HASH_FOREACH_END();
}
}
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_header_class_entry;
-
PHP_MINIT_FUNCTION(http_header)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Header", php_http_header_methods);
- php_http_header_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
- zend_class_implements(php_http_header_class_entry TSRMLS_CC, 1, zend_ce_serializable);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_LOOSE"), PHP_HTTP_MATCH_LOOSE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_CASE"), PHP_HTTP_MATCH_CASE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_WORD"), PHP_HTTP_MATCH_WORD TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_FULL"), PHP_HTTP_MATCH_FULL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_STRICT"), PHP_HTTP_MATCH_STRICT TSRMLS_CC);
- zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("value"), ZEND_ACC_PUBLIC TSRMLS_CC);
+ php_http_header_class_entry = zend_register_internal_class(&ce);
+ zend_class_implements(php_http_header_class_entry, 1, zend_ce_serializable);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_LOOSE"), PHP_HTTP_MATCH_LOOSE);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_CASE"), PHP_HTTP_MATCH_CASE);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_WORD"), PHP_HTTP_MATCH_WORD);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_FULL"), PHP_HTTP_MATCH_FULL);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_STRICT"), PHP_HTTP_MATCH_STRICT);
+ zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("value"), ZEND_ACC_PUBLIC);
return SUCCESS;
}
#include "php_http_info.h"
-PHP_HTTP_API ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data);
-PHP_HTTP_API void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC);
-PHP_HTTP_API void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC);
+PHP_HTTP_API void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg);
+PHP_HTTP_API void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers);
-PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC);
+PHP_HTTP_API zend_string *php_http_header_value_to_string(zval *header);
+PHP_HTTP_API zend_string *php_http_header_value_array_to_string(zval *header);
-PHP_HTTP_API zend_class_entry *php_http_header_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_header_get_class_entry(void);
PHP_MINIT_FUNCTION(http_header);
#endif
{PHP_HTTP_HEADER_PARSER_STATE_DONE, 0}
};
-php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC)
+php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser)
{
if (!parser) {
parser = emalloc(sizeof(*parser));
}
memset(parser, 0, sizeof(*parser));
- TSRMLS_SET_CTX(parser->ts);
-
return parser;
}
}
/* NOTE: 'str' has to be null terminated */
-static void php_http_header_parser_error(size_t valid_len, char *str, size_t len, const char *eol_str TSRMLS_DC)
+static void php_http_header_parser_error(size_t valid_len, char *str, size_t len, const char *eol_str )
{
- int escaped_len;
- char *escaped_str;
+ zend_string *escaped_str = zend_string_init(str, len, 0);
- escaped_str = php_addcslashes(str, len, &escaped_len, 0, ZEND_STRL("\x0..\x1F\x7F..\xFF") TSRMLS_CC);
+ escaped_str = php_addcslashes(escaped_str, 1, ZEND_STRL("\x0..\x1F\x7F..\xFF"));
if (valid_len != len && (!eol_str || (str+valid_len) != eol_str)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse headers: unexpected character '\\%03o' at pos %zu of '%.*s'", str[valid_len], valid_len, escaped_len, escaped_str);
+ php_error_docref(NULL, E_WARNING, "Failed to parse headers: unexpected character '\\%03o' at pos %zu of '%s'", str[valid_len], valid_len, escaped_str->val);
} else if (eol_str) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse headers: unexpected end of line at pos %zu of '%.*s'", eol_str - str, escaped_len, escaped_str);
+ php_error_docref(NULL, E_WARNING, "Failed to parse headers: unexpected end of line at pos %zu of '%s'", eol_str - str, escaped_str->val);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse headers: unexpected end of input at pos %zu of '%.*s'", len, escaped_len, escaped_str);
+ php_error_docref(NULL, E_WARNING, "Failed to parse headers: unexpected end of input at pos %zu of '%s'", len, escaped_str->val);
}
efree(escaped_str);
php_http_header_parser_state_t php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg)
{
- TSRMLS_FETCH_FROM_CTX(parser->ts);
-
while (buffer->used || !php_http_header_parser_states[php_http_header_parser_state_is(parser)].need_data) {
#if DBG_PARSER
const char *state[] = {"START", "KEY", "VALUE", "VALUE_EX", "HEADER_DONE", "DONE"};
#endif
switch (php_http_header_parser_state_pop(parser)) {
case PHP_HTTP_HEADER_PARSER_STATE_FAILURE:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse headers");
+ php_error_docref(NULL, E_WARNING, "Failed to parse headers");
return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE);
case PHP_HTTP_HEADER_PARSER_STATE_START: {
/* end of headers */
php_http_buffer_cut(buffer, 0, eol_len);
php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_DONE);
- } else if (php_http_info_parse(&parser->info, buffer->data TSRMLS_CC)) {
+ } else if (php_http_info_parse(&parser->info, buffer->data)) {
/* new message starting with request/response line */
if (callback_func) {
- callback_func(callback_arg, &headers, &parser->info TSRMLS_CC);
+ callback_func(callback_arg, &headers, &parser->info);
}
php_http_info_dtor(&parser->info);
php_http_buffer_cut(buffer, 0, eol_str + eol_len - buffer->data);
valid_len = strspn(parser->_key.str, PHP_HTTP_HEADER_NAME_CHARS);
if (valid_len != parser->_key.len) {
- php_http_header_parser_error(valid_len, parser->_key.str, parser->_key.len, eol_str TSRMLS_CC);
+ php_http_header_parser_error(valid_len, parser->_key.str, parser->_key.len, eol_str);
PTR_SET(parser->_key.str, NULL);
return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE);
}
php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_VALUE);
} else if (eol_str || (flags & PHP_HTTP_HEADER_PARSER_CLEANUP)) {
/* neither reqeust/response line nor 'header:' string, or injected new line or NUL etc. */
- php_http_header_parser_error(strspn(buffer->data, PHP_HTTP_HEADER_NAME_CHARS), buffer->data, buffer->used, eol_str TSRMLS_CC);
+ php_http_header_parser_error(strspn(buffer->data, PHP_HTTP_HEADER_NAME_CHARS), buffer->data, buffer->used, eol_str);
return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE);
} else {
/* keep feeding */
case PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE:
if (parser->_key.str && parser->_val.str) {
- zval array, **exist;
+ zval tmp, *exist;
size_t valid_len = strlen(parser->_val.str);
/* check for truncation */
if (valid_len != parser->_val.len) {
- php_http_header_parser_error(valid_len, parser->_val.str, parser->_val.len, NULL TSRMLS_CC);
+ php_http_header_parser_error(valid_len, parser->_val.str, parser->_val.len, NULL);
PTR_SET(parser->_key.str, NULL);
PTR_SET(parser->_val.str, NULL);
}
if (!headers && callback_func) {
- callback_func(callback_arg, &headers, NULL TSRMLS_CC);
+ callback_func(callback_arg, &headers, NULL);
}
- INIT_PZVAL_ARRAY(&array, headers);
php_http_pretty_key(parser->_key.str, parser->_key.len, 1, 1);
- if (SUCCESS == zend_symtable_find(headers, parser->_key.str, parser->_key.len + 1, (void *) &exist)) {
- convert_to_array(*exist);
- add_next_index_stringl(*exist, parser->_val.str, parser->_val.len, 0);
+ if ((exist = zend_symtable_str_find(headers, parser->_key.str, parser->_key.len))) {
+ convert_to_array(exist);
+ add_next_index_str(exist, php_http_cs2zs(parser->_val.str, parser->_val.len));
} else {
- add_assoc_stringl_ex(&array, parser->_key.str, parser->_key.len + 1, parser->_val.str, parser->_val.len, 0);
+ ZVAL_STR(&tmp, php_http_cs2zs(parser->_val.str, parser->_val.len));
+ zend_symtable_str_update(headers, parser->_key.str, parser->_key.len, &tmp);
}
parser->_val.str = NULL;
}
php_http_header_parser_state_t php_http_header_parser_parse_stream(php_http_header_parser_t *parser, php_http_buffer_t *buf, php_stream *s, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg)
{
php_http_header_parser_state_t state = PHP_HTTP_HEADER_PARSER_STATE_START;
- TSRMLS_FETCH_FROM_CTX(parser->ts);
if (!buf->data) {
php_http_buffer_resize_ex(buf, 0x1000, 1, 0);
return PHP_HTTP_HEADER_PARSER_STATE_DONE;
}
-zend_class_entry *php_http_header_parser_class_entry;
+static zend_class_entry *php_http_header_parser_class_entry;
+zend_class_entry *php_http_get_header_parser_class_entry(void)
+{
+ return php_http_header_parser_class_entry;
+}
static zend_object_handlers php_http_header_parser_object_handlers;
-zend_object_value php_http_header_parser_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_header_parser_object_new(zend_class_entry *ce)
{
- return php_http_header_parser_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_header_parser_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_header_parser_object_new_ex(zend_class_entry *ce, php_http_header_parser_t *parser, php_http_header_parser_object_t **ptr TSRMLS_DC)
+php_http_header_parser_object_t *php_http_header_parser_object_new_ex(zend_class_entry *ce, php_http_header_parser_t *parser)
{
php_http_header_parser_object_t *o;
- o = ecalloc(1, sizeof(php_http_header_parser_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
-
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(php_http_header_parser_object_t) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
if (parser) {
o->parser = parser;
} else {
- o->parser = php_http_header_parser_init(NULL TSRMLS_CC);
+ o->parser = php_http_header_parser_init(NULL);
}
o->buffer = php_http_buffer_new();
- o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_header_parser_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_header_parser_object_handlers;
+ o->zo.handlers = &php_http_header_parser_object_handlers;
- return o->zv;
+ return o;
}
-void php_http_header_parser_object_free(void *object TSRMLS_DC)
+void php_http_header_parser_object_free(zend_object *object)
{
- php_http_header_parser_object_t *o = (php_http_header_parser_object_t *) object;
+ php_http_header_parser_object_t *o = PHP_HTTP_OBJ(object, NULL);
if (o->parser) {
php_http_header_parser_free(&o->parser);
if (o->buffer) {
php_http_buffer_free(&o->buffer);
}
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeaderParser_getState, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpHeaderParser, getState)
{
- php_http_header_parser_object_t *parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_header_parser_object_t *parser_obj = PHP_HTTP_OBJ(NULL, getThis());
zend_parse_parameters_none();
/* always return the real state */
php_http_header_parser_object_t *parser_obj;
zval *zmsg;
char *data_str;
- int data_len;
- long flags;
+ size_t data_len;
+ zend_long flags;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz", &data_str, &data_len, &flags, &zmsg), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "slz", &data_str, &data_len, &flags, &zmsg), invalid_arg, return);
+ ZVAL_DEREF(zmsg);
if (Z_TYPE_P(zmsg) != IS_ARRAY) {
zval_dtor(zmsg);
array_init(zmsg);
}
- parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ parser_obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_buffer_append(parser_obj->buffer, data_str, data_len);
RETVAL_LONG(php_http_header_parser_parse(parser_obj->parser, parser_obj->buffer, flags, Z_ARRVAL_P(zmsg), NULL, NULL));
}
zend_error_handling zeh;
zval *zmsg, *zstream;
php_stream *s;
- long flags;
+ zend_long flags;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &zstream, &flags, &zmsg), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zstream, &flags, &zmsg), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
- php_stream_from_zval(s, &zstream);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh);
+ php_stream_from_zval(s, zstream);
+ zend_restore_error_handling(&zeh);
+ ZVAL_DEREF(zmsg);
if (Z_TYPE_P(zmsg) != IS_ARRAY) {
zval_dtor(zmsg);
array_init(zmsg);
}
- parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ parser_obj = PHP_HTTP_OBJ(NULL, getThis());
RETVAL_LONG(php_http_header_parser_parse_stream(parser_obj->parser, parser_obj->buffer, s, flags, Z_ARRVAL_P(zmsg), NULL, NULL));
}
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "http\\Header", "Parser", php_http_header_parser_methods);
- php_http_header_parser_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_header_parser_class_entry = zend_register_internal_class(&ce);
memcpy(&php_http_header_parser_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
php_http_header_parser_class_entry->create_object = php_http_header_parser_object_new;
+ php_http_header_parser_object_handlers.offset = XtOffsetOf(php_http_header_parser_object_t, zo);
php_http_header_parser_object_handlers.clone_obj = NULL;
+ php_http_header_parser_object_handlers.free_obj = php_http_header_parser_object_free;
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("CLEANUP"), PHP_HTTP_HEADER_PARSER_CLEANUP TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("CLEANUP"), PHP_HTTP_HEADER_PARSER_CLEANUP);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_FAILURE"), PHP_HTTP_HEADER_PARSER_STATE_FAILURE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_START"), PHP_HTTP_HEADER_PARSER_STATE_START TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_KEY"), PHP_HTTP_HEADER_PARSER_STATE_KEY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_VALUE"), PHP_HTTP_HEADER_PARSER_STATE_VALUE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_VALUE_EX"), PHP_HTTP_HEADER_PARSER_STATE_VALUE_EX TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_HEADER_DONE"), PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_DONE"), PHP_HTTP_HEADER_PARSER_STATE_DONE TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_FAILURE"), PHP_HTTP_HEADER_PARSER_STATE_FAILURE);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_START"), PHP_HTTP_HEADER_PARSER_STATE_START);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_KEY"), PHP_HTTP_HEADER_PARSER_STATE_KEY);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_VALUE"), PHP_HTTP_HEADER_PARSER_STATE_VALUE);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_VALUE_EX"), PHP_HTTP_HEADER_PARSER_STATE_VALUE_EX);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_HEADER_DONE"), PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE);
+ zend_declare_class_constant_long(php_http_header_parser_class_entry, ZEND_STRL("STATE_DONE"), PHP_HTTP_HEADER_PARSER_STATE_DONE);
return SUCCESS;
}
char *str;
size_t len;
} _val;
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_header_parser_t;
-PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC);
+PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser);
PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_push(php_http_header_parser_t *parser, unsigned argc, ...);
PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_is(php_http_header_parser_t *parser);
PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_pop(php_http_header_parser_t *parser);
PHP_HTTP_API php_http_header_parser_state_t php_http_headerparser_parse_stream(php_http_header_parser_t *parser, php_http_buffer_t *buffer, php_stream *s, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg);
typedef struct php_http_header_parser_object {
- zend_object zo;
- zend_object_value zv;
php_http_buffer_t *buffer;
php_http_header_parser_t *parser;
+ zend_object zo;
} php_http_header_parser_object_t;
-PHP_HTTP_API zend_class_entry *php_http_header_parser_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_header_parser_class_entry(void);
PHP_MINIT_FUNCTION(http_header_parser);
-zend_object_value php_http_header_parser_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_header_parser_object_new_ex(zend_class_entry *ce, php_http_header_parser_t *parser, php_http_header_parser_object_t **ptr TSRMLS_DC);
-void php_http_header_parser_object_free(void *object TSRMLS_DC);
+zend_object *php_http_header_parser_object_new(zend_class_entry *ce);
+php_http_header_parser_object_t *php_http_header_parser_object_new_ex(zend_class_entry *ce, php_http_header_parser_t *parser);
+void php_http_header_parser_object_free(zend_object *object);
#endif /* PHP_HTTP_HEADER_PARSER_H */
#include "php_http_api.h"
-php_http_info_t *php_http_info_init(php_http_info_t *i TSRMLS_DC)
+php_http_info_t *php_http_info_init(php_http_info_t *i)
{
if (!i) {
i = emalloc(sizeof(*i));
}
}
-php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC)
+php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header)
{
const char *end, *http;
zend_bool free_info = !info;
return NULL;
}
- info = php_http_info_init(info TSRMLS_CC);
+ info = php_http_info_init(info);
/* and nothing than SPACE or NUL after HTTP/X.x */
- if (!php_http_version_parse(&info->http.version, http TSRMLS_CC)
+ if (!php_http_version_parse(&info->http.version, http)
|| (http[lenof("HTTP/X.x")] && (!PHP_HTTP_IS_CTYPE(space, http[lenof("HTTP/X.x")])))) {
if (free_info) {
php_http_info_free(&info);
const char *status = NULL, *code = http + sizeof("HTTP/X.x");
info->type = PHP_HTTP_RESPONSE;
- while (' ' == *code) ++code;
+ while (code < end && ' ' == *code) ++code;
if (code && end > code) {
/* rfc7230#3.1.2 The status-code element is a 3-digit integer code */
PHP_HTTP_INFO(info).response.code = 100*(*code++ - '0');
if (http > url) {
/* CONNECT presents an authority only */
if (strcasecmp(PHP_HTTP_INFO(info).request.method, "CONNECT")) {
- PHP_HTTP_INFO(info).request.url = php_http_url_parse(url, http - url, ~0 TSRMLS_CC);
+ PHP_HTTP_INFO(info).request.url = php_http_url_parse(url, http - url, ~0);
} else {
- PHP_HTTP_INFO(info).request.url = php_http_url_parse_authority(url, http - url, ~0 TSRMLS_CC);
+ PHP_HTTP_INFO(info).request.url = php_http_url_parse_authority(url, http - url, ~0);
}
if (!PHP_HTTP_INFO(info).request.url) {
PTR_SET(PHP_HTTP_INFO(info).request.method, NULL);
php_http_version_t version;
} php_http_info_data_t;
+#undef PHP_HTTP_REQUEST
+#undef PHP_HTTP_RESPONSE
typedef enum php_http_info_type {
PHP_HTTP_NONE = 0,
PHP_HTTP_REQUEST,
PHP_HTTP_INFO_IMPL(http, type)
} php_http_info_t;
-typedef zend_bool (*php_http_info_callback_t)(void **callback_data, HashTable **headers, php_http_info_t *info TSRMLS_DC);
+typedef zend_bool (*php_http_info_callback_t)(void **callback_data, HashTable **headers, php_http_info_t *info);
-PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *info TSRMLS_DC);
-PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC);
+PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *info);
+PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header);
PHP_HTTP_API void php_http_info_dtor(php_http_info_t *info);
PHP_HTTP_API void php_http_info_free(php_http_info_t **info);
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str);
-zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
+zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info)
{
php_http_message_t *old = *message;
/* advance message */
if (!old || old->type || zend_hash_num_elements(&old->hdrs)) {
- (*message) = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
+ (*message) = php_http_message_init(NULL, 0, NULL);
(*message)->parent = old;
if (headers) {
(*headers) = &((*message)->hdrs);
return old != *message;
}
-php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body TSRMLS_DC)
+php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body)
{
if (!message) {
message = emalloc(sizeof(*message));
}
memset(message, 0, sizeof(*message));
- TSRMLS_SET_CTX(message->ts);
php_http_message_set_type(message, type);
message->http.version.major = 1;
message->http.version.minor = 1;
zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0);
- message->body = body ? body : php_http_message_body_init(NULL, NULL TSRMLS_CC);
+ message->body = body ? body : php_http_message_body_init(NULL, NULL);
return message;
}
-php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC)
+php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type)
{
int free_msg = !message;
zval *sval, tval;
switch (type) {
case PHP_HTTP_REQUEST:
- mbody = php_http_env_get_request_body(TSRMLS_C);
+ mbody = php_http_env_get_request_body();
php_http_message_body_addref(mbody);
- message = php_http_message_init(message, type, mbody TSRMLS_CC);
- if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1 TSRMLS_CC)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
- php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC);
+ message = php_http_message_init(message, type, mbody);
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
+ php_http_version_parse(&message->http.version, Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1 TSRMLS_CC))) {
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1))) {
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
- message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), ~0 TSRMLS_CC);
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1))) {
+ message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), ~0);
}
- php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
+ php_http_env_get_request_headers(&message->hdrs);
break;
case PHP_HTTP_RESPONSE:
- message = php_http_message_init(NULL, type, NULL TSRMLS_CC);
- if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line TSRMLS_CC)) {
+ message = php_http_message_init(NULL, type, NULL);
+ if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line)) {
if (!(message->http.info.response.code = SG(sapi_headers).http_response_code)) {
message->http.info.response.code = 200;
}
message->http.info.response.status = estrdup(php_http_env_get_response_status_for_code(message->http.info.response.code));
}
- php_http_env_get_response_headers(&message->hdrs TSRMLS_CC);
-#if PHP_VERSION_ID >= 50400
- if (php_output_get_level(TSRMLS_C)) {
- if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C));
- goto error;
- } else if (SUCCESS != php_output_get_contents(&tval TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body");
- goto error;
- } else {
- php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval));
- zval_dtor(&tval);
- }
- }
-#else
- if (OG(ob_nesting_level)) {
- if (php_get_output_start_filename(TSRMLS_C)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_get_output_start_filename(TSRMLS_C), php_get_output_start_lineno(TSRMLS_C));
+ php_http_env_get_response_headers(&message->hdrs);
+ if (php_output_get_level()) {
+ if (php_output_get_status() & PHP_OUTPUT_SENT) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(), php_output_get_start_lineno());
+
goto error;
- } else if (SUCCESS != php_ob_get_buffer(&tval TSRMLS_CC)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body");
+ } else if (SUCCESS != php_output_get_contents(&tval)) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch response body");
goto error;
} else {
php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval));
zval_dtor(&tval);
}
}
-#endif
break;
default:
return message;
}
-php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC)
+php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy)
{
php_http_message_parser_t p;
php_http_buffer_t buf;
int free_msg;
php_http_buffer_from_string_ex(&buf, str, len);
- php_http_message_parser_init(&p TSRMLS_CC);
+ php_http_message_parser_init(&p);
if ((free_msg = !msg)) {
- msg = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
+ msg = php_http_message_init(NULL, 0, NULL);
}
if (greedy) {
return msg;
}
-zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join)
+zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len)
{
- zval *ret = NULL, **header;
+ zval *ret;
char *key;
ALLOCA_FLAG(free_key);
key = do_alloca(key_len + 1, free_key);
+
memcpy(key, key_str, key_len);
key[key_len] = '\0';
php_http_pretty_key(key, key_len, 1, 1);
- if (SUCCESS == zend_symtable_find(&msg->hdrs, key, key_len + 1, (void *) &header)) {
- if (join && Z_TYPE_PP(header) == IS_ARRAY) {
- TSRMLS_FETCH_FROM_CTX(msg->ts);
-
- ret = php_http_header_value_to_string(*header TSRMLS_CC);
- } else {
- Z_ADDREF_PP(header);
- ret = *header;
- }
- }
+ ret = zend_symtable_str_find(&msg->hdrs, key, key_len);
free_alloca(key, free_key);
zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
{
- zval *ct = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1);
+ zend_string *ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type"));
zend_bool is_multipart = 0;
- TSRMLS_FETCH_FROM_CTX(msg->ts);
if (ct) {
php_http_params_opts_t popts;
ZEND_INIT_SYMTABLE(¶ms);
php_http_params_opts_default_get(&popts);
- popts.input.str = Z_STRVAL_P(ct);
- popts.input.len = Z_STRLEN_P(ct);
+ popts.input.str = ct->val;
+ popts.input.len = ct->len;
- if (php_http_params_parse(¶ms, &popts TSRMLS_CC)) {
- zval **cur, **arg;
- char *ct_str;
+ if (php_http_params_parse(¶ms, &popts)) {
+ zval *cur, *arg;
+ zend_string *ct_str;
+ zend_ulong index;
zend_hash_internal_pointer_reset(¶ms);
- if (SUCCESS == zend_hash_get_current_data(¶ms, (void *) &cur)
- && Z_TYPE_PP(cur) == IS_ARRAY
- && HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, NULL, 0)
+ if ((cur = zend_hash_get_current_data(¶ms))
+ && (Z_TYPE_P(cur) == IS_ARRAY)
+ && (HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, &index))
) {
- if (php_http_match(ct_str, "multipart", PHP_HTTP_MATCH_WORD)) {
+ if (php_http_match(ct_str->val, "multipart", PHP_HTTP_MATCH_WORD)) {
is_multipart = 1;
/* get boundary */
if (boundary
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(cur), ZEND_STRS("arguments"), (void *) &arg)
- && Z_TYPE_PP(arg) == IS_ARRAY
+ && (arg = zend_hash_str_find(Z_ARRVAL_P(cur), ZEND_STRL("arguments")))
+ && Z_TYPE_P(arg) == IS_ARRAY
) {
- zval **val;
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval *val;
+ php_http_arrkey_t key;
- FOREACH_KEYVAL(pos, *arg, key, val) {
- if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "boundary")) {
- zval *bnd = php_http_ztyp(IS_STRING, *val);
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arg), key.h, key.key, val)
+ {
+ if (key.key && key.key->len == lenof("boundary") && !strcasecmp(key.key->val, "boundary")) {
+ zend_string *bnd = zval_get_string(val);
- if (Z_STRLEN_P(bnd)) {
- *boundary = estrndup(Z_STRVAL_P(bnd), Z_STRLEN_P(bnd));
+ if (bnd->len) {
+ *boundary = estrndup(bnd->val, bnd->len);
}
- zval_ptr_dtor(&bnd);
+ zend_string_release(bnd);
}
}
+ ZEND_HASH_FOREACH_END();
}
}
}
}
zend_hash_destroy(¶ms);
- zval_ptr_dtor(&ct);
+ zend_string_release(ct);
}
return is_multipart;
void php_http_message_update_headers(php_http_message_t *msg)
{
- zval *h;
+ zval h;
size_t size;
+ zend_string *cl;
if (php_http_message_body_stream(msg->body)->readfilters.head) {
/* if a read stream filter is attached to the body the caller must also care for the headers */
- } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Range"), 0))) {
+ } else if (php_http_message_header(msg, ZEND_STRL("Content-Range"))) {
/* don't mess around with a Content-Range message */
- zval_ptr_dtor(&h);
} else if ((size = php_http_message_body_size(msg->body))) {
- MAKE_STD_ZVAL(h);
- ZVAL_LONG(h, size);
- zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL);
+ ZVAL_LONG(&h, size);
+ zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h);
if (msg->body->boundary) {
char *str;
size_t len;
+ zend_string *ct;
- if (!(h = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1))) {
+ if (!(ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type")))) {
len = spprintf(&str, 0, "multipart/form-data; boundary=\"%s\"", msg->body->boundary);
- MAKE_STD_ZVAL(h);
- ZVAL_STRINGL(h, str, len, 0);
- zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL);
- } else if (!php_http_match(Z_STRVAL_P(h), "boundary=", PHP_HTTP_MATCH_WORD)) {
- zval_dtor(h);
- Z_STRLEN_P(h) = spprintf(&Z_STRVAL_P(h), 0, "%s; boundary=\"%s\"", Z_STRVAL_P(h), msg->body->boundary);
- zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL);
+ ZVAL_STR(&h, php_http_cs2zs(str, len));
+ zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h);
+ } else if (!php_http_match(ct->val, "boundary=", PHP_HTTP_MATCH_WORD)) {
+ len = spprintf(&str, 0, "%s; boundary=\"%s\"", ct->val, msg->body->boundary);
+ ZVAL_STR(&h, php_http_cs2zs(str, len));
+ zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h);
+ zend_string_release(ct);
} else {
- zval_ptr_dtor(&h);
+ zend_string_release(ct);
}
}
- } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Length"), 1))) {
- zval *h_cpy = php_http_ztyp(IS_LONG, h);
-
- zval_ptr_dtor(&h);
- if (Z_LVAL_P(h_cpy)) {
+ } else if ((cl = php_http_message_header_string(msg, ZEND_STRL("Content-Length")))) {
+ if (!zend_string_equals_literal(cl, "0")) {
/* body->size == 0, so get rid of old Content-Length */
- zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length"));
+ zend_hash_str_del(&msg->hdrs, ZEND_STRL("Content-Length"));
}
- zval_ptr_dtor(&h_cpy);
+ zend_string_release(cl);
} else if (msg->type == PHP_HTTP_REQUEST) {
- if ((h = php_http_message_header(msg, ZEND_STRL("Transfer-Encoding"), 0))) {
- zval_ptr_dtor(&h);
- } else {
+ if (!php_http_message_header(msg, ZEND_STRL("Transfer-Encoding"))) {
/* no filter, no CR, no size, no TE, no CL */
if (0 <= php_http_select_str(msg->http.info.request.method, 3, "POST", "PUT", "PATCH")) {
/* quoting RFC7230#section-3.3.2
a payload body and the method semantics do not anticipate such a
body.
*/
- MAKE_STD_ZVAL(h);
- ZVAL_LONG(h, 0);
- zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL);
+ ZVAL_LONG(&h, 0);
+ zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h);
}
}
}
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
{
char *tmp = NULL;
- TSRMLS_FETCH_FROM_CTX(msg->ts);
switch (msg->type) {
case PHP_HTTP_REQUEST:
}
php_http_message_update_headers(msg);
- php_http_header_to_string(str, &msg->hdrs TSRMLS_CC);
+ php_http_header_to_string(str, &msg->hdrs);
}
void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
{
- int i, c = 0;
-
- php_http_message_count(c, msg);
+ size_t i, c = php_http_message_count(msg);
if (c > 1) {
php_http_message_t *tmp = msg, **arr;
return msg;
}
-php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two)
+php_http_message_t *php_http_message_zip(php_http_message_t *dst, php_http_message_t *src)
{
- php_http_message_t *dst = php_http_message_copy(one, NULL), *src = php_http_message_copy(two, NULL), *tmp_dst, *tmp_src, *ret = dst;
+ php_http_message_t *tmp_dst, *tmp_src, *ret = dst;
- while(dst && src) {
+ while (dst && src) {
tmp_dst = dst->parent;
tmp_src = src->parent;
dst->parent = src;
{
php_http_message_t *temp, *copy = NULL;
php_http_info_t info;
- TSRMLS_FETCH_FROM_CTX(from->ts);
if (from) {
info.type = from->type;
info.http = from->http;
- copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL) TSRMLS_CC);
+ copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL));
php_http_message_set_info(temp, &info);
- zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref);
if (parents) while (from->parent) {
info.type = from->parent->type;
info.http = from->parent->http;
- temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL) TSRMLS_CC);
+ temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL));
php_http_message_set_info(temp->parent, &info);
- zend_hash_copy(&temp->parent->hdrs, &from->parent->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ array_copy(&from->parent->hdrs, &temp->parent->hdrs);
temp = temp->parent;
from = from->parent;
return copy;
}
-php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to)
-{
- return php_http_message_copy_ex(from, to, 1);
-}
-
void php_http_message_dtor(php_http_message_t *message)
{
if (message) {
}
}
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC);
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC);
-static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC);
+static zend_class_entry *php_http_message_class_entry;
+zend_class_entry *php_http_message_get_class_entry(void)
+{
+ return php_http_message_class_entry;
+}
+
+static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv);
+static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
static zend_object_handlers php_http_message_object_handlers;
static HashTable php_http_message_object_prophandlers;
-typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v TSRMLS_DC);
+static void php_http_message_object_prophandler_hash_dtor(zval *pData)
+{
+ pefree(Z_PTR_P(pData), 1);
+}
+
+typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v);
typedef struct php_http_message_object_prophandler {
php_http_message_object_prophandler_func_t read;
static ZEND_RESULT_CODE php_http_message_object_add_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_func_t read, php_http_message_object_prophandler_func_t write) {
php_http_message_object_prophandler_t h = { read, write };
- return zend_hash_add(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) &h, sizeof(h), NULL);
+ if (!zend_hash_str_add_mem(&php_http_message_object_prophandlers, prop_str, prop_len, (void *) &h, sizeof(h))) {
+ return FAILURE;
+ }
+ return SUCCESS;
}
-static ZEND_RESULT_CODE php_http_message_object_get_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_t **handler) {
- return zend_hash_find(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) handler);
+static php_http_message_object_prophandler_t *php_http_message_object_get_prophandler(zend_string *name_str) {
+ return zend_hash_str_find_ptr(&php_http_message_object_prophandlers, name_str->val, name_str->len);
}
-static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value) {
RETVAL_LONG(obj->message->type);
}
-static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_LONG, value);
- php_http_message_set_type(obj->message, Z_LVAL_P(cpy));
- zval_ptr_dtor(&cpy);
+static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value) {
+ php_http_message_set_type(obj->message, zval_get_long(value));
}
-static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.method) {
- RETVAL_STRING(obj->message->http.info.request.method, 1);
+ RETVAL_STRING(obj->message->http.info.request.method);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- PTR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ zend_string *zs = zval_get_string(value);
+ PTR_SET(obj->message->http.info.request.method, estrndup(zs->val, zs->len));
+ zend_string_release(zs);
}
}
-static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value) {
char *url_str;
size_t url_len;
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url && php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0)) {
- RETVAL_STRINGL(url_str, url_len, 0);
+ RETVAL_STR(php_http_cs2zs(url_str, url_len));
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0 TSRMLS_CC));
+ PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0));
}
}
-static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message) && obj->message->http.info.response.status) {
- RETVAL_STRING(obj->message->http.info.response.status, 1);
+ RETVAL_STRING(obj->message->http.info.response.status);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- PTR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ zend_string *zs = zval_get_string(value);
+ PTR_SET(obj->message->http.info.response.status, estrndup(zs->val, zs->len));
+ zend_string_release(zs);
}
}
-static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
RETVAL_LONG(obj->message->http.info.response.code);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
- zval *cpy = php_http_ztyp(IS_LONG, value);
- obj->message->http.info.response.code = Z_LVAL_P(cpy);
+ obj->message->http.info.response.code = zval_get_long(value);
PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
- zval_ptr_dtor(&cpy);
}
}
-static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value) {
char *version_str;
size_t version_len;
- php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL TSRMLS_CC);
- RETVAL_STRINGL(version_str, version_len, 0);
+ php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL);
+ RETVAL_STR(php_http_cs2zs(version_str, version_len));
}
-static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- php_http_version_parse(&obj->message->http.version, Z_STRVAL_P(cpy) TSRMLS_CC);
- zval_ptr_dtor(&cpy);
+static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value) {
+ zend_string *zs = zval_get_string(value);
+ php_http_version_parse(&obj->message->http.version, zs->val);
+ zend_string_release(zs);
}
-static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value ) {
array_init(return_value);
- zend_hash_copy(Z_ARRVAL_P(return_value), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value));
}
-static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_ARRAY, value);
+static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value) {
+ HashTable *headers;
+ zval *orig_value = value;
+
+ if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) {
+ convert_to_array_ex(value);
+ }
+ headers = HASH_OF(value);
zend_hash_clean(&obj->message->hdrs);
- zend_hash_copy(&obj->message->hdrs, Z_ARRVAL_P(cpy), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- zval_ptr_dtor(&cpy);
+ array_copy(headers, &obj->message->hdrs);
+
+ if (orig_value != value) {
+ zval_ptr_dtor(value);
+ }
}
-static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value) {
if (obj->body) {
- RETVAL_OBJVAL(obj->body->zv, 1);
+ RETVAL_OBJECT(&obj->body->zo, 1);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- php_http_message_object_set_body(obj, value TSRMLS_CC);
+static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value) {
+ php_http_message_object_set_body(obj, value);
}
-static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value) {
if (obj->message->parent) {
- RETVAL_OBJVAL(obj->parent->zv, 1);
+ RETVAL_OBJECT(&obj->parent->zo, 1);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry TSRMLS_CC)) {
- php_http_message_object_t *parent_obj = zend_object_store_get_object(value TSRMLS_CC);
+static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value) {
+ if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry)) {
+ php_http_message_object_t *parent_obj = PHP_HTTP_OBJ(NULL, value);
if (obj->message->parent) {
- zend_objects_store_del_ref_by_handle(obj->parent->zv.handle TSRMLS_CC);
+ zend_objects_store_del(&obj->parent->zo);
}
- Z_OBJ_ADDREF_P(value);
+ Z_ADDREF_P(value);
obj->parent = parent_obj;
obj->message->parent = parent_obj->message;
}
#define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
do { \
if (!obj->message) { \
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); \
+ obj->message = php_http_message_init(NULL, 0, NULL); \
} \
} while(0)
-void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC)
+void php_http_message_object_reverse(zval *zmsg, zval *return_value)
{
- int i = 0;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ size_t i;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, zmsg);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
/* count */
- php_http_message_count(i, obj->message);
+ i = php_http_message_count(obj->message);
if (i > 1) {
php_http_message_object_t **objects;
objects[0]->parent = NULL;
/* add ref, because we previously have not been a parent message */
- Z_OBJ_ADDREF_P(getThis());
- RETVAL_OBJVAL(objects[last]->zv, 0);
+ Z_ADDREF_P(zmsg);
+ /* no addref, because we've been a parent message previously */
+ RETVAL_OBJECT(&objects[last]->zo, 0);
efree(objects);
} else {
- RETURN_ZVAL(getThis(), 1, 0);
+ RETURN_ZVAL(zmsg, 1, 0);
}
}
-void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC)
+void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top)
{
- zval m;
php_http_message_t *save_parent_msg = NULL;
- php_http_message_object_t *save_parent_obj = NULL, *obj = zend_object_store_get_object(this_ptr TSRMLS_CC);
- php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
-
- INIT_PZVAL(&m);
- m.type = IS_OBJECT;
+ php_http_message_object_t *save_parent_obj = NULL, *obj = PHP_HTTP_OBJ(NULL, this_ptr);
+ php_http_message_object_t *prepend_obj = PHP_HTTP_OBJ(NULL, prepend);
if (!top) {
save_parent_obj = obj->parent;
obj->message->parent = prepend_obj->message;
/* add ref */
- zend_objects_store_add_ref(prepend TSRMLS_CC);
+ Z_ADDREF_P(prepend);
if (!top) {
prepend_obj->parent = save_parent_obj;
}
}
-ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody TSRMLS_DC)
+ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody)
{
- zval *tmp = NULL;
php_stream *s;
- zend_object_value ov;
+ zend_string *body_str;
php_http_message_body_t *body;
php_http_message_body_object_t *body_obj;
switch (Z_TYPE_P(zbody)) {
case IS_RESOURCE:
- php_stream_from_zval_no_verify(s, &zbody);
+ php_stream_from_zval_no_verify(s, zbody);
if (!s) {
php_http_throw(unexpected_val, "The stream is not a valid resource", NULL);
return FAILURE;
is_resource:
- body = php_http_message_body_init(NULL, s TSRMLS_CC);
- if (SUCCESS != php_http_new(&ov, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, body, NULL TSRMLS_CC)) {
+ body = php_http_message_body_init(NULL, s);
+ if (!(body_obj = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), body))) {
php_http_message_body_free(&body);
return FAILURE;
}
- MAKE_STD_ZVAL(tmp);
- ZVAL_OBJVAL(tmp, ov, 0);
- zbody = tmp;
break;
case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) {
- Z_OBJ_ADDREF_P(zbody);
+ if (instanceof_function(Z_OBJCE_P(zbody), php_http_get_message_body_class_entry())) {
+ Z_ADDREF_P(zbody);
+ body_obj = PHP_HTTP_OBJ(NULL, zbody);
break;
}
/* no break */
default:
- tmp = php_http_ztyp(IS_STRING, zbody);
+ body_str = zval_get_string(zbody);
s = php_stream_temp_new();
- php_stream_write(s, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
- zval_ptr_dtor(&tmp);
- tmp = NULL;
+ php_stream_write(s, body_str->val, body_str->len);
+ zend_string_release(body_str);
goto is_resource;
}
- body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
if (!body_obj->body) {
- body_obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC);
+ body_obj->body = php_http_message_body_init(NULL, NULL);
}
if (msg_obj->body) {
- zend_objects_store_del_ref_by_handle(msg_obj->body->zv.handle TSRMLS_CC);
+ zend_objects_store_del(&msg_obj->body->zo);
}
if (msg_obj->message) {
php_http_message_body_free(&msg_obj->message->body);
- msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
+ msg_obj->message->body = body_obj->body;
} else {
- msg_obj->message = php_http_message_init(NULL, 0, php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC) TSRMLS_CC);
+ msg_obj->message = php_http_message_init(NULL, 0, body_obj->body);
}
+ php_http_message_body_addref(body_obj->body);
msg_obj->body = body_obj;
- if (tmp) {
- FREE_ZVAL(tmp);
- }
return SUCCESS;
}
ZEND_RESULT_CODE php_http_message_object_init_body_object(php_http_message_object_t *obj)
{
- TSRMLS_FETCH_FROM_CTX(obj->message->ts);
-
php_http_message_body_addref(obj->message->body);
- return php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC);
+ return php_http_new((void *) &obj->body, php_http_get_message_body_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body);
}
-zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_message_object_new(zend_class_entry *ce)
{
- return php_http_message_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_message_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC)
+php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg)
{
php_http_message_object_t *o;
- o = ecalloc(1, sizeof(php_http_message_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
-
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
if (msg) {
o->message = msg;
if (msg->parent) {
- php_http_message_object_new_ex(ce, msg->parent, &o->parent TSRMLS_CC);
+ o->parent = php_http_message_object_new_ex(ce, msg->parent);
}
- php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL TSRMLS_CC), &o->body TSRMLS_CC);
+ o->body = php_http_message_body_object_new_ex(php_http_get_message_body_class_entry(), php_http_message_body_init(&msg->body, NULL));
}
- o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_message_object_handlers;
+ o->zo.handlers = &php_http_message_object_handlers;
- return o->zv;
+ return o;
}
-zend_object_value php_http_message_object_clone(zval *this_ptr TSRMLS_DC)
+zend_object *php_http_message_object_clone(zval *this_ptr)
{
- zend_object_value new_ov;
php_http_message_object_t *new_obj = NULL;
- php_http_message_object_t *old_obj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ php_http_message_object_t *old_obj = PHP_HTTP_OBJ(NULL, this_ptr);
- new_ov = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL), &new_obj TSRMLS_CC);
- zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ new_obj = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL));
+ zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
- return new_ov;
+ return &new_obj->zo;
}
-void php_http_message_object_free(void *object TSRMLS_DC)
+void php_http_message_object_free(zend_object *object)
{
- php_http_message_object_t *o = (php_http_message_object_t *) object;
+ php_http_message_object_t *o = PHP_HTTP_OBJ(object, NULL);
- if (o->iterator) {
+ if (!Z_ISUNDEF(o->iterator)) {
zval_ptr_dtor(&o->iterator);
- o->iterator = NULL;
+ ZVAL_UNDEF(&o->iterator);
}
if (o->message) {
/* do NOT free recursivly */
o->message = NULL;
}
if (o->parent) {
- zend_objects_store_del_ref_by_handle(o->parent->zv.handle TSRMLS_CC);
+ if (GC_REFCOUNT(&o->parent->zo) == 1) {
+ zend_objects_store_del(&o->parent->zo);
+ }
+ zend_objects_store_del(&o->parent->zo);
o->parent = NULL;
}
if (o->body) {
- zend_objects_store_del_ref_by_handle(o->body->zv.handle TSRMLS_CC);
+ if (GC_REFCOUNT(&o->body->zo) == 1) {
+ zend_objects_store_del(&o->body->zo);
+ }
+ zend_objects_store_del(&o->body->zo);
o->body = NULL;
}
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
}
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC)
+static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
{
- php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
- php_http_message_object_prophandler_t *handler;
- zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
+ zval *return_value;
+ zend_string *member_name = zval_get_string(member);
+ php_http_message_object_prophandler_t *handler = php_http_message_object_get_prophandler(member_name);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ if (!handler || type == BP_VAR_R || type == BP_VAR_IS) {
+ return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
- if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
- ALLOC_ZVAL(return_value);
- Z_SET_REFCOUNT_P(return_value, 0);
- Z_UNSET_ISREF_P(return_value);
+ if (handler) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
- if (type == BP_VAR_R) {
- handler->read(obj, return_value TSRMLS_CC);
- } else {
- php_property_proxy_t *proxy = php_property_proxy_init(object, Z_STRVAL_P(copy), Z_STRLEN_P(copy) TSRMLS_CC);
- RETVAL_OBJVAL(php_property_proxy_object_new_ex(php_property_proxy_get_class_entry(), proxy, NULL TSRMLS_CC), 0);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ handler->read(obj, tmp);
+
+ zval_ptr_dtor(return_value);
+ ZVAL_COPY_VALUE(return_value, tmp);
}
+ zend_string_release(member_name);
+ return return_value;
} else {
- return_value = zend_get_std_object_handlers()->read_property(object, member, type PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC);
- }
+ php_property_proxy_t *proxy;
+ php_property_proxy_object_t *proxy_obj;
- zval_ptr_dtor(©);
+ proxy = php_property_proxy_init(object, member_name);
+ proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
- return return_value;
+ ZVAL_OBJ(tmp, &proxy_obj->zo);
+ zend_string_release(member_name);
+ return tmp;
+ }
}
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC)
+static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
{
- php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
php_http_message_object_prophandler_t *handler;
- zval *copy = php_http_ztyp(IS_STRING, member);
+ zend_string *member_name = zval_get_string(member);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
- handler->write(obj, value TSRMLS_CC);
+ if ((handler = php_http_message_object_get_prophandler(member_name))) {
+ handler->write(obj, value);
} else {
- zend_get_std_object_handlers()->write_property(object, member, value PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC);
+ zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
}
- zval_ptr_dtor(©);
+ zend_string_release(member_name);
}
-static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC)
+static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_temp)
{
- zval *headers;
- php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
- HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC);
- zval array, *parent, *body;
+ zval tmp;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+ HashTable *props = zend_get_std_object_handlers()->get_properties(object);
char *ver_str, *url_str = NULL;
size_t ver_len, url_len = 0;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- INIT_PZVAL_ARRAY(&array, props);
+ *is_temp = 0;
-#define ASSOC_PROP(ptype, n, val) \
+#define UPDATE_PROP(name_str, action_with_tmp) \
do { \
zend_property_info *pi; \
- if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \
- add_assoc_ ##ptype## _ex(&array, pi->name, pi->name_length + 1, val); \
- } \
- } while(0) \
-
-#define ASSOC_STRING(name, val) ASSOC_STRINGL(name, val, strlen(val))
-#define ASSOC_STRINGL(name, val, len) ASSOC_STRINGL_EX(name, val, len, 1)
-#define ASSOC_STRINGL_EX(n, val, len, cpy) \
- do { \
- zend_property_info *pi; \
- if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \
- add_assoc_stringl_ex(&array, pi->name, pi->name_length + 1, val, len, cpy); \
+ if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \
+ action_with_tmp; \
+ zend_hash_update_ind(props, pi->name, &tmp); \
} \
} while(0)
- ASSOC_PROP(long, "type", obj->message->type);
+ UPDATE_PROP("type", ZVAL_LONG(&tmp, obj->message->type));
+
ver_len = spprintf(&ver_str, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor);
- ASSOC_STRINGL_EX("httpVersion", ver_str, ver_len, 0);
+ UPDATE_PROP("httpVersion", ZVAL_STR(&tmp, php_http_cs2zs(ver_str, ver_len)));
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
- ASSOC_PROP(long, "responseCode", 0);
- ASSOC_STRINGL("responseStatus", "", 0);
- ASSOC_STRING("requestMethod", STR_PTR(obj->message->http.info.request.method));
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0));
+ UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestMethod", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.request.method)));
if (obj->message->http.info.request.url) {
php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
- ASSOC_STRINGL_EX("requestUrl", url_str, url_len, 0);
+ UPDATE_PROP("requestUrl", ZVAL_STR(&tmp, php_http_cs2zs(url_str, url_len)));
} else {
- ASSOC_STRINGL("requestUrl", "", 0);
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
}
break;
case PHP_HTTP_RESPONSE:
- ASSOC_PROP(long, "responseCode", obj->message->http.info.response.code);
- ASSOC_STRING("responseStatus", STR_PTR(obj->message->http.info.response.status));
- ASSOC_STRINGL("requestMethod", "", 0);
- ASSOC_STRINGL("requestUrl", "", 0);
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, obj->message->http.info.response.code));
+ UPDATE_PROP("responseStatus", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.response.status)));
+ UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
break;
case PHP_HTTP_NONE:
default:
- ASSOC_PROP(long, "responseCode", 0);
- ASSOC_STRINGL("responseStatus", "", 0);
- ASSOC_STRINGL("requestMethod", "", 0);
- ASSOC_STRINGL("requestUrl", "", 0);
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0));
+ UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
break;
}
- MAKE_STD_ZVAL(headers);
- array_init(headers);
- zend_hash_copy(Z_ARRVAL_P(headers), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- ASSOC_PROP(zval, "headers", headers);
+ UPDATE_PROP("headers",
+ array_init(&tmp);
+ array_copy(&obj->message->hdrs, Z_ARRVAL(tmp));
+ );
- MAKE_STD_ZVAL(body);
- if (obj->body) {
- ZVAL_OBJVAL(body, obj->body->zv, 1);
- } else {
- ZVAL_NULL(body);
- }
- ASSOC_PROP(zval, "body", body);
+ UPDATE_PROP("body",
+ if (obj->body) {
+ ZVAL_OBJECT(&tmp, &obj->body->zo, 1);
+ } else {
+ ZVAL_NULL(&tmp);
+ }
+ );
- MAKE_STD_ZVAL(parent);
- if (obj->message->parent) {
- ZVAL_OBJVAL(parent, obj->parent->zv, 1);
- } else {
- ZVAL_NULL(parent);
- }
- ASSOC_PROP(zval, "parentMessage", parent);
+ UPDATE_PROP("parentMessage",
+ if (obj->message->parent) {
+ ZVAL_OBJECT(&tmp, &obj->parent->zo, 1);
+ } else {
+ ZVAL_NULL(&tmp);
+ }
+ );
return props;
}
zend_bool greedy = 1;
zval *zmessage = NULL;
php_http_message_t *msg = NULL;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!b", &zmessage, &greedy), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage, &greedy), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_message_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_message_class_entry(), &zeh);
if (zmessage && Z_TYPE_P(zmessage) == IS_RESOURCE) {
php_stream *s;
php_http_message_parser_t p;
zend_error_handling zeh;
- zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
- php_stream_from_zval(s, &zmessage);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh);
+ php_stream_from_zval(s, zmessage);
+ zend_restore_error_handling(&zeh);
- if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
+ if (s && php_http_message_parser_init(&p)) {
unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
php_http_buffer_t buf;
php_http_throw(bad_message, "Empty message received from stream", NULL);
}
} else if (zmessage) {
- zmessage = php_http_ztyp(IS_STRING, zmessage);
- msg = php_http_message_parse(NULL, Z_STRVAL_P(zmessage), Z_STRLEN_P(zmessage), greedy TSRMLS_CC);
+ zend_string *zs_msg = zval_get_string(zmessage);
+
+ msg = php_http_message_parse(NULL, zs_msg->val, zs_msg->len, greedy);
if (!msg && !EG(exception)) {
- php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, Z_STRLEN_P(zmessage)), Z_STRVAL_P(zmessage));
+ php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, zs_msg->len), zs_msg->val);
}
- zval_ptr_dtor(&zmessage);
+ zend_string_release(zs_msg);
}
if (msg) {
php_http_message_dtor(obj->message);
obj->message = msg;
if (obj->message->parent) {
- php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, &obj->parent TSRMLS_CC);
+ obj->parent = php_http_message_object_new_ex(obj->zo.ce, obj->message->parent);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
}
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!obj->body) {
}
if (obj->body) {
- RETVAL_OBJVAL(obj->body->zv, 1);
+ RETVAL_OBJECT(&obj->body->zo, 1);
}
}
{
zval *zbody;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_class_entry)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody, php_http_get_message_body_class_entry())) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC);
+ php_http_message_object_prophandler_set_body(obj, zbody);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *new_body;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &new_body, php_http_message_body_class_entry)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_body_object_t *new_obj = zend_object_store_get_object(new_body TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body, php_http_get_message_body_class_entry())) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+ php_http_message_body_object_t *new_obj = PHP_HTTP_OBJ(NULL, new_body);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_body_to_callback(new_obj->body, (php_http_pass_callback_t) php_http_message_body_append, obj->message->body, 0, 0);
static PHP_METHOD(HttpMessage, getHeader)
{
char *header_str;
- int header_len;
+ size_t header_len;
zend_class_entry *header_ce = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C!", &header_str, &header_len, &header_ce)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|C!", &header_str, &header_len, &header_ce)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zval *header;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) {
+ if ((header = php_http_message_header(obj->message, header_str, header_len))) {
if (!header_ce) {
- RETURN_ZVAL(header, 1, 1);
- } else if (instanceof_function(header_ce, php_http_header_class_entry TSRMLS_CC)) {
+ RETURN_ZVAL(header, 1, 0);
+ } else if (instanceof_function(header_ce, php_http_header_get_class_entry())) {
php_http_object_method_t cb;
- zval *header_name, **argv[2];
-
- MAKE_STD_ZVAL(header_name);
- ZVAL_STRINGL(header_name, header_str, header_len, 1);
+ zval argv[2];
- argv[0] = &header_name;
- argv[1] = &header;
+ ZVAL_STRINGL(&argv[0], header_str, header_len);
+ ZVAL_COPY(&argv[1], header);
object_init_ex(return_value, header_ce);
- php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct") TSRMLS_CC);
- php_http_object_method_call(&cb, return_value, NULL, 2, argv TSRMLS_CC);
+ php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct"));
+ php_http_object_method_call(&cb, return_value, NULL, 2, argv);
php_http_object_method_dtor(&cb);
- zval_ptr_dtor(&header_name);
- zval_ptr_dtor(&header);
+ zval_ptr_dtor(&argv[0]);
+ zval_ptr_dtor(&argv[1]);
return;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name);
+ php_error_docref(NULL, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name->val);
}
}
}
static PHP_METHOD(HttpMessage, getHeaders)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
{
zval *zvalue = NULL;
char *name_str;
- int name_len;
+ size_t name_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!", &name_str, &name_len, &zvalue)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &name_str, &name_len, &zvalue)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!zvalue) {
- zend_symtable_del(&obj->message->hdrs, name, name_len + 1);
+ zend_symtable_str_del(&obj->message->hdrs, name, name_len);
} else {
- Z_ADDREF_P(zvalue);
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ Z_TRY_ADDREF_P(zvalue);
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, zvalue);
}
efree(name);
}
{
zval *new_headers = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a/!", &new_headers)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
{
zval *zvalue;
char *name_str;
- int name_len;
+ size_t name_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &zvalue)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str, &name_len, &zvalue)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
zval *header;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- Z_ADDREF_P(zvalue);
- if ((header = php_http_message_header(obj->message, name, name_len, 0))) {
+ Z_TRY_ADDREF_P(zvalue);
+ if ((header = php_http_message_header(obj->message, name, name_len))) {
convert_to_array(header);
- zend_hash_next_index_insert(Z_ARRVAL_P(header), &zvalue, sizeof(void *), NULL);
- zval_ptr_dtor(&header);
+ zend_hash_next_index_insert(Z_ARRVAL_P(header), zvalue);
} else {
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, zvalue);
}
efree(name);
}
zval *new_headers;
zend_bool append = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &new_headers, &append)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
static PHP_METHOD(HttpMessage, getType)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, setType)
{
- long type;
+ zend_long type;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
static PHP_METHOD(HttpMessage, getInfo)
{
if (SUCCESS == zend_parse_parameters_none()) {
- char *tmp = NULL;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ char *str, *tmp = NULL;
+ size_t len;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
- Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, ""));
+ len = spprintf(&str, 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, ""));
PTR_FREE(tmp);
break;
case PHP_HTTP_RESPONSE:
- Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
+ len = spprintf(&str, 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
PTR_FREE(tmp);
break;
default:
RETURN_NULL();
break;
}
- Z_TYPE_P(return_value) = IS_STRING;
- return;
+
+ RETVAL_STR(php_http_cs2zs(str, len));
}
}
static PHP_METHOD(HttpMessage, setInfo)
{
char *str;
- int len;
+ size_t len;
php_http_message_object_t *obj;
php_http_info_t inf;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if (!php_http_info_parse(&inf, str TSRMLS_CC)) {
+ if (!php_http_info_parse(&inf, str)) {
php_http_throw(bad_header, "Could not parse message info '%s'", str);
return;
}
if (SUCCESS == zend_parse_parameters_none()) {
char *str;
size_t len;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL TSRMLS_CC);
- RETURN_STRINGL(str, len, 0);
+ php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL);
+ RETURN_STR(php_http_cs2zs(str, len));
}
}
static PHP_METHOD(HttpMessage, setHttpVersion)
{
char *v_str;
- int v_len;
+ size_t v_len;
php_http_version_t version;
php_http_message_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &v_str, &v_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &v_str, &v_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_expect(php_http_version_parse(&version, v_str TSRMLS_CC), unexpected_val, return);
+ php_http_expect(php_http_version_parse(&version, v_str), unexpected_val, return);
obj->message->http.version = version;
static PHP_METHOD(HttpMessage, getResponseCode)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->type != PHP_HTTP_RESPONSE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not if type response");
+ php_error_docref(NULL, E_WARNING, "http\\Message is not if type response");
RETURN_FALSE;
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, setResponseCode)
{
- long code;
+ zend_long code;
zend_bool strict = 1;
php_http_message_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict), invalid_arg, return);
-
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &code, &strict), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->type != PHP_HTTP_RESPONSE) {
static PHP_METHOD(HttpMessage, getResponseStatus)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->type != PHP_HTTP_RESPONSE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type response");
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type response");
}
if (obj->message->http.info.response.status) {
- RETURN_STRING(obj->message->http.info.response.status, 1);
+ RETURN_STRING(obj->message->http.info.response.status);
} else {
RETURN_EMPTY_STRING();
}
static PHP_METHOD(HttpMessage, setResponseStatus)
{
char *status;
- int status_len;
+ size_t status_len;
php_http_message_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &status, &status_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
static PHP_METHOD(HttpMessage, getRequestMethod)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->type != PHP_HTTP_REQUEST) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request");
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type request");
RETURN_FALSE;
}
if (obj->message->http.info.request.method) {
- RETURN_STRING(obj->message->http.info.request.method, 1);
+ RETURN_STRING(obj->message->http.info.request.method);
} else {
RETURN_EMPTY_STRING();
}
static PHP_METHOD(HttpMessage, setRequestMethod)
{
char *method;
- int method_len;
+ size_t method_len;
php_http_message_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &method, &method_len), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
static PHP_METHOD(HttpMessage, getRequestUrl)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->type != PHP_HTTP_REQUEST) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request");
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type request");
RETURN_FALSE;
}
size_t url_len;
php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
- RETURN_STRINGL(url_str, url_len, 0);
+ RETURN_STR(php_http_cs2zs(url_str, url_len));
} else {
RETURN_EMPTY_STRING();
}
php_http_message_object_t *obj;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zurl), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zurl), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
return;
}
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
- url = php_http_url_from_zval(zurl, ~0 TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
+ url = php_http_url_from_zval(zurl, ~0);
+ zend_restore_error_handling(&zeh);
if (url && php_http_url_is_empty(url)) {
php_http_url_free(&url);
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!obj->message->parent) {
return;
}
- RETVAL_OBJVAL(obj->parent->zv, 1);
+ RETVAL_OBJECT(&obj->parent->zo, 1);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0)
{
zend_bool include_parent = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &include_parent)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &include_parent)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;
php_http_message_to_string(obj->message, &string, &length);
}
if (string) {
- RETURN_STRINGL(string, length, 0);
+ RETURN_STR(php_http_cs2zs(string, length));
}
}
RETURN_EMPTY_STRING();
}
-#ifdef ZTS
-static size_t write_to_stream(void *s, const char *str, size_t len)
-{
- TSRMLS_FETCH();
- return php_stream_write(s, str, len);
-}
-#else
-# define write_to_stream (php_http_pass_callback_t)_php_stream_write
-#endif
-
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1)
ZEND_ARG_INFO(0, stream)
ZEND_END_ARG_INFO();
{
zval *zstream;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_stream *s;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_stream_from_zval(s, &zstream);
- php_http_message_to_callback(obj->message, write_to_stream, s);
+ php_stream_from_zval(s, zstream);
+ php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
}
}
{
php_http_pass_fcall_arg_t fcd;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fcd.fci, &fcd.fcc)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- fcd.fcz = getThis();
- Z_ADDREF_P(fcd.fcz);
- TSRMLS_SET_CTX(fcd.ts);
-
+ ZVAL_COPY(&fcd.fcz, getThis());
php_http_message_to_callback(obj->message, php_http_pass_fcall_callback, &fcd);
zend_fcall_info_args_clear(&fcd.fci, 1);
-
zval_ptr_dtor(&fcd.fcz);
+
RETURN_ZVAL(getThis(), 1, 0);
}
}
static PHP_METHOD(HttpMessage, serialize)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_serialize(obj->message, &string, &length);
- RETURN_STRINGL(string, length, 0);
+ RETURN_STR(php_http_cs2zs(string, length));
}
RETURN_EMPTY_STRING();
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, unserialize)
{
- int length;
+ size_t length;
char *serialized;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &length)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &length)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_message_t *msg;
if (obj->message) {
+ /* do not free recursively */
php_http_message_dtor(obj->message);
efree(obj->message);
}
- if ((msg = php_http_message_parse(NULL, serialized, (size_t) length, 1 TSRMLS_CC))) {
+ if ((msg = php_http_message_parse(NULL, serialized, length, 1))) {
obj->message = msg;
} else {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not unserialize http\\Message");
+ obj->message = php_http_message_init(NULL, 0, NULL);
+ php_error_docref(NULL, E_ERROR, "Could not unserialize http\\Message");
}
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, detach)
{
- php_http_message_object_t *obj;
+ php_http_message_object_t *obj, *new_obj;
+ php_http_message_t *msg_cpy;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
+ msg_cpy = php_http_message_copy_ex(obj->message, NULL, 0);
+ new_obj = php_http_message_object_new_ex(obj->zo.ce, msg_cpy);
+
+ RETVAL_OBJ(&new_obj->zo);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend, 0, 0, 1)
php_http_message_t *msg[2];
php_http_message_object_t *obj, *prepend_obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
+ prepend_obj = PHP_HTTP_OBJ(NULL, prepend);
PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj);
/* safety check */
}
}
- php_http_message_object_prepend(getThis(), prepend, top TSRMLS_CC);
+ php_http_message_object_prepend(getThis(), prepend, top);
RETURN_ZVAL(getThis(), 1, 0);
}
{
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- php_http_message_object_reverse(getThis(), return_value TSRMLS_CC);
+ php_http_message_object_reverse(getThis(), return_value);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart, 0, 0, 0)
{
zval *zboundary = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &zboundary)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zboundary)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *boundary = NULL;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- RETVAL_BOOL(php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL));
+ if (php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL)) {
+ RETVAL_TRUE;
+ } else {
+ RETVAL_FALSE;
+ }
if (zboundary && boundary) {
+ ZVAL_DEREF(zboundary);
zval_dtor(zboundary);
- ZVAL_STRING(zboundary, boundary, 0);
+ ZVAL_STR(zboundary, php_http_cs2zs(boundary, strlen(boundary)));
}
}
}
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!php_http_message_is_multipart(obj->message, &boundary)) {
PTR_FREE(boundary);
- RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
+ RETURN_OBJ(&php_http_message_object_new_ex(obj->zo.ce, msg)->zo);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, count)
{
- long count_mode = -1;
+ zend_long count_mode = -1;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &count_mode)) {
- long i = 0;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &count_mode)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_message_count(i, obj->message);
- RETURN_LONG(i);
+ RETURN_LONG(php_http_message_count(obj->message));
}
}
{
if (SUCCESS == zend_parse_parameters_none()) {
zval *zobj = getThis();
- php_http_message_object_t *obj = zend_object_store_get_object(zobj TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- if (obj->iterator) {
+ if (!Z_ISUNDEF(obj->iterator)) {
zval_ptr_dtor(&obj->iterator);
}
- Z_ADDREF_P(zobj);
- obj->iterator = zobj;
+ ZVAL_COPY(&obj->iterator, zobj);
}
}
static PHP_METHOD(HttpMessage, valid)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- RETURN_BOOL(obj->iterator != NULL);
+ RETURN_BOOL(!Z_ISUNDEF(obj->iterator));
}
}
static PHP_METHOD(HttpMessage, next)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+
+ if (!Z_ISUNDEF(obj->iterator)) {
+ php_http_message_object_t *itr = PHP_HTTP_OBJ(NULL, &obj->iterator);
- if (obj->iterator) {
- php_http_message_object_t *itr = zend_object_store_get_object(obj->iterator TSRMLS_CC);
+ if (itr->parent) {
+ zval tmp;
- if (itr && itr->parent) {
- zval *old = obj->iterator;
- MAKE_STD_ZVAL(obj->iterator);
- ZVAL_OBJVAL(obj->iterator, itr->parent->zv, 1);
- zval_ptr_dtor(&old);
+ ZVAL_OBJECT(&tmp, &itr->parent->zo, 1);
+ zval_ptr_dtor(&obj->iterator);
+ obj->iterator = tmp;
} else {
zval_ptr_dtor(&obj->iterator);
- obj->iterator = NULL;
+ ZVAL_UNDEF(&obj->iterator);
}
}
}
static PHP_METHOD(HttpMessage, key)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- RETURN_LONG(obj->iterator ? obj->iterator->value.obj.handle:0);
+ RETURN_LONG(Z_ISUNDEF(obj->iterator) ? 0 : Z_OBJ_HANDLE(obj->iterator));
}
}
static PHP_METHOD(HttpMessage, current)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- if (obj->iterator) {
- RETURN_ZVAL(obj->iterator, 1, 0);
+ if (!Z_ISUNDEF(obj->iterator)) {
+ RETURN_ZVAL(&obj->iterator, 1, 0);
}
}
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_message_class_entry;
-
PHP_MINIT_FUNCTION(http_message)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Message", php_http_message_methods);
- php_http_message_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_message_class_entry = zend_register_internal_class(&ce);
php_http_message_class_entry->create_object = php_http_message_object_new;
memcpy(&php_http_message_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_message_object_handlers.offset = XtOffsetOf(php_http_message_object_t, zo);
php_http_message_object_handlers.clone_obj = php_http_message_object_clone;
+ php_http_message_object_handlers.free_obj = php_http_message_object_free;
php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
- php_http_message_object_handlers.get_properties = php_http_message_object_get_props;
+ php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
php_http_message_object_handlers.get_property_ptr_ptr = NULL;
- zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
+ zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
- zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1);
- zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, php_http_message_object_prophandler_hash_dtor, 1);
+ zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status);
- zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED);
php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message);
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE);
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST);
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE);
return SUCCESS;
}
#define PHP_HTTP_MESSAGE_H
#include "php_http_message_body.h"
+#include "php_http_header.h"
/* required minimum length of an HTTP message "HTTP/1.1" */
#define PHP_HTTP_MESSAGE_MIN_SIZE 8
php_http_message_body_t *body;
php_http_message_t *parent;
void *opaque;
-#ifdef ZTS
- void ***ts;
-#endif
};
-PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC);
+PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info);
-PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *m, php_http_message_type_t t, php_http_message_body_t *body TSRMLS_DC);
-PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m, php_http_message_type_t t TSRMLS_DC);
-PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to);
+PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *m, php_http_message_type_t t, php_http_message_body_t *body);
+PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *m, php_http_message_type_t t);
PHP_HTTP_API php_http_message_t *php_http_message_copy_ex(php_http_message_t *from, php_http_message_t *to, zend_bool parents);
+static inline php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to)
+{
+ return php_http_message_copy_ex(from, to, 1);
+}
+
PHP_HTTP_API void php_http_message_dtor(php_http_message_t *message);
PHP_HTTP_API void php_http_message_free(php_http_message_t **message);
PHP_HTTP_API void php_http_message_update_headers(php_http_message_t *msg);
-PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join);
+PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len);
+
+static inline zend_string *php_http_message_header_string(php_http_message_t *msg, const char *key_str, size_t key_len)
+{
+ zval *header;
+
+ if ((header = php_http_message_header(msg, key_str, key_len))) {
+ return php_http_header_value_to_string(header);
+ }
+ return NULL;
+}
+
PHP_HTTP_API zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary);
PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length);
PHP_HTTP_API php_http_message_t *php_http_message_reverse(php_http_message_t *msg);
PHP_HTTP_API php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two);
-#define php_http_message_count(c, m) \
-{ \
- php_http_message_t *__tmp_msg = (m); \
- for (c = 0; __tmp_msg; __tmp_msg = __tmp_msg->parent, ++(c)); \
+static inline size_t php_http_message_count(php_http_message_t *m)
+{
+ size_t c = 1;
+
+ while ((m = m->parent)) {
+ ++c;
+ }
+
+ return c;
}
-PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC);
+PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy);
typedef struct php_http_message_object {
- zend_object zo;
- zend_object_value zv;
php_http_message_t *message;
struct php_http_message_object *parent;
php_http_message_body_object_t *body;
- zval *iterator;
+ zval iterator;
+ zend_object zo;
} php_http_message_object_t;
-PHP_HTTP_API zend_class_entry *php_http_message_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_message_get_class_entry(void);
PHP_MINIT_FUNCTION(http_message);
PHP_MSHUTDOWN_FUNCTION(http_message);
-void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top /* = 1 */ TSRMLS_DC);
-void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC);
-ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *obj, zval *zbody TSRMLS_DC);
+void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top /* = 1 */);
+void php_http_message_object_reverse(zval *this_ptr, zval *return_value);
+ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *obj, zval *zbody);
ZEND_RESULT_CODE php_http_message_object_init_body_object(php_http_message_object_t *obj);
-zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC);
-zend_object_value php_http_message_object_clone(zval *object TSRMLS_DC);
-void php_http_message_object_free(void *object TSRMLS_DC);
+zend_object *php_http_message_object_new(zend_class_entry *ce);
+php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg);
+zend_object *php_http_message_object_clone(zval *object);
+void php_http_message_object_free(zend_object *object);
#endif
#define BOUNDARY_CLOSE(body) \
php_http_message_body_appendf(body, PHP_HTTP_CRLF "--%s--" PHP_HTTP_CRLF, php_http_message_body_boundary(body))
-static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, const char *name, zval *value);
-static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const char *name, zval *value);
+static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, const char *name, HashTable *fields);
+static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const char *name, HashTable *files);
-php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body_ptr, php_stream *stream TSRMLS_DC)
+php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body_ptr, php_stream *stream)
{
php_http_message_body_t *body;
if (body_ptr && *body_ptr) {
body = *body_ptr;
- ++body->refcount;
+ php_http_message_body_addref(body);
return body;
}
body->refcount = 1;
if (stream) {
- php_stream_auto_cleanup(stream);
- body->stream_id = php_stream_get_resource_id(stream);
- zend_list_addref(body->stream_id);
+ body->res = stream->res;
+ ++GC_REFCOUNT(body->res);
} else {
stream = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff);
- php_stream_auto_cleanup(stream);
- body->stream_id = php_stream_get_resource_id(stream);
+ body->res = stream->res;
}
- TSRMLS_SET_CTX(body->ts);
+ php_stream_auto_cleanup(stream);
if (body_ptr) {
*body_ptr = body;
php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to)
{
if (from) {
- TSRMLS_FETCH_FROM_CTX(from->ts);
-
if (to) {
php_stream_truncate_set_size(php_http_message_body_stream(to), 0);
} else {
- to = php_http_message_body_init(NULL, NULL TSRMLS_CC);
+ to = php_http_message_body_init(NULL, NULL);
}
php_http_message_body_to_stream(from, php_http_message_body_stream(to), 0, 0);
php_http_message_body_t *body = *body_ptr;
if (!--body->refcount) {
- TSRMLS_FETCH_FROM_CTX(body->ts);
- /* NOFIXME: shows leakinfo in DEBUG mode */
- zend_list_delete(body->stream_id);
+ zend_list_delete(body->res);
PTR_FREE(body->boundary);
efree(body);
}
const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body)
{
- TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_stat(php_http_message_body_stream(body), &body->ssb);
return &body->ssb;
}
{
if (!body->boundary) {
union { double dbl; int num[2]; } data;
- TSRMLS_FETCH_FROM_CTX(body->ts);
- data.dbl = php_combined_lcg(TSRMLS_C);
+ data.dbl = php_combined_lcg();
spprintf(&body->boundary, 0, "%x.%x", data.num[0], data.num[1]);
}
return body->boundary;
{
php_http_etag_t *etag;
php_stream *s = php_http_message_body_stream(body);
- TSRMLS_FETCH_FROM_CTX(body->ts);
/* real file or temp buffer ? */
if (s->ops != &php_stream_temp_ops && s->ops != &php_stream_memory_ops) {
}
/* content based */
- if ((etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode TSRMLS_CC))) {
+ if ((etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode))) {
php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0);
return php_http_etag_finish(etag);
}
return NULL;
}
-void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen)
+zend_string *php_http_message_body_to_string(php_http_message_body_t *body, off_t offset, size_t forlen)
{
php_stream *s = php_http_message_body_stream(body);
- TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_seek(s, offset, SEEK_SET);
if (!forlen) {
forlen = -1;
}
- *len = php_stream_copy_to_mem(s, buf, forlen, 0);
+ return php_stream_copy_to_mem(s, forlen, 0);
}
ZEND_RESULT_CODE php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *dst, off_t offset, size_t forlen)
{
php_stream *s = php_http_message_body_stream(body);
- TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_seek(s, offset, SEEK_SET);
{
php_stream *s = php_http_message_body_stream(body);
char *buf = emalloc(0x1000);
- TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_seek(s, offset, SEEK_SET);
{
php_stream *s;
size_t written;
- TSRMLS_FETCH_FROM_CTX(body->ts);
if (!(s = php_http_message_body_stream(body))) {
return -1;
written = php_stream_write(s, buf, len);
if (written != len) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to append %zu bytes to body; wrote %zu", len, written);
+ php_error_docref(NULL, E_WARNING, "Failed to append %zu bytes to body; wrote %zu", len, written);
}
return len;
ZEND_RESULT_CODE php_http_message_body_add_form(php_http_message_body_t *body, HashTable *fields, HashTable *files)
{
- zval tmp;
-
if (fields) {
- INIT_PZVAL_ARRAY(&tmp, fields);
- if (SUCCESS != add_recursive_fields(body, NULL, &tmp)) {
+ if (SUCCESS != add_recursive_fields(body, NULL, fields)) {
return FAILURE;
}
}
if (files) {
- INIT_PZVAL_ARRAY(&tmp, files);
- if (SUCCESS != add_recursive_files(body, NULL, &tmp)) {
+ if (SUCCESS != add_recursive_files(body, NULL, files)) {
return FAILURE;
}
}
void php_http_message_body_add_part(php_http_message_body_t *body, php_http_message_t *part)
{
- TSRMLS_FETCH_FROM_CTX(body->ts);
-
BOUNDARY_OPEN(body);
php_http_message_to_callback(part, (php_http_pass_callback_t) php_http_message_body_append, body);
BOUNDARY_CLOSE(body);
ZEND_RESULT_CODE php_http_message_body_add_form_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len)
{
- char *safe_name;
- TSRMLS_FETCH_FROM_CTX(body->ts);
+ zend_string *safe_name = zend_string_init(name, strlen(name), 0);
- safe_name = php_addslashes(estrdup(name), strlen(name), NULL, 1 TSRMLS_CC);
+ safe_name = php_addslashes(safe_name, 1);
BOUNDARY_OPEN(body);
php_http_message_body_appendf(
body,
"Content-Disposition: form-data; name=\"%s\"" PHP_HTTP_CRLF
"" PHP_HTTP_CRLF,
- safe_name
+ safe_name->val
);
php_http_message_body_append(body, value_str, value_len);
BOUNDARY_CLOSE(body);
- efree(safe_name);
+ zend_string_release(safe_name);
return SUCCESS;
}
ZEND_RESULT_CODE php_http_message_body_add_form_file(php_http_message_body_t *body, const char *name, const char *ctype, const char *path, php_stream *in)
{
- char *safe_name, *path_dup = estrdup(path), *bname;
- size_t bname_len;
- TSRMLS_FETCH_FROM_CTX(body->ts);
+ size_t path_len = strlen(path);
+ char *path_dup = estrndup(path, path_len);
+ zend_string *base_name, *safe_name = zend_string_init(name, strlen(name), 0);
- safe_name = php_addslashes(estrdup(name), strlen(name), NULL, 1 TSRMLS_CC);
-
- php_basename(path_dup, strlen(path_dup), NULL, 0, &bname, &bname_len TSRMLS_CC);
+ safe_name = php_addslashes(safe_name, 1);
+ base_name = php_basename(path_dup, path_len, NULL, 0);
BOUNDARY_OPEN(body);
php_http_message_body_appendf(
"Content-Transfer-Encoding: binary" PHP_HTTP_CRLF
"Content-Type: %s" PHP_HTTP_CRLF
PHP_HTTP_CRLF,
- safe_name, bname, ctype
+ safe_name->val, base_name->val, ctype
);
php_stream_copy_to_stream_ex(in, php_http_message_body_stream(body), PHP_STREAM_COPY_ALL, NULL);
BOUNDARY_CLOSE(body);
- efree(safe_name);
+ zend_string_release(safe_name);
+ zend_string_release(base_name);
efree(path_dup);
- efree(bname);
return SUCCESS;
}
-static inline char *format_key(uint type, char *str, ulong num, const char *prefix) {
+static inline char *format_key(php_http_arrkey_t *key, const char *prefix) {
char *new_key = NULL;
if (prefix && *prefix) {
- if (type == HASH_KEY_IS_STRING) {
- spprintf(&new_key, 0, "%s[%s]", prefix, str);
+ if (key->key) {
+ spprintf(&new_key, 0, "%s[%s]", prefix, key->key->val);
} else {
- spprintf(&new_key, 0, "%s[%lu]", prefix, num);
+ spprintf(&new_key, 0, "%s[%lu]", prefix, key->h);
}
- } else if (type == HASH_KEY_IS_STRING) {
- new_key = estrdup(str);
+ } else if (key->key) {
+ new_key = estrdup(key->key->val);
} else {
new_key = estrdup("");
}
return new_key;
}
-static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, const char *name, zval *value)
+static ZEND_RESULT_CODE add_recursive_field_value(php_http_message_body_t *body, const char *name, zval *value)
+{
+ zend_string *zs = zval_get_string(value);
+ ZEND_RESULT_CODE rc = php_http_message_body_add_form_field(body, name, zs->val, zs->len);
+ zend_string_release(zs);
+ return rc;
+}
+
+static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, const char *name, HashTable *fields)
{
- if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
- zval **val;
- HashTable *ht;
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- TSRMLS_FETCH_FROM_CTX(body->ts);
+ zval *val;
+ php_http_arrkey_t key;
- ht = HASH_OF(value);
- if (!ht->nApplyCount) {
- ++ht->nApplyCount;
- FOREACH_KEYVAL(pos, value, key, val) {
- char *str = format_key(key.type, key.str, key.num, name);
- if (SUCCESS != add_recursive_fields(body, str, *val)) {
+ if (!ZEND_HASH_GET_APPLY_COUNT(fields)) {
+ ZEND_HASH_INC_APPLY_COUNT(fields);
+ ZEND_HASH_FOREACH_KEY_VAL_IND(fields, key.h, key.key, val)
+ {
+ char *str = format_key(&key, name);
+
+ if (Z_TYPE_P(val) != IS_ARRAY && Z_TYPE_P(val) != IS_OBJECT) {
+ if (SUCCESS != add_recursive_field_value(body, str, val)) {
efree(str);
- ht->nApplyCount--;
+ ZEND_HASH_DEC_APPLY_COUNT(fields);
return FAILURE;
}
+ } else if (SUCCESS != add_recursive_fields(body, str, HASH_OF(val))) {
efree(str);
+ ZEND_HASH_DEC_APPLY_COUNT(fields);
+ return FAILURE;
}
- --ht->nApplyCount;
+ efree(str);
}
- } else {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- php_http_message_body_add_form_field(body, name, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
+ ZEND_HASH_FOREACH_END();
+ ZEND_HASH_DEC_APPLY_COUNT(fields);
}
return SUCCESS;
}
-static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const char *name, zval *value)
+static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const char *name, HashTable *files)
{
- zval **zdata = NULL, **zfile, **zname, **ztype;
- HashTable *ht;
- TSRMLS_FETCH_FROM_CTX(body->ts);
-
- if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array or object (name, type, file) for message body file to add");
- return FAILURE;
- }
+ zval *zdata = NULL, *zfile, *zname, *ztype;
- ht = HASH_OF(value);
-
- if ((SUCCESS != zend_hash_find(ht, ZEND_STRS("name"), (void *) &zname))
- || (SUCCESS != zend_hash_find(ht, ZEND_STRS("type"), (void *) &ztype))
- || (SUCCESS != zend_hash_find(ht, ZEND_STRS("file"), (void *) &zfile))
+ /* single entry */
+ if (!(zname = zend_hash_str_find(files, ZEND_STRL("name")))
+ || !(ztype = zend_hash_str_find(files, ZEND_STRL("type")))
+ || !(zfile = zend_hash_str_find(files, ZEND_STRL("file")))
) {
- zval **val;
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval *val;
+ php_http_arrkey_t key;
- if (!ht->nApplyCount) {
- ++ht->nApplyCount;
- FOREACH_HASH_KEYVAL(pos, ht, key, val) {
- if (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT) {
- char *str = format_key(key.type, key.str, key.num, name);
+ if (!ZEND_HASH_GET_APPLY_COUNT(files)) {
+ ZEND_HASH_INC_APPLY_COUNT(files);
+ ZEND_HASH_FOREACH_KEY_VAL_IND(files, key.h, key.key, val)
+ {
+ if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) {
+ char *str = format_key(&key, name);
- if (SUCCESS != add_recursive_files(body, str, *val)) {
+ if (SUCCESS != add_recursive_files(body, str, HASH_OF(val))) {
efree(str);
- --ht->nApplyCount;
+ ZEND_HASH_DEC_APPLY_COUNT(files);
return FAILURE;
}
efree(str);
}
}
- --ht->nApplyCount;
+ ZEND_HASH_FOREACH_END();
+ ZEND_HASH_DEC_APPLY_COUNT(files);
}
return SUCCESS;
} else {
+ /* stream entry */
php_stream *stream;
- zval *zfc = php_http_ztyp(IS_STRING, *zfile);
+ zend_string *zfc = zval_get_string(zfile);
- if (SUCCESS == zend_hash_find(ht, ZEND_STRS("data"), (void *) &zdata)) {
- if (Z_TYPE_PP(zdata) == IS_RESOURCE) {
+ if ((zdata = zend_hash_str_find(files, ZEND_STRL("data")))) {
+ if (Z_TYPE_P(zdata) == IS_RESOURCE) {
php_stream_from_zval_no_verify(stream, zdata);
} else {
- zval *tmp = php_http_ztyp(IS_STRING, *zdata);
+ zend_string *tmp = zval_get_string(zdata);
- stream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
- zval_ptr_dtor(&tmp);
+ stream = php_stream_memory_open(TEMP_STREAM_READONLY, tmp->val, tmp->len);
+ zend_string_release(tmp);
}
} else {
- stream = php_stream_open_wrapper(Z_STRVAL_P(zfc), "r", REPORT_ERRORS|USE_PATH, NULL);
+ stream = php_stream_open_wrapper(zfc->val, "r", REPORT_ERRORS|USE_PATH, NULL);
}
if (!stream) {
- zval_ptr_dtor(&zfc);
+ zend_string_release(zfc);
return FAILURE;
} else {
- zval *znc = php_http_ztyp(IS_STRING, *zname), *ztc = php_http_ztyp(IS_STRING, *ztype);
- char *key = format_key(HASH_KEY_IS_STRING, Z_STRVAL_P(znc), 0, name);
- ZEND_RESULT_CODE ret = php_http_message_body_add_form_file(body, key, Z_STRVAL_P(ztc), Z_STRVAL_P(zfc), stream);
+ zend_string *znc = zval_get_string(zname), *ztc = zval_get_string(ztype);
+ php_http_arrkey_t arrkey = {0, znc};
+ char *key = format_key(&arrkey, name);
+ ZEND_RESULT_CODE ret = php_http_message_body_add_form_file(body, key, ztc->val, zfc->val, stream);
efree(key);
- zval_ptr_dtor(&znc);
- zval_ptr_dtor(&ztc);
- zval_ptr_dtor(&zfc);
- if (!zdata || Z_TYPE_PP(zdata) != IS_RESOURCE) {
+ zend_string_release(znc);
+ zend_string_release(ztc);
+ zend_string_release(zfc);
+ if (!zdata || Z_TYPE_P(zdata) != IS_RESOURCE) {
php_stream_close(stream);
}
return ret;
size_t consumed;
};
-static size_t splitbody(void *opaque, char *buf, size_t len TSRMLS_DC)
+static size_t splitbody(void *opaque, char *buf, size_t len)
{
struct splitbody_arg *arg = opaque;
const char *boundary = NULL;
/* advance messages */
php_http_message_t *msg;
- msg = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
+ msg = php_http_message_init(NULL, 0, NULL);
msg->parent = arg->parser->message;
arg->parser->message = msg;
}
len = 0;
} else {
/* let this be garbage */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Malformed multipart boundary at pos %zu", consumed);
+ php_error_docref(NULL, E_WARNING, "Malformed multipart boundary at pos %zu", consumed);
return -1;
}
}
php_http_buffer_t *tmp = NULL;
php_http_message_t *msg = NULL;
struct splitbody_arg arg;
- TSRMLS_FETCH_FROM_CTX(body->ts);
php_http_buffer_init(&arg.buf);
- arg.parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ arg.parser = php_http_message_parser_init(NULL);
arg.boundary_len = spprintf(&arg.boundary_str, 0, "\n--%s", boundary);
arg.consumed = 0;
php_stream_rewind(s);
while (!php_stream_eof(s)) {
- php_http_buffer_passthru(&tmp, 0x1000, (php_http_buffer_pass_func_t) _php_stream_read, s, splitbody, &arg TSRMLS_CC);
+ php_http_buffer_passthru(&tmp, 0x1000, (php_http_buffer_pass_func_t) _php_stream_read, s, splitbody, &arg);
}
msg = arg.parser->message;
return msg;
}
+static zend_class_entry *php_http_message_body_class_entry;
+zend_class_entry *php_http_get_message_body_class_entry(void)
+{
+ return php_http_message_body_class_entry;
+}
+
static zend_object_handlers php_http_message_body_object_handlers;
-zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_message_body_object_new(zend_class_entry *ce)
{
- return php_http_message_body_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_message_body_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body, php_http_message_body_object_t **ptr TSRMLS_DC)
+php_http_message_body_object_t *php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body)
{
php_http_message_body_object_t *o;
- o = ecalloc(1, sizeof(php_http_message_body_object_t));
- zend_object_std_init((zend_object *) o, php_http_message_body_class_entry TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
-
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, php_http_message_body_class_entry);
+ object_properties_init(&o->zo, ce);
if (body) {
o->body = body;
}
- o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_body_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_message_body_object_handlers;
+ o->zo.handlers = &php_http_message_body_object_handlers;
- return o->zv;
+ return o;
}
-zend_object_value php_http_message_body_object_clone(zval *object TSRMLS_DC)
+zend_object *php_http_message_body_object_clone(zval *object)
{
- zend_object_value new_ov;
php_http_message_body_object_t *new_obj = NULL;
- php_http_message_body_object_t *old_obj = zend_object_store_get_object(object TSRMLS_CC);
+ php_http_message_body_object_t *old_obj = PHP_HTTP_OBJ(NULL, object);
php_http_message_body_t *body = php_http_message_body_copy(old_obj->body, NULL);
- new_ov = php_http_message_body_object_new_ex(old_obj->zo.ce, body, &new_obj TSRMLS_CC);
- zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
+ new_obj = php_http_message_body_object_new_ex(old_obj->zo.ce, body);
+ zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
- return new_ov;
+ return &new_obj->zo;
}
-void php_http_message_body_object_free(void *object TSRMLS_DC)
+void php_http_message_body_object_free(zend_object *object)
{
- php_http_message_body_object_t *obj = object;
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(object, NULL);
php_http_message_body_free(&obj->body);
- zend_object_std_dtor((zend_object *) obj TSRMLS_CC);
- efree(obj);
+ zend_object_std_dtor(object);
}
#define PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj) \
do { \
if (!obj->body) { \
- obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC); \
+ obj->body = php_http_message_body_init(NULL, NULL); \
} \
} while(0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpMessageBody, __construct)
{
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zval *zstream = NULL;
php_stream *stream;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r!", &zstream), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &zstream), invalid_arg, return);
if (zstream) {
- php_http_expect(php_stream_from_zval_no_verify(stream, &zstream), unexpected_val, return);
+ php_http_expect(php_stream_from_zval_no_verify(stream, zstream), unexpected_val, return);
if (obj->body) {
php_http_message_body_free(&obj->body);
}
- obj->body = php_http_message_body_init(NULL, stream TSRMLS_CC);
+ obj->body = php_http_message_body_init(NULL, stream);
}
}
PHP_METHOD(HttpMessageBody, __toString)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- char *str;
- size_t len;
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+ zend_string *zs;
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- php_http_message_body_to_string(obj->body, &str, &len, 0, 0);
- if (str) {
- RETURN_STRINGL(str, len, 0);
+ zs = php_http_message_body_to_string(obj->body, 0, 0);
+ if (zs) {
+ RETURN_STR(zs);
}
}
RETURN_EMPTY_STRING();
PHP_METHOD(HttpMessageBody, unserialize)
{
char *us_str;
- int us_len;
+ size_t us_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &us_str, &us_len)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &us_str, &us_len)) {
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_stream *s = php_stream_memory_open(0, us_str, us_len);
- obj->body = php_http_message_body_init(NULL, s TSRMLS_CC);
+ obj->body = php_http_message_body_init(NULL, s);
}
}
PHP_METHOD(HttpMessageBody, toStream)
{
zval *zstream;
- long offset = 0, forlen = 0;
+ zend_long offset = 0, forlen = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zstream, &offset, &forlen)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "r|ll", &zstream, &offset, &forlen)) {
php_stream *stream;
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- php_stream_from_zval(stream, &zstream);
+ php_stream_from_zval(stream, zstream);
php_http_message_body_to_stream(obj->body, stream, offset, forlen);
RETURN_ZVAL(getThis(), 1, 0);
}
PHP_METHOD(HttpMessageBody, toCallback)
{
php_http_pass_fcall_arg_t fcd;
- long offset = 0, forlen = 0;
+ zend_long offset = 0, forlen = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|ll", &fcd.fci, &fcd.fcc, &offset, &forlen)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "f|ll", &fcd.fci, &fcd.fcc, &offset, &forlen)) {
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- fcd.fcz = getThis();
- Z_ADDREF_P(fcd.fcz);
- TSRMLS_SET_CTX(fcd.ts);
-
+ ZVAL_COPY(&fcd.fcz, getThis());
php_http_message_body_to_callback(obj->body, php_http_pass_fcall_callback, &fcd, offset, forlen);
zend_fcall_info_args_clear(&fcd.fci, 1);
-
zval_ptr_dtor(&fcd.fcz);
RETURN_ZVAL(getThis(), 1, 0);
}
PHP_METHOD(HttpMessageBody, getResource)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- zend_list_addref(obj->body->stream_id);
- RETVAL_RESOURCE(obj->body->stream_id);
+ ++GC_REFCOUNT(obj->body->res);
+ RETVAL_RES(obj->body->res);
}
}
PHP_METHOD(HttpMessageBody, getBoundary)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_body_object_t * obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_body_object_t * obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
if (obj->body->boundary) {
- RETURN_STRING(obj->body->boundary, 1);
+ RETURN_STRING(obj->body->boundary);
}
}
}
PHP_METHOD(HttpMessageBody, append)
{
char *str;
- int len;
+ size_t len;
php_http_message_body_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len), invalid_arg, return);
-
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
php_http_expect(len == php_http_message_body_append(obj->body, str, len), runtime, return);
HashTable *fields = NULL, *files = NULL;
php_http_message_body_object_t *obj;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h!h!", &fields, &files), invalid_arg, return);
-
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|h!h!", &fields, &files), invalid_arg, return);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
php_http_expect(SUCCESS == php_http_message_body_add_form(obj->body, fields, files), runtime, return);
php_http_message_object_t *mobj;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobj, php_http_message_class_entry), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zobj, php_http_message_get_class_entry()), invalid_arg, return);
- obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- mobj = zend_object_store_get_object(zobj TSRMLS_CC);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ mobj = PHP_HTTP_OBJ(NULL, zobj);
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh);
php_http_message_body_add_part(obj->body, mobj->message);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
if (!EG(exception)) {
RETURN_ZVAL(getThis(), 1, 0);
PHP_METHOD(HttpMessageBody, etag)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *etag;
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
if ((etag = php_http_message_body_etag(obj->body))) {
- RETURN_STRING(etag, 0);
+ RETURN_STR(php_http_cs2zs(etag, strlen(etag)));
} else {
RETURN_FALSE;
}
PHP_METHOD(HttpMessageBody, stat)
{
char *field_str = NULL;
- int field_len = 0;
+ size_t field_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &field_str, &field_len)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &field_str, &field_len)) {
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
const php_stream_statbuf *sb;
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
RETURN_LONG(sb->sb.st_ctime);
break;
default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown stat field: '%s' (should be one of [s]ize, [a]time, [m]time or [c]time)", field_str);
+ php_error_docref(NULL, E_WARNING, "Unknown stat field: '%s' (should be one of [s]ize, [a]time, [m]time or [c]time)", field_str);
break;
}
} else {
object_init(return_value);
- add_property_long_ex(return_value, ZEND_STRS("size"), sb->sb.st_size TSRMLS_CC);
- add_property_long_ex(return_value, ZEND_STRS("atime"), sb->sb.st_atime TSRMLS_CC);
- add_property_long_ex(return_value, ZEND_STRS("mtime"), sb->sb.st_mtime TSRMLS_CC);
- add_property_long_ex(return_value, ZEND_STRS("ctime"), sb->sb.st_ctime TSRMLS_CC);
+ add_property_long_ex(return_value, ZEND_STRL("size"), sb->sb.st_size);
+ add_property_long_ex(return_value, ZEND_STRL("atime"), sb->sb.st_atime);
+ add_property_long_ex(return_value, ZEND_STRL("mtime"), sb->sb.st_mtime);
+ add_property_long_ex(return_value, ZEND_STRL("ctime"), sb->sb.st_ctime);
}
}
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_message_body_class_entry;
-
PHP_MINIT_FUNCTION(http_message_body)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Message", "Body", php_http_message_body_methods);
- php_http_message_body_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_message_body_class_entry = zend_register_internal_class(&ce);
php_http_message_body_class_entry->create_object = php_http_message_body_object_new;
memcpy(&php_http_message_body_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_message_body_object_handlers.offset = XtOffsetOf(php_http_message_body_object_t, zo);
php_http_message_body_object_handlers.clone_obj = php_http_message_body_object_clone;
- zend_class_implements(php_http_message_body_class_entry TSRMLS_CC, 1, zend_ce_serializable);
+ php_http_message_body_object_handlers.free_obj = php_http_message_body_object_free;
+ zend_class_implements(php_http_message_body_class_entry, 1, zend_ce_serializable);
return SUCCESS;
}
#define PHP_HTTP_MESSAGE_BODY_H
typedef struct php_http_message_body {
- int stream_id;
php_stream_statbuf ssb;
+ zend_resource *res;
char *boundary;
unsigned refcount;
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_message_body_t;
struct php_http_message;
-PHP_HTTP_API php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body, php_stream *stream TSRMLS_DC);
+PHP_HTTP_API php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body, php_stream *stream);
PHP_HTTP_API unsigned php_http_message_body_addref(php_http_message_body_t *body);
PHP_HTTP_API php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to);
PHP_HTTP_API ZEND_RESULT_CODE php_http_message_body_add_form(php_http_message_body_t *body, HashTable *fields, HashTable *files);
PHP_HTTP_API void php_http_message_body_add_part(php_http_message_body_t *body, struct php_http_message *part);
PHP_HTTP_API size_t php_http_message_body_append(php_http_message_body_t *body, const char *buf, size_t len);
PHP_HTTP_API size_t php_http_message_body_appendf(php_http_message_body_t *body, const char *fmt, ...);
-PHP_HTTP_API void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen);
+PHP_HTTP_API zend_string *php_http_message_body_to_string(php_http_message_body_t *body, off_t offset, size_t forlen);
PHP_HTTP_API ZEND_RESULT_CODE php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *s, off_t offset, size_t forlen);
PHP_HTTP_API ZEND_RESULT_CODE php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen);
PHP_HTTP_API void php_http_message_body_free(php_http_message_body_t **body);
PHP_HTTP_API const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body);
-#define php_http_message_body_size(b) (php_http_message_body_stat((b))->sb.st_size)
-#define php_http_message_body_mtime(b) (php_http_message_body_stat((b))->sb.st_mtime)
PHP_HTTP_API char *php_http_message_body_etag(php_http_message_body_t *body);
PHP_HTTP_API const char *php_http_message_body_boundary(php_http_message_body_t *body);
PHP_HTTP_API struct php_http_message *php_http_message_body_split(php_http_message_body_t *body, const char *boundary);
+static inline size_t php_http_message_body_size(php_http_message_body_t *b)
+{
+ return php_http_message_body_stat(b)->sb.st_size;
+}
+
+static inline time_t php_http_message_body_mtime(php_http_message_body_t *b)
+{
+ return php_http_message_body_stat(b)->sb.st_mtime;
+}
+
static inline php_stream *php_http_message_body_stream(php_http_message_body_t *body)
{
- TSRMLS_FETCH_FROM_CTX(body->ts);
- return zend_fetch_resource(NULL TSRMLS_CC, body->stream_id, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream());
+ return body->res->ptr;
}
typedef struct php_http_message_body_object {
- zend_object zo;
- zend_object_value zv;
php_http_message_body_t *body;
+ zend_object zo;
} php_http_message_body_object_t;
-PHP_HTTP_API zend_class_entry *php_http_message_body_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_message_body_class_entry(void);
PHP_MINIT_FUNCTION(http_message_body);
-zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body, php_http_message_body_object_t **ptr TSRMLS_DC);
-zend_object_value php_http_message_body_object_clone(zval *object TSRMLS_DC);
-void php_http_message_body_object_free(void *object TSRMLS_DC);
+zend_object *php_http_message_body_object_new(zend_class_entry *ce);
+php_http_message_body_object_t *php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body);
+zend_object *php_http_message_body_object_clone(zval *object);
+void php_http_message_body_object_free(zend_object *object);
#endif
}
#endif
-php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser TSRMLS_DC)
+php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser)
{
if (!parser) {
parser = emalloc(sizeof(*parser));
}
memset(parser, 0, sizeof(*parser));
- TSRMLS_SET_CTX(parser->ts);
-
- php_http_header_parser_init(&parser->header TSRMLS_CC);
+ php_http_header_parser_init(&parser->header);
return parser;
}
php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_message_parser_t *parser, php_http_buffer_t *buf, php_stream *s, unsigned flags, php_http_message_t **message)
{
php_http_message_parser_state_t state = PHP_HTTP_MESSAGE_PARSER_STATE_START;
- TSRMLS_FETCH_FROM_CTX(parser->ts);
if (!buf->data) {
php_http_buffer_resize_ex(buf, 0x1000, 1, 0);
char *str = NULL;
size_t len = 0;
size_t cut = 0;
- TSRMLS_FETCH_FROM_CTX(parser->ts);
while (buffer->used || !php_http_message_parser_states[php_http_message_parser_state_is(parser)].need_data) {
#if DBG_PARSER
case PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE:
{
- zval *h, *h_loc = NULL, *h_con = NULL, **h_cl = NULL, **h_cr = NULL, **h_te = NULL;
+ zval h, *h_ptr, *h_loc = NULL, *h_con = NULL, *h_ce;
+ zend_bool chunked = 0;
+ zend_long content_length = -1;
+ zend_string *content_range = NULL;
/* Content-Range has higher precedence than Content-Length,
* and content-length denotes the original length of the entity,
* so let's *NOT* remove CR/CL, because that would fundamentally
* change the meaning of the whole message
*/
- if ((h = php_http_message_header(*message, ZEND_STRL("Transfer-Encoding"), 1))) {
- zend_hash_update(&(*message)->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &h, sizeof(zval *), (void *) &h_te);
- zend_hash_del(&(*message)->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding"));
+ if ((h_ptr = php_http_message_header(*message, ZEND_STRL("Transfer-Encoding")))) {
+ zend_string *zs = zval_get_string(h_ptr);
+
+ chunked = zend_string_equals_literal(zs, "chunked");
+ zend_string_release(zs);
+
+ Z_TRY_ADDREF_P(h_ptr);
+ zend_hash_str_update(&(*message)->hdrs, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), h_ptr);
+ zend_hash_str_del(&(*message)->hdrs, "Transfer-Encoding", lenof("Transfer-Encoding"));
/* reset */
- MAKE_STD_ZVAL(h);
- ZVAL_LONG(h, 0);
- zend_hash_update(&(*message)->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &h, sizeof(zval *), NULL);
- } else if ((h = php_http_message_header(*message, ZEND_STRL("Content-Length"), 1))) {
- zend_hash_update(&(*message)->hdrs, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), (void *) &h, sizeof(zval *), (void *) &h_cl);
+ ZVAL_LONG(&h, 0);
+ zend_hash_str_update(&(*message)->hdrs, "Content-Length", lenof("Content-Length"), &h);
+ } else if ((h_ptr = php_http_message_header(*message, ZEND_STRL("Content-Length")))) {
+ content_length = zval_get_long(h_ptr);
+ Z_TRY_ADDREF_P(h_ptr);
+ zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Length", lenof("X-Original-Content-Length"), h_ptr);
}
- if ((h = php_http_message_header(*message, ZEND_STRL("Content-Range"), 1))) {
- zend_hash_find(&(*message)->hdrs, ZEND_STRS("Content-Range"), (void *) &h_cr);
- if (h != *h_cr) {
- zend_hash_update(&(*message)->hdrs, "Content-Range", sizeof("Content-Range"), &h, sizeof(zval *), (void *) &h_cr);
- } else {
- zval_ptr_dtor(&h);
- }
+ if ((content_range = php_http_message_header_string(*message, ZEND_STRL("Content-Range")))) {
+ ZVAL_STR_COPY(&h, content_range);
+ zend_hash_str_update(&(*message)->hdrs, "Content-Range", lenof("Content-Range"), &h);
}
/* so, if curl sees a 3xx code, a Location header and a Connection:close header
if ((flags & PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS)
&& (*message)->type == PHP_HTTP_RESPONSE
&& (*message)->http.info.response.code/100 == 3
- && (h_loc = php_http_message_header(*message, ZEND_STRL("Location"), 1))
- && (h_con = php_http_message_header(*message, ZEND_STRL("Connection"), 1))
+ && (h_loc = php_http_message_header(*message, ZEND_STRL("Location")))
+ && (h_con = php_http_message_header(*message, ZEND_STRL("Connection")))
) {
- if (php_http_match(Z_STRVAL_P(h_con), "close", PHP_HTTP_MATCH_WORD)) {
+ zend_string *con = zval_get_string(h_con);
+
+ if (php_http_match(con->val, "close", PHP_HTTP_MATCH_WORD)) {
+ zend_string_release(con);
php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_DONE);
- zval_ptr_dtor(&h_loc);
- zval_ptr_dtor(&h_con);
break;
}
+ zend_string_release(con);
}
- if (h_loc) {
- zval_ptr_dtor(&h_loc);
- }
- if (h_con) {
- zval_ptr_dtor(&h_con);
- }
- if ((h = php_http_message_header(*message, ZEND_STRL("Content-Encoding"), 1))) {
- if (php_http_match(Z_STRVAL_P(h), "gzip", PHP_HTTP_MATCH_WORD)
- || php_http_match(Z_STRVAL_P(h), "x-gzip", PHP_HTTP_MATCH_WORD)
- || php_http_match(Z_STRVAL_P(h), "deflate", PHP_HTTP_MATCH_WORD)
+ if ((h_ce = php_http_message_header(*message, ZEND_STRL("Content-Encoding")))) {
+ zend_string *ce = zval_get_string(h_ce);
+
+ if (php_http_match(ce->val, "gzip", PHP_HTTP_MATCH_WORD)
+ || php_http_match(ce->val, "x-gzip", PHP_HTTP_MATCH_WORD)
+ || php_http_match(ce->val, "deflate", PHP_HTTP_MATCH_WORD)
) {
if (parser->inflate) {
php_http_encoding_stream_reset(&parser->inflate);
} else {
- parser->inflate = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), 0 TSRMLS_CC);
+ parser->inflate = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), 0);
}
- zend_hash_update(&(*message)->hdrs, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), &h, sizeof(zval *), NULL);
- zend_hash_del(&(*message)->hdrs, "Content-Encoding", sizeof("Content-Encoding"));
- } else {
- zval_ptr_dtor(&h);
+ Z_TRY_ADDREF_P(h_ce);
+ zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), h_ce);
+ zend_hash_str_del(&(*message)->hdrs, "Content-Encoding", lenof("Content-Encoding"));
}
+ zend_string_release(ce);
}
if ((flags & PHP_HTTP_MESSAGE_PARSER_DUMB_BODIES)) {
php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB);
} else {
- if (h_te) {
- if (strstr(Z_STRVAL_PP(h_te), "chunked")) {
- parser->dechunk = php_http_encoding_stream_init(parser->dechunk, php_http_encoding_stream_get_dechunk_ops(), 0 TSRMLS_CC);
- php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED);
- break;
- }
+ if (chunked) {
+ parser->dechunk = php_http_encoding_stream_init(parser->dechunk, php_http_encoding_stream_get_dechunk_ops(), 0);
+ php_http_message_parser_state_push(parser, 1, PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED);
+ break;
}
- if (h_cr) {
+ if (content_range) {
ulong total = 0, start = 0, end = 0;
- if (!strncasecmp(Z_STRVAL_PP(h_cr), "bytes", lenof("bytes"))
- && ( Z_STRVAL_PP(h_cr)[lenof("bytes")] == ':'
- || Z_STRVAL_PP(h_cr)[lenof("bytes")] == ' '
- || Z_STRVAL_PP(h_cr)[lenof("bytes")] == '='
+ if (!strncasecmp(content_range->val, "bytes", lenof("bytes"))
+ && ( content_range->val[lenof("bytes")] == ':'
+ || content_range->val[lenof("bytes")] == ' '
+ || content_range->val[lenof("bytes")] == '='
)
) {
char *total_at = NULL, *end_at = NULL;
- char *start_at = Z_STRVAL_PP(h_cr) + sizeof("bytes");
+ char *start_at = content_range->val + sizeof("bytes");
start = strtoul(start_at, &end_at, 10);
if (end_at) {
if (end >= start && (!total || end <= total)) {
parser->body_length = end + 1 - start;
php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH);
+ zend_string_release(content_range);
break;
}
}
}
- }
-
- if (h_cl) {
- char *stop;
- if (Z_TYPE_PP(h_cl) == IS_STRING) {
- parser->body_length = strtoul(Z_STRVAL_PP(h_cl), &stop, 10);
+ zend_string_release(content_range);
+ }
- if (stop != Z_STRVAL_PP(h_cl)) {
- php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH);
- break;
- }
- } else if (Z_TYPE_PP(h_cl) == IS_LONG) {
- parser->body_length = Z_LVAL_PP(h_cl);
- php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH);
- break;
- }
+ if (content_length >= 0) {
+ parser->body_length = content_length;
+ php_http_message_parser_state_push(parser, 1, !parser->body_length?PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE:PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH);
+ break;
}
if ((*message)->type == PHP_HTTP_REQUEST) {
case PHP_HTTP_MESSAGE_PARSER_STATE_BODY:
{
if (len) {
- /* FIXME: what if we re-use the parser? */
if (parser->inflate) {
char *dec_str = NULL;
size_t dec_len;
}
php_stream_write(php_http_message_body_stream((*message)->body), str, len);
-
}
if (cut) {
case PHP_HTTP_MESSAGE_PARSER_STATE_UPDATE_CL:
{
- zval *zcl;
- MAKE_STD_ZVAL(zcl);
- ZVAL_LONG(zcl, php_http_message_body_size((*message)->body));
- zend_hash_update(&(*message)->hdrs, "Content-Length", sizeof("Content-Length"), &zcl, sizeof(zval *), NULL);
+ zval zcl;
+
+ ZVAL_LONG(&zcl, php_http_message_body_size((*message)->body));
+ zend_hash_str_update(&(*message)->hdrs, "Content-Length", lenof("Content-Length"), &zcl);
break;
}
return php_http_message_parser_state_is(parser);
}
-zend_class_entry *php_http_message_parser_class_entry;
+static zend_class_entry *php_http_message_parser_class_entry;
+zend_class_entry *php_http_get_message_parser_class_entry(void)
+{
+ return php_http_message_parser_class_entry;
+}
static zend_object_handlers php_http_message_parser_object_handlers;
-zend_object_value php_http_message_parser_object_new(zend_class_entry *ce TSRMLS_DC)
+zend_object *php_http_message_parser_object_new(zend_class_entry *ce)
{
- return php_http_message_parser_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_message_parser_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_message_parser_object_new_ex(zend_class_entry *ce, php_http_message_parser_t *parser, php_http_message_parser_object_t **ptr TSRMLS_DC)
+php_http_message_parser_object_t *php_http_message_parser_object_new_ex(zend_class_entry *ce, php_http_message_parser_t *parser)
{
php_http_message_parser_object_t *o;
- o = ecalloc(1, sizeof(php_http_message_parser_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
-
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
if (parser) {
o->parser = parser;
} else {
- o->parser = php_http_message_parser_init(NULL TSRMLS_CC);
+ o->parser = php_http_message_parser_init(NULL);
}
- o->buffer = php_http_buffer_new();
+ php_http_buffer_init(&o->buffer);
+ o->zo.handlers = &php_http_message_parser_object_handlers;
- o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_parser_object_free, NULL TSRMLS_CC);
- o->zv.handlers = &php_http_message_parser_object_handlers;
-
- return o->zv;
+ return o;
}
-void php_http_message_parser_object_free(void *object TSRMLS_DC)
+void php_http_message_parser_object_free(zend_object *object)
{
- php_http_message_parser_object_t *o = (php_http_message_parser_object_t *) object;
+ php_http_message_parser_object_t *o = PHP_HTTP_OBJ(object, NULL);
if (o->parser) {
php_http_message_parser_free(&o->parser);
}
- if (o->buffer) {
- php_http_buffer_free(&o->buffer);
- }
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ php_http_buffer_dtor(&o->buffer);
+ zend_object_std_dtor(object);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageParser_getState, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessageParser, getState)
{
- php_http_message_parser_object_t *parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_parser_object_t *parser_obj = PHP_HTTP_OBJ(NULL, getThis());
zend_parse_parameters_none();
/* always return the real state */
php_http_message_parser_object_t *parser_obj;
zval *zmsg;
char *data_str;
- int data_len;
- long flags;
+ size_t data_len;
+ zend_long flags;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz", &data_str, &data_len, &flags, &zmsg), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "slz", &data_str, &data_len, &flags, &zmsg), invalid_arg, return);
- parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_buffer_append(parser_obj->buffer, data_str, data_len);
- RETVAL_LONG(php_http_message_parser_parse(parser_obj->parser, parser_obj->buffer, flags, &parser_obj->parser->message));
+ parser_obj = PHP_HTTP_OBJ(NULL, getThis());
+ php_http_buffer_append(&parser_obj->buffer, data_str, data_len);
+ RETVAL_LONG(php_http_message_parser_parse(parser_obj->parser, &parser_obj->buffer, flags, &parser_obj->parser->message));
+ ZVAL_DEREF(zmsg);
zval_dtor(zmsg);
+ ZVAL_NULL(zmsg);
if (parser_obj->parser->message) {
- ZVAL_OBJVAL(zmsg, php_http_message_object_new_ex(php_http_message_class_entry, php_http_message_copy(parser_obj->parser->message, NULL), NULL TSRMLS_CC), 0);
+ php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL);
+ php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), msg_cpy);
+ ZVAL_OBJ(zmsg, &msg_obj->zo);
}
}
zend_error_handling zeh;
zval *zmsg, *zstream;
php_stream *s;
- long flags;
+ zend_long flags;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &zstream, &flags, &zmsg), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zstream, &flags, &zmsg), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
- php_stream_from_zval(s, &zstream);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_unexpected_val_class_entry(), &zeh);
+ php_stream_from_zval(s, zstream);
+ zend_restore_error_handling(&zeh);
- parser_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- RETVAL_LONG(php_http_message_parser_parse_stream(parser_obj->parser, parser_obj->buffer, s, flags, &parser_obj->parser->message));
+ parser_obj = PHP_HTTP_OBJ(NULL, getThis());
+ RETVAL_LONG(php_http_message_parser_parse_stream(parser_obj->parser, &parser_obj->buffer, s, flags, &parser_obj->parser->message));
+ ZVAL_DEREF(zmsg);
zval_dtor(zmsg);
+ ZVAL_NULL(zmsg);
if (parser_obj->parser->message) {
- ZVAL_OBJVAL(zmsg, php_http_message_object_new_ex(php_http_message_class_entry, php_http_message_copy(parser_obj->parser->message, NULL), NULL TSRMLS_CC), 0);
+ php_http_message_t *msg_cpy = php_http_message_copy(parser_obj->parser->message, NULL);
+ php_http_message_object_t *msg_obj = php_http_message_object_new_ex(php_http_message_get_class_entry(), msg_cpy);
+ ZVAL_OBJ(zmsg, &msg_obj->zo);
}
}
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, "http\\Message", "Parser", php_http_message_parser_methods);
- php_http_message_parser_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_message_parser_class_entry = zend_register_internal_class(&ce);
memcpy(&php_http_message_parser_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
php_http_message_parser_class_entry->create_object = php_http_message_parser_object_new;
php_http_message_parser_object_handlers.clone_obj = NULL;
-
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("CLEANUP"), PHP_HTTP_MESSAGE_PARSER_CLEANUP TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("DUMB_BODIES"), PHP_HTTP_MESSAGE_PARSER_DUMB_BODIES TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("EMPTY_REDIRECTS"), PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("GREEDY"), PHP_HTTP_MESSAGE_PARSER_GREEDY TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_FAILURE"), PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_START"), PHP_HTTP_MESSAGE_PARSER_STATE_START TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_HEADER"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_HEADER_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_DUMB"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_LENGTH"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_CHUNKED"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_UPDATE_CL"), PHP_HTTP_MESSAGE_PARSER_STATE_UPDATE_CL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_DONE TSRMLS_CC);
+ php_http_message_parser_object_handlers.free_obj = php_http_message_parser_object_free;
+ php_http_message_parser_object_handlers.offset = XtOffsetOf(php_http_message_parser_object_t, zo);
+
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("CLEANUP"), PHP_HTTP_MESSAGE_PARSER_CLEANUP);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("DUMB_BODIES"), PHP_HTTP_MESSAGE_PARSER_DUMB_BODIES);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("EMPTY_REDIRECTS"), PHP_HTTP_MESSAGE_PARSER_EMPTY_REDIRECTS);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("GREEDY"), PHP_HTTP_MESSAGE_PARSER_GREEDY);
+
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_FAILURE"), PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_START"), PHP_HTTP_MESSAGE_PARSER_STATE_START);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_HEADER"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_HEADER_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_HEADER_DONE);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_DUMB"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DUMB);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_LENGTH"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_LENGTH);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_CHUNKED"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_CHUNKED);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_BODY_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_BODY_DONE);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_UPDATE_CL"), PHP_HTTP_MESSAGE_PARSER_STATE_UPDATE_CL);
+ zend_declare_class_constant_long(php_http_message_parser_class_entry, ZEND_STRL("STATE_DONE"), PHP_HTTP_MESSAGE_PARSER_STATE_DONE);
return SUCCESS;
}
php_http_message_t *message;
php_http_encoding_stream_t *dechunk;
php_http_encoding_stream_t *inflate;
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_message_parser_t;
-PHP_HTTP_API php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser TSRMLS_DC);
+PHP_HTTP_API php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser);
PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_push(php_http_message_parser_t *parser, unsigned argc, ...);
PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_is(php_http_message_parser_t *parser);
PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_pop(php_http_message_parser_t *parser);
PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_message_parser_t *parser, php_http_buffer_t *buffer, php_stream *s, unsigned flags, php_http_message_t **message);
typedef struct php_http_message_parser_object {
- zend_object zo;
- zend_object_value zv;
- php_http_buffer_t *buffer;
+ php_http_buffer_t buffer;
php_http_message_parser_t *parser;
+ zend_object zo;
} php_http_message_parser_object_t;
-PHP_HTTP_API zend_class_entry *php_http_message_parser_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_get_message_parser_class_entry(void);
PHP_MINIT_FUNCTION(http_message_parser);
-zend_object_value php_http_message_parser_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_message_parser_object_new_ex(zend_class_entry *ce, php_http_message_parser_t *parser, php_http_message_parser_object_t **ptr TSRMLS_DC);
-void php_http_message_parser_object_free(void *object TSRMLS_DC);
+zend_object *php_http_message_parser_object_new(zend_class_entry *ce);
+php_http_message_parser_object_t *php_http_message_parser_object_new_ex(zend_class_entry *ce, php_http_message_parser_t *parser);
+void php_http_message_parser_object_free(zend_object *object);
#endif
}
-size_t php_http_boundary(char *buf, size_t buf_len TSRMLS_DC)
+size_t php_http_boundary(char *buf, size_t buf_len)
{
- return snprintf(buf, buf_len, "%15.15F", sapi_get_request_time(TSRMLS_C) * php_combined_lcg(TSRMLS_C));
+ return snprintf(buf, buf_len, "%15.15F", sapi_get_request_time() * php_combined_lcg());
}
int php_http_select_str(const char *cmp, int argc, ...)
/* ARRAYS */
-unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...)
+unsigned php_http_array_list(HashTable *ht, unsigned argc, ...)
{
- HashPosition pos;
unsigned argl = 0;
va_list argv;
+ zval *data;
va_start(argv, argc);
- for ( zend_hash_internal_pointer_reset_ex(ht, &pos);
- SUCCESS == zend_hash_has_more_elements_ex(ht, &pos) && (argl < argc);
- zend_hash_move_forward_ex(ht, &pos))
- {
- zval **data, ***argp = (zval ***) va_arg(argv, zval ***);
-
- if (SUCCESS == zend_hash_get_current_data_ex(ht, (void *) &data, &pos)) {
- *argp = data;
- ++argl;
- }
- }
+ ZEND_HASH_FOREACH_VAL(ht, data) {
+ zval **argp = (zval **) va_arg(argv, zval **);
+ *argp = data;
+ ++argl;
+ } ZEND_HASH_FOREACH_END();
va_end(argv);
return argl;
}
-void php_http_array_copy_strings(void *zpp)
+void php_http_array_copy_strings(zval *zp)
{
- zval **zvpp = ((zval **) zpp);
-
- *zvpp = php_http_zsep(1, IS_STRING, *zvpp);
+ Z_TRY_ADDREF_P(zp);
+ convert_to_string_ex(zp);
}
-int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+int php_http_array_apply_append_func(zval *value, int num_args, va_list args, zend_hash_key *hash_key)
{
int flags;
char *key = NULL;
HashTable *dst;
- zval **data = NULL, *value = *((zval **) pDest);
+ zval *data = NULL;
dst = va_arg(args, HashTable *);
flags = va_arg(args, int);
- if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
- if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
- key = php_http_pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
- zend_hash_find(dst, key, hash_key->nKeyLength, (void *) &data);
- } else if (hash_key->nKeyLength) {
- zend_hash_quick_find(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &data);
+ if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->key) {
+ if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->key) {
+ key = php_http_pretty_key(estrndup(hash_key->key->val, hash_key->key->len), hash_key->key->len, 1, 1);
+ data = zend_hash_str_find(dst, key, hash_key->key->len);
+ } else if (hash_key->key) {
+ data = zend_hash_find(dst, hash_key->key);
} else {
- zend_hash_index_find(dst, hash_key->h, (void *) &data);
+ data = zend_hash_index_find(dst, hash_key->h);
}
if (flags & ARRAY_JOIN_STRINGIFY) {
- value = php_http_zsep(1, IS_STRING, value);
- } else {
- Z_ADDREF_P(value);
+ convert_to_string_ex(value);
}
+ Z_ADDREF_P(value);
if (data) {
- if (Z_TYPE_PP(data) != IS_ARRAY) {
- convert_to_array(*data);
+ if (Z_TYPE_P(data) != IS_ARRAY) {
+ convert_to_array(data);
}
- add_next_index_zval(*data, value);
+ add_next_index_zval(data, value);
} else if (key) {
- zend_symtable_update(dst, key, hash_key->nKeyLength, &value, sizeof(zval *), NULL);
- } else if (hash_key->nKeyLength) {
- zend_hash_quick_add(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, &value, sizeof(zval *), NULL);
+ zend_hash_str_update(dst, key, hash_key->key->len, value);
+ } else if (hash_key->key) {
+ zend_hash_update(dst, hash_key->key, value);
} else {
- zend_hash_index_update(dst, hash_key->h, (void *) &value, sizeof(zval *), NULL);
+ zend_hash_index_update(dst, hash_key->h, value);
}
if (key) {
return ZEND_HASH_APPLY_KEEP;
}
-int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+int php_http_array_apply_merge_func(zval *value, int num_args, va_list args, zend_hash_key *hash_key)
{
int flags;
char *key = NULL;
HashTable *dst;
- zval *value = *((zval **) pDest);
dst = va_arg(args, HashTable *);
flags = va_arg(args, int);
- if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
+ if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->key) {
if (flags & ARRAY_JOIN_STRINGIFY) {
- value = php_http_zsep(1, IS_STRING, value);
- } else {
- Z_ADDREF_P(value);
+ convert_to_string_ex(value);
}
- if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
- key = php_http_pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
- zend_hash_update(dst, key, hash_key->nKeyLength, (void *) &value, sizeof(zval *), NULL);
+ Z_TRY_ADDREF_P(value);
+
+ if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->key) {
+ key = php_http_pretty_key(estrndup(hash_key->key->val, hash_key->key->len), hash_key->key->len, 1, 1);
+ zend_hash_str_update(dst, key, hash_key->key->len, value);
efree(key);
- } else if (hash_key->nKeyLength) {
- zend_hash_quick_update(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &value, sizeof(zval *), NULL);
+ } else if (hash_key->key) {
+ zend_hash_update(dst, hash_key->key, value);
} else {
- zend_hash_index_update(dst, hash_key->h, (void *) &value, sizeof(zval *), NULL);
+ zend_hash_index_update(dst, hash_key->h, value);
}
}
size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len)
{
php_http_pass_fcall_arg_t *fcd = cb_arg;
- zval *zdata;
- TSRMLS_FETCH_FROM_CTX(fcd->ts);
+ zval zdata;
- MAKE_STD_ZVAL(zdata);
- ZVAL_STRINGL(zdata, str, len, 1);
- if (SUCCESS == zend_fcall_info_argn(&fcd->fci TSRMLS_CC, 2, &fcd->fcz, &zdata)) {
- zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL TSRMLS_CC);
+ ZVAL_STRINGL(&zdata, str, len);
+ if (SUCCESS == zend_fcall_info_argn(&fcd->fci, 2, &fcd->fcz, &zdata)) {
+ zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL);
zend_fcall_info_args_clear(&fcd->fci, 0);
}
zval_ptr_dtor(&zdata);
int php_http_match(const char *haystack, const char *needle, int flags);
char *php_http_pretty_key(register char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
-size_t php_http_boundary(char *buf, size_t len TSRMLS_DC);
+size_t php_http_boundary(char *buf, size_t len);
int php_http_select_str(const char *cmp, int argc, ...);
/* See "A Reusable Duff Device" By Ralf Holly, August 01, 2005 */
/* ZEND */
-#if PHP_VERSION_ID < 50400
-# define object_properties_init(o, ce) zend_hash_copy(((zend_object *) o)->properties, &(ce->default_properties), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*))
-# define PHP_HTTP_ZEND_LITERAL_DC
-# define PHP_HTTP_ZEND_LITERAL_CC
-# define PHP_HTTP_ZEND_LITERAL_CCN
-# define ZVAL_COPY_VALUE(zv, arr) do { \
- (zv)->value = (arr)->value; \
- Z_TYPE_P(zv) = Z_TYPE_P(arr); \
- } while (0)
-#else
-# define PHP_HTTP_ZEND_LITERAL_DC , const zend_literal *literal_key
-# define PHP_HTTP_ZEND_LITERAL_CC , (literal_key)
-# define PHP_HTTP_ZEND_LITERAL_CCN , NULL
+#ifdef PHP_DEBUG
+# undef HASH_OF
+# define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL))))
#endif
-#if PHP_VERSION_ID < 50500
-#undef SUCCESS
-#undef FAILURE
-typedef enum {
- SUCCESS = 0,
- FAILURE = -1
-} ZEND_RESULT_CODE;
-#endif
-
-#if PHP_VERSION_ID < 50700
-# define z_is_true zend_is_true
-#else
-# define z_is_true(z) zend_is_true(z TSRMLS_CC)
-#endif
-
-#define INIT_PZVAL_ARRAY(zv, ht) \
- { \
- INIT_PZVAL((zv)); \
- Z_TYPE_P(zv) = IS_ARRAY; \
- Z_ARRVAL_P(zv) = (ht); \
- }
-
-static inline zval *php_http_zconv(int type, zval *z)
+static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv)
{
- switch (type) {
- case IS_NULL: convert_to_null_ex(&z); break;
- case IS_BOOL: convert_to_boolean_ex(&z); break;
- case IS_LONG: convert_to_long_ex(&z); break;
- case IS_DOUBLE: convert_to_double_ex(&z); break;
- case IS_STRING: convert_to_string_ex(&z); break;
- case IS_ARRAY: convert_to_array_ex(&z); break;
- case IS_OBJECT: convert_to_object_ex(&z); break;
+ if (!zo) {
+ zo = Z_OBJ_P(zv);
}
- return z;
+ return (char *) zo - zo->handlers->offset;
}
-static inline zval *php_http_ztyp(int type, zval *z)
+static inline zend_string *php_http_cs2zs(char *s, size_t l)
{
- SEPARATE_ARG_IF_REF(z);
- return (Z_TYPE_P(z) == type) ? z : php_http_zconv(type, z);
-}
+ zend_string *str = erealloc(s, sizeof(*str) + l);
-static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z)
-{
- if (add_ref) {
- Z_ADDREF_P(z);
- }
- if (Z_TYPE_P(z) != type) {
- return php_http_zconv(type, z);
- } else {
- SEPARATE_ZVAL_IF_NOT_REF(&z);
- return z;
- }
+ memmove(str->val, str, l);
+ str->val[l] = 0;
+ str->len = l;
+ str->h = 0;
+
+ GC_REFCOUNT(str) = 1;
+ GC_TYPE_INFO(str) = IS_STRING;
+
+ return str;
}
-static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t name_len, const char **value_str, size_t *value_len, zend_bool orig TSRMLS_DC)
+static inline ZEND_RESULT_CODE php_http_ini_entry(const char *name_str, size_t name_len, const char **val_str, size_t *val_len, zend_bool orig)
{
zend_ini_entry *ini_entry;
- if (SUCCESS == zend_hash_find(EG(ini_directives), name_str, name_len + 1, (void *) &ini_entry)) {
+ if ((ini_entry = zend_hash_str_find_ptr(EG(ini_directives), name_str, name_len))) {
if (orig && ini_entry->modified) {
- *value_str = ini_entry->orig_value;
- *value_len = (size_t) ini_entry->orig_value_length;
+ *val_str = ini_entry->orig_value->val;
+ *val_len = ini_entry->orig_value->len;
} else {
- *value_str = ini_entry->value;
- *value_len = (size_t) ini_entry->value_length;
+ *val_str = ini_entry->value->val;
+ *val_len = ini_entry->value->len;
}
return SUCCESS;
}
return FAILURE;
}
+#define Z_ISUSER(zv) (Z_TYPE(zv) <= 10)
+#define Z_ISUSER_P(zvp) Z_ISUSER(*(zvp))
+
/* return object(values) */
+#define ZVAL_OBJECT(z, o, addref) \
+ ZVAL_OBJ(z, o); \
+ if (addref) { \
+ Z_ADDREF_P(z); \
+ }
#define RETVAL_OBJECT(o, addref) \
- RETVAL_OBJVAL((o)->value.obj, addref)
+ ZVAL_OBJECT(return_value, o, addref)
#define RETURN_OBJECT(o, addref) \
RETVAL_OBJECT(o, addref); \
return
-#define RETVAL_OBJVAL(ov, addref) \
- ZVAL_OBJVAL(return_value, ov, addref)
-#define RETURN_OBJVAL(ov, addref) \
- RETVAL_OBJVAL(ov, addref); \
- return
-#define ZVAL_OBJVAL(zv, ov, addref) \
- (zv)->type = IS_OBJECT; \
- (zv)->value.obj = (ov);\
- if (addref && Z_OBJ_HT_P(zv)->add_ref) { \
- Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \
- }
-
-#define Z_OBJ_DELREF(z) \
- if (Z_OBJ_HT(z)->del_ref) { \
- Z_OBJ_HT(z)->del_ref(&(z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF(z) \
- if (Z_OBJ_HT(z)->add_ref) { \
- Z_OBJ_HT(z)->add_ref(&(z) TSRMLS_CC); \
- }
-#define Z_OBJ_DELREF_P(z) \
- if (Z_OBJ_HT_P(z)->del_ref) { \
- Z_OBJ_HT_P(z)->del_ref((z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF_P(z) \
- if (Z_OBJ_HT_P(z)->add_ref) { \
- Z_OBJ_HT_P(z)->add_ref((z) TSRMLS_CC); \
- }
-#define Z_OBJ_DELREF_PP(z) \
- if (Z_OBJ_HT_PP(z)->del_ref) { \
- Z_OBJ_HT_PP(z)->del_ref(*(z) TSRMLS_CC); \
- }
-#define Z_OBJ_ADDREF_PP(z) \
- if (Z_OBJ_HT_PP(z)->add_ref) { \
- Z_OBJ_HT_PP(z)->add_ref(*(z) TSRMLS_CC); \
- }
#define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
/* ARRAYS */
-#ifndef HASH_KEY_NON_EXISTENT
-# define HASH_KEY_NON_EXISTENT HASH_KEY_NON_EXISTANT
-#endif
-
-PHP_HTTP_API unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...);
+PHP_HTTP_API unsigned php_http_array_list(HashTable *ht, unsigned argc, ...);
-typedef struct php_http_array_hashkey {
- char *str;
- uint len;
- ulong num;
- uint dup:1;
- uint type:31;
-} php_http_array_hashkey_t;
-#define php_http_array_hashkey_init(dup) {NULL, 0, 0, (dup), 0}
+typedef struct php_http_arrkey {
+ zend_ulong h;
+ zend_string *key;
+ unsigned allocated:1;
+ unsigned stringified:1;
+} php_http_arrkey_t;
-static inline void php_http_array_hashkey_stringify(php_http_array_hashkey_t *key)
+static inline void *php_http_arrkey_stringify(php_http_arrkey_t *arrkey, zend_hash_key *key)
{
- if (key->type != HASH_KEY_IS_STRING) {
- key->len = spprintf(&key->str, 0, "%lu", key->num) + 1;
+ if (arrkey) {
+ arrkey->allocated = 0;
+ } else {
+ arrkey = emalloc(sizeof(*arrkey));
+ arrkey->allocated = 1;
+ }
+
+ if (key) {
+ memcpy(arrkey, key, sizeof(*key));
+ }
+ if ((arrkey->stringified = !arrkey->key)) {
+ arrkey->key = zend_long_to_str(arrkey->h);
}
+ return arrkey;
}
-static inline void php_http_array_hashkey_stringfree(php_http_array_hashkey_t *key)
+static inline void php_http_arrkey_dtor(php_http_arrkey_t *arrkey)
{
- if (key->type != HASH_KEY_IS_STRING || key->dup) {
- PTR_FREE(key->str);
+ if (arrkey->stringified) {
+ zend_string_release(arrkey->key);
+ }
+ if (arrkey->allocated) {
+ efree(arrkey);
}
}
-#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, HASH_OF(array), val)
-#define FOREACH_HASH_VAL(pos, hash, val) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
- zend_hash_move_forward_ex(hash, &pos))
-
-#define FOREACH_KEY(pos, array, key) FOREACH_HASH_KEY(pos, HASH_OF(array), key)
-#define FOREACH_HASH_KEY(pos, hash, _key) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT; \
- zend_hash_move_forward_ex(hash, &pos)) \
-
-#define FOREACH_KEYVAL(pos, array, key, val) FOREACH_HASH_KEYVAL(pos, HASH_OF(array), key, val)
-#define FOREACH_HASH_KEYVAL(pos, hash, _key, val) \
- for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
- ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT && \
- zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
- zend_hash_move_forward_ex(hash, &pos))
-
-#define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
-#define array_copy_strings(src, dst) zend_hash_copy(dst, src, php_http_array_copy_strings, NULL, sizeof(zval *))
+#define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref)
+#define array_copy_strings(src, dst) zend_hash_copy(dst, src, php_http_array_copy_strings)
#define ARRAY_JOIN_STRONLY 0x01
#define ARRAY_JOIN_PRETTIFY 0x02
#define ARRAY_JOIN_STRINGIFY 0x04
-#define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src TSRMLS_CC, (append)?php_http_array_apply_append_func:php_http_array_apply_merge_func, 2, dst, (int)flags)
+#define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src, (append)?php_http_array_apply_append_func:php_http_array_apply_merge_func, 2, dst, (int)flags)
-void php_http_array_copy_strings(void *zpp);
-int php_http_array_apply_append_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
-int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
+void php_http_array_copy_strings(zval *zp);
+int php_http_array_apply_append_func(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
+int php_http_array_apply_merge_func(zval *pDest, int num_args, va_list args, zend_hash_key *hash_key);
/* PASS CALLBACK */
typedef size_t (*php_http_pass_format_callback_t)(void *cb_arg, const char *fmt, ...);
typedef struct php_http_pass_fcall_arg {
- zval *fcz;
+ zval fcz;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
-#ifdef ZTS
- void ***ts;
-#endif
} php_http_pass_fcall_arg_t;
PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len);
#include "php_http_api.h"
-static int php_http_negotiate_sort(const void *a, const void *b TSRMLS_DC)
+static int php_http_negotiate_sort(const void *first, const void *second)
{
- zval result, *first, *second;
+ Bucket *b1 = (Bucket *) first, *b2 = (Bucket *) second;
+ int result = numeric_compare_function(&b1->val, &b2->val);
- first = *((zval **) (*((Bucket **) a))->pData);
- second= *((zval **) (*((Bucket **) b))->pData);
-
- if (numeric_compare_function(&result, first, second TSRMLS_CC) != SUCCESS) {
- return 0;
- }
- return (Z_LVAL(result) > 0 ? -1 : (Z_LVAL(result) < 0 ? 1 : 0));
+ return (result > 0 ? -1 : (result < 0 ? 1 : 0));
}
#define M_PRI 5
#define M_SEC 2
#define M_ANY 1
#define M_NOT 0
-#define M_ALL -1
+#define M_ALL ~0
static inline unsigned php_http_negotiate_match(const char *param_str, size_t param_len, const char *supported_str, size_t supported_len, const char *sep_str, size_t sep_len)
{
- int match = M_NOT;
+ unsigned match = M_NOT;
if (param_len == supported_len && !strncasecmp(param_str, supported_str, param_len)) {
/* that was easy */
#endif
return match;
}
-
-static int php_http_negotiate_reduce(void *p TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
+static int php_http_negotiate_reduce(zval *p, int num_args, va_list args, zend_hash_key *hash_key)
{
unsigned best_match = 0;
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **q = NULL, **val, *supported = php_http_ztyp(IS_STRING, *(zval **)p);
+ php_http_arrkey_t key;
+ zval *value, *q = NULL;
+ zend_string *supported = zval_get_string(p);
HashTable *params = va_arg(args, HashTable *);
HashTable *result = va_arg(args, HashTable *);
const char *sep_str = va_arg(args, const char *);
size_t sep_len = va_arg(args, size_t);
- FOREACH_HASH_KEYVAL(pos, params, key, val) {
- if (key.type == HASH_KEY_IS_STRING) {
- unsigned match = php_http_negotiate_match(key.str, key.len-1, Z_STRVAL_P(supported), Z_STRLEN_P(supported), sep_str, sep_len);
+ ZEND_HASH_FOREACH_KEY_VAL(params, key.h, key.key, value)
+ {
+ unsigned match;
- if (match > best_match) {
- best_match = match;
- q = val;
- }
+ php_http_arrkey_stringify(&key, NULL);
+ match = php_http_negotiate_match(key.key->val, key.key->len, supported->val, supported->len, sep_str, sep_len);
+
+ if (match > best_match) {
+ best_match = match;
+ q = value;
}
+ php_http_arrkey_dtor(&key);
}
+ ZEND_HASH_FOREACH_END();
- if (q && Z_DVAL_PP(q) > 0) {
- Z_ADDREF_PP(q);
- zend_hash_update(result, Z_STRVAL_P(supported), Z_STRLEN_P(supported) + 1, (void *) q, sizeof(zval *), NULL);
+ if (q && Z_DVAL_P(q) > 0) {
+ Z_TRY_ADDREF_P(q);
+ zend_hash_update(result, supported, q);
}
- zval_ptr_dtor(&supported);
+ zend_string_release(supported);
return ZEND_HASH_APPLY_KEEP;
}
-HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len TSRMLS_DC)
+HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len)
{
HashTable *result = NULL;
if (value_str && value_len) {
unsigned i = 0;
- zval arr, **val, **arg, **zq;
- HashPosition pos;
+ zval arr, *val, *arg, *zq;
HashTable params;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(1);
+ php_http_arrkey_t key;
php_http_params_opts_t opts;
zend_hash_init(¶ms, 10, NULL, ZVAL_PTR_DTOR, 0);
php_http_params_opts_default_get(&opts);
opts.input.str = estrndup(value_str, value_len);
opts.input.len = value_len;
- php_http_params_parse(¶ms, &opts TSRMLS_CC);
+ php_http_params_parse(¶ms, &opts);
efree(opts.input.str);
- INIT_PZVAL(&arr);
array_init(&arr);
- FOREACH_HASH_KEYVAL(pos, ¶ms, key, val) {
+ ZEND_HASH_FOREACH_KEY_VAL(¶ms, key.h, key.key, val)
+ {
double q;
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("arguments"), (void *) &arg)
- && IS_ARRAY == Z_TYPE_PP(arg)
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(arg), ZEND_STRS("q"), (void *) &zq)) {
- zval *tmp = php_http_ztyp(IS_DOUBLE, *zq);
-
- q = Z_DVAL_P(tmp);
- zval_ptr_dtor(&tmp);
+ if ((arg = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("arguments")))
+ && (IS_ARRAY == Z_TYPE_P(arg))
+ && (zq = zend_hash_str_find(Z_ARRVAL_P(arg), ZEND_STRL("q")))) {
+ q = zval_get_double(zq);
} else {
q = 1.0 - ++i / 100.0;
}
- if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_double_ex(&arr, key.str, key.len, q);
+#if 0
+ fprintf(stderr, "Q: %s=%1.3f\n", key.key->val, q);
+#endif
+
+ if (key.key) {
+ add_assoc_double_ex(&arr, key.key->val, key.key->len, q);
} else {
- add_index_double(&arr, key.num, q);
+ add_index_double(&arr, key.h, q);
}
- PTR_FREE(key.str);
}
+ ZEND_HASH_FOREACH_END();
#if 0
- zend_print_zval_r(&arr, 1 TSRMLS_CC);
+ zend_print_zval_r(&arr, 1);
#endif
ALLOC_HASHTABLE(result);
zend_hash_init(result, zend_hash_num_elements(supported), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_apply_with_arguments(supported TSRMLS_CC, php_http_negotiate_reduce, 4, Z_ARRVAL(arr), result, primary_sep_str, primary_sep_len);
+ zend_hash_apply_with_arguments(supported, php_http_negotiate_reduce, 4, Z_ARRVAL(arr), result, primary_sep_str, primary_sep_len);
zend_hash_destroy(¶ms);
zval_dtor(&arr);
- zend_hash_sort(result, zend_qsort, php_http_negotiate_sort, 0 TSRMLS_CC);
+ zend_hash_sort(result, php_http_negotiate_sort, 0);
}
-
+
return result;
}
#ifndef PHP_HTTP_NEGOTIATE_H
#define PHP_HTTP_NEGOTIATE_H
-PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len TSRMLS_DC);
+PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len);
-static inline HashTable *php_http_negotiate_language(HashTable *supported, php_http_message_t *request TSRMLS_DC)
+static inline HashTable *php_http_negotiate_language(HashTable *supported, php_http_message_t *request)
{
HashTable *result = NULL;
size_t length;
- char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Language"), &length, request TSRMLS_CC);
+ char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Language"), &length, request);
if (value) {
- result = php_http_negotiate(value, length, supported, "-", 1 TSRMLS_CC);
+ result = php_http_negotiate(value, length, supported, "-", 1);
}
PTR_FREE(value);
return result;
}
-static inline HashTable *php_http_negotiate_encoding(HashTable *supported, php_http_message_t *request TSRMLS_DC)
+static inline HashTable *php_http_negotiate_encoding(HashTable *supported, php_http_message_t *request)
{
HashTable *result = NULL;
size_t length;
- char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Encoding"), &length, request TSRMLS_CC);
+ char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Encoding"), &length, request);
if (value) {
- result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
+ result = php_http_negotiate(value, length, supported, NULL, 0);
}
PTR_FREE(value);
return result;
}
-static inline HashTable *php_http_negotiate_charset(HashTable *supported, php_http_message_t *request TSRMLS_DC)
+static inline HashTable *php_http_negotiate_charset(HashTable *supported, php_http_message_t *request)
{
HashTable *result = NULL;
size_t length;
- char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Charset"), &length, request TSRMLS_CC);
+ char *value = php_http_env_get_request_header(ZEND_STRL("Accept-Charset"), &length, request);
if (value) {
- result = php_http_negotiate(value, length, supported, NULL, 0 TSRMLS_CC);
+ result = php_http_negotiate(value, length, supported, NULL, 0);
}
PTR_FREE(value);
return result;
}
-static inline HashTable *php_http_negotiate_content_type(HashTable *supported, php_http_message_t *request TSRMLS_DC)
+static inline HashTable *php_http_negotiate_content_type(HashTable *supported, php_http_message_t *request)
{
HashTable *result = NULL;
size_t length;
- char *value = php_http_env_get_request_header(ZEND_STRL("Accept"), &length, request TSRMLS_CC);
+ char *value = php_http_env_get_request_header(ZEND_STRL("Accept"), &length, request);
if (value) {
- result = php_http_negotiate(value, length, supported, "/", 1 TSRMLS_CC);
+ result = php_http_negotiate(value, length, supported, "/", 1);
}
PTR_FREE(value);
#define PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported) \
{ \
- zval **value; \
+ zval *value; \
\
zend_hash_internal_pointer_reset((supported)); \
- if (SUCCESS == zend_hash_get_current_data((supported), (void *) &value)) { \
- RETVAL_ZVAL(*value, 1, 0); \
+ if ((value = zend_hash_get_current_data((supported)))) { \
+ RETVAL_ZVAL(value, 1, 0); \
} else { \
RETVAL_NULL(); \
} \
#define PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array) \
PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported); \
if (rs_array) { \
- HashPosition pos; \
- zval **value_ptr; \
+ zval *value; \
\
- FOREACH_HASH_VAL(pos, supported, value_ptr) { \
- zval *value = php_http_ztyp(IS_STRING, *value_ptr); \
- add_assoc_double(rs_array, Z_STRVAL_P(value), 1.0); \
- zval_ptr_dtor(&value); \
+ ZEND_HASH_FOREACH_VAL(supported, value) \
+ { \
+ zend_string *zs = zval_get_string(value); \
+ add_assoc_double_ex(rs_array, zs->val, zs->len, 1.0); \
+ zend_string_release(zs); \
} \
+ ZEND_HASH_FOREACH_END(); \
}
#define PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array) \
{ \
- char *key; \
- uint key_len; \
- ulong idx; \
+ zend_string *key; \
+ zend_ulong idx; \
\
- if (zend_hash_num_elements(result) && HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \
- RETVAL_STRINGL(key, key_len-1, 0); \
+ if (zend_hash_num_elements(result) && HASH_KEY_IS_STRING == zend_hash_get_current_key(result, &key, &idx)) { \
+ RETVAL_STR_COPY(key); \
} else { \
PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported); \
} \
\
if (rs_array) { \
- zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); \
+ zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref); \
} \
\
zend_hash_destroy(result); \
#define PHP_HTTP_DO_NEGOTIATE(type, supported, rs_array) \
{ \
HashTable *result; \
- if ((result = php_http_negotiate_ ##type(supported, NULL TSRMLS_CC))) { \
+ if ((result = php_http_negotiate_ ##type(supported, NULL))) { \
PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array); \
} else { \
PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); \
} \
}
-
#endif
/*
#include "php_http_api.h"
-zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC)
+static zend_object_handlers php_http_object_handlers;
+
+zend_object *php_http_object_new(zend_class_entry *ce)
{
- return php_http_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ return &php_http_object_new_ex(ce, NULL)->zo;
}
-zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, php_http_object_t **ptr TSRMLS_DC)
+php_http_object_t *php_http_object_new_ex(zend_class_entry *ce, void *intern)
{
php_http_object_t *o;
- o = ecalloc(1, sizeof(php_http_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
- if (ptr) {
- *ptr = o;
- }
+ o->intern = intern;
+ o->zo.handlers = &php_http_object_handlers;
- o->zv.handle = zend_objects_store_put(o, NULL, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
- o->zv.handlers = zend_get_std_object_handlers();
+ return o;
+}
- return o->zv;
+void php_http_object_free(zend_object *object)
+{
+ zend_object_std_dtor(object);
}
-ZEND_RESULT_CODE php_http_new(zend_object_value *ovp, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
+ZEND_RESULT_CODE php_http_new(void **obj_ptr, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr)
{
- zend_object_value ov;
+ void *obj;
if (!ce) {
ce = parent_ce;
- } else if (parent_ce && !instanceof_function(ce, parent_ce TSRMLS_CC)) {
- php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name, parent_ce->name);
+ } else if (parent_ce && !instanceof_function(ce, parent_ce)) {
+ php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name->val, parent_ce->name->val);
return FAILURE;
}
- ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
- if (ovp) {
- *ovp = ov;
+ obj = create(ce, intern_ptr);
+ if (obj_ptr) {
+ *obj_ptr = obj;
}
return SUCCESS;
}
-static inline zend_function *get_object_method(zval *zobject, zval *zmeth TSRMLS_DC)
+php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len)
{
-#if PHP_VERSION_ID >= 50400
- return Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(zmeth), Z_STRLEN_P(zmeth), NULL TSRMLS_CC);
-#else
- return Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(zmeth), Z_STRLEN_P(zmeth) TSRMLS_CC);
-#endif
-}
-
-php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len TSRMLS_DC)
-{
- zval *zfn;
-
if (!cb) {
cb = ecalloc(1, sizeof(*cb));
} else {
memset(cb, 0, sizeof(*cb));
}
- MAKE_STD_ZVAL(zfn);
- ZVAL_STRINGL(zfn, method_str, method_len, 1);
-
cb->fci.size = sizeof(cb->fci);
- cb->fci.function_name = zfn;
+ ZVAL_STRINGL(&cb->fci.function_name, method_str, method_len);
cb->fcc.initialized = 1;
cb->fcc.calling_scope = cb->fcc.called_scope = Z_OBJCE_P(zobject);
- cb->fcc.function_handler = get_object_method(zobject, cb->fci.function_name TSRMLS_CC);
+ cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&Z_OBJ_P(zobject), Z_STR(cb->fci.function_name), NULL);
return cb;
}
void php_http_object_method_dtor(php_http_object_method_t *cb)
{
- if (cb->fci.function_name) {
- zval_ptr_dtor(&cb->fci.function_name);
- cb->fci.function_name = NULL;
- }
+ zval_ptr_dtor(&cb->fci.function_name);
}
void php_http_object_method_free(php_http_object_method_t **cb)
}
}
-ZEND_RESULT_CODE php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval **retval_ptr, int argc, zval ***args TSRMLS_DC)
+ZEND_RESULT_CODE php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval *retval_ptr, int argc, zval *args)
{
ZEND_RESULT_CODE rv;
- zval *retval = NULL;
+ zval retval;
+ ZVAL_UNDEF(&retval);
Z_ADDREF_P(zobject);
- cb->fci.object_ptr = zobject;
- cb->fcc.object_ptr = zobject;
+ cb->fci.object = Z_OBJ_P(zobject);
+ cb->fcc.object = Z_OBJ_P(zobject);
- cb->fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval;
+ cb->fci.retval = retval_ptr ? retval_ptr : &retval;
cb->fci.param_count = argc;
cb->fci.params = args;
if (cb->fcc.called_scope != Z_OBJCE_P(zobject)) {
cb->fcc.called_scope = Z_OBJCE_P(zobject);
- cb->fcc.function_handler = get_object_method(zobject, cb->fci.function_name TSRMLS_CC);
+ cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&Z_OBJ_P(zobject), Z_STR(cb->fci.function_name), NULL);
}
- rv = zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC);
+ rv = zend_call_function(&cb->fci, &cb->fcc);
- zval_ptr_dtor(&zobject);
- if (!retval_ptr && retval) {
+ zval_ptr_dtor(zobject);
+ if (!retval_ptr && !Z_ISUNDEF(retval)) {
zval_ptr_dtor(&retval);
}
return rv;
}
+PHP_MINIT_FUNCTION(http_object)
+{
+ memcpy(&php_http_object_handlers, zend_get_std_object_handlers(), sizeof(php_http_object_handlers));
+ php_http_object_handlers.offset = XtOffsetOf(php_http_object_t, zo);
+
+ return SUCCESS;
+}
+
/*
* Local variables:
* tab-width: 4
#define PHP_HTTP_OBJECT_H
typedef struct php_http_object {
+ void *intern;
zend_object zo;
- zend_object_value zv;
} php_http_object_t;
-zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, php_http_object_t **ptr TSRMLS_DC);
+zend_object *php_http_object_new(zend_class_entry *ce);
+php_http_object_t *php_http_object_new_ex(zend_class_entry *ce, void *nothing);
-typedef zend_object_value (*php_http_new_t)(zend_class_entry *ce, void *, void ** TSRMLS_DC);
+typedef void *(*php_http_new_t)(zend_class_entry *ce, void *);
-ZEND_RESULT_CODE php_http_new(zend_object_value *ov, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC);
+ZEND_RESULT_CODE php_http_new(void **obj_ptr, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr);
+
+PHP_MINIT_FUNCTION(http_object);
typedef struct php_http_method {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
} php_http_object_method_t;
-php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len TSRMLS_DC);
-ZEND_RESULT_CODE php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval **retval, int argc, zval ***args TSRMLS_DC);
+php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len);
+ZEND_RESULT_CODE php_http_object_method_call(php_http_object_method_t *cb, zval *zobject, zval *retval, int argc, zval *args);
void php_http_object_method_dtor(php_http_object_method_t *cb);
void php_http_object_method_free(php_http_object_method_t **cb);
#include "php_http_api.h"
+static void php_http_options_hash_dtor(zval *pData)
+{
+ php_http_option_t *opt = Z_PTR_P(pData);
+
+ zval_ptr_dtor(&opt->defval);
+ zend_hash_destroy(&opt->suboptions.options);
+ zend_string_release(opt->name);
+ pefree(opt, opt->persistent);
+}
+
php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_bool persistent)
{
if (!registry) {
}
registry->persistent = persistent;
- zend_hash_init(®istry->options, 0, NULL, (dtor_func_t) zend_hash_destroy, persistent);
+ zend_hash_init(®istry->options, 0, NULL, php_http_options_hash_dtor, persistent);
return registry;
}
ZEND_RESULT_CODE php_http_options_apply(php_http_options_t *registry, HashTable *options, void *userdata)
{
- HashPosition pos;
- zval *val;
+ zval *entry, *val;
php_http_option_t *opt;
- FOREACH_HASH_VAL(pos, ®istry->options, opt) {
+ ZEND_HASH_FOREACH_VAL(®istry->options, entry)
+ {
+ opt = Z_PTR_P(entry);
if (!(val = registry->getter(opt, options, userdata))) {
val = &opt->defval;
}
return FAILURE;
}
}
+ ZEND_HASH_FOREACH_END();
+
return SUCCESS;
}
php_http_option_t *php_http_option_register(php_http_options_t *registry, const char *name_str, size_t name_len, ulong option, zend_uchar type)
{
- php_http_option_t opt, *dst = NULL;
+ php_http_option_t opt;
memset(&opt, 0, sizeof(opt));
opt.suboptions.getter = registry->getter;
opt.suboptions.setter = registry->setter;
- opt.name.h = zend_hash_func(opt.name.s = name_str, opt.name.l = name_len + 1);
+ opt.persistent = registry->persistent;
+ opt.name = zend_string_init(name_str, name_len, registry->persistent);
opt.type = type;
opt.option = option;
- INIT_ZVAL(opt.defval);
switch ((opt.type = type)) {
- case IS_BOOL:
- ZVAL_BOOL(&opt.defval, 0);
+ case IS_TRUE:
+ ZVAL_TRUE(&opt.defval);
break;
- case IS_LONG:
- ZVAL_LONG(&opt.defval, 0);
+ case IS_FALSE:
+ ZVAL_FALSE(&opt.defval);
break;
- case IS_STRING:
- ZVAL_STRINGL(&opt.defval, NULL, 0, 0);
+ case IS_LONG:
+ ZVAL_LONG(&opt.defval, 0);
break;
case IS_DOUBLE:
break;
}
- zend_hash_quick_update(®istry->options, opt.name.s, opt.name.l, opt.name.h, (void *) &opt, sizeof(opt), (void *) &dst);
- return dst;
+ return zend_hash_update_mem(®istry->options, opt.name, &opt, sizeof(opt));
}
zval *php_http_option_get(php_http_option_t *opt, HashTable *options, void *userdata)
{
if (options) {
- zval **zoption;
-
- if (SUCCESS == zend_hash_quick_find(options, opt->name.s, opt->name.l, opt->name.h, (void *) &zoption)) {
- return *zoption;
- }
+ return zend_hash_find(options, opt->name);
}
return NULL;
struct php_http_option {
php_http_options_t suboptions;
- struct {
- const char *s;
- size_t l;
- ulong h;
- } name;
-
+ zend_string *name;
ulong option;
zend_uchar type;
unsigned flags;
zval defval;
php_http_option_set_callback_t setter;
+ unsigned persistent:1;
};
PHP_HTTP_API php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_bool persistent);
def_param_sep_ptr,
def_arg_sep_ptr,
def_val_sep_ptr,
- NULL,
+ {{0}},
PHP_HTTP_PARAMS_DEFAULT
};
php_http_params_token_t arg;
php_http_params_token_t val;
struct {
- zval **param;
- zval **args;
- zval **val;
+ zval *param;
+ zval *args;
+ zval *val;
} current;
unsigned quotes:1;
unsigned escape:1;
unsigned rfc5987:1;
} php_http_params_state_t;
-static inline void sanitize_escaped(zval *zv TSRMLS_DC)
+static inline void sanitize_escaped(zval *zv)
{
if (Z_STRVAL_P(zv)[0] == '"' && Z_STRVAL_P(zv)[Z_STRLEN_P(zv) - 1] == '"') {
size_t deq_len = Z_STRLEN_P(zv) - 2;
char *deq = estrndup(Z_STRVAL_P(zv) + 1, deq_len);
zval_dtor(zv);
- ZVAL_STRINGL(zv, deq, deq_len, 0);
+ ZVAL_STR(zv, php_http_cs2zs(deq, deq_len));
}
- php_stripcslashes(Z_STRVAL_P(zv), &Z_STRLEN_P(zv));
+ php_stripcslashes(Z_STR_P(zv));
}
-static inline void quote_string(zval *zv, zend_bool force TSRMLS_DC)
+static inline void quote_string(zend_string **zs, zend_bool force)
{
- int len = Z_STRLEN_P(zv);
+ int len = (*zs)->len;
- Z_STRVAL_P(zv) = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &Z_STRLEN_P(zv), 1,
- ZEND_STRL("\0..\37\173\\\"") TSRMLS_CC);
+ *zs = php_addcslashes(*zs, 1, ZEND_STRL("\0..\37\173\\\""));
- if (force || len != Z_STRLEN_P(zv) || strpbrk(Z_STRVAL_P(zv), "()<>@,;:\"[]?={} ")) {
- zval tmp = *zv;
- int len = Z_STRLEN_P(zv) + 2;
- char *str = emalloc(len + 1);
+ if (force || len != (*zs)->len || strpbrk((*zs)->val, "()<>@,;:\"[]?={} ")) {
+ int len = (*zs)->len + 2;
- str[0] = '"';
- memcpy(&str[1], Z_STRVAL_P(zv), Z_STRLEN_P(zv));
- str[len-1] = '"';
- str[len] = '\0';
+ *zs = zend_string_extend(*zs, len, 0);
- zval_dtor(&tmp);
- ZVAL_STRINGL(zv, str, len, 0);
+ memmove(&(*zs)->val[1], (*zs)->val, (*zs)->len);
+ (*zs)->val[0] = '"';
+ (*zs)->val[len-1] = '"';
+ (*zs)->val[len] = '\0';
+
+ zend_string_forget_hash_val(*zs);
}
}
-static inline void prepare_escaped(zval *zv TSRMLS_DC)
+/* if (Z_TYPE_P(zv) == IS_STRING) {
+ size_t len = Z_STRLEN_P(zv);
+ zend_string *stripped = php_addcslashes(Z_STR_P(zv), 0,
+ ZEND_STRL("\0..\37\173\\\""));
+
+ if (len != stripped->len || strpbrk(stripped->val, "()<>@,;:\"[]?={} ")) {
+ size_t len = stripped->len + 2;
+ char *str = emalloc(len + 1);
+
+ str[0] = '"';
+ memcpy(&str[1], stripped->val, stripped->len);
+ str[len-1] = '"';
+ str[len] = '\0';
+
+ zval_dtor(zv);
+ zend_string_release(stripped);
+ ZVAL_STR(zv, php_http_cs2zs(str, len));
+ } else {
+ zval_dtor(zv);
+ ZVAL_STR(zv, stripped);
+ }
+*/
+
+static inline void prepare_escaped(zval *zv)
{
if (Z_TYPE_P(zv) == IS_STRING) {
- quote_string(zv, 0 TSRMLS_CC);
+ quote_string(&Z_STR_P(zv), 0);
} else {
zval_dtor(zv);
ZVAL_EMPTY_STRING(zv);
}
}
-static inline void sanitize_urlencoded(zval *zv TSRMLS_DC)
+static inline void sanitize_urlencoded(zval *zv)
{
Z_STRLEN_P(zv) = php_raw_url_decode(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
}
-static inline void prepare_urlencoded(zval *zv TSRMLS_DC)
+static inline void prepare_urlencoded(zval *zv)
{
- int len;
- char *str = php_raw_url_encode(Z_STRVAL_P(zv), Z_STRLEN_P(zv), &len);
+ zend_string *str = php_raw_url_encode(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
zval_dtor(zv);
- ZVAL_STRINGL(zv, str, len, 0);
+ ZVAL_STR(zv, str);
}
-static void sanitize_dimension(zval *zv TSRMLS_DC)
+static void sanitize_dimension(zval *zv)
{
- zval *arr = NULL, *tmp = NULL, **cur = NULL;
+ zval arr, tmp, *cur = NULL;
char *var = NULL, *ptr = Z_STRVAL_P(zv), *end = Z_STRVAL_P(zv) + Z_STRLEN_P(zv);
long level = 0;
- MAKE_STD_ZVAL(arr);
- array_init(arr);
+ array_init(&arr);
cur = &arr;
while (ptr < end) {
case '[':
if (++level > PG(max_input_nesting_level)) {
zval_ptr_dtor(&arr);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Max input nesting level of %ld exceeded", (long) PG(max_input_nesting_level));
+ php_error_docref(NULL, E_WARNING, "Max input nesting level of %ld exceeded", (long) PG(max_input_nesting_level));
return;
}
if (ptr - var == 0) {
case ']':
- MAKE_STD_ZVAL(tmp);
- ZVAL_NULL(tmp);
- convert_to_array(*cur);
+ ZVAL_NULL(&tmp);
+ convert_to_array(cur);
if (ptr - var) {
char chr = *ptr;
*ptr = '\0';
- zend_symtable_update(Z_ARRVAL_PP(cur), var, ptr - var + 1, (void *) &tmp, sizeof(zval *), (void *) &cur);
+ cur = zend_symtable_str_update(Z_ARRVAL_P(cur), var, ptr - var, &tmp);
*ptr = chr;
} else {
- zend_hash_next_index_insert(Z_ARRVAL_PP(cur), (void *) &tmp, sizeof(zval *), (void *) &cur);
+ cur = zend_hash_next_index_insert(Z_ARRVAL_P(cur), &tmp);
}
var = NULL;
++ptr;
}
- if (zend_hash_num_elements(Z_ARRVAL_P(arr))) {
+ if (zend_hash_num_elements(Z_ARRVAL(arr))) {
zval_dtor(zv);
-#if PHP_VERSION_ID >= 50400
- ZVAL_COPY_VALUE(zv, arr);
-#else
- zv->value = arr->value;
- Z_TYPE_P(zv) = Z_TYPE_P(arr);
-#endif
- FREE_ZVAL(arr);
+ ZVAL_COPY_VALUE(zv, &arr);
} else {
zval_ptr_dtor(&arr);
}
}
-static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags TSRMLS_DC);
-static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags TSRMLS_DC);
+static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags);
+static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags);
-static void prepare_dimension(php_http_buffer_t *buf, php_http_buffer_t *keybuf, zval *zvalue, const char *pss, size_t psl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+static void prepare_dimension(php_http_buffer_t *buf, php_http_buffer_t *keybuf, zval *zvalue, const char *pss, size_t psl, const char *vss, size_t vsl, unsigned flags)
{
HashTable *ht = HASH_OF(zvalue);
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **val;
+ php_http_arrkey_t key;
+ zval *val;
php_http_buffer_t prefix;
- if (!ht->nApplyCount++) {
+ if (!ZEND_HASH_GET_APPLY_COUNT(ht)) {
+ ZEND_HASH_INC_APPLY_COUNT(ht);
php_http_buffer_init(&prefix);
php_http_buffer_append(&prefix, keybuf->data, keybuf->used);
- FOREACH_HASH_KEYVAL(pos, ht, key, val) {
- if (key.type == HASH_KEY_IS_STRING && !*key.str) {
+ ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, val)
+ {
+ if (key.key && !*key.key->val) {
/* only public properties */
continue;
}
php_http_buffer_appends(&prefix, "[");
- if (key.type == HASH_KEY_IS_STRING) {
- php_http_buffer_append(&prefix, key.str, key.len - 1);
+ if (key.key) {
+ php_http_buffer_append(&prefix, key.key->val, key.key->len);
} else {
- php_http_buffer_appendf(&prefix, "%lu", key.num);
+ php_http_buffer_appendf(&prefix, "%lu", key.h);
}
php_http_buffer_appends(&prefix, "]");
- if (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT) {
- prepare_dimension(buf, &prefix, *val, pss, psl, vss, vsl, flags TSRMLS_CC);
+ if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) {
+ prepare_dimension(buf, &prefix, val, pss, psl, vss, vsl, flags);
} else {
- zval *cpy = php_http_ztyp(IS_STRING, *val);
+ zend_string *cpy = zval_get_string(val);
+ zval tmp;
- shift_key(buf, prefix.data, prefix.used, pss, psl, flags TSRMLS_CC);
- shift_val(buf, cpy, vss, vsl, flags TSRMLS_CC);
- zval_ptr_dtor(&cpy);
+ ZVAL_STR(&tmp, cpy);
+ shift_key(buf, prefix.data, prefix.used, pss, psl, flags);
+ shift_val(buf, &tmp, vss, vsl, flags);
+ zend_string_release(cpy);
}
php_http_buffer_cut(&prefix, keybuf->used, prefix.used - keybuf->used);
}
+ ZEND_HASH_FOREACH_END();
+ ZEND_HASH_DEC_APPLY_COUNT(ht);
+
php_http_buffer_dtor(&prefix);
}
- --ht->nApplyCount;
}
-static inline void sanitize_key(unsigned flags, char *str, size_t len, zval *zv, zend_bool *rfc5987 TSRMLS_DC)
+static inline void sanitize_key(unsigned flags, const char *str, size_t len, zval *zv, zend_bool *rfc5987)
{
char *eos;
+ zend_string *zs = zend_string_init(str, len, 0);
zval_dtor(zv);
- php_trim(str, len, NULL, 0, zv, 3 TSRMLS_CC);
+ ZVAL_STR(zv, php_trim(zs, NULL, 0, 3));
+ zend_string_release(zs);
if (flags & PHP_HTTP_PARAMS_ESCAPED) {
- sanitize_escaped(zv TSRMLS_CC);
+ sanitize_escaped(zv);
}
if (!Z_STRLEN_P(zv)) {
}
if (flags & PHP_HTTP_PARAMS_URLENCODED) {
- sanitize_urlencoded(zv TSRMLS_CC);
+ sanitize_urlencoded(zv);
}
if (flags & PHP_HTTP_PARAMS_DIMENSION) {
- sanitize_dimension(zv TSRMLS_CC);
+ sanitize_dimension(zv);
}
}
-static inline void sanitize_rfc5987(zval *zv, char **language, zend_bool *latin1 TSRMLS_DC)
+static inline void sanitize_rfc5987(zval *zv, char **language, zend_bool *latin1)
{
char *ptr;
/* remainder */
ptr = estrdup(++ptr);
zval_dtor(zv);
- ZVAL_STRING(zv, ptr, 0);
+ ZVAL_STR(zv, php_http_cs2zs(ptr, strlen(ptr)));
}
}
-static inline void sanitize_rfc5988(char *str, size_t len, zval *zv TSRMLS_DC)
+static inline void sanitize_rfc5988(char *str, size_t len, zval *zv)
{
+ zend_string *zs = zend_string_init(str, len, 0);
+
zval_dtor(zv);
- php_trim(str, len, " ><", 3, zv, 3 TSRMLS_CC);
+ ZVAL_STR(zv, php_trim(zs, " ><", 3, 3));
+ zend_string_release(zs);
}
-static inline void prepare_rfc5988(zval *zv TSRMLS_DC)
+static inline void prepare_rfc5988(zval *zv)
{
if (Z_TYPE_P(zv) != IS_STRING) {
zval_dtor(zv);
}
}
zval_dtor(zv);
- ZVAL_STRINGL(zv, (char *) ptr, pos-1, 0);
+ ZVAL_STR(zv, php_http_cs2zs((char *) ptr, pos-1));
}
-static inline void sanitize_value(unsigned flags, char *str, size_t len, zval *zv, zend_bool rfc5987 TSRMLS_DC)
+static inline void sanitize_value(unsigned flags, const char *str, size_t len, zval *zv, zend_bool rfc5987)
{
char *language = NULL;
zend_bool latin1 = 0;
+ zend_string *zs = zend_string_init(str, len, 0);
zval_dtor(zv);
- php_trim(str, len, NULL, 0, zv, 3 TSRMLS_CC);
+ ZVAL_STR(zv, php_trim(zs, NULL, 0, 3));
+ zend_string_release(zs);
if (rfc5987) {
- sanitize_rfc5987(zv, &language, &latin1 TSRMLS_CC);
+ sanitize_rfc5987(zv, &language, &latin1);
}
if (flags & PHP_HTTP_PARAMS_ESCAPED) {
- sanitize_escaped(zv TSRMLS_CC);
+ sanitize_escaped(zv);
}
if ((flags & PHP_HTTP_PARAMS_URLENCODED) || (rfc5987 && language)) {
- sanitize_urlencoded(zv TSRMLS_CC);
+ sanitize_urlencoded(zv);
}
if (rfc5987 && language) {
- zval *tmp;
+ zval tmp;
if (latin1) {
utf8encode(zv);
}
- MAKE_STD_ZVAL(tmp);
- ZVAL_COPY_VALUE(tmp, zv);
+ ZVAL_COPY_VALUE(&tmp, zv);
array_init(zv);
- add_assoc_zval(zv, language, tmp);
- PTR_FREE(language);
+ add_assoc_zval(zv, language, &tmp);
+ efree(language);
}
}
-static inline void prepare_key(unsigned flags, char *old_key, size_t old_len, char **new_key, size_t *new_len TSRMLS_DC)
+static inline void prepare_key(unsigned flags, char *old_key, size_t old_len, char **new_key, size_t *new_len)
{
zval zv;
- INIT_PZVAL(&zv);
- ZVAL_STRINGL(&zv, old_key, old_len, 1);
+ ZVAL_STRINGL(&zv, old_key, old_len);
if (flags & PHP_HTTP_PARAMS_URLENCODED) {
- prepare_urlencoded(&zv TSRMLS_CC);
+ prepare_urlencoded(&zv);
}
if (flags & PHP_HTTP_PARAMS_ESCAPED) {
if (flags & PHP_HTTP_PARAMS_RFC5988) {
- prepare_rfc5988(&zv TSRMLS_CC);
+ prepare_rfc5988(&zv);
} else {
- prepare_escaped(&zv TSRMLS_CC);
+ prepare_escaped(&zv);
}
}
- *new_key = Z_STRVAL(zv);
+ *new_key = estrndup(Z_STRVAL(zv), Z_STRLEN(zv));
*new_len = Z_STRLEN(zv);
+ zval_ptr_dtor(&zv);
}
-static inline void prepare_value(unsigned flags, zval *zv TSRMLS_DC)
+static inline void prepare_value(unsigned flags, zval *zv)
{
if (flags & PHP_HTTP_PARAMS_URLENCODED) {
- prepare_urlencoded(zv TSRMLS_CC);
+ prepare_urlencoded(zv);
}
if (flags & PHP_HTTP_PARAMS_ESCAPED) {
- prepare_escaped(zv TSRMLS_CC);
+ prepare_escaped(zv);
}
}
-static void merge_param(HashTable *params, zval *zdata, zval ***current_param, zval ***current_args TSRMLS_DC)
+static void merge_param(HashTable *params, zval *zdata, zval **current_param, zval **current_args)
{
- zval **ptr, **zdata_ptr;
- php_http_array_hashkey_t hkey = php_http_array_hashkey_init(0);
+ zval *ptr, *zdata_ptr;
+ php_http_arrkey_t hkey = {0};
#if 0
{
zval tmp;
INIT_PZVAL_ARRAY(&tmp, params);
fprintf(stderr, "params = ");
- zend_print_zval_r(&tmp, 1 TSRMLS_CC);
+ zend_print_zval_r(&tmp, 1);
fprintf(stderr, "\n");
}
#endif
- hkey.type = zend_hash_get_current_key_ex(Z_ARRVAL_P(zdata), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL);
+ zend_hash_get_current_key(Z_ARRVAL_P(zdata), &hkey.key, &hkey.h);
- if ((hkey.type == HASH_KEY_IS_STRING && !zend_hash_exists(params, hkey.str, hkey.len))
- || (hkey.type == HASH_KEY_IS_LONG && !zend_hash_index_exists(params, hkey.num))
+ if ((hkey.key && !zend_hash_exists(params, hkey.key))
+ || (!hkey.key && !zend_hash_index_exists(params, hkey.h))
) {
- zval *tmp, *arg, **args;
+ zval tmp, arg, *args;
/* create the entry if it doesn't exist */
- zend_hash_get_current_data(Z_ARRVAL_P(zdata), (void *) &ptr);
- Z_ADDREF_PP(ptr);
- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
- add_assoc_zval_ex(tmp, ZEND_STRS("value"), *ptr);
-
- MAKE_STD_ZVAL(arg);
- array_init(arg);
- zend_hash_update(Z_ARRVAL_P(tmp), "arguments", sizeof("arguments"), (void *) &arg, sizeof(zval *), (void *) &args);
+ ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata));
+ Z_TRY_ADDREF_P(ptr);
+ array_init(&tmp);
+ add_assoc_zval_ex(&tmp, ZEND_STRL("value"), ptr);
+
+ array_init(&arg);
+ args = zend_hash_str_update(Z_ARRVAL(tmp), "arguments", lenof("arguments"), &arg);
*current_args = args;
- if (hkey.type == HASH_KEY_IS_STRING) {
- zend_hash_update(params, hkey.str, hkey.len, (void *) &tmp, sizeof(zval *), (void *) &ptr);
+ if (hkey.key) {
+ ptr = zend_hash_update(params, hkey.key, &tmp);
} else {
- zend_hash_index_update(params, hkey.num, (void *) &tmp, sizeof(zval *), (void *) &ptr);
+ ptr = zend_hash_index_update(params, hkey.h, &tmp);
}
} else {
/* merge */
- if (hkey.type == HASH_KEY_IS_STRING) {
- zend_hash_find(params, hkey.str, hkey.len, (void *) &ptr);
+ if (hkey.key) {
+ ptr = zend_hash_find(params, hkey.key);
} else {
- zend_hash_index_find(params, hkey.num, (void *) &ptr);
+ ptr = zend_hash_index_find(params, hkey.h);
}
- zdata_ptr = &zdata;
+ zdata_ptr = zdata;
- if (Z_TYPE_PP(ptr) == IS_ARRAY
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(ptr), "value", sizeof("value"), (void *) &ptr)
- && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zdata_ptr), (void *) &zdata_ptr)
+ if (Z_TYPE_P(ptr) == IS_ARRAY
+ && (ptr = zend_hash_str_find(Z_ARRVAL_P(ptr), "value", lenof("value")))
+ && (zdata_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))
) {
/*
* params = [arr => [value => [0 => 1]]]
* zdata = [arr => [0 => NULL]]
* ^- zdata_ptr
*/
- zval **test_ptr;
+ zval *test_ptr;
- while (Z_TYPE_PP(zdata_ptr) == IS_ARRAY
- && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(zdata_ptr), (void *) &test_ptr)
- ) {
- if (Z_TYPE_PP(test_ptr) == IS_ARRAY) {
+ while (Z_TYPE_P(zdata_ptr) == IS_ARRAY && (test_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))) {
+ if (Z_TYPE_P(test_ptr) == IS_ARRAY) {
+ zval *tmp_ptr = ptr;
/* now find key in ptr */
- if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(zdata_ptr), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL)) {
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) &ptr)) {
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) {
+ if ((ptr = zend_hash_find(Z_ARRVAL_P(ptr), hkey.key))) {
zdata_ptr = test_ptr;
} else {
- Z_ADDREF_PP(test_ptr);
- zend_hash_update(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ ptr = tmp_ptr;
+ Z_TRY_ADDREF_P(test_ptr);
+ ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr);
break;
}
} else {
- if (SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(ptr), hkey.num, (void *) &ptr)) {
+ if ((ptr = zend_hash_index_find(Z_ARRVAL_P(ptr), hkey.h))) {
zdata_ptr = test_ptr;
- } else if (hkey.num) {
- Z_ADDREF_PP(test_ptr);
- zend_hash_index_update(Z_ARRVAL_PP(ptr), hkey.num, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ } else if (hkey.h) {
+ ptr = tmp_ptr;
+ Z_TRY_ADDREF_P(test_ptr);
+ ptr = zend_hash_index_update(Z_ARRVAL_P(ptr), hkey.h, test_ptr);
break;
} else {
- Z_ADDREF_PP(test_ptr);
- zend_hash_next_index_insert(Z_ARRVAL_PP(ptr), (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ ptr = tmp_ptr;
+ Z_TRY_ADDREF_P(test_ptr);
+ ptr = zend_hash_next_index_insert(Z_ARRVAL_P(ptr), test_ptr);
break;
}
}
} else {
/* this is the leaf */
- Z_ADDREF_PP(test_ptr);
- if (Z_TYPE_PP(ptr) != IS_ARRAY) {
- zval_dtor(*ptr);
- array_init(*ptr);
+ Z_TRY_ADDREF_P(test_ptr);
+ if (Z_TYPE_P(ptr) != IS_ARRAY) {
+ zval_dtor(ptr);
+ array_init(ptr);
}
- if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(zdata_ptr), &hkey.str, &hkey.len, &hkey.num, hkey.dup, NULL)) {
- zend_hash_update(Z_ARRVAL_PP(ptr), hkey.str, hkey.len, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
- } else if (hkey.num) {
- zend_hash_index_update(Z_ARRVAL_PP(ptr), hkey.num, (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ if (HASH_KEY_IS_STRING == zend_hash_get_current_key(Z_ARRVAL_P(zdata_ptr), &hkey.key, &hkey.h)) {
+ ptr = zend_hash_update(Z_ARRVAL_P(ptr), hkey.key, test_ptr);
+ } else if (hkey.h) {
+ ptr = zend_hash_index_update(Z_ARRVAL_P(ptr), hkey.h, test_ptr);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_PP(ptr), (void *) test_ptr, sizeof(zval *), (void *) &ptr);
+ ptr = zend_hash_next_index_insert(Z_ARRVAL_P(ptr), test_ptr);
}
break;
}
}
/* bubble up */
- while (Z_TYPE_PP(ptr) == IS_ARRAY && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_PP(ptr), (void *) &ptr));
+ while (Z_TYPE_P(ptr) == IS_ARRAY) {
+ zval *tmp = zend_hash_get_current_data(Z_ARRVAL_P(ptr));
+
+ if (tmp) {
+ ptr = tmp;
+ } else {
+ break;
+ }
+ }
*current_param = ptr;
}
-static void push_param(HashTable *params, php_http_params_state_t *state, const php_http_params_opts_t *opts TSRMLS_DC)
+static void push_param(HashTable *params, php_http_params_state_t *state, const php_http_params_opts_t *opts)
{
if (state->val.str) {
if (0 < (state->val.len = state->input.str - state->val.str)) {
- sanitize_value(opts->flags, state->val.str, state->val.len, *(state->current.val), state->rfc5987 TSRMLS_CC);
+ sanitize_value(opts->flags, state->val.str, state->val.len, state->current.val, state->rfc5987);
}
state->rfc5987 = 0;
} else if (state->arg.str) {
if (0 < (state->arg.len = state->input.str - state->arg.str)) {
- zval *val, key;
+ zval val, key;
zend_bool rfc5987 = 0;
- INIT_PZVAL(&key);
ZVAL_NULL(&key);
- sanitize_key(opts->flags, state->arg.str, state->arg.len, &key, &rfc5987 TSRMLS_CC);
+ sanitize_key(opts->flags, state->arg.str, state->arg.len, &key, &rfc5987);
state->rfc5987 = rfc5987;
if (Z_TYPE(key) == IS_STRING && Z_STRLEN(key)) {
- MAKE_STD_ZVAL(val);
- ZVAL_TRUE(val);
+ ZVAL_TRUE(&val);
if (rfc5987) {
- zval **rfc;
+ zval *rfc;
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(state->current.args), ZEND_STRS("*rfc5987*"), (void *) &rfc)) {
- zend_symtable_update(Z_ARRVAL_PP(rfc), Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &val, sizeof(zval *), (void *) &state->current.val);
+ if ((rfc = zend_hash_str_find(Z_ARRVAL_P(state->current.args), ZEND_STRL("*rfc5987*")))) {
+ state->current.val = zend_symtable_str_update(Z_ARRVAL_P(rfc), Z_STRVAL(key), Z_STRLEN(key), &val);
} else {
- zval *tmp;
+ zval tmp;
- MAKE_STD_ZVAL(tmp);
- array_init_size(tmp, 1);
- zend_symtable_update(Z_ARRVAL_P(tmp), Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &val, sizeof(zval *), (void *) &state->current.val);
- zend_symtable_update(Z_ARRVAL_PP(state->current.args), ZEND_STRS("*rfc5987*"), (void *) &tmp, sizeof(zval *), NULL);
+ array_init_size(&tmp, 1);
+ state->current.val = zend_symtable_str_update(Z_ARRVAL(tmp), Z_STRVAL(key), Z_STRLEN(key), &val);
+ zend_symtable_str_update(Z_ARRVAL_P(state->current.args), ZEND_STRL("*rfc5987*"), &tmp);
}
} else {
- zend_symtable_update(Z_ARRVAL_PP(state->current.args), Z_STRVAL(key), Z_STRLEN(key) + 1, (void *) &val, sizeof(zval *), (void *) &state->current.val);
+ state->current.val = zend_symtable_str_update(Z_ARRVAL_P(state->current.args), Z_STRVAL(key), Z_STRLEN(key), &val);
}
}
zval_dtor(&key);
}
} else if (state->param.str) {
if (0 < (state->param.len = state->input.str - state->param.str)) {
- zval *prm, *arg, *val, *key;
+ zval prm, arg, val, key;
zend_bool rfc5987 = 0;
- MAKE_STD_ZVAL(key);
- ZVAL_NULL(key);
+ ZVAL_NULL(&key);
if (opts->flags & PHP_HTTP_PARAMS_RFC5988) {
- sanitize_rfc5988(state->param.str, state->param.len, key TSRMLS_CC);
+ sanitize_rfc5988(state->param.str, state->param.len, &key);
} else {
- sanitize_key(opts->flags, state->param.str, state->param.len, key, &rfc5987 TSRMLS_CC);
+ sanitize_key(opts->flags, state->param.str, state->param.len, &key, &rfc5987);
state->rfc5987 = rfc5987;
}
- if (Z_TYPE_P(key) != IS_STRING) {
- merge_param(params, key, &state->current.val, &state->current.args TSRMLS_CC);
- } else if (Z_STRLEN_P(key)) {
- MAKE_STD_ZVAL(prm);
- array_init_size(prm, 2);
-
- MAKE_STD_ZVAL(val);
- if (opts->defval) {
- ZVAL_COPY_VALUE(val, opts->defval);
- zval_copy_ctor(val);
+ if (Z_TYPE(key) == IS_ARRAY) {
+ merge_param(params, &key, &state->current.val, &state->current.args);
+ } else if (Z_TYPE(key) == IS_STRING && Z_STRLEN(key)) {
+ // FIXME: array_init_size(&prm, 2);
+ array_init(&prm);
+
+ if (!Z_ISUNDEF(opts->defval)) {
+ ZVAL_COPY_VALUE(&val, &opts->defval);
+ zval_copy_ctor(&val);
} else {
- ZVAL_TRUE(val);
+ ZVAL_TRUE(&val);
}
if (rfc5987 && (opts->flags & PHP_HTTP_PARAMS_RFC5987)) {
- zend_hash_update(Z_ARRVAL_P(prm), "*rfc5987*", sizeof("*rfc5987*"), (void *) &val, sizeof(zval *), (void *) &state->current.val);
+ state->current.val = zend_hash_str_update(Z_ARRVAL(prm), "*rfc5987*", lenof("*rfc5987*"), &val);
} else {
- zend_hash_update(Z_ARRVAL_P(prm), "value", sizeof("value"), (void *) &val, sizeof(zval *), (void *) &state->current.val);
+ state->current.val = zend_hash_str_update(Z_ARRVAL(prm), "value", lenof("value"), &val);
}
-
- MAKE_STD_ZVAL(arg);
- array_init_size(arg, 3);
- zend_hash_update(Z_ARRVAL_P(prm), "arguments", sizeof("arguments"), (void *) &arg, sizeof(zval *), (void *) &state->current.args);
-
- zend_symtable_update(params, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void *) &prm, sizeof(zval *), (void *) &state->current.param);
+ // FIXME: array_init_size(&arg, 3);
+ array_init(&arg);
+ state->current.args = zend_hash_str_update(Z_ARRVAL(prm), "arguments", lenof("arguments"), &arg);
+ state->current.param = zend_symtable_str_update(params, Z_STRVAL(key), Z_STRLEN(key), &prm);
}
zval_ptr_dtor(&key);
}
return 0;
}
-static void skip_sep(size_t skip, php_http_params_state_t *state, php_http_params_token_t **param, php_http_params_token_t **arg, php_http_params_token_t **val TSRMLS_DC)
+static void skip_sep(size_t skip, php_http_params_state_t *state, php_http_params_token_t **param, php_http_params_token_t **arg, php_http_params_token_t **val)
{
size_t sep_len;
}
}
-HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts TSRMLS_DC)
+HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts)
{
php_http_params_state_t state = {{NULL,0}, {NULL,0}, {NULL,0}, {NULL,0}, {NULL,NULL,NULL}, 0, 0};
if (!state.param.str) {
/* initialize */
- skip_sep(0, &state, opts->param, opts->arg, opts->val TSRMLS_CC);
+ skip_sep(0, &state, opts->param, opts->arg, opts->val);
state.param.str = state.input.str;
} else {
size_t sep_len;
/* are we at a param separator? */
if (0 < (sep_len = check_sep(&state, opts->param))) {
- push_param(params, &state, opts TSRMLS_CC);
+ push_param(params, &state, opts);
- skip_sep(sep_len, &state, opts->param, opts->arg, opts->val TSRMLS_CC);
+ skip_sep(sep_len, &state, opts->param, opts->arg, opts->val);
/* start off with a new param */
state.param.str = state.input.str;
} else
/* are we at an arg separator? */
if (0 < (sep_len = check_sep(&state, opts->arg))) {
- push_param(params, &state, opts TSRMLS_CC);
+ push_param(params, &state, opts);
- skip_sep(sep_len, &state, NULL, opts->arg, opts->val TSRMLS_CC);
+ skip_sep(sep_len, &state, NULL, opts->arg, opts->val);
/* continue with a new arg */
state.arg.str = state.input.str;
if (0 < (sep_len = check_sep(&state, opts->val))) {
/* only handle separator if we're not already reading in a val */
if (!state.val.str) {
- push_param(params, &state, opts TSRMLS_CC);
+ push_param(params, &state, opts);
- skip_sep(sep_len, &state, NULL, NULL, opts->val TSRMLS_CC);
+ skip_sep(sep_len, &state, NULL, NULL, opts->val);
state.val.str = state.input.str;
state.val.len = 0;
}
}
/* finalize */
- push_param(params, &state, opts TSRMLS_CC);
+ push_param(params, &state, opts);
return params;
}
-static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags TSRMLS_DC)
+static inline void shift_key(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags)
{
char *str;
size_t len;
php_http_buffer_append(buf, ass, asl);
}
- prepare_key(flags, key_str, key_len, &str, &len TSRMLS_CC);
+ prepare_key(flags, key_str, key_len, &str, &len);
php_http_buffer_append(buf, str, len);
efree(str);
}
-static inline void shift_rfc5987(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+static inline void shift_rfc5987(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags)
{
HashTable *ht = HASH_OF(zvalue);
- zval **zdata, *tmp;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval *zdata, tmp;
+ zend_string *zs;
+ php_http_arrkey_t key = {0};
- if (SUCCESS == zend_hash_get_current_data(ht, (void *) &zdata)
- && HASH_KEY_NON_EXISTENT != (key.type = zend_hash_get_current_key_ex(ht, &key.str, &key.len, &key.num, key.dup, NULL))
+ if ((zdata = zend_hash_get_current_data(ht))
+ && HASH_KEY_NON_EXISTENT != zend_hash_get_current_key(ht, &key.key, &key.h)
) {
- php_http_array_hashkey_stringify(&key);
+ php_http_arrkey_stringify(&key, NULL);
php_http_buffer_appendf(buf, "*%.*sutf-8'%.*s'",
(int) (vsl > INT_MAX ? INT_MAX : vsl), vss,
- (int) (key.len > INT_MAX ? INT_MAX : key.len), key.str);
- php_http_array_hashkey_stringfree(&key);
+ (int) (key.key->len > INT_MAX ? INT_MAX : key.key->len), key.key->val);
+ php_http_arrkey_dtor(&key);
- tmp = php_http_zsep(1, IS_STRING, *zdata);
- prepare_value(flags | PHP_HTTP_PARAMS_URLENCODED, tmp TSRMLS_CC);
- php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ if (Z_TYPE_P(zdata) == IS_INDIRECT) {
+ zdata = Z_INDIRECT_P(zdata);
+ }
+ zs = zval_get_string(zdata);
+ ZVAL_STR(&tmp, zs);
+ prepare_value(flags | PHP_HTTP_PARAMS_URLENCODED, &tmp);
+ php_http_buffer_append(buf, Z_STRVAL(tmp), Z_STRLEN(tmp));
zval_ptr_dtor(&tmp);
}
}
-static inline void shift_rfc5988(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags TSRMLS_DC)
+static inline void shift_rfc5988(php_http_buffer_t *buf, char *key_str, size_t key_len, const char *ass, size_t asl, unsigned flags)
{
char *str;
size_t len;
php_http_buffer_append(buf, ass, asl);
}
- prepare_key(flags, key_str, key_len, &str, &len TSRMLS_CC);
+ prepare_key(flags, key_str, key_len, &str, &len);
php_http_buffer_appends(buf, "<");
php_http_buffer_append(buf, str, len);
php_http_buffer_appends(buf, ">");
efree(str);
}
-static inline void shift_rfc5988_val(php_http_buffer_t *buf, zval *zv, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+static inline void shift_rfc5988_val(php_http_buffer_t *buf, zval *zv, const char *vss, size_t vsl, unsigned flags)
{
- zval *tmp = php_http_zsep(1, IS_STRING, zv);
+ zend_string *zs = zval_get_string(zv);
- quote_string(tmp, 1 TSRMLS_CC);
+ quote_string(&zs, 1);
php_http_buffer_append(buf, vss, vsl);
- php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ php_http_buffer_append(buf, zs->val, zs->len);
- zval_ptr_dtor(&tmp);
+ zend_string_release(zs);
}
-static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+static inline void shift_val(php_http_buffer_t *buf, zval *zvalue, const char *vss, size_t vsl, unsigned flags)
{
- if (Z_TYPE_P(zvalue) != IS_BOOL) {
- zval *tmp = php_http_zsep(1, IS_STRING, zvalue);
+ zval tmp;
+ zend_string *zs;
- prepare_value(flags, tmp TSRMLS_CC);
- php_http_buffer_append(buf, vss, vsl);
- php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
+ switch (Z_TYPE_P(zvalue)) {
+ case IS_TRUE:
+ break;
- zval_ptr_dtor(&tmp);
- } else if (!Z_BVAL_P(zvalue)) {
+ case IS_FALSE:
php_http_buffer_append(buf, vss, vsl);
php_http_buffer_appends(buf, "0");
+ break;
+
+ default:
+ zs = zval_get_string(zvalue);
+
+ ZVAL_STR(&tmp, zs);
+ prepare_value(flags, &tmp);
+ php_http_buffer_append(buf, vss, vsl);
+ php_http_buffer_append(buf, Z_STRVAL(tmp), Z_STRLEN(tmp));
+
+ zval_ptr_dtor(&tmp);
+ break;
}
}
-static void shift_arg(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+static void shift_arg(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags)
{
if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **val;
+ php_http_arrkey_t key;
+ HashTable *ht = HASH_OF(zvalue);
+ zval *val;
zend_bool rfc5987 = !strcmp(key_str, "*rfc5987*");
if (!rfc5987) {
- shift_key(buf, key_str, key_len, ass, asl, flags TSRMLS_CC);
+ shift_key(buf, key_str, key_len, ass, asl, flags);
}
- FOREACH_KEYVAL(pos, zvalue, key, val) {
+ ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, val)
+ {
/* did you mean recursion? */
- php_http_array_hashkey_stringify(&key);
- if (rfc5987 && (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT)) {
- shift_key(buf, key.str, key.len-1, ass, asl, flags TSRMLS_CC);
- shift_rfc5987(buf, *val, vss, vsl, flags TSRMLS_CC);
+ php_http_arrkey_stringify(&key, NULL);
+ if (rfc5987 && (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT)) {
+ shift_key(buf, key.key->val, key.key->len, ass, asl, flags);
+ shift_rfc5987(buf, val, vss, vsl, flags);
} else {
- shift_arg(buf, key.str, key.len-1, *val, ass, asl, vss, vsl, flags TSRMLS_CC);
+ shift_arg(buf, key.key->val, key.key->len, val, ass, asl, vss, vsl, flags);
}
- php_http_array_hashkey_stringfree(&key);
+ php_http_arrkey_dtor(&key);
}
+ ZEND_HASH_FOREACH_END();
} else {
- shift_key(buf, key_str, key_len, ass, asl, flags TSRMLS_CC);
+ shift_key(buf, key_str, key_len, ass, asl, flags);
if (flags & PHP_HTTP_PARAMS_RFC5988) {
switch (key_len) {
case lenof("anchor"):
/* some args must be quoted */
if (0 <= php_http_select_str(key_str, 3, "rel", "title", "anchor")) {
- shift_rfc5988_val(buf, zvalue, vss, vsl, flags TSRMLS_CC);
+ shift_rfc5988_val(buf, zvalue, vss, vsl, flags);
return;
}
break;
}
}
- shift_val(buf, zvalue, vss, vsl, flags TSRMLS_CC);
+ shift_val(buf, zvalue, vss, vsl, flags);
}
}
-static void shift_param(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags, zend_bool rfc5987 TSRMLS_DC)
+static void shift_param(php_http_buffer_t *buf, char *key_str, size_t key_len, zval *zvalue, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags, zend_bool rfc5987)
{
if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
/* treat as arguments, unless we care for dimensions or rfc5987 */
if (flags & PHP_HTTP_PARAMS_DIMENSION) {
php_http_buffer_t *keybuf = php_http_buffer_from_string(key_str, key_len);
- prepare_dimension(buf, keybuf, zvalue, pss, psl, vss, vsl, flags TSRMLS_CC);
+ prepare_dimension(buf, keybuf, zvalue, pss, psl, vss, vsl, flags);
php_http_buffer_free(&keybuf);
} else if (rfc5987) {
- shift_key(buf, key_str, key_len, pss, psl, flags TSRMLS_CC);
- shift_rfc5987(buf, zvalue, vss, vsl, flags TSRMLS_CC);
+ shift_key(buf, key_str, key_len, pss, psl, flags);
+ shift_rfc5987(buf, zvalue, vss, vsl, flags);
} else {
- shift_arg(buf, key_str, key_len, zvalue, ass, asl, vss, vsl, flags TSRMLS_CC);
+ shift_arg(buf, key_str, key_len, zvalue, ass, asl, vss, vsl, flags);
}
} else {
if (flags & PHP_HTTP_PARAMS_RFC5988) {
- shift_rfc5988(buf, key_str, key_len, pss, psl, flags TSRMLS_CC);
+ shift_rfc5988(buf, key_str, key_len, pss, psl, flags);
} else {
- shift_key(buf, key_str, key_len, pss, psl, flags TSRMLS_CC);
+ shift_key(buf, key_str, key_len, pss, psl, flags);
}
- shift_val(buf, zvalue, vss, vsl, flags TSRMLS_CC);
+ shift_val(buf, zvalue, vss, vsl, flags);
}
}
-php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags)
{
- zval **zparam;
- HashPosition pos, pos1;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0), key1 = php_http_array_hashkey_init(0);
+ zval *zparam;
+ php_http_arrkey_t key;
zend_bool rfc5987 = 0;
if (!buf) {
buf = php_http_buffer_init(NULL);
}
- FOREACH_HASH_KEYVAL(pos, params, key, zparam) {
- zval **zvalue, **zargs;
+ ZEND_HASH_FOREACH_KEY_VAL(params, key.h, key.key, zparam)
+ {
+ zval *zvalue, *zargs;
- if (Z_TYPE_PP(zparam) != IS_ARRAY) {
+ if (Z_TYPE_P(zparam) != IS_ARRAY) {
zvalue = zparam;
} else {
- if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("value"), (void *) &zvalue)) {
- if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("*rfc5987*"), (void *) &zvalue)) {
+ if (!(zvalue = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("value")))) {
+ if (!(zvalue = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("*rfc5987*")))) {
zvalue = zparam;
} else {
rfc5987 = 1;
}
}
- php_http_array_hashkey_stringify(&key);
- shift_param(buf, key.str, key.len - 1, *zvalue, pss, psl, ass, asl, vss, vsl, flags, rfc5987 TSRMLS_CC);
- php_http_array_hashkey_stringfree(&key);
+ php_http_arrkey_stringify(&key, NULL);
+ shift_param(buf, key.key->val, key.key->len, zvalue, pss, psl, ass, asl, vss, vsl, flags, rfc5987);
+ php_http_arrkey_dtor(&key);
+
+ if (Z_TYPE_P(zparam) == IS_ARRAY) {
+ zval *tmp = zend_hash_str_find(Z_ARRVAL_P(zparam), ZEND_STRL("arguments"));
- if (Z_TYPE_PP(zparam) == IS_ARRAY && SUCCESS != zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("arguments"), (void *) &zvalue)) {
- if (zvalue == zparam) {
+ if (tmp) {
+ zvalue = tmp;
+ } else if (zvalue == zparam) {
continue;
+ } else {
+ zvalue = zparam;
}
- zvalue = zparam;
}
- if (Z_TYPE_PP(zvalue) == IS_ARRAY) {
- FOREACH_KEYVAL(pos1, *zvalue, key1, zargs) {
- if (zvalue == zparam && key1.type == HASH_KEY_IS_STRING && !strcmp(key1.str, "value")) {
+ if (Z_TYPE_P(zvalue) == IS_ARRAY) {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zvalue), key.h, key.key, zargs)
+ {
+ if (zvalue == zparam && key.key && zend_string_equals_literal(key.key, "value")) {
continue;
}
- php_http_array_hashkey_stringify(&key1);
- shift_arg(buf, key1.str, key1.len - 1, *zargs, ass, asl, vss, vsl, flags TSRMLS_CC);
- php_http_array_hashkey_stringfree(&key1);
+ php_http_arrkey_stringify(&key, NULL);
+ shift_arg(buf, key.key->val, key.key->len, zargs, ass, asl, vss, vsl, flags);
+ php_http_arrkey_dtor(&key);
}
+ ZEND_HASH_FOREACH_END();
}
}
+ ZEND_HASH_FOREACH_END();
php_http_buffer_shrink(buf);
php_http_buffer_fix(buf);
return buf;
}
-php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC)
+php_http_params_token_t **php_http_params_separator_init(zval *zv)
{
- zval **sep;
- HashPosition pos;
+ zval *sep, ztmp;
php_http_params_token_t **ret, **tmp;
if (!zv) {
return NULL;
}
- zv = php_http_ztyp(IS_ARRAY, zv);
+ ZVAL_DUP(&ztmp, zv);
+ zv = &ztmp;
+ convert_to_array(zv);
+
ret = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(zv)) + 1, sizeof(*ret));
tmp = ret;
- FOREACH_VAL(pos, zv, sep) {
- zval *zt = php_http_ztyp(IS_STRING, *sep);
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zv), sep)
+ {
+ zend_string *zs = zval_get_string(sep);
- if (Z_STRLEN_P(zt)) {
+ if (zs->len) {
*tmp = emalloc(sizeof(**tmp));
- (*tmp)->str = estrndup(Z_STRVAL_P(zt), (*tmp)->len = Z_STRLEN_P(zt));
+ (*tmp)->str = estrndup(zs->val, (*tmp)->len = zs->len);
++tmp;
}
- zval_ptr_dtor(&zt);
+ zend_string_release(zs);
}
- zval_ptr_dtor(&zv);
+ ZEND_HASH_FOREACH_END();
+
+ zval_ptr_dtor(&ztmp);
*tmp = NULL;
return ret;
}
}
+static zend_class_entry *php_http_params_class_entry;
+zend_class_entry *php_http_params_get_class_entry(void)
+{
+ return php_http_params_class_entry;
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams___construct, 0, 0, 0)
ZEND_ARG_INFO(0, params)
ZEND_ARG_INFO(0, param_sep)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, __construct)
{
- zval *zcopy, *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
- long flags = PHP_HTTP_PARAMS_DEFAULT;
+ zval *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
+ zend_long flags = PHP_HTTP_PARAMS_DEFAULT;
zend_error_handling zeh;
+ zend_string *zs;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh);
{
switch (ZEND_NUM_ARGS()) {
case 5:
- zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags TSRMLS_CC);
+ zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags);
/* no break */
case 4:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep);
/* no break */
case 3:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep TSRMLS_CC);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep);
/* no break */
case 2:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep TSRMLS_CC);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep);
/* no break */
}
switch (Z_TYPE_P(zparams)) {
case IS_OBJECT:
case IS_ARRAY:
- zcopy = php_http_zsep(1, IS_ARRAY, zparams);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zcopy TSRMLS_CC);
- zval_ptr_dtor(&zcopy);
+ convert_to_array(zparams);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
break;
default:
- zcopy = php_http_ztyp(IS_STRING, zparams);
- if (Z_STRLEN_P(zcopy)) {
+ zs = zval_get_string(zparams);
+ if (zs->len) {
+ zval tmp;
+
php_http_params_opts_t opts = {
- {Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy)},
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- NULL, flags
+ {zs->val, zs->len},
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0, &tmp)),
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0, &tmp)),
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0, &tmp)),
+ {{0}}, flags
};
- MAKE_STD_ZVAL(zparams);
- array_init(zparams);
- php_http_params_parse(Z_ARRVAL_P(zparams), &opts TSRMLS_CC);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
+ array_init(&tmp);
+ php_http_params_parse(Z_ARRVAL(tmp), &opts);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
+ zval_ptr_dtor(&tmp);
php_http_params_separator_free(opts.param);
php_http_params_separator_free(opts.arg);
php_http_params_separator_free(opts.val);
}
- zval_ptr_dtor(&zcopy);
+ zend_string_release(zs);
break;
}
} else {
- MAKE_STD_ZVAL(zparams);
- array_init(zparams);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
+ zval tmp;
+
+ array_init(&tmp);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
+ zval_ptr_dtor(&tmp);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toArray, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, toArray)
{
- zval *zparams;
+ zval zparams_tmp, *zparams;
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC);
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
RETURN_ZVAL(zparams, 1, 0);
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, toString)
{
- zval **tmp, *zparams, *zpsep, *zasep, *zvsep, *zflags;
+ zval *tmp, *zparams, *zpsep, *zasep, *zvsep;
+ zval zparams_tmp, flags_tmp, psep_tmp, asep_tmp, vsep_tmp;
+ zend_string *psep, *asep, *vsep;
+ long flags;
php_http_buffer_t buf;
- zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
- zflags = php_http_ztyp(IS_LONG, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), 0 TSRMLS_CC));
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
+ convert_to_array_ex(zparams);
+ flags = zval_get_long(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), 0, &flags_tmp));
- zpsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC);
- if (Z_TYPE_P(zpsep) == IS_ARRAY && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zpsep), (void *) &tmp)) {
- zpsep = php_http_ztyp(IS_STRING, *tmp);
+ zpsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0, &psep_tmp);
+ if (Z_TYPE_P(zpsep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zpsep)))) {
+ psep = zval_get_string(tmp);
} else {
- zpsep = php_http_ztyp(IS_STRING, zpsep);
+ psep = zval_get_string(zpsep);
}
- zasep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC);
- if (Z_TYPE_P(zasep) == IS_ARRAY && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zasep), (void *) &tmp)) {
- zasep = php_http_ztyp(IS_STRING, *tmp);
+ zasep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0, &asep_tmp);
+ if (Z_TYPE_P(zasep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zasep)))) {
+ asep = zval_get_string(tmp);
} else {
- zasep = php_http_ztyp(IS_STRING, zasep);
+ asep = zval_get_string(zasep);
}
- zvsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC);
- if (Z_TYPE_P(zvsep) == IS_ARRAY && SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zvsep), (void *) &tmp)) {
- zvsep = php_http_ztyp(IS_STRING, *tmp);
+ zvsep = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0, &vsep_tmp);
+ if (Z_TYPE_P(zvsep) == IS_ARRAY && (tmp = zend_hash_get_current_data(Z_ARRVAL_P(zvsep)))) {
+ vsep = zval_get_string(tmp);
} else {
- zvsep = php_http_ztyp(IS_STRING, zvsep);
+ vsep = zval_get_string(zvsep);
}
php_http_buffer_init(&buf);
- php_http_params_to_string(&buf, Z_ARRVAL_P(zparams), Z_STRVAL_P(zpsep), Z_STRLEN_P(zpsep), Z_STRVAL_P(zasep), Z_STRLEN_P(zasep), Z_STRVAL_P(zvsep), Z_STRLEN_P(zvsep), Z_LVAL_P(zflags) TSRMLS_CC);
+ php_http_params_to_string(&buf, Z_ARRVAL_P(zparams), psep->val, psep->len, asep->val, asep->len, vsep->val, vsep->len, flags);
- zval_ptr_dtor(&zparams);
- zval_ptr_dtor(&zpsep);
- zval_ptr_dtor(&zasep);
- zval_ptr_dtor(&zvsep);
- zval_ptr_dtor(&zflags);
+ zend_string_release(psep);
+ zend_string_release(asep);
+ zend_string_release(vsep);
- RETVAL_PHP_HTTP_BUFFER_VAL(&buf);
+ RETVAL_STR(php_http_cs2zs(buf.data, buf.used));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetExists, 0, 0, 1)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, offsetExists)
{
- char *name_str;
- int name_len;
- zval **zparam, *zparams;
+ zend_string *name;
+ zval zparams_tmp, *zparam, *zparams;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
return;
}
- zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- RETVAL_BOOL(Z_TYPE_PP(zparam) != IS_NULL);
+ if (Z_TYPE_P(zparams) == IS_ARRAY && (zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
+ RETVAL_BOOL(Z_TYPE_P(zparam) != IS_NULL);
} else {
RETVAL_FALSE;
}
- zval_ptr_dtor(&zparams);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetGet, 0, 0, 1)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, offsetGet)
{
- char *name_str;
- int name_len;
- zval **zparam, *zparams;
+ zend_string *name;
+ zval zparams_tmp, *zparam, *zparams;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
return;
}
- zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- RETVAL_ZVAL(*zparam, 1, 0);
+ if (Z_TYPE_P(zparams) == IS_ARRAY && (zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
+ RETVAL_ZVAL(zparam, 1, 0);
}
-
- zval_ptr_dtor(&zparams);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetUnset, 0, 0, 1)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, offsetUnset)
{
- char *name_str;
- int name_len;
- zval *zparams;
+ zend_string *name;
+ zval zparams_tmp, *zparams;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name)) {
return;
}
- zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
- zend_symtable_del(Z_ARRVAL_P(zparams), name_str, name_len + 1);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
-
- zval_ptr_dtor(&zparams);
+ if (Z_TYPE_P(zparams) == IS_ARRAY) {
+ zend_symtable_del(Z_ARRVAL_P(zparams), name);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetSet, 0, 0, 2)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, offsetSet)
{
- zval *nvalue;
- char *name_str;
- int name_len;
- zval **zparam, *zparams;
+ zend_string *name;
+ zval zparams_tmp, *zparam, *zparams, *nvalue;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &nvalue)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &nvalue)) {
return;
}
- zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0, &zparams_tmp);
+ convert_to_array(zparams);
- if (name_len) {
+ if (name->len) {
if (Z_TYPE_P(nvalue) == IS_ARRAY) {
- zval *new_zparam;
-
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- new_zparam = php_http_zsep(1, IS_ARRAY, *zparam);
- array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(new_zparam), 0, 0);
+ if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
+ convert_to_array(zparam);
+ array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(zparam), 0, 0);
} else {
- new_zparam = nvalue;
- Z_ADDREF_P(new_zparam);
+ Z_TRY_ADDREF_P(nvalue);
+ add_assoc_zval_ex(zparams, name->val, name->len, nvalue);
}
- add_assoc_zval_ex(zparams, name_str, name_len + 1, new_zparam);
} else {
- zval *tmp;
+ zval tmp;
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- tmp = php_http_zsep(1, IS_ARRAY, *zparam);
+ if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
+ ZVAL_DUP(&tmp, zparam);
+ convert_to_array(&tmp);
} else {
- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
+ array_init(&tmp);
}
- Z_ADDREF_P(nvalue);
- add_assoc_zval_ex(tmp, ZEND_STRS("value"), nvalue);
- add_assoc_zval_ex(zparams, name_str, name_len + 1, tmp);
+ Z_TRY_ADDREF_P(nvalue);
+ add_assoc_zval_ex(&tmp, ZEND_STRL("value"), nvalue);
+ add_assoc_zval_ex(zparams, name->val, name->len, &tmp);
}
} else {
- zval *tmp = php_http_ztyp(IS_STRING, nvalue), *arr;
+ zval arr;
+ zend_string *zs = zval_get_string(nvalue);
- MAKE_STD_ZVAL(arr);
- array_init(arr);
- add_assoc_bool_ex(arr, ZEND_STRS("value"), 1);
- add_assoc_zval_ex(zparams, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 1, arr);
- zval_ptr_dtor(&tmp);
+ array_init(&arr);
+ add_assoc_bool_ex(&arr, ZEND_STRL("value"), 1);
+ add_assoc_zval_ex(zparams, zs->val, zs->len, &arr);
+ zend_string_release(zs);
}
-
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
}
static zend_function_entry php_http_params_methods[] = {
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_params_class_entry;
-
PHP_MINIT_FUNCTION(http_params)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Params", php_http_params_methods);
- php_http_params_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_params_class_entry = zend_register_internal_class(&ce);
php_http_params_class_entry->create_object = php_http_params_object_new;
- zend_class_implements(php_http_params_class_entry TSRMLS_CC, 1, zend_ce_arrayaccess);
-
- zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_PARAM_SEP"), ZEND_STRL(",") TSRMLS_CC);
- zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_ARG_SEP"), ZEND_STRL(";") TSRMLS_CC);
- zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("=") TSRMLS_CC);
- zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL("") TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_ESCAPED"), PHP_HTTP_PARAMS_ESCAPED TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5987"), PHP_HTTP_PARAMS_RFC5987 TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5988"), PHP_HTTP_PARAMS_RFC5988 TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY TSRMLS_CC);
-
- zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_class_implements(php_http_params_class_entry, 1, zend_ce_arrayaccess);
+
+ zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_PARAM_SEP"), ZEND_STRL(","));
+ zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_ARG_SEP"), ZEND_STRL(";"));
+ zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("="));
+ zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL(""));
+
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_ESCAPED"), PHP_HTTP_PARAMS_ESCAPED);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5987"), PHP_HTTP_PARAMS_RFC5987);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RFC5988"), PHP_HTTP_PARAMS_RFC5988);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT);
+ zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY);
+
+ zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC);
+ zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC);
+ zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC);
+ zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC);
+ zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC);
return SUCCESS;
}
php_http_params_token_t **param;
php_http_params_token_t **arg;
php_http_params_token_t **val;
- zval *defval;
+ zval defval;
unsigned flags;
} php_http_params_opts_t;
PHP_HTTP_API php_http_params_opts_t *php_http_params_opts_default_get(php_http_params_opts_t *opts);
-PHP_HTTP_API HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts TSRMLS_DC);
-PHP_HTTP_API php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC);
+PHP_HTTP_API HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts);
+PHP_HTTP_API php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags);
-PHP_HTTP_API php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC);
+PHP_HTTP_API php_http_params_token_t **php_http_params_separator_init(zval *zv);
PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separator);
typedef php_http_object_t php_http_params_object_t;
-PHP_HTTP_API zend_class_entry *php_http_params_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_params_get_class_entry(void);
PHP_MINIT_FUNCTION(http_params);
# include <ext/iconv/php_iconv.h>
#endif
+static zend_class_entry *php_http_querystring_class_entry;
+zend_class_entry *php_http_querystring_get_class_entry(void)
+{
+ return php_http_querystring_class_entry;
+}
+
#define QS_MERGE 1
-static inline void php_http_querystring_set(zval *instance, zval *params, int flags TSRMLS_DC)
+static inline void php_http_querystring_set(zval *instance, zval *params, int flags)
{
- zval *qa;
+ zval qa;
+
+ array_init(&qa);
if (flags & QS_MERGE) {
- qa = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC));
- } else {
- MAKE_STD_ZVAL(qa);
- array_init(qa);
+ zval old_tmp, *old = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &old_tmp);
+
+ ZVAL_DEREF(old);
+ if (Z_TYPE_P(old) == IS_ARRAY) {
+ array_copy(Z_ARRVAL_P(old), Z_ARRVAL(qa));
+ }
}
- php_http_querystring_update(qa, params, NULL TSRMLS_CC);
- zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), qa TSRMLS_CC);
+ php_http_querystring_update(&qa, params, NULL);
+ zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), &qa);
zval_ptr_dtor(&qa);
}
-static inline void php_http_querystring_str(zval *instance, zval *return_value TSRMLS_DC)
+static inline void php_http_querystring_str(zval *instance, zval *return_value)
{
- zval *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ zval qa_tmp, *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &qa_tmp);
+ ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
- php_http_querystring_update(qa, NULL, return_value TSRMLS_CC);
+ php_http_querystring_update(qa, NULL, return_value);
} else {
RETURN_EMPTY_STRING();
}
}
-static inline void php_http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
+static inline void php_http_querystring_get(zval *instance, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value)
{
- zval **arrval, *qarray = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ zval *arrval, qarray_tmp, *qarray = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0, &qarray_tmp);
- if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
- if (type) {
- zval *value = php_http_ztyp(type, *arrval);
- RETVAL_ZVAL(value, 1, 1);
+ ZVAL_DEREF(qarray);
+ if ((Z_TYPE_P(qarray) == IS_ARRAY) && (arrval = zend_symtable_str_find(Z_ARRVAL_P(qarray), name, name_len))) {
+ if (type && type != Z_TYPE_P(arrval)) {
+ zval tmp;
+
+ ZVAL_DUP(&tmp, arrval);
+ convert_to_explicit_type(&tmp, type);
+ RETVAL_ZVAL(&tmp, 0, 0);
} else {
- RETVAL_ZVAL(*arrval, 1, 0);
+ RETVAL_ZVAL(arrval, 1, 0);
}
if (del) {
- zval *delarr;
+ zval delarr;
- MAKE_STD_ZVAL(delarr);
- array_init(delarr);
- add_assoc_null_ex(delarr, name, name_len + 1);
- php_http_querystring_set(this_ptr, delarr, QS_MERGE TSRMLS_CC);
+ array_init(&delarr);
+ add_assoc_null_ex(&delarr, name, name_len);
+ php_http_querystring_set(instance, &delarr, QS_MERGE);
zval_ptr_dtor(&delarr);
}
} else if(defval) {
}
#ifdef PHP_HTTP_HAVE_ICONV
-ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe TSRMLS_DC)
+ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe)
{
- HashPosition pos;
- zval **entry = NULL;
- char *xlate_str = NULL, *xkey;
- size_t xlate_len = 0, xlen;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval *entry;
+ zend_string *xkey, *xstr;
+ php_http_arrkey_t key;
- FOREACH_KEYVAL(pos, src, key, entry) {
- if (key.type == HASH_KEY_IS_STRING) {
- if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.str, key.len-1, &xkey, &xlen, oe, ie)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe);
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(src), key.h, key.key, entry)
+ {
+ if (key.key) {
+ if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.key->val, key.key->len, &xkey, oe, ie)) {
+ php_error_docref(NULL, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", key.key->len, key.key->val, ie, oe);
return FAILURE;
}
}
- if (Z_TYPE_PP(entry) == IS_STRING) {
- if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), &xlate_str, &xlate_len, oe, ie)) {
- if (key.type == HASH_KEY_IS_STRING) {
- efree(xkey);
+ if (Z_TYPE_P(entry) == IS_STRING) {
+ if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_P(entry), Z_STRLEN_P(entry), &xstr, oe, ie)) {
+ if (key.key) {
+ zend_string_release(xkey);
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe);
+ php_error_docref(NULL, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_P(entry), Z_STRVAL_P(entry), ie, oe);
return FAILURE;
}
- if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_stringl_ex(dst, xkey, xlen+1, xlate_str, xlate_len, 0);
+ if (key.key) {
+ add_assoc_str_ex(dst, xkey->val, xkey->len, xstr);
} else {
- add_index_stringl(dst, key.num, xlate_str, xlate_len, 0);
+ add_index_str(dst, key.h, xstr);
}
- } else if (Z_TYPE_PP(entry) == IS_ARRAY) {
- zval *subarray;
+ } else if (Z_TYPE_P(entry) == IS_ARRAY) {
+ zval subarray;
- MAKE_STD_ZVAL(subarray);
- array_init(subarray);
- if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_zval_ex(dst, xkey, xlen+1, subarray);
+ array_init(&subarray);
+ if (key.key) {
+ add_assoc_zval_ex(dst, xkey->val, xkey->len, &subarray);
} else {
- add_index_zval(dst, key.num, subarray);
+ add_index_zval(dst, key.h, &subarray);
}
- if (SUCCESS != php_http_querystring_xlate(subarray, *entry, ie, oe TSRMLS_CC)) {
- if (key.type == HASH_KEY_IS_STRING) {
- efree(xkey);
+ if (SUCCESS != php_http_querystring_xlate(&subarray, entry, ie, oe)) {
+ if (key.key) {
+ zend_string_release(xkey);
}
return FAILURE;
}
}
- if (key.type == HASH_KEY_IS_STRING) {
- efree(xkey);
+ if (key.key) {
+ zend_string_release(xkey);
}
}
+ ZEND_HASH_FOREACH_END();
+
return SUCCESS;
}
#endif /* HAVE_ICONV */
-ZEND_RESULT_CODE php_http_querystring_ctor(zval *instance, zval *params TSRMLS_DC)
+ZEND_RESULT_CODE php_http_querystring_ctor(zval *instance, zval *params)
{
- php_http_querystring_set(instance, params, 0 TSRMLS_CC);
+ php_http_querystring_set(instance, params, 0);
return SUCCESS;
}
-static int apply_querystring(void *pData TSRMLS_DC)
+static int apply_querystring(zval *val)
{
- zval **val = pData;
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ zval *zvalue;
- if (Z_TYPE_PP(val) == IS_ARRAY) {
- zval **zvalue;
+ if ((zvalue = zend_hash_str_find(Z_ARRVAL_P(val), ZEND_STRL("value")))) {
+ zval tmp;
- if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(val), ZEND_STRS("value"), (void *) &zvalue)) {
- zval *tmp = *val;
-
- Z_ADDREF_PP(zvalue);
- *val = *zvalue;
- zval_dtor(tmp);
- Z_TYPE_P(tmp) = IS_NULL;
- zval_ptr_dtor(&tmp);
+ ZVAL_COPY(&tmp, zvalue);
+ zval_dtor(val);
+ ZVAL_COPY_VALUE(val, &tmp);
}
}
return ZEND_HASH_APPLY_KEEP;
}
-ZEND_RESULT_CODE php_http_querystring_parse(HashTable *ht, const char *str, size_t len TSRMLS_DC)
+ZEND_RESULT_CODE php_http_querystring_parse(HashTable *ht, const char *str, size_t len)
{
ZEND_RESULT_CODE rv = FAILURE;
php_http_params_opts_t opts;
opts.val = vsepp;
opts.flags = PHP_HTTP_PARAMS_QUERY;
- if (SUCCESS == php_http_ini_entry(ZEND_STRL("arg_separator.input"), &asi_str, &asi_len, 0 TSRMLS_CC) && asi_len) {
- zval *arr;
+ if (SUCCESS == php_http_ini_entry(ZEND_STRL("arg_separator.input"), &asi_str, &asi_len, 0) && asi_len) {
+ zval arr;
- MAKE_STD_ZVAL(arr);
- array_init_size(arr, asi_len);
+ array_init_size(&arr, asi_len);
do {
- add_next_index_stringl(arr, asi_str++, 1, 1);
+ add_next_index_stringl(&arr, asi_str++, 1);
} while (*asi_str);
- opts.param = php_http_params_separator_init(arr TSRMLS_CC);
-
+ opts.param = php_http_params_separator_init(&arr);
zval_ptr_dtor(&arr);
}
- MAKE_STD_ZVAL(opts.defval);
- ZVAL_NULL(opts.defval);
+ ZVAL_NULL(&opts.defval);
- if (php_http_params_parse(ht, &opts TSRMLS_CC)) {
- zend_hash_apply(ht, apply_querystring TSRMLS_CC);
+ if (php_http_params_parse(ht, &opts)) {
+ zend_hash_apply(ht, apply_querystring);
rv = SUCCESS;
}
return rv;
}
-ZEND_RESULT_CODE php_http_querystring_update(zval *qarray, zval *params, zval *outstring TSRMLS_DC)
+ZEND_RESULT_CODE php_http_querystring_update(zval *qarray, zval *params, zval *outstring)
{
/* enforce proper type */
if (Z_TYPE_P(qarray) != IS_ARRAY) {
/* modify qarray */
if (params) {
- HashPosition pos;
- HashTable *ptr;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **params_entry, **qarray_entry;
- zval zv, *zv_ptr = NULL;
+ HashTable *ht;
+ php_http_arrkey_t key;
+ zval zv, *params_entry, *qarray_entry;
- INIT_PZVAL(&zv);
ZVAL_NULL(&zv);
/* squeeze the hash out of the zval */
- if (Z_TYPE_P(params) == IS_OBJECT && instanceof_function(Z_OBJCE_P(params), php_http_querystring_class_entry TSRMLS_CC)) {
- zv_ptr = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_class_entry, params, ZEND_STRL("queryArray"), 0 TSRMLS_CC));
- ptr = Z_ARRVAL_P(zv_ptr);
+ if (Z_TYPE_P(params) == IS_OBJECT && instanceof_function(Z_OBJCE_P(params), php_http_querystring_class_entry)) {
+ zval qa_tmp, *qa = zend_read_property(php_http_querystring_class_entry, params, ZEND_STRL("queryArray"), 0, &qa_tmp);
+
+ ZVAL_DEREF(qa);
+ convert_to_array(qa);
+ ht = Z_ARRVAL_P(qa);
} else if (Z_TYPE_P(params) == IS_OBJECT || Z_TYPE_P(params) == IS_ARRAY) {
- ptr = HASH_OF(params);
+ ht = HASH_OF(params);
} else {
- zv_ptr = php_http_ztyp(IS_STRING, params);
+ zend_string *zs = zval_get_string(params);
+
array_init(&zv);
- php_http_querystring_parse(Z_ARRVAL(zv), Z_STRVAL_P(zv_ptr), Z_STRLEN_P(zv_ptr) TSRMLS_CC);
- zval_ptr_dtor(&zv_ptr);
- zv_ptr = NULL;
- ptr = Z_ARRVAL(zv);
+ php_http_querystring_parse(Z_ARRVAL(zv), zs->val, zs->len);
+ zend_string_release(zs);
+
+ ht = Z_ARRVAL(zv);
}
- FOREACH_HASH_KEYVAL(pos, ptr, key, params_entry) {
+ ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key.h, key.key, params_entry)
+ {
/* only public properties */
- if (key.type != HASH_KEY_IS_STRING || *key.str) {
- if (Z_TYPE_PP(params_entry) == IS_NULL) {
+ if (!key.key || *key.key->val) {
+ if (Z_TYPE_P(params_entry) == IS_NULL) {
/*
* delete
*/
- if (key.type == HASH_KEY_IS_STRING) {
- zend_hash_del(Z_ARRVAL_P(qarray), key.str, key.len);
+ if (key.key) {
+ zend_hash_del(Z_ARRVAL_P(qarray), key.key);
} else {
- zend_hash_index_del(Z_ARRVAL_P(qarray), key.num);
+ zend_hash_index_del(Z_ARRVAL_P(qarray), key.h);
}
- } else if ( ((key.type == HASH_KEY_IS_STRING) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), key.str, key.len, (void *) &qarray_entry)))
- || ((key.type == HASH_KEY_IS_LONG) && (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(qarray), key.num, (void *) &qarray_entry)))) {
+ } else if ( ((key.key) && (qarray_entry = zend_hash_find(Z_ARRVAL_P(qarray), key.key)))
+ || ((!key.key) && (qarray_entry = zend_hash_index_find(Z_ARRVAL_P(qarray), key.h)))) {
/*
* update
*/
- zval equal, *entry = NULL;
+ zval equal, tmp, *entry = &tmp;
+ ZVAL_UNDEF(&tmp);
/* recursive */
- if (Z_TYPE_PP(params_entry) == IS_ARRAY || Z_TYPE_PP(params_entry) == IS_OBJECT) {
- entry = php_http_zsep(1, IS_ARRAY, *qarray_entry);
- php_http_querystring_update(entry, *params_entry, NULL TSRMLS_CC);
- } else if ((FAILURE == is_equal_function(&equal, *qarray_entry, *params_entry TSRMLS_CC)) || !Z_BVAL(equal)) {
- Z_ADDREF_PP(params_entry);
- entry = *params_entry;
+ if (Z_TYPE_P(params_entry) == IS_ARRAY || Z_TYPE_P(params_entry) == IS_OBJECT) {
+ ZVAL_DUP(entry, qarray_entry);
+ convert_to_array(entry);
+ php_http_querystring_update(entry, params_entry, NULL);
+ } else if ((FAILURE == is_equal_function(&equal, qarray_entry, params_entry)) || Z_TYPE(equal) != IS_TRUE) {
+ Z_TRY_ADDREF_P(params_entry);
+ entry = params_entry;
}
if (entry) {
- if (key.type == HASH_KEY_IS_STRING) {
- zend_hash_update(Z_ARRVAL_P(qarray), key.str, key.len, (void *) &entry, sizeof(zval *), NULL);
+ if (key.key) {
+ zend_hash_update(Z_ARRVAL_P(qarray), key.key, entry);
} else {
- zend_hash_index_update(Z_ARRVAL_P(qarray), key.num, (void *) &entry, sizeof(zval *), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(qarray), key.h, entry);
}
}
} else {
- zval *entry;
+ zval entry, *entry_ptr = &entry;
/*
* add
*/
- if (Z_TYPE_PP(params_entry) == IS_OBJECT) {
- MAKE_STD_ZVAL(entry);
- array_init(entry);
- php_http_querystring_update(entry, *params_entry, NULL TSRMLS_CC);
+ if (Z_TYPE_P(params_entry) == IS_OBJECT) {
+ array_init(&entry);
+ php_http_querystring_update(&entry, params_entry, NULL);
} else {
- Z_ADDREF_PP(params_entry);
- entry = *params_entry;
+ Z_TRY_ADDREF_P(params_entry);
+ entry_ptr = params_entry;
}
- if (key.type == HASH_KEY_IS_STRING) {
- add_assoc_zval_ex(qarray, key.str, key.len, entry);
+ if (key.key) {
+ add_assoc_zval_ex(qarray, key.key->val, key.key->len, entry_ptr);
} else {
- add_index_zval(qarray, key.num, entry);
+ add_index_zval(qarray, key.h, entry_ptr);
}
}
}
}
- /* clean up */
- if (zv_ptr) {
- zval_ptr_dtor(&zv_ptr);
- }
+ ZEND_HASH_FOREACH_END();
+
zval_dtor(&zv);
}
char *s;
size_t l;
- if (SUCCESS == php_http_url_encode_hash(Z_ARRVAL_P(qarray), NULL, 0, &s, &l TSRMLS_CC)) {
+ if (SUCCESS == php_http_url_encode_hash(Z_ARRVAL_P(qarray), NULL, 0, &s, &l)) {
zval_dtor(outstring);
- ZVAL_STRINGL(outstring, s, l, 0);
+ ZVAL_STR(outstring, php_http_cs2zs(s, l));
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to encode query string");
+ php_error_docref(NULL, E_WARNING, "Failed to encode query string");
return FAILURE;
}
}
zval *params = NULL;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶ms), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z", ¶ms), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh TSRMLS_CC);
- php_http_querystring_set(getThis(), params, 0 TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh);
+ php_http_querystring_set(getThis(), params, 0);
+ zend_restore_error_handling(&zeh);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getGlobalInstance, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getGlobalInstance)
{
- zval *instance;
+ zval *instance, *_GET;
+ zend_string *zs;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- instance = *zend_std_get_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), 0 PHP_HTTP_ZEND_LITERAL_CCN TSRMLS_CC);
-
- if (Z_TYPE_P(instance) != IS_OBJECT) {
- zval **_GET = NULL;
-
- zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
+ zs = zend_string_init(ZEND_STRL("instance"), 0);
+ instance = zend_std_get_static_property(php_http_querystring_class_entry, zs, 0);
+ zend_string_release(zs);
- if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET))
- && (Z_TYPE_PP(_GET) == IS_ARRAY)
- ) {
- MAKE_STD_ZVAL(instance);
- ZVAL_OBJVAL(instance, php_http_querystring_object_new(php_http_querystring_class_entry TSRMLS_CC), 0);
+ if (Z_TYPE_P(instance) == IS_OBJECT) {
+ RETVAL_ZVAL(instance, 1, 0);
+ } else if ((_GET = php_http_env_get_superglobal(ZEND_STRL("_GET")))) {
+ ZVAL_OBJ(return_value, php_http_querystring_object_new(php_http_querystring_class_entry));
- SEPARATE_ZVAL_TO_MAKE_IS_REF(_GET);
- convert_to_array(*_GET);
- zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), *_GET TSRMLS_CC);
+ ZVAL_MAKE_REF(_GET);
+ zend_update_property(php_http_querystring_class_entry, return_value, ZEND_STRL("queryArray"), _GET);
- zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), instance TSRMLS_CC);
- zval_ptr_dtor(&instance);
- } else {
- php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
- }
+ zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), return_value);
+ } else {
+ php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
}
- RETVAL_ZVAL(instance, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getIterator, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getIterator)
{
- zval *retval = NULL, *qa;
+ zval qa_tmp, *qa;
php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
object_init_ex(return_value, spl_ce_RecursiveArrayIterator);
- zend_call_method_with_1_params(&return_value, spl_ce_RecursiveArrayIterator, NULL, "__construct", &retval, qa);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ zend_call_method_with_1_params(return_value, spl_ce_RecursiveArrayIterator, NULL, "__construct", NULL, qa);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_toString, 0, 0, 0)
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- php_http_querystring_str(getThis(), return_value TSRMLS_CC);
+ php_http_querystring_str(getThis(), return_value);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_toArray, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, toArray)
{
- zval *zqa;
+ zval zqa_tmp, *zqa;
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &zqa_tmp);
RETURN_ZVAL(zqa, 1, 0);
}
PHP_METHOD(HttpQueryString, get)
{
char *name_str = NULL;
- int name_len = 0;
- long type = 0;
+ size_t name_len = 0;
+ zend_long type = 0;
zend_bool del = 0;
zval *ztype = NULL, *defval = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szzb", &name_str, &name_len, &ztype, &defval, &del)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|szzb", &name_str, &name_len, &ztype, &defval, &del)) {
if (name_str && name_len) {
if (ztype) {
if (Z_TYPE_P(ztype) == IS_LONG) {
}
}
}
- php_http_querystring_get(getThis(), type, name_str, name_len, defval, del, return_value TSRMLS_CC);
+ php_http_querystring_get(getThis(), type, name_str, name_len, defval, del, return_value);
} else {
- php_http_querystring_str(getThis(), return_value TSRMLS_CC);
+ php_http_querystring_str(getThis(), return_value);
}
}
}
{
zval *params;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms)) {
return;
}
- php_http_querystring_set(getThis(), params, QS_MERGE TSRMLS_CC);
+ php_http_querystring_set(getThis(), params, QS_MERGE);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, mod)
{
- zval *params;
+ zval qa_tmp, *params, *instance = getThis();
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶ms), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh TSRMLS_CC);
- ZVAL_OBJVAL(return_value, Z_OBJ_HT_P(getThis())->clone_obj(getThis() TSRMLS_CC), 0);
- php_http_querystring_set(return_value, params, QS_MERGE TSRMLS_CC);
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_querystring_class_entry(), &zeh);
+ ZVAL_OBJ(return_value, Z_OBJ_HT_P(instance)->clone_obj(instance));
+ /* make sure we do not inherit the reference to _GET */
+ SEPARATE_ZVAL(zend_read_property(Z_OBJCE_P(return_value), return_value, ZEND_STRL("queryArray"), 0, &qa_tmp));
+ php_http_querystring_set(return_value, params, QS_MERGE);
+ zend_restore_error_handling(&zeh);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString___getter, 0, 0, 1)
PHP_METHOD(HttpQueryString, method) \
{ \
char *name; \
- int name_len; \
+ size_t name_len; \
zval *defval = NULL; \
zend_bool del = 0; \
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zb", &name, &name_len, &defval, &del)) { \
- php_http_querystring_get(getThis(), TYPE, name, name_len, defval, del, return_value TSRMLS_CC); \
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|zb", &name, &name_len, &defval, &del)) { \
+ php_http_querystring_get(getThis(), TYPE, name, name_len, defval, del, return_value); \
} \
}
-PHP_HTTP_QUERYSTRING_GETTER(getBool, IS_BOOL);
+PHP_HTTP_QUERYSTRING_GETTER(getBool, _IS_BOOL);
PHP_HTTP_QUERYSTRING_GETTER(getInt, IS_LONG);
PHP_HTTP_QUERYSTRING_GETTER(getFloat, IS_DOUBLE);
PHP_HTTP_QUERYSTRING_GETTER(getString, IS_STRING);
PHP_METHOD(HttpQueryString, xlate)
{
char *ie, *oe;
- int ie_len, oe_len;
- zval *na, *qa;
+ size_t ie_len, oe_len;
+ zval na, qa_tmp, *qa;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &ie, &ie_len, &oe, &oe_len), invalid_arg, return);
- MAKE_STD_ZVAL(na);
- array_init(na);
- qa = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC));
+ array_init(&na);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
+ ZVAL_DEREF(qa);
+ convert_to_array(qa);
- php_http_expect(SUCCESS == php_http_querystring_xlate(na, qa, ie, oe TSRMLS_CC), bad_conversion,
+ php_http_expect(SUCCESS == php_http_querystring_xlate(&na, qa, ie, oe), bad_conversion,
zval_ptr_dtor(&na);
- zval_ptr_dtor(&qa);
return;
);
- php_http_querystring_set(getThis(), na, 0 TSRMLS_CC);
+ php_http_querystring_set(getThis(), &na, 0);
RETVAL_ZVAL(getThis(), 1, 0);
zval_ptr_dtor(&na);
- zval_ptr_dtor(&qa);
}
#endif /* HAVE_ICONV */
if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- php_http_querystring_str(getThis(), return_value TSRMLS_CC);
+ php_http_querystring_str(getThis(), return_value);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_unserialize, 0, 0, 1)
{
zval *serialized;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "z", &serialized)) {
return;
}
if (Z_TYPE_P(serialized) == IS_STRING) {
- php_http_querystring_set(getThis(), serialized, 0 TSRMLS_CC);
+ php_http_querystring_set(getThis(), serialized, 0);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected a string as parameter");
+ php_error_docref(NULL, E_WARNING, "Expected a string as parameter");
}
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, offsetGet)
{
- char *offset_str;
- int offset_len;
- zval **value, *qa;
+ zend_string *offset;
+ zval *value, qa_tmp, *qa;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
+ ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)) {
- RETVAL_ZVAL(*value, 1, 0);
+ if ((value = zend_symtable_find(Z_ARRVAL_P(qa), offset))) {
+ RETVAL_ZVAL(value, 1, 0);
}
}
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, offsetSet)
{
- char *offset_str;
- int offset_len;
- zval *value, *param;
+ zend_string *offset;
+ zval *value, param, znull;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &offset, &value)) {
return;
}
- param = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
-
- if (Z_TYPE_P(param) == IS_ARRAY && zend_symtable_exists(Z_ARRVAL_P(param), offset_str, offset_len + 1)) {
- Z_ADDREF_P(value);
- zend_symtable_update(Z_ARRVAL_P(param), offset_str, offset_len + 1, (void *) &value, sizeof(zval *), NULL);
- Z_ADDREF_P(param);
- } else {
- MAKE_STD_ZVAL(param);
- array_init(param);
- Z_ADDREF_P(value);
- add_assoc_zval_ex(param, offset_str, offset_len + 1, value);
- }
- php_http_querystring_set(getThis(), param, QS_MERGE TSRMLS_CC);
+ array_init_size(¶m, 1);
+ /* unset first */
+ ZVAL_NULL(&znull);
+ zend_symtable_update(Z_ARRVAL(param), offset, &znull);
+ php_http_querystring_set(getThis(), ¶m, QS_MERGE);
+ /* then update, else QS_MERGE would merge sub-arrrays */
+ Z_TRY_ADDREF_P(value);
+ zend_symtable_update(Z_ARRVAL(param), offset, value);
+ php_http_querystring_set(getThis(), ¶m, QS_MERGE);
zval_ptr_dtor(¶m);
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, offsetExists)
{
- char *offset_str;
- int offset_len;
- zval **value, *qa;
+ zend_string *offset;
+ zval *value, qa_tmp, *qa;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}
- qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0, &qa_tmp);
+ ZVAL_DEREF(qa);
if (Z_TYPE_P(qa) == IS_ARRAY) {
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)) {
- RETURN_BOOL(Z_TYPE_PP(value) != IS_NULL);
+ if ((value = zend_symtable_find(Z_ARRVAL_P(qa), offset))) {
+ RETURN_BOOL(Z_TYPE_P(value) != IS_NULL);
}
}
RETURN_FALSE;
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, offsetUnset)
{
- char *offset_str;
- int offset_len;
- zval *param;
+ zend_string *offset;
+ zval param, znull;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "S", &offset)) {
return;
}
- MAKE_STD_ZVAL(param);
- array_init(param);
- add_assoc_null_ex(param, offset_str, offset_len + 1);
- php_http_querystring_set(getThis(), param, QS_MERGE TSRMLS_CC);
+ array_init(¶m);
+ ZVAL_NULL(&znull);
+ zend_symtable_update(Z_ARRVAL(param), offset, &znull);
+ php_http_querystring_set(getThis(), ¶m, QS_MERGE);
zval_ptr_dtor(¶m);
}
-zend_class_entry *php_http_querystring_class_entry;
-
static zend_function_entry php_http_querystring_methods[] = {
PHP_ME(HttpQueryString, __construct, ai_HttpQueryString___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL)
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "QueryString", php_http_querystring_methods);
- php_http_querystring_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_querystring_class_entry = zend_register_internal_class(&ce);
php_http_querystring_class_entry->create_object = php_http_querystring_object_new;
- zend_class_implements(php_http_querystring_class_entry TSRMLS_CC, 3, zend_ce_serializable, zend_ce_arrayaccess, zend_ce_aggregate);
+ zend_class_implements(php_http_querystring_class_entry, 3, zend_ce_serializable, zend_ce_arrayaccess, zend_ce_aggregate);
- zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("instance"), (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
- zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("queryArray"), ZEND_ACC_PRIVATE TSRMLS_CC);
+ zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("instance"), (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE));
+ zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("queryArray"), ZEND_ACC_PRIVATE);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_BOOL"), PHP_HTTP_QUERYSTRING_TYPE_BOOL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_INT"), PHP_HTTP_QUERYSTRING_TYPE_INT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_FLOAT"), PHP_HTTP_QUERYSTRING_TYPE_FLOAT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_STRING"), PHP_HTTP_QUERYSTRING_TYPE_STRING TSRMLS_CC);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_ARRAY"), PHP_HTTP_QUERYSTRING_TYPE_ARRAY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_OBJECT"), PHP_HTTP_QUERYSTRING_TYPE_OBJECT TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_BOOL"), PHP_HTTP_QUERYSTRING_TYPE_BOOL);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_INT"), PHP_HTTP_QUERYSTRING_TYPE_INT);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_FLOAT"), PHP_HTTP_QUERYSTRING_TYPE_FLOAT);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_STRING"), PHP_HTTP_QUERYSTRING_TYPE_STRING);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_ARRAY"), PHP_HTTP_QUERYSTRING_TYPE_ARRAY);
+ zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_OBJECT"), PHP_HTTP_QUERYSTRING_TYPE_OBJECT);
return SUCCESS;
}
#define PHP_HTTP_QUERYSTRING_H
#ifdef PHP_HTTP_HAVE_ICONV
-PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe TSRMLS_DC);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe);
#endif /* PHP_HTTP_HAVE_ICONV */
-PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_update(zval *qarray, zval *params, zval *qstring TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_ctor(zval *instance, zval *params TSRMLS_DC);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_update(zval *qarray, zval *params, zval *qstring);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_querystring_ctor(zval *instance, zval *params);
typedef php_http_object_t php_http_querystring_object_t;
-#define PHP_HTTP_QUERYSTRING_TYPE_BOOL IS_BOOL
+#define PHP_HTTP_QUERYSTRING_TYPE_BOOL _IS_BOOL
#define PHP_HTTP_QUERYSTRING_TYPE_INT IS_LONG
#define PHP_HTTP_QUERYSTRING_TYPE_FLOAT IS_DOUBLE
#define PHP_HTTP_QUERYSTRING_TYPE_STRING IS_STRING
#define PHP_HTTP_QUERYSTRING_TYPE_ARRAY IS_ARRAY
#define PHP_HTTP_QUERYSTRING_TYPE_OBJECT IS_OBJECT
-PHP_HTTP_API zend_class_entry *php_http_querystring_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_querystring_get_class_entry(void);
PHP_MINIT_FUNCTION(http_querystring);
#define url(buf) ((php_http_url_t *) (buf).data)
-static php_http_url_t *php_http_url_from_env(TSRMLS_D)
+static php_http_url_t *php_http_url_from_env(void)
{
zval *https, *zhost, *zport;
long port;
/* scheme */
url(buf)->scheme = &buf.data[buf.used];
- https = php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1 TSRMLS_CC);
+ https = php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1);
if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
php_http_buffer_append(&buf, "https", sizeof("https"));
} else {
/* host */
url(buf)->host = &buf.data[buf.used];
- if ((((zhost = php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1 TSRMLS_CC)) ||
- (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1 TSRMLS_CC)) ||
- (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1 TSRMLS_CC)))) && Z_STRLEN_P(zhost)) {
+ if ((((zhost = php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1)) ||
+ (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1)) ||
+ (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1)))) && Z_STRLEN_P(zhost)) {
size_t stop_at = strspn(Z_STRVAL_P(zhost), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.");
php_http_buffer_append(&buf, Z_STRVAL_P(zhost), stop_at);
}
/* port */
- zport = php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1 TSRMLS_CC);
+ zport = php_http_env_get_server_var(ZEND_STRL("SERVER_PORT"), 1);
if (zport && IS_LONG == is_numeric_string(Z_STRVAL_P(zport), Z_STRLEN_P(zport), &port, NULL, 0)) {
url(buf)->port = port;
}
} \
} while (0)
-php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_url_t *new_url, unsigned flags TSRMLS_DC)
+php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_url_t *new_url, unsigned flags)
{
php_http_url_t *tmp_url = NULL;
php_http_buffer_t buf;
/* set from env if requested */
if (flags & PHP_HTTP_URL_FROM_ENV) {
- php_http_url_t *env_url = php_http_url_from_env(TSRMLS_C);
+ php_http_url_t *env_url = php_http_url_from_env();
- old_url = tmp_url = php_http_url_mod(env_url, old_url, flags ^ PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
+ old_url = tmp_url = php_http_url_mod(env_url, old_url, flags ^ PHP_HTTP_URL_FROM_ENV);
php_http_url_free(&env_url);
}
if ((flags & PHP_HTTP_URL_JOIN_QUERY) && url_isset(new_url, query) && url_isset(old_url, query)) {
zval qarr, qstr;
- INIT_PZVAL(&qstr);
- INIT_PZVAL(&qarr);
array_init(&qarr);
- ZVAL_STRING(&qstr, old_url->query, 0);
- php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
- ZVAL_STRING(&qstr, new_url->query, 0);
- php_http_querystring_update(&qarr, &qstr, NULL TSRMLS_CC);
+ ZVAL_STRING(&qstr, old_url->query);
+ php_http_querystring_update(&qarr, &qstr, NULL);
+ zval_ptr_dtor(&qstr);
+ ZVAL_STRING(&qstr, new_url->query);
+ php_http_querystring_update(&qarr, &qstr, NULL);
+ zval_ptr_dtor(&qstr);
ZVAL_NULL(&qstr);
- php_http_querystring_update(&qarr, NULL, &qstr TSRMLS_CC);
+ php_http_querystring_update(&qarr, NULL, &qstr);
url(buf)->query = &buf.data[buf.used];
url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL(qstr), Z_STRLEN(qstr) + 1));
return buf.data;
}
-php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags TSRMLS_DC)
+php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags)
{
- zval *zcpy;
+ zend_string *zs;
php_http_url_t *purl;
switch (Z_TYPE_P(value)) {
break;
default:
- zcpy = php_http_ztyp(IS_STRING, value);
- purl = php_http_url_parse(Z_STRVAL_P(zcpy), Z_STRLEN_P(zcpy), flags TSRMLS_CC);
- zval_ptr_dtor(&zcpy);
+ zs = zval_get_string(value);
+ purl = php_http_url_parse(zs->val, zs->len, flags);
+ zend_string_release(zs);
}
return purl;
php_http_url_t *php_http_url_from_struct(HashTable *ht)
{
- zval **e;
+ zval *e;
php_http_buffer_t buf;
php_http_buffer_init_ex(&buf, MAX(PHP_HTTP_BUFFER_DEFAULT_SIZE, sizeof(php_http_url_t)<<2), PHP_HTTP_BUFFER_INIT_PREALLOC);
php_http_buffer_account(&buf, sizeof(php_http_url_t));
memset(buf.data, 0, buf.used);
- if (SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("scheme")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->scheme = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("user")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->user = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("pass")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->pass = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("host")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->host = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_LONG, *e);
- url(buf)->port = (unsigned short) Z_LVAL_P(cpy);
- zval_ptr_dtor(&cpy);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("port")))) {
+ url(buf)->port = (unsigned short) zval_get_long(e);
}
- if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("path")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->path = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("query")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->query = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
- if (SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e)) {
- zval *cpy = php_http_ztyp(IS_STRING, *e);
+ if ((e = zend_hash_str_find_ind(ht, ZEND_STRL("fragment")))) {
+ zend_string *zs = zval_get_string(e);
url(buf)->fragment = &buf.data[buf.used];
- url_append(&buf, php_http_buffer_append(&buf, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy) + 1));
- zval_ptr_dtor(&cpy);
+ url_append(&buf, php_http_buffer_append(&buf, zs->val, zs->len + 1));
+ zend_string_release(zs);
}
return url(buf);
}
-HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct TSRMLS_DC)
+HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct)
{
- zval arr;
+ HashTable *ht;
+ zval tmp;
if (strct) {
switch (Z_TYPE_P(strct)) {
/* no break */
case IS_ARRAY:
case IS_OBJECT:
- INIT_PZVAL_ARRAY((&arr), HASH_OF(strct));
+ ht = HASH_OF(strct);
break;
}
} else {
- INIT_PZVAL(&arr);
- array_init(&arr);
+ ALLOC_HASHTABLE(ht);
+ zend_hash_init(ht, 8, NULL, ZVAL_PTR_DTOR, 0);
+ }
+
+#define url_struct_add(part) \
+ if (Z_TYPE_P(strct) == IS_ARRAY) { \
+ zend_hash_str_update(Z_ARRVAL_P(strct), part, lenof(part), &tmp); \
+ } else { \
+ zend_update_property(Z_OBJCE_P(strct), strct, part, lenof(part), &tmp); \
+ zval_ptr_dtor(&tmp); \
}
if (url) {
if (url->scheme) {
- add_assoc_string(&arr, "scheme", url->scheme, 1);
+ ZVAL_STRING(&tmp, url->scheme);
+ url_struct_add("scheme");
}
if (url->user) {
- add_assoc_string(&arr, "user", url->user, 1);
+ ZVAL_STRING(&tmp, url->user);
+ url_struct_add("user");
}
if (url->pass) {
- add_assoc_string(&arr, "pass", url->pass, 1);
+ ZVAL_STRING(&tmp, url->pass);
+ url_struct_add("pass");
}
if (url->host) {
- add_assoc_string(&arr, "host", url->host, 1);
+ ZVAL_STRING(&tmp, url->host);
+ url_struct_add("host");
}
if (url->port) {
- add_assoc_long(&arr, "port", (long) url->port);
+ ZVAL_LONG(&tmp, url->port);
+ url_struct_add("port");
}
if (url->path) {
- add_assoc_string(&arr, "path", url->path, 1);
+ ZVAL_STRING(&tmp, url->path);
+ url_struct_add("path");
}
if (url->query) {
- add_assoc_string(&arr, "query", url->query, 1);
+ ZVAL_STRING(&tmp, url->query);
+ url_struct_add("query");
}
if (url->fragment) {
- add_assoc_string(&arr, "fragment", url->fragment, 1);
+ ZVAL_STRING(&tmp, url->fragment);
+ url_struct_add("fragment");
}
}
- return Z_ARRVAL(arr);
+ return ht;
}
-ZEND_RESULT_CODE php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC)
+ZEND_RESULT_CODE php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len)
{
const char *arg_sep_str = "&";
size_t arg_sep_len = 1;
php_http_buffer_t *qstr = php_http_buffer_new();
- php_http_url_argsep(&arg_sep_str, &arg_sep_len TSRMLS_CC);
+ php_http_url_argsep(&arg_sep_str, &arg_sep_len);
- if (SUCCESS != php_http_url_encode_hash_ex(hash, qstr, arg_sep_str, arg_sep_len, "=", 1, pre_encoded_str, pre_encoded_len TSRMLS_CC)) {
+ if (SUCCESS != php_http_url_encode_hash_ex(hash, qstr, arg_sep_str, arg_sep_len, "=", 1, pre_encoded_str, pre_encoded_len)) {
php_http_buffer_free(&qstr);
return FAILURE;
}
return SUCCESS;
}
-ZEND_RESULT_CODE php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len TSRMLS_DC)
+ZEND_RESULT_CODE php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len)
{
if (pre_encoded_len && pre_encoded_str) {
php_http_buffer_append(qstr, pre_encoded_str, pre_encoded_len);
}
- if (!php_http_params_to_string(qstr, hash, arg_sep_str, arg_sep_len, "", 0, val_sep_str, val_sep_len, PHP_HTTP_PARAMS_QUERY TSRMLS_CC)) {
+ if (!php_http_params_to_string(qstr, hash, arg_sep_str, arg_sep_len, "", 0, val_sep_str, val_sep_len, PHP_HTTP_PARAMS_QUERY)) {
return FAILURE;
}
struct parse_state {
php_http_url_t url;
-#ifdef ZTS
- void ***ts;
-#endif
const char *ptr;
const char *end;
size_t maxlen;
}
if (!silent) {
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (consumed) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse %s; unexpected multibyte sequence 0x%x at pos %u in '%s'",
parse_what[what], wchar, (unsigned) (ptr - begin), begin);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse %s; unexpected byte 0x%02x at pos %u in '%s'",
parse_what[what], (unsigned char) *ptr, (unsigned) (ptr - begin), begin);
}
{
size_t mb;
const char *password = NULL, *end = state->ptr, *tmp = ptr;
- TSRMLS_FETCH_FROM_CTX(state->ts);
state->url.user = &state->buffer[state->offset];
switch (*ptr) {
case ':':
if (password) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse password; duplicate ':' at pos %u in '%s'",
(unsigned) (ptr - tmp), tmp);
return FAILURE;
case '%':
if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse userinfo; invalid percent encoding at pos %u in '%s'",
(unsigned) (ptr - tmp), tmp);
return FAILURE;
#if defined(PHP_WIN32) || defined(HAVE_UIDNA_IDNTOASCII)
typedef size_t (*parse_mb_func)(unsigned *wc, const char *ptr, const char *end);
-static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u16, size_t *len TSRMLS_DC)
+static ZEND_RESULT_CODE to_utf16(parse_mb_func fn, const char *u8, uint16_t **u16, size_t *len)
{
size_t offset = 0, u8_len = strlen(u8);
if (!consumed) {
efree(*u16);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse UTF-8 at pos %zu of '%s'", offset, u8);
+ php_error_docref(NULL, E_WARNING, "Failed to parse UTF-8 at pos %zu of '%s'", offset, u8);
return FAILURE;
} else {
offset += consumed;
case 0:
default:
efree(*u16);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert UTF-32 'U+%X' to UTF-16", wc);
+ php_error_docref(NULL, E_WARNING, "Failed to convert UTF-32 'U+%X' to UTF-16", wc);
return FAILURE;
}
}
{
char *idn = NULL;
int rv = -1;
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
rv = idn2_lookup_u8((const unsigned char *) state->url.host, (unsigned char **) &idn, IDN2_NFC_INPUT);
}
# endif
if (rv != IDN2_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idn2_strerror(rv));
return FAILURE;
} else {
size_t idnlen = strlen(idn);
{
char *idn = NULL;
int rv = -1;
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
rv = idna_to_ascii_8z(state->url.host, &idn, IDNA_ALLOW_UNASSIGNED|IDNA_USE_STD3_ASCII_RULES);
}
# endif
if (rv != IDNA_SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; %s", idna_strerror(rv));
return FAILURE;
} else {
size_t idnlen = strlen(idn);
uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
size_t uhost_len, ahost_len;
UErrorCode error = U_ZERO_ERROR;
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
- if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
+ if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len)) {
return FAILURE;
}
#ifdef PHP_HTTP_HAVE_WCHAR
} else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
- if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len TSRMLS_CC)) {
+ if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len)) {
return FAILURE;
}
#endif
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; codepage not specified");
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; codepage not specified");
return FAILURE;
}
efree(uhost_str);
if (error != U_ZERO_ERROR) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN; ICU error %d", error);
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN; ICU error %d", error);
return FAILURE;
}
char *host_ptr;
uint16_t *uhost_str, ahost_str[MAXHOSTNAMELEN], *ahost_ptr;
size_t uhost_len;
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (state->flags & PHP_HTTP_URL_PARSE_MBUTF8) {
if (SUCCESS != to_utf16(parse_mb_utf8, state->url.host, &uhost_str, &uhost_len)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN");
return FAILURE;
}
#ifdef PHP_HTTP_HAVE_WCHAR
} else if (state->flags & PHP_HTTP_URL_PARSE_MBLOC) {
if (SUCCESS != to_utf16(parse_mb_loc, state->url.host, &uhost_str, &uhost_len)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN");
return FAILURE;
}
#endif
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN");
return FAILURE;
}
if (!IdnToAscii(IDN_ALLOW_UNASSIGNED|IDN_USE_STD3_ASCII_RULES, uhost_str, uhost_len, ahost_str, MAXHOSTNAMELEN)) {
efree(uhost_str);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse IDN");
+ php_error_docref(NULL, E_WARNING, "Failed to parse IDN");
return FAILURE;
}
static const char *parse_ip6(struct parse_state *state, const char *ptr)
{
const char *error = NULL, *end = state->ptr, *tmp = memchr(ptr, ']', end - ptr);
- TSRMLS_FETCH_FROM_CTX(state->ts);
if (tmp) {
size_t addrlen = tmp - ptr + 1;
}
if (error) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse hostinfo; %s", error);
+ php_error_docref(NULL, E_WARNING, "Failed to parse hostinfo; %s", error);
return NULL;
}
{
size_t mb, len;
const char *end = state->ptr, *tmp = ptr, *port = NULL, *label = NULL;
- TSRMLS_FETCH_FROM_CTX(state->ts);
#ifdef HAVE_INET_PTON
if (*ptr == '[' && !(ptr = parse_ip6(state, ptr))) {
switch (*ptr) {
case ':':
if (port) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse port; unexpected ':' at pos %u in '%s'",
(unsigned) (ptr - tmp), tmp);
return FAILURE;
case '%':
if (ptr[1] != '%' && (end - ptr <= 2 || !isxdigit(*(ptr+1)) || !isxdigit(*(ptr+2)))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse hostinfo; invalid percent encoding at pos %u in '%s'",
(unsigned) (ptr - tmp), tmp);
return FAILURE;
/* sort of a compromise, just ensure we don't end up
* with a dot at the beginning or two consecutive dots
*/
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse %s; unexpected '%c' at pos %u in '%s'",
port ? "port" : "host",
(unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
case 'v': case 'w': case 'x': case 'y': case 'z':
if (port) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse port; unexpected char '%c' at pos %u in '%s'",
(unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
return FAILURE;
if (ptr == end) {
break;
} else if (port) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse port; unexpected byte 0x%02x at pos %u in '%s'",
(unsigned char) *ptr, (unsigned) (ptr - tmp), tmp);
return FAILURE;
case '@':
/* userinfo delimiter */
if (host) {
- TSRMLS_FETCH_FROM_CTX(state->ts);
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse userinfo; unexpected '@'");
return NULL;
}
{
size_t mb;
const char *tmp;
- TSRMLS_FETCH_FROM_CTX(state->ts);
/* is there actually a path to parse? */
if (!*state->ptr) {
case '%':
if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse path; invalid percent encoding at pos %u in '%s'",
(unsigned) (state->ptr - tmp), tmp);
return NULL;
{
size_t mb;
const char *tmp = state->ptr + !!*state->ptr;
- TSRMLS_FETCH_FROM_CTX(state->ts);
/* is there actually a query to parse? */
if (*state->ptr != '?') {
case '%':
if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse query; invalid percent encoding at pos %u in '%s'",
(unsigned) (state->ptr - tmp), tmp);
return NULL;
{
size_t mb;
const char *tmp;
- TSRMLS_FETCH_FROM_CTX(state->ts);
/* is there actually a fragment to parse? */
if (*state->ptr != '#') {
switch (*state->ptr) {
case '%':
if (state->ptr[1] != '%' && (state->end - state->ptr <= 2 || !isxdigit(*(state->ptr+1)) || !isxdigit(*(state->ptr+2)))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse fragment; invalid percent encoding at pos %u in '%s'",
(unsigned) (state->ptr - tmp), tmp);
return NULL;
return state->ptr = tmp;
}
-php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC)
+php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags)
{
size_t maxlen = 3 * len;
struct parse_state *state = ecalloc(1, sizeof(*state) + maxlen);
state->ptr = str;
state->flags = flags;
state->maxlen = maxlen;
- TSRMLS_SET_CTX(state->ts);
if (!parse_scheme(state)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr);
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr);
efree(state);
return NULL;
}
}
if (!parse_query(state)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL query: '%s'", state->ptr);
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL query: '%s'", state->ptr);
efree(state);
return NULL;
}
if (!parse_fragment(state)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr);
+ php_error_docref(NULL, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr);
efree(state);
return NULL;
}
return (php_http_url_t *) state;
}
-php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsigned flags TSRMLS_DC)
+php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsigned flags)
{
size_t maxlen = 3 * len;
struct parse_state *state = ecalloc(1, sizeof(*state) + maxlen);
state->ptr = str;
state->flags = flags;
state->maxlen = maxlen;
- TSRMLS_SET_CTX(state->ts);
if (!(state->ptr = parse_authority(state))) {
efree(state);
}
if (state->ptr != state->end) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ php_error_docref(NULL, E_WARNING,
"Failed to parse URL authority, unexpected character at pos %u in '%s'",
(unsigned) (state->ptr - str), str);
efree(state);
return (php_http_url_t *) state;
}
+static zend_class_entry *php_http_url_class_entry;
+static zend_class_entry *php_http_env_url_class_entry;
+
+zend_class_entry *php_http_url_get_class_entry(void)
+{
+ return php_http_url_class_entry;
+}
+
+zend_class_entry *php_http_get_env_url_class_entry(void)
+{
+ return php_http_env_url_class_entry;
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0)
ZEND_ARG_INFO(0, old_url)
ZEND_ARG_INFO(0, new_url)
PHP_METHOD(HttpUrl, __construct)
{
zval *new_url = NULL, *old_url = NULL;
- long flags = PHP_HTTP_URL_FROM_ENV;
+ zend_long flags = 0;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
+ /* always set http\Url::FROM_ENV for instances of http\Env\Url */
+ if (instanceof_function(Z_OBJCE_P(getThis()), php_http_env_url_class_entry)) {
+ flags |= PHP_HTTP_URL_FROM_ENV;
+ }
+
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
{
php_http_url_t *res_purl, *new_purl = NULL, *old_purl = NULL;
if (new_url) {
- new_purl = php_http_url_from_zval(new_url, flags TSRMLS_CC);
+ new_purl = php_http_url_from_zval(new_url, flags);
if (!new_purl) {
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
return;
}
}
if (old_url) {
- old_purl = php_http_url_from_zval(old_url, flags TSRMLS_CC);
+ old_purl = php_http_url_from_zval(old_url, flags);
if (!old_purl) {
if (new_purl) {
php_http_url_free(&new_purl);
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
return;
}
}
- res_purl = php_http_url_mod(old_purl, new_purl, flags TSRMLS_CC);
- php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
+ res_purl = php_http_url_mod(old_purl, new_purl, flags);
+ php_http_url_to_struct(res_purl, getThis());
php_http_url_free(&res_purl);
if (old_purl) {
php_http_url_free(&new_purl);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
PHP_METHOD(HttpUrl, mod)
{
zval *new_url = NULL;
- long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY | PHP_HTTP_URL_SANITIZE_PATH;
+ zend_long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY | PHP_HTTP_URL_SANITIZE_PATH;
zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url, &flags), invalid_arg, return);
- zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);
{
php_http_url_t *new_purl = NULL, *old_purl = NULL;
if (new_url) {
- new_purl = php_http_url_from_zval(new_url, flags TSRMLS_CC);
+ new_purl = php_http_url_from_zval(new_url, flags);
if (!new_purl) {
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
return;
}
}
if ((old_purl = php_http_url_from_struct(HASH_OF(getThis())))) {
php_http_url_t *res_purl;
- ZVAL_OBJVAL(return_value, zend_objects_clone_obj(getThis() TSRMLS_CC), 0);
+ ZVAL_OBJ(return_value, zend_objects_clone_obj(getThis()));
- res_purl = php_http_url_mod(old_purl, new_purl, flags TSRMLS_CC);
- php_http_url_to_struct(res_purl, return_value TSRMLS_CC);
+ res_purl = php_http_url_mod(old_purl, new_purl, flags);
+ php_http_url_to_struct(res_purl, return_value);
php_http_url_free(&res_purl);
php_http_url_free(&old_purl);
php_http_url_free(&new_purl);
}
}
- zend_restore_error_handling(&zeh TSRMLS_CC);
+ zend_restore_error_handling(&zeh);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
php_http_url_to_string(purl, &str, &len, 0);
php_http_url_free(&purl);
- RETURN_STRINGL(str, len, 0);
+ RETURN_STR(php_http_cs2zs(str, len));
}
}
RETURN_EMPTY_STRING();
/* strip any non-URL properties */
purl = php_http_url_from_struct(HASH_OF(getThis()));
- php_http_url_to_struct(purl, return_value TSRMLS_CC);
+ php_http_url_to_struct(purl, return_value);
php_http_url_free(&purl);
}
EMPTY_FUNCTION_ENTRY
};
-zend_class_entry *php_http_url_class_entry;
-
PHP_MINIT_FUNCTION(http_url)
{
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
- php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
-
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC);
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC);
+ php_http_url_class_entry = zend_register_internal_class(&ce);
+
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("pass"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("host"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("port"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("path"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC);
+ zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("fragment"), ZEND_ACC_PUBLIC);
+
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("REPLACE"), PHP_HTTP_URL_REPLACE);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_PATH"), PHP_HTTP_URL_JOIN_PATH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("JOIN_QUERY"), PHP_HTTP_URL_JOIN_QUERY);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_USER"), PHP_HTTP_URL_STRIP_USER);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PASS"), PHP_HTTP_URL_STRIP_PASS);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_AUTH"), PHP_HTTP_URL_STRIP_AUTH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PORT"), PHP_HTTP_URL_STRIP_PORT);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_PATH"), PHP_HTTP_URL_STRIP_PATH);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_QUERY"), PHP_HTTP_URL_STRIP_QUERY);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH);
#ifdef PHP_HTTP_HAVE_WCHAR
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBLOC"), PHP_HTTP_URL_PARSE_MBLOC);
#endif
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8 TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_MBUTF8"), PHP_HTTP_URL_PARSE_MBUTF8);
#if defined(PHP_HTTP_HAVE_IDN2) || defined(PHP_HTTP_HAVE_IDN) || defined(HAVE_UIDNA_IDNTOASCII)
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOIDN"), PHP_HTTP_URL_PARSE_TOIDN);
#endif
- zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("PARSE_TOPCT"), PHP_HTTP_URL_PARSE_TOPCT);
+
+ INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Url", php_http_url_methods);
+ php_http_env_url_class_entry = zend_register_internal_class_ex(&ce, php_http_url_class_entry);
return SUCCESS;
}
char *fragment;
} php_http_url_t;
-PHP_HTTP_API php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags TSRMLS_DC);
-PHP_HTTP_API php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsigned flags TSRMLS_DC);
-PHP_HTTP_API php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_url_t *new_url, unsigned flags TSRMLS_DC);
+PHP_HTTP_API php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags);
+PHP_HTTP_API php_http_url_t *php_http_url_parse_authority(const char *str, size_t len, unsigned flags);
+PHP_HTTP_API php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_url_t *new_url, unsigned flags);
PHP_HTTP_API php_http_url_t *php_http_url_copy(const php_http_url_t *url, zend_bool persistent);
PHP_HTTP_API php_http_url_t *php_http_url_from_struct(HashTable *ht);
-PHP_HTTP_API php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags TSRMLS_DC);
-PHP_HTTP_API HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct TSRMLS_DC);
+PHP_HTTP_API php_http_url_t *php_http_url_from_zval(zval *value, unsigned flags);
+PHP_HTTP_API HashTable *php_http_url_to_struct(const php_http_url_t *url, zval *strct);
PHP_HTTP_API char *php_http_url_to_string(const php_http_url_t *url, char **url_str, size_t *url_len, zend_bool persistent);
PHP_HTTP_API char *php_http_url_authority_to_string(const php_http_url_t *url, char **url_str, size_t *url_len);
PHP_HTTP_API void php_http_url_free(php_http_url_t **url);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC);
-PHP_HTTP_API ZEND_RESULT_CODE php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len TSRMLS_DC);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len);
+PHP_HTTP_API ZEND_RESULT_CODE php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len);
-static inline void php_http_url_argsep(const char **str, size_t *len TSRMLS_DC)
+static inline void php_http_url_argsep(const char **str, size_t *len)
{
- php_http_ini_entry(ZEND_STRL("arg_separator.output"), str, len, 0 TSRMLS_CC);
+ if (SUCCESS != php_http_ini_entry(ZEND_STRL("arg_separator.output"), str, len, 0) || !*len) {
+ *str = PHP_HTTP_URL_ARGSEP;
+ *len = lenof(PHP_HTTP_URL_ARGSEP);
+ }
}
static inline zend_bool php_http_url_is_empty(const php_http_url_t *url) {
return !(url->scheme || url->pass || url->user || url->host || url->port || url->path || url->query || url->fragment);
}
-PHP_HTTP_API zend_class_entry *php_http_url_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_url_get_class_entry(void);
+PHP_HTTP_API zend_class_entry *php_http_get_env_url_class_entry(void);
PHP_MINIT_FUNCTION(http_url);
#define php_http_url_object_new php_http_object_new
#include "php_http_api.h"
-php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC)
+php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor)
{
if (!v) {
v = emalloc(sizeof(*v));
return v;
}
-php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC)
+php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str)
{
long major, minor;
char separator = 0;
separator = *ptr++;
if (separator) {
if (separator != '.' && separator != ',') {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2);
+ php_error_docref(NULL, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2);
}
minor = *ptr - '0';
if (minor >= 0 && minor <= 9) {
- return php_http_version_init(v, major, minor TSRMLS_CC);
+ return php_http_version_init(v, major, minor);
}
}
}
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP protocol version '%s'", str);
+ php_error_docref(NULL, E_WARNING, "Could not parse HTTP protocol version '%s'", str);
return NULL;
}
-void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC)
+void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post)
{
*len = spprintf(str, 0, "%s%u.%u%s", pre ? pre : "", v->major, v->minor, post ? post : "");
}
unsigned minor;
} php_http_version_t;
-PHP_HTTP_API php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC);
-PHP_HTTP_API php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC);
-PHP_HTTP_API void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC);
+PHP_HTTP_API php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor);
+PHP_HTTP_API php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str);
+PHP_HTTP_API void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post);
PHP_HTTP_API void php_http_version_dtor(php_http_version_t *v);
PHP_HTTP_API void php_http_version_free(php_http_version_t **v);
Content-Length: %d
Etag: "%s"
X-Original-Transfer-Encoding: chunked
+X-Request-Content-Length: 3
GET / HTTP/1.1
Accept: */*
--TEST--
client seek
--SKIPIF--
-<?php
+<?php
include "skipif.inc";
?>
--FILE--
-<?php
+<?php
include "helper/dump.inc";
include "helper/server.inc";
Content-Length: %d
Etag: "%x"
X-Original-Transfer-Encoding: chunked
+X-Request-Content-Length: 2
PUT / HTTP/1.1
Accept: */*
<?php
include "helper/server.inc";
+include "helper/dump.inc";
echo "Test\n";
$request->setOptions(array("timeout" => 10, "expect_100_timeout" => 0));
$client->enqueue($request);
$client->send();
- var_dump($client->getResponse()->getHeaders());
+ dump_headers(null, $client->getResponse()->getHeaders());
});
?>
===DONE===
--EXPECTF--
Test
-array(5) {
- ["Accept-Ranges"]=>
- string(5) "bytes"
- ["Etag"]=>
- string(%d) "%s"
- ["Last-Modified"]=>
- string(%d) "%s"
- ["X-Original-Transfer-Encoding"]=>
- string(7) "chunked"
- ["Content-Length"]=>
- int(134217%d%d%d)
-}
+Accept-Ranges: bytes
+Content-Length: %d
+Etag: "%x"
+Last-Modified: %s
+X-Original-Transfer-Encoding: chunked
+X-Request-Content-Length: 134217728
+
===DONE===
--TEST--
etags with hash
--SKIPIF--
-<?php
-include "skipif.inc";
-_ext("hash");
-version_compare(PHP_VERSION, "5.4.0", ">=") or die("skip PHP>=5.4 required");
+<?php
+include "skipif.inc";
+_ext("hash");
?>
--FILE--
<?php
$body = new http\Message\Body;
$body->append("Hello, my old fellow.");
foreach (hash_algos() as $algo) {
- switch ($algo) {
- case "gost-crypto":
- case "fnv1a32":
- case "fnv1a64":
- continue 2;
+ if (strncmp($algo, "sha3-", 5)) {
+ ini_set("http.etag.mode", $algo);
+ printf("%10s: %s\n",
+ $algo,
+ $body->etag()
+ );
}
- ini_set("http.etag.mode", $algo);
- printf("%10s: %s\n",
- $algo,
- $body->etag()
- );
}
?>
DONE
snefru: 8f50c66c8f0a1510f9c591a2b7a070853d4770c60a38394c8857918dd91a2e5b
snefru256: 8f50c66c8f0a1510f9c591a2b7a070853d4770c60a38394c8857918dd91a2e5b
gost: efc79cdd01331adf80b30af816ff7a934f3f3df3085294a310918cacff3500f0
+gost-crypto: 2e6bd37841520cc9ccb8c7abd68bd3ec9ce601651b995f3639090f585cc23684
adler32: 4ff5075d
crc32: 757b06f7
crc32b: e56655c5
fnv132: ebd1fa1f
+ fnv1a32: 8e2ee037
fnv164: 9790ce01eba3ae9f
+ fnv1a64: 43ef200fe3ef9b37
joaat: 70a407c9
haval128,3: 68a1bee33d2a4fa5543be7fa871f84ea
haval160,3: b4204e8c4f3c993385d997539afa723888700bbd
--- /dev/null
+--TEST--
+crash when query string has nested array keys
+--SKIPIF--
+<?php
+include "skipif.inc";
+php_version_compare(PHP_VERSION, "7.0.0-dev") or die("skip php<7");
+?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+$q = new http\QueryString("a[0][0]=x&a[1][0]=x");
+printf("%s\n", $q);
+
+?>
+===DONE===
+--EXPECT--
+Test
+a%5B0%5D%5B0%5D=x&a%5B1%5D%5B0%5D=x
+===DONE===
--TEST--
crash with querystring and exception from error handler
--SKIPIF--
-<?php include "skipif.inc"; ?>
+<?php
+include "skipif.inc";
+if (version_compare(PHP_VERSION, "7", ">=")) {
+ die("skip PHP>=7\n");
+}
+?>
--GET--
q[]=1&r[]=2
--FILE--
<?php
-function dump_message($stream, http\Message $msg, $parent = false) {
+function dump_headers($stream, array $headers) {
if (!is_resource($stream)) {
$stream = fopen("php://output", "w");
}
- fprintf($stream, "%s\n", $msg->getInfo());
- $headers = $msg->getHeaders();
ksort($headers);
foreach ($headers as $key => $val) {
fprintf($stream, "%s: %s\n", $key, $val);
}
fprintf($stream, "\n");
+}
+
+function dump_message($stream, http\Message $msg, $parent = false) {
+ if (!is_resource($stream)) {
+ $stream = fopen("php://output", "w");
+ }
+ fprintf($stream, "%s\n", $msg->getInfo());
+ dump_headers($stream, $msg->getHeaders());
$msg->getBody()->toStream($stream);
if ($parent && ($msg = $msg->getParentMessage())) {
-<?php
+<?php
include "dump.inc";
include "server.inc";
serve(function($client) {
/* this might be a proxy connect or a standard request */
$request = new http\Message($client, false);
-
+
if ($request->getHeader("Proxy-Connection")) {
$response = new http\Env\Response;
$response->setEnvRequest($request);
$response->send($client);
-
+
/* soak up the request following the connect */
new http\Message($client, false);
}
-
+
/* return the initial message as response body */
$response = new http\Env\Response;
+ $response->setHeader("X-Request-Content-Length", $request->getBody()->stat("size"));
/* avoid OOM with $response->getBody()->append($request); */
dump_message($response->getBody()->getResource(), $request);
$response->send($client);
define("PHP_BIN", PHP_BINDIR.DIRECTORY_SEPARATOR."php");
}
+foreach (array("raphf", "propro", "http") as $ext) {
+ if (!extension_loaded($ext)) {
+ switch (PHP_SHLIB_SUFFIX) {
+ case "dll":
+ dl("php_$ext.dll");
+ break;
+ default:
+ dl($ext .".". PHP_SHLIB_SUFFIX);
+ }
+ }
+}
+
function serve($cb) {
/* stream_socket_server() automatically sets SO_REUSEADDR,
* which is, well, bad if the tests are run in parallel
?>
DONE
--EXPECTF--
-exception 'http\Exception\BadMessageException' with message 'http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 3 of 'GET HTTP/1.1'' in %s
+http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 3 of 'GET HTTP/1.1' in %s
Stack trace:
#0 %s: http\Message->__construct('GET HTTP/1.1')
#1 {main}
-exception 'http\Exception\BadMessageException' with message 'http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 3 of 'GET HTTP/1.123'' in %s
+http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 3 of 'GET HTTP/1.123' in %s
Stack trace:
#0 %s: http\Message->__construct('GET HTTP/1.123')
#1 {main}
-exception 'http\Exception\BadMessageException' with message 'http\Message::__construct(): Failed to parse headers: unexpected character '\057' at pos 7 of 'GETHTTP/1.1'' %s
+http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\057' at pos 7 of 'GETHTTP/1.1' %s
Stack trace:
#0 %s: http\Message->__construct('GETHTTP/1.1')
#1 {main}
===DONE===
--EXPECTF--
Test
-exception 'http\Exception\BadMessageException' with message 'http\Message::__construct(): Failed to parse headers: unexpected character '\057' at pos 4 of 'HTTP/1.1 99 Apples in my Basket'' in %sinfo002.php:%d
+http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\057' at pos 4 of 'HTTP/1.1 99 Apples in my Basket' in %sinfo002.php:%d
Stack trace:
#0 %sinfo002.php(%d): http\Message->__construct('HTTP/1.1 99 App...')
#1 %sinfo002.php(%d): {closure}()
#2 %sinfo002.php(%d): trap(Object(Closure))
#3 {main}
-exception 'http\Exception\BadMessageException' with message 'http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 7 of 'CONNECT HTTP/1.1'' in %sinfo002.php:%d
+http\Exception\BadMessageException: http\Message::__construct(): Failed to parse headers: unexpected character '\040' at pos 7 of 'CONNECT HTTP/1.1' in %sinfo002.php:%d
Stack trace:
#0 %sinfo002.php(%d): http\Message->__construct('CONNECT HTTP/1....')
#1 %sinfo002.php(%d): {closure}()
DONE
--EXPECTF--
Test
-exception 'http\Exception\RuntimeException' with message 'http\Message\Body::append(): Failed to append 4 bytes to body; wrote 0' in %s:%d
+http\Exception\RuntimeException: http\Message\Body::append(): Failed to append 4 bytes to body; wrote 0 in %s:%d
Stack trace:
#0 %s(%d): http\Message\Body->append('nope')
#1 {main}
["type":protected]=>
int(1)
["body":protected]=>
- object(http\Message\Body)#2 (0) {
+ object(http\Message\Body)#%d (0) {
}
["requestMethod":protected]=>
string(3) "GET"
}
string(3) "OK
"
-DONE
\ No newline at end of file
+DONE
a.b: Array
(
[a.b] => 0.9
- [c.e] => 0.1
[a.x] => 0.1
+ [c.e] => 0.1
)
DONE
Test
%a
HTTP Support => enabled
-Extension Version => 2.%s
+Extension Version => 3.%s
%a
Done
<?php
include "skipif.inc";
?>
---XFAIL--
-TBD
--FILE--
<?php
["by1ref"]=>
int(2)
["by2ref"]=>
- &int(1)
+ int(1)
}
array(4) {
["bykey"]=>
["by1ref"]=>
int(2)
["by2ref"]=>
- &int(1)
+ int(1)
["byXref"]=>
- &int(2)
+ int(2)
}
array(5) {
["bykey"]=>
["by1ref"]=>
int(2)
["by2ref"]=>
- &int(1)
+ int(1)
["byXref"]=>
- &int(2)
+ int(2)
["bynext"]=>
array(3) {
[0]=>
--EXPECT--
Test
foo=bar&bar=baz
-foo=baz&bar=baz
+bar=baz&foo=baz
===DONE===
s=b&i=0&e=&a[]=1&a[]=2
--FILE--
<?php
-printf("%s\n", new http\Url);
-printf("%s\n", new http\Url("other", "index"));
-printf("%s\n", new http\Url(array("scheme" => "https", "port" => 443)));
-printf("%s\n", new http\Url(array("path" => "/./up/../down/../././//index.php/.", "query" => null), null, http\Url::SANITIZE_PATH|http\Url::FROM_ENV));
-printf("%s\n", new http\Url(null, null, 0));
+printf("%s\n", new http\Env\Url);
+printf("%s\n", new http\Env\Url("other", "index"));
+printf("%s\n", new http\Env\Url(array("scheme" => "https", "port" => 443)));
+printf("%s\n", new http\Env\Url(array("path" => "/./up/../down/../././//index.php/.", "query" => null), null, http\Url::SANITIZE_PATH|http\Url::FROM_ENV));
+printf("%s\n", new http\Env\Url(null, null, 0));
+printf("%s\n", new http\Url(null, null, http\Url::FROM_ENV));
?>
DONE
--EXPECTF--
http://example.com:55555/index?s=b&i=0&e=&a[]=1&a[]=2
https://example.com/?s=b&i=0&e=&a[]=1&a[]=2
http://example.com:55555/index.php/
-
+http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2
+http://example.com:55555/?s=b&i=0&e=&a[]=1&a[]=2
DONE
--- /dev/null
+#!/usr/bin/env php
+<?php
+
+/**
+ * The installer sub-stub for extension phars
+ */
+
+namespace pharext;
+
+define("PHAREXT_PHAR", __FILE__);
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+
+
+namespace pharext;
+
+class Exception extends \Exception
+{
+ public function __construct($message = null, $code = 0, $previous = null) {
+ if (!isset($message)) {
+ $last_error = error_get_last();
+ $message = $last_error["message"];
+ if (!$code) {
+ $code = $last_error["type"];
+ }
+ }
+ parent::__construct($message, $code, $previous);
+ }
+}
+
+
+
+namespace pharext;
+
+use pharext\Exception;
+
+/**
+ * A temporary file/directory name
+ */
+class Tempname
+{
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ */
+ public function __construct($prefix, $suffix = null) {
+ $temp = sys_get_temp_dir() . "/pharext-" . $this->getUser();
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception;
+ }
+ $this->name = $temp ."/". uniqid($prefix) . $suffix;
+ }
+
+ private function getUser() {
+ if (extension_loaded("posix") && function_exists("posix_getpwuid")) {
+ return posix_getpwuid(posix_getuid())["name"];
+ }
+ return trim(`whoami 2>/dev/null`)
+ ?: trim(`id -nu 2>/dev/null`)
+ ?: getenv("USER")
+ ?: get_current_user();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString() {
+ return (string) $this->name;
+ }
+}
+
+
+
+namespace pharext;
+
+/**
+ * Create a new temporary file
+ */
+class Tempfile extends \SplFileInfo
+{
+ /**
+ * @var resource
+ */
+ private $handle;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix, $suffix = ".tmp") {
+ $tries = 0;
+ $omask = umask(077);
+ do {
+ $path = new Tempname($prefix, $suffix);
+ $this->handle = fopen($path, "x");
+ } while (!is_resource($this->handle) && $tries++ < 10);
+ umask($omask);
+
+ if (!is_resource($this->handle)) {
+ throw new Exception("Could not create temporary file");
+ }
+
+ parent::__construct($path);
+ }
+
+ /**
+ * Unlink the file
+ */
+ public function __destruct() {
+ if (is_file($this->getPathname())) {
+ @unlink($this->getPathname());
+ }
+ }
+
+ /**
+ * Close the stream
+ */
+ public function closeStream() {
+ fclose($this->handle);
+ }
+
+ /**
+ * Retrieve the stream resource
+ * @return resource
+ */
+ public function getStream() {
+ return $this->handle;
+ }
+}
+
+
+
+namespace pharext;
+
+/**
+ * Create a temporary directory
+ */
+class Tempdir extends \SplFileInfo
+{
+ /**
+ * @param string $prefix prefix to uniqid()
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix) {
+ $temp = new Tempname($prefix);
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
+ }
+ parent::__construct($temp);
+ }
+}
+
+
+
+namespace pharext;
+
+use ArrayAccess;
+use IteratorAggregate;
+use RecursiveDirectoryIterator;
+use SplFileInfo;
+
+use pharext\Exception;
+
+class Archive implements ArrayAccess, IteratorAggregate
+{
+ const HALT_COMPILER = "\137\137\150\141\154\164\137\143\157\155\160\151\154\145\162\50\51\73";
+ const SIGNED = 0x10000;
+ const SIG_MD5 = 0x0001;
+ const SIG_SHA1 = 0x0002;
+ const SIG_SHA256 = 0x0003;
+ const SIG_SHA512 = 0x0004;
+ const SIG_OPENSSL= 0x0010;
+
+ private static $siglen = [
+ self::SIG_MD5 => 16,
+ self::SIG_SHA1 => 20,
+ self::SIG_SHA256 => 32,
+ self::SIG_SHA512 => 64,
+ self::SIG_OPENSSL=> 0
+ ];
+
+ private static $sigalg = [
+ self::SIG_MD5 => "md5",
+ self::SIG_SHA1 => "sha1",
+ self::SIG_SHA256 => "sha256",
+ self::SIG_SHA512 => "sha512",
+ self::SIG_OPENSSL=> "openssl"
+ ];
+
+ private static $sigtyp = [
+ self::SIG_MD5 => "MD5",
+ self::SIG_SHA1 => "SHA-1",
+ self::SIG_SHA256 => "SHA-256",
+ self::SIG_SHA512 => "SHA-512",
+ self::SIG_OPENSSL=> "OpenSSL",
+ ];
+
+ const PERM_FILE_MASK = 0x01ff;
+ const COMP_FILE_MASK = 0xf000;
+ const COMP_GZ_FILE = 0x1000;
+ const COMP_BZ2_FILE = 0x2000;
+
+ const COMP_PHAR_MASK= 0xf000;
+ const COMP_PHAR_GZ = 0x1000;
+ const COMP_PHAR_BZ2 = 0x2000;
+
+ private $file;
+ private $fd;
+ private $stub;
+ private $manifest;
+ private $signature;
+ private $extracted;
+
+ function __construct($file = null) {
+ if (strlen($file)) {
+ $this->open($file);
+ }
+ }
+
+ function open($file) {
+ if (!$this->fd = @fopen($file, "r")) {
+ throw new Exception;
+ }
+ $this->file = $file;
+ $this->stub = $this->readStub();
+ $this->manifest = $this->readManifest();
+ $this->signature = $this->readSignature();
+ }
+
+ function getIterator() {
+ return new RecursiveDirectoryIterator($this->extract());
+ }
+
+ function extract() {
+ return $this->extracted ?: $this->extractTo(new Tempdir("archive"));
+ }
+
+ function extractTo($dir) {
+ if ((string) $this->extracted == (string) $dir) {
+ return $this->extracted;
+ }
+ foreach ($this->manifest["entries"] as $file => $entry) {
+ fseek($this->fd, $this->manifest["offset"]+$entry["offset"]);
+ $path = "$dir/$file";
+ $copy = stream_copy_to_stream($this->fd, $this->outFd($path, $entry["flags"]), $entry["csize"]);
+ if ($entry["osize"] != $copy) {
+ throw new Exception("Copied '$copy' of '$file', expected '{$entry["osize"]}' from '{$entry["csize"]}");
+ }
+
+ $crc = hexdec(hash_file("crc32b", $path));
+ if ($crc !== $entry["crc32"]) {
+ throw new Exception("CRC mismatch of '$file': '$crc' != '{$entry["crc32"]}");
+ }
+
+ chmod($path, $entry["flags"] & self::PERM_FILE_MASK);
+ touch($path, $entry["stamp"]);
+ }
+ return $this->extracted = $dir;
+ }
+
+ function offsetExists($o) {
+ return isset($this->entries[$o]);
+ }
+
+ function offsetGet($o) {
+ $this->extract();
+ return new SplFileInfo($this->extracted."/$o");
+ }
+
+ function offsetSet($o, $v) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function offsetUnset($o) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function getSignature() {
+ /* compatible with Phar::getSignature() */
+ return [
+ "hash_type" => self::$sigtyp[$this->signature["flags"]],
+ "hash" => strtoupper(bin2hex($this->signature["hash"])),
+ ];
+ }
+
+ function getPath() {
+ /* compatible with Phar::getPath() */
+ return new SplFileInfo($this->file);
+ }
+
+ function getMetadata($key = null) {
+ if (isset($key)) {
+ return $this->manifest["meta"][$key];
+ }
+ return $this->manifest["meta"];
+ }
+
+ private function outFd($path, $flags) {
+ $dirn = dirname($path);
+ if (!is_dir($dirn) && !@mkdir($dirn, 0777, true)) {
+ throw new Exception;
+ }
+ if (!$fd = @fopen($path, "w")) {
+ throw new Exception;
+ }
+ switch ($flags & self::COMP_FILE_MASK) {
+ case self::COMP_GZ_FILE:
+ if (!@stream_filter_append($fd, "zlib.inflate")) {
+ throw new Exception;
+ }
+ break;
+ case self::COMP_BZ2_FILE:
+ if (!@stream_filter_append($fd, "bz2.decompress")) {
+ throw new Exception;
+ }
+ break;
+ }
+
+ }
+ private function readVerified($fd, $len) {
+ if ($len != strlen($data = fread($fd, $len))) {
+ throw new Exception("Unexpected EOF");
+ }
+ return $data;
+ }
+
+ private function readFormat($format, $fd, $len) {
+ if (false === ($data = @unpack($format, $this->readVerified($fd, $len)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+
+ private function readSingleFormat($format, $fd, $len) {
+ return current($this->readFormat($format, $fd, $len));
+ }
+
+ private function readStringBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ return $this->readVerified($this->fd, $length);
+ }
+ return null;
+ }
+
+ private function readSerializedBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ if (false === ($data = unserialize($this->readVerified($fd, $length)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+ return null;
+ }
+
+ private function readStub() {
+ $stub = "";
+ while (!feof($this->fd)) {
+ $line = fgets($this->fd);
+ $stub .= $line;
+ if (false !== stripos($line, self::HALT_COMPILER)) {
+ /* check for '?>' on a separate line */
+ if ('?>' === $this->readVerified($this->fd, 2)) {
+ $stub .= '?>' . fgets($this->fd);
+ } else {
+ fseek($this->fd, -2, SEEK_CUR);
+ }
+ break;
+ }
+ }
+ return $stub;
+ }
+
+ private function readManifest() {
+ $current = ftell($this->fd);
+ $header = $this->readFormat("Vlen/Vnum/napi/Vflags", $this->fd, 14);
+ $alias = $this->readStringBinary($this->fd);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries = [];
+ for ($i = 0; $i < $header["num"]; ++$i) {
+ $this->readEntry($entries);
+ }
+ $offset = ftell($this->fd);
+ if (($length = $offset - $current - 4) != $header["len"]) {
+ throw new Exception("Manifest length read was '$length', expected '{$header["len"]}'");
+ }
+ return $header + compact("alias", "meta", "entries", "offset");
+ }
+
+ private function readEntry(array &$entries) {
+ if (!count($entries)) {
+ $offset = 0;
+ } else {
+ $last = end($entries);
+ $offset = $last["offset"] + $last["csize"];
+ }
+ $file = $this->readStringBinary($this->fd);
+ if (!strlen($file)) {
+ throw new Exception("Empty file name encountered at offset '$offset'");
+ }
+ $header = $this->readFormat("Vosize/Vstamp/Vcsize/Vcrc32/Vflags", $this->fd, 20);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries[$file] = $header + compact("meta", "offset");
+ }
+
+ private function readSignature() {
+ fseek($this->fd, -8, SEEK_END);
+ $sig = $this->readFormat("Vflags/Z4magic", $this->fd, 8);
+ $end = ftell($this->fd);
+
+ if ($sig["magic"] !== "GBMB") {
+ throw new Exception("Invalid signature magic value '{$sig["magic"]}");
+ }
+
+ switch ($sig["flags"]) {
+ case self::SIG_OPENSSL:
+ fseek($this->fd, -12, SEEK_END);
+ if (($hash = $this->readSingleFormat("V", $this->fd, 4))) {
+ $offset = 4 + $hash;
+ fseek($this->fd, -$offset, SEEK_CUR);
+ $hash = $this->readVerified($this->fd, $hash);
+ fseek($this->fd, 0, SEEK_SET);
+ $valid = openssl_verify($this->readVerified($this->fd, $end - $offset - 8),
+ $hash, @file_get_contents($this->file.".pubkey")) === 1;
+ }
+ break;
+
+ case self::SIG_MD5:
+ case self::SIG_SHA1:
+ case self::SIG_SHA256:
+ case self::SIG_SHA512:
+ $offset = 8 + self::$siglen[$sig["flags"]];
+ fseek($this->fd, -$offset, SEEK_END);
+ $hash = $this->readVerified($this->fd, self::$siglen[$sig["flags"]]);
+ $algo = hash_init(self::$sigalg[$sig["flags"]]);
+ fseek($this->fd, 0, SEEK_SET);
+ hash_update_stream($algo, $this->fd, $end - $offset);
+ $valid = hash_final($algo, true) === $hash;
+ break;
+
+ default:
+ throw new Exception("Invalid signature type '{$sig["flags"]}");
+ }
+
+ return $sig + compact("hash", "valid");
+ }
+}
+
+
+namespace pharext;
+
+if (extension_loaded("Phar")) {
+ \Phar::interceptFileFuncs();
+ \Phar::mapPhar();
+ $phardir = "phar://".__FILE__;
+} else {
+ $archive = new Archive(__FILE__);
+ $phardir = $archive->extract();
+}
+
+set_include_path("$phardir:". get_include_path());
+
+$installer = new Installer();
+$installer->run($argc, $argv);
+
+__HALT_COMPILER(); ?>\r
+\92\12\0\0D\0\0\0\11\0\0\0\ 1\0\0\0\0\0*\ 6\0\0a:7:{s:7:"version";s:5:"4.1.1";s:6:"header";s:49:"pharext v4.1.1 (c) Michael Wallner <mike@php.net>";s:4:"date";s:10:"2015-12-03";s:4:"name";s:6:"propro";s:7:"release";s:6:"master";s:7:"license";s:1345:"Copyright (c) 2013, Michael Wallner <mike@php.net>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+";s:4:"type";s:9:"extension";}\13\0\0\0pharext/Archive.php\18\1e\0\0a9`V\18\1e\0\04-ÔI¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Cli/Args/Help.phpÉ\f\0\0a9`VÉ\f\0\0gX'\1f¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Cli/Args.php\ f\1d\0\0a9`V\ f\1d\0\0?n\9dö¶\ 1\0\0\0\0\0\0\17\0\0\0pharext/Cli/Command.phpk \0\0a9`Vk \0\0d\84aê¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/Command.php\12\ 4\0\0a9`V\12\ 4\0\0Ôm`Ͷ\ 1\0\0\0\0\0\0\15\0\0\0pharext/Exception.phpc\ 1\0\0a9`Vc\ 1\0\0U\86Ï{¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/ExecCmd.php\1c\ e\0\0a9`V\1c\ e\0\0¹l\94ʶ\ 1\0\0\0\0\0\0\15\0\0\0pharext/Installer.php&\18\0\0a9`V&\18\0\0ød&À¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/License.php\93\ 4\0\0a9`V\93\ 4\0\0î\ 4òE¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Metadata.php\95\ 1\0\0a9`V\95\ 1\0\0¿Ú\90\9e¶\ 1\0\0\0\0\0\0\1e\0\0\0pharext/Openssl/PrivateKey.phpÁ\ 4\0\0a9`VÁ\ 4\0\0&æP\1a¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Packager.phpÌ!\0\0a9`VÌ!\0\00\ 2\ 3<¶\ 1\0\0\0\0\0\0\e\0\0\0pharext/SourceDir/Basic.phpz\ 5\0\0a9`Vz\ 5\0\0÷+Ôâ¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/SourceDir/Git.phpZ\ 6\0\0a9`VZ\ 6\0\0É\bÎ\¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/SourceDir/Pecl.phpø\11\0\0a9`Vø\11\0\0ã\bùж\ 1\0\0\0\0\0\0\15\0\0\0pharext/SourceDir.php½\ 2\0\0a9`V½\ 2\0\03·#\ f¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/Activate.phpÜ\v\0\0a9`VÜ\v\0\0I\93\1c\18¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Askpass.phpU\ 2\0\0a9`VU\ 2\0\0\87*\1e\90¶\ 1\0\0\0\0\0\0 \0\0\0pharext/Task/BundleGenerator.php}\ 2\0\0a9`V}\ 2\0\0 ï`Y¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Cleanup.php\1e\ 4\0\0a9`V\1e\ 4\0\0ÉI\80B¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/Configure.phpT\ 4\0\0a9`VT\ 4\0\0}\17Ëì¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Extract.phpp\ 3\0\0a9`Vp\ 3\0\0[¨Û̶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/GitClone.phpm\ 3\0\0a9`Vm\ 3\0\0óyµ@¶\ 1\0\0\0\0\0\0\15\0\0\0pharext/Task/Make.phpª\ 4\0\0a9`Vª\ 4\0\0\9cç6\r¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PaxFixup.php¬\ 3\0\0a9`V¬\ 3\0\0yâ¯\e¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/PeclFixup.php\9c\ 4\0\0a9`V\9c\ 4\0\0eùt\9a¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/PharBuild.phpâ\a\0\0a9`Vâ\a\0\0ζ0ɶ\ 1\0\0\0\0\0\0\1d\0\0\0pharext/Task/PharCompress.phpc\ 4\0\0a9`Vc\ 4\0\0½\10³Ï¶\ 1\0\0\0\0\0\0\e\0\0\0pharext/Task/PharRename.phpä\ 3\0\0a9`Vä\ 3\0\0\8a[Þ˶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PharSign.php¨\ 3\0\0a9`V¨\ 3\0\0Ûº¦i¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PharStub.phpæ\ 3\0\0a9`Væ\ 3\0\0Y|\9b¶\ 1\0\0\0\0\0\0\17\0\0\0pharext/Task/Phpize.php\ f\ 4\0\0a9`V\ f\ 4\0\0ù\f2Ѷ\ 1\0\0\0\0\0\0\1c\0\0\0pharext/Task/StreamFetch.php\10\a\0\0a9`V\10\a\0\0\88îs\¶\ 1\0\0\0\0\0\0\10\0\0\0pharext/Task.phpw\0\0\0a9`Vw\0\0\0 ÄIǶ\ 1\0\0\0\0\0\0\13\0\0\0pharext/Tempdir.phpµ\ 1\0\0a9`Vµ\ 1\0\0ë\7f\96,¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Tempfile.php\ f\ 4\0\0a9`V\ f\ 4\0\0\0®ô\1e¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Tempname.phpt\ 3\0\0a9`Vt\ 3\0\0\9en<\8d¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/Updater.php\8d\10\0\0a9`V\8d\10\0\0\9eÏv\16¶\ 1\0\0\0\0\0\0\15\0\0\0pharext_installer.phpÝ\ 2\0\0a9`VÝ\ 2\0\0\19\8cÞq¶\ 1\0\0\0\0\0\0\14\0\0\0pharext_packager.phpb\ 3\0\0a9`Vb\ 3\0\0îVÓ϶\ 1\0\0\0\0\0\0\13\0\0\0pharext_updater.phph\ 3\0\0a9`Vh\ 3\0\0 Êúj¶\ 1\0\0\0\0\0\0\r\0\0\0.editorconfigL\ 1\0\0a9`VL\ 1\0\0Þ\18\8d1¶\ 1\0\0\0\0\0\0\ e\0\0\0.gitattributesG\0\0\0a9`VG\0\0\0$\8bÂ\9b¶\ 1\0\0\0\0\0\0
+\0\0\0.gitignoreï\0\0\0a9`Vï\0\0\0B\12¦ÿ¶\ 1\0\0\0\0\0\0\v\0\0\0.gitmodulesn\0\0\0a9`Vn\0\0\0¥ÉN\82¶\ 1\0\0\0\0\0\0\v\0\0\0.travis.yml÷\ 1\0\0a9`V÷\ 1\0\0\8e[dá¶\ 1\0\0\0\0\0\0\a\0\0\0AUTHORS\1f\0\0\0a9`V\1f\0\0\0\ÄH¶\ 1\0\0\0\0\0\0\ 4\0\0\0BUGS*\0\0\0a9`V*\0\0\0\a<î\ f¶\ 1\0\0\0\0\0\0\ f\0\0\0CONTRIBUTING.md\8e\a\0\0a9`V\8e\a\0\0¶N\81q¶\ 1\0\0\0\0\0\0\a\0\0\0CREDITS\17\0\0\0a9`V\17\0\0\0 \87\12+¶\ 1\0\0\0\0\0\0\b\0\0\0DoxyfileO,\0\0a9`VO,\0\0U,\ 6,¶\ 1\0\0\0\0\0\0\a\0\0\0LICENSEA\ 5\0\0a9`VA\ 5\0\0¾¬Jþ¶\ 1\0\0\0\0\0\0\r\0\0\0Makefile.fragÌ\ 1\0\0a9`VÌ\ 1\0\0È\1dÿV¶\ 1\0\0\0\0\0\0 \0\0\0README.md%\ 5\0\0a9`V%\ 5\0\0I{ö\ 4¶\ 1\0\0\0\0\0\0\ 6\0\0\0THANKSd\0\0\0a9`Vd\0\0\0ÌD"å¶\ 1\0\0\0\0\0\0\ 4\0\0\0TODO\0\0\0\0a9`V\0\0\0\0\0\0\0\0¶\ 1\0\0\0\0\0\0 \0\0\0config.m4\15\0\0\0a9`V\15\0\0\0oêd\94¶\ 1\0\0\0\0\0\0
+\0\0\0config.w32\ 1\ 2\0\0a9`V\ 1\ 2\0\05è¡{¶\ 1\0\0\0\0\0\0
+\0\0\0config0.m4ë\ 2\0\0a9`Vë\ 2\0\0ã7\8a°¶\ 1\0\0\0\0\0\0\v\0\0\0package.xml\ 5 \0\0a9`V\ 5 \0\0\90\9eøF¶\ 1\0\0\0\0\0\0\f\0\0\0php_propro.hO\ 5\0\0a9`VO\ 5\0\0±é\1eK¶\ 1\0\0\0\0\0\0\1a\0\0\0scripts/gen_travis_yml.phpå\ 1\0\0a9`Vå\ 1\0\0=VÊ\98¶\ 1\0\0\0\0\0\0\14\0\0\0src/php_propro_api.c08\0\0a9`V08\0\0\99ÿ^\ 1¶\ 1\0\0\0\0\0\0\14\0\0\0src/php_propro_api.hö\ e\0\0a9`Vö\ e\0\0\û}£¶\ 1\0\0\0\0\0\0\ e\0\0\0tests/001.phpt9\ 3\0\0a9`V9\ 3\0\02Õ½A¶\ 1\0\0\0\0\0\0\ e\0\0\0tests/002.phpt8\ 5\0\0a9`V8\ 5\0\0L\18Â\ f¶\ 1\0\0\0\0\0\0\ e\0\0\0tests/003.phptï\ 1\0\0a9`Vï\ 1\0\0U8Ìå¶\ 1\0\0\0\0\0\0\v\0\0\0travis/pecl\0\0\0\0a9`V\0\0\0\0\0\0\0\0¶\ 1\0\0\0\0\0\0<?php
+
+namespace pharext;
+
+use ArrayAccess;
+use IteratorAggregate;
+use RecursiveDirectoryIterator;
+use SplFileInfo;
+
+use pharext\Exception;
+
+class Archive implements ArrayAccess, IteratorAggregate
+{
+ const HALT_COMPILER = "\137\137\150\141\154\164\137\143\157\155\160\151\154\145\162\50\51\73";
+ const SIGNED = 0x10000;
+ const SIG_MD5 = 0x0001;
+ const SIG_SHA1 = 0x0002;
+ const SIG_SHA256 = 0x0003;
+ const SIG_SHA512 = 0x0004;
+ const SIG_OPENSSL= 0x0010;
+
+ private static $siglen = [
+ self::SIG_MD5 => 16,
+ self::SIG_SHA1 => 20,
+ self::SIG_SHA256 => 32,
+ self::SIG_SHA512 => 64,
+ self::SIG_OPENSSL=> 0
+ ];
+
+ private static $sigalg = [
+ self::SIG_MD5 => "md5",
+ self::SIG_SHA1 => "sha1",
+ self::SIG_SHA256 => "sha256",
+ self::SIG_SHA512 => "sha512",
+ self::SIG_OPENSSL=> "openssl"
+ ];
+
+ private static $sigtyp = [
+ self::SIG_MD5 => "MD5",
+ self::SIG_SHA1 => "SHA-1",
+ self::SIG_SHA256 => "SHA-256",
+ self::SIG_SHA512 => "SHA-512",
+ self::SIG_OPENSSL=> "OpenSSL",
+ ];
+
+ const PERM_FILE_MASK = 0x01ff;
+ const COMP_FILE_MASK = 0xf000;
+ const COMP_GZ_FILE = 0x1000;
+ const COMP_BZ2_FILE = 0x2000;
+
+ const COMP_PHAR_MASK= 0xf000;
+ const COMP_PHAR_GZ = 0x1000;
+ const COMP_PHAR_BZ2 = 0x2000;
+
+ private $file;
+ private $fd;
+ private $stub;
+ private $manifest;
+ private $signature;
+ private $extracted;
+
+ function __construct($file = null) {
+ if (strlen($file)) {
+ $this->open($file);
+ }
+ }
+
+ function open($file) {
+ if (!$this->fd = @fopen($file, "r")) {
+ throw new Exception;
+ }
+ $this->file = $file;
+ $this->stub = $this->readStub();
+ $this->manifest = $this->readManifest();
+ $this->signature = $this->readSignature();
+ }
+
+ function getIterator() {
+ return new RecursiveDirectoryIterator($this->extract());
+ }
+
+ function extract() {
+ return $this->extracted ?: $this->extractTo(new Tempdir("archive"));
+ }
+
+ function extractTo($dir) {
+ if ((string) $this->extracted == (string) $dir) {
+ return $this->extracted;
+ }
+ foreach ($this->manifest["entries"] as $file => $entry) {
+ fseek($this->fd, $this->manifest["offset"]+$entry["offset"]);
+ $path = "$dir/$file";
+ $copy = stream_copy_to_stream($this->fd, $this->outFd($path, $entry["flags"]), $entry["csize"]);
+ if ($entry["osize"] != $copy) {
+ throw new Exception("Copied '$copy' of '$file', expected '{$entry["osize"]}' from '{$entry["csize"]}");
+ }
+
+ $crc = hexdec(hash_file("crc32b", $path));
+ if ($crc !== $entry["crc32"]) {
+ throw new Exception("CRC mismatch of '$file': '$crc' != '{$entry["crc32"]}");
+ }
+
+ chmod($path, $entry["flags"] & self::PERM_FILE_MASK);
+ touch($path, $entry["stamp"]);
+ }
+ return $this->extracted = $dir;
+ }
+
+ function offsetExists($o) {
+ return isset($this->entries[$o]);
+ }
+
+ function offsetGet($o) {
+ $this->extract();
+ return new SplFileInfo($this->extracted."/$o");
+ }
+
+ function offsetSet($o, $v) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function offsetUnset($o) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function getSignature() {
+ /* compatible with Phar::getSignature() */
+ return [
+ "hash_type" => self::$sigtyp[$this->signature["flags"]],
+ "hash" => strtoupper(bin2hex($this->signature["hash"])),
+ ];
+ }
+
+ function getPath() {
+ /* compatible with Phar::getPath() */
+ return new SplFileInfo($this->file);
+ }
+
+ function getMetadata($key = null) {
+ if (isset($key)) {
+ return $this->manifest["meta"][$key];
+ }
+ return $this->manifest["meta"];
+ }
+
+ private function outFd($path, $flags) {
+ $dirn = dirname($path);
+ if (!is_dir($dirn) && !@mkdir($dirn, 0777, true)) {
+ throw new Exception;
+ }
+ if (!$fd = @fopen($path, "w")) {
+ throw new Exception;
+ }
+ switch ($flags & self::COMP_FILE_MASK) {
+ case self::COMP_GZ_FILE:
+ if (!@stream_filter_append($fd, "zlib.inflate")) {
+ throw new Exception;
+ }
+ break;
+ case self::COMP_BZ2_FILE:
+ if (!@stream_filter_append($fd, "bz2.decompress")) {
+ throw new Exception;
+ }
+ break;
+ }
+
+ }
+ private function readVerified($fd, $len) {
+ if ($len != strlen($data = fread($fd, $len))) {
+ throw new Exception("Unexpected EOF");
+ }
+ return $data;
+ }
+
+ private function readFormat($format, $fd, $len) {
+ if (false === ($data = @unpack($format, $this->readVerified($fd, $len)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+
+ private function readSingleFormat($format, $fd, $len) {
+ return current($this->readFormat($format, $fd, $len));
+ }
+
+ private function readStringBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ return $this->readVerified($this->fd, $length);
+ }
+ return null;
+ }
+
+ private function readSerializedBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ if (false === ($data = unserialize($this->readVerified($fd, $length)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+ return null;
+ }
+
+ private function readStub() {
+ $stub = "";
+ while (!feof($this->fd)) {
+ $line = fgets($this->fd);
+ $stub .= $line;
+ if (false !== stripos($line, self::HALT_COMPILER)) {
+ /* check for '?>' on a separate line */
+ if ('?>' === $this->readVerified($this->fd, 2)) {
+ $stub .= '?>' . fgets($this->fd);
+ } else {
+ fseek($this->fd, -2, SEEK_CUR);
+ }
+ break;
+ }
+ }
+ return $stub;
+ }
+
+ private function readManifest() {
+ $current = ftell($this->fd);
+ $header = $this->readFormat("Vlen/Vnum/napi/Vflags", $this->fd, 14);
+ $alias = $this->readStringBinary($this->fd);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries = [];
+ for ($i = 0; $i < $header["num"]; ++$i) {
+ $this->readEntry($entries);
+ }
+ $offset = ftell($this->fd);
+ if (($length = $offset - $current - 4) != $header["len"]) {
+ throw new Exception("Manifest length read was '$length', expected '{$header["len"]}'");
+ }
+ return $header + compact("alias", "meta", "entries", "offset");
+ }
+
+ private function readEntry(array &$entries) {
+ if (!count($entries)) {
+ $offset = 0;
+ } else {
+ $last = end($entries);
+ $offset = $last["offset"] + $last["csize"];
+ }
+ $file = $this->readStringBinary($this->fd);
+ if (!strlen($file)) {
+ throw new Exception("Empty file name encountered at offset '$offset'");
+ }
+ $header = $this->readFormat("Vosize/Vstamp/Vcsize/Vcrc32/Vflags", $this->fd, 20);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries[$file] = $header + compact("meta", "offset");
+ }
+
+ private function readSignature() {
+ fseek($this->fd, -8, SEEK_END);
+ $sig = $this->readFormat("Vflags/Z4magic", $this->fd, 8);
+ $end = ftell($this->fd);
+
+ if ($sig["magic"] !== "GBMB") {
+ throw new Exception("Invalid signature magic value '{$sig["magic"]}");
+ }
+
+ switch ($sig["flags"]) {
+ case self::SIG_OPENSSL:
+ fseek($this->fd, -12, SEEK_END);
+ if (($hash = $this->readSingleFormat("V", $this->fd, 4))) {
+ $offset = 4 + $hash;
+ fseek($this->fd, -$offset, SEEK_CUR);
+ $hash = $this->readVerified($this->fd, $hash);
+ fseek($this->fd, 0, SEEK_SET);
+ $valid = openssl_verify($this->readVerified($this->fd, $end - $offset - 8),
+ $hash, @file_get_contents($this->file.".pubkey")) === 1;
+ }
+ break;
+
+ case self::SIG_MD5:
+ case self::SIG_SHA1:
+ case self::SIG_SHA256:
+ case self::SIG_SHA512:
+ $offset = 8 + self::$siglen[$sig["flags"]];
+ fseek($this->fd, -$offset, SEEK_END);
+ $hash = $this->readVerified($this->fd, self::$siglen[$sig["flags"]]);
+ $algo = hash_init(self::$sigalg[$sig["flags"]]);
+ fseek($this->fd, 0, SEEK_SET);
+ hash_update_stream($algo, $this->fd, $end - $offset);
+ $valid = hash_final($algo, true) === $hash;
+ break;
+
+ default:
+ throw new Exception("Invalid signature type '{$sig["flags"]}");
+ }
+
+ return $sig + compact("hash", "valid");
+ }
+}
+<?php
+
+namespace pharext\Cli\Args;
+
+use pharext\Cli\Args;
+
+class Help
+{
+ private $args;
+
+ function __construct($prog, Args $args) {
+ $this->prog = $prog;
+ $this->args = $args;
+ }
+
+ function __toString() {
+ $usage = "Usage:\n\n \$ ";
+ $usage .= $this->prog;
+
+ list($flags, $required, $optional, $positional) = $this->listSpec();
+ if ($flags) {
+ $usage .= $this->dumpFlags($flags);
+ }
+ if ($required) {
+ $usage .= $this->dumpRequired($required);
+ }
+ if ($optional) {
+ $usage .= $this->dumpOptional($optional);
+ }
+ if ($positional) {
+ $usage .= $this->dumpPositional($positional);
+ }
+
+ $help = $this->dumpHelp($positional);
+
+ return $usage . "\n\n" . $help . "\n";
+ }
+
+ function listSpec() {
+ $flags = [];
+ $required = [];
+ $optional = [];
+ $positional = [];
+ foreach ($this->args->getSpec() as $spec) {
+ if (is_numeric($spec[0])) {
+ $positional[] = $spec;
+ } elseif ($spec[3] & Args::REQUIRED) {
+ $required[] = $spec;
+ } elseif ($spec[3] & (Args::OPTARG|Args::REQARG)) {
+ $optional[] = $spec;
+ } else {
+ $flags[] = $spec;
+ }
+ }
+
+ return [$flags, $required, $optional, $positional]
+ + compact("flags", "required", "optional", "positional");
+ }
+
+ function dumpFlags(array $flags) {
+ return sprintf(" [-%s]", implode("", array_column($flags, 0)));
+ }
+
+ function dumpRequired(array $required) {
+ $dump = "";
+ foreach ($required as $req) {
+ $dump .= sprintf(" -%s <%s>", $req[0], $req[1]);
+ }
+ return $dump;
+ }
+
+ function dumpOptional(array $optional) {
+ $req = array_filter($optional, function($a) {
+ return $a[3] & Args::REQARG;
+ });
+ $opt = array_filter($optional, function($a) {
+ return $a[3] & Args::OPTARG;
+ });
+
+ $dump = "";
+ if ($req) {
+ $dump .= sprintf(" [-%s <arg>]", implode("|-", array_column($req, 0)));
+ }
+ if ($opt) {
+ $dump .= sprintf(" [-%s [<arg>]]", implode("|-", array_column($opt, 0)));
+ }
+ return $dump;
+ }
+
+ function dumpPositional(array $positional) {
+ $dump = " [--]";
+ foreach ($positional as $pos) {
+ if ($pos[3] & Args::REQUIRED) {
+ $dump .= sprintf(" <%s>", $pos[1]);
+ } else {
+ $dump .= sprintf(" [<%s>]", $pos[1]);
+ }
+ if ($pos[3] & Args::MULTI) {
+ $dump .= sprintf(" [<%s>]...", $pos[1]);
+ }
+ }
+ return $dump;
+ }
+
+ function calcMaxLen() {
+ $spc = $this->args->getSpec();
+ $max = max(array_map("strlen", array_column($spc, 1)));
+ $max += $max % 8 + 2;
+ return $max;
+ }
+
+ function dumpHelp() {
+ $max = $this->calcMaxLen();
+ $dump = "";
+ foreach ($this->args->getSpec() as $spec) {
+ $dump .= " ";
+ if (is_numeric($spec[0])) {
+ $dump .= sprintf("-- %s ", $spec[1]);
+ } elseif (isset($spec[0])) {
+ $dump .= sprintf("-%s|", $spec[0]);
+ }
+ if (!is_numeric($spec[0])) {
+ $dump .= sprintf("--%s ", $spec[1]);
+ }
+ if ($spec[3] & Args::REQARG) {
+ $dump .= "<arg> ";
+ } elseif ($spec[3] & Args::OPTARG) {
+ $dump .= "[<arg>]";
+ } else {
+ $dump .= " ";
+ }
+
+ $dump .= str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0]));
+ $dump .= $spec[2];
+
+ if ($spec[3] & Args::REQUIRED) {
+ $dump .= " (REQUIRED)";
+ }
+ if ($spec[3] & Args::MULTI) {
+ $dump .= " (MULTIPLE)";
+ }
+ if (isset($spec[4])) {
+ $dump .= sprintf(" [%s]", $spec[4]);
+ }
+ $dump .= "\n";
+ }
+ return $dump;
+ }
+}
+<?php
+
+namespace pharext\Cli;
+
+/**
+ * Command line arguments
+ */
+class Args implements \ArrayAccess
+{
+ /**
+ * Optional option
+ */
+ const OPTIONAL = 0x000;
+
+ /**
+ * Required Option
+ */
+ const REQUIRED = 0x001;
+
+ /**
+ * Only one value, even when used multiple times
+ */
+ const SINGLE = 0x000;
+
+ /**
+ * Aggregate an array, when used multiple times
+ */
+ const MULTI = 0x010;
+
+ /**
+ * Option takes no argument
+ */
+ const NOARG = 0x000;
+
+ /**
+ * Option requires an argument
+ */
+ const REQARG = 0x100;
+
+ /**
+ * Option takes an optional argument
+ */
+ const OPTARG = 0x200;
+
+ /**
+ * Option halts processing
+ */
+ const HALT = 0x10000000;
+
+ /**
+ * Original option spec
+ * @var array
+ */
+ private $orig = [];
+
+ /**
+ * Compiled spec
+ * @var array
+ */
+ private $spec = [];
+
+ /**
+ * Parsed args
+ * @var array
+ */
+ private $args = [];
+
+ /**
+ * Compile the original spec
+ * @param array|Traversable $spec
+ */
+ public function __construct($spec = null) {
+ if (is_array($spec) || $spec instanceof Traversable) {
+ $this->compile($spec);
+ }
+
+ }
+
+ /**
+ * Compile the original spec
+ * @param array|Traversable $spec
+ * @return pharext\Cli\Args self
+ */
+ public function compile($spec) {
+ foreach ($spec as $arg) {
+ if (isset($arg[0]) && is_numeric($arg[0])) {
+ $arg[3] &= ~0xf00;
+ $this->spec["--".$arg[0]] = $arg;
+ } elseif (isset($arg[0])) {
+ $this->spec["-".$arg[0]] = $arg;
+ $this->spec["--".$arg[1]] = $arg;
+ } else {
+ $this->spec["--".$arg[1]] = $arg;
+ }
+ $this->orig[] = $arg;
+ }
+ return $this;
+ }
+
+ /**
+ * Get original spec
+ * @return array
+ */
+ public function getSpec() {
+ return $this->orig;
+ }
+
+ /**
+ * Get compiled spec
+ * @return array
+ */
+ public function getCompiledSpec() {
+ return $this->spec;
+ }
+
+ /**
+ * Parse command line arguments according to the compiled spec.
+ *
+ * The Generator yields any parsing errors.
+ * Parsing will stop when all arguments are processed or the first option
+ * flagged Cli\Args::HALT was encountered.
+ *
+ * @param int $argc
+ * @param array $argv
+ * @return Generator
+ */
+ public function parse($argc, array $argv) {
+ for ($f = false, $p = 0, $i = 0; $i < $argc; ++$i) {
+ $o = $argv[$i];
+
+ if ($o{0} === "-" && strlen($o) > 2 && $o{1} !== "-") {
+ // multiple short opts, e.g. -vps
+ $argc += strlen($o) - 2;
+ array_splice($argv, $i, 1, array_map(function($s) {
+ return "-$s";
+ }, str_split(substr($o, 1))));
+ $o = $argv[$i];
+ } elseif ($o{0} === "-" && strlen($o) > 2 && $o{1} === "-" && 0 < ($eq = strpos($o, "="))) {
+ // long opt with argument, e.g. --foo=bar
+ $argc++;
+ array_splice($argv, $i, 1, [
+ substr($o, 0, $eq++),
+ substr($o, $eq)
+ ]);
+ $o = $argv[$i];
+ } elseif ($o === "--") {
+ // only positional args following
+ $f = true;
+ continue;
+ }
+
+ if ($f || !isset($this->spec[$o])) {
+ if ($o{0} !== "-" && isset($this->spec["--$p"])) {
+ $this[$p] = $o;
+ if (!$this->optIsMulti($p)) {
+ ++$p;
+ }
+ } else {
+ yield sprintf("Unknown option %s", $o);
+ }
+ } elseif (!$this->optAcceptsArg($o)) {
+ $this[$o] = true;
+ } elseif ($i+1 < $argc && !isset($this->spec[$argv[$i+1]])) {
+ $this[$o] = $argv[++$i];
+ } elseif ($this->optRequiresArg($o)) {
+ yield sprintf("Option --%s requires an argument", $this->optLongName($o));
+ } else {
+ // OPTARG
+ $this[$o] = $this->optDefaultArg($o);
+ }
+
+ if ($this->optHalts($o)) {
+ return;
+ }
+ }
+ }
+
+ /**
+ * Validate that all required options were given.
+ *
+ * The Generator yields any validation errors.
+ *
+ * @return Generator
+ */
+ public function validate() {
+ $required = array_filter($this->orig, function($spec) {
+ return $spec[3] & self::REQUIRED;
+ });
+ foreach ($required as $req) {
+ if ($req[3] & self::MULTI) {
+ if (is_array($this[$req[0]])) {
+ continue;
+ }
+ } elseif (strlen($this[$req[0]])) {
+ continue;
+ }
+ if (is_numeric($req[0])) {
+ yield sprintf("Argument <%s> is required", $req[1]);
+ } else {
+ yield sprintf("Option --%s is required", $req[1]);
+ }
+ }
+ }
+
+
+ public function toArray() {
+ $args = [];
+ foreach ($this->spec as $spec) {
+ $opt = $this->opt($spec[1]);
+ $args[$opt] = $this[$opt];
+ }
+ return $args;
+ }
+
+ /**
+ * Retreive the default argument of an option
+ * @param string $o
+ * @return mixed
+ */
+ private function optDefaultArg($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o][4])) {
+ return $this->spec[$o][4];
+ }
+ return null;
+ }
+
+ /**
+ * Retrieve the help message of an option
+ * @param string $o
+ * @return string
+ */
+ private function optHelp($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o][2])) {
+ return $this->spec[$o][2];
+ }
+ return "";
+ }
+
+ /**
+ * Retrieve option's flags
+ * @param string $o
+ * @return int
+ */
+ private function optFlags($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o])) {
+ return $this->spec[$o][3];
+ }
+ return null;
+ }
+
+ /**
+ * Check whether an option is flagged for halting argument processing
+ * @param string $o
+ * @return boolean
+ */
+ private function optHalts($o) {
+ return $this->optFlags($o) & self::HALT;
+ }
+
+ /**
+ * Check whether an option needs an argument
+ * @param string $o
+ * @return boolean
+ */
+ private function optRequiresArg($o) {
+ return $this->optFlags($o) & self::REQARG;
+ }
+
+ /**
+ * Check wether an option accepts any argument
+ * @param string $o
+ * @return boolean
+ */
+ private function optAcceptsArg($o) {
+ return $this->optFlags($o) & 0xf00;
+ }
+
+ /**
+ * Check whether an option can be used more than once
+ * @param string $o
+ * @return boolean
+ */
+ private function optIsMulti($o) {
+ return $this->optFlags($o) & self::MULTI;
+ }
+
+ /**
+ * Retreive the long name of an option
+ * @param string $o
+ * @return string
+ */
+ private function optLongName($o) {
+ $o = $this->opt($o);
+ return is_numeric($this->spec[$o][0]) ? $this->spec[$o][0] : $this->spec[$o][1];
+ }
+
+ /**
+ * Retreive the short name of an option
+ * @param string $o
+ * @return string
+ */
+ private function optShortName($o) {
+ $o = $this->opt($o);
+ return is_numeric($this->spec[$o][0]) ? null : $this->spec[$o][0];
+ }
+
+ /**
+ * Retreive the canonical name (--long-name) of an option
+ * @param string $o
+ * @return string
+ */
+ private function opt($o) {
+ if (is_numeric($o)) {
+ return "--$o";
+ }
+ if ($o{0} !== '-') {
+ if (strlen($o) > 1) {
+ $o = "-$o";
+ }
+ $o = "-$o";
+ }
+ return $o;
+ }
+
+ /**@+
+ * Implements ArrayAccess and virtual properties
+ */
+ function offsetExists($o) {
+ $o = $this->opt($o);
+ return isset($this->args[$o]);
+ }
+ function __isset($o) {
+ return $this->offsetExists($o);
+ }
+ function offsetGet($o) {
+ $o = $this->opt($o);
+ if (isset($this->args[$o])) {
+ return $this->args[$o];
+ }
+ return $this->optDefaultArg($o);
+ }
+ function __get($o) {
+ return $this->offsetGet($o);
+ }
+ function offsetSet($o, $v) {
+ $osn = $this->optShortName($o);
+ $oln = $this->optLongName($o);
+ if ($this->optIsMulti($o)) {
+ if (isset($osn)) {
+ $this->args["-$osn"][] = $v;
+ }
+ $this->args["--$oln"][] = $v;
+ } else {
+ if (isset($osn)) {
+ $this->args["-$osn"] = $v;
+ }
+ $this->args["--$oln"] = $v;
+ }
+ }
+ function __set($o, $v) {
+ $this->offsetSet($o, $v);
+ }
+ function offsetUnset($o) {
+ unset($this->args["-".$this->optShortName($o)]);
+ unset($this->args["--".$this->optLongName($o)]);
+ }
+ function __unset($o) {
+ $this->offsetUnset($o);
+ }
+ /**@-*/
+}
+<?php
+
+namespace pharext\Cli;
+
+use pharext\Archive;
+
+use Phar;
+
+trait Command
+{
+ /**
+ * Command line arguments
+ * @var pharext\Cli\Args
+ */
+ private $args;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::getArgs()
+ */
+ public function getArgs() {
+ return $this->args;
+ }
+
+ /**
+ * Retrieve metadata of the currently running phar
+ * @param string $key
+ * @return mixed
+ */
+ public function metadata($key = null) {
+ if (extension_loaded("Phar")) {
+ $running = new Phar(Phar::running(false));
+ } else {
+ $running = new Archive(PHAREXT_PHAR);
+ }
+
+ if ($key === "signature") {
+ $sig = $running->getSignature();
+ return sprintf("%s signature of %s\n%s",
+ $sig["hash_type"],
+ $this->metadata("name"),
+ chunk_split($sig["hash"], 64, "\n"));
+ }
+
+ $metadata = $running->getMetadata();
+ if (isset($key)) {
+ return $metadata[$key];
+ }
+ return $metadata;
+ }
+
+ /**
+ * Output pharext vX.Y.Z header
+ */
+ public function header() {
+ if (!headers_sent()) {
+ /* only display header, if we didn't generate any output yet */
+ printf("%s\n\n", $this->metadata("header"));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::debug()
+ */
+ public function debug($fmt) {
+ if ($this->args->verbose) {
+ vprintf($fmt, array_slice(func_get_args(), 1));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::info()
+ */
+ public function info($fmt) {
+ if (!$this->args->quiet) {
+ vprintf($fmt, array_slice(func_get_args(), 1));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::warn()
+ */
+ public function warn($fmt) {
+ if (!$this->args->quiet) {
+ if (!isset($fmt)) {
+ $fmt = "%s\n";
+ $arg = error_get_last()["message"];
+ } else {
+ $arg = array_slice(func_get_args(), 1);
+ }
+ vfprintf(STDERR, "Warning: $fmt", $arg);
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::error()
+ */
+ public function error($fmt) {
+ if (!isset($fmt)) {
+ $fmt = "%s\n";
+ $arg = error_get_last()["message"];
+ } else {
+ $arg = array_slice(func_get_args(), 1);
+ }
+ vfprintf(STDERR, "ERROR: $fmt", $arg);
+ }
+
+ /**
+ * Output command line help message
+ * @param string $prog
+ */
+ public function help($prog) {
+ print new Args\Help($prog, $this->args);
+ }
+
+ /**
+ * Verbosity
+ * @return boolean
+ */
+ public function verbosity() {
+ if ($this->args->verbose) {
+ return true;
+ } elseif ($this->args->quiet) {
+ return false;
+ } else {
+ return null;
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Command interface
+ */
+interface Command
+{
+ /**
+ * Argument error
+ */
+ const EARGS = 1;
+ /**
+ * Build error
+ */
+ const EBUILD = 2;
+ /**
+ * Signature error
+ */
+ const ESIGN = 3;
+ /**
+ * Extract/unpack error
+ */
+ const EEXTRACT = 4;
+ /**
+ * Install error
+ */
+ const EINSTALL = 5;
+
+ /**
+ * Retrieve command line arguments
+ * @return pharext\Cli\Args
+ */
+ public function getArgs();
+
+ /**
+ * Print debug message
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function debug($fmt);
+
+ /**
+ * Print info
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function info($fmt);
+
+ /**
+ * Print warning
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function warn($fmt);
+
+ /**
+ * Print error
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function error($fmt);
+
+ /**
+ * Execute the command
+ * @param int $argc command line argument count
+ * @param array $argv command line argument list
+ */
+ public function run($argc, array $argv);
+}
+<?php
+
+namespace pharext;
+
+class Exception extends \Exception
+{
+ public function __construct($message = null, $code = 0, $previous = null) {
+ if (!isset($message)) {
+ $last_error = error_get_last();
+ $message = $last_error["message"];
+ if (!$code) {
+ $code = $last_error["type"];
+ }
+ }
+ parent::__construct($message, $code, $previous);
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Execute system command
+ */
+class ExecCmd
+{
+ /**
+ * Sudo command, if the cmd needs escalated privileges
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ * Executable of the cmd
+ * @var string
+ */
+ private $command;
+
+ /**
+ * Passthrough cmd output
+ * @var bool
+ */
+ private $verbose;
+
+ /**
+ * Output of cmd run
+ * @var string
+ */
+ private $output;
+
+ /**
+ * Return code of cmd run
+ * @var int
+ */
+ private $status;
+
+ /**
+ * @param string $command
+ * @param bool verbose
+ */
+ public function __construct($command, $verbose = false) {
+ $this->command = $command;
+ $this->verbose = $verbose;
+ }
+
+ /**
+ * (Re-)set sudo command
+ * @param string $sudo
+ */
+ public function setSu($sudo = false) {
+ $this->sudo = $sudo;
+ }
+
+ /**
+ * Execute a program with escalated privileges handling interactive password prompt
+ * @param string $command
+ * @param bool $verbose
+ * @return int exit status
+ */
+ private function suExec($command, $verbose = null) {
+ if (!($proc = proc_open($command, [STDIN,["pipe","w"],["pipe","w"]], $pipes))) {
+ $this->status = -1;
+ throw new Exception("Failed to run {$command}");
+ }
+
+ $stdout = $pipes[1];
+ $passwd = 0;
+ $checks = 10;
+
+ while (!feof($stdout)) {
+ $R = [$stdout]; $W = []; $E = [];
+ if (!stream_select($R, $W, $E, null)) {
+ continue;
+ }
+ $data = fread($stdout, 0x1000);
+ /* only check a few times */
+ if ($passwd < $checks) {
+ $passwd++;
+ if (stristr($data, "password")) {
+ $passwd = $checks + 1;
+ printf("\n%s", $data);
+ continue;
+ }
+ } elseif ($passwd > $checks) {
+ /* new line after pw entry */
+ printf("\n");
+ $passwd = $checks;
+ }
+
+ if ($verbose === null) {
+ print $this->progress($data, 0);
+ } else {
+ if ($verbose) {
+ printf("%s", $data);
+ }
+ $this->output .= $data;
+ }
+ }
+ if ($verbose === null) {
+ $this->progress("", PHP_OUTPUT_HANDLER_FINAL);
+ }
+ return $this->status = proc_close($proc);
+ }
+
+ /**
+ * Output handler that displays some progress while soaking output
+ * @param string $string
+ * @param int $flags
+ * @return string
+ */
+ private function progress($string, $flags) {
+ static $counter = 0;
+ static $symbols = ["\\","|","/","-"];
+
+ $this->output .= $string;
+
+ if (false !== strpos($string, "\n")) {
+ ++$counter;
+ }
+
+ return $flags & PHP_OUTPUT_HANDLER_FINAL
+ ? " \r"
+ : sprintf(" %s\r", $symbols[$counter % 4]);
+ }
+
+ /**
+ * Run the command
+ * @param array $args
+ * @return \pharext\ExecCmd self
+ * @throws \pharext\Exception
+ */
+ public function run(array $args = null) {
+ $exec = escapeshellcmd($this->command);
+ if ($args) {
+ $exec .= " ". implode(" ", array_map("escapeshellarg", (array) $args));
+ }
+
+ if ($this->sudo) {
+ $this->suExec(sprintf($this->sudo." 2>&1", $exec), $this->verbose);
+ } elseif ($this->verbose) {
+ ob_start(function($s) {
+ $this->output .= $s;
+ return $s;
+ }, 1);
+ passthru($exec, $this->status);
+ ob_end_flush();
+ } elseif ($this->verbose !== false /* !quiet */) {
+ ob_start([$this, "progress"], 1);
+ passthru($exec . " 2>&1", $this->status);
+ ob_end_flush();
+ } else {
+ exec($exec ." 2>&1", $output, $this->status);
+ $this->output = implode("\n", $output);
+ }
+
+ if ($this->status) {
+ throw new Exception("Command {$exec} failed ({$this->status})");
+ }
+
+ return $this;
+ }
+
+ /**
+ * Retrieve exit code of cmd run
+ * @return int
+ */
+ public function getStatus() {
+ return $this->status;
+ }
+
+ /**
+ * Retrieve output of cmd run
+ * @return string
+ */
+ public function getOutput() {
+ return $this->output;
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use SplObjectStorage;
+
+/**
+ * The extension install command executed by the extension phar
+ */
+class Installer implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Cleanups
+ * @var array
+ */
+ private $cleanup = [];
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["p", "prefix", "PHP installation prefix if phpize is not in \$PATH, e.g. /opt/php7",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["n", "common-name", "PHP common program name, e.g. php5 or zts-php",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG,
+ "php"],
+ ["c", "configure", "Additional extension configure flags, e.g. -c --with-flag",
+ Cli\Args::OPTIONAL|Cli\Args::MULTI|Cli\Args::REQARG],
+ ["s", "sudo", "Installation might need increased privileges",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::OPTARG,
+ "sudo -S %s"],
+ ["i", "ini", "Activate in this php.ini instead of loaded default php.ini",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ [null, "signature", "Show package signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show package license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "name", "Show package name",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "date", "Show package release date",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "release", "Show package release version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ]);
+ }
+
+ /**
+ * Perform cleaniup
+ */
+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
+ private function extract($phar) {
+ $temp = (new Task\Extract($phar))->run($this->verbosity());
+ $this->cleanup[] = new Task\Cleanup($temp);
+ return $temp;
+ }
+
+ private function hooks(SplObjectStorage $phars) {
+ $hook = [];
+ foreach ($phars as $phar) {
+ if (isset($phar["pharext_package.php"])) {
+ $sdir = include $phar["pharext_package.php"];
+ if ($sdir instanceof SourceDir) {
+ $this->args->compile($sdir->getArgs());
+ $hook[] = $sdir;
+ }
+ }
+ }
+ return $hook;
+ }
+
+ private function load() {
+ $list = new SplObjectStorage();
+ $phar = extension_loaded("Phar")
+ ? new Phar(Phar::running(false))
+ : new Archive(PHAREXT_PHAR);
+ $temp = $this->extract($phar);
+
+ foreach ($phar as $entry) {
+ $dep_file = $entry->getBaseName();
+ if (fnmatch("*.ext.phar*", $dep_file)) {
+ $dep_phar = extension_loaded("Phar")
+ ? new Phar("$temp/$dep_file")
+ : new Archive("$temp/$dep_file");
+ $list[$dep_phar] = $this->extract($dep_phar);
+ }
+ }
+
+ /* the actual ext.phar at last */
+ $list[$phar] = $temp;
+ return $list;
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ try {
+ /* load the phar(s) */
+ $list = $this->load();
+ /* installer hooks */
+ $hook = $this->hooks($list);
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EEXTRACT);
+ }
+
+ /* standard arg stuff */
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+ try {
+ foreach (["signature", "name", "date", "license", "release", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ try {
+ /* post process hooks */
+ foreach ($hook as $sdir) {
+ $sdir->setArgs($this->args);
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ /* install packages */
+ try {
+ foreach ($list as $phar) {
+ $this->info("Installing %s ...\n", basename($phar->getPath()));
+ $this->install($list[$phar]);
+ $this->activate($list[$phar]);
+ $this->info("Successfully installed %s!\n", basename($phar->getPath()));
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EINSTALL);
+ }
+ }
+
+ /**
+ * Phpize + trinity
+ */
+ private function install($temp) {
+ // phpize
+ $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"});
+ $phpize->run($this->verbosity());
+
+ // configure
+ $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args->{"common-name"});
+ $configure->run($this->verbosity());
+
+ // make
+ $make = new Task\Make($temp);
+ $make->run($this->verbosity());
+
+ // install
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $install = new Task\Make($temp, ["install"], $sudo);
+ $install->run($this->verbosity());
+ }
+
+ private function activate($temp) {
+ if ($this->args->ini) {
+ $files = [$this->args->ini];
+ } else {
+ $files = array_filter(array_map("trim", explode(",", php_ini_scanned_files())));
+ $files[] = php_ini_loaded_file();
+ }
+
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $type = $this->metadata("type") ?: "extension";
+
+ $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
+ if (!$activate->run($this->verbosity())) {
+ $this->info("Extension already activated ...\n");
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+trait License
+{
+ function findLicense($dir, $file = null) {
+ if (isset($file)) {
+ return realpath("$dir/$file");
+ }
+
+ $names = [];
+ foreach (["{,UN}LICEN{S,C}{E,ING}", "COPY{,ING,RIGHT}"] as $name) {
+ $names[] = $this->mergeLicensePattern($name, strtolower($name));
+ }
+ $exts = [];
+ foreach (["t{,e}xt", "rst", "asc{,i,ii}", "m{,ark}d{,own}", "htm{,l}"] as $ext) {
+ $exts[] = $this->mergeLicensePattern(strtoupper($ext), $ext);
+ }
+
+ $pattern = "{". implode(",", $names) ."}{,.{". implode(",", $exts) ."}}";
+
+ if (($glob = glob("$dir/$pattern", GLOB_BRACE))) {
+ return current($glob);
+ }
+ }
+
+ private function mergeLicensePattern($upper, $lower) {
+ $pattern = "";
+ $length = strlen($upper);
+ for ($i = 0; $i < $length; ++$i) {
+ if ($lower{$i} === $upper{$i}) {
+ $pattern .= $upper{$i};
+ } else {
+ $pattern .= "[" . $upper{$i} . $lower{$i} . "]";
+ }
+ }
+ return $pattern;
+ }
+
+ public function readLicense($file) {
+ $text = file_get_contents($file);
+ switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {
+ case "htm":
+ case "html":
+ $text = strip_tags($text);
+ break;
+ }
+ return $text;
+ }
+}
+<?php
+
+namespace pharext;
+
+class Metadata
+{
+ static function version() {
+ return "4.1.1";
+ }
+
+ static function header() {
+ return sprintf("pharext v%s (c) Michael Wallner <mike@php.net>", self::version());
+ }
+
+ static function date() {
+ return gmdate("Y-m-d");
+ }
+
+ static function all() {
+ return [
+ "version" => self::version(),
+ "header" => self::header(),
+ "date" => self::date(),
+ ];
+ }
+}
+<?php
+
+namespace pharext\Openssl;
+
+use pharext\Exception;
+
+class PrivateKey
+{
+ /**
+ * Private key
+ * @var string
+ */
+ private $key;
+
+ /**
+ * Public key
+ * @var string
+ */
+ private $pub;
+
+ /**
+ * Read a private key
+ * @param string $file
+ * @param string $password
+ * @throws \pharext\Exception
+ */
+ function __construct($file, $password) {
+ /* there appears to be a bug with refcount handling of this
+ * resource; when the resource is stored as property, it cannot be
+ * "coerced to a private key" on openssl_sign() later in another method
+ */
+ $key = openssl_pkey_get_private("file://$file", $password);
+ if (!is_resource($key)) {
+ throw new Exception("Could not load private key");
+ }
+ openssl_pkey_export($key, $this->key);
+ $this->pub = openssl_pkey_get_details($key)["key"];
+ }
+
+ /**
+ * Sign the PHAR
+ * @param \Phar $package
+ */
+ function sign(\Phar $package) {
+ $package->setSignatureAlgorithm(\Phar::OPENSSL, $this->key);
+ }
+
+ /**
+ * Export the public key to a file
+ * @param string $file
+ * @throws \pharext\Exception
+ */
+ function exportPublicKey($file) {
+ if (!file_put_contents("$file.tmp", $this->pub) || !rename("$file.tmp", $file)) {
+ throw new Exception;
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use pharext\Exception;
+
+/**
+ * The extension packaging command executed by bin/pharext
+ */
+class Packager implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Extension source directory
+ * @var pharext\SourceDir
+ */
+ private $source;
+
+ /**
+ * Cleanups
+ * @var array
+ */
+ private $cleanup = [];
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display this help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["n", "name", "Extension name",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["r", "release", "Extension release version",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["s", "source", "Extension source directory",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["g", "git", "Use `git ls-tree` to determine file list",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["b", "branch", "Checkout this tag/branch",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["p", "pecl", "Use PECL package.xml to determine file list, name and release",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["d", "dest", "Destination directory",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG,
+ "."],
+ ["z", "gzip", "Create additional PHAR compressed with gzip",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["Z", "bzip", "Create additional PHAR compressed with bzip",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["S", "sign", "Sign the PHAR with a private key",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["E", "zend", "Mark as Zend Extension",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ [null, "signature", "Show pharext signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show pharext license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ]);
+ }
+
+ /**
+ * Perform cleaniup
+ */
+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+ try {
+ foreach (["signature", "license", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ try {
+ /* source needs to be evaluated before Cli\Args validation,
+ * so e.g. name and version can be overriden and Cli\Args
+ * does not complain about missing arguments
+ */
+ $this->loadSource();
+ } catch (\Exception $e) {
+ $errs[] = $e->getMessage();
+ }
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ printf("\n");
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ $this->createPackage();
+ }
+
+ /**
+ * Download remote source
+ * @param string $source
+ * @return string local source
+ */
+ private function download($source) {
+ if ($this->args->git) {
+ $task = new Task\GitClone($source, $this->args->branch);
+ } else {
+ /* print newline only once */
+ $done = false;
+ $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) {
+ if (!$done) {
+ $this->info(" %3d%% [%s>%s] \r",
+ floor($bytes_pct*100),
+ str_repeat("=", round(50*$bytes_pct)),
+ str_repeat(" ", round(50*(1-$bytes_pct)))
+ );
+ if ($bytes_pct == 1) {
+ $done = true;
+ $this->info("\n");
+ }
+ }
+ });
+ }
+ $local = $task->run($this->verbosity());
+
+ $this->cleanup[] = new Task\Cleanup($local);
+ return $local;
+ }
+
+ /**
+ * Extract local archive
+ * @param stirng $source
+ * @return string extracted directory
+ */
+ private function extract($source) {
+ try {
+ $task = new Task\Extract($source);
+ $dest = $task->run($this->verbosity());
+ } catch (\Exception $e) {
+ if (false === strpos($e->getMessage(), "checksum mismatch")) {
+ throw $e;
+ }
+ $dest = (new Task\PaxFixup($source))->run($this->verbosity());
+ }
+
+ $this->cleanup[] = new Task\Cleanup($dest);
+ return $dest;
+ }
+
+ /**
+ * Localize a possibly remote source
+ * @param string $source
+ * @return string local source directory
+ */
+ private function localize($source) {
+ if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) {
+ $source = $this->download($source);
+ $this->cleanup[] = new Task\Cleanup($source);
+ }
+ $source = realpath($source);
+ if (!is_dir($source)) {
+ $source = $this->extract($source);
+ $this->cleanup[] = new Task\Cleanup($source);
+
+ if (!$this->args->git) {
+ $source = (new Task\PeclFixup($source))->run($this->verbosity());
+ }
+ }
+ return $source;
+ }
+
+ /**
+ * Load the source dir
+ * @throws \pharext\Exception
+ */
+ private function loadSource(){
+ if ($this->args["source"]) {
+ $source = $this->localize($this->args["source"]);
+
+ if ($this->args["pecl"]) {
+ $this->source = new SourceDir\Pecl($source);
+ } elseif ($this->args["git"]) {
+ $this->source = new SourceDir\Git($source);
+ } elseif (is_file("$source/pharext_package.php")) {
+ $this->source = include "$source/pharext_package.php";
+ } else {
+ $this->source = new SourceDir\Basic($source);
+ }
+
+ if (!$this->source instanceof SourceDir) {
+ throw new Exception("Unknown source dir $source");
+ }
+
+ foreach ($this->source->getPackageInfo() as $key => $val) {
+ $this->args->$key = $val;
+ }
+ }
+ }
+
+ /**
+ * Creates the extension phar
+ */
+ private function createPackage() {
+ try {
+ $meta = array_merge(Metadata::all(), [
+ "name" => $this->args->name,
+ "release" => $this->args->release,
+ "license" => $this->source->getLicense(),
+ "type" => $this->args->zend ? "zend_extension" : "extension",
+ ]);
+ $file = (new Task\PharBuild($this->source, __DIR__."/../pharext_installer.php", $meta))->run($this->verbosity());
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EBUILD);
+ }
+
+ try {
+ if ($this->args->sign) {
+ $this->info("Using private key to sign phar ...\n");
+ $pass = (new Task\Askpass)->run($this->verbosity());
+ $sign = new Task\PharSign($file, $this->args->sign, $pass);
+ $pkey = $sign->run($this->verbosity());
+ }
+
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::ESIGN);
+ }
+
+ if ($this->args->gzip) {
+ try {
+ $gzip = (new Task\PharCompress($file, Phar::GZ))->run();
+ $move = new Task\PharRename($gzip, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created gzipped phar %s\n", $name);
+
+ if ($this->args->sign) {
+ $sign = new Task\PharSign($name, $this->args->sign, $pass);
+ $sign->run($this->verbosity())->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->warn("%s\n", $e->getMessage());
+ }
+ }
+
+ if ($this->args->bzip) {
+ try {
+ $bzip = (new Task\PharCompress($file, Phar::BZ2))->run();
+ $move = new Task\PharRename($bzip, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created bzipped phar %s\n", $name);
+
+ if ($this->args->sign) {
+ $sign = new Task\PharSign($name, $this->args->sign, $pass);
+ $sign->run($this->verbosity())->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->warn("%s\n", $e->getMessage());
+ }
+ }
+
+ try {
+ $move = new Task\PharRename($file, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created executable phar %s\n", $name);
+
+ if (isset($pkey)) {
+ $pkey->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EBUILD);
+ }
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\License;
+use pharext\SourceDir;
+
+use FilesystemIterator;
+use IteratorAggregate;
+use RecursiveCallbackFilterIterator;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+
+class Basic implements IteratorAggregate, SourceDir
+{
+ use License;
+
+ private $path;
+
+ public function __construct($path) {
+ $this->path = $path;
+ }
+
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ public function getPackageInfo() {
+ return [];
+ }
+
+ public function getLicense() {
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ return "UNKNOWN";
+ }
+
+ public function getArgs() {
+ return [];
+ }
+
+ public function setArgs(Args $args) {
+ }
+
+ public function filter($current, $key, $iterator) {
+ $sub = $current->getSubPath();
+ if ($sub === ".git" || $sub === ".hg" || $sub === ".svn") {
+ return false;
+ }
+ return true;
+ }
+
+ public function getIterator() {
+ $rdi = new RecursiveDirectoryIterator($this->path,
+ FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5
+ FilesystemIterator::KEY_AS_PATHNAME |
+ FilesystemIterator::SKIP_DOTS);
+ $rci = new RecursiveCallbackFilterIterator($rdi, [$this, "filter"]);
+ $rii = new RecursiveIteratorIterator($rci);
+ foreach ($rii as $path => $child) {
+ if (!$child->isDir()) {
+ yield realpath($path);
+ }
+ }
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\License;
+use pharext\SourceDir;
+
+/**
+ * Extension source directory which is a git repo
+ */
+class Git implements \IteratorAggregate, SourceDir
+{
+ use License;
+
+ /**
+ * Base directory
+ * @var string
+ */
+ private $path;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::__construct()
+ */
+ public function __construct($path) {
+ $this->path = $path;
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getBaseDir()
+ */
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public function getPackageInfo() {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ * @return string
+ */
+ public function getLicense() {
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ return "UNKNOWN";
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public function getArgs() {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setArgs(Args $args) {
+ }
+
+ /**
+ * Generate a list of files by `git ls-files`
+ * @return Generator
+ */
+ private function generateFiles() {
+ $pwd = getcwd();
+ chdir($this->path);
+ if (($pipe = popen("git ls-tree -r --name-only HEAD", "r"))) {
+ $path = realpath($this->path);
+ while (!feof($pipe)) {
+ if (strlen($file = trim(fgets($pipe)))) {
+ /* there may be symlinks, so no realpath here */
+ yield "$path/$file";
+ }
+ }
+ pclose($pipe);
+ }
+ chdir($pwd);
+ }
+
+ /**
+ * Implements IteratorAggregate
+ * @see IteratorAggregate::getIterator()
+ */
+ public function getIterator() {
+ return $this->generateFiles();
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\Exception;
+use pharext\SourceDir;
+use pharext\License;
+
+/**
+ * A PECL extension source directory containing a v2 package.xml
+ */
+class Pecl implements \IteratorAggregate, SourceDir
+{
+ use License;
+
+ /**
+ * The package.xml
+ * @var SimpleXmlElement
+ */
+ private $sxe;
+
+ /**
+ * The base directory
+ * @var string
+ */
+ private $path;
+
+ /**
+ * The package.xml
+ * @var string
+ */
+ private $file;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::__construct()
+ */
+ public function __construct($path) {
+ if (is_file("$path/package2.xml")) {
+ $sxe = simplexml_load_file($this->file = "$path/package2.xml");
+ } elseif (is_file("$path/package.xml")) {
+ $sxe = simplexml_load_file($this->file = "$path/package.xml");
+ } else {
+ throw new Exception("Missing package.xml in $path");
+ }
+
+ $sxe->registerXPathNamespace("pecl", $sxe->getDocNamespaces()[""]);
+
+ $this->sxe = $sxe;
+ $this->path = realpath($path);
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getBaseDir()
+ */
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ /**
+ * Retrieve gathered package info
+ * @return Generator
+ */
+ public function getPackageInfo() {
+ if (($name = $this->sxe->xpath("/pecl:package/pecl:name"))) {
+ yield "name" => (string) $name[0];
+ }
+ if (($release = $this->sxe->xpath("/pecl:package/pecl:version/pecl:release"))) {
+ yield "release" => (string) $release[0];
+ }
+ if ($this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease")) {
+ yield "zend" => true;
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @return string
+ */
+ public function getLicense() {
+ if (($license = $this->sxe->xpath("/pecl:package/pecl:license"))) {
+ if (($file = $this->findLicense($this->getBaseDir(), $license[0]["filesource"]))) {
+ return $this->readLicense($file);
+ }
+ }
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ if ($license) {
+ return $license[0] ." ". $license[0]["uri"];
+ }
+ return "UNKNOWN";
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getArgs()
+ */
+ public function getArgs() {
+ $configure = $this->sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ yield [null, $cfg["name"], ucfirst($cfg["prompt"]), Args::OPTARG,
+ strlen($cfg["default"]) ? $cfg["default"] : null];
+ }
+ $configure = $this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ yield [null, $cfg["name"], ucfirst($cfg["prompt"]), Args::OPTARG,
+ strlen($cfg["default"]) ? $cfg["default"] : null];
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::setArgs()
+ */
+ public function setArgs(Args $args) {
+ $configure = $this->sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ if (isset($args[$cfg["name"]])) {
+ $args->configure = "--{$cfg["name"]}={$args[$cfg["name"]]}";
+ }
+ }
+ $configure = $this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ if (isset($args[$cfg["name"]])) {
+ $args->configure = "--{$cfg["name"]}={$args[$cfg["name"]]}";
+ }
+ }
+ }
+
+ /**
+ * Compute the path of a file by parent dir nodes
+ * @param \SimpleXMLElement $ele
+ * @return string
+ */
+ private function dirOf($ele) {
+ $path = "";
+ while (($ele = current($ele->xpath(".."))) && $ele->getName() == "dir") {
+ $path = trim($ele["name"], "/") ."/". $path ;
+ }
+ return trim($path, "/");
+ }
+
+ /**
+ * Generate a list of files from the package.xml
+ * @return Generator
+ */
+ private function generateFiles() {
+ /* hook */
+ $temp = tmpfile();
+ fprintf($temp, "<?php\nreturn new %s(__DIR__);\n", get_class($this));
+ rewind($temp);
+ yield "pharext_package.php" => $temp;
+
+ /* deps */
+ $dependencies = $this->sxe->xpath("/pecl:package/pecl:dependencies/pecl:required/pecl:package");
+ foreach ($dependencies as $key => $dep) {
+ if (($glob = glob("{$this->path}/{$dep->name}-*.ext.phar*"))) {
+ usort($glob, function($a, $b) {
+ return version_compare(
+ substr($a, strpos(".ext.phar", $a)),
+ substr($b, strpos(".ext.phar", $b))
+ );
+ });
+ yield end($glob);
+ }
+ }
+
+ /* files */
+ yield realpath($this->file);
+ foreach ($this->sxe->xpath("//pecl:file") as $file) {
+ yield realpath($this->path ."/". $this->dirOf($file) ."/". $file["name"]);
+ }
+ }
+
+ /**
+ * Implements IteratorAggregate
+ * @see IteratorAggregate::getIterator()
+ */
+ public function getIterator() {
+ return $this->generateFiles();
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Source directory interface, which should yield file names to package on traversal
+ */
+interface SourceDir extends \Traversable
+{
+ /**
+ * Retrieve the base directory
+ * @return string
+ */
+ public function getBaseDir();
+
+ /**
+ * Retrieve gathered package info
+ * @return array|Traversable
+ */
+ public function getPackageInfo();
+
+ /**
+ * Retrieve the full text license
+ * @return string
+ */
+ public function getLicense();
+
+ /**
+ * Provide installer command line args
+ * @return array|Traversable
+ */
+ public function getArgs();
+
+ /**
+ * Process installer command line args
+ * @param \pharext\Cli\Args $args
+ */
+ public function setArgs(Cli\Args $args);
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+use pharext\Tempfile;
+
+/**
+ * PHP INI activation
+ */
+class Activate implements Task
+{
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @var array
+ */
+ private $inis;
+
+ /**
+ * @var string
+ */
+ private $type;
+
+ /**
+ * @var string
+ */
+ private $php_config;
+
+ /**
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ * @param string $cwd working directory
+ * @param array $inis custom INI or list of loaded/scanned INI files
+ * @param string $type extension or zend_extension
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP programs common name, e.g. php5
+ * @param string $sudo sudo command
+ * @throws \pharext\Exception
+ */
+ public function __construct($cwd, array $inis, $type = "extension", $prefix = null, $common_name = "php", $sudo = null) {
+ $this->cwd = $cwd;
+ $this->type = $type;
+ $this->sudo = $sudo;
+ if (!$this->inis = $inis) {
+ throw new Exception("No PHP INIs given");
+ }
+ $cmd = $common_name . "-config";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->php_config = $cmd;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return boolean false, if extension was already activated
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running INI activation ...\n");
+ }
+ $extension = basename(current(glob("{$this->cwd}/modules/*.so")));
+
+ if ($this->type === "zend_extension") {
+ $pattern = preg_quote((new ExecCmd($this->php_config))->run(["--extension-dir"])->getOutput() . "/$extension", "/");
+ } else {
+ $pattern = preg_quote($extension, "/");
+ }
+
+ foreach ($this->inis as $file) {
+ if ($verbose) {
+ printf("Checking %s ...\n", $file);
+ }
+ if (!file_exists($file)) {
+ throw new Exception(sprintf("INI file '%s' does not exist", $file));
+ }
+ $temp = new Tempfile("phpini");
+ foreach (file($file) as $line) {
+ if (preg_match("/^\s*{$this->type}\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
+ return false;
+ }
+ fwrite($temp->getStream(), $line);
+ }
+ }
+
+ /* not found; append to last processed file, which is the main by default */
+ if ($verbose) {
+ printf("Activating in %s ...\n", $file);
+ }
+ fprintf($temp->getStream(), $this->type . "=%s\n", $extension);
+ $temp->closeStream();
+
+ $path = $temp->getPathname();
+ $stat = stat($file);
+
+ // owner transfer
+ $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]);
+ $cmd = new ExecCmd("chown", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$ugid, $path]);
+
+ // permission transfer
+ $perm = decoct($stat["mode"] & 0777);
+ $cmd = new ExecCmd("chmod", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$perm, $path]);
+
+ // rename
+ $cmd = new ExecCmd("mv", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$path, $file]);
+
+ if ($verbose) {
+ printf("Replaced %s ...\n", $file);
+ }
+
+ return true;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+/**
+ * Ask password on console
+ */
+class Askpass implements Task
+{
+ /**
+ * @var string
+ */
+ private $prompt;
+
+ /**
+ * @param string $prompt
+ */
+ public function __construct($prompt = "Password:") {
+ $this->prompt = $prompt;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string
+ */
+ public function run($verbose = false) {
+ system("stty -echo");
+ printf("%s ", $this->prompt);
+ $pass = fgets(STDIN, 1024);
+ printf("\n");
+ system("stty echo");
+ if (substr($pass, -1) == "\n") {
+ $pass = substr($pass, 0, -1);
+ }
+ return $pass;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+/**
+ * List all library files of pharext to bundle with a phar
+ */
+class BundleGenerator implements Task
+{
+ /**
+ * @param bool $verbose
+ * @return Generator
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Packaging pharext ... \n");
+ }
+ $rdi = new RecursiveDirectoryIterator(dirname(dirname(__DIR__)));
+ $rii = new RecursiveIteratorIterator($rdi);
+ for ($rii->rewind(); $rii->valid(); $rii->next()) {
+ if (!$rii->isDot()) {
+ yield $rii->getSubPathname() => $rii->key();
+ }
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use FilesystemIterator;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+/**
+ * Recursively cleanup FS entries
+ */
+class Cleanup implements Task
+{
+ /**
+ * @var string
+ */
+ private $rm;
+
+ public function __construct($rm) {
+ $this->rm = $rm;
+ }
+
+ /**
+ * @param bool $verbose
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Cleaning up %s ...\n", $this->rm);
+ }
+ if ($this->rm instanceof Tempfile) {
+ unset($this->rm);
+ } elseif (is_dir($this->rm)) {
+ $rdi = new RecursiveDirectoryIterator($this->rm,
+ FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5
+ FilesystemIterator::KEY_AS_PATHNAME |
+ FilesystemIterator::SKIP_DOTS);
+ $rii = new RecursiveIteratorIterator($rdi,
+ RecursiveIteratorIterator::CHILD_FIRST);
+ foreach ($rii as $path => $child) {
+ if ($child->isDir()) {
+ @rmdir($path);
+ } else {
+ @unlink($path);
+ }
+ }
+ @rmdir($this->rm);
+ } elseif (file_exists($this->rm)) {
+ @unlink($this->rm);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+
+/**
+ * Runs extension's configure
+ */
+class Configure implements Task
+{
+ /**
+ * @var array
+ */
+ private $args;
+
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @param string $cwd working directory
+ * @param array $args configure args
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP programs common name, e.g. php5
+ */
+ public function __construct($cwd, array $args = null, $prefix = null, $common_name = "php") {
+ $this->cwd = $cwd;
+ $cmd = $common_name . "-config";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->args = ["--with-php-config=$cmd"];
+ if ($args) {
+ $this->args = array_merge($this->args, $args);
+ }
+ }
+
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running ./configure ...\n");
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd("./configure", $verbose);
+ $cmd->run($this->args);
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Archive;
+use pharext\Task;
+use pharext\Tempdir;
+
+use Phar;
+use PharData;
+
+/**
+ * Extract a package archive
+ */
+class Extract implements Task
+{
+ /**
+ * @var Phar(Data)
+ */
+ private $source;
+
+ /**
+ * @param mixed $source archive location
+ */
+ public function __construct($source) {
+ if ($source instanceof Phar || $source instanceof PharData || $source instanceof Archive) {
+ $this->source = $source;
+ } else {
+ $this->source = new PharData($source);
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempdir
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Extracting %s ...\n", basename($this->source->getPath()));
+ }
+ if ($this->source instanceof Archive) {
+ return $this->source->extract();
+ }
+ $dest = new Tempdir("extract");
+ $this->source->extractTo($dest);
+ return $dest;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\ExecCmd;
+use pharext\Task;
+use pharext\Tempdir;
+
+/**
+ * Clone a git repo
+ */
+class GitClone implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @var string
+ */
+ private $branch;
+
+ /**
+ * @param string $source git repo location
+ */
+ public function __construct($source, $branch = null) {
+ $this->source = $source;
+ $this->branch = $branch;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempdir
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
+ $local = new Tempdir("gitclone");
+ $cmd = new ExecCmd("git", $verbose);
+ if (strlen($this->branch)) {
+ $cmd->run(["clone", "--depth", 1, "--branch", $this->branch, $this->source, $local]);
+ } else {
+ $cmd->run(["clone", $this->source, $local]);
+ }
+ return $local;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\ExecCmd;
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Run make in the source dir
+ */
+class Make implements Task
+{
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @var array
+ */
+ private $args;
+
+ /**
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ *
+ * @param string $cwd working directory
+ * @param array $args make's arguments
+ * @param string $sudo sudo command
+ */
+ public function __construct($cwd, array $args = null, $sudo = null) {
+ $this->cwd = $cwd;
+ $this->sudo = $sudo;
+ $this->args = $args;
+ }
+
+ /**
+ *
+ * @param bool $verbose
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running make");
+ if ($this->args) {
+ foreach ($this->args as $arg) {
+ printf(" %s", $arg);
+ }
+ }
+ printf(" ...\n");
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd("make", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $args = $this->args;
+ if (!$verbose) {
+ $args = array_merge((array) $args, ["-s"]);
+ }
+ $cmd->run($args);
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+use pharext\Tempfile;
+
+class PaxFixup implements Task
+{
+ private $source;
+
+ public function __construct($source) {
+ $this->source = $source;
+ }
+
+ private function openArchive($source) {
+ $hdr = file_get_contents($source, false, null, 0, 3);
+ if ($hdr === "\x1f\x8b\x08") {
+ $fd = fopen("compress.zlib://$source", "r");
+ } elseif ($hdr === "BZh") {
+ $fd = fopen("compress.bzip2://$source", "r");
+ } else {
+ $fd = fopen($source, "r");
+ }
+ if (!is_resource($fd)) {
+ throw new Exception;
+ }
+ return $fd;
+ }
+
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fixing up a tarball with global pax header ...\n");
+ }
+ $temp = new Tempfile("paxfix");
+ stream_copy_to_stream($this->openArchive($this->source),
+ $temp->getStream(), -1, 1024);
+ $temp->closeStream();
+ return (new Extract((string) $temp))->run($verbose);
+ }
+}<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Fixup package.xml files in an extracted PECL dir
+ */
+class PeclFixup implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @param string $source source directory
+ */
+ public function __construct($source) {
+ $this->source = $source;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string sanitized source location
+ * @throws \pahrext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Sanitizing PECL dir ...\n");
+ }
+ $dirs = glob("{$this->source}/*", GLOB_ONLYDIR);
+ $files = array_diff(glob("{$this->source}/*"), $dirs);
+ $check = array_reduce($files, function($r, $v) {
+ return $v && fnmatch("package*.xml", basename($v));
+ }, true);
+
+ if (count($dirs) !== 1 || !$check) {
+ throw new Exception("Does not look like an extracted PECL dir: {$this->source}");
+ }
+
+ $dest = current($dirs);
+
+ foreach ($files as $file) {
+ if ($verbose) {
+ printf("Moving %s into %s ...\n", basename($file), basename($dest));
+ }
+ if (!rename($file, "$dest/" . basename($file))) {
+ throw new Exception;
+ }
+ }
+
+ return $dest;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\SourceDir;
+use pharext\Task;
+use pharext\Tempname;
+
+use Phar;
+
+/**
+ * Build phar
+ */
+class PharBuild implements Task
+{
+ /**
+ * @var \pharext\SourceDir
+ */
+ private $source;
+
+ /**
+ * @var string
+ */
+ private $stub;
+
+ /**
+ * @var array
+ */
+ private $meta;
+
+ /**
+ * @var bool
+ */
+ private $readonly;
+
+ /**
+ * @param SourceDir $source extension source directory
+ * @param string $stub path to phar stub
+ * @param array $meta phar meta data
+ * @param bool $readonly whether the stub has -dphar.readonly=1 set
+ */
+ public function __construct(SourceDir $source = null, $stub, array $meta = null, $readonly = true) {
+ $this->source = $source;
+ $this->stub = $stub;
+ $this->meta = $meta;
+ $this->readonly = $readonly;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempname
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ /* Phar::compress() and ::convert*() use strtok("."), ugh!
+ * so, be sure to not use any other dots in the filename
+ * except for .phar
+ */
+ $temp = new Tempname("", "-pharext.phar");
+
+ $phar = new Phar($temp);
+ $phar->startBuffering();
+
+ if ($this->meta) {
+ $phar->setMetadata($this->meta);
+ }
+ if ($this->stub) {
+ (new PharStub($phar, $this->stub))->run($verbose);
+ }
+
+ $phar->buildFromIterator((new Task\BundleGenerator)->run());
+
+ if ($this->source) {
+ if ($verbose) {
+ $bdir = $this->source->getBaseDir();
+ $blen = strlen($bdir);
+ foreach ($this->source as $index => $file) {
+ if (is_resource($file)) {
+ printf("Packaging %s ...\n", $index);
+ $phar[$index] = $file;
+ } else {
+ printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/"));
+ $phar->addFile($file, $index);
+ }
+ }
+ } else {
+ $phar->buildFromIterator($this->source, $this->source->getBaseDir());
+ }
+ }
+
+ $phar->stopBuffering();
+
+ if (!chmod($temp, fileperms($temp) | 0111)) {
+ throw new Exception;
+ }
+
+ return $temp;
+ }
+}<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use Phar;
+
+/**
+ * Clone a compressed copy of a phar
+ */
+class PharCompress implements Task
+{
+ /**
+ * @var string
+ */
+ private $file;
+
+ /**
+ * @var Phar
+ */
+ private $package;
+
+ /**
+ * @var int
+ */
+ private $encoding;
+
+ /**
+ * @var string
+ */
+ private $extension;
+
+ /**
+ * @param string $file path to the original phar
+ * @param int $encoding Phar::GZ or Phar::BZ2
+ */
+ public function __construct($file, $encoding) {
+ $this->file = $file;
+ $this->package = new Phar($file);
+ $this->encoding = $encoding;
+
+ switch ($encoding) {
+ case Phar::GZ:
+ $this->extension = ".gz";
+ break;
+ case Phar::BZ2:
+ $this->extension = ".bz2";
+ break;
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Compressing %s ...\n", basename($this->package->getPath()));
+ }
+ /* stop shebang */
+ $stub = $this->package->getStub();
+ $phar = $this->package->compress($this->encoding);
+ $phar->setStub(substr($stub, strpos($stub, "\n")+1));
+ return $this->file . $this->extension;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Rename the phar archive
+ */
+class PharRename implements Task
+{
+ /**
+ * @var string
+ */
+ private $phar;
+
+ /**
+ * @var string
+ */
+ private $dest;
+
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $phar path to phar
+ * @param string $dest destination dir
+ * @param string $name package name
+ */
+ public function __construct($phar, $dest, $name) {
+ $this->phar = $phar;
+ $this->dest = $dest;
+ $this->name = $name;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string path to renamed phar
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ $extension = substr(strstr($this->phar, "-pharext.phar"), 8);
+ $name = sprintf("%s/%s.ext%s", $this->dest, $this->name, $extension);
+
+ if ($verbose) {
+ printf("Renaming %s to %s ...\n", basename($this->phar), basename($name));
+ }
+
+ if (!rename($this->phar, $name)) {
+ throw new Exception;
+ }
+
+ return $name;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Openssl;
+use pharext\Task;
+
+use Phar;
+
+/**
+ * Sign the phar with a private key
+ */
+class PharSign implements Task
+{
+ /**
+ * @var Phar
+ */
+ private $phar;
+
+ /**
+ * @var \pharext\Openssl\PrivateKey
+ */
+ private $pkey;
+
+ /**
+ *
+ * @param mixed $phar phar instance or path to phar
+ * @param string $pkey path to private key
+ * @param string $pass password for the private key
+ */
+ public function __construct($phar, $pkey, $pass) {
+ if ($phar instanceof Phar || $phar instanceof PharData) {
+ $this->phar = $phar;
+ } else {
+ $this->phar = new Phar($phar);
+ }
+ $this->pkey = new Openssl\PrivateKey($pkey, $pass);
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Openssl\PrivateKey
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Signing %s ...\n", basename($this->phar->getPath()));
+ }
+ $this->pkey->sign($this->phar);
+ return $this->pkey;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use Phar;
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Set the phar's stub
+ */
+class PharStub implements Task
+{
+ /**
+ * @var \Phar
+ */
+ private $phar;
+
+ /**
+ * @var string
+ */
+ private $stub;
+
+ /**
+ * @param \Phar $phar
+ * @param string $stub file path to the stub
+ * @throws \pharext\Exception
+ */
+ function __construct(Phar $phar, $stub) {
+ $this->phar = $phar;
+ if (!file_exists($this->stub = $stub)) {
+ throw new Exception("File '$stub' does not exist");
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ */
+ function run($verbose = false) {
+ if ($verbose) {
+ printf("Using stub '%s'...\n", basename($this->stub));
+ }
+ $stub = preg_replace_callback('/^#include <([^>]+)>/m', function($includes) {
+ return file_get_contents($includes[1], true, null, 5);
+ }, file_get_contents($this->stub));
+ if ($this->phar->isCompressed() && substr($stub, 0, 2) === "#!") {
+ $stub = substr($stub, strpos($stub, "\n")+1);
+ }
+ $this->phar->setStub($stub);
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+
+/**
+ * Run phpize in the extension source directory
+ */
+class Phpize implements Task
+{
+ /**
+ * @var string
+ */
+ private $phpize;
+
+ /**
+ *
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @param string $cwd working directory
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP program common name, e.g. php5
+ */
+ public function __construct($cwd, $prefix = null, $common_name = "php") {
+ $this->cwd = $cwd;
+ $cmd = $common_name . "ize";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->phpize = $cmd;
+ }
+
+ /**
+ * @param bool $verbose
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running %s ...\n", $this->phpize);
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd($this->phpize, $verbose);
+ $cmd->run();
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+use pharext\Tempfile;
+
+/**
+ * Fetch a remote archive
+ */
+class StreamFetch implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @var callable
+ */
+ private $progress;
+
+ /**
+ * @param string $source remote file location
+ * @param callable $progress progress callback
+ */
+ public function __construct($source, callable $progress) {
+ $this->source = $source;
+ $this->progress = $progress;
+ }
+
+ private function createStreamContext() {
+ $progress = $this->progress;
+
+ /* avoid bytes_max bug of older PHP versions */
+ $maxbytes = 0;
+ return stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) use($progress, &$maxbytes) {
+ if ($bytes_max > $maxbytes) {
+ $maxbytes = $bytes_max;
+ }
+ switch ($notification) {
+ case STREAM_NOTIFY_CONNECT:
+ $progress(0);
+ break;
+ case STREAM_NOTIFY_PROGRESS:
+ $progress($maxbytes > 0 ? $bytes_cur/$maxbytes : .5);
+ break;
+ case STREAM_NOTIFY_COMPLETED:
+ /* this is sometimes not generated, why? */
+ $progress(1);
+ break;
+ }
+ }]);
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Task\Tempfile
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
+ $context = $this->createStreamContext();
+
+ if (!$remote = fopen($this->source, "r", false, $context)) {
+ throw new Exception;
+ }
+
+ $local = new Tempfile("remote");
+ if (!stream_copy_to_stream($remote, $local->getStream())) {
+ throw new Exception;
+ }
+ $local->closeStream();
+
+ /* STREAM_NOTIFY_COMPLETED is not generated, see above */
+ call_user_func($this->progress, 1);
+
+ return $local;
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Simple task interface
+ */
+interface Task
+{
+ public function run($verbose = false);
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Create a temporary directory
+ */
+class Tempdir extends \SplFileInfo
+{
+ /**
+ * @param string $prefix prefix to uniqid()
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix) {
+ $temp = new Tempname($prefix);
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
+ }
+ parent::__construct($temp);
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Create a new temporary file
+ */
+class Tempfile extends \SplFileInfo
+{
+ /**
+ * @var resource
+ */
+ private $handle;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix, $suffix = ".tmp") {
+ $tries = 0;
+ $omask = umask(077);
+ do {
+ $path = new Tempname($prefix, $suffix);
+ $this->handle = fopen($path, "x");
+ } while (!is_resource($this->handle) && $tries++ < 10);
+ umask($omask);
+
+ if (!is_resource($this->handle)) {
+ throw new Exception("Could not create temporary file");
+ }
+
+ parent::__construct($path);
+ }
+
+ /**
+ * Unlink the file
+ */
+ public function __destruct() {
+ if (is_file($this->getPathname())) {
+ @unlink($this->getPathname());
+ }
+ }
+
+ /**
+ * Close the stream
+ */
+ public function closeStream() {
+ fclose($this->handle);
+ }
+
+ /**
+ * Retrieve the stream resource
+ * @return resource
+ */
+ public function getStream() {
+ return $this->handle;
+ }
+}
+<?php
+
+namespace pharext;
+
+use pharext\Exception;
+
+/**
+ * A temporary file/directory name
+ */
+class Tempname
+{
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ */
+ public function __construct($prefix, $suffix = null) {
+ $temp = sys_get_temp_dir() . "/pharext-" . $this->getUser();
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception;
+ }
+ $this->name = $temp ."/". uniqid($prefix) . $suffix;
+ }
+
+ private function getUser() {
+ if (extension_loaded("posix") && function_exists("posix_getpwuid")) {
+ return posix_getpwuid(posix_getuid())["name"];
+ }
+ return trim(`whoami 2>/dev/null`)
+ ?: trim(`id -nu 2>/dev/null`)
+ ?: getenv("USER")
+ ?: get_current_user();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString() {
+ return (string) $this->name;
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use PharFileInfo;
+use SplFileInfo;
+use pharext\Exception;
+
+class Updater implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display this help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ [null, "signature", "Show pharext signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show pharext license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [0, "path", "Path to .ext.phar to update",
+ Cli\Args::REQUIRED|Cli\Args::MULTI],
+ ]);
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+
+ try {
+ foreach (["signature", "license", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ printf("\n");
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ foreach ($this->args[0] as $file) {
+ $info = new SplFileInfo($file);
+
+ while ($info->isLink()) {
+ $info = new SplFileInfo($info->getLinkTarget());
+ }
+
+ if ($info->isFile()) {
+ if (!$this->updatePackage($info)) {
+ $this->warn("Cannot upgrade pre-v3 packages\n");
+ }
+ } else {
+ $this->error("File '%s' does not exist\n", $file);
+ exit(self::EARGS);
+ }
+ }
+ }
+
+ /**
+ * Replace the pharext core in an .ext.phar package
+ * @param string $temp path to temp phar
+ * @return boolean FALSE if the package is too old (pre-v3) to upgrade
+ */
+ private function replacePharext($temp) {
+ $phar = new Phar($temp, Phar::CURRENT_AS_SELF);
+ $phar->startBuffering();
+
+ if (!$meta = $phar->getMetadata()) {
+ // don't upgrade pre-v3 packages
+ return false;
+ }
+
+ // replace current pharext files
+ $core = (new Task\BundleGenerator)->run($this->verbosity());
+ $phar->buildFromIterator($core);
+ $stub = __DIR__."/../pharext_installer.php";
+ (new Task\PharStub($phar, $stub))->run($this->verbosity());
+
+ // check dependencies
+ foreach ($phar as $info) {
+ if (fnmatch("*.ext.phar*", $info->getBasename())) {
+ $this->updatePackage($info, $phar);
+ }
+ }
+
+ $phar->stopBuffering();
+
+ $phar->setMetadata([
+ "version" => Metadata::version(),
+ "header" => Metadata::header(),
+ ] + $meta);
+
+ $this->info("Updated pharext version from '%s' to '%s'\n",
+ isset($meta["version"]) ? $meta["version"] : "(unknown)",
+ $phar->getMetadata()["version"]);
+
+ return true;
+ }
+
+ /**
+ * Update an .ext.phar package to the current pharext version
+ * @param SplFileInfo $file
+ * @param Phar $phar the parent phar containing $file as dependency
+ * @return boolean FALSE if the package is too old (pre-v3) to upgrade
+ * @throws Exception
+ */
+ private function updatePackage(SplFileInfo $file, Phar $phar = null) {
+ $this->info("Updating pharext core in '%s'...\n", basename($file));
+
+ $temp = new Tempname("update", substr(strstr($file, ".ext.phar"), 4));
+
+ if (!copy($file->getPathname(), $temp)) {
+ throw new Exception;
+ }
+ if (!chmod($temp, $file->getPerms())) {
+ throw new Exception;
+ }
+
+ if (!$this->replacePharext($temp)) {
+ return false;
+ }
+
+ if ($phar) {
+ $phar->addFile($temp, $file);
+ } elseif (!rename($temp, $file->getPathname())) {
+ throw new Exception;
+ }
+
+ return true;
+ }
+}
+#!/usr/bin/env php
+<?php
+
+/**
+ * The installer sub-stub for extension phars
+ */
+
+namespace pharext;
+
+define("PHAREXT_PHAR", __FILE__);
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+#include <pharext/Exception.php>
+#include <pharext/Tempname.php>
+#include <pharext/Tempfile.php>
+#include <pharext/Tempdir.php>
+#include <pharext/Archive.php>
+
+namespace pharext;
+
+if (extension_loaded("Phar")) {
+ \Phar::interceptFileFuncs();
+ \Phar::mapPhar();
+ $phardir = "phar://".__FILE__;
+} else {
+ $archive = new Archive(__FILE__);
+ $phardir = $archive->extract();
+}
+
+set_include_path("$phardir:". get_include_path());
+
+$installer = new Installer();
+$installer->run($argc, $argv);
+
+__HALT_COMPILER();
+#!/usr/bin/php -dphar.readonly=0
+<?php
+
+/**
+ * The packager sub-stub for bin/pharext
+ */
+
+namespace pharext;
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+set_include_path('phar://' . __FILE__ .":". get_include_path());
+
+if (!extension_loaded("Phar")) {
+ fprintf(STDERR, "ERROR: Phar extension not loaded\n\n");
+ fprintf(STDERR, "\tPlease load the phar extension in your php.ini\n".
+ "\tor rebuild PHP with the --enable-phar flag.\n\n");
+ exit(1);
+}
+
+if (ini_get("phar.readonly")) {
+ fprintf(STDERR, "ERROR: Phar is configured read-only\n\n");
+ fprintf(STDERR, "\tPlease specify phar.readonly=0 in your php.ini\n".
+ "\tor run this command with php -dphar.readonly=0\n\n");
+ exit(1);
+}
+
+\Phar::interceptFileFuncs();
+\Phar::mapPhar();
+
+$packager = new Packager();
+$packager->run($argc, $argv);
+
+__HALT_COMPILER();
+#!/usr/bin/php -dphar.readonly=0
+<?php
+
+/**
+ * The installer updater stub for extension phars
+ */
+
+namespace pharext;
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+set_include_path('phar://' . __FILE__ .":". get_include_path());
+
+if (!extension_loaded("Phar")) {
+ fprintf(STDERR, "ERROR: Phar extension not loaded\n\n");
+ fprintf(STDERR, "\tPlease load the phar extension in your php.ini\n".
+ "\tor rebuild PHP with the --enable-phar flag.\n\n");
+ exit(1);
+}
+
+if (ini_get("phar.readonly")) {
+ fprintf(STDERR, "ERROR: Phar is configured read-only\n\n");
+ fprintf(STDERR, "\tPlease specify phar.readonly=0 in your php.ini\n".
+ "\tor run this command with php -dphar.readonly=0\n\n");
+ exit(1);
+}
+
+\Phar::interceptFileFuncs();
+\Phar::mapPhar();
+
+$updater = new Updater();
+$updater->run($argc, $argv);
+
+__HALT_COMPILER();
+; see http://editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = tab
+charset = utf-8
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.json]
+indent_style = space
+indent_size = 4
+
+[package.xml]
+indent_style = space
+indent_size = 1
+
+[config.w32]
+end_of_line = crlf
+package.xml merge=touch
+php_propro.h merge=touch
+config.w32 eol=crlf
+
+# /
+*~
+/*.tgz
+/.deps
+*.lo
+*.la
+/config.[^wm]*
+/configure*
+/lib*
+/ac*.m4
+/ltmain.sh
+/install-sh
+/Make*
+/mk*
+/missing
+/.libs
+/build
+/include
+/modules
+/autom4te*
+/.dep.inc
+run-tests.php
+.libs/
+/php_propro_api.h
+/Doxyfile.bak
+!/Makefile.frag
+[submodule "travis-pecl"]
+ path = travis/pecl
+ url = https://github.com/m6w6/travis-pecl.git
+ branch = master
+# autogenerated file; do not edit
+sudo: false
+language: c
+
+addons:
+ apt:
+ packages:
+ - php5-cli
+ - php-pear
+
+env:
+ matrix:
+ - PHP=master enable_debug=no enable_maintainer_zts=no
+ - PHP=master enable_debug=yes enable_maintainer_zts=no
+ - PHP=master enable_debug=no enable_maintainer_zts=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=yes
+
+before_script:
+ - make -f travis/pecl/Makefile php
+ - make -f travis/pecl/Makefile ext PECL=propro
+
+script:
+ - make -f travis/pecl/Makefile test
+
+Michael Wallner <mike@php.net>
+Yay, now known and unresolved issues yet!
+# Contributor Code of Conduct
+
+As contributors and maintainers of this project, and in the interest of
+fostering an open and welcoming community, we pledge to respect all people who
+contribute through reporting issues, posting feature requests, updating
+documentation, submitting pull requests or patches, and other activities.
+
+We are committed to making participation in this project a harassment-free
+experience for everyone, regardless of level of experience, gender, gender
+identity and expression, sexual orientation, disability, personal appearance,
+body size, race, ethnicity, age, religion, or nationality.
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery
+* Personal attacks
+* Trolling or insulting/derogatory comments
+* Public or private harassment
+* Publishing other's private information, such as physical or electronic
+ addresses, without explicit permission
+* Other unethical or unprofessional conduct.
+
+Project maintainers have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct. By adopting this Code of Conduct, project
+maintainers commit themselves to fairly and consistently applying these
+principles to every aspect of managing this project. Project maintainers who do
+not follow or enforce the Code of Conduct may be permanently removed from the
+project team.
+
+This code of conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community.
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by opening an issue or contacting one or more of the project maintainers.
+
+This Code of Conduct is adapted from the
+[Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
+available at http://contributor-covenant.org/version/1/2/0/.
+propro
+Michael Wallner
+# Doxyfile 1.8.10
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "Property proxy API"
+PROJECT_NUMBER =
+PROJECT_BRIEF = "A facility to manage extension object properties tied to C-struct members"
+PROJECT_LOGO =
+OUTPUT_DIRECTORY =
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING = no_extension=md
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+GROUP_NESTED_COMPOUNDS = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = YES
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+HIDE_COMPOUND_REFERENCE= NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = README.md CONTRIBUTING.md php_propro.h src
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS =
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE = README.md
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT =
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES = BUGS CONTRIBUTING.md LICENSE THANKS TODO
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = NO
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = YES
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED = DOXYGEN \
+ TSRMLS_C= \
+ TSRMLS_D= \
+ TSRMLS_CC= \
+ TSRMLS_DC= \
+ PHP_PROPRO_API=
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = NO
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = YES
+CALLER_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+Copyright (c) 2013, Michael Wallner <mike@php.net>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# provide headers in builddir, so they do not end up in /usr/include/ext/propro/src
+
+PHP_PROPRO_HEADERS := $(addprefix $(PHP_PROPRO_BUILDDIR)/,$(PHP_PROPRO_HEADERS))
+
+$(PHP_PROPRO_BUILDDIR)/%.h: $(PHP_PROPRO_SRCDIR)/src/%.h
+ @cat >$@ <$<
+
+$(all_targets): propro-build-headers
+clean: propro-clean-headers
+
+.PHONY: propro-build-headers
+propro-build-headers: $(PHP_PROPRO_HEADERS)
+
+.PHONY: propro-clean-headers
+propro-clean-headers:
+ -rm -f $(PHP_PROPRO_HEADERS)
+# ext-propro
+
+[![Build Status](https://travis-ci.org/m6w6/ext-propro.svg?branch=master)](https://travis-ci.org/m6w6/ext-propro)
+
+The "Property Proxy" extension provides a fairly transparent proxy for internal
+object properties hidden in custom non-zval implementations.
+
+## Documentation
+
+See the [online markdown reference](https://mdref.m6w6.name/propro).
+
+Known issues are listed in [BUGS](./BUGS) and future ideas can be found in [TODO](./TODO).
+
+## Installing
+
+### PECL
+
+ pecl install propro
+
+### PHARext
+
+Watch out for [PECL replicates](https://replicator.pharext.org?propro)
+and pharext packages attached to [releases](./releases).
+
+### Checkout
+
+ git clone github.com:m6w6/ext-propro
+ cd ext-propro
+ /path/to/phpize
+ ./configure --with-php-config=/path/to/php-config
+ make
+ sudo make install
+
+## ChangeLog
+
+A comprehensive list of changes can be obtained from the
+[PECL website](https://pecl.php.net/package-changelog.php?package=propro).
+
+## License
+
+ext-propro is licensed under the 2-Clause-BSD license, which can be found in
+the accompanying [LICENSE](./LICENSE) file.
+
+## Contributing
+
+All forms of contribution are welcome! Please see the bundled
+[CONTRIBUTING](./CONTRIBUTING.md) note for the general principles followed.
+
+The list of past and current contributors is maintained in [THANKS](./THANKS).
+Thanks go to the following people, who have contributed to this project:
+
+Anatol Belski
+Remi Collet
+sinclude(config0.m4)
+\r
+ARG_ENABLE("propro", "for propro support", "no");\r
+\r
+if (PHP_PROPRO == "yes") {\r
+ var PHP_PROPRO_HEADERS=glob("src/*.h"), PHP_PROPRO_SOURCES=glob("src/*.c");\r
+\r
+ EXTENSION("propro", PHP_PROPRO_SOURCES);\r
+ PHP_INSTALL_HEADERS("ext/propro", "php_propro.h");\r
+ for (var i=0; i<PHP_PROPRO_HEADERS.length; ++i) {\r
+ var basename = FSO.GetFileName(PHP_PROPRO_HEADERS[i]);\r
+ copy_and_subst(PHP_PROPRO_HEADERS[i], basename, []);\r
+ PHP_INSTALL_HEADERS("ext/propro", basename);\r
+ }\r
+\r
+ AC_DEFINE("HAVE_PROPRO", 1);\r
+}\r
+PHP_ARG_ENABLE(propro, whether to enable property proxy support,
+[ --enable-propro Enable property proxy support])
+
+if test "$PHP_PROPRO" != "no"; then
+ PHP_PROPRO_SRCDIR=PHP_EXT_SRCDIR(propro)
+ PHP_PROPRO_BUILDDIR=PHP_EXT_BUILDDIR(propro)
+
+ PHP_ADD_INCLUDE($PHP_PROPRO_SRCDIR/src)
+ PHP_ADD_BUILD_DIR($PHP_PROPRO_BUILDDIR/src)
+
+ PHP_PROPRO_HEADERS=`(cd $PHP_PROPRO_SRCDIR/src && echo *.h)`
+ PHP_PROPRO_SOURCES=`(cd $PHP_PROPRO_SRCDIR && echo src/*.c)`
+
+ PHP_NEW_EXTENSION(propro, $PHP_PROPRO_SOURCES, $ext_shared)
+ PHP_INSTALL_HEADERS(ext/propro, php_propro.h $PHP_PROPRO_HEADERS)
+
+ PHP_SUBST(PHP_PROPRO_HEADERS)
+ PHP_SUBST(PHP_PROPRO_SOURCES)
+
+ PHP_SUBST(PHP_PROPRO_SRCDIR)
+ PHP_SUBST(PHP_PROPRO_BUILDDIR)
+
+ PHP_ADD_MAKEFILE_FRAGMENT
+fi
+<?xml version="1.0" encoding="UTF-8"?>
+<package
+ packagerversion="1.4.11"
+ version="2.0"
+ xmlns="http://pear.php.net/dtd/package-2.0"
+ xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>propro</name>
+ <channel>pecl.php.net</channel>
+ <summary>Property proxy</summary>
+ <description>A reusable split-off of pecl_http's property proxy API.</description>
+ <lead>
+ <name>Michael Wallner</name>
+ <user>mike</user>
+ <email>mike@php.net</email>
+ <active>yes</active>
+ </lead>
+ <date>2015-12-01</date>
+ <version>
+ <release>2.0.0RC1</release>
+ <api>2.0.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://copyfree.org/content/standard/licenses/2bsd/license.txt">BSD-2-Clause</license>
+ <notes><![CDATA[
+* Internals documentation at http://m6w6.github.io/ext-propro/master/
+* Travis support
+* PHP7 compatible version
+]]></notes>
+ <contents>
+ <dir name="/">
+ <file role="doc" name="AUTHORS"/>
+ <file role="doc" name="BUGS"/>
+ <file role="doc" name="CONTRIBUTING.md"/>
+ <file role="doc" name="CREDITS"/>
+ <file role="doc" name="LICENSE"/>
+ <file role="doc" name="README.md"/>
+ <file role="doc" name="THANKS"/>
+ <file role="doc" name="TODO"/>
+ <file role="doc" name="Doxyfile" />
+ <file role="src" name="config.m4"/>
+ <file role="src" name="config0.m4"/>
+ <file role="src" name="config.w32"/>
+ <file role="src" name="Makefile.frag"/>
+ <file role="src" name="php_propro.h"/>
+ <dir name="src">
+ <file role="src" name="php_propro_api.h"/>
+ <file role="src" name="php_propro_api.c"/>
+ </dir>
+ <dir name="scripts">
+ <file role="src" name="gen_travis_yml.php"/>
+ </dir>
+ <dir name="tests">
+ <file role="test" name="001.phpt" />
+ <file role="test" name="002.phpt" />
+ <file role="test" name="003.phpt" />
+ </dir>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>7.0.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <providesextension>propro</providesextension>
+ <extsrcrelease/>
+</package>
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: propro |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013 Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_PROPRO_H
+#define PHP_PROPRO_H
+
+extern zend_module_entry propro_module_entry;
+#define phpext_propro_ptr &propro_module_entry
+
+#define PHP_PROPRO_VERSION "2.0.0RC1"
+
+#ifdef PHP_WIN32
+# define PHP_PROPRO_API __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
+# define PHP_PROPRO_API extern __attribute__ ((visibility("default")))
+#else
+# define PHP_PROPRO_API extern
+#endif
+
+#ifdef ZTS
+# include <TSRM/TSRM.h>
+#endif
+
+#define PHP_PROPRO_PTR(zo) (void*)(((char*)(zo))-(zo)->handlers->offset)
+
+#endif /* PHP_PROPRO_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+#!/usr/bin/env php
+# autogenerated file; do not edit
+sudo: false
+language: c
+
+addons:
+ apt:
+ packages:
+ - php5-cli
+ - php-pear
+
+env:
+ matrix:
+<?php
+
+$gen = include "./travis/pecl/gen-matrix.php";
+$env = $gen([
+ "PHP" => ["master"],
+ "enable_debug",
+ "enable_maintainer_zts",
+]);
+foreach ($env as $e) {
+ printf(" - %s\n", $e);
+}
+
+?>
+
+before_script:
+ - make -f travis/pecl/Makefile php
+ - make -f travis/pecl/Makefile ext PECL=propro
+
+script:
+ - make -f travis/pecl/Makefile test
+
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: propro |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013 Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <php.h>
+#include <ext/standard/info.h>
+
+#include "php_propro_api.h"
+
+#define DEBUG_PROPRO 0
+
+static inline zval *get_referenced_zval(zval *ref)
+{
+ while (Z_ISREF_P(ref)) {
+ ref = Z_REFVAL_P(ref);
+ }
+ return ref;
+}
+
+php_property_proxy_t *php_property_proxy_init(zval *container, zend_string *member)
+{
+ php_property_proxy_t *proxy = ecalloc(1, sizeof(*proxy));
+
+ ZVAL_COPY(&proxy->container, get_referenced_zval(container));
+ proxy->member = zend_string_copy(member);
+
+ return proxy;
+}
+
+void php_property_proxy_free(php_property_proxy_t **proxy)
+{
+ if (*proxy) {
+ zval_ptr_dtor(&(*proxy)->container);
+ zend_string_release((*proxy)->member);
+ efree(*proxy);
+ *proxy = NULL;
+ }
+}
+
+static zend_class_entry *php_property_proxy_class_entry;
+static zend_object_handlers php_property_proxy_object_handlers;
+
+zend_class_entry *php_property_proxy_get_class_entry(void)
+{
+ return php_property_proxy_class_entry;
+}
+
+static inline php_property_proxy_object_t *get_propro(zval *object);
+static zval *get_parent_proxied_value(zval *object, zval *return_value);
+static zval *get_proxied_value(zval *object, zval *return_value);
+static zval *read_dimension(zval *object, zval *offset, int type, zval *return_value);
+static ZEND_RESULT_CODE cast_proxied_value(zval *object, zval *return_value, int type);
+static void write_dimension(zval *object, zval *offset, zval *value);
+static void set_proxied_value(zval *object, zval *value);
+
+#if DEBUG_PROPRO
+/* we do not really care about TS when debugging */
+static int level = 1;
+static const char space[] = " ";
+static const char *inoutstr[] = {"< return","="," > enter"};
+
+static void _walk(php_property_proxy_object_t *obj)
+{
+ if (obj) {
+ if (!Z_ISUNDEF(obj->parent)) {
+ _walk(get_propro(&obj->parent));
+ }
+ if (obj->proxy) {
+ fprintf(stderr, ".%s", obj->proxy->member->val);
+ }
+ }
+}
+
+static void debug_propro(int inout, const char *f,
+ php_property_proxy_object_t *obj, zval *offset, zval *value TSRMLS_DC)
+{
+ fprintf(stderr, "#PP %p %s %s %s ", obj, &space[sizeof(space)-level],
+ inoutstr[inout+1], f);
+
+ level += inout;
+
+ _walk(obj);
+
+ if (*f++=='d'
+ && *f++=='i'
+ && *f++=='m'
+ ) {
+ char *offset_str = "[]";
+ zval *o = offset;
+
+ if (o) {
+ convert_to_string_ex(o);
+ offset_str = Z_STRVAL_P(o);
+ }
+
+ fprintf(stderr, ".%s", offset_str);
+
+ if (o && o != offset) {
+ zval_ptr_dtor(o);
+ }
+ }
+ if (value && !Z_ISUNDEF_P(value)) {
+ const char *t[] = {
+ "UNDEF",
+ "NULL",
+ "FALSE",
+ "TRUE",
+ "int",
+ "float",
+ "string",
+ "Array",
+ "Object",
+ "resource",
+ "reference",
+ "constant",
+ "constant AST",
+ "_BOOL",
+ "callable",
+ "indirect",
+ "---",
+ "pointer"
+ };
+ fprintf(stderr, " = (%s) ", t[Z_TYPE_P(value)&0xf]);
+ if (!Z_ISUNDEF_P(value) && Z_TYPE_P(value) != IS_INDIRECT) {
+ zend_print_flat_zval_r(value TSRMLS_CC);
+ }
+ }
+
+ fprintf(stderr, "\n");
+}
+#else
+#define debug_propro(l, f, obj, off, val)
+#endif
+
+php_property_proxy_object_t *php_property_proxy_object_new_ex(
+ zend_class_entry *ce, php_property_proxy_t *proxy)
+{
+ php_property_proxy_object_t *o;
+
+ if (!ce) {
+ ce = php_property_proxy_class_entry;
+ }
+
+ o = ecalloc(1, sizeof(*o) + sizeof(zval) * (ce->default_properties_count - 1));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
+
+ o->proxy = proxy;
+ o->zo.handlers = &php_property_proxy_object_handlers;
+
+ debug_propro(0, "init", o, NULL, NULL);
+
+ return o;
+}
+
+zend_object *php_property_proxy_object_new(zend_class_entry *ce)
+{
+ return &php_property_proxy_object_new_ex(ce, NULL)->zo;
+}
+
+static void destroy_obj(zend_object *object)
+{
+ php_property_proxy_object_t *o = PHP_PROPRO_PTR(object);
+
+ debug_propro(0, "dtor", o, NULL, NULL);
+
+ if (o->proxy) {
+ php_property_proxy_free(&o->proxy);
+ }
+ if (!Z_ISUNDEF(o->parent)) {
+ zval_ptr_dtor(&o->parent);
+ ZVAL_UNDEF(&o->parent);
+ }
+ zend_object_std_dtor(object);
+}
+
+static inline php_property_proxy_object_t *get_propro(zval *object)
+{
+ object = get_referenced_zval(object);
+ switch (Z_TYPE_P(object)) {
+ case IS_OBJECT:
+ break;
+
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+ return PHP_PROPRO_PTR(Z_OBJ_P(object));
+}
+
+static inline zend_bool got_value(zval *container, zval *value)
+{
+ zval identical;
+
+ if (!Z_ISUNDEF_P(value)) {
+ if (SUCCESS == is_identical_function(&identical, value, container)) {
+ if (Z_TYPE(identical) != IS_TRUE) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static zval *get_parent_proxied_value(zval *object, zval *return_value)
+{
+ php_property_proxy_object_t *obj;
+
+ obj = get_propro(object);
+ debug_propro(1, "parent_get", obj, NULL, NULL);
+
+ if (obj->proxy) {
+ if (!Z_ISUNDEF(obj->parent)) {
+ get_proxied_value(&obj->parent, return_value);
+ }
+ }
+
+ debug_propro(-1, "parent_get", obj, NULL, return_value);
+
+ return return_value;
+}
+
+static zval *get_proxied_value(zval *object, zval *return_value)
+{
+ zval *hash_value, *ref, prop_tmp;
+ php_property_proxy_object_t *obj;
+
+ obj = get_propro(object);
+ debug_propro(1, "get", obj, NULL, NULL);
+
+ if (obj->proxy) {
+ if (!Z_ISUNDEF(obj->parent)) {
+ zval parent_value;
+
+ ZVAL_UNDEF(&parent_value);
+ get_parent_proxied_value(object, &parent_value);
+
+ if (got_value(&obj->proxy->container, &parent_value)) {
+ zval_ptr_dtor(&obj->proxy->container);
+ ZVAL_COPY(&obj->proxy->container, &parent_value);
+ }
+ }
+
+ ref = get_referenced_zval(&obj->proxy->container);
+
+ switch (Z_TYPE_P(ref)) {
+ case IS_OBJECT:
+ RETVAL_ZVAL(zend_read_property(Z_OBJCE_P(ref), ref,
+ obj->proxy->member->val, obj->proxy->member->len, 0, &prop_tmp),
+ 0, 0);
+ break;
+
+ case IS_ARRAY:
+ hash_value = zend_symtable_find(Z_ARRVAL_P(ref), obj->proxy->member);
+
+ if (hash_value) {
+ RETVAL_ZVAL(hash_value, 0, 0);
+ }
+ break;
+ }
+ }
+
+ debug_propro(-1, "get", obj, NULL, return_value);
+
+ return return_value;
+}
+
+static ZEND_RESULT_CODE cast_proxied_value(zval *object, zval *return_value,
+ int type)
+{
+ get_proxied_value(object, return_value);
+
+ debug_propro(0, "cast", get_propro(object), NULL, return_value);
+
+ if (!Z_ISUNDEF_P(return_value)) {
+ convert_to_explicit_type_ex(return_value, type);
+ return SUCCESS;
+ }
+
+ return FAILURE;
+}
+
+static void set_proxied_value(zval *object, zval *value)
+{
+ php_property_proxy_object_t *obj;
+ zval *ref;
+
+ obj = get_propro(object);
+ debug_propro(1, "set", obj, NULL, value TSRMLS_CC);
+
+ if (obj->proxy) {
+ if (!Z_ISUNDEF(obj->parent)) {
+ zval parent_value;
+
+ ZVAL_UNDEF(&parent_value);
+ get_parent_proxied_value(object, &parent_value);
+
+ if (got_value(&obj->proxy->container, &parent_value)) {
+ zval_ptr_dtor(&obj->proxy->container);
+ ZVAL_COPY(&obj->proxy->container, &parent_value);
+ }
+ }
+
+ ref = get_referenced_zval(&obj->proxy->container);
+
+ switch (Z_TYPE_P(ref)) {
+ case IS_OBJECT:
+ zend_update_property(Z_OBJCE_P(ref), ref, obj->proxy->member->val,
+ obj->proxy->member->len, value);
+ break;
+
+ default:
+ convert_to_array(ref);
+ /* no break */
+
+ case IS_ARRAY:
+ Z_TRY_ADDREF_P(value);
+ zend_symtable_update(Z_ARRVAL_P(ref), obj->proxy->member, value);
+ break;
+ }
+
+ if (!Z_ISUNDEF(obj->parent)) {
+ set_proxied_value(&obj->parent, &obj->proxy->container);
+ }
+ }
+
+ debug_propro(-1, "set", obj, NULL, NULL);
+}
+
+static zval *read_dimension(zval *object, zval *offset, int type, zval *return_value)
+{
+ zval proxied_value;
+ zend_string *member = offset ? zval_get_string(offset) : NULL;
+
+ debug_propro(1, type == BP_VAR_R ? "dim_read" : "dim_read_ref",
+ get_propro(object), offset, NULL);
+
+ ZVAL_UNDEF(&proxied_value);
+ get_proxied_value(object, &proxied_value);
+
+ if (BP_VAR_R == type && member && !Z_ISUNDEF(proxied_value)) {
+ if (Z_TYPE(proxied_value) == IS_ARRAY) {
+ zval *hash_value = zend_symtable_find(Z_ARRVAL(proxied_value),
+ member);
+
+ if (hash_value) {
+ RETVAL_ZVAL(hash_value, 1, 0);
+ }
+ }
+ } else {
+ php_property_proxy_t *proxy;
+ php_property_proxy_object_t *proxy_obj;
+
+ if (!Z_ISUNDEF(proxied_value)) {
+ convert_to_array(&proxied_value);
+ Z_ADDREF(proxied_value);
+ } else {
+ array_init(&proxied_value);
+ set_proxied_value(object, &proxied_value);
+ }
+
+ if (!member) {
+ member = zend_long_to_str(zend_hash_next_free_element(
+ Z_ARRVAL(proxied_value)));
+ }
+
+ proxy = php_property_proxy_init(&proxied_value, member);
+ zval_ptr_dtor(&proxied_value);
+
+ proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
+ ZVAL_COPY(&proxy_obj->parent, object);
+ RETVAL_OBJ(&proxy_obj->zo);
+ }
+
+ if (member) {
+ zend_string_release(member);
+ }
+
+ debug_propro(-1, type == BP_VAR_R ? "dim_read" : "dim_read_ref",
+ get_propro(object), offset, return_value);
+
+ return return_value;
+}
+
+static int has_dimension(zval *object, zval *offset, int check_empty)
+{
+ zval proxied_value;
+ int exists = 0;
+
+ debug_propro(1, "dim_exists", get_propro(object), offset, NULL);
+
+ ZVAL_UNDEF(&proxied_value);
+ get_proxied_value(object, &proxied_value);
+ if (Z_ISUNDEF(proxied_value)) {
+ exists = 0;
+ } else {
+ zend_string *zs = zval_get_string(offset);
+
+ if (Z_TYPE(proxied_value) == IS_ARRAY) {
+ zval *zentry = zend_symtable_find(Z_ARRVAL(proxied_value), zs);
+
+ if (!zentry) {
+ exists = 0;
+ } else {
+ if (check_empty) {
+ exists = !Z_ISNULL_P(zentry);
+ } else {
+ exists = 1;
+ }
+ }
+ }
+
+ zend_string_release(zs);
+ }
+
+ debug_propro(-1, "dim_exists", get_propro(object), offset, NULL);
+
+ return exists;
+}
+
+static void write_dimension(zval *object, zval *offset, zval *value)
+{
+ zval proxied_value;
+
+ debug_propro(1, "dim_write", get_propro(object), offset, value);
+
+ ZVAL_UNDEF(&proxied_value);
+ get_proxied_value(object, &proxied_value);
+
+ if (!Z_ISUNDEF(proxied_value)) {
+ if (Z_TYPE(proxied_value) == IS_ARRAY) {
+ Z_ADDREF(proxied_value);
+ } else {
+ convert_to_array(&proxied_value);
+ }
+ } else {
+ array_init(&proxied_value);
+ }
+
+ SEPARATE_ZVAL(value);
+ Z_TRY_ADDREF_P(value);
+
+ if (offset) {
+ zend_string *zs = zval_get_string(offset);
+ zend_symtable_update(Z_ARRVAL(proxied_value), zs, value);
+ zend_string_release(zs);
+ } else {
+ zend_hash_next_index_insert(Z_ARRVAL(proxied_value), value);
+ }
+
+ set_proxied_value(object, &proxied_value);
+
+ debug_propro(-1, "dim_write", get_propro(object), offset, &proxied_value);
+
+ zval_ptr_dtor(&proxied_value);
+}
+
+static void unset_dimension(zval *object, zval *offset)
+{
+ zval proxied_value;
+
+ debug_propro(1, "dim_unset", get_propro(object), offset, NULL);
+
+ ZVAL_UNDEF(&proxied_value);
+ get_proxied_value(object, &proxied_value);
+
+ if (Z_TYPE(proxied_value) == IS_ARRAY) {
+ zval *o = offset;
+ ZEND_RESULT_CODE rv;
+
+ convert_to_string_ex(o);
+ rv = zend_symtable_del(Z_ARRVAL(proxied_value), Z_STR_P(o));
+ if (SUCCESS == rv) {
+ set_proxied_value(object, &proxied_value);
+ }
+
+ if (o != offset) {
+ zval_ptr_dtor(o);
+ }
+ }
+
+ debug_propro(-1, "dim_unset", get_propro(object), offset, &proxied_value);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_propro_construct, 0, 0, 2)
+ ZEND_ARG_INFO(1, object)
+ ZEND_ARG_INFO(0, member)
+ ZEND_ARG_OBJ_INFO(0, parent, php\\PropertyProxy, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(propro, __construct) {
+ zend_error_handling zeh;
+ zval *container, *parent = NULL;
+ zend_string *member;
+
+ zend_replace_error_handling(EH_THROW, NULL, &zeh);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "zS|O!",
+ &container, &member, &parent,
+ php_property_proxy_class_entry)) {
+ php_property_proxy_object_t *obj;
+ zval *ref = get_referenced_zval(container);
+
+ switch (Z_TYPE_P(ref)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ break;
+ default:
+ convert_to_array(ref);
+ }
+ obj = get_propro(getThis());
+ obj->proxy = php_property_proxy_init(container, member);
+ if (parent) {
+ ZVAL_COPY(&obj->parent, parent);
+ }
+ }
+ zend_restore_error_handling(&zeh);
+}
+
+static const zend_function_entry php_property_proxy_method_entry[] = {
+ PHP_ME(propro, __construct, ai_propro_construct, ZEND_ACC_PUBLIC)
+ {0}
+};
+
+static PHP_MINIT_FUNCTION(propro)
+{
+ zend_class_entry ce = {0};
+
+ INIT_NS_CLASS_ENTRY(ce, "php", "PropertyProxy",
+ php_property_proxy_method_entry);
+ php_property_proxy_class_entry = zend_register_internal_class(&ce);
+ php_property_proxy_class_entry->create_object = php_property_proxy_object_new;
+ php_property_proxy_class_entry->ce_flags |= ZEND_ACC_FINAL;
+
+ memcpy(&php_property_proxy_object_handlers, zend_get_std_object_handlers(),
+ sizeof(zend_object_handlers));
+ php_property_proxy_object_handlers.offset = XtOffsetOf(php_property_proxy_object_t, zo);
+ php_property_proxy_object_handlers.free_obj = destroy_obj;
+ php_property_proxy_object_handlers.set = set_proxied_value;
+ php_property_proxy_object_handlers.get = get_proxied_value;
+ php_property_proxy_object_handlers.cast_object = cast_proxied_value;
+ php_property_proxy_object_handlers.read_dimension = read_dimension;
+ php_property_proxy_object_handlers.write_dimension = write_dimension;
+ php_property_proxy_object_handlers.has_dimension = has_dimension;
+ php_property_proxy_object_handlers.unset_dimension = unset_dimension;
+
+ return SUCCESS;
+}
+
+PHP_MINFO_FUNCTION(propro)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2, "Property proxy support", "enabled");
+ php_info_print_table_row(2, "Extension version", PHP_PROPRO_VERSION);
+ php_info_print_table_end();
+}
+
+static const zend_function_entry propro_functions[] = {
+ {0}
+};
+
+zend_module_entry propro_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "propro",
+ propro_functions,
+ PHP_MINIT(propro),
+ NULL,
+ NULL,
+ NULL,
+ PHP_MINFO(propro),
+ PHP_PROPRO_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+
+#ifdef COMPILE_DL_PROPRO
+ZEND_GET_MODULE(propro)
+#endif
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: propro |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013 Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_PROPRO_API_H
+#define PHP_PROPRO_API_H
+
+#include "php_propro.h"
+
+/**
+ * The internal property proxy.
+ *
+ * Container for the object/array holding the proxied property.
+ */
+struct php_property_proxy {
+ /** The container holding the property */
+ zval container;
+ /** The name of the proxied property */
+ zend_string *member;
+};
+typedef struct php_property_proxy php_property_proxy_t;
+
+/**
+ * The userland object.
+ *
+ * Return an object instance of php\\PropertyProxy to make your C-struct
+ * member accessible by reference from PHP userland.
+ *
+ * Example:
+ * \code{.c}
+ * static zval *my_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+ * {
+ * zval *return_value;
+ * zend_string *member_name = zval_get_string(member);
+ * my_prophandler_t *handler = my_get_prophandler(member_name);
+ *
+ * if (!handler || type == BP_VAR_R || type == BP_VAR_IS) {
+ * return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
+ *
+ * if (handler) {
+ * handler->read(object, tmp);
+ *
+ * zval_ptr_dtor(return_value);
+ * ZVAL_COPY_VALUE(return_value, tmp);
+ * }
+ * } else {
+ * return_value = php_property_proxy_zval(object, member_name);
+ * }
+ *
+ * zend_string_release(member_name);
+ *
+ * return return_value;
+ * }
+ * \endcode
+ */
+struct php_property_proxy_object {
+ /** The actual property proxy */
+ php_property_proxy_t *proxy;
+ /** Any parent property proxy object */
+ zval parent;
+ /** The std zend_object */
+ zend_object zo;
+};
+typedef struct php_property_proxy_object php_property_proxy_object_t;
+
+/**
+ * Create a property proxy
+ *
+ * The property proxy will forward reads and writes to itself to the
+ * proxied property with name \a member_str of \a container.
+ *
+ * @param container the container holding the property
+ * @param member the name of the proxied property
+ * @return a new property proxy
+ */
+PHP_PROPRO_API php_property_proxy_t *php_property_proxy_init(zval *container,
+ zend_string *member);
+
+/**
+ * Destroy and free a property proxy.
+ *
+ * The destruction of the property proxy object calls this.
+ *
+ * @param proxy a pointer to the allocated property proxy
+ */
+PHP_PROPRO_API void php_property_proxy_free(php_property_proxy_t **proxy);
+
+/**
+ * Get the zend_class_entry of php\\PropertyProxy
+ * @return the class entry pointer
+ */
+PHP_PROPRO_API zend_class_entry *php_property_proxy_get_class_entry(void);
+
+/**
+ * Instantiate a new php\\PropertyProxy
+ * @param ce the property proxy or derived class entry
+ * @return the zend object
+ */
+PHP_PROPRO_API zend_object *php_property_proxy_object_new(zend_class_entry *ce);
+
+/**
+ * Instantiate a new php\\PropertyProxy with \a proxy
+ * @param ce the property proxy or derived class entry
+ * @param proxy the internal property proxy
+ * @return the property proxy
+ */
+PHP_PROPRO_API php_property_proxy_object_t *php_property_proxy_object_new_ex(
+ zend_class_entry *ce, php_property_proxy_t *proxy);
+
+#endif /* PHP_PROPRO_API_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+--TEST--
+property proxy
+--SKIPIF--
+<?php if (!extension_loaded("propro")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class c {
+ private $prop;
+ private $anon;
+ function __get($p) {
+ return new php\PropertyProxy($this, $p);
+ }
+}
+
+$c = new c;
+
+$p = $c->prop;
+$a = $c->anon;
+
+var_dump($c);
+
+echo "set\n";
+$a = 123;
+echo "get\n";
+echo $a,"\n";
+
+$p["foo"] = 123;
+$p["bar"]["baz"]["a"]["b"]=987;
+
+var_dump($c);
+
+?>
+DONE
+--EXPECTF--
+Test
+object(c)#%d (2) {
+ ["prop":"c":private]=>
+ NULL
+ ["anon":"c":private]=>
+ NULL
+}
+set
+get
+123
+object(c)#%d (2) {
+ ["prop":"c":private]=>
+ array(2) {
+ ["foo"]=>
+ int(123)
+ ["bar"]=>
+ array(1) {
+ ["baz"]=>
+ array(1) {
+ ["a"]=>
+ array(1) {
+ ["b"]=>
+ int(987)
+ }
+ }
+ }
+ }
+ ["anon":"c":private]=>
+ int(123)
+}
+DONE
+--TEST--
+property proxy
+--SKIPIF--
+<?php if (!extension_loaded("propro")) print "skip"; ?>
+--FILE--
+<?php
+
+echo "Test\n";
+
+class c {
+ private $storage = array();
+ function __get($p) {
+ return new php\PropertyProxy($this->storage, $p);
+ }
+ function __set($p, $v) {
+ $this->storage[$p] = $v;
+ }
+}
+
+$c = new c;
+$c->data["foo"] = 1;
+var_dump(
+ isset($c->data["foo"]),
+ isset($c->data["bar"])
+);
+
+var_dump($c);
+
+$c->data[] = 1;
+$c->data[] = 2;
+$c->data[] = 3;
+$c->data["bar"][] = 123;
+$c->data["bar"][] = 456;
+
+var_dump($c);
+unset($c->data["bar"][0]);
+
+var_dump($c);
+
+?>
+DONE
+--EXPECTF--
+Test
+bool(true)
+bool(false)
+object(c)#%d (1) {
+ ["storage":"c":private]=>
+ array(1) {
+ ["data"]=>
+ array(1) {
+ ["foo"]=>
+ int(1)
+ }
+ }
+}
+object(c)#%d (1) {
+ ["storage":"c":private]=>
+ array(1) {
+ ["data"]=>
+ array(5) {
+ ["foo"]=>
+ int(1)
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ ["bar"]=>
+ array(2) {
+ [0]=>
+ int(123)
+ [1]=>
+ int(456)
+ }
+ }
+ }
+}
+object(c)#%d (1) {
+ ["storage":"c":private]=>
+ array(1) {
+ ["data"]=>
+ array(5) {
+ ["foo"]=>
+ int(1)
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ ["bar"]=>
+ array(1) {
+ [1]=>
+ int(456)
+ }
+ }
+ }
+}
+DONE
+--TEST--
+property proxy
+--SKIPIF--
+<?php
+extension_loaded("propro") || print "skip";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+class t {
+ private $ref;
+ function __get($v) {
+ return new php\PropertyProxy($this, $v);
+ }
+}
+
+$t = new t;
+$r = &$t->ref;
+$r = 1;
+var_dump($t);
+$t->ref[] = 2;
+var_dump($t);
+?>
+===DONE===
+--EXPECTF--
+Test
+object(t)#%d (1) {
+ ["ref":"t":private]=>
+ int(1)
+}
+object(t)#%d (1) {
+ ["ref":"t":private]=>
+ array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ }
+}
+===DONE===EJ¶ÒddgR¨Æö¤\r%÷ÃIdÀ¥\ 2\0\0\0GBMB
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env php
+<?php
+
+/**
+ * The installer sub-stub for extension phars
+ */
+
+namespace pharext;
+
+define("PHAREXT_PHAR", __FILE__);
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+
+
+namespace pharext;
+
+class Exception extends \Exception
+{
+ public function __construct($message = null, $code = 0, $previous = null) {
+ if (!isset($message)) {
+ $last_error = error_get_last();
+ $message = $last_error["message"];
+ if (!$code) {
+ $code = $last_error["type"];
+ }
+ }
+ parent::__construct($message, $code, $previous);
+ }
+}
+
+
+
+namespace pharext;
+
+use pharext\Exception;
+
+/**
+ * A temporary file/directory name
+ */
+class Tempname
+{
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ */
+ public function __construct($prefix, $suffix = null) {
+ $temp = sys_get_temp_dir() . "/pharext-" . $this->getUser();
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception;
+ }
+ $this->name = $temp ."/". uniqid($prefix) . $suffix;
+ }
+
+ private function getUser() {
+ if (extension_loaded("posix") && function_exists("posix_getpwuid")) {
+ return posix_getpwuid(posix_getuid())["name"];
+ }
+ return trim(`whoami 2>/dev/null`)
+ ?: trim(`id -nu 2>/dev/null`)
+ ?: getenv("USER")
+ ?: get_current_user();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString() {
+ return (string) $this->name;
+ }
+}
+
+
+
+namespace pharext;
+
+/**
+ * Create a new temporary file
+ */
+class Tempfile extends \SplFileInfo
+{
+ /**
+ * @var resource
+ */
+ private $handle;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix, $suffix = ".tmp") {
+ $tries = 0;
+ $omask = umask(077);
+ do {
+ $path = new Tempname($prefix, $suffix);
+ $this->handle = fopen($path, "x");
+ } while (!is_resource($this->handle) && $tries++ < 10);
+ umask($omask);
+
+ if (!is_resource($this->handle)) {
+ throw new Exception("Could not create temporary file");
+ }
+
+ parent::__construct($path);
+ }
+
+ /**
+ * Unlink the file
+ */
+ public function __destruct() {
+ if (is_file($this->getPathname())) {
+ @unlink($this->getPathname());
+ }
+ }
+
+ /**
+ * Close the stream
+ */
+ public function closeStream() {
+ fclose($this->handle);
+ }
+
+ /**
+ * Retrieve the stream resource
+ * @return resource
+ */
+ public function getStream() {
+ return $this->handle;
+ }
+}
+
+
+
+namespace pharext;
+
+/**
+ * Create a temporary directory
+ */
+class Tempdir extends \SplFileInfo
+{
+ /**
+ * @param string $prefix prefix to uniqid()
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix) {
+ $temp = new Tempname($prefix);
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
+ }
+ parent::__construct($temp);
+ }
+}
+
+
+
+namespace pharext;
+
+use ArrayAccess;
+use IteratorAggregate;
+use RecursiveDirectoryIterator;
+use SplFileInfo;
+
+use pharext\Exception;
+
+class Archive implements ArrayAccess, IteratorAggregate
+{
+ const HALT_COMPILER = "\137\137\150\141\154\164\137\143\157\155\160\151\154\145\162\50\51\73";
+ const SIGNED = 0x10000;
+ const SIG_MD5 = 0x0001;
+ const SIG_SHA1 = 0x0002;
+ const SIG_SHA256 = 0x0003;
+ const SIG_SHA512 = 0x0004;
+ const SIG_OPENSSL= 0x0010;
+
+ private static $siglen = [
+ self::SIG_MD5 => 16,
+ self::SIG_SHA1 => 20,
+ self::SIG_SHA256 => 32,
+ self::SIG_SHA512 => 64,
+ self::SIG_OPENSSL=> 0
+ ];
+
+ private static $sigalg = [
+ self::SIG_MD5 => "md5",
+ self::SIG_SHA1 => "sha1",
+ self::SIG_SHA256 => "sha256",
+ self::SIG_SHA512 => "sha512",
+ self::SIG_OPENSSL=> "openssl"
+ ];
+
+ private static $sigtyp = [
+ self::SIG_MD5 => "MD5",
+ self::SIG_SHA1 => "SHA-1",
+ self::SIG_SHA256 => "SHA-256",
+ self::SIG_SHA512 => "SHA-512",
+ self::SIG_OPENSSL=> "OpenSSL",
+ ];
+
+ const PERM_FILE_MASK = 0x01ff;
+ const COMP_FILE_MASK = 0xf000;
+ const COMP_GZ_FILE = 0x1000;
+ const COMP_BZ2_FILE = 0x2000;
+
+ const COMP_PHAR_MASK= 0xf000;
+ const COMP_PHAR_GZ = 0x1000;
+ const COMP_PHAR_BZ2 = 0x2000;
+
+ private $file;
+ private $fd;
+ private $stub;
+ private $manifest;
+ private $signature;
+ private $extracted;
+
+ function __construct($file = null) {
+ if (strlen($file)) {
+ $this->open($file);
+ }
+ }
+
+ function open($file) {
+ if (!$this->fd = @fopen($file, "r")) {
+ throw new Exception;
+ }
+ $this->file = $file;
+ $this->stub = $this->readStub();
+ $this->manifest = $this->readManifest();
+ $this->signature = $this->readSignature();
+ }
+
+ function getIterator() {
+ return new RecursiveDirectoryIterator($this->extract());
+ }
+
+ function extract() {
+ return $this->extracted ?: $this->extractTo(new Tempdir("archive"));
+ }
+
+ function extractTo($dir) {
+ if ((string) $this->extracted == (string) $dir) {
+ return $this->extracted;
+ }
+ foreach ($this->manifest["entries"] as $file => $entry) {
+ fseek($this->fd, $this->manifest["offset"]+$entry["offset"]);
+ $path = "$dir/$file";
+ $copy = stream_copy_to_stream($this->fd, $this->outFd($path, $entry["flags"]), $entry["csize"]);
+ if ($entry["osize"] != $copy) {
+ throw new Exception("Copied '$copy' of '$file', expected '{$entry["osize"]}' from '{$entry["csize"]}");
+ }
+
+ $crc = hexdec(hash_file("crc32b", $path));
+ if ($crc !== $entry["crc32"]) {
+ throw new Exception("CRC mismatch of '$file': '$crc' != '{$entry["crc32"]}");
+ }
+
+ chmod($path, $entry["flags"] & self::PERM_FILE_MASK);
+ touch($path, $entry["stamp"]);
+ }
+ return $this->extracted = $dir;
+ }
+
+ function offsetExists($o) {
+ return isset($this->entries[$o]);
+ }
+
+ function offsetGet($o) {
+ $this->extract();
+ return new SplFileInfo($this->extracted."/$o");
+ }
+
+ function offsetSet($o, $v) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function offsetUnset($o) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function getSignature() {
+ /* compatible with Phar::getSignature() */
+ return [
+ "hash_type" => self::$sigtyp[$this->signature["flags"]],
+ "hash" => strtoupper(bin2hex($this->signature["hash"])),
+ ];
+ }
+
+ function getPath() {
+ /* compatible with Phar::getPath() */
+ return new SplFileInfo($this->file);
+ }
+
+ function getMetadata($key = null) {
+ if (isset($key)) {
+ return $this->manifest["meta"][$key];
+ }
+ return $this->manifest["meta"];
+ }
+
+ private function outFd($path, $flags) {
+ $dirn = dirname($path);
+ if (!is_dir($dirn) && !@mkdir($dirn, 0777, true)) {
+ throw new Exception;
+ }
+ if (!$fd = @fopen($path, "w")) {
+ throw new Exception;
+ }
+ switch ($flags & self::COMP_FILE_MASK) {
+ case self::COMP_GZ_FILE:
+ if (!@stream_filter_append($fd, "zlib.inflate")) {
+ throw new Exception;
+ }
+ break;
+ case self::COMP_BZ2_FILE:
+ if (!@stream_filter_append($fd, "bz2.decompress")) {
+ throw new Exception;
+ }
+ break;
+ }
+
+ }
+ private function readVerified($fd, $len) {
+ if ($len != strlen($data = fread($fd, $len))) {
+ throw new Exception("Unexpected EOF");
+ }
+ return $data;
+ }
+
+ private function readFormat($format, $fd, $len) {
+ if (false === ($data = @unpack($format, $this->readVerified($fd, $len)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+
+ private function readSingleFormat($format, $fd, $len) {
+ return current($this->readFormat($format, $fd, $len));
+ }
+
+ private function readStringBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ return $this->readVerified($this->fd, $length);
+ }
+ return null;
+ }
+
+ private function readSerializedBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ if (false === ($data = unserialize($this->readVerified($fd, $length)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+ return null;
+ }
+
+ private function readStub() {
+ $stub = "";
+ while (!feof($this->fd)) {
+ $line = fgets($this->fd);
+ $stub .= $line;
+ if (false !== stripos($line, self::HALT_COMPILER)) {
+ /* check for '?>' on a separate line */
+ if ('?>' === $this->readVerified($this->fd, 2)) {
+ $stub .= '?>' . fgets($this->fd);
+ } else {
+ fseek($this->fd, -2, SEEK_CUR);
+ }
+ break;
+ }
+ }
+ return $stub;
+ }
+
+ private function readManifest() {
+ $current = ftell($this->fd);
+ $header = $this->readFormat("Vlen/Vnum/napi/Vflags", $this->fd, 14);
+ $alias = $this->readStringBinary($this->fd);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries = [];
+ for ($i = 0; $i < $header["num"]; ++$i) {
+ $this->readEntry($entries);
+ }
+ $offset = ftell($this->fd);
+ if (($length = $offset - $current - 4) != $header["len"]) {
+ throw new Exception("Manifest length read was '$length', expected '{$header["len"]}'");
+ }
+ return $header + compact("alias", "meta", "entries", "offset");
+ }
+
+ private function readEntry(array &$entries) {
+ if (!count($entries)) {
+ $offset = 0;
+ } else {
+ $last = end($entries);
+ $offset = $last["offset"] + $last["csize"];
+ }
+ $file = $this->readStringBinary($this->fd);
+ if (!strlen($file)) {
+ throw new Exception("Empty file name encountered at offset '$offset'");
+ }
+ $header = $this->readFormat("Vosize/Vstamp/Vcsize/Vcrc32/Vflags", $this->fd, 20);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries[$file] = $header + compact("meta", "offset");
+ }
+
+ private function readSignature() {
+ fseek($this->fd, -8, SEEK_END);
+ $sig = $this->readFormat("Vflags/Z4magic", $this->fd, 8);
+ $end = ftell($this->fd);
+
+ if ($sig["magic"] !== "GBMB") {
+ throw new Exception("Invalid signature magic value '{$sig["magic"]}");
+ }
+
+ switch ($sig["flags"]) {
+ case self::SIG_OPENSSL:
+ fseek($this->fd, -12, SEEK_END);
+ if (($hash = $this->readSingleFormat("V", $this->fd, 4))) {
+ $offset = 4 + $hash;
+ fseek($this->fd, -$offset, SEEK_CUR);
+ $hash = $this->readVerified($this->fd, $hash);
+ fseek($this->fd, 0, SEEK_SET);
+ $valid = openssl_verify($this->readVerified($this->fd, $end - $offset - 8),
+ $hash, @file_get_contents($this->file.".pubkey")) === 1;
+ }
+ break;
+
+ case self::SIG_MD5:
+ case self::SIG_SHA1:
+ case self::SIG_SHA256:
+ case self::SIG_SHA512:
+ $offset = 8 + self::$siglen[$sig["flags"]];
+ fseek($this->fd, -$offset, SEEK_END);
+ $hash = $this->readVerified($this->fd, self::$siglen[$sig["flags"]]);
+ $algo = hash_init(self::$sigalg[$sig["flags"]]);
+ fseek($this->fd, 0, SEEK_SET);
+ hash_update_stream($algo, $this->fd, $end - $offset);
+ $valid = hash_final($algo, true) === $hash;
+ break;
+
+ default:
+ throw new Exception("Invalid signature type '{$sig["flags"]}");
+ }
+
+ return $sig + compact("hash", "valid");
+ }
+}
+
+
+namespace pharext;
+
+if (extension_loaded("Phar")) {
+ \Phar::interceptFileFuncs();
+ \Phar::mapPhar();
+ $phardir = "phar://".__FILE__;
+} else {
+ $archive = new Archive(__FILE__);
+ $phardir = $archive->extract();
+}
+
+set_include_path("$phardir:". get_include_path());
+
+$installer = new Installer();
+$installer->run($argc, $argv);
+
+__HALT_COMPILER(); ?>\r
+D\13\0\0H\0\0\0\11\0\0\0\ 1\0\0\0\0\0)\ 6\0\0a:7:{s:7:"version";s:5:"4.1.1";s:6:"header";s:49:"pharext v4.1.1 (c) Michael Wallner <mike@php.net>";s:4:"date";s:10:"2015-12-03";s:4:"name";s:5:"raphf";s:7:"release";s:6:"master";s:7:"license";s:1345:"Copyright (c) 2013, Michael Wallner <mike@php.net>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+";s:4:"type";s:9:"extension";}\13\0\0\0pharext/Archive.php\18\1e\0\0x9`V\18\1e\0\04-ÔI¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Cli/Args/Help.phpÉ\f\0\0x9`VÉ\f\0\0gX'\1f¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Cli/Args.php\ f\1d\0\0x9`V\ f\1d\0\0?n\9dö¶\ 1\0\0\0\0\0\0\17\0\0\0pharext/Cli/Command.phpk \0\0x9`Vk \0\0d\84aê¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/Command.php\12\ 4\0\0x9`V\12\ 4\0\0Ôm`Ͷ\ 1\0\0\0\0\0\0\15\0\0\0pharext/Exception.phpc\ 1\0\0x9`Vc\ 1\0\0U\86Ï{¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/ExecCmd.php\1c\ e\0\0x9`V\1c\ e\0\0¹l\94ʶ\ 1\0\0\0\0\0\0\15\0\0\0pharext/Installer.php&\18\0\0x9`V&\18\0\0ød&À¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/License.php\93\ 4\0\0x9`V\93\ 4\0\0î\ 4òE¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Metadata.php\95\ 1\0\0x9`V\95\ 1\0\0¿Ú\90\9e¶\ 1\0\0\0\0\0\0\1e\0\0\0pharext/Openssl/PrivateKey.phpÁ\ 4\0\0x9`VÁ\ 4\0\0&æP\1a¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Packager.phpÌ!\0\0x9`VÌ!\0\00\ 2\ 3<¶\ 1\0\0\0\0\0\0\e\0\0\0pharext/SourceDir/Basic.phpz\ 5\0\0x9`Vz\ 5\0\0÷+Ôâ¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/SourceDir/Git.phpZ\ 6\0\0x9`VZ\ 6\0\0É\bÎ\¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/SourceDir/Pecl.phpø\11\0\0x9`Vø\11\0\0ã\bùж\ 1\0\0\0\0\0\0\15\0\0\0pharext/SourceDir.php½\ 2\0\0x9`V½\ 2\0\03·#\ f¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/Activate.phpÜ\v\0\0x9`VÜ\v\0\0I\93\1c\18¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Askpass.phpU\ 2\0\0x9`VU\ 2\0\0\87*\1e\90¶\ 1\0\0\0\0\0\0 \0\0\0pharext/Task/BundleGenerator.php}\ 2\0\0x9`V}\ 2\0\0 ï`Y¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Cleanup.php\1e\ 4\0\0x9`V\1e\ 4\0\0ÉI\80B¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/Configure.phpT\ 4\0\0x9`VT\ 4\0\0}\17Ëì¶\ 1\0\0\0\0\0\0\18\0\0\0pharext/Task/Extract.phpp\ 3\0\0x9`Vp\ 3\0\0[¨Û̶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/GitClone.phpm\ 3\0\0x9`Vm\ 3\0\0óyµ@¶\ 1\0\0\0\0\0\0\15\0\0\0pharext/Task/Make.phpª\ 4\0\0x9`Vª\ 4\0\0\9cç6\r¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PaxFixup.php¬\ 3\0\0x9`V¬\ 3\0\0yâ¯\e¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/PeclFixup.php\9c\ 4\0\0x9`V\9c\ 4\0\0eùt\9a¶\ 1\0\0\0\0\0\0\1a\0\0\0pharext/Task/PharBuild.phpâ\a\0\0x9`Vâ\a\0\0ζ0ɶ\ 1\0\0\0\0\0\0\1d\0\0\0pharext/Task/PharCompress.phpc\ 4\0\0x9`Vc\ 4\0\0½\10³Ï¶\ 1\0\0\0\0\0\0\e\0\0\0pharext/Task/PharRename.phpä\ 3\0\0x9`Vä\ 3\0\0\8a[Þ˶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PharSign.php¨\ 3\0\0x9`V¨\ 3\0\0Ûº¦i¶\ 1\0\0\0\0\0\0\19\0\0\0pharext/Task/PharStub.phpæ\ 3\0\0x9`Væ\ 3\0\0Y|\9b¶\ 1\0\0\0\0\0\0\17\0\0\0pharext/Task/Phpize.php\ f\ 4\0\0x9`V\ f\ 4\0\0ù\f2Ѷ\ 1\0\0\0\0\0\0\1c\0\0\0pharext/Task/StreamFetch.php\10\a\0\0x9`V\10\a\0\0\88îs\¶\ 1\0\0\0\0\0\0\10\0\0\0pharext/Task.phpw\0\0\0x9`Vw\0\0\0 ÄIǶ\ 1\0\0\0\0\0\0\13\0\0\0pharext/Tempdir.phpµ\ 1\0\0x9`Vµ\ 1\0\0ë\7f\96,¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Tempfile.php\ f\ 4\0\0x9`V\ f\ 4\0\0\0®ô\1e¶\ 1\0\0\0\0\0\0\14\0\0\0pharext/Tempname.phpt\ 3\0\0x9`Vt\ 3\0\0\9en<\8d¶\ 1\0\0\0\0\0\0\13\0\0\0pharext/Updater.php\8d\10\0\0x9`V\8d\10\0\0\9eÏv\16¶\ 1\0\0\0\0\0\0\15\0\0\0pharext_installer.phpÝ\ 2\0\0x9`VÝ\ 2\0\0\19\8cÞq¶\ 1\0\0\0\0\0\0\14\0\0\0pharext_packager.phpb\ 3\0\0x9`Vb\ 3\0\0îVÓ϶\ 1\0\0\0\0\0\0\13\0\0\0pharext_updater.phph\ 3\0\0x9`Vh\ 3\0\0 Êúj¶\ 1\0\0\0\0\0\0\r\0\0\0.editorconfigL\ 1\0\0x9`VL\ 1\0\0Þ\18\8d1¶\ 1\0\0\0\0\0\0\ e\0\0\0.gitattributesG\0\0\0x9`VG\0\0\0y\15\e\96¶\ 1\0\0\0\0\0\0
+\0\0\0.gitignore\ 2\ 1\0\0x9`V\ 2\ 1\0\0}\1a
+I¶\ 1\0\0\0\0\0\0\v\0\0\0.gitmodulesn\0\0\0x9`Vn\0\0\0¥ÉN\82¶\ 1\0\0\0\0\0\0\v\0\0\0.travis.ymlõ\ 1\0\0x9`Võ\ 1\0\0(@©D¶\ 1\0\0\0\0\0\0\a\0\0\0AUTHORS\1f\0\0\0x9`V\1f\0\0\0\ÄH¶\ 1\0\0\0\0\0\0\ 4\0\0\0BUGS*\0\0\0x9`V*\0\0\0\a<î\ f¶\ 1\0\0\0\0\0\0\ f\0\0\0CONTRIBUTING.md\8e\a\0\0x9`V\8e\a\0\0¶N\81q¶\ 1\0\0\0\0\0\0\a\0\0\0CREDITS\16\0\0\0x9`V\16\0\0\0Cµ]²¶\ 1\0\0\0\0\0\0\b\0\0\0DoxyfileÓ,\0\0x9`VÓ,\0\0Mc¾Ü¶\ 1\0\0\0\0\0\0\a\0\0\0LICENSEA\ 5\0\0x9`VA\ 5\0\0¾¬Jþ¶\ 1\0\0\0\0\0\0\r\0\0\0Makefile.frag¾\ 1\0\0x9`V¾\ 1\0\0ݯõ¯¶\ 1\0\0\0\0\0\0 \0\0\0README.md\ 1\ 5\0\0x9`V\ 1\ 5\0\0\99ËÜ?¶\ 1\0\0\0\0\0\0\ 6\0\0\0THANKSd\0\0\0x9`Vd\0\0\0ÌD"å¶\ 1\0\0\0\0\0\0\ 4\0\0\0TODO\ 6\0\0\0x9`V\ 6\0\0\0y_÷E¶\ 1\0\0\0\0\0\0 \0\0\0config.m4\15\0\0\0x9`V\15\0\0\0oêd\94¶\ 1\0\0\0\0\0\0
+\0\0\0config.w32ò\ 1\0\0x9`Vò\ 1\0\0L÷fO¶\ 1\0\0\0\0\0\0
+\0\0\0config0.m4å\ 2\0\0x9`Vå\ 2\0\0Ç×Îb¶\ 1\0\0\0\0\0\0\v\0\0\0package.xml. \0\0x9`V. \0\0Z-Áü¶\ 1\0\0\0\0\0\0\v\0\0\0php_raphf.h\12\ 5\0\0x9`V\12\ 5\0\0µ\98:\8e¶\ 1\0\0\0\0\0\0\10\0\0\0php_raphf_test.cÍ\19\0\0x9`VÍ\19\0\0·f>x¶\ 1\0\0\0\0\0\0 \0\0\0raphf.png|p\0\0x9`V|p\0\0sä\99³¶\ 1\0\0\0\0\0\0\1a\0\0\0scripts/gen_travis_yml.phpã\ 1\0\0x9`Vã\ 1\0\0îÌÙö¶\ 1\0\0\0\0\0\0\13\0\0\0src/php_raphf_api.c\81E\0\0x9`V\81E\0\0\99P\18\1d¶\ 1\0\0\0\0\0\0\13\0\0\0src/php_raphf_api.hf2\0\0x9`Vf2\0\0ÓI}\9e¶\ 1\0\0\0\0\0\0\12\0\0\0tests/http001.phpt\14\ 6\0\0x9`V\14\ 6\0\0\f*®\e¶\ 1\0\0\0\0\0\0\12\0\0\0tests/http002.phptL\ 5\0\0x9`VL\ 5\0\0\80ÔïS¶\ 1\0\0\0\0\0\0\12\0\0\0tests/http003.phpt^\ 5\0\0x9`V^\ 5\0\0\14\88\19p¶\ 1\0\0\0\0\0\0\12\0\0\0tests/http004.phpt[\b\0\0x9`V[\b\0\0Yè\1c«¶\ 1\0\0\0\0\0\0\ f\0\0\0tests/test.phpt¾
+\0\0x9`V¾
+\0\0$àíY¶\ 1\0\0\0\0\0\0\v\0\0\0travis/pecl\0\0\0\0x9`V\0\0\0\0\0\0\0\0¶\ 1\0\0\0\0\0\0<?php
+
+namespace pharext;
+
+use ArrayAccess;
+use IteratorAggregate;
+use RecursiveDirectoryIterator;
+use SplFileInfo;
+
+use pharext\Exception;
+
+class Archive implements ArrayAccess, IteratorAggregate
+{
+ const HALT_COMPILER = "\137\137\150\141\154\164\137\143\157\155\160\151\154\145\162\50\51\73";
+ const SIGNED = 0x10000;
+ const SIG_MD5 = 0x0001;
+ const SIG_SHA1 = 0x0002;
+ const SIG_SHA256 = 0x0003;
+ const SIG_SHA512 = 0x0004;
+ const SIG_OPENSSL= 0x0010;
+
+ private static $siglen = [
+ self::SIG_MD5 => 16,
+ self::SIG_SHA1 => 20,
+ self::SIG_SHA256 => 32,
+ self::SIG_SHA512 => 64,
+ self::SIG_OPENSSL=> 0
+ ];
+
+ private static $sigalg = [
+ self::SIG_MD5 => "md5",
+ self::SIG_SHA1 => "sha1",
+ self::SIG_SHA256 => "sha256",
+ self::SIG_SHA512 => "sha512",
+ self::SIG_OPENSSL=> "openssl"
+ ];
+
+ private static $sigtyp = [
+ self::SIG_MD5 => "MD5",
+ self::SIG_SHA1 => "SHA-1",
+ self::SIG_SHA256 => "SHA-256",
+ self::SIG_SHA512 => "SHA-512",
+ self::SIG_OPENSSL=> "OpenSSL",
+ ];
+
+ const PERM_FILE_MASK = 0x01ff;
+ const COMP_FILE_MASK = 0xf000;
+ const COMP_GZ_FILE = 0x1000;
+ const COMP_BZ2_FILE = 0x2000;
+
+ const COMP_PHAR_MASK= 0xf000;
+ const COMP_PHAR_GZ = 0x1000;
+ const COMP_PHAR_BZ2 = 0x2000;
+
+ private $file;
+ private $fd;
+ private $stub;
+ private $manifest;
+ private $signature;
+ private $extracted;
+
+ function __construct($file = null) {
+ if (strlen($file)) {
+ $this->open($file);
+ }
+ }
+
+ function open($file) {
+ if (!$this->fd = @fopen($file, "r")) {
+ throw new Exception;
+ }
+ $this->file = $file;
+ $this->stub = $this->readStub();
+ $this->manifest = $this->readManifest();
+ $this->signature = $this->readSignature();
+ }
+
+ function getIterator() {
+ return new RecursiveDirectoryIterator($this->extract());
+ }
+
+ function extract() {
+ return $this->extracted ?: $this->extractTo(new Tempdir("archive"));
+ }
+
+ function extractTo($dir) {
+ if ((string) $this->extracted == (string) $dir) {
+ return $this->extracted;
+ }
+ foreach ($this->manifest["entries"] as $file => $entry) {
+ fseek($this->fd, $this->manifest["offset"]+$entry["offset"]);
+ $path = "$dir/$file";
+ $copy = stream_copy_to_stream($this->fd, $this->outFd($path, $entry["flags"]), $entry["csize"]);
+ if ($entry["osize"] != $copy) {
+ throw new Exception("Copied '$copy' of '$file', expected '{$entry["osize"]}' from '{$entry["csize"]}");
+ }
+
+ $crc = hexdec(hash_file("crc32b", $path));
+ if ($crc !== $entry["crc32"]) {
+ throw new Exception("CRC mismatch of '$file': '$crc' != '{$entry["crc32"]}");
+ }
+
+ chmod($path, $entry["flags"] & self::PERM_FILE_MASK);
+ touch($path, $entry["stamp"]);
+ }
+ return $this->extracted = $dir;
+ }
+
+ function offsetExists($o) {
+ return isset($this->entries[$o]);
+ }
+
+ function offsetGet($o) {
+ $this->extract();
+ return new SplFileInfo($this->extracted."/$o");
+ }
+
+ function offsetSet($o, $v) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function offsetUnset($o) {
+ throw new Exception("Archive is read-only");
+ }
+
+ function getSignature() {
+ /* compatible with Phar::getSignature() */
+ return [
+ "hash_type" => self::$sigtyp[$this->signature["flags"]],
+ "hash" => strtoupper(bin2hex($this->signature["hash"])),
+ ];
+ }
+
+ function getPath() {
+ /* compatible with Phar::getPath() */
+ return new SplFileInfo($this->file);
+ }
+
+ function getMetadata($key = null) {
+ if (isset($key)) {
+ return $this->manifest["meta"][$key];
+ }
+ return $this->manifest["meta"];
+ }
+
+ private function outFd($path, $flags) {
+ $dirn = dirname($path);
+ if (!is_dir($dirn) && !@mkdir($dirn, 0777, true)) {
+ throw new Exception;
+ }
+ if (!$fd = @fopen($path, "w")) {
+ throw new Exception;
+ }
+ switch ($flags & self::COMP_FILE_MASK) {
+ case self::COMP_GZ_FILE:
+ if (!@stream_filter_append($fd, "zlib.inflate")) {
+ throw new Exception;
+ }
+ break;
+ case self::COMP_BZ2_FILE:
+ if (!@stream_filter_append($fd, "bz2.decompress")) {
+ throw new Exception;
+ }
+ break;
+ }
+
+ }
+ private function readVerified($fd, $len) {
+ if ($len != strlen($data = fread($fd, $len))) {
+ throw new Exception("Unexpected EOF");
+ }
+ return $data;
+ }
+
+ private function readFormat($format, $fd, $len) {
+ if (false === ($data = @unpack($format, $this->readVerified($fd, $len)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+
+ private function readSingleFormat($format, $fd, $len) {
+ return current($this->readFormat($format, $fd, $len));
+ }
+
+ private function readStringBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ return $this->readVerified($this->fd, $length);
+ }
+ return null;
+ }
+
+ private function readSerializedBinary($fd) {
+ if (($length = $this->readSingleFormat("V", $fd, 4))) {
+ if (false === ($data = unserialize($this->readVerified($fd, $length)))) {
+ throw new Exception;
+ }
+ return $data;
+ }
+ return null;
+ }
+
+ private function readStub() {
+ $stub = "";
+ while (!feof($this->fd)) {
+ $line = fgets($this->fd);
+ $stub .= $line;
+ if (false !== stripos($line, self::HALT_COMPILER)) {
+ /* check for '?>' on a separate line */
+ if ('?>' === $this->readVerified($this->fd, 2)) {
+ $stub .= '?>' . fgets($this->fd);
+ } else {
+ fseek($this->fd, -2, SEEK_CUR);
+ }
+ break;
+ }
+ }
+ return $stub;
+ }
+
+ private function readManifest() {
+ $current = ftell($this->fd);
+ $header = $this->readFormat("Vlen/Vnum/napi/Vflags", $this->fd, 14);
+ $alias = $this->readStringBinary($this->fd);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries = [];
+ for ($i = 0; $i < $header["num"]; ++$i) {
+ $this->readEntry($entries);
+ }
+ $offset = ftell($this->fd);
+ if (($length = $offset - $current - 4) != $header["len"]) {
+ throw new Exception("Manifest length read was '$length', expected '{$header["len"]}'");
+ }
+ return $header + compact("alias", "meta", "entries", "offset");
+ }
+
+ private function readEntry(array &$entries) {
+ if (!count($entries)) {
+ $offset = 0;
+ } else {
+ $last = end($entries);
+ $offset = $last["offset"] + $last["csize"];
+ }
+ $file = $this->readStringBinary($this->fd);
+ if (!strlen($file)) {
+ throw new Exception("Empty file name encountered at offset '$offset'");
+ }
+ $header = $this->readFormat("Vosize/Vstamp/Vcsize/Vcrc32/Vflags", $this->fd, 20);
+ $meta = $this->readSerializedBinary($this->fd);
+ $entries[$file] = $header + compact("meta", "offset");
+ }
+
+ private function readSignature() {
+ fseek($this->fd, -8, SEEK_END);
+ $sig = $this->readFormat("Vflags/Z4magic", $this->fd, 8);
+ $end = ftell($this->fd);
+
+ if ($sig["magic"] !== "GBMB") {
+ throw new Exception("Invalid signature magic value '{$sig["magic"]}");
+ }
+
+ switch ($sig["flags"]) {
+ case self::SIG_OPENSSL:
+ fseek($this->fd, -12, SEEK_END);
+ if (($hash = $this->readSingleFormat("V", $this->fd, 4))) {
+ $offset = 4 + $hash;
+ fseek($this->fd, -$offset, SEEK_CUR);
+ $hash = $this->readVerified($this->fd, $hash);
+ fseek($this->fd, 0, SEEK_SET);
+ $valid = openssl_verify($this->readVerified($this->fd, $end - $offset - 8),
+ $hash, @file_get_contents($this->file.".pubkey")) === 1;
+ }
+ break;
+
+ case self::SIG_MD5:
+ case self::SIG_SHA1:
+ case self::SIG_SHA256:
+ case self::SIG_SHA512:
+ $offset = 8 + self::$siglen[$sig["flags"]];
+ fseek($this->fd, -$offset, SEEK_END);
+ $hash = $this->readVerified($this->fd, self::$siglen[$sig["flags"]]);
+ $algo = hash_init(self::$sigalg[$sig["flags"]]);
+ fseek($this->fd, 0, SEEK_SET);
+ hash_update_stream($algo, $this->fd, $end - $offset);
+ $valid = hash_final($algo, true) === $hash;
+ break;
+
+ default:
+ throw new Exception("Invalid signature type '{$sig["flags"]}");
+ }
+
+ return $sig + compact("hash", "valid");
+ }
+}
+<?php
+
+namespace pharext\Cli\Args;
+
+use pharext\Cli\Args;
+
+class Help
+{
+ private $args;
+
+ function __construct($prog, Args $args) {
+ $this->prog = $prog;
+ $this->args = $args;
+ }
+
+ function __toString() {
+ $usage = "Usage:\n\n \$ ";
+ $usage .= $this->prog;
+
+ list($flags, $required, $optional, $positional) = $this->listSpec();
+ if ($flags) {
+ $usage .= $this->dumpFlags($flags);
+ }
+ if ($required) {
+ $usage .= $this->dumpRequired($required);
+ }
+ if ($optional) {
+ $usage .= $this->dumpOptional($optional);
+ }
+ if ($positional) {
+ $usage .= $this->dumpPositional($positional);
+ }
+
+ $help = $this->dumpHelp($positional);
+
+ return $usage . "\n\n" . $help . "\n";
+ }
+
+ function listSpec() {
+ $flags = [];
+ $required = [];
+ $optional = [];
+ $positional = [];
+ foreach ($this->args->getSpec() as $spec) {
+ if (is_numeric($spec[0])) {
+ $positional[] = $spec;
+ } elseif ($spec[3] & Args::REQUIRED) {
+ $required[] = $spec;
+ } elseif ($spec[3] & (Args::OPTARG|Args::REQARG)) {
+ $optional[] = $spec;
+ } else {
+ $flags[] = $spec;
+ }
+ }
+
+ return [$flags, $required, $optional, $positional]
+ + compact("flags", "required", "optional", "positional");
+ }
+
+ function dumpFlags(array $flags) {
+ return sprintf(" [-%s]", implode("", array_column($flags, 0)));
+ }
+
+ function dumpRequired(array $required) {
+ $dump = "";
+ foreach ($required as $req) {
+ $dump .= sprintf(" -%s <%s>", $req[0], $req[1]);
+ }
+ return $dump;
+ }
+
+ function dumpOptional(array $optional) {
+ $req = array_filter($optional, function($a) {
+ return $a[3] & Args::REQARG;
+ });
+ $opt = array_filter($optional, function($a) {
+ return $a[3] & Args::OPTARG;
+ });
+
+ $dump = "";
+ if ($req) {
+ $dump .= sprintf(" [-%s <arg>]", implode("|-", array_column($req, 0)));
+ }
+ if ($opt) {
+ $dump .= sprintf(" [-%s [<arg>]]", implode("|-", array_column($opt, 0)));
+ }
+ return $dump;
+ }
+
+ function dumpPositional(array $positional) {
+ $dump = " [--]";
+ foreach ($positional as $pos) {
+ if ($pos[3] & Args::REQUIRED) {
+ $dump .= sprintf(" <%s>", $pos[1]);
+ } else {
+ $dump .= sprintf(" [<%s>]", $pos[1]);
+ }
+ if ($pos[3] & Args::MULTI) {
+ $dump .= sprintf(" [<%s>]...", $pos[1]);
+ }
+ }
+ return $dump;
+ }
+
+ function calcMaxLen() {
+ $spc = $this->args->getSpec();
+ $max = max(array_map("strlen", array_column($spc, 1)));
+ $max += $max % 8 + 2;
+ return $max;
+ }
+
+ function dumpHelp() {
+ $max = $this->calcMaxLen();
+ $dump = "";
+ foreach ($this->args->getSpec() as $spec) {
+ $dump .= " ";
+ if (is_numeric($spec[0])) {
+ $dump .= sprintf("-- %s ", $spec[1]);
+ } elseif (isset($spec[0])) {
+ $dump .= sprintf("-%s|", $spec[0]);
+ }
+ if (!is_numeric($spec[0])) {
+ $dump .= sprintf("--%s ", $spec[1]);
+ }
+ if ($spec[3] & Args::REQARG) {
+ $dump .= "<arg> ";
+ } elseif ($spec[3] & Args::OPTARG) {
+ $dump .= "[<arg>]";
+ } else {
+ $dump .= " ";
+ }
+
+ $dump .= str_repeat(" ", $max-strlen($spec[1])+3*!isset($spec[0]));
+ $dump .= $spec[2];
+
+ if ($spec[3] & Args::REQUIRED) {
+ $dump .= " (REQUIRED)";
+ }
+ if ($spec[3] & Args::MULTI) {
+ $dump .= " (MULTIPLE)";
+ }
+ if (isset($spec[4])) {
+ $dump .= sprintf(" [%s]", $spec[4]);
+ }
+ $dump .= "\n";
+ }
+ return $dump;
+ }
+}
+<?php
+
+namespace pharext\Cli;
+
+/**
+ * Command line arguments
+ */
+class Args implements \ArrayAccess
+{
+ /**
+ * Optional option
+ */
+ const OPTIONAL = 0x000;
+
+ /**
+ * Required Option
+ */
+ const REQUIRED = 0x001;
+
+ /**
+ * Only one value, even when used multiple times
+ */
+ const SINGLE = 0x000;
+
+ /**
+ * Aggregate an array, when used multiple times
+ */
+ const MULTI = 0x010;
+
+ /**
+ * Option takes no argument
+ */
+ const NOARG = 0x000;
+
+ /**
+ * Option requires an argument
+ */
+ const REQARG = 0x100;
+
+ /**
+ * Option takes an optional argument
+ */
+ const OPTARG = 0x200;
+
+ /**
+ * Option halts processing
+ */
+ const HALT = 0x10000000;
+
+ /**
+ * Original option spec
+ * @var array
+ */
+ private $orig = [];
+
+ /**
+ * Compiled spec
+ * @var array
+ */
+ private $spec = [];
+
+ /**
+ * Parsed args
+ * @var array
+ */
+ private $args = [];
+
+ /**
+ * Compile the original spec
+ * @param array|Traversable $spec
+ */
+ public function __construct($spec = null) {
+ if (is_array($spec) || $spec instanceof Traversable) {
+ $this->compile($spec);
+ }
+
+ }
+
+ /**
+ * Compile the original spec
+ * @param array|Traversable $spec
+ * @return pharext\Cli\Args self
+ */
+ public function compile($spec) {
+ foreach ($spec as $arg) {
+ if (isset($arg[0]) && is_numeric($arg[0])) {
+ $arg[3] &= ~0xf00;
+ $this->spec["--".$arg[0]] = $arg;
+ } elseif (isset($arg[0])) {
+ $this->spec["-".$arg[0]] = $arg;
+ $this->spec["--".$arg[1]] = $arg;
+ } else {
+ $this->spec["--".$arg[1]] = $arg;
+ }
+ $this->orig[] = $arg;
+ }
+ return $this;
+ }
+
+ /**
+ * Get original spec
+ * @return array
+ */
+ public function getSpec() {
+ return $this->orig;
+ }
+
+ /**
+ * Get compiled spec
+ * @return array
+ */
+ public function getCompiledSpec() {
+ return $this->spec;
+ }
+
+ /**
+ * Parse command line arguments according to the compiled spec.
+ *
+ * The Generator yields any parsing errors.
+ * Parsing will stop when all arguments are processed or the first option
+ * flagged Cli\Args::HALT was encountered.
+ *
+ * @param int $argc
+ * @param array $argv
+ * @return Generator
+ */
+ public function parse($argc, array $argv) {
+ for ($f = false, $p = 0, $i = 0; $i < $argc; ++$i) {
+ $o = $argv[$i];
+
+ if ($o{0} === "-" && strlen($o) > 2 && $o{1} !== "-") {
+ // multiple short opts, e.g. -vps
+ $argc += strlen($o) - 2;
+ array_splice($argv, $i, 1, array_map(function($s) {
+ return "-$s";
+ }, str_split(substr($o, 1))));
+ $o = $argv[$i];
+ } elseif ($o{0} === "-" && strlen($o) > 2 && $o{1} === "-" && 0 < ($eq = strpos($o, "="))) {
+ // long opt with argument, e.g. --foo=bar
+ $argc++;
+ array_splice($argv, $i, 1, [
+ substr($o, 0, $eq++),
+ substr($o, $eq)
+ ]);
+ $o = $argv[$i];
+ } elseif ($o === "--") {
+ // only positional args following
+ $f = true;
+ continue;
+ }
+
+ if ($f || !isset($this->spec[$o])) {
+ if ($o{0} !== "-" && isset($this->spec["--$p"])) {
+ $this[$p] = $o;
+ if (!$this->optIsMulti($p)) {
+ ++$p;
+ }
+ } else {
+ yield sprintf("Unknown option %s", $o);
+ }
+ } elseif (!$this->optAcceptsArg($o)) {
+ $this[$o] = true;
+ } elseif ($i+1 < $argc && !isset($this->spec[$argv[$i+1]])) {
+ $this[$o] = $argv[++$i];
+ } elseif ($this->optRequiresArg($o)) {
+ yield sprintf("Option --%s requires an argument", $this->optLongName($o));
+ } else {
+ // OPTARG
+ $this[$o] = $this->optDefaultArg($o);
+ }
+
+ if ($this->optHalts($o)) {
+ return;
+ }
+ }
+ }
+
+ /**
+ * Validate that all required options were given.
+ *
+ * The Generator yields any validation errors.
+ *
+ * @return Generator
+ */
+ public function validate() {
+ $required = array_filter($this->orig, function($spec) {
+ return $spec[3] & self::REQUIRED;
+ });
+ foreach ($required as $req) {
+ if ($req[3] & self::MULTI) {
+ if (is_array($this[$req[0]])) {
+ continue;
+ }
+ } elseif (strlen($this[$req[0]])) {
+ continue;
+ }
+ if (is_numeric($req[0])) {
+ yield sprintf("Argument <%s> is required", $req[1]);
+ } else {
+ yield sprintf("Option --%s is required", $req[1]);
+ }
+ }
+ }
+
+
+ public function toArray() {
+ $args = [];
+ foreach ($this->spec as $spec) {
+ $opt = $this->opt($spec[1]);
+ $args[$opt] = $this[$opt];
+ }
+ return $args;
+ }
+
+ /**
+ * Retreive the default argument of an option
+ * @param string $o
+ * @return mixed
+ */
+ private function optDefaultArg($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o][4])) {
+ return $this->spec[$o][4];
+ }
+ return null;
+ }
+
+ /**
+ * Retrieve the help message of an option
+ * @param string $o
+ * @return string
+ */
+ private function optHelp($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o][2])) {
+ return $this->spec[$o][2];
+ }
+ return "";
+ }
+
+ /**
+ * Retrieve option's flags
+ * @param string $o
+ * @return int
+ */
+ private function optFlags($o) {
+ $o = $this->opt($o);
+ if (isset($this->spec[$o])) {
+ return $this->spec[$o][3];
+ }
+ return null;
+ }
+
+ /**
+ * Check whether an option is flagged for halting argument processing
+ * @param string $o
+ * @return boolean
+ */
+ private function optHalts($o) {
+ return $this->optFlags($o) & self::HALT;
+ }
+
+ /**
+ * Check whether an option needs an argument
+ * @param string $o
+ * @return boolean
+ */
+ private function optRequiresArg($o) {
+ return $this->optFlags($o) & self::REQARG;
+ }
+
+ /**
+ * Check wether an option accepts any argument
+ * @param string $o
+ * @return boolean
+ */
+ private function optAcceptsArg($o) {
+ return $this->optFlags($o) & 0xf00;
+ }
+
+ /**
+ * Check whether an option can be used more than once
+ * @param string $o
+ * @return boolean
+ */
+ private function optIsMulti($o) {
+ return $this->optFlags($o) & self::MULTI;
+ }
+
+ /**
+ * Retreive the long name of an option
+ * @param string $o
+ * @return string
+ */
+ private function optLongName($o) {
+ $o = $this->opt($o);
+ return is_numeric($this->spec[$o][0]) ? $this->spec[$o][0] : $this->spec[$o][1];
+ }
+
+ /**
+ * Retreive the short name of an option
+ * @param string $o
+ * @return string
+ */
+ private function optShortName($o) {
+ $o = $this->opt($o);
+ return is_numeric($this->spec[$o][0]) ? null : $this->spec[$o][0];
+ }
+
+ /**
+ * Retreive the canonical name (--long-name) of an option
+ * @param string $o
+ * @return string
+ */
+ private function opt($o) {
+ if (is_numeric($o)) {
+ return "--$o";
+ }
+ if ($o{0} !== '-') {
+ if (strlen($o) > 1) {
+ $o = "-$o";
+ }
+ $o = "-$o";
+ }
+ return $o;
+ }
+
+ /**@+
+ * Implements ArrayAccess and virtual properties
+ */
+ function offsetExists($o) {
+ $o = $this->opt($o);
+ return isset($this->args[$o]);
+ }
+ function __isset($o) {
+ return $this->offsetExists($o);
+ }
+ function offsetGet($o) {
+ $o = $this->opt($o);
+ if (isset($this->args[$o])) {
+ return $this->args[$o];
+ }
+ return $this->optDefaultArg($o);
+ }
+ function __get($o) {
+ return $this->offsetGet($o);
+ }
+ function offsetSet($o, $v) {
+ $osn = $this->optShortName($o);
+ $oln = $this->optLongName($o);
+ if ($this->optIsMulti($o)) {
+ if (isset($osn)) {
+ $this->args["-$osn"][] = $v;
+ }
+ $this->args["--$oln"][] = $v;
+ } else {
+ if (isset($osn)) {
+ $this->args["-$osn"] = $v;
+ }
+ $this->args["--$oln"] = $v;
+ }
+ }
+ function __set($o, $v) {
+ $this->offsetSet($o, $v);
+ }
+ function offsetUnset($o) {
+ unset($this->args["-".$this->optShortName($o)]);
+ unset($this->args["--".$this->optLongName($o)]);
+ }
+ function __unset($o) {
+ $this->offsetUnset($o);
+ }
+ /**@-*/
+}
+<?php
+
+namespace pharext\Cli;
+
+use pharext\Archive;
+
+use Phar;
+
+trait Command
+{
+ /**
+ * Command line arguments
+ * @var pharext\Cli\Args
+ */
+ private $args;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::getArgs()
+ */
+ public function getArgs() {
+ return $this->args;
+ }
+
+ /**
+ * Retrieve metadata of the currently running phar
+ * @param string $key
+ * @return mixed
+ */
+ public function metadata($key = null) {
+ if (extension_loaded("Phar")) {
+ $running = new Phar(Phar::running(false));
+ } else {
+ $running = new Archive(PHAREXT_PHAR);
+ }
+
+ if ($key === "signature") {
+ $sig = $running->getSignature();
+ return sprintf("%s signature of %s\n%s",
+ $sig["hash_type"],
+ $this->metadata("name"),
+ chunk_split($sig["hash"], 64, "\n"));
+ }
+
+ $metadata = $running->getMetadata();
+ if (isset($key)) {
+ return $metadata[$key];
+ }
+ return $metadata;
+ }
+
+ /**
+ * Output pharext vX.Y.Z header
+ */
+ public function header() {
+ if (!headers_sent()) {
+ /* only display header, if we didn't generate any output yet */
+ printf("%s\n\n", $this->metadata("header"));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::debug()
+ */
+ public function debug($fmt) {
+ if ($this->args->verbose) {
+ vprintf($fmt, array_slice(func_get_args(), 1));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::info()
+ */
+ public function info($fmt) {
+ if (!$this->args->quiet) {
+ vprintf($fmt, array_slice(func_get_args(), 1));
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::warn()
+ */
+ public function warn($fmt) {
+ if (!$this->args->quiet) {
+ if (!isset($fmt)) {
+ $fmt = "%s\n";
+ $arg = error_get_last()["message"];
+ } else {
+ $arg = array_slice(func_get_args(), 1);
+ }
+ vfprintf(STDERR, "Warning: $fmt", $arg);
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::error()
+ */
+ public function error($fmt) {
+ if (!isset($fmt)) {
+ $fmt = "%s\n";
+ $arg = error_get_last()["message"];
+ } else {
+ $arg = array_slice(func_get_args(), 1);
+ }
+ vfprintf(STDERR, "ERROR: $fmt", $arg);
+ }
+
+ /**
+ * Output command line help message
+ * @param string $prog
+ */
+ public function help($prog) {
+ print new Args\Help($prog, $this->args);
+ }
+
+ /**
+ * Verbosity
+ * @return boolean
+ */
+ public function verbosity() {
+ if ($this->args->verbose) {
+ return true;
+ } elseif ($this->args->quiet) {
+ return false;
+ } else {
+ return null;
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Command interface
+ */
+interface Command
+{
+ /**
+ * Argument error
+ */
+ const EARGS = 1;
+ /**
+ * Build error
+ */
+ const EBUILD = 2;
+ /**
+ * Signature error
+ */
+ const ESIGN = 3;
+ /**
+ * Extract/unpack error
+ */
+ const EEXTRACT = 4;
+ /**
+ * Install error
+ */
+ const EINSTALL = 5;
+
+ /**
+ * Retrieve command line arguments
+ * @return pharext\Cli\Args
+ */
+ public function getArgs();
+
+ /**
+ * Print debug message
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function debug($fmt);
+
+ /**
+ * Print info
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function info($fmt);
+
+ /**
+ * Print warning
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function warn($fmt);
+
+ /**
+ * Print error
+ * @param string $fmt
+ * @param string ...$args
+ */
+ public function error($fmt);
+
+ /**
+ * Execute the command
+ * @param int $argc command line argument count
+ * @param array $argv command line argument list
+ */
+ public function run($argc, array $argv);
+}
+<?php
+
+namespace pharext;
+
+class Exception extends \Exception
+{
+ public function __construct($message = null, $code = 0, $previous = null) {
+ if (!isset($message)) {
+ $last_error = error_get_last();
+ $message = $last_error["message"];
+ if (!$code) {
+ $code = $last_error["type"];
+ }
+ }
+ parent::__construct($message, $code, $previous);
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Execute system command
+ */
+class ExecCmd
+{
+ /**
+ * Sudo command, if the cmd needs escalated privileges
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ * Executable of the cmd
+ * @var string
+ */
+ private $command;
+
+ /**
+ * Passthrough cmd output
+ * @var bool
+ */
+ private $verbose;
+
+ /**
+ * Output of cmd run
+ * @var string
+ */
+ private $output;
+
+ /**
+ * Return code of cmd run
+ * @var int
+ */
+ private $status;
+
+ /**
+ * @param string $command
+ * @param bool verbose
+ */
+ public function __construct($command, $verbose = false) {
+ $this->command = $command;
+ $this->verbose = $verbose;
+ }
+
+ /**
+ * (Re-)set sudo command
+ * @param string $sudo
+ */
+ public function setSu($sudo = false) {
+ $this->sudo = $sudo;
+ }
+
+ /**
+ * Execute a program with escalated privileges handling interactive password prompt
+ * @param string $command
+ * @param bool $verbose
+ * @return int exit status
+ */
+ private function suExec($command, $verbose = null) {
+ if (!($proc = proc_open($command, [STDIN,["pipe","w"],["pipe","w"]], $pipes))) {
+ $this->status = -1;
+ throw new Exception("Failed to run {$command}");
+ }
+
+ $stdout = $pipes[1];
+ $passwd = 0;
+ $checks = 10;
+
+ while (!feof($stdout)) {
+ $R = [$stdout]; $W = []; $E = [];
+ if (!stream_select($R, $W, $E, null)) {
+ continue;
+ }
+ $data = fread($stdout, 0x1000);
+ /* only check a few times */
+ if ($passwd < $checks) {
+ $passwd++;
+ if (stristr($data, "password")) {
+ $passwd = $checks + 1;
+ printf("\n%s", $data);
+ continue;
+ }
+ } elseif ($passwd > $checks) {
+ /* new line after pw entry */
+ printf("\n");
+ $passwd = $checks;
+ }
+
+ if ($verbose === null) {
+ print $this->progress($data, 0);
+ } else {
+ if ($verbose) {
+ printf("%s", $data);
+ }
+ $this->output .= $data;
+ }
+ }
+ if ($verbose === null) {
+ $this->progress("", PHP_OUTPUT_HANDLER_FINAL);
+ }
+ return $this->status = proc_close($proc);
+ }
+
+ /**
+ * Output handler that displays some progress while soaking output
+ * @param string $string
+ * @param int $flags
+ * @return string
+ */
+ private function progress($string, $flags) {
+ static $counter = 0;
+ static $symbols = ["\\","|","/","-"];
+
+ $this->output .= $string;
+
+ if (false !== strpos($string, "\n")) {
+ ++$counter;
+ }
+
+ return $flags & PHP_OUTPUT_HANDLER_FINAL
+ ? " \r"
+ : sprintf(" %s\r", $symbols[$counter % 4]);
+ }
+
+ /**
+ * Run the command
+ * @param array $args
+ * @return \pharext\ExecCmd self
+ * @throws \pharext\Exception
+ */
+ public function run(array $args = null) {
+ $exec = escapeshellcmd($this->command);
+ if ($args) {
+ $exec .= " ". implode(" ", array_map("escapeshellarg", (array) $args));
+ }
+
+ if ($this->sudo) {
+ $this->suExec(sprintf($this->sudo." 2>&1", $exec), $this->verbose);
+ } elseif ($this->verbose) {
+ ob_start(function($s) {
+ $this->output .= $s;
+ return $s;
+ }, 1);
+ passthru($exec, $this->status);
+ ob_end_flush();
+ } elseif ($this->verbose !== false /* !quiet */) {
+ ob_start([$this, "progress"], 1);
+ passthru($exec . " 2>&1", $this->status);
+ ob_end_flush();
+ } else {
+ exec($exec ." 2>&1", $output, $this->status);
+ $this->output = implode("\n", $output);
+ }
+
+ if ($this->status) {
+ throw new Exception("Command {$exec} failed ({$this->status})");
+ }
+
+ return $this;
+ }
+
+ /**
+ * Retrieve exit code of cmd run
+ * @return int
+ */
+ public function getStatus() {
+ return $this->status;
+ }
+
+ /**
+ * Retrieve output of cmd run
+ * @return string
+ */
+ public function getOutput() {
+ return $this->output;
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use SplObjectStorage;
+
+/**
+ * The extension install command executed by the extension phar
+ */
+class Installer implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Cleanups
+ * @var array
+ */
+ private $cleanup = [];
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["p", "prefix", "PHP installation prefix if phpize is not in \$PATH, e.g. /opt/php7",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["n", "common-name", "PHP common program name, e.g. php5 or zts-php",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG,
+ "php"],
+ ["c", "configure", "Additional extension configure flags, e.g. -c --with-flag",
+ Cli\Args::OPTIONAL|Cli\Args::MULTI|Cli\Args::REQARG],
+ ["s", "sudo", "Installation might need increased privileges",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::OPTARG,
+ "sudo -S %s"],
+ ["i", "ini", "Activate in this php.ini instead of loaded default php.ini",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ [null, "signature", "Show package signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show package license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "name", "Show package name",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "date", "Show package release date",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "release", "Show package release version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ]);
+ }
+
+ /**
+ * Perform cleaniup
+ */
+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
+ private function extract($phar) {
+ $temp = (new Task\Extract($phar))->run($this->verbosity());
+ $this->cleanup[] = new Task\Cleanup($temp);
+ return $temp;
+ }
+
+ private function hooks(SplObjectStorage $phars) {
+ $hook = [];
+ foreach ($phars as $phar) {
+ if (isset($phar["pharext_package.php"])) {
+ $sdir = include $phar["pharext_package.php"];
+ if ($sdir instanceof SourceDir) {
+ $this->args->compile($sdir->getArgs());
+ $hook[] = $sdir;
+ }
+ }
+ }
+ return $hook;
+ }
+
+ private function load() {
+ $list = new SplObjectStorage();
+ $phar = extension_loaded("Phar")
+ ? new Phar(Phar::running(false))
+ : new Archive(PHAREXT_PHAR);
+ $temp = $this->extract($phar);
+
+ foreach ($phar as $entry) {
+ $dep_file = $entry->getBaseName();
+ if (fnmatch("*.ext.phar*", $dep_file)) {
+ $dep_phar = extension_loaded("Phar")
+ ? new Phar("$temp/$dep_file")
+ : new Archive("$temp/$dep_file");
+ $list[$dep_phar] = $this->extract($dep_phar);
+ }
+ }
+
+ /* the actual ext.phar at last */
+ $list[$phar] = $temp;
+ return $list;
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ try {
+ /* load the phar(s) */
+ $list = $this->load();
+ /* installer hooks */
+ $hook = $this->hooks($list);
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EEXTRACT);
+ }
+
+ /* standard arg stuff */
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+ try {
+ foreach (["signature", "name", "date", "license", "release", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ try {
+ /* post process hooks */
+ foreach ($hook as $sdir) {
+ $sdir->setArgs($this->args);
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ /* install packages */
+ try {
+ foreach ($list as $phar) {
+ $this->info("Installing %s ...\n", basename($phar->getPath()));
+ $this->install($list[$phar]);
+ $this->activate($list[$phar]);
+ $this->info("Successfully installed %s!\n", basename($phar->getPath()));
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EINSTALL);
+ }
+ }
+
+ /**
+ * Phpize + trinity
+ */
+ private function install($temp) {
+ // phpize
+ $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"});
+ $phpize->run($this->verbosity());
+
+ // configure
+ $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args->{"common-name"});
+ $configure->run($this->verbosity());
+
+ // make
+ $make = new Task\Make($temp);
+ $make->run($this->verbosity());
+
+ // install
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $install = new Task\Make($temp, ["install"], $sudo);
+ $install->run($this->verbosity());
+ }
+
+ private function activate($temp) {
+ if ($this->args->ini) {
+ $files = [$this->args->ini];
+ } else {
+ $files = array_filter(array_map("trim", explode(",", php_ini_scanned_files())));
+ $files[] = php_ini_loaded_file();
+ }
+
+ $sudo = isset($this->args->sudo) ? $this->args->sudo : null;
+ $type = $this->metadata("type") ?: "extension";
+
+ $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo);
+ if (!$activate->run($this->verbosity())) {
+ $this->info("Extension already activated ...\n");
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+trait License
+{
+ function findLicense($dir, $file = null) {
+ if (isset($file)) {
+ return realpath("$dir/$file");
+ }
+
+ $names = [];
+ foreach (["{,UN}LICEN{S,C}{E,ING}", "COPY{,ING,RIGHT}"] as $name) {
+ $names[] = $this->mergeLicensePattern($name, strtolower($name));
+ }
+ $exts = [];
+ foreach (["t{,e}xt", "rst", "asc{,i,ii}", "m{,ark}d{,own}", "htm{,l}"] as $ext) {
+ $exts[] = $this->mergeLicensePattern(strtoupper($ext), $ext);
+ }
+
+ $pattern = "{". implode(",", $names) ."}{,.{". implode(",", $exts) ."}}";
+
+ if (($glob = glob("$dir/$pattern", GLOB_BRACE))) {
+ return current($glob);
+ }
+ }
+
+ private function mergeLicensePattern($upper, $lower) {
+ $pattern = "";
+ $length = strlen($upper);
+ for ($i = 0; $i < $length; ++$i) {
+ if ($lower{$i} === $upper{$i}) {
+ $pattern .= $upper{$i};
+ } else {
+ $pattern .= "[" . $upper{$i} . $lower{$i} . "]";
+ }
+ }
+ return $pattern;
+ }
+
+ public function readLicense($file) {
+ $text = file_get_contents($file);
+ switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {
+ case "htm":
+ case "html":
+ $text = strip_tags($text);
+ break;
+ }
+ return $text;
+ }
+}
+<?php
+
+namespace pharext;
+
+class Metadata
+{
+ static function version() {
+ return "4.1.1";
+ }
+
+ static function header() {
+ return sprintf("pharext v%s (c) Michael Wallner <mike@php.net>", self::version());
+ }
+
+ static function date() {
+ return gmdate("Y-m-d");
+ }
+
+ static function all() {
+ return [
+ "version" => self::version(),
+ "header" => self::header(),
+ "date" => self::date(),
+ ];
+ }
+}
+<?php
+
+namespace pharext\Openssl;
+
+use pharext\Exception;
+
+class PrivateKey
+{
+ /**
+ * Private key
+ * @var string
+ */
+ private $key;
+
+ /**
+ * Public key
+ * @var string
+ */
+ private $pub;
+
+ /**
+ * Read a private key
+ * @param string $file
+ * @param string $password
+ * @throws \pharext\Exception
+ */
+ function __construct($file, $password) {
+ /* there appears to be a bug with refcount handling of this
+ * resource; when the resource is stored as property, it cannot be
+ * "coerced to a private key" on openssl_sign() later in another method
+ */
+ $key = openssl_pkey_get_private("file://$file", $password);
+ if (!is_resource($key)) {
+ throw new Exception("Could not load private key");
+ }
+ openssl_pkey_export($key, $this->key);
+ $this->pub = openssl_pkey_get_details($key)["key"];
+ }
+
+ /**
+ * Sign the PHAR
+ * @param \Phar $package
+ */
+ function sign(\Phar $package) {
+ $package->setSignatureAlgorithm(\Phar::OPENSSL, $this->key);
+ }
+
+ /**
+ * Export the public key to a file
+ * @param string $file
+ * @throws \pharext\Exception
+ */
+ function exportPublicKey($file) {
+ if (!file_put_contents("$file.tmp", $this->pub) || !rename("$file.tmp", $file)) {
+ throw new Exception;
+ }
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use pharext\Exception;
+
+/**
+ * The extension packaging command executed by bin/pharext
+ */
+class Packager implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Extension source directory
+ * @var pharext\SourceDir
+ */
+ private $source;
+
+ /**
+ * Cleanups
+ * @var array
+ */
+ private $cleanup = [];
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display this help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["n", "name", "Extension name",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["r", "release", "Extension release version",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["s", "source", "Extension source directory",
+ Cli\Args::REQUIRED|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["g", "git", "Use `git ls-tree` to determine file list",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["b", "branch", "Checkout this tag/branch",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["p", "pecl", "Use PECL package.xml to determine file list, name and release",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["d", "dest", "Destination directory",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG,
+ "."],
+ ["z", "gzip", "Create additional PHAR compressed with gzip",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["Z", "bzip", "Create additional PHAR compressed with bzip",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["S", "sign", "Sign the PHAR with a private key",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::REQARG],
+ ["E", "zend", "Mark as Zend Extension",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ [null, "signature", "Show pharext signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show pharext license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ]);
+ }
+
+ /**
+ * Perform cleaniup
+ */
+ function __destruct() {
+ foreach ($this->cleanup as $cleanup) {
+ $cleanup->run();
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+ try {
+ foreach (["signature", "license", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+ try {
+ /* source needs to be evaluated before Cli\Args validation,
+ * so e.g. name and version can be overriden and Cli\Args
+ * does not complain about missing arguments
+ */
+ $this->loadSource();
+ } catch (\Exception $e) {
+ $errs[] = $e->getMessage();
+ }
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ printf("\n");
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ $this->createPackage();
+ }
+
+ /**
+ * Download remote source
+ * @param string $source
+ * @return string local source
+ */
+ private function download($source) {
+ if ($this->args->git) {
+ $task = new Task\GitClone($source, $this->args->branch);
+ } else {
+ /* print newline only once */
+ $done = false;
+ $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) {
+ if (!$done) {
+ $this->info(" %3d%% [%s>%s] \r",
+ floor($bytes_pct*100),
+ str_repeat("=", round(50*$bytes_pct)),
+ str_repeat(" ", round(50*(1-$bytes_pct)))
+ );
+ if ($bytes_pct == 1) {
+ $done = true;
+ $this->info("\n");
+ }
+ }
+ });
+ }
+ $local = $task->run($this->verbosity());
+
+ $this->cleanup[] = new Task\Cleanup($local);
+ return $local;
+ }
+
+ /**
+ * Extract local archive
+ * @param stirng $source
+ * @return string extracted directory
+ */
+ private function extract($source) {
+ try {
+ $task = new Task\Extract($source);
+ $dest = $task->run($this->verbosity());
+ } catch (\Exception $e) {
+ if (false === strpos($e->getMessage(), "checksum mismatch")) {
+ throw $e;
+ }
+ $dest = (new Task\PaxFixup($source))->run($this->verbosity());
+ }
+
+ $this->cleanup[] = new Task\Cleanup($dest);
+ return $dest;
+ }
+
+ /**
+ * Localize a possibly remote source
+ * @param string $source
+ * @return string local source directory
+ */
+ private function localize($source) {
+ if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) {
+ $source = $this->download($source);
+ $this->cleanup[] = new Task\Cleanup($source);
+ }
+ $source = realpath($source);
+ if (!is_dir($source)) {
+ $source = $this->extract($source);
+ $this->cleanup[] = new Task\Cleanup($source);
+
+ if (!$this->args->git) {
+ $source = (new Task\PeclFixup($source))->run($this->verbosity());
+ }
+ }
+ return $source;
+ }
+
+ /**
+ * Load the source dir
+ * @throws \pharext\Exception
+ */
+ private function loadSource(){
+ if ($this->args["source"]) {
+ $source = $this->localize($this->args["source"]);
+
+ if ($this->args["pecl"]) {
+ $this->source = new SourceDir\Pecl($source);
+ } elseif ($this->args["git"]) {
+ $this->source = new SourceDir\Git($source);
+ } elseif (is_file("$source/pharext_package.php")) {
+ $this->source = include "$source/pharext_package.php";
+ } else {
+ $this->source = new SourceDir\Basic($source);
+ }
+
+ if (!$this->source instanceof SourceDir) {
+ throw new Exception("Unknown source dir $source");
+ }
+
+ foreach ($this->source->getPackageInfo() as $key => $val) {
+ $this->args->$key = $val;
+ }
+ }
+ }
+
+ /**
+ * Creates the extension phar
+ */
+ private function createPackage() {
+ try {
+ $meta = array_merge(Metadata::all(), [
+ "name" => $this->args->name,
+ "release" => $this->args->release,
+ "license" => $this->source->getLicense(),
+ "type" => $this->args->zend ? "zend_extension" : "extension",
+ ]);
+ $file = (new Task\PharBuild($this->source, __DIR__."/../pharext_installer.php", $meta))->run($this->verbosity());
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EBUILD);
+ }
+
+ try {
+ if ($this->args->sign) {
+ $this->info("Using private key to sign phar ...\n");
+ $pass = (new Task\Askpass)->run($this->verbosity());
+ $sign = new Task\PharSign($file, $this->args->sign, $pass);
+ $pkey = $sign->run($this->verbosity());
+ }
+
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::ESIGN);
+ }
+
+ if ($this->args->gzip) {
+ try {
+ $gzip = (new Task\PharCompress($file, Phar::GZ))->run();
+ $move = new Task\PharRename($gzip, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created gzipped phar %s\n", $name);
+
+ if ($this->args->sign) {
+ $sign = new Task\PharSign($name, $this->args->sign, $pass);
+ $sign->run($this->verbosity())->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->warn("%s\n", $e->getMessage());
+ }
+ }
+
+ if ($this->args->bzip) {
+ try {
+ $bzip = (new Task\PharCompress($file, Phar::BZ2))->run();
+ $move = new Task\PharRename($bzip, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created bzipped phar %s\n", $name);
+
+ if ($this->args->sign) {
+ $sign = new Task\PharSign($name, $this->args->sign, $pass);
+ $sign->run($this->verbosity())->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->warn("%s\n", $e->getMessage());
+ }
+ }
+
+ try {
+ $move = new Task\PharRename($file, $this->args->dest, $this->args->name ."-". $this->args->release);
+ $name = $move->run($this->verbosity());
+
+ $this->info("Created executable phar %s\n", $name);
+
+ if (isset($pkey)) {
+ $pkey->exportPublicKey($name.".pubkey");
+ }
+
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EBUILD);
+ }
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\License;
+use pharext\SourceDir;
+
+use FilesystemIterator;
+use IteratorAggregate;
+use RecursiveCallbackFilterIterator;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+
+class Basic implements IteratorAggregate, SourceDir
+{
+ use License;
+
+ private $path;
+
+ public function __construct($path) {
+ $this->path = $path;
+ }
+
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ public function getPackageInfo() {
+ return [];
+ }
+
+ public function getLicense() {
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ return "UNKNOWN";
+ }
+
+ public function getArgs() {
+ return [];
+ }
+
+ public function setArgs(Args $args) {
+ }
+
+ public function filter($current, $key, $iterator) {
+ $sub = $current->getSubPath();
+ if ($sub === ".git" || $sub === ".hg" || $sub === ".svn") {
+ return false;
+ }
+ return true;
+ }
+
+ public function getIterator() {
+ $rdi = new RecursiveDirectoryIterator($this->path,
+ FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5
+ FilesystemIterator::KEY_AS_PATHNAME |
+ FilesystemIterator::SKIP_DOTS);
+ $rci = new RecursiveCallbackFilterIterator($rdi, [$this, "filter"]);
+ $rii = new RecursiveIteratorIterator($rci);
+ foreach ($rii as $path => $child) {
+ if (!$child->isDir()) {
+ yield realpath($path);
+ }
+ }
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\License;
+use pharext\SourceDir;
+
+/**
+ * Extension source directory which is a git repo
+ */
+class Git implements \IteratorAggregate, SourceDir
+{
+ use License;
+
+ /**
+ * Base directory
+ * @var string
+ */
+ private $path;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::__construct()
+ */
+ public function __construct($path) {
+ $this->path = $path;
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getBaseDir()
+ */
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public function getPackageInfo() {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ * @return string
+ */
+ public function getLicense() {
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ return "UNKNOWN";
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public function getArgs() {
+ return [];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function setArgs(Args $args) {
+ }
+
+ /**
+ * Generate a list of files by `git ls-files`
+ * @return Generator
+ */
+ private function generateFiles() {
+ $pwd = getcwd();
+ chdir($this->path);
+ if (($pipe = popen("git ls-tree -r --name-only HEAD", "r"))) {
+ $path = realpath($this->path);
+ while (!feof($pipe)) {
+ if (strlen($file = trim(fgets($pipe)))) {
+ /* there may be symlinks, so no realpath here */
+ yield "$path/$file";
+ }
+ }
+ pclose($pipe);
+ }
+ chdir($pwd);
+ }
+
+ /**
+ * Implements IteratorAggregate
+ * @see IteratorAggregate::getIterator()
+ */
+ public function getIterator() {
+ return $this->generateFiles();
+ }
+}
+<?php
+
+namespace pharext\SourceDir;
+
+use pharext\Cli\Args;
+use pharext\Exception;
+use pharext\SourceDir;
+use pharext\License;
+
+/**
+ * A PECL extension source directory containing a v2 package.xml
+ */
+class Pecl implements \IteratorAggregate, SourceDir
+{
+ use License;
+
+ /**
+ * The package.xml
+ * @var SimpleXmlElement
+ */
+ private $sxe;
+
+ /**
+ * The base directory
+ * @var string
+ */
+ private $path;
+
+ /**
+ * The package.xml
+ * @var string
+ */
+ private $file;
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::__construct()
+ */
+ public function __construct($path) {
+ if (is_file("$path/package2.xml")) {
+ $sxe = simplexml_load_file($this->file = "$path/package2.xml");
+ } elseif (is_file("$path/package.xml")) {
+ $sxe = simplexml_load_file($this->file = "$path/package.xml");
+ } else {
+ throw new Exception("Missing package.xml in $path");
+ }
+
+ $sxe->registerXPathNamespace("pecl", $sxe->getDocNamespaces()[""]);
+
+ $this->sxe = $sxe;
+ $this->path = realpath($path);
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getBaseDir()
+ */
+ public function getBaseDir() {
+ return $this->path;
+ }
+
+ /**
+ * Retrieve gathered package info
+ * @return Generator
+ */
+ public function getPackageInfo() {
+ if (($name = $this->sxe->xpath("/pecl:package/pecl:name"))) {
+ yield "name" => (string) $name[0];
+ }
+ if (($release = $this->sxe->xpath("/pecl:package/pecl:version/pecl:release"))) {
+ yield "release" => (string) $release[0];
+ }
+ if ($this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease")) {
+ yield "zend" => true;
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @return string
+ */
+ public function getLicense() {
+ if (($license = $this->sxe->xpath("/pecl:package/pecl:license"))) {
+ if (($file = $this->findLicense($this->getBaseDir(), $license[0]["filesource"]))) {
+ return $this->readLicense($file);
+ }
+ }
+ if (($file = $this->findLicense($this->getBaseDir()))) {
+ return $this->readLicense($file);
+ }
+ if ($license) {
+ return $license[0] ." ". $license[0]["uri"];
+ }
+ return "UNKNOWN";
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::getArgs()
+ */
+ public function getArgs() {
+ $configure = $this->sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ yield [null, $cfg["name"], ucfirst($cfg["prompt"]), Args::OPTARG,
+ strlen($cfg["default"]) ? $cfg["default"] : null];
+ }
+ $configure = $this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ yield [null, $cfg["name"], ucfirst($cfg["prompt"]), Args::OPTARG,
+ strlen($cfg["default"]) ? $cfg["default"] : null];
+ }
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\SourceDir::setArgs()
+ */
+ public function setArgs(Args $args) {
+ $configure = $this->sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ if (isset($args[$cfg["name"]])) {
+ $args->configure = "--{$cfg["name"]}={$args[$cfg["name"]]}";
+ }
+ }
+ $configure = $this->sxe->xpath("/pecl:package/pecl:zendextsrcrelease/pecl:configureoption");
+ foreach ($configure as $cfg) {
+ if (isset($args[$cfg["name"]])) {
+ $args->configure = "--{$cfg["name"]}={$args[$cfg["name"]]}";
+ }
+ }
+ }
+
+ /**
+ * Compute the path of a file by parent dir nodes
+ * @param \SimpleXMLElement $ele
+ * @return string
+ */
+ private function dirOf($ele) {
+ $path = "";
+ while (($ele = current($ele->xpath(".."))) && $ele->getName() == "dir") {
+ $path = trim($ele["name"], "/") ."/". $path ;
+ }
+ return trim($path, "/");
+ }
+
+ /**
+ * Generate a list of files from the package.xml
+ * @return Generator
+ */
+ private function generateFiles() {
+ /* hook */
+ $temp = tmpfile();
+ fprintf($temp, "<?php\nreturn new %s(__DIR__);\n", get_class($this));
+ rewind($temp);
+ yield "pharext_package.php" => $temp;
+
+ /* deps */
+ $dependencies = $this->sxe->xpath("/pecl:package/pecl:dependencies/pecl:required/pecl:package");
+ foreach ($dependencies as $key => $dep) {
+ if (($glob = glob("{$this->path}/{$dep->name}-*.ext.phar*"))) {
+ usort($glob, function($a, $b) {
+ return version_compare(
+ substr($a, strpos(".ext.phar", $a)),
+ substr($b, strpos(".ext.phar", $b))
+ );
+ });
+ yield end($glob);
+ }
+ }
+
+ /* files */
+ yield realpath($this->file);
+ foreach ($this->sxe->xpath("//pecl:file") as $file) {
+ yield realpath($this->path ."/". $this->dirOf($file) ."/". $file["name"]);
+ }
+ }
+
+ /**
+ * Implements IteratorAggregate
+ * @see IteratorAggregate::getIterator()
+ */
+ public function getIterator() {
+ return $this->generateFiles();
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Source directory interface, which should yield file names to package on traversal
+ */
+interface SourceDir extends \Traversable
+{
+ /**
+ * Retrieve the base directory
+ * @return string
+ */
+ public function getBaseDir();
+
+ /**
+ * Retrieve gathered package info
+ * @return array|Traversable
+ */
+ public function getPackageInfo();
+
+ /**
+ * Retrieve the full text license
+ * @return string
+ */
+ public function getLicense();
+
+ /**
+ * Provide installer command line args
+ * @return array|Traversable
+ */
+ public function getArgs();
+
+ /**
+ * Process installer command line args
+ * @param \pharext\Cli\Args $args
+ */
+ public function setArgs(Cli\Args $args);
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+use pharext\Tempfile;
+
+/**
+ * PHP INI activation
+ */
+class Activate implements Task
+{
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @var array
+ */
+ private $inis;
+
+ /**
+ * @var string
+ */
+ private $type;
+
+ /**
+ * @var string
+ */
+ private $php_config;
+
+ /**
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ * @param string $cwd working directory
+ * @param array $inis custom INI or list of loaded/scanned INI files
+ * @param string $type extension or zend_extension
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP programs common name, e.g. php5
+ * @param string $sudo sudo command
+ * @throws \pharext\Exception
+ */
+ public function __construct($cwd, array $inis, $type = "extension", $prefix = null, $common_name = "php", $sudo = null) {
+ $this->cwd = $cwd;
+ $this->type = $type;
+ $this->sudo = $sudo;
+ if (!$this->inis = $inis) {
+ throw new Exception("No PHP INIs given");
+ }
+ $cmd = $common_name . "-config";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->php_config = $cmd;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return boolean false, if extension was already activated
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running INI activation ...\n");
+ }
+ $extension = basename(current(glob("{$this->cwd}/modules/*.so")));
+
+ if ($this->type === "zend_extension") {
+ $pattern = preg_quote((new ExecCmd($this->php_config))->run(["--extension-dir"])->getOutput() . "/$extension", "/");
+ } else {
+ $pattern = preg_quote($extension, "/");
+ }
+
+ foreach ($this->inis as $file) {
+ if ($verbose) {
+ printf("Checking %s ...\n", $file);
+ }
+ if (!file_exists($file)) {
+ throw new Exception(sprintf("INI file '%s' does not exist", $file));
+ }
+ $temp = new Tempfile("phpini");
+ foreach (file($file) as $line) {
+ if (preg_match("/^\s*{$this->type}\s*=\s*[\"']?{$pattern}[\"']?\s*(;.*)?\$/", $line)) {
+ return false;
+ }
+ fwrite($temp->getStream(), $line);
+ }
+ }
+
+ /* not found; append to last processed file, which is the main by default */
+ if ($verbose) {
+ printf("Activating in %s ...\n", $file);
+ }
+ fprintf($temp->getStream(), $this->type . "=%s\n", $extension);
+ $temp->closeStream();
+
+ $path = $temp->getPathname();
+ $stat = stat($file);
+
+ // owner transfer
+ $ugid = sprintf("%d:%d", $stat["uid"], $stat["gid"]);
+ $cmd = new ExecCmd("chown", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$ugid, $path]);
+
+ // permission transfer
+ $perm = decoct($stat["mode"] & 0777);
+ $cmd = new ExecCmd("chmod", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$perm, $path]);
+
+ // rename
+ $cmd = new ExecCmd("mv", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $cmd->run([$path, $file]);
+
+ if ($verbose) {
+ printf("Replaced %s ...\n", $file);
+ }
+
+ return true;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+/**
+ * Ask password on console
+ */
+class Askpass implements Task
+{
+ /**
+ * @var string
+ */
+ private $prompt;
+
+ /**
+ * @param string $prompt
+ */
+ public function __construct($prompt = "Password:") {
+ $this->prompt = $prompt;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string
+ */
+ public function run($verbose = false) {
+ system("stty -echo");
+ printf("%s ", $this->prompt);
+ $pass = fgets(STDIN, 1024);
+ printf("\n");
+ system("stty echo");
+ if (substr($pass, -1) == "\n") {
+ $pass = substr($pass, 0, -1);
+ }
+ return $pass;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+/**
+ * List all library files of pharext to bundle with a phar
+ */
+class BundleGenerator implements Task
+{
+ /**
+ * @param bool $verbose
+ * @return Generator
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Packaging pharext ... \n");
+ }
+ $rdi = new RecursiveDirectoryIterator(dirname(dirname(__DIR__)));
+ $rii = new RecursiveIteratorIterator($rdi);
+ for ($rii->rewind(); $rii->valid(); $rii->next()) {
+ if (!$rii->isDot()) {
+ yield $rii->getSubPathname() => $rii->key();
+ }
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use FilesystemIterator;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+/**
+ * Recursively cleanup FS entries
+ */
+class Cleanup implements Task
+{
+ /**
+ * @var string
+ */
+ private $rm;
+
+ public function __construct($rm) {
+ $this->rm = $rm;
+ }
+
+ /**
+ * @param bool $verbose
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Cleaning up %s ...\n", $this->rm);
+ }
+ if ($this->rm instanceof Tempfile) {
+ unset($this->rm);
+ } elseif (is_dir($this->rm)) {
+ $rdi = new RecursiveDirectoryIterator($this->rm,
+ FilesystemIterator::CURRENT_AS_SELF | // needed for 5.5
+ FilesystemIterator::KEY_AS_PATHNAME |
+ FilesystemIterator::SKIP_DOTS);
+ $rii = new RecursiveIteratorIterator($rdi,
+ RecursiveIteratorIterator::CHILD_FIRST);
+ foreach ($rii as $path => $child) {
+ if ($child->isDir()) {
+ @rmdir($path);
+ } else {
+ @unlink($path);
+ }
+ }
+ @rmdir($this->rm);
+ } elseif (file_exists($this->rm)) {
+ @unlink($this->rm);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+
+/**
+ * Runs extension's configure
+ */
+class Configure implements Task
+{
+ /**
+ * @var array
+ */
+ private $args;
+
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @param string $cwd working directory
+ * @param array $args configure args
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP programs common name, e.g. php5
+ */
+ public function __construct($cwd, array $args = null, $prefix = null, $common_name = "php") {
+ $this->cwd = $cwd;
+ $cmd = $common_name . "-config";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->args = ["--with-php-config=$cmd"];
+ if ($args) {
+ $this->args = array_merge($this->args, $args);
+ }
+ }
+
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running ./configure ...\n");
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd("./configure", $verbose);
+ $cmd->run($this->args);
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Archive;
+use pharext\Task;
+use pharext\Tempdir;
+
+use Phar;
+use PharData;
+
+/**
+ * Extract a package archive
+ */
+class Extract implements Task
+{
+ /**
+ * @var Phar(Data)
+ */
+ private $source;
+
+ /**
+ * @param mixed $source archive location
+ */
+ public function __construct($source) {
+ if ($source instanceof Phar || $source instanceof PharData || $source instanceof Archive) {
+ $this->source = $source;
+ } else {
+ $this->source = new PharData($source);
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempdir
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Extracting %s ...\n", basename($this->source->getPath()));
+ }
+ if ($this->source instanceof Archive) {
+ return $this->source->extract();
+ }
+ $dest = new Tempdir("extract");
+ $this->source->extractTo($dest);
+ return $dest;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\ExecCmd;
+use pharext\Task;
+use pharext\Tempdir;
+
+/**
+ * Clone a git repo
+ */
+class GitClone implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @var string
+ */
+ private $branch;
+
+ /**
+ * @param string $source git repo location
+ */
+ public function __construct($source, $branch = null) {
+ $this->source = $source;
+ $this->branch = $branch;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempdir
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
+ $local = new Tempdir("gitclone");
+ $cmd = new ExecCmd("git", $verbose);
+ if (strlen($this->branch)) {
+ $cmd->run(["clone", "--depth", 1, "--branch", $this->branch, $this->source, $local]);
+ } else {
+ $cmd->run(["clone", $this->source, $local]);
+ }
+ return $local;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\ExecCmd;
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Run make in the source dir
+ */
+class Make implements Task
+{
+ /**
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @var array
+ */
+ private $args;
+
+ /**
+ * @var string
+ */
+ private $sudo;
+
+ /**
+ *
+ * @param string $cwd working directory
+ * @param array $args make's arguments
+ * @param string $sudo sudo command
+ */
+ public function __construct($cwd, array $args = null, $sudo = null) {
+ $this->cwd = $cwd;
+ $this->sudo = $sudo;
+ $this->args = $args;
+ }
+
+ /**
+ *
+ * @param bool $verbose
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running make");
+ if ($this->args) {
+ foreach ($this->args as $arg) {
+ printf(" %s", $arg);
+ }
+ }
+ printf(" ...\n");
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd("make", $verbose);
+ if (isset($this->sudo)) {
+ $cmd->setSu($this->sudo);
+ }
+ $args = $this->args;
+ if (!$verbose) {
+ $args = array_merge((array) $args, ["-s"]);
+ }
+ $cmd->run($args);
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+use pharext\Tempfile;
+
+class PaxFixup implements Task
+{
+ private $source;
+
+ public function __construct($source) {
+ $this->source = $source;
+ }
+
+ private function openArchive($source) {
+ $hdr = file_get_contents($source, false, null, 0, 3);
+ if ($hdr === "\x1f\x8b\x08") {
+ $fd = fopen("compress.zlib://$source", "r");
+ } elseif ($hdr === "BZh") {
+ $fd = fopen("compress.bzip2://$source", "r");
+ } else {
+ $fd = fopen($source, "r");
+ }
+ if (!is_resource($fd)) {
+ throw new Exception;
+ }
+ return $fd;
+ }
+
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fixing up a tarball with global pax header ...\n");
+ }
+ $temp = new Tempfile("paxfix");
+ stream_copy_to_stream($this->openArchive($this->source),
+ $temp->getStream(), -1, 1024);
+ $temp->closeStream();
+ return (new Extract((string) $temp))->run($verbose);
+ }
+}<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Fixup package.xml files in an extracted PECL dir
+ */
+class PeclFixup implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @param string $source source directory
+ */
+ public function __construct($source) {
+ $this->source = $source;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string sanitized source location
+ * @throws \pahrext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Sanitizing PECL dir ...\n");
+ }
+ $dirs = glob("{$this->source}/*", GLOB_ONLYDIR);
+ $files = array_diff(glob("{$this->source}/*"), $dirs);
+ $check = array_reduce($files, function($r, $v) {
+ return $v && fnmatch("package*.xml", basename($v));
+ }, true);
+
+ if (count($dirs) !== 1 || !$check) {
+ throw new Exception("Does not look like an extracted PECL dir: {$this->source}");
+ }
+
+ $dest = current($dirs);
+
+ foreach ($files as $file) {
+ if ($verbose) {
+ printf("Moving %s into %s ...\n", basename($file), basename($dest));
+ }
+ if (!rename($file, "$dest/" . basename($file))) {
+ throw new Exception;
+ }
+ }
+
+ return $dest;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\SourceDir;
+use pharext\Task;
+use pharext\Tempname;
+
+use Phar;
+
+/**
+ * Build phar
+ */
+class PharBuild implements Task
+{
+ /**
+ * @var \pharext\SourceDir
+ */
+ private $source;
+
+ /**
+ * @var string
+ */
+ private $stub;
+
+ /**
+ * @var array
+ */
+ private $meta;
+
+ /**
+ * @var bool
+ */
+ private $readonly;
+
+ /**
+ * @param SourceDir $source extension source directory
+ * @param string $stub path to phar stub
+ * @param array $meta phar meta data
+ * @param bool $readonly whether the stub has -dphar.readonly=1 set
+ */
+ public function __construct(SourceDir $source = null, $stub, array $meta = null, $readonly = true) {
+ $this->source = $source;
+ $this->stub = $stub;
+ $this->meta = $meta;
+ $this->readonly = $readonly;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Tempname
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ /* Phar::compress() and ::convert*() use strtok("."), ugh!
+ * so, be sure to not use any other dots in the filename
+ * except for .phar
+ */
+ $temp = new Tempname("", "-pharext.phar");
+
+ $phar = new Phar($temp);
+ $phar->startBuffering();
+
+ if ($this->meta) {
+ $phar->setMetadata($this->meta);
+ }
+ if ($this->stub) {
+ (new PharStub($phar, $this->stub))->run($verbose);
+ }
+
+ $phar->buildFromIterator((new Task\BundleGenerator)->run());
+
+ if ($this->source) {
+ if ($verbose) {
+ $bdir = $this->source->getBaseDir();
+ $blen = strlen($bdir);
+ foreach ($this->source as $index => $file) {
+ if (is_resource($file)) {
+ printf("Packaging %s ...\n", $index);
+ $phar[$index] = $file;
+ } else {
+ printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/"));
+ $phar->addFile($file, $index);
+ }
+ }
+ } else {
+ $phar->buildFromIterator($this->source, $this->source->getBaseDir());
+ }
+ }
+
+ $phar->stopBuffering();
+
+ if (!chmod($temp, fileperms($temp) | 0111)) {
+ throw new Exception;
+ }
+
+ return $temp;
+ }
+}<?php
+
+namespace pharext\Task;
+
+use pharext\Task;
+
+use Phar;
+
+/**
+ * Clone a compressed copy of a phar
+ */
+class PharCompress implements Task
+{
+ /**
+ * @var string
+ */
+ private $file;
+
+ /**
+ * @var Phar
+ */
+ private $package;
+
+ /**
+ * @var int
+ */
+ private $encoding;
+
+ /**
+ * @var string
+ */
+ private $extension;
+
+ /**
+ * @param string $file path to the original phar
+ * @param int $encoding Phar::GZ or Phar::BZ2
+ */
+ public function __construct($file, $encoding) {
+ $this->file = $file;
+ $this->package = new Phar($file);
+ $this->encoding = $encoding;
+
+ switch ($encoding) {
+ case Phar::GZ:
+ $this->extension = ".gz";
+ break;
+ case Phar::BZ2:
+ $this->extension = ".bz2";
+ break;
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Compressing %s ...\n", basename($this->package->getPath()));
+ }
+ /* stop shebang */
+ $stub = $this->package->getStub();
+ $phar = $this->package->compress($this->encoding);
+ $phar->setStub(substr($stub, strpos($stub, "\n")+1));
+ return $this->file . $this->extension;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Rename the phar archive
+ */
+class PharRename implements Task
+{
+ /**
+ * @var string
+ */
+ private $phar;
+
+ /**
+ * @var string
+ */
+ private $dest;
+
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $phar path to phar
+ * @param string $dest destination dir
+ * @param string $name package name
+ */
+ public function __construct($phar, $dest, $name) {
+ $this->phar = $phar;
+ $this->dest = $dest;
+ $this->name = $name;
+ }
+
+ /**
+ * @param bool $verbose
+ * @return string path to renamed phar
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ $extension = substr(strstr($this->phar, "-pharext.phar"), 8);
+ $name = sprintf("%s/%s.ext%s", $this->dest, $this->name, $extension);
+
+ if ($verbose) {
+ printf("Renaming %s to %s ...\n", basename($this->phar), basename($name));
+ }
+
+ if (!rename($this->phar, $name)) {
+ throw new Exception;
+ }
+
+ return $name;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Openssl;
+use pharext\Task;
+
+use Phar;
+
+/**
+ * Sign the phar with a private key
+ */
+class PharSign implements Task
+{
+ /**
+ * @var Phar
+ */
+ private $phar;
+
+ /**
+ * @var \pharext\Openssl\PrivateKey
+ */
+ private $pkey;
+
+ /**
+ *
+ * @param mixed $phar phar instance or path to phar
+ * @param string $pkey path to private key
+ * @param string $pass password for the private key
+ */
+ public function __construct($phar, $pkey, $pass) {
+ if ($phar instanceof Phar || $phar instanceof PharData) {
+ $this->phar = $phar;
+ } else {
+ $this->phar = new Phar($phar);
+ }
+ $this->pkey = new Openssl\PrivateKey($pkey, $pass);
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Openssl\PrivateKey
+ */
+ public function run($verbose = false) {
+ if ($verbose) {
+ printf("Signing %s ...\n", basename($this->phar->getPath()));
+ }
+ $this->pkey->sign($this->phar);
+ return $this->pkey;
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use Phar;
+use pharext\Exception;
+use pharext\Task;
+
+/**
+ * Set the phar's stub
+ */
+class PharStub implements Task
+{
+ /**
+ * @var \Phar
+ */
+ private $phar;
+
+ /**
+ * @var string
+ */
+ private $stub;
+
+ /**
+ * @param \Phar $phar
+ * @param string $stub file path to the stub
+ * @throws \pharext\Exception
+ */
+ function __construct(Phar $phar, $stub) {
+ $this->phar = $phar;
+ if (!file_exists($this->stub = $stub)) {
+ throw new Exception("File '$stub' does not exist");
+ }
+ }
+
+ /**
+ * @param bool $verbose
+ */
+ function run($verbose = false) {
+ if ($verbose) {
+ printf("Using stub '%s'...\n", basename($this->stub));
+ }
+ $stub = preg_replace_callback('/^#include <([^>]+)>/m', function($includes) {
+ return file_get_contents($includes[1], true, null, 5);
+ }, file_get_contents($this->stub));
+ if ($this->phar->isCompressed() && substr($stub, 0, 2) === "#!") {
+ $stub = substr($stub, strpos($stub, "\n")+1);
+ }
+ $this->phar->setStub($stub);
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\ExecCmd;
+use pharext\Task;
+
+/**
+ * Run phpize in the extension source directory
+ */
+class Phpize implements Task
+{
+ /**
+ * @var string
+ */
+ private $phpize;
+
+ /**
+ *
+ * @var string
+ */
+ private $cwd;
+
+ /**
+ * @param string $cwd working directory
+ * @param string $prefix install prefix, e.g. /usr/local
+ * @param string $common_name PHP program common name, e.g. php5
+ */
+ public function __construct($cwd, $prefix = null, $common_name = "php") {
+ $this->cwd = $cwd;
+ $cmd = $common_name . "ize";
+ if (isset($prefix)) {
+ $cmd = $prefix . "/bin/" . $cmd;
+ }
+ $this->phpize = $cmd;
+ }
+
+ /**
+ * @param bool $verbose
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Running %s ...\n", $this->phpize);
+ }
+ $pwd = getcwd();
+ if (!chdir($this->cwd)) {
+ throw new Exception;
+ }
+ try {
+ $cmd = new ExecCmd($this->phpize, $verbose);
+ $cmd->run();
+ } finally {
+ chdir($pwd);
+ }
+ }
+}
+<?php
+
+namespace pharext\Task;
+
+use pharext\Exception;
+use pharext\Task;
+use pharext\Tempfile;
+
+/**
+ * Fetch a remote archive
+ */
+class StreamFetch implements Task
+{
+ /**
+ * @var string
+ */
+ private $source;
+
+ /**
+ * @var callable
+ */
+ private $progress;
+
+ /**
+ * @param string $source remote file location
+ * @param callable $progress progress callback
+ */
+ public function __construct($source, callable $progress) {
+ $this->source = $source;
+ $this->progress = $progress;
+ }
+
+ private function createStreamContext() {
+ $progress = $this->progress;
+
+ /* avoid bytes_max bug of older PHP versions */
+ $maxbytes = 0;
+ return stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) use($progress, &$maxbytes) {
+ if ($bytes_max > $maxbytes) {
+ $maxbytes = $bytes_max;
+ }
+ switch ($notification) {
+ case STREAM_NOTIFY_CONNECT:
+ $progress(0);
+ break;
+ case STREAM_NOTIFY_PROGRESS:
+ $progress($maxbytes > 0 ? $bytes_cur/$maxbytes : .5);
+ break;
+ case STREAM_NOTIFY_COMPLETED:
+ /* this is sometimes not generated, why? */
+ $progress(1);
+ break;
+ }
+ }]);
+ }
+
+ /**
+ * @param bool $verbose
+ * @return \pharext\Task\Tempfile
+ * @throws \pharext\Exception
+ */
+ public function run($verbose = false) {
+ if ($verbose !== false) {
+ printf("Fetching %s ...\n", $this->source);
+ }
+ $context = $this->createStreamContext();
+
+ if (!$remote = fopen($this->source, "r", false, $context)) {
+ throw new Exception;
+ }
+
+ $local = new Tempfile("remote");
+ if (!stream_copy_to_stream($remote, $local->getStream())) {
+ throw new Exception;
+ }
+ $local->closeStream();
+
+ /* STREAM_NOTIFY_COMPLETED is not generated, see above */
+ call_user_func($this->progress, 1);
+
+ return $local;
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Simple task interface
+ */
+interface Task
+{
+ public function run($verbose = false);
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Create a temporary directory
+ */
+class Tempdir extends \SplFileInfo
+{
+ /**
+ * @param string $prefix prefix to uniqid()
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix) {
+ $temp = new Tempname($prefix);
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception("Could not create tempdir: ".error_get_last()["message"]);
+ }
+ parent::__construct($temp);
+ }
+}
+<?php
+
+namespace pharext;
+
+/**
+ * Create a new temporary file
+ */
+class Tempfile extends \SplFileInfo
+{
+ /**
+ * @var resource
+ */
+ private $handle;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ * @throws \pharext\Exception
+ */
+ public function __construct($prefix, $suffix = ".tmp") {
+ $tries = 0;
+ $omask = umask(077);
+ do {
+ $path = new Tempname($prefix, $suffix);
+ $this->handle = fopen($path, "x");
+ } while (!is_resource($this->handle) && $tries++ < 10);
+ umask($omask);
+
+ if (!is_resource($this->handle)) {
+ throw new Exception("Could not create temporary file");
+ }
+
+ parent::__construct($path);
+ }
+
+ /**
+ * Unlink the file
+ */
+ public function __destruct() {
+ if (is_file($this->getPathname())) {
+ @unlink($this->getPathname());
+ }
+ }
+
+ /**
+ * Close the stream
+ */
+ public function closeStream() {
+ fclose($this->handle);
+ }
+
+ /**
+ * Retrieve the stream resource
+ * @return resource
+ */
+ public function getStream() {
+ return $this->handle;
+ }
+}
+<?php
+
+namespace pharext;
+
+use pharext\Exception;
+
+/**
+ * A temporary file/directory name
+ */
+class Tempname
+{
+ /**
+ * @var string
+ */
+ private $name;
+
+ /**
+ * @param string $prefix uniqid() prefix
+ * @param string $suffix e.g. file extension
+ */
+ public function __construct($prefix, $suffix = null) {
+ $temp = sys_get_temp_dir() . "/pharext-" . $this->getUser();
+ if (!is_dir($temp) && !mkdir($temp, 0700, true)) {
+ throw new Exception;
+ }
+ $this->name = $temp ."/". uniqid($prefix) . $suffix;
+ }
+
+ private function getUser() {
+ if (extension_loaded("posix") && function_exists("posix_getpwuid")) {
+ return posix_getpwuid(posix_getuid())["name"];
+ }
+ return trim(`whoami 2>/dev/null`)
+ ?: trim(`id -nu 2>/dev/null`)
+ ?: getenv("USER")
+ ?: get_current_user();
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString() {
+ return (string) $this->name;
+ }
+}
+<?php
+
+namespace pharext;
+
+use Phar;
+use PharFileInfo;
+use SplFileInfo;
+use pharext\Exception;
+
+class Updater implements Command
+{
+ use Cli\Command;
+
+ /**
+ * Create the command
+ */
+ public function __construct() {
+ $this->args = new Cli\Args([
+ ["h", "help", "Display this help",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ ["v", "verbose", "More output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ ["q", "quiet", "Less output",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG],
+ [null, "signature", "Show pharext signature",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "license", "Show pharext license",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [null, "version", "Show pharext version",
+ Cli\Args::OPTIONAL|Cli\Args::SINGLE|Cli\Args::NOARG|Cli\Args::HALT],
+ [0, "path", "Path to .ext.phar to update",
+ Cli\Args::REQUIRED|Cli\Args::MULTI],
+ ]);
+ }
+
+ /**
+ * @inheritdoc
+ * @see \pharext\Command::run()
+ */
+ public function run($argc, array $argv) {
+ $errs = [];
+ $prog = array_shift($argv);
+ foreach ($this->args->parse(--$argc, $argv) as $error) {
+ $errs[] = $error;
+ }
+
+ if ($this->args["help"]) {
+ $this->header();
+ $this->help($prog);
+ exit;
+ }
+
+ try {
+ foreach (["signature", "license", "version"] as $opt) {
+ if ($this->args[$opt]) {
+ printf("%s\n", $this->metadata($opt));
+ exit;
+ }
+ }
+ } catch (\Exception $e) {
+ $this->error("%s\n", $e->getMessage());
+ exit(self::EARGS);
+ }
+
+
+ foreach ($this->args->validate() as $error) {
+ $errs[] = $error;
+ }
+
+ if ($errs) {
+ if (!$this->args["quiet"]) {
+ $this->header();
+ }
+ foreach ($errs as $err) {
+ $this->error("%s\n", $err);
+ }
+ printf("\n");
+ if (!$this->args["quiet"]) {
+ $this->help($prog);
+ }
+ exit(self::EARGS);
+ }
+
+ foreach ($this->args[0] as $file) {
+ $info = new SplFileInfo($file);
+
+ while ($info->isLink()) {
+ $info = new SplFileInfo($info->getLinkTarget());
+ }
+
+ if ($info->isFile()) {
+ if (!$this->updatePackage($info)) {
+ $this->warn("Cannot upgrade pre-v3 packages\n");
+ }
+ } else {
+ $this->error("File '%s' does not exist\n", $file);
+ exit(self::EARGS);
+ }
+ }
+ }
+
+ /**
+ * Replace the pharext core in an .ext.phar package
+ * @param string $temp path to temp phar
+ * @return boolean FALSE if the package is too old (pre-v3) to upgrade
+ */
+ private function replacePharext($temp) {
+ $phar = new Phar($temp, Phar::CURRENT_AS_SELF);
+ $phar->startBuffering();
+
+ if (!$meta = $phar->getMetadata()) {
+ // don't upgrade pre-v3 packages
+ return false;
+ }
+
+ // replace current pharext files
+ $core = (new Task\BundleGenerator)->run($this->verbosity());
+ $phar->buildFromIterator($core);
+ $stub = __DIR__."/../pharext_installer.php";
+ (new Task\PharStub($phar, $stub))->run($this->verbosity());
+
+ // check dependencies
+ foreach ($phar as $info) {
+ if (fnmatch("*.ext.phar*", $info->getBasename())) {
+ $this->updatePackage($info, $phar);
+ }
+ }
+
+ $phar->stopBuffering();
+
+ $phar->setMetadata([
+ "version" => Metadata::version(),
+ "header" => Metadata::header(),
+ ] + $meta);
+
+ $this->info("Updated pharext version from '%s' to '%s'\n",
+ isset($meta["version"]) ? $meta["version"] : "(unknown)",
+ $phar->getMetadata()["version"]);
+
+ return true;
+ }
+
+ /**
+ * Update an .ext.phar package to the current pharext version
+ * @param SplFileInfo $file
+ * @param Phar $phar the parent phar containing $file as dependency
+ * @return boolean FALSE if the package is too old (pre-v3) to upgrade
+ * @throws Exception
+ */
+ private function updatePackage(SplFileInfo $file, Phar $phar = null) {
+ $this->info("Updating pharext core in '%s'...\n", basename($file));
+
+ $temp = new Tempname("update", substr(strstr($file, ".ext.phar"), 4));
+
+ if (!copy($file->getPathname(), $temp)) {
+ throw new Exception;
+ }
+ if (!chmod($temp, $file->getPerms())) {
+ throw new Exception;
+ }
+
+ if (!$this->replacePharext($temp)) {
+ return false;
+ }
+
+ if ($phar) {
+ $phar->addFile($temp, $file);
+ } elseif (!rename($temp, $file->getPathname())) {
+ throw new Exception;
+ }
+
+ return true;
+ }
+}
+#!/usr/bin/env php
+<?php
+
+/**
+ * The installer sub-stub for extension phars
+ */
+
+namespace pharext;
+
+define("PHAREXT_PHAR", __FILE__);
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+#include <pharext/Exception.php>
+#include <pharext/Tempname.php>
+#include <pharext/Tempfile.php>
+#include <pharext/Tempdir.php>
+#include <pharext/Archive.php>
+
+namespace pharext;
+
+if (extension_loaded("Phar")) {
+ \Phar::interceptFileFuncs();
+ \Phar::mapPhar();
+ $phardir = "phar://".__FILE__;
+} else {
+ $archive = new Archive(__FILE__);
+ $phardir = $archive->extract();
+}
+
+set_include_path("$phardir:". get_include_path());
+
+$installer = new Installer();
+$installer->run($argc, $argv);
+
+__HALT_COMPILER();
+#!/usr/bin/php -dphar.readonly=0
+<?php
+
+/**
+ * The packager sub-stub for bin/pharext
+ */
+
+namespace pharext;
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+set_include_path('phar://' . __FILE__ .":". get_include_path());
+
+if (!extension_loaded("Phar")) {
+ fprintf(STDERR, "ERROR: Phar extension not loaded\n\n");
+ fprintf(STDERR, "\tPlease load the phar extension in your php.ini\n".
+ "\tor rebuild PHP with the --enable-phar flag.\n\n");
+ exit(1);
+}
+
+if (ini_get("phar.readonly")) {
+ fprintf(STDERR, "ERROR: Phar is configured read-only\n\n");
+ fprintf(STDERR, "\tPlease specify phar.readonly=0 in your php.ini\n".
+ "\tor run this command with php -dphar.readonly=0\n\n");
+ exit(1);
+}
+
+\Phar::interceptFileFuncs();
+\Phar::mapPhar();
+
+$packager = new Packager();
+$packager->run($argc, $argv);
+
+__HALT_COMPILER();
+#!/usr/bin/php -dphar.readonly=0
+<?php
+
+/**
+ * The installer updater stub for extension phars
+ */
+
+namespace pharext;
+
+spl_autoload_register(function($c) {
+ return include strtr($c, "\\_", "//") . ".php";
+});
+
+set_include_path('phar://' . __FILE__ .":". get_include_path());
+
+if (!extension_loaded("Phar")) {
+ fprintf(STDERR, "ERROR: Phar extension not loaded\n\n");
+ fprintf(STDERR, "\tPlease load the phar extension in your php.ini\n".
+ "\tor rebuild PHP with the --enable-phar flag.\n\n");
+ exit(1);
+}
+
+if (ini_get("phar.readonly")) {
+ fprintf(STDERR, "ERROR: Phar is configured read-only\n\n");
+ fprintf(STDERR, "\tPlease specify phar.readonly=0 in your php.ini\n".
+ "\tor run this command with php -dphar.readonly=0\n\n");
+ exit(1);
+}
+
+\Phar::interceptFileFuncs();
+\Phar::mapPhar();
+
+$updater = new Updater();
+$updater->run($argc, $argv);
+
+__HALT_COMPILER();
+; see http://editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = tab
+charset = utf-8
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.json]
+indent_style = space
+indent_size = 4
+
+[package.xml]
+indent_style = space
+indent_size = 1
+
+[config.w32]
+end_of_line = crlf
+package.xml merge=touch
+php_raphf.h merge=touch
+config.w32 eol=crlf
+
+# /
+*~
+/*.tgz
+/.deps
+*.lo
+*.la
+/config.[^mw]*
+/configure*
+/lib*
+/ac*.m4
+/ltmain.sh
+/install-sh
+/Make*
+/mk*
+/missing
+/.libs
+/build
+/include
+/modules
+/autom4te*
+/.dep.inc
+run-tests.php
+/.cproject
+/.project
+.libs/
+/php_raphf_api.h
+Doxyfile.bak
+!/Makefile.frag
+[submodule "travis-pecl"]
+ path = travis/pecl
+ url = https://github.com/m6w6/travis-pecl.git
+ branch = master
+# autogenerated file; do not edit
+sudo: false
+language: c
+
+addons:
+ apt:
+ packages:
+ - php5-cli
+ - php-pear
+
+env:
+ matrix:
+ - PHP=master enable_debug=no enable_maintainer_zts=no
+ - PHP=master enable_debug=yes enable_maintainer_zts=no
+ - PHP=master enable_debug=no enable_maintainer_zts=yes
+ - PHP=master enable_debug=yes enable_maintainer_zts=yes
+
+before_script:
+ - make -f travis/pecl/Makefile php
+ - make -f travis/pecl/Makefile ext PECL=raphf
+
+script:
+ - make -f travis/pecl/Makefile test
+Michael Wallner <mike@php.net>
+Yay, now known and unresolved issues yet!
+# Contributor Code of Conduct
+
+As contributors and maintainers of this project, and in the interest of
+fostering an open and welcoming community, we pledge to respect all people who
+contribute through reporting issues, posting feature requests, updating
+documentation, submitting pull requests or patches, and other activities.
+
+We are committed to making participation in this project a harassment-free
+experience for everyone, regardless of level of experience, gender, gender
+identity and expression, sexual orientation, disability, personal appearance,
+body size, race, ethnicity, age, religion, or nationality.
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery
+* Personal attacks
+* Trolling or insulting/derogatory comments
+* Public or private harassment
+* Publishing other's private information, such as physical or electronic
+ addresses, without explicit permission
+* Other unethical or unprofessional conduct.
+
+Project maintainers have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct. By adopting this Code of Conduct, project
+maintainers commit themselves to fairly and consistently applying these
+principles to every aspect of managing this project. Project maintainers who do
+not follow or enforce the Code of Conduct may be permanently removed from the
+project team.
+
+This code of conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community.
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by opening an issue or contacting one or more of the project maintainers.
+
+This Code of Conduct is adapted from the
+[Contributor Covenant](http://contributor-covenant.org), version 1.2.0,
+available at http://contributor-covenant.org/version/1/2/0/.
+raphf
+Michael Wallner
+# Doxyfile 1.8.10
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = "Resource and persistent handle factory API"
+PROJECT_NUMBER =
+PROJECT_BRIEF = "A facility to manage possibly persistent resources with a comprehensible API. Provides simliar functionality like the zend_list API, but with more flexiblity and freedom."
+PROJECT_LOGO = raphf.png
+OUTPUT_DIRECTORY =
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH =
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+TCL_SUBST =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+EXTENSION_MAPPING = no_extension=md
+MARKDOWN_SUPPORT = YES
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+GROUP_NESTED_COMPOUNDS = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = YES
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = YES
+EXTRACT_PRIVATE = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+HIDE_COMPOUND_REFERENCE= NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = README.md CONTRIBUTING.md php_raphf.h src
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS =
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE = README.md
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = .
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES = BUGS CONTRIBUTING.md LICENSE THANKS TODO
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = NO
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = YES
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED = DOXYGEN \
+ TSRMLS_C= \
+ TSRMLS_D= \
+ TSRMLS_CC= \
+ TSRMLS_DC= \
+ PHP_RAPHF_API=
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+MSCGEN_PATH =
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = NO
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = YES
+CALLER_GRAPH = YES
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+Copyright (c) 2013, Michael Wallner <mike@php.net>.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# provide headers in builddir, so they do not end up in /usr/include/ext/raphf/src
+
+PHP_RAPHF_HEADERS := $(addprefix $(PHP_RAPHF_BUILDDIR)/,$(PHP_RAPHF_HEADERS))
+
+$(PHP_RAPHF_BUILDDIR)/%.h: $(PHP_RAPHF_SRCDIR)/src/%.h
+ @cat >$@ <$<
+
+$(all_targets): raphf-build-headers
+clean: raphf-clean-headers
+
+.PHONY: raphf-build-headers
+raphf-build-headers: $(PHP_RAPHF_HEADERS)
+
+.PHONY: raphf-clean-headers
+raphf-clean-headers:
+ -rm -f $(PHP_RAPHF_HEADERS)
+# ext-raphf
+
+[![Build Status](https://travis-ci.org/m6w6/ext-raphf.svg?branch=master)](https://travis-ci.org/m6w6/ext-raphf)
+
+The "Resource and Persistent Handle Factory" extension provides facilities to manage those in a convenient manner.
+
+## Documentation
+
+See the [online markdown reference](https://mdref.m6w6.name/raphf).
+
+Known issues are listed in [BUGS](./BUGS) and future ideas can be found in [TODO](./TODO).
+
+## Installing
+
+### PECL
+
+ pecl install raphf
+
+### PHARext
+
+Watch out for [PECL replicates](https://replicator.pharext.org?raphf)
+and pharext packages attached to [releases](./releases).
+
+### Checkout
+
+ git clone github.com:m6w6/ext-raphf
+ cd ext-raphf
+ /path/to/phpize
+ ./configure --with-php-config=/path/to/php-config
+ make
+ sudo make install
+
+## ChangeLog
+
+A comprehensive list of changes can be obtained from the
+[PECL website](https://pecl.php.net/package-changelog.php?package=raphf).
+
+## License
+
+ext-raphf is licensed under the 2-Clause-BSD license, which can be found in
+the accompanying [LICENSE](./LICENSE) file.
+
+## Contributing
+
+All forms of contribution are welcome! Please see the bundled
+[CONTRIBUTING](./CONTRIBUTING.md) note for the general principles followed.
+
+The list of past and current contributors is maintained in [THANKS](./THANKS).
+Thanks go to the following people, who have contributed to this project:
+
+Anatol Belski
+Remi Collet
+* TTL
+sinclude(config0.m4)
+ARG_ENABLE("raphf", "for raphf support", "no");\r
+\r
+if (PHP_RAPHF == "yes") {\r
+ var PHP_RAPHF_HEADERS=glob("src/*.h"), PHP_RAPHF_SOURCES=glob("src/*.c");\r
+\r
+ EXTENSION("raphf", PHP_RAPHF_SOURCES);\r
+ PHP_INSTALL_HEADERS("ext/raphf", "php_propro.h");\r
+ for (var i=0; i<PHP_RAPHF_HEADERS.length; ++i) {\r
+ var basename = FSO.GetFileName(PHP_RAPHF_HEADERS[i]);\r
+ copy_and_subst(PHP_RAPHF_HEADERS[i], basename, []);\r
+ PHP_INSTALL_HEADERS("ext/raphf", basename);\r
+ }\r
+\r
+ AC_DEFINE("HAVE_RAPHF", 1);\r
+}\r
+PHP_ARG_ENABLE(raphf, whether to enable raphf support,
+[ --enable-raphf Enable resource and persistent handles factory support])
+
+if test "$PHP_RAPHF" != "no"; then
+ PHP_RAPHF_SRCDIR=PHP_EXT_SRCDIR(raphf)
+ PHP_RAPHF_BUILDDIR=PHP_EXT_BUILDDIR(raphf)
+
+ PHP_ADD_INCLUDE($PHP_RAPHF_SRCDIR/src)
+ PHP_ADD_BUILD_DIR($PHP_RAPHF_BUILDDIR/src)
+
+ PHP_RAPHF_HEADERS=`(cd $PHP_RAPHF_SRCDIR/src && echo *.h)`
+ PHP_RAPHF_SOURCES=`(cd $PHP_RAPHF_SRCDIR && echo src/*.c)`
+
+ PHP_NEW_EXTENSION(raphf, $PHP_RAPHF_SOURCES, $ext_shared)
+ PHP_INSTALL_HEADERS(ext/raphf, php_raphf.h $PHP_RAPHF_HEADERS)
+
+ PHP_SUBST(PHP_RAPHF_HEADERS)
+ PHP_SUBST(PHP_RAPHF_SOURCES)
+
+ PHP_SUBST(PHP_RAPHF_SRCDIR)
+ PHP_SUBST(PHP_RAPHF_BUILDDIR)
+
+ PHP_ADD_MAKEFILE_FRAGMENT
+fi
+<?xml version="1.0" encoding="UTF-8"?>
+<package
+ packagerversion="1.4.11"
+ version="2.0"
+ xmlns="http://pear.php.net/dtd/package-2.0"
+ xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>raphf</name>
+ <channel>pecl.php.net</channel>
+ <summary>Resource and persistent handles factory</summary>
+ <description>A reusable split-off of pecl_http's persistent handle and resource factory API.</description>
+ <lead>
+ <name>Michael Wallner</name>
+ <user>mike</user>
+ <email>mike@php.net</email>
+ <active>yes</active>
+ </lead>
+ <date>2015-12-01</date>
+ <version>
+ <release>2.0.0RC1</release>
+ <api>2.0.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>stable</api>
+ </stability>
+ <license>BSD, revised</license>
+ <notes><![CDATA[
+* Internals documentation available at http://m6w6.github.io/ext-raphf/master/
+* Travis support
+* PHP 7 compatible version
+]]></notes>
+ <contents>
+ <dir name="/">
+ <file role="doc" name="AUTHORS"/>
+ <file role="doc" name="BUGS"/>
+ <file role="doc" name="CONTRIBUTING.md"/>
+ <file role="doc" name="CREDITS"/>
+ <file role="doc" name="LICENSE"/>
+ <file role="doc" name="README.md"/>
+ <file role="doc" name="THANKS"/>
+ <file role="doc" name="TODO"/>
+ <file role="doc" name="Doxyfile"/>
+ <file role="src" name="config.m4"/>
+ <file role="src" name="config0.m4"/>
+ <file role="src" name="config.w32"/>
+ <file role="src" name="Makefile.frag"/>
+ <file role="src" name="php_raphf.h"/>
+ <dir name="src">
+ <file role="src" name="php_raphf_api.h"/>
+ <file role="src" name="php_raphf_api.c"/>
+ </dir>
+ <dir name="scripts">
+ <file role="src" name="gen_travis_yml.php"/>
+ </dir>
+ <dir name="tests">
+ <file role="test" name="http001.phpt" />
+ <file role="test" name="http002.phpt" />
+ <file role="test" name="http003.phpt" />
+ <file role="test" name="http004.phpt" />
+ </dir>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>7.0.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <providesextension>raphf</providesextension>
+ <extsrcrelease/>
+</package>
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: raphf |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_RAPHF_H
+#define PHP_RAPHF_H
+
+extern zend_module_entry raphf_module_entry;
+#define phpext_raphf_ptr &raphf_module_entry
+
+#define PHP_RAPHF_VERSION "2.0.0RC1"
+
+#ifdef PHP_WIN32
+# define PHP_RAPHF_API __declspec(dllexport)
+#elif defined(__GNUC__) && __GNUC__ >= 4
+# define PHP_RAPHF_API extern __attribute__ ((visibility("default")))
+#else
+# define PHP_RAPHF_API extern
+#endif
+
+#ifdef ZTS
+# include "TSRM.h"
+#endif
+
+#include "php_raphf_api.h"
+
+#endif /* PHP_RAPHF_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: raphf |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2014, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#include <php.h>
+
+struct user_cb {
+ zend_fcall_info fci;
+ zend_fcall_info_cache fcc;
+};
+
+struct raphf_user {
+ struct user_cb ctor;
+ struct user_cb copy;
+ struct user_cb dtor;
+ struct {
+ struct user_cb dtor;
+ zval data;
+ } data;
+};
+
+static inline void user_cb_addref(struct user_cb *cb)
+{
+ Z_ADDREF(cb->fci.function_name);
+ if (cb->fci.object) {
+ Z_ADDREF_P((zval *) cb->fci.object);
+ }
+}
+
+static inline void user_cb_delref(struct user_cb *cb)
+{
+ if (cb->fci.object) {
+ Z_DELREF_P((zval *) cb->fci.object);
+ }
+}
+
+static void raphf_user_dtor(void *opaque)
+{
+ struct raphf_user *ru = opaque;
+
+ zend_fcall_info_argn(&ru->data.dtor.fci, 1, &ru->data.data);
+ zend_fcall_info_call(&ru->data.dtor.fci, &ru->data.dtor.fcc, NULL, NULL);
+ zend_fcall_info_args_clear(&ru->data.dtor.fci, 1);
+ user_cb_delref(&ru->data.dtor);
+ zend_fcall_info_args_clear(&ru->ctor.fci, 1);
+ user_cb_delref(&ru->ctor);
+ zend_fcall_info_args_clear(&ru->copy.fci, 1);
+ user_cb_delref(&ru->copy);
+ zend_fcall_info_args_clear(&ru->dtor.fci, 1);
+ user_cb_delref(&ru->dtor);
+ memset(ru, 0, sizeof(*ru));
+ efree(ru);
+}
+
+static void *user_ctor(void *opaque, void *init_arg TSRMLS_DC)
+{
+ struct raphf_user *ru = opaque;
+ zval *zinit_arg = init_arg, *retval = ecalloc(1, sizeof(*retval));
+
+ zend_fcall_info_argn(&ru->ctor.fci, 2, &ru->data.data, zinit_arg);
+ zend_fcall_info_call(&ru->ctor.fci, &ru->ctor.fcc, retval, NULL);
+ zend_fcall_info_args_clear(&ru->ctor.fci, 0);
+
+ return retval;
+}
+
+static void *user_copy(void *opaque, void *handle TSRMLS_DC)
+{
+ struct raphf_user *ru = opaque;
+ zval *zhandle = handle, *retval = ecalloc(1, sizeof(*retval));
+
+ zend_fcall_info_argn(&ru->copy.fci, 2, &ru->data.data, zhandle);
+ zend_fcall_info_call(&ru->copy.fci, &ru->copy.fcc, retval, NULL);
+ zend_fcall_info_args_clear(&ru->copy.fci, 0);
+
+ return retval;
+}
+
+static void user_dtor(void *opaque, void *handle TSRMLS_DC)
+{
+ struct raphf_user *ru = opaque;
+ zval *zhandle = handle, retval;
+
+ ZVAL_UNDEF(&retval);
+ zend_fcall_info_argn(&ru->dtor.fci, 2, &ru->data.data, zhandle);
+ zend_fcall_info_call(&ru->dtor.fci, &ru->dtor.fcc, &retval, NULL);
+ zend_fcall_info_args_clear(&ru->dtor.fci, 0);
+ if (!Z_ISUNDEF(retval)) {
+ zval_ptr_dtor(&retval);
+ }
+}
+
+static php_resource_factory_ops_t user_ops = {
+ user_ctor,
+ user_copy,
+ user_dtor
+};
+
+static int raphf_user_le;
+
+static void raphf_user_res_dtor(zend_resource *res TSRMLS_DC)
+{
+ php_resource_factory_free((void *) &res->ptr);
+}
+
+static PHP_FUNCTION(raphf_provide)
+{
+ struct raphf_user *ru;
+ char *name_str;
+ size_t name_len;
+ zval *zdata;
+
+ ru = ecalloc(1, sizeof(*ru));
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sfffzf",
+ &name_str, &name_len,
+ &ru->ctor.fci, &ru->ctor.fcc,
+ &ru->copy.fci, &ru->copy.fcc,
+ &ru->dtor.fci, &ru->dtor.fcc,
+ &zdata,
+ &ru->data.dtor.fci, &ru->data.dtor.fcc)) {
+ efree(ru);
+ return;
+ }
+
+ user_cb_addref(&ru->ctor);
+ user_cb_addref(&ru->copy);
+ user_cb_addref(&ru->dtor);
+ user_cb_addref(&ru->data.dtor);
+
+ ZVAL_COPY(&ru->data.data, zdata);
+
+ if (SUCCESS != php_persistent_handle_provide(name_str, name_len,
+ &user_ops, ru, raphf_user_dtor)) {
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+
+static PHP_FUNCTION(raphf_conceal)
+{
+ zend_string *name;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &name)) {
+ return;
+ }
+
+ RETURN_BOOL(FAILURE != zend_hash_del(&PHP_RAPHF_G->persistent_handle.hash, name));
+}
+
+static PHP_FUNCTION(raphf_concede)
+{
+ char *name_str, *id_str;
+ size_t name_len, id_len;
+ php_persistent_handle_factory_t *pf;
+ php_resource_factory_t *rf;
+ php_resource_factory_ops_t *ops;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
+ &name_str, &name_len, &id_str, &id_len)) {
+ return;
+ }
+
+ ops = php_persistent_handle_get_resource_factory_ops();
+ pf = php_persistent_handle_concede(NULL, name_str, name_len, id_str, id_len,
+ NULL, NULL TSRMLS_CC);
+ if (!pf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Could not locate persistent handle factory '%s'", name_str);
+ RETURN_FALSE;
+ }
+ rf = php_resource_factory_init(NULL, ops, pf,
+ (void(*)(void*)) php_persistent_handle_abandon);
+ if (!rf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Could not create resource factory "
+ "for persistent handle factory '%s'", name_str);
+ RETURN_FALSE;
+ }
+
+ zend_register_resource(return_value, rf, raphf_user_le);
+}
+
+static PHP_FUNCTION(raphf_dispute)
+{
+ zval *zrf;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zrf)) {
+ return;
+ }
+
+ RETURN_BOOL(SUCCESS == zend_list_close(Z_RES_P(zrf)));
+}
+
+static PHP_FUNCTION(raphf_handle_ctor)
+{
+ zval *zrf, *zrv, *zinit_arg;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz",
+ &zrf, &zinit_arg)) {
+ return;
+ }
+
+ zrv = php_resource_factory_handle_ctor(Z_RES_VAL_P(zrf), zinit_arg);
+ RETVAL_ZVAL(zrv, 0, 0);
+ efree(zrv);
+}
+
+static PHP_FUNCTION(raphf_handle_copy)
+{
+ zval *zrf, *zrv, *zhandle;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz",
+ &zrf, &zhandle)) {
+ return;
+ }
+
+ zrv = php_resource_factory_handle_copy(Z_RES_VAL_P(zrf), zhandle);
+ RETVAL_ZVAL(zrv, 0, 0);
+ efree(zrv);
+}
+
+static PHP_FUNCTION(raphf_handle_dtor)
+{
+ zval *zrf, *zhandle;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz",
+ &zrf, &zhandle)) {
+ return;
+ }
+
+ php_resource_factory_handle_dtor(Z_RES_VAL_P(zrf), zhandle);
+}
+
+static PHP_MINIT_FUNCTION(raphf_test)
+{
+ zend_register_long_constant(ZEND_STRL("RAPHF_TEST"), PHP_RAPHF_TEST, CONST_CS|CONST_PERSISTENT, module_number);
+ raphf_user_le = zend_register_list_destructors_ex(raphf_user_res_dtor, NULL,
+ "raphf_user", module_number);
+ return SUCCESS;
+}
+
+static PHP_MSHUTDOWN_FUNCTION(raphf_test)
+{
+ php_persistent_handle_cleanup(ZEND_STRL("test"), NULL, 0 TSRMLS_CC);
+ return SUCCESS;
+}
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+\89PNG\r
+\1a
+\0\0\0\rIHDR\0\0\0Ù\0\0\0l\b\ 6\0\0\0ç¹\17°\0\0\0\ 4gAMA\0\0±\8f\vüa\ 5\0\0\0\ 6bKGD\0\0\0\0\0\0ùC»\7f\0\0\0 pHYs\0\0\v\13\0\0\v\13\ 1\0\9a\9c\18\0\0\0\atIME\aÝ\f\ 4\b\10'É=)\85\0\0 \0IDATxÚì½G\8fÜùu5|*ç\9csWçfhr\98&hFÒ(YòH\90 Ë\ 6\1c\0ÛðÆ6¼´\97\ 6¸ñ\að'0\fm´²$À0\ 4\aÙ3\8f$\12\138$;\87ê®\9csÎõ.Fç¢z,ùµ¤ç}\17\ 4k£Ñ\fYá\7f\7fáÞsÏ9Wñ\ fÿð\ f\8bÉd\ 2¯×\8bJ¥\ 2½^\ f\9dN\87gÏ\9eÉ?\ f\87CÌf3,\16\vôû}¨Õj4\1a\r¼öÚkP©TÈd2è÷ûX,\16°Ûí8<<Äîî.ªÕ*>÷¹Ïáää\ 4\83Á\0\9dN\aV«\15+++°X,8;;C¹\\86ÛíÆh4Ât:E§Ó\81ÅbA¯×Ãöö64\1a\r\9e={\ 6§Ó »Ý\ e\0H§Óp:\9d0\9bÍè÷û\0 \9f\v\0V\vÝn\177nÜÀ|>\87Ëå\82F£A6\9b\85Ãá\80ÇãA©TÂùù9VVV0\9fϱ²²\82|>\8fx<\8eF£\81~¿\8fñx\8cñx\8c\9b7oâää\ 4*\95
+'''hµZxóÍ71\9fÏ\11\ e\87¡R©Ðjµ\90ÉdÐn·\11\8fÇ1\1e\8f1\9dNáv»Q©Tðüùs\f\87Cܺu\vN§\13Ï\9e=\83ÉdB,\16Ã`0\80R©ÄÖÖ\16
+\85\ 2^ÆãÅ\8a\87ê\8d7ÞxØét R©p||\8cn·\8bH$\ 2\8dF\83`0\88Ñh\84F£\ 1\9dN\87Ñh\ 4\0\18\8fÇðûý\18\ e\87¸¸¸\80F£\81Åb\81ÕjE¥RA(\14Âb±\80ÃáÀ³gÏ°X, Õj¡Õj¡Óé`4\1aQV¡Ñh P(Ðjµ0\1e\8f¡ÓéÐjµ`·Ûáóù T*Ñn·a0\18`2\99 T*¡P(0\1e\8f\11\b\ 4P«Õ`2\99\10\89D`6\9b\11\f\ 6Ñl61\9bÍpÿþ}\8cÇc\94ËeD"\11(\14
+L§S¬®®¢×ëa2\99\0\0æó9ö÷÷Ñn·±³³\83Ùl\86jµ
+\8bÅ\ 2\97Ë\85x<\8eóós\f\87Clooc8\1c¢\.c>\9f\ 3\0Ün7l6\e:\9d\ et:\1d,\16\vNNNÐh4àt:±X, R©\0\0>\9f\ fz½\1e*\95
+\1e\8f\a\9dN\aív\eÑh\14Óé\14Íf\13õz\1d/ãñbÅCõÎ;ï<ôx<¸¸¸Àl6\83Á`Àb±\80ÕjE£Ñ\80Á`Àh4\82Çã\81ÃáÀp8\84Éd\82ÅbA2\99\84Íf\83ÍfC³ÙD£ÑÀh4B$\12\81ÍfC»Ý\86^¯G³ÙD:\9dF$\12\81J¥Âh4B»ÝF¯×\83B¡\80Á`@¯×\83Z\86ßïÇx<\96\80\9aL&x<\1e \82×ë\95\93\10\0´Z-ìv;Úí6jµ\1az½\1eÌf3¦Ó)4\1a\ræó9L&\13\86Ã!b±\18Òé´üÎ^¯\87t:\8d\9d\9d\1d\98Íf¼ÿþûP(\14¸~ý:\86Ã!ªÕ*úý>ìv;¦Ó)\12\89\ 4\16\8b\ 5nÞ¼ ¯×\v\9dN\87L&\83Z\ 6\9bÍ\86\95\95\15Yl*\95
+\9dN\a\8dF\ 3^¯\17\83Á\0³Ù\fv»\1dV«\15Ýn\17V\v\91H\ 4ãñ\18Éd\12ív\e6\9b\r/ãñbÅCõÕ¯~õa>\9f\87Ãá\80Éd\92Sp4\1aáÃ\ f?Ä`0ÀÍ\9b7Q«ÕP(\14°¹¹ \8dF\83n·\8bN§\ 3\8dF\83Åb\ 1\8bÅ\82áp\b\8fÇ\83Ñh\84ããc\f\87Ch4\1aøý~(\14
+\98Íf,\16\v\8cÇc\1c\1c\1cÀjµB£ÑÀl6Ãn·CV\ 3\0L&\13\0@§Óa±X`8\1cb4\1aA¡P@VC¯×C«ÕÂb±Àãñ ßïc:\9dÊ"Ðëõ\98ÏçrÂL&\13èõzôû}8\1c\ e\0Àh4\82Á`@(\14\92ÓÐjµ¢^¯Ãáp`±XÈ{6\9bMìììÀåra:\9dÊßU©TÐëõ\98N§\98L&øè£\8fàñxàñx`µZ\91J¥`³Ù\90Íf¡Ñh ×ëáp8ptt\84\.\a£Ñ\88`0\b³Ù\8cD"\81`0\b¥R\89\97ñx±â¡úÂ\17¾ðp}}\1d¥R \ 6\83Av`«Õ\82Çã\81Óé\84R©Äb±\80ÍfÃb±@µZ\85B¡\80ÏçCVÃ|>\87^¯\87Éd\82V«E³ÙD¿ßG·Û\85Á`\80ÝnÇÎÎ\ e\9aÍ&\ 6\83\ 1ªÕ*¬V+ü~?F£\11l6\9b\9c\bÍf\13*\95
+F£\11\8bÅ\ 2³Ù\fÍf\13óù\1cF£QN\ f¦*Óé\14\1e\8fG>3\97ËÁ`0 V«Ál6CV\7fòCU*L&\13(\95J(\95Jx<\1e¨Õj(\95JÌçs8\1c\ eܺu\vZ\16jµ\1aZ\16J¥\12jµ\1aý~\1f:\9d\ eõz\1d^¯\17óù\1c\9dN\a\95J\ 5^¯\17ñx\1c\17\17\17rºµÛm\ 4\ 2\ 18\9dNèõz\8cF#Ìçslll\0\0\ 6\83\ 1ºÝ.l6\eêõ:\8aÅ"\1e<x\80ñx\8cÁ`\80\97ñx±â¡úæ7¿ù0\91H ×ëA§Ó¡Zâðð\10\16\8b\ 5^¯\17\1a\8d\ 6ý~\1f\1a\8d\ 6Óé\14J¥\12\95JEN\ e\9bÍ\86Éd\ 2«Õ
+µZ\8dÅb!?Øãñ \1a\8d\ 2\0NOO%Hãñ\18f³Yþût:E:\9dF«Õ\82Ñh\84Ñh\84J¥B©T\82ZÆêê*4\1a\r\ 6\83\ 1Æã1\16\8b\85\9cªÅb\11V«\15Åb\11F£Q¾ïl6\93\93P£ÑÀn·Ëb©Õjp»Ýèv»\9fäÌ*\15z½\1eT*\15L&\13T*\15\86á,T\87Ã\81L&#Å3\08\1c\ e\18\8dFôz=\9c\9e\9ebkk\v\00\1c\ eÑl6Ñét T*át:aµZáp8`³Ùp~~\ e½^\8f·Þz\v¥R ³Ù\fN§SN\7f\9dN\87\97ñx±â¡øû¿ÿûÅb±@»ÝÆl6\93\87±X,°X,P(\14\10\ e\87aµZQ*\95 T*a2\99Ðn·qíÚ5\14
+\ 54\9bMXV)>Õj5¬V+\94J%\1a\8d\ 6Òé4NNNðꫯB©TÂívK:\92Ïç¥\88n·ÛÐét\98Ïç¨×ë\0 é\8eÏçC£Ñ\80Ýn\87Ñh\94\87Ì\82<\9fÏc:\9dBVc8\1cÂív£V«Áëõb8\1cb±X@VË\8fÏçó\18\8fÇp»ÝÐëõ¨×ë0\99L°Ùl\18\ e\87¨×ëðûýh6\9bèv»\88ÅbH$\12r"\12`p8\1c\82zõû}\ 4\83A¨T*är9\ 1\17B¡\10Z\16\86Ã!æó¹<k\93É\84Ñh$)\9e^¯G»ÝÆËx¼XñP}ñ\8b_|xqq\81z½\8e`0\88µµ5\98L&Ôëuär9¸ÝnÌf3(\14
+x<\1eT*\15Ìçs¨T*,\16\v\f\ 6\ 3(\14
+Ìçs,\16\v4\9bM8\9dN¨T*\14
+\ 5\94ËeØl6¬a±XHQX«Õ\90Ïçå\ 4dJ0\9bÍ R© Óé P(Ðl6\ 5\ 6f\81Ê\13Z¡P \97Ë BÖn·\ 1\0F£\11\93É\ 4áp\18Ýn\17ù|\1e³Ù\f6\9b\rÕj\15\83Á\0N§\13\ 6\83\ 1
+\85B\16¢V«E·ÛÅx<\86ÉdÂ`0Àh4B§ÓAVC8\1c\86^¯\87ÕjÅp8D:\9d\86N§\83Çã\11X[§Ó ¤íóù ÓéP(\14\90N§\11\f\ 6a·Û1\99L`³Ù0\1a\8d°²²\ 2µZ\8df³\89f³\89Åb\81\97ñx±â¡òù|\ f\ 3\81\0\1c\ e\ajµ\1a\f\ 6\ 3J¥\12|>\1f,\16\v¢Ñ(\86Ã!\14
+\ 5.//a4\1a1\9dNaµZQ(\14°X,àr¹\ 4\89ÇãÐjµ8::B£Ñ\90\13Á`0@£ÑH
+Ñív¡Óé T*%]á ÂÜ»V«ÉÉ`4\1aQ¯×a4\1a\ 5\16&|<\9fÏ¥ðÖh4\18\ e\87èõzr\9aÙl6h4\1aY\18Óé\14&\93 \9dN\a\ e\87\ 3\1a\8dFÒ&ötôz=\ 2\81\0\9aͦ¤>\1e\8f\a\83Á\0¥R óù\1c\ 6\83\ 1óù\1cÍf\13\1a\8dF\8az\87Ã\ 1\9fÏ\87\.\87N§\ 3\83Á\80[·n¡Ñh P(Àf³Áëõ"\16\8báìì\f\85BANü\83\83\ 3¼\8cÇ\8b\15\ fÕ\9fþé\9f>ÜÞÞ\86Z\86N§C³ÙÄt:E·Û\957è÷û\18\f\ 6è÷û(\95JP(\14è÷ûP*\95\b\87ÃP*\950\1a\8d°Ùl¸¼¼Äññ1ôz=|>\9fäÊ*\95
+J¥\12½^\ fý~\1fóù\1cN§S
+O\85B\81Á`\80Á`\0µZ-péÆÆ\86¼/¡`\85B\ 1\85B\ 1½^\ f\8bÅ\82J¥"¹;¿«ÝnG2\99Ä|>\87ÏçÃt:\95EÂ\93W«Õb2\99 ßï£ÕjA§Ó¡\.C§ÓIÏh4\1aÉo\0p¥À\1f\ e\87°X,èv»0\9bÍp8\1cò\9dJ¥\12jµ\1aÖ××áõz\91N§%àÁ`\10år\19ÿöoÿ\86ét
+§Ó\89\93\93\13hµZ¬®®âe<^¬x¨~ÿ÷\7fÿá`0\90þF³Ù\84N§\93^F§ÓA*\95B¥R\91ëy8\1cÂårÁh4"\1a\8d¢ÕjI\97\9b»7\1c\ e#\93É \18\fÂét
+RÅ¢\18\0\ 2\81\0\0ÈéÂff4\1a\15\ 4\88\ 5çx<Æp8\84R©Äd2\11DI§ÓIóq8\1c¢T*ÉIY.\97\11\8fÇ\85-`6\9b¥ð/\16\8bÂ\0(\95J\922¹\.éó$\12 x½^Øív(\14
+\81~\ 3\81\80Ô\rÌáY_°\1eQ*\95ðù|rKðÏp!=zô\bV«UX\10ìóXV¼\8cÇ\8b\15\ fÕ×¾öµ\87\85B\ 1ççç\98Ïçr\82E"\11\f\87CÔj5Ôj5,\16\v\98ÍfA©\14
+\ 5\1c\ e\aÔj5Z\16\ e\ e\ e\ 4â\f\ 4\ 2\92sW*\15Ìf3ôû}ù{>\9f\ f\0Ðëõ0\9dN\11\8dFÑíva±Xàp8Ðjµ¤°\9cN§(\14
+òÃY\80v:\1dD"\11Ìçsôû}øý~´Z-Äb1L&\13\94Ëeܽ{\17år\19ív\eãñ\18kkkÈårÐëõ\18\8fÇP©TW~\a\17\8f^¯G«Õ\82ÏçC·Û\95\13ßçó \88À÷q8\1cÐjµ¸¸¸\90~\11\19\ 2lôÚl¶+H\17Ó$ö\90Æã1F£\91¤7/ãñbÅCõ;¿ó;\ fm6\e\1c\ e\aÒé4Úí¶ô9:\9d\ e<\1e\ fb±\18¼^/&\93\8949É׺¼¼DV\13$\87\81á\8f(\97Ë(\97ËX__\97ÞÆd2\91¦¥ÓéD¯×\93\1a\81\ fÙl"\93É`:\9dÂl6C¥R¡\.£ßïÃ`0Àf³Áï÷\vE¦ÑhHJsyy)?P£Ñ P(`}}]`èr¹\8cp8\8c-i\1a\92\87V*\95\90N§\11\b\ 4¤Ø&S\82§¿^¯\87Ñh\14\14«ÝnÃáp\bt~qq!ÏÂãñ ^¯#\91H\b\bÁß\«ÕP©T°ºº
+«Õ*,\8b\97ñx±â¡úæ7¿ù\90hQ8\1cF \10@¹\\86R©DµZ\15ªL \10\80Åb\11ZL£Ñ@·Û\85J¥\82Ãá\80Åb\ 1\0L§Sá\8717w¹\\12d¦\15Ãá\10\ e\87\ 3\8dFC\98\ 6<YXdÛl6\18\8dFa.èt:¨Õj\98Íf\98L&ø|>T«UéG°°e\8f¨Õja:\9dÂn·£Ûíb6\9báüü\1c\16\8b\ 5\16\8b\ 5\93É\ 4\8bÅ\ 2N§S\ 2d±X`·ÛÑét\84\87æt:¡ÑhÐëõ Õjqzz
+³Ù\f\8bÅ\82D"!E~¯×\83ÅbÁúú:òù<*\95
+:\9d\8e@Ç$ΦÓi¨Õji\8e^^^¢Óé`6\9bÉ\9f{\19\8f\17'\1eªû÷ï?\9cÍf0\1a\8d\b\ 4\ 2ÒÁ¯×ër\9aL&\13d³Yèõz\84Ãa4\9bM\f\87C\0\80ÕjÅx<Æd2Á`0\10(´Ûí"\14
+!\18\f\82ï_VÑëõ\84±=\18\fàr¹\84®²\8cb\19\f\ 6t»]AÊ\1a\8d\ 6\ 2\81\0\86Ã!¼^¯ü¹v»\r·Û\8dét*\ 19??\87F£\11\bÚd2a>\9fc0\18\0\0l6\e¦Ó)¦Ó)z½\9eð×Æã1ÔjµÐfxÂ\17\8bEL&\13!Ôò$eo&\12\89 Ýnc4\1a!\1c\ eÃápH1Î\82\98ý$6\82ÙÄt»Ý0\99L\82¾µZ-¼\8cÇ\8b\15\ fÕ\9bo¾ù\90]óÉd\ 2µZ-Ô~\85B\ 1¥R\89B¡\0\9dN'4\19£Ñ(½\17\9bÍ&ù1ósµZ\r\93É$y6\99ÕF£\11:\9d\ en·[z\1eäÅ-\16\vÌçséY$\12 h4\1aI[x\ 5\93vc±X\ 4ý2\99LH&\93Èår\12øù|\8eáp\b\9dN\aV\8bB¡\80x<\ e³Ù\f\85B!iÒb±\80ßïG¹\Æh4\92n¿V«\85F£\11f¶J¥\82Õj\15ä¨ÑhÀb±`ccC>Ïçóa±Xàôô\14Z\16>\9fOè@Ï\9f?G¿ßGVC4\1a\85Z\86B¡Àp8\14ôNV£Ûíâe<^¬x¨¾ýío?$lÉ¢¯V«Áétb8\1c¢X,"\14
+A¡PH7\9e'\9bN§Ãt:\85Ëå\92kx4\1aa4\1aÉ)zyy\89áp\88x<\ eµZ\8dñx\f\83Á l\82L&#hV.\97Ãx<\96\93\91\8b\85\14\9eÅb!'´Ùl\96bX¡P Ýnc8\1c¢Ñh\b²¦P(Ðét\84JCé\86Ãá\90\9e
+\19åÃá\10Ýn\17ZV´C\h\ 4\f\98b©T*\91It:\1dÉÅ\8dF#òù<NOO±»»+\84Ö~¿\ f\8bÅ"t¡R©$\rÚÙl\86n·\8bF£\81d2\89\95\95\15¼\8cÇ\8b\15\ fÕç>÷¹\87l®±×P,\16Ñjµ ×ëa6\9b\ 1\0«««è÷ûÒq',\(\14$÷e\ 3\91MÂËËKÉUÙ\ 1×étÒ\14mµZÒ姬 ÕjÁår]y?\92B\89\16åóyáÔ±\ 6\18\f\ 6°X,h4\1aR\94ûý~Io\94J%f³\19t:\1d\8aÅ"\.\17t:\1dt:\1dºÝ.úý>L&\13f³\19\ e\ f\ faµZár¹\ 4îµX,P(\14H¥R0\9bͲ8É\84p:\9d\98Ïç\18\8fÇ\b\87Ã\82Pñ\7fy2Îf3¸Ýnôz=är9L&\13¸Ýn¸ÝnÄãqÔëu¼\8cÇ\8b\15\ fÕÛo¿ýÐï÷Ë\95Üëõ0\1c\ e¥síp8àt:qyyy¥\10%9\94'N«Õ\82V«\15¶v£Ñ@(\14\92^\ 5\9b\89üaz½^Цv»\8dX,&Wr³ÙD8\1c\96Þ\f¹nÌß\99\82Ôëu\81h©ªÕj\98L&ØÚÚÂb±@¯×\13\91`£Ñ\90\a\1f\f\ 6aµZ¥\87\ 2@(C&\93IÒ\10²"f³\19Ìf³\9c®
+\85B\18×n·\eù|\1e\0`6\9beq\9e\9d\9d\89þ\88i\ 6å\19óù\1c±X\fÃá\10¹\\ e\16\8b\ 5ù|\1e
+\85\ 2/ãñbÅCõå/\7fùa0\18\84N§Ãéé)t:\1d\1c\ e\aÎÏÏá÷û¡×ë\91Íf¥\18eÎÊ\9eÀd2\11\b\97BAµZ\8d`0(?\84ªS½^\8fÁ`\80B¡\0£Ñ(ª]\92P«Õ*\.\17Ôj5²Ù,:\9d\ eìv;f³\99À©£ÑHȬÌ\99É\ 2ÈårÐh4\b\85B\98Íf\98Ïç\b\ 4\ 2H&\93P«Õ\98Ïç(\97ËØÙÙ\11Z\ fUÀ\fà2*g2\99\84²3\1e\8f%à\14BR}LÎ\1cû:äãY,\16èõzèõz¸\.ôû}á¼ÅãqA¢ìv;*\95
+\1a\8d\ 6l6\e^ÆãÅ\8a\87ê«_ýêCþ\1fæ\9c<í´Z-ÎÏÏát:\11\f\ 61\9fÏá÷ûQ«Õ\84Z\ 2\0\16\8bEÄtÁ`PÐ\19jlòù¼¤\1d\9dNGh3kkkh4\1aèt:\b\ 4\ 20\1a\8døðÃ\ f\ 5áÑh4899\91\82÷îÝ»P©Tøøã\8fE»£V«¥ÉÈ^\85ÕjÅh4\92\9a$\18\f
+%\87\8c\avéÙ\88%¬Ûï÷%¿¦èp:\9d
+\9bÀl6Ã`0\88¬a<\1eKss>\9fÃjµ¢ÕjÉÉ;\9bÍàñx$=S*\95\b\ 4\ 2"'!° P(°ºº\8aÑh\84\97ñx±â¡zýõ×\1fúý~ôz=á|ñdªV«0\99LX]]E«ÕBµZ\85V«\85Ûí\86B¡\90âu0\18H\1f\85=\ 5¥R)_\8aâ<\16´ô\80¨V«\98ÏçR\170gv»Ý¢!r¹\P(\14B\9d\19\8dFP*\95\92÷×j5øý~Ìf3\84Ãa\f\ 6\ 38\1c\ eù=ô£ Èn<\1eK\1a2\9fÏa6\9bÑh4®4c\99"\91r´X,\10\89D\84\ËÞ\12É«f³\19\93É\ 4~¿\1fétZH·z½^
+~\0¨T*p¹\¨Õjèt:\b\ 6\83p8\1cH¥R°X,è÷ûèt:x\19\8f\17+\1eªx<þÐl6c{{\e\ e\87\ 3*\95J®n\0\b\ 6\83h4\1aèõzÂIëõzh4\1aÒùW(\14ò÷\98\86\10å\1a\f\ 6"Îc\9f¤Ýn\vm\87M@æø.\97\vÉd\12\95J\ 5jµZÐ,\1a\95\8cF#èõzÌf3T*\15lmmÉ©ùôéS\91@¬¯¯c8\1c~Òqÿ9¥F¯×K\ e_*\95Ðëõ`4\1aEë¤Óé ×ëÑëõ®,
+V\v\83Á\0\8fÇ#é\10\ 5\82,¢©Áâ\82S«ÕÈårR\a\91%Þï÷a4\1a1\18\fDêO1âññ1*\95
+^ÆãÅ\8a\87ê\ fÿð\ f\1f\12MâÕKo\87ÕÕUi¼QÁÊ^\8bV«E.\97\93\ fæ\89CÉ\83Õj\85ÅbA§Ó\81ÏçC¡P\10\ 2)û7v»]\14±ìß\18\8dF¹þ{½\1eZ\16Ìf3\94J¥ðÖ\94J%²Ù¬¤1\9dN\a\89D\ 2:\9d\ eëëë0\18\f¨T*(\95JÒ±\9fL&"ê;>>\96f$õO\81@@\16\r\1f<\9b\8d$Æò{)\14
+Ôj5)¬\97û5ü-Íf\13&\93IôY.\97KD\7f\91H\ 4:\9d\ e\9dN\a\99L\ 6±X\fÍf\13\93É\ 4Ñh\14/ãñ\82ÅãÞ½{\ f\97¯}\97Ë\85\93\93\13Aa
+\85\ 2ìv»Øk©T*´Ûm)î\12\89\ 4úý>¬V«@ºZ\16+++ØÛÛ\83ÛíÆd2A£ÑÀd2A»Ý\86B¡\108\98\92\bV\v\93É$Ww±X\84R©\94^Êd2A(\14\12\19\86ËåB¯×\13Ö\82Ûí\86ÙlÆÚÚ\1a²Ù,\9e>}\8aÝÝ]ôû}9¹\89ö¸Ýn \bû\1f4Ká©W©T R©`±X\ 4í¢c\12\9b\93v»]ôU\14#º\.Éùçó9r¹\1c\.\97 i\16\8bE\8cnjµ\1a4\1a\8dô±2\99\8c¤u/ãñâÄCI©4O¿\8b\8b\vøý~QÕR\90Ç"\94]{î|RGÎÎΤ\ 3Î×úú:\1a\8d\ 62\99\8cô/t:\1d\9cN§¸\10±ï Ñh`µZ\85\8cêñx ×ë\855¾\9c¿\9bL&Qâ\12a
+\85B\b\85Bx÷ÝwÑï÷ñÆ\eo`8\1c\8aÌÜjµÂf³ Ê5\9bÍ\84¡NvÀh4B«Õ\12\rÓÆÆ\ 6:\9d\ eF£\11,\16\v2\99\8c\18À0Eêt:¨V«¨×ë¢Çj·Ûh4\1a¢ébQM½S¿ß\17\7f¿@ °¹×ëÅËx¼xñP}ùË_~8\18\f\10\8dF1\9fÏ\ 5¹¡Ä\81VXÌÉm6\e\1a\8d\86|A³Ù\8cz½.×&)þ¥RIòv\9e\16<QhpÉÿN\9e\18I\9fL\17Ø8\8cÅbâ\bK\ f@²\9cM&\13îÞ½\8b\8b\8b\v|øá\87ØÞÞ\16oÁb±\b\93É\ 4\83Á\0¯×\8bD"\81N§\83X,\ 6\9bÍ&,o\83ÁðÉÃø9\89V©T"\1a\8dÊBeѯP($Ía_&\97Ë¡ÝnckkKÄ\81$åòä§NJVãüü\1c\8bÅBrùÃÃC¸\.ܺu\vv»\1dV\v/ãñbÅC9\9bÍðæ\9boÂív#\9dNãüü\1c6\9b\rÉdRdê¹\\ e6\9bMP\13j\82T*\95ô/X\fW*\15´ÛmÌçs!^\8eF#øý~awët:qE"òåp8ðÁ\a\1fÈ d2\99 V«qûöm©\19¨\ 5êõz(\14
+¨ÕjxõÕWqvv\86D"!Wú|>\97Â\94Z¦^¯\87p8\8cµµ54\9bM\14
+\ 51ô\1c\8fÇÐjµ(\97ËXYYÁÖÖ\96\18]®¯¯\8b\8b,\9d\9a\8cF#F£\91ôMØíç\9faaìr¹¤ïC¿?\97Ë\ 5³Ù\8c³³3hµZ¬\89\88\92Ìô\97ñx±â¡úË¿üË\87J¥\12årY<õìv;\ 2\81\80äµ»»»èv»¨V«\98Íf¢\94-\16\8b\82ªÐNù\95W^\11'ØH$\ 2«Õ\8aÉd\82b±(ð¦ÏçC¹\\96\9c×jµ"\99LÂï÷Ãçóa<\1e#\91HH#\94ý\10ö]H\0µÛíÈf³\ 2§¾ùæ\9b"_\9fÍf\18\ e\87\b\ 6\83\88F£¨ÕjòïhGVV\ 5\11j4\1aRÃ\94Ëe\18\8dFÄãqÑ\19±?Â\94Àd2Ájµ\8aï^V\13\96\ 5\8dg¦Ó)Âá° cN§\13^¯\17ù|\1eÑh\14ëëëÒ,e:CCÍ\97ñxqâ¡øÞ÷¾·\98L&èv»øà\83\ fðÙÏ~V\1c])»¦4a>\9f\8b¥3;í½^O¸Z\91HD®g:Á²7ë\96¦ü¡PH¤\a\14Âñä#|\9cÍf1\1e\8fqÿþ}±å¢¯{*\95\82Á`@«Õ\92\0G£Qa)\94Ëe4\1a\rlnn"\9fÏK~ìv»át:\ 5]#\9af±XÄ*\9aÀ\ 1Ù\ 5\94\94³·²¹¹\89V«\ 5·Û-§ål6\13\ 66\1d\8cÈXg_\8a\fð@ è\13µLÑhTNýñx\8c^¯\87\ f>ø\0o½õ\96è¨\18\ f£Ñ(ñ H\91ñà þ\8bâA¸ýW\8d\a\15ÁL\ fÿÿ\8cG¿ß\17ó\9db±(ñ Læÿëx\90\ 4ý\9bì\ fÕ·¿ýí\87ì\93¼ùæ\9b\ 2£Ò\96\8b½\f\0â½Ç\93\81\9d|²\9e)\9e£¬B£Ñ\bA5\10\bH/D«ÕJß\86ü/."þýL&\ 3\8fÇ\ 3\0Ðh4H&\93X]]\85ËåÂÙÙ\19vvv\ 4\rcÁËàP±k·Û\91ÉdÐívåïrÃ(\14
+T*\158\9dN \ 2§\87°¯\94ÍfÅÕ\88ÄXÊ?Hl¥ÄA£Ñ\88 Òf³I³\97\ 2Jòýl6\ejµ\9a\80\v~¿\1f\ e\87\ 3Íf\13¹\N\18
+\9dN\ao¼ñ\ 6\f\ 6\ 3²Ù,æó¹,\fn¢z½.µ\86^¯\17í\18ãqvv\ 6\8bÅ\ 2\93É$ú«ét
+¯×\8b`0(ñÐét\98Ífp¹\âÞË\e\8añH¥Rðz½\12\8fËËK¬¬¬ÀétþÒxt:\1d\98ÍfI\ fm6\eÒé4ºÝ.âñ¸X¶\11¡,\97Ëp8\1c².\9aÍæ\15¨>\97ËawwW\1aå*\95JPQV+·3)_\8c\a='\99&\9aÍæ_9\1e¿êþX\8e\87ê\eßøÆÃ÷Þ{\ f>\9fO\82AÒ#\e\8c¤\96èõz(\95JØl6\11é\11V¥'\ 2ÙÓ\95J\ 5
+\85â\8aáÈh4\12ÓM\85B!A¦¿:¡dÂÏf³\19¡PH8p\e\e\e888@8\1cÆáá¡ÀÄÕj\15Á`\10\a\a\aBÌ\[[C§Ó\11SÌF£!t"vÿ\9dN'¦Ó)ªÕª°\eh\IÔl<\1e#\1a\8dÊûv»]Ù8¥Ré\8aò\97RýeOv¥R)¶ÖË\b\98Ýn\17°\80l\ 5¦rï½÷\1e\9cN§,\18ö\88úý>
+\85\ 2ºÝ®¸ùr¡¨ÕjÔëu)¾'\93\89¨\98\97\9d{m6\9b@ç<èH\18®V«"\1dY\9ePÂþ\92Á`@ \10\90Ó~}}\1dGGG\b\85B8>>\96ú¦ZÂï÷ãàà@\9c\9c\b\96Ð-¸^¯#\9bÍ¢ÑhÈçsQRKF\ e¤R©\94\r;\1c\ e\11\b\ 4ÐëõäÖµZ0\1a\8dÂ\8e_\9e8c4\1a¡P(¤\16åá4\9dNåÐ!\80A\e=Z Ð\83ÿ'?ù ¼^¯0Iþßö\87Ýn\87F£\91g®øîw¿» \13`8\1c\8a?\82ÙlFVC©T\12¶3U´\14¸\91÷Öï÷?!BþÜf\8c\90èt:\85^¯\17(\99¾\ fLqÈzæ\83¡ù%¸<\1e\8fH
+B¡\90ôvø°\9f={&vÉn·[z9Åb\11~¿\1fZ\16\1e\8f\açççWXÛäóQÚÐëõ\84Y@V\ 1\e\99&\93I\j3\99\8cøý\95Ëe\1c\1d\1daeeE\82±ºº
+\95J\85'O\9eÀl6c6\9b!\14
+ £\9c\82E
+\1eI\m4\1a\b\87ÃÈår\b\ 6\83ò]È)ä\ 6æfäf\9dÏçrÐðp \9f<UÃtgb<è\1c¥×ëQV1\1e\8f\ 5ö¾~ý:Úí¶\98\9cúý~1Í¡D¦^¯C§Ó!\12\89|RÔ«Tr`<\7fþ\|4\1c\ e\87¤ûÙlö\13ñâÏ\112\99\8c0.\ 6\83\ 1Ün·4¬9@\82R\16ò\ 1ÉÚ'3\83^!4Ï©×ëH&\93ò=\17\8b\ 5B¡\90\8c<"s\9f·1½\1c¹1x\18r=ììì \.css\13n·[bö¿Ù\1fôF\19\f\ 6\9f\(ÿø\8fÿ¸`
+a6\9b\ 5qI§Óòeø&³ÙL\1caio\9cÉdpxx(5\vM!y\12\11ZåÉÈÓbÙk\8fÐ*O\7f\9fÏ\87X,\ 6¥R\89ÍÍM¬¬¬HÁIn\19 ¢o¾ù&Þ{ï=\94J%)@É\1eP(\148??G¥RA<\1eÇb±\10÷¤ÿüÏÿ\94Åi4\1a%¥8>>dåðæ\0\0 \0IDATF±XD"\91Àp8\14\ 4L§ÓÁn·#\1e\8f£R©\88 \91"EÖ0¤\ 39\1c\ e\9c\9c\9c \18\fJ*I_\88ÓÓS\\\ P(H\1aCö\ 1oOêX{PfÂ\8d´\9c\96ÐÎÚn·Ë"
+\ 4\ 2p¹\¢\90¦ç\ 4\ 6jµ\1a\86Ã!\1e=z$ß\83§;k\96Åb!\87\ eá}\83Á\0«Õ
+\83Á\80-ܾ}[\80\8añx\8cÏ|æ3x÷Ýw\85ÂÄÙ`\p´\ 5 ô\9fk©R©\88E\81Á`\80Ïç\13a©ÏçC¥RÁéé©@êô5ämÍú\94\87:\99\1dL+\99fsSÑ^\ 1\0f³\99\04t¬¢öíõ×_Çb±\90L\8fÍì_¶?\98½q¨\86J¥\82úæÍ\9bÈår888\90üýøøXN\94ÕÕUÔëuôz=x<\1e\99^H²æ£G\8f\90Ïç%íãb!x±üâ\89Á\7f^þw´\1cc\8aÄÑ5£Ñ\b\89DB\86Èííí¡Ýncmm\rJ¥\12ÿñ\1fÿ!\8eÙl\167oÞ\94S\8a\ 4Sê\8cL&\93XD³Þ##áøø\18\0PV±··'´ ét
+\83Á\80·Þz\vn·\eûûûP*\95\b\ 6\83â\97ÁÏbJC\950g{±Fk6\9b8;;ÃÓ§Oq~~.\16llÆþ¢\17\9fϧ\9f\eÿy6\9bÉÍe0\18ÄÄ4\95JáÞ½{²¸\ 1\b9\97#}ø;©\80æë\17Å\8e\9fÇz<\12\89È\8dj2\99°¹¹ \85B\81\1fÿøDz\19÷÷÷\91J¥p~~.©Ú/{o¾?à\b\83߸qCêçt:\8dd2)\aö/ZgL\13Ù\18çóZþsüoü>T\/\16\viÂ\8fÇc¬¯¯ãúõë¨ÕjØÛÛû_í\8fl6\8bn·+Ö\a©T
+ê\8b\8b\v\94J%\91\98s\82ÅÆÆ\ 6êõ:\8e\8e\8eàt:\11\8bÅ\ 4M¢\ e¨×ëÉIÌT\11\80@¶\9f~x\84S \98°\9eXN\8b(\11`!Ûn·±¹¹\89\.\87J¥\ 2«Õ\8aõõuhµZ¤Ói¹®9Å\83>\r\17\17\17Bà\f\ 6\83è÷ûH$\12(\14
+p8\1c\98ÏçX__Ç|>\97|}:\9d¢R©HzI³\17¦§¹\N\18Øv»]
+îÁ` µ\1eÇ\9bò´^NõÚíö\15=\14k\86ét*\13J¸\18x»sa\13\8càmÃFñd2\11\90\825\14ÓÙl\86\e7nÀl6ÃårÁétJêƦ-o\81åŹü=>½Áx{\98L&<\7fþ\1cáp\18ׯ_\17Ù\a\9bÉlî²\94X^ø\ÐË/ÖM\1c\95Ôï÷Q,\16ñÎ;ï\88t\84ô)Ú\87\7fú}ب&I\9a¿\89\9fÉõIô\91 \16×ðò\8b1Îçó¨×ëâñÈÃñ\7fÚ\1fd\99\18\f\86OHÂÛÛÛ\ fùÅÈ\17óûý2?¸Óé\88\85\18Ñ\17ö(è<\e
+\85°²²\ 2\83Á\0¿ß/h\90V«\95tÌf³auu\15\ e\87\ 3¡P\b.\97K\16\96ÏçÃÖÖ\96,\\8aô\86áÐ`h\1a\19
+\85àóùP¯×\ 5Õq¹\R\83)\14
+¹U)¡gï\86ßm±XÀ`0\b\va\19:\7fòä \1a\8dÆ\95ßKð\86ô!¯×+\104{=\1cÌ@\1fB2»ÉÕ«V«8;;\13\1fy·Û\8dk×® Ôn0\18ĨÅh4ÂápÀjµbss\137oÞ\94´Q¥Raee\ 5n·\e^¯\17\9b\9b\9brCqÜ\ fk%\12\849Ë\99P>'£p1\8b çÏy\82d*p\93Ó$Õn·ãÁ\83\aØÜÜ\84R©Ä\9fÿù\9fcww\17ñx\@\fZº¹Ýn\91Õ,\ fè£T\86^\89tãu8\1c2Î\88\92\93?û³?\83Ùl\96\ 1\82\1c\91˹̬}¨(°ZÒ÷óûý²Îâñ¸L\eµÛíXYY\9145\10\b\b\84Ïær8\1c\86Ïç»â\1e\f@\b¿ÿÓþ\b\ 4\ 2\98L&0\99L(\16\8b\9f\94F+++¨T*RË05a\87\9cÁ¢\vët:\95<Øív#\14
+¡V«\89ç\1cGÔP¤·\8cL½þúë¸}û¶\90:\89\10Qð·¿¿/6Ë\9cæÑï÷Ñl6¥ÓÏ\9aÅ`0 \1e\8f_ñô£¢Õl6£ÝnË÷äìß\e7nH*Õh4\ 4Yâ¨ÕZ\86r¹,§\19û1¼-hriµZÅq\97\13(É\19¤ï;=\ ey\vV«UlooË\109\ 6zgg\a\97\97\97\18\8dFò¼9.Õëõâ\eßø\ 6Âá0Þ}÷]\ 1S(Q¡=öææ&~úÓ\9fb±X\b\e\9c\1a+ÎSÞØØ\90zË`0\88¯Å½{÷P.\97¡ÕjåæN¥RÂlw»Ýâ)Oòî\9bo¾\89@ \ 2Ë\8b\8b\v\f\87C¬]\81ËÃá°è´\b\90Íçs|üñÇ2³\99Y\r\ f\86{÷îÁëõ
+÷ñôô\14\8dF\ 3\ f\1e<@¡P@¡P\80V«\95Ú\8e0;3\ 6\9bÍ\86o~ó\9b²ykµ\1a¬V« á¼í\93É$¼^¯8qU*\15$\12 að\17
+\ 5|ç;ß\81×ë\15s!Ú\83ÿOû\83é3Ùÿ\81@à\93>\99Åb\91\93 V«É(\e\9a\82ØívádÑÅU£ÑH1ÈùLd\12p\80\9cB¡ÀÖÖ\96 twîÜ\11Æ3eÞ\91HDd\13\1c\92ÍÞ\84Ñh\14`a>\9f\8bÁ?\83§ÓéÄv«T*ÁívK\8aÐh4dáðtÕh48::B·ÛÅÚÚ\9aÜ°årYÆ\9fòvæÉÄ[nssSÜfkµ\1a´ZÈèù`kµ\9a,¨f³)·2{DÜ<ô\8d0\18\fh4\1a(\16\8b(\95J\92\8eÆb1\84Ãa¬¬¬ \18\fÂh4bssS\80\90`0(\96ÕL·].\97ÜRn·[Ð4ö\ eé0\15\8bÅäû²¦"û\9d\0\9aÊXVAhý~?~÷w\7f\17_ûÚ×àñx°¶¶\86ÍÍM$\93IhµZ±\8c#c¤\.#\14
+ÉÁÄv\ 6E\93\94ÖÐ\18çîÝ»ø\93?ù\13¬¯¯£Ýn#\12\89\b
+yãÆ\rifÓÑ\8a>ûÝnWD¤lZß»wOØ\e[[[2mfÙÎ\80Ïßn·£Z¢Z"\9fÏËaʲ\80ë\97ëvyÔÓ/Ú\1fÌ\1a4\1a\8d¨\v\94\99LFN\18jr\98JqÊ;=\1e\bû6\9bMI\87\b¡Òû\81½\1c2\94\8f\8f\8f\85sFQ\1cQ>\87Ã\81b±(\8bÂår!\1c\ e\v\91\94Ó\11WWWáóùp~~.-\ 2nN6\ eYg°Ðf\9f\83½+\82\13´\86&\ 2§P(°¶¶\86½½=q\84eNÎ x<\1eÑb1 \9cMÅi\90ív\e>\9f\ fgggÈd2¢Âå¼*\9aÎÐ\9c¥ßïãàà@`a¶\13h<£Õj%\1eä ®®®
+0ÀC\85z*\ eË#\18Ãô.\12\89 Ñh V«áòò\12?ýéOÅR\9b \89ÍfÃîî.B¡\10òù<²Ù¬pü\82Á
+\85\ 2ªÕªÔ\89ñx\1cz½\1e\87\87\87h·ÛhµZ\88F£X,\16°Ûíâ\8dQ*\95\84¢¤R©\84´Ì¾$×\ f]\8a···át:ñ\85/|\ 1ï¿ÿ>Úí¶l`\ e\9f\88D"2X\9d}OöCÃá°¤Ú½^\ f·nÝB6\9bEµZ\85×ë\15\ 6\86Ñh\84ÙlF,\16\93z\8fh53:\ 2W©T
+½^ï\7f½?è\rÂ6\90J¥\82Òçó¡Õj¡ÙlJ·»X,J±~çÎ\1d¡\99¤Ói\914\14
+\ 5I\1d\99¾\11â¤Þ\88\82¿gÏ\9eá\87?ü!t:\1d|>\1f"\91\bÎÎÎpyy §Ó)S\19É"áµl6\9b%E`Z7\9dN1\9bÍ Ñh°¹¹)´\17ö%\.\97°¸):\9cÏçÂøv»Ýxã\8d7 P(\ 4\9e®V«â\8bÁ\17¥ \1e\8f\a\1a\8d\ 6\87\87\87\98ÏçÈf³"AçxÔ\.'è!OM\1e\0¡PHü6\9aͦ\8cý)\95JB"e}I\0\89\90øÚÚ\1a\1c\ e\aNOO1\1a\8d\90Éd°½½-N·§§§W\86ì1McZH\84\8bðu,\16\83N§Ãþþ>Þ}÷]èõz\ 4\83AiK\94ËeY¼¬'\89ÄòPËårxÿý÷ñïÿþïøøã\8fÅ¥\89\9bo6\9bI=N»\ 2*\91Ûí¶l:²(\.\17>ÿùÏ\8b6KV#\95JáîÝ»r\13\90YCïúÁ` \8c\12\ 2hF£\11J¥Rê%ZàÑÀ\94`\1aY@ét\1a\97\97\972W\9b
+k\ eª§Õ[4\1a\95rãWÙ\1f\Ó&\93 Êjµz\85:Ãü\9dÈÈÑÑ\91\f)\b\ 6\83\ 2}\12-")²Z"\9dN\v¬LN\1cÓ;wî`4\1aáÑ£G\88D"2ö\94¬ ·Û\8dd2\89n·\8bëׯË&èv»RT/\8fí¡x\8f\e!\9bÍ\8aÅ\99F£\81Ëå\12ð\83ð*A
+\8bÅ"º&ª}Ë岤wz½\1e\1e\8fGx\83ô\ 2¤5óp8Äd2\81Ýn\17¾Ú|>\17'Y»Ý.3\8fÉ|1\1a\8dò[è\9b±µµ%-\ f¢±t;2\1a\8d8<<Äl6õkפqúüùsäóyär91\ 2eo\86VÛ4æ<>>\86ÃáÀ½{÷D)×ë±X,pëÖ-Ìf3<\7fþ\1c¡P\b\1e\8fGÆÖ\12Èév»(\16\8b¸\7fÿ¾\80
+z½\1eûûû8==E"\91ÀÖÖ\96¨\86\89Øy½^d³YA$U*\95|7\8eM"#\9f)^V\93ÅÌt\8b\r^\8bÅ">\88´\17XF°É¹dÉBÒðññ±x\96\94J%\8cF#1we[\80ÙѲ·äb±À׿þu1Q%\10ô«î\8fÅbñ\89\ 4\86\r´\83\83\ 3I/ªÕª,\8aeêϵk×dt\fùxD$Yè25"\12ÆÔ\87sª666°··\87z½\8eT*\ 5\93É$H\14½ØØäUn6\9b±±±!\fj\9e\92¬\1fÊå²\ 4q4\1a!\1a\8dÊÈ\9b££#looË\rãt:å»\10\ 2¯T*\ 2ù+\14
+\84B!¼óÎ;èõzxòä\89ܲì\9b1\1dãTG»Ý.¬tö &\93 r¹\1c"\91\88L£$=\8a\v\82u
+af¢\95Óé\14ûûûðz½p:\9d²\88\v\85\824ó;\9d\ evvv$\1e\ 6\83\ 1³Ù\fGGGr"sü,[-LÍidêñx$Å\1d\8fÇ(\14
+\98L&ò]x#år9ôû}\1c\1f\1fcwwWZ(³ÙL\9aÚì\11v:\1d¡¤\r\87C¡¥\95J%¡¦q!2\ 3I&\93²\86ø¾GGGÂ\ e\8aÅb\ 2&\9d\9e\9eÊ\9a\~f\84ã{½\1evwwe
+&A\1c\8dF\83l6{%\1e´Î#-¯ÛíJ\93Üëõ¢ßïËgìïïÃf³!\1c\ eÿÊûCI\9bb¯×\v¯×\8bb±(\88\1a\11:»Ý.<?~\ 1\ 6-\10\bàìììʤÄå¾\ 5=\148ñ\83ïqyy ¿ß/5D"\91À\9d;w\ 4ý"\8by8\1cÊ÷¡O\1e\aÅ5\1a\rñJ'½GV£P( R©ÀápàÆ\8d\e\922,\16\vd³YñX'©9\99L\8ac\12ae²\ 3\88@y<\1e|üñÇR\83\91AÁ\16\ 4oõt:-§!§\91\90¥A\9a\13§£x½^a¼,/\18¦EÁ`\10ÙlöÊð\ 3Æ\83}3\ eKg\9aIà\85é\14aäX,\ 6¿ß/z«`0(3\91\15
+\ 5Òé´¸øòE\9d\16=1Z\16þë¿þ\v:\9dNPS¢¹ÙlVN}ÞâËÃÞ)]Ñh4\92Êóö\1f\f\ 6\b\85Bp8\1c8::\12)˲Cñ£G\8f Õj±»»\v·Û-ïÃÃ\9cæ5\93ÉDjíR©\84\8b\8b\viøÛl6ÑÖ\91\ 5¢Ñhàõz\11\8fÇqãÆ\rD£Q\98L&É8Úí6²Ù,<\1eϯ½?ÔL}hÅ\8e~.\97\13
+N·Û\15».²£»Ý.666$HF£\11O\9e<¹Ò\1cä4\f6g9Ac±XàæÍ\9b¸¸¸\10n\eÕ®:\9dNÐ;\9evüÌ\e7nÈ\ 6có5\1e\8fãÁ\83\a888\10x\95õK,\16\83F£A8\1c\16h>\9bÍJ^}qq\ 1V+}1¦\8a´
+Ëd2(\95JÐëõØØظâdËÁ\f¤1\r\ 6\ 3\99dB \81¦\98ôF§±èh4\92÷åɹ̶`\7f\89 \86^¯\17a Ãá\90±>\16\8bE\9eM§ÓÁöö¶\10\91Ëå²ô\11¹ ûý>Âá°\1c\ 2*\95
+Éd\12Ãá\10ÛÛÛØßß¿\92\89Ìçsi\8f\90½îõz¥\ 6ôx<Ðjµxþü¹øÇollàþýû8::\92[z4\1a!\95JI¯\8f\a0QåÅb!ó\96766$ÍnµZh·Û¸¸¸ÀÊÊ\8aÔBìi-?3Òôü~¿üVn¬z½\8eZ\86@ p%\1eTH\93?ËAíÄ)®_¿\8e\9füä'èt:\82p\13üùUö\87\92¨\17?¬X,¢^¯Ãn·KMÃ>\17;ê\84My\92\8eÇc4\1a\røýþ+'\fS4\95J%i\ 2û\16Z\16f³\19\17\17\17Â\1d$\93\80\8c\fæíä@6\1a\r\9c\9e\9eâéÓ§xë·pûöm¨T*\9c\9e\9e"\1c\ e£V«\89"÷\95W^A³ÙDV\93q<z½\1e\9fÿüç1\9bÍ\90Éd\84fU(\14® \8aßùÎwä¤î÷û¨V«RóÑÒLV\8bÑ\vµT\94m\90×Æ\1a\90\ 4X6ÂYO\\\È©½üÒétp¹\\92nT*\15Ióþ§xP3Å\98ð¶h6\9b¸¼¼\94\96\ 6»Õj5\9aͦ@üÔÓ-³<(ì\,\16ØØØ\10OFZQ'\93IX,\16ܽ{W¨UgggWâ1\1e\8fqíÚ5a\97,3H^yå\15L§S$\93Iø|>Ìf3\9c\9e\9eJ\r<\1e\8f\85wÊ´\90³Ë\96×\19ÇèªT*Ù°T\85ü²x°>å\l¶\9d¨Ú.\16\8bB\12çä\9b_g\7f(¯]»&(T·ÛE*\95\92æ\1cE~\9cÈøìÙ3\11ä\85ÃaL§S\81¤Y°.ÿx¢\80¤¹\18\8dF¼òÊ+¢"V«R¼s$)\9b\99$Åò¤âB'SºÙlÊ\ 4úÕÕU\81\99Ùí???\87ÇãÁÖÖ\16\86Ã!ö÷÷a6\9b\91Ïç¥\10???G:\9d\96Ïa\8eN§!"¤$¸\16
+\ 51oá¦%û\80\vÏ`0`ss\13«««R\vP/ÅT\90h,g~-¿ôz½0ê[\16\12\89\ 4\8e\8e\8e\90ÏçÿÇx\90\15Ï´\987!\19\1d¬\97\9e<y"¾÷f³\19×®]C¯×C½^\97aè|\11e£Ù\ ee/&\93 étZho$FÛív\98L&Äãñ+ñ \ 1\8043Ö{\1a\8dF¼1\9cN§hͨd ÂLñ(\9bÖ¬1\97ÓE¦àÍfSnB¶\86¶¶¶þ[<¸>©McVÁßS.\97ñ³\9fý\f«««rÈüºûCI\ 4\8f\6³Ù,4\15\83Á \83§IybqHõg,\16Ã`0Àáá¡\böø"4:\9bÍP.\97¥\91Ûjµp||\8cP($\8c\10r
+\e\8d\ 6\8e\8e\8eäÇòE6\85ÏçÃ\17¿øEÌf3q\1c\1a\8dFp»ÝøÒ\97¾\ 4\97Ë\85ÓÓSlmmassS
+T¿ß\8fgÏ\9e¡Ñh\88}\97Ñh\94[\8cµM¿ßG4\1a\95T\80\ec\7f\7f_ ÙÅb\81R©\ 4¥R\89ëׯ\võ\87\e{ggG¨8ü~ÍfS\8cEV«ôÏ8_xù`"\bA\1a\r79âè\97Å\83½F
+\12yú§R)ܸq\ 3ëëëò½©Xfm\99H$¤¶[î\15v»]ìííÉâÞÛÛ\93æ/¥\1dT\d³Y\ 1\9f\96ãqvv\86x<.\1e\18¼}\1a\8d\86¬£`0\88ÝÝ]Aü(\b-\97ËÒ\ 6 8Â6ÑrºH2Ã\83\a\ f\ 4\94:88\80Ïçû¥ñ`MR©¤\ 6óx<\98N§(\97Ëxíµ×¤Õ\90Íf\7fíý¡ænãàîP($^r\0ppp\80\e7n \91H\88%\17\vø~¿/jÖ¯\7fýëxþüù\95\93\90ÊZ\1a±p´\8cÉd\12ÈxY\ 4\97N§ås©>]&t\92\9bÈAãgggðx<(\95J"\1cìõzÂçÛÛÛ\93æ$óir"§Ó©Pv\96OÃ/}éKW\1cb¹P§Ó©\f\7fûÙÏ~\86»wïâòò\12³Ù\f+++Ò'#\95\89í\ 1\93É$Ú(\8aS3\99\8c\10P3\99Ì\95MFí\19Á\96û÷ï£R©È ó_\14\ f\12¯»Ý.\92Éä\95l\82,\8c\1fýèGðx<ø\8b¿ø\véÕ\11í#·ðÓ\84[\8e6â¼d¿ß/r\9aB¡ 4;ZÉ]^^"\1e\8f\8b\9d\ 1Ó¾µµ5!\95ó\10f\v\88Sb8àB¡Pàþýûxüø±¬Çét*¶\ 2Ô=òFdí8\99L\90N§¡Õjño}K¼BR©Ô\95x°\11Í6@:\9d\16ò@4\1aE±X\84Ãá\80Ïç\13\95D.\97û\8dö\87²Ñh \9dN\8b\9bQ"\91\80Ùl\86Ãá\10~Z*\95\92ü\95BÊB¡ ©Ä`0@³ÙÄÚÚÚ\95\9a\8c©âÞÞ\1e\9aÍ&´Z-l6\eîܹ#ðs¹\9cð\1cçó9R©\94\0\ eËiË`0\10¦\ 5§&^¿~]\1c]3\99\f\ 2\81\0¶··±³³#f/\ 4<J¥\12nݺ%Á©T*H&\93ò\19ì#ùý~¸ÝnD"\11Ñy1\85¥Ó\92Ãá¸ÒßJ¥R¸¸¸Àl6C6\9bE"\91\10º\12\17-)Pìélll \95J]©S\98F\11\91¼¼¼ÄÉÉ ¬Vë\15rô/\8aG>\9f\97\9bgù\94§\ 5D4\1a\15g§½½=iÎZV\»vM\94Á\ 4\94øj·ÛrÐÄb1ܸq\ 3?úÑ\8f\90L&\91Éd\90Íf\ 5à¢ü\85sü^/Ö××±¹¹yÅ.\80\e\83\ 6:TAd³Y¬a±X`ggG¦g\92^W¯×\91ÏçÅ\87\7f9]d\8d©P($Åfl\96E»dïS!°··\87½½=\94Ëe<\7fþ\ìÜ\9aÍ&NOOQ¯×\7fãý¡ÜÜÜ\14\1e\9fÃá@¡PÀl6\13ÊÊîî.Âá0¢Ñ(|>\9fì~Ne¤áH0\18¼rR-\13l\ 3\81\0\8aÅ"~ð\83\1f\0\0
+\85\ 2ÖÖÖ°±±\81[·na8\1câñãÇBy:99¹\12lææwîÜ\91<\9a\rßJ¥\82ííma\apV\14ç÷j4\1aq)â\80ºR©\84½½=¡ÉÐ×\8fòw¦[\84çé£Á\91«ì©ñ\ 6&[\84Mo\83Á |Èv»\r§Ó\89ÕÕU\99\88rëÖ-\19Pn·Û%\95á3³ÙlÐëõ°X,²\88S©\14\9aÍ&nݺu%\1e½^\ f©T
+*\95
+'''âu²|[\10î¿wï\1eúý>¶¶¶\90J¥ðOÿôOÒz\88Åbâ\7f¸¼x\99>F"\11Ôëu|÷»ß\15ß\94@ \80V«%ÈaµZE*\95\12º\19YùO\9f>\15[\ 3®\ fZ\1cÐÆâèè\b\1a\8d\ 6\1f\7fü±ÔÕl\95ôz=É.ØD_Feys/\1f$\9cNãóù`0\18P*\95¤\rÂ\81\82\8f\1f?Æññ1Êå²XÂ9\9dN\84B!ißüßØ\1fj·Û\8d×_\7f\1d{{{\12\búàE"\11\99ÙD\7fp\95J%\83\vØí¾\7fÿ¾8ú,çôlÔíììÈ¿?==\95Ñ£\84QYèÿä'?Áññ1.//¯\9cÄìU)\95JüÝßý\1dòù<ÎÏÏ\11\8bÅP©Tpyy)\80\b\17\9bÉdÂ\9d;w°²²"\ 2Sz`\90áÁ\ 2\98\´ßû½ßC$\12A \10Àóçϱ½½-`\09\85$\83îíí!\10\bàââ\ 26\9bMê\e¾\1fYõ4éaÀ\97O`Jb\96{\8b\1a\8dFÈ*\95
+_ýêW\85\ fº½½-ua4\1a\15\7f\fò\ 5ß\7fÿ}\9c\9f\9f_I³ \f}þó\9fÇ\87\1f~\88¯|å+¸\7fÿ>\9aÍ&ÎÏÏqqq!VjD&\97ãÇ\99eôÅ BúéÓ§"¥a\1aëv»1\1a\8dðäÉ\13¹¡\99MðöàáI \88\19\ 2[8\ 4±ÎÎÎ\84¾¦ÑhP,\16±µµ%\83û\96y¦Ô+N§S\1c\1d\1dá·~ë·¤n&!¹×ëÁl6\8b\95\eµoäd\92\83\e\89DD\8fǹϿéþPw»]iĺÝn\11\1fÒ\1c\87¦4©TJè>jµ\1aét\1a»»»P*\95ø×\7fýWÄb11ç_\ e²V«ÅÏ~ö3\98Íf|éK_\12_\87G\8f\1e ª¨ÑhÄ3\83|<\ 6Âf³\89ì#\18\f
+R\19\8bÅ\90Ëåpvv&ý*\8fÇ\83D"!'e¡P\90> y\94\9c#Ì[\8cßÓjµ"\10\b`0\18àüü\¬\ 5"\91\br¹\9cÔ\94\89D\ 2¯½ö\9aÈ\1d83\99t*ÒÌh°É\86&\89ÆVKÒ
+³Ù\8cL&s%Å&ÐB/\91z½\ e\8bÅ\ 2\9bÍ\86Á` NOÉdRdô\93É\ 4ûûû\ 2{óE6y¿ßÇéé)þê¯þ
+Íf\13?þñ\8fÑívñöÛo\v³ÿôô\14Ífó
+jÇø\11)\__Çåå%NOO¥õÀZ\95\87èòMÅ\rÄZo\99AÁf0o\8e|>\ f\8fÇ\ 3\9bÍ\86\8f>ú\bf³Yüé¹\ ec±\98¸Z-?3ʳ¸ñ\98:Ïf3\19µD\90\8bÀ[:\9dF*\95\92¿\1f\f\ 6±³³#Þ\92ìÙr\90âo²?Ô¼n)<\e\8dFb\96Â\1eJ¹\¾b&ât:áñxÐl6Q*\95àñxÄpeùE§ZjÁÈí+\14
+H$\12R\90R¯³|:q\0Á²\b/\12\89`\7f\7f\1f\1e\8fG~P·ÛÅÊÊ\8aè\9ahj³\8cn>yò\ 4N§\137oÞÄþþ>\ e\ f\ fåÁÑ:\8c\8b+\18\f"\9dNÃëõ
+\90Á\80òÄ\1c\ e\870\18\fÂh¿~ýºlb2U8\0\81µ\0Ó\ZËQ.Do\93å\17]¤X\v\96Ëe\91Y(\95J\14
+\ 5XVqâB \85\ 2\ f(\9aÚXVT«U$\93I|å+_AµZÅÿù?ÿG\18\1aäz\92y¿Ìø àb±Xpxx((){\88t\1ecìI\15[¶\ 6àÿ2]d\rå÷û¯ØK0ýe\7f\94ýÍjµ*©éåå¥Ô¬Ë/Nz¹¼¼Äõë×ÅA*\95J¡ÓéÈ÷#Ð\92ÏçeÓ³¥aµZáp8\840@äù7Ý\1fj\ 6$\9bÍJqIò-eÞ\94·sÇSR>\1e\8f±²²\82\95\95\15$\12\89+\ 3Öøbξºº\8av»\8dÓÓS\91\95ÐzëÓþ\16jµ\1a\81@@ÆýÜ¿\7f\1fßùÎwP.\97åôyüø1\1a\8d\ 6>ûÙÏ
+»áÚµk8??\17½\1ak'ª¶Éãã\rÄá\bñx\1cwïÞ\95ïÁô\8b°ð²)\8aÕj\15åu½^Çúúº¤|TýR:Ab)Õ\ 3\9cöa·Û%0¿ÈÛ\83ñX[[\13 \85\86§¼9é\16VVñôéS\1c\1c\1c\y\ f\97Ë\85`0\88@ \0»Ý\8eo\7fûÛèõz(\16\8b899\81Íf\ 3³\18Î\84\8eÇãW6\19g#¯¬¬È;\9dNñÆ\eo X,\8aø\95Eÿl6C0\18D§ÓÁx<\96\rBú\12o%n`Z\19PºÂM¿³³\83çÏ\9f\vw\92¾õl{,\9b:-³d\88\f\8eF#ñ\17!mkÙ_d9=çaÎÍÍõÛï÷áóùpyyù\eï\ f5{1\1c\9aÍü´R©\\11ܱxäè\9d\8b\8b\vi\14\96Ëe\81L\97\7f<Ù\ 1\1a\8d\ 6\99LF¨E<¥>ý°X§Äb1!y¾óÎ;¸}û6NOOát:ñ¹Ï}\ eßûÞ÷D¨Hn\1eQ3*«kµ\1a\ e\ f\ fÅZ\8e\ 5~¹\\96¡ÝL©t:\1d¶··Å²\8d\9e\e\84î9a\84¹ør:DfÁêêªØY\13ºg;\83ü¾ÍÍMQ\16\90~ói?\r\1aópÔì`0\80R©ÄÉÉ\89¸óv»]ôû}I{i\85À\17\vöh4
+\8dF\83?ú£?ú\84C§Vãý÷ßG©T\12\94\8d\r[ö.)ñàT(\14àt:qíÚ5ìîî
+dÿýï\7f\1f\e\e\e¸}û6Þ{ï=ñwd£\9e\0\93Åb\11}\17ëoúx\90\ 2F#¡N§\ 3\9bÍ&\ 2Ýjµ*h%\91ÜN§#³\9f\977\19\aO\18\8dF\99Z³\9c\9a.\13±Ù®à\1aå÷\9eL&\ 2xe³Y\84B!üßØ\1fj\ 6\9cÐv$\12AVÃêê*\86áxA\90«vtt$b>½^/\ 51A\8cåS\82Å?5I\1c\MÂ0sýe\a^£Ñ\88P(\84·ß~\e÷îÝ\93\8d¹¾¾\8eT*\85\1füà\aB²e h7@û3\16ׯ½ö\1aæó9úý¾<øåF&9pkkkÂE¬T*\92J\18\8dFܽ{\17\99L\ 6Åbñ\8a-¹ÍfC<\1e\17Ý×ññ±\98ö0\9d\98Ïç(\16\8bÂvÉçóðù|¢îV«Õøà\83\ f®Ô*¬ÉÈ\93T«Õxòä\89h 8M\92ò\9aå\17\11°X,\86x<\ e\93É\84/~ñ\8bÂ`/\16\8bÒ¬w»Ý°Ùl¸¸¸\10Ù¾×ëýoé"\9dÄ
+\85\ 2þöoÿ\16\9dNGê§B¡\80Ñh\84?þã?Æp8\94´Z¯×KíI¿G:\e\9f\9d\9d!\97Ëáââ\ 2ápX\ eâV«\85·Þz\v\83Á\0[[[Øßß\97øòw\ 6\ 2\ 1a\93<\7fþüJª¨P(\84äëõzqrr\82h4\8aN§s%í£º\9a\9cUÖ~ñx\tuõz]ÔÝÝnWÔ\ 2¿îþP\13\96äµ9\18\f\10\8fÇ¥'A×Ør¹\f\95J%j\.\bNûX6\9e\þñÅb\11¯¾ú*Âá0nß\12¯\96&\0\0 \0IDAT¾\8dét\8aG\8f\1eÉà\81\1fÿøÇ¢\\9eL&XYYÁ\1füÁ\1f \14
+ ªöꫯJ\9aDuíêêª\18þ·Z-!»\8eF#lmm!\14
+a6\9b!\99L"\9fÏÃjµ"\95J]é\8dq@^,\16\93áu\1cÝJÙ>{läÑQ¤J\9dR±XÄÙÙ\99\fÁcó\99T 6j9c+\95JI¾NÁà§)Bd}8\1c\ eQ\a\93yÀC\8cMf\85B!
+nzgºÝn¼ýöÛðx<\b\87Ãè÷û¢1£â\97\8c\ 5\8bÅ\82D"\ 1¯×+\fúåC\92é¢×ë\15ÆÌ\eo¼\81@ |M\1e4ív\eétZ4b\14OÞ¸q\ 3\1e\8f\a{{{x÷Ýw\91L&\853Øï÷EþÔét`2\99DûÅþ\19']\86Ãa,\16\v©å?Í]díùúë¯ãÁ\83\a\925ðÙQû×ívQ.\97Q«Õppp ZC¶\8a\0àääDÌ}\98ùüÚû\83\ e\84à\99¿rî/;õ$\84r\92 ÙçdqP\86¾|º\12¢5\99LBÁùÆ7¾\81\a\ f\1e \9fÏãââ\ 2·oßÆÑÑ\11\14
+\ 5"\91\b¶¶¶ðÏÿüÏbÖòÚk¯áìì\fÉdR\9a\80\91H\ 4O\9f>\15\8a\14õW+++\ 2÷\92Çæõz¥®zòäÉ\15£\1c
+<)\8e,\95J8??¿"6eÚÈ\9b\83·>ÿ\99ô\9d7ÞxCܱXøó&b\7fnyJ ½E\96©cË\142ÊD\8e\8f\8fe\9e\17ý<Ȥ\99N§R¤\a\83A1+b¯\8b\eÒétâðð\10\97\97\970\9bÍ¢Ã#\90âóùD\7f·|H\92SÈÚëöíÛøìg?\8bb±\88óós\89G4\1a\951K\14¸>\7fþ\1c\e\e\ep:\9d\92B\7fôÑGâ§È>×l6ÃG\1f}\ 4\8bÅ\82ñx,u\10k\Þ<\e\e\e\0\80çÏ\9fË\0ùet\911& \81u43(\96&óù\\0²áp\88ÍÍM\94ËeܺuKRQ¦³üÿ¿éþP\93Ä»ì=\9eH$®8\1aQ&Ïi\82$¶Ò#\91éÚòD\16æ»\84¾\99k3\ f\ f\ 6\83¢Cóx<Âõb\9dÁúà\87?ü¡äõ\1e\8f\aù|\1eÿò/ÿ"´£\83\83\ 38\1c\ eܽ{\17ÑhT
+S\ 6\82cqNOO¯\98x²QKGZ\9a\0\91rEq&óxJ)8\19\84·¬Á`\90q=Ëu&å0³Ù\fn·[Ná½½=iz//\92åúb\99Áð7\7fó7ØßßÇ÷¿ÿ}looË\88£¯|å+â\ 6FT\93uH0\18D2\99\84Á`@¡P\10\ 42\12\89HàÉ°§X\96àÍ2]\89\aÄh4Â\9d;w\10\f\ 6ññÇ\1f\8bM\9cÉdÂÉÉ \1e?~,-\8a\8f>ú\bN§\13ׯ_\97\f\81\v»V«I¯\8c5\10\ fæT*u\85©â÷û1\9fÏ\ 5RO$\12â±É\ 6óòM6\1c\ e¥eÃì\801ã\ 1Éx\90Uòøñc\ 1Ç8¤\83Ss\82Á \8e\8e\8e\ 4\92ÿMö\87\9aì\0ú\1a\12\1d\v\ 6\83h·Û\98L&²H:\9d\ er¹\9c°)R©\94(K}>\9f°+\96\83¤×ë\85SF\90 X,\8aE×l6\93éö\89D\ 2+++ÂuËår²\19èÊûþûï\v\15¨ÛíâöíÛ\18\f\ 60\99Lâ7o±Xp~~.'R>\9fG"\91@6\9b½Ro\90®3\18\f\84\8aåóùP«ÕD`j·ÛÑn·áv»¥%@_½Z\ 6§Ó)è%½þ írr
+\91/§Ó)DgÒ\9d(åù4\14]©Tpýúué÷üõ_ÿµ\fÊS(\14\88F£b\0JD.\95JIKçä\8b\8b\v¤Óilll\bu*\93ÉHL ÖÐ\v\19\1d¦Ô\9fñ(\95JR§ñ;>~ü\18f³\19ÛÛÛèt:ØÝÝ\95xð\ 6÷x<\12K\1eÂ\ 4~&\93 nܸ!Ên\ 2 >\9f\ fétZ@,ö5].\17\9e>}z\85ô@^+¹\8fL\v º]^^Ân·\8b·?g5°ßåt:\ 5\1ddy°X,\10\ e\87¥¶üMö\87:\10\b \9bÍ
+»¡X,â3\9fù\f\92ɤäç×®]\13çY\1a^rp\ 3\11ª_t\93qÁìîîÂd2ɬ^zø-ç¯\1cøMÊÔb±@:\9dF(\14\92ÓÔl6ceeEЦeÿs
+!«Õª\f\1aè÷û\88Åb8??G2\99\14£\1c¦n\81@@,í\8cF£¤U\1e\8fG<\ 6\99rµZOF\93þ\1cº\9dÏç\ 2^ÐÎí·\7fû·\ 5ú5\99L\92\9a\92\98|~~\ e\95J\ 5¯×+sèÀ^®\13ùÌ\95J%\ e\ f\ fño}K¸xjµ\1a¯¼ò
+\92ɤ\90¬é\87á÷û\85ÅÂÙ\´WcÚÅѬ¼)³Ù¬\10\ 2X#}Ú®\9bÏ\96õ7u\87\9c³Lí\14Ójº(\97J%!7Óä\87\v\99¤^~'\1eXä4Òº`\7f\7f_\fH\8dF£<ßgÏ\9eý7\12ôÖÖ\16æó¹hÜÖ××Eâ¤×ëq~~~åséµ\12\ e\87¥ÇÈç\95J¥\84:F\ 3£_w\7f¨¹k94\8dW -½®]»&·MµZÅÚÚ\1a¢Ñ(2\99\8cðÀ8³\89Þ{|Ñä\85óÏø y\92ü?í\9dYSÛé\99öo\10b\11\bÐ\8a$$@\ 6\83ñ\86ín·S\1e§&\9dNW¥jªf¦æd²U\96\93|\ e¾A*\87ù"ÉA*©¤;\9d®ôô¤Ûv³X\80¬]BB\v\12Bìz\ fÞù]%\9cdÞtú=¢ðQ¯¶Ðóÿ?ÏýÜ÷uý.jbæ?´¬\1d\ e\87ÍÏÏ["\91°_ýêW¶¼¼lóóó\1aHrÒ<xð@
+\80ÁÁA\8bÅb\16\b\ 4lkkK´\\9a\1d½J\88±±1\8bÅböo}KyX»»»¶°° ²/âÙýý}å#ã,Îd2öÁ\a\1fØññ±Ý¿\7f_T&8\17¨âý~¿åóyËårj2°yP¢y<\9eKÚÅ^ÈL2\99´\7fþç\7f¶T*¥\97vyyÙö÷÷e'\90c{{ûRW\12N!Z¾N§cårÙÆÇÇÙl*\87ÍëõÚþþ¾Ê\9eÞ2\f\19ÕÄÄ\84\ 4»¨)\b\9d(\14
+¶··g\95JÅ\1e>|hfvi=ü~¿Æ\ fð;Øx|>\9fÆ\f\91HD\9aÑ££#Ù\98\18ü\ 3®á¤zÓ´\89¨wyyY\9cM Ql\16\90ÅPÝ\87B!EI=}úT´+\94úT _õýpüøÇ?^Íçó\97r¶À¯\ 1\9f<??×\90×ívk\9e\80\91¯7¥cssÓ*\95\8aJ2x\f\98 á!|þùç¢,Q§»\.«ÕjÖl6UrÀÊp:\9dªÉ)Ý8\9d(\178qÀ,sÇZ__×\8b×××g·nݲ`0hï¾û®vj\90Ü\10\99¸OÂ\85ðûý\16
+\85¬ÝnÛöö¶\8c§§§§\16\8dF5\98¦arpp`ýýýV©T\942sttd\81@@PVRlP´\9b\99¹ÝnÍq\ 2\81\80-..ZVS\89IJåÚÚ\9a,\15xï\90^¡½£Ôåå\ 5ð
+\8c\88ÐF2\93OOO5®à¡t:\9d\ 2å,//ë4\1f\19\19±íím9Ä\87\87\87¥Æè]\8fF£a\91HÄÜn·½zõÊ\8aÅ¢N´ÑÑQ[ZZ²ÙÙYëv»öèÑ#U3ÀOéðöÎ\13³Ùì%i\1c!\118ñ\9f<ybûûûânð{öFæ\92A\10\8bÅ\ 4BÂ\92D\ e4²¾¯ú~ô_\\X<\1e·ÙÙYÕ«Ü\ 3\90\9b@I\85g\80\8c§¿¿_\9c\87^ûwïNÈ\f\8cÈ\9a\83\83\ 3ûÓ\9fþd\ e\87CZD\1e`\bÂäöîîîʸG\88D±XÔ\8eLø\ 5\83Yvræ=^¯W°IÊ( 0?üá\ f¥tç\81Gý\80Dlooϲ٬º\9e###\9a¯p\9f \94Â\8d\8d¶\12\1a3m_\1eÎ\.§M\ 3pM/û\82FÐìì¬år9\ 1^Ù\bØH¨ \9aͦÕj5«Õj\978\91è\ 2\199\02j4\1a\92s\ 1\8a}ùò¥9\1c\8eK0\98Þî"ëN×\96¦D>\9f×fãv»56ù[ë\ 1ö ·ÒÙÜÜ´f³iËËË\9a±ñÒÐlà3ãà&\83¬÷N\ 6î\9d±\a®y\1a4àÝ ü¢Ú\80\9d¨àððPò1bj¿êûÑ\9fN§eÁ =\90\85¥!\12\ e\87mnnN\ f"\96mN\17ZÊLÝ{\1f\18ÂÞ\10\9b¦Ói5.\80bÞ¾}ÛÂá°:@x\8cFFFlmmÍJ¥\92ýö·¿ÕÎ\0\8a\8c¡",F\94\10\84HàSë\15\ 3»\.k·Û\96H$.\r¢{[¶\98ý¸Çäóy+\95Jvrrb\9b\9b\9b2\8fB &L\8f{ \7f\1d\89Dd\88ÅÊ\ f\18\96ú¿·TäÄ!\96\95õ@ÝM)\16
+\85\ 4*×ëb%\ e\f\f\88¦Ä¬n||ÜÆÇÇÑh¨s:22¢î"âçÅÅE\95÷üB\1e5??oñxÜ&''í£\8f>²õõuÛØØ\10\hppÐjµ\9aÖ\83\jÖ\83TP^ÜÞ\12\ f¸Ñï~÷;EYMMM\99×ë\95A\97\13\11á\ 1X¼Þ_N§Sw9þ=\90(\9eÃ`0hù|^
+\11Ö\83,ìb±x Ýpvvfÿ?Þ\8f\ 1vÞW¯^i\97&\1fÊív[,\16Ó\eîóùÔaCPÊüÀétÊÌØû\83³\13±¸$h\94J%í(N§S`Ô±±1iÔÎÎÎ,\1c\ eÛÙÙ\99\95J%ÕÄ\94\ eÄ\99Ò\89k·ÛºÄ·Z-5$(_Ù#\91\88ÍÎÎ
+§Ì\v\86ZÃívkþ·¿¿oápØÖ××ÍétÚ½{÷dÎ\84`Ûn·\952I3ÀëõÚÔÔ\94(K
+\18\8aò"râ¿ùkssS\1aJ·Ûmù|ÞÂá°\1a\rÿ¯õà\ 4I&\93"CE"\111JºÝ®0ÝtÏÞt\1cÓlBAö6/{¡P°ééi½\9c¨aÊå²Ý½{×\ e\ e\ eTbñàõ6Å°ñ\87B!\r\99Ýn·\86Ê\94áÌ\a¹\1a`N}Ó´\89^pppÐ^¾|)[\12
+ùx<n333
+\ 3á\19â\1eHr\ f\1eHÀ8_õýèïïï\97@\13@\rYÍVKl\aXt°\16\bë;<<ÔîòòåË¿xX&''mhhHísvev@\86®ápØ\1e?~,Å\ 4\881î\ f´\84ñ\ 2¥Ói¡¡ÿé\9fþI\17{\1e\ e\×\e\e\e\1a\º\.»}û¶}ó\9bß´¡¡!\ 1H\19\ f0÷¢K
+@åùóçb\1dRæ\11b~zzj{{{*\83r¹\9cL\83ÇÇÇJ¼ä\ 1¡$âçÁVÿ¦z\9e]¸ZÚÄÄ\84ÍÍÍé.ð÷®ÇÇ\1f\7f¬\ 6\ 3\ fc,\16\93¼\8cÓ\94;\16ÃùÞS\9fr\94M\81à\86ááa\8bÅb2\8dòàÎÍÍÙ³gÏd½g=p·³¡p\12ÄãñK¹jµZMsSF\ 6\9câ\ 47¾Ù`ã;ÝÝݵÓÓSe¤\99\99e2\19)YH\94\ 5\18\8bS`hhÈ\.\97\9aEÄ\1e1OüªïG?\93{\86\94\ f\1e<Ðe\9aä\vºO\94s\81@@¾)\87ÃaÕjÕ\ e\ f\ f\15)ôfp\9cÇã\916\10è ZB.Ë\0O\0\99ðÅ°ÃÌÌÌØÈÈ\88íììÈ"\81\14\a\80e<\1e×\83H\84k¯}\86¹\15\19cËË˲ÚP\ 6d2\19 Y\ 1ªÎÍÍ©Y188h>\9fÏ\ 2\81\80\8c§\9cLVËb±\98\86 ëëëò°Q~ÑÎ\1f\e\e³{÷îi¦Ó{z0T><<´Ç\8f\1f\9bÓé´z½.Ç.\10\987×\ 3N"\18<6\82½½==H\bx¹Ó°\9b\17
+\ 5=\18½\95Èéé©mllè\9f3À¦\8cs8\1c\9asmmmÙáá¡P\fñx\0ÑÞö=Ï\86Ëå\12X\96\96;\8a÷óósÉ´z×\ 3\98RïÝ\9f±
+\98AHb\84ò\81ðÛÙÙ\11\95\8aþ\0³Z·Ûm+++\9a\aâOû*ï\aëÑ?;;k[[[æt:-\16\8bi·\8dÅb\96L&ÕR/\95JÂjÑí"\18\81ûÉ\9b6\ 2Ôì´¾IsAèÙ\vè§\83599i\91HDÌ\ f\1e<\94\vÁ`Pª\b"l+\95\8avl\8fÇc[[[Öh44: áÁé477§ShrrR\16\f¾ RVÚí¶\ 6Íü·\94P(Í\99ót»]\r{\7fùË_ênùÙg\9fY©T2§Ó©\9fóüü\.m.Ͻs20i³³³\92nÍÎÎÚææ¦\1d\1e\1eZ__\9f\95J%\9d\ 2ÜÉ\bnÇk\87ª\824\1e¸\16\9dNG%Z$\12Ѭ¨P(\\92+á\19óûý\1aò3óÊår\96L&5ô\86çQ©T$4ðûý\92U\81\93ë½N0ò\b\ 6\83jß\87B!¡¿éNCñe\13{Sô@W\91n/\96\17\Ð¥RI\1dÅ\17/^È×Ƚ½ÛíJÈ\80§\8cÍý\1f}?z×£\1f\8c6í`\bEÍfÓnܸ!hãÍ\9b7Íív[6\9bµl6k>\9fOe\ f.d\14ù½¿P\ 6à£\82ïÇ \ f;;ÆÉ`0h>\9fÏ\.\97°c\94(wîÜ1§Ói\1f}ô\91vóããc[XX°n·k¯^½RÐ\ 1@\9eÞÝÎívÛ\7füÇ\7f\98Ëå²\e7nX©T\12Ú\19\9bM³Ù¼Ô\9db\9e7>>n¯_¿V{\e\86\1fó\9a½½=\99)£Ñ¨²¡d}öÙg2\81.,,Øøø¸ýñ\8f\7f\14@³·YD÷\11æ\7f·Ûµl6k¡PH;øÂÂ\82<^(8z!±\942Ìu\18ô\12]Äz´Z-k·Ûz1z\85·l\80\94î¬\15\9bêÒÒ\92\9d\9c\9cX:\9d\16õybbBÐÙ-Å`õ"ØØ\8c¹#\93\ 3F\89\88\92\82ç\10n?\16\13X+½¿xø!G§R)K¥RR\9cüùÏ\7fÖ\89åv»U\ 5\1d\1c\1cØòò²MMMÙ\9fÿügU\15\8c6þÑ÷£w=\ 6`ÞÑmÁÔH4\10\13vì"½\9a°z½n.\97Ë\92ɤµZ-K$\122U²H~¿_¥b/Ñ\17\82R__\9fE£QQ_Ab³\v\8c\8d\8d©u\.\97ÛíÊbÂÃ\8f\89ÑëõZ2\99´t:métú\12ñ
+ Õîî®\95ËeµéÏÏÏ-\1a\8dJ\9dÝl6e\92d8\8b\vöääD TÒA\90ã\10\80¾µµeÃÃò\83`\91Á$é÷û-\9bÍÚÎÎ\8e\15
+\ 5-Jï%\9e»\1f\7f.É0X*âñ¸fZ\94J¼\fd5ûý~Ù<<\1e\8får9\e\1c\1c´\e7n\\8ax¢B@\9dÑ+=ë\8d·Õj\96H$¬¿¿ß²Ù¬:y\ 3\ 3\ 3¢T¥R)óûý\1aq\80:Ïd2J²\14U÷\7f\9a\\0o8\1d\18âÂ\ 4\81òupp qL.\97»ô\9dѽ½yó¦¼w¬\r\81ê½zUÌ\94gggò\ 1\12mË8 ^¯k~÷eß\8f7×c \16\8bÙg\9f}f\87\87\87\16
+\85ìáÃ\87\96H$\84Ñ¢\94á®@Ë\1e·ë\1fþð\aͯzU\15Ôô}}}Òye³Y\11\8d8¢ÉÛ\9a\98\98PûøèèÈîÝ»g©TÊ\8aÅ¢MOO[¹\V§\11,r>\9f7§Ó©Å£>N¥R\97fO\94\96¥RIò\99\ f?üP\ fô½{÷TwS.\11î\80l«×
+\93H$¤\0yÓ6\83ÄgjjÊ666Ô\14 \87ÃÒ
+f³Y{ñâÅ_@:qjg2\19\e\19\19±\99\99\19s»ÝöâÅ\vu7éàú|>\v\ 6\83¢bq\19ÇèÈ]\ 3T@/½\17¦\ 6jú\97/_Z©Tºt\1fcýè\ 4Çãqk4\1a\96ËåÔÐ\88F£RÏ3·\1c\1c\1cTî6á|kkk²!õ~_$UÆb1Ù_¶··\ 5\v"\84Âáp\88\8f¸½½-\15Fïïåt:X,*\95'\9bÍ^zIãñ¸}ñÅ\17*Açææ\948\ 4va||\\9e³¥¥%k·Ûö\8f¼\1fD{±\1e\8e[·n\ e\r\rÙÂÂ\82\8d\8c\8cX¥R±ÝÝ]Ío\98}y<\1eÛÜÜ\94>+\95JY©T²µµ5ÛØظôÀÑ!óx<²i\0\17\ 1ËÅÀ\96\16/w\r\86\80Ì0P\1cà\83¢ì!y\12ü\e,\8ct:ý\17\8b\19\89D\14´Ðh4\94\ eC\88!wF~Næ]ü\1c.\97Ëöööl\7f\7fßþøÇ?Z2\99¼T®\80\ f#ácxxXFI\14û \9dÏÏÏíùóçöêÕ«¿Ø\b\18gx<\1e¥\97¼xñÂ^¼x¡q\bï\99\99\19+\16\8b¢ë\16
+\ 5\e\1a\1a²p8¬!.ÆS\14,\8c\10HI¥RöñÇ\1fÿ\ 5\10\155\ 6¥\ \100\8fÇcù|^ó*Æ+4@òù¼\bZ\10\84³Ù¬ýéO\7fÒ\ 3Ù+kC|\10\b\ 4Ôu$\ fºZJq\ 3r0\97ËÙÚÚÚ%W;ê\f:z|\8fxÈèX\12EË\9f '\14\81\0ê\1cþ\1cª¯V«e;;;öeÞ\ fÔ=ù|^ë1@§fvvVü\8d§O\9fên\ 3ïýøøØâñ¸\1c°}}}¶¾¾.\1d\17\16\96n·k£££Z|èTGGGJ$ \87ÃÖjµleeEI\93ÐiA\1f\97J%\9b\9e\9e\16\a\91\99\11æH\10ßñxÜ^¼xa_ûÚפ ¨ÕjæñxtBòbÞºuëR¶u¹\\16\9e\80Y
+»'\18\82h4*åÿþþ¾\8cx\9c¨4\19`\92`ù¨V«\16\f\ 6mggG³\16¼MÌjh¢°À\ e\87榦ÌãñØ\93'OdÏùÏÿüOûä\93O\14\11Åå\7feeE6\vÔ6©TÊB¡\906\89b±x oÆÅ\1cû\v9Ö\17\17\17R¿àS\8bF£\12\ 6ìîîÚ[o½¥Nr\7f\7f¿-//[4\1a\15M\18Ì^¹\VìÒÙÙ\99MLL\88\87áñxô¼\84Ãaóz½699©\97\8cT¡L&c·oß\96¢(\95J]\1a8ÓÈà4"ó\8d\80ö\87\ f\1fjäCC\85® b\82l6+d\1e\9b\a\86ÌT*¥´Ò/ó~°\99òYR©\949~úÓ\9f®NLLØÇ\1f\7fl\ e\87Cmm\8eÞ`0(é\ f\92'¾¨jµª{\ 2§\96ÇãQª&;<÷\93\93\13Eðt»]«V«¶°° \99\ eö\ 4jèÑÑQiÿ0-F"\91K\81\100ö/..ì·Þ²b±(\89N,\16³±±1]èévñ°\82ï^\\T\9bøõë×\1axC\ ff\a£9@®ðÔÔ\94Pe$¢\84B!\19)_¿~&\ ew\84\9füä'Ößßo\89DB\1aJ<a\1e\8fÇîܹcÑhÔ~ûÛßZ\7f\7f¿½ýöÛÖn·õ²¬¬¬(z\8aÝ\96\8d\ 4}\1dã\84Zf\83\83\83ò¡A΢\95Í\9d\8a\91 Þ-¿ß¯õdÈÊð\1a4ú×¾ö5Ëçóöøñc\9b\9e\9eVç´R©\88Ü\ 58\bÁm<\1e·ññqÍ(q;Ð\ 2çDà\9e\v)znnN\1dG*#6z·Û4\1e¿ßo\85BAÝãZfËË˶¼¼lÕjU\ 1ód3\f\r\ri\98\8c\95\ 5T\ 2â ·\7fïû\81ÙÔëõj\18ß÷\8b_ü¢ûêÕ+»\7fÿ¾u»]kµZVVUbÌÎÎÚúúº\1d\1f\1fÛÝ»w5\ 5/\95JJ©\ 4CM×®X,*\ 6Éáp¨)À\84\7fppP`\9d¯\7fýëÒ3öÆÿð×Ìe¸§ôv´îÝ»gwïÞµv»m\9b\9b\9b\96Ëå,\12\89È,Ç\89Gâ\88ßï\17\83\11\155\16\97Zfëëë\ 2©p\1a÷b¿:\9dÎ%ËG»Ý\96\8e\8eïÎëõÚÌÌ\8cD»\ 4Ç5\1a\r{ç\9dw¬ÑhèÎ\82ú\ 5¡ôÛo¿mëë붽½mo¿ý¶\94(ܳÆÆÆleeEi\9a·oßÖ:0\80\85q\98Édħ\84hËX\ 4¥
+Í\1e\18\92ÃÃÃöðáCÝÃ8e9\89è*âñ\8aÅböèÑ#{ùò¥ýæ7¿\11I·V«Ùöö¶º4Ë\18EPix½^1&Ýn·>³×ëµÁÁA\95t{{{:Aéüö\96ß$µ\92\98\89î±V«\99×ëµÅÅEѾFGGíóÏ?·\.g\v\v\vvxx(|\ 5Ò¾³³3\e\1e\1e¶\95\95\15{ùò¥}\99÷\83Æ\a§ùÅÅ\859nß¾½Úét4\ 3`\88Fc\82Á%ìz\0\98$\°3¼õÖ[v÷î]»¸¸°¥¥%»sç\8eår9\19ã8]\8e\8e\8elkkË<\1e\8f<:årYÁ {{{\16\8fÇÕ\19¤\94\9b\99\99Ñ<effÆB¡\90ÍÌÌÈ\87Öl6í½÷ÞSp\ 5¡\81\fqC¡\90U*\15\11\82\91.±\8bÓ@\80\9bÁ)\80\84\8a\92êæÍ\9b633#.ÉÓ§O5l\1d\1d\1dµùùyûôÓOmhhÈæææÔB\7fôè\91À3\8dFÃfgg¥Ø\1e\1a\1a²\1fýèG\96N§\15bqûöm\rúyH\9bͦJ¬ññqËd2V(\14´V(1\8aÅ¢E£QÍ\9c\82Á \85Ãa{ýúµ0k\ 4óûNOOÛ£G\8ftr3to6\9b¶²²"û
+e\13M\19\1aI\f¹\89|jµZöôéSEü\9e\9c\9cØÃ\87\ fÕjÙÌÌ\8c$lÌM\91.õ\ 6\8aðý£\1eñz½º\ 6ÌÏÏÛðð°-//[0\18\94!ôÑ£Gê\0¢\bb\ 3Ç\7f·»»kóóó: È,çE=::²÷ß\7fß666twþ2ï\a\8e{ÖÃñôéÓÕgÏ\9eIÝ\80°\12ÐMµZÕ?C\ 2U©TÄ\1f$8\9b\16»Ëå²ùùy«×ëR-³+\11\986::ªÿ\9fÎ$w\12\98\1d\80t\98ñp"ܸqÃnݺ¥\80\ 2üM\81@@'^¯\1c)\1c\ e[½^\17O¤V«©3È)·±±!æßÙÙ\99¼QívÛ²Ù¬E£Q\e\1f\1f×\97Ì\1d\8c\ 1n2\99´n·« n2¹Z\96½xñBA\1305z-B\17\17\17æñxl{{[w¨o|ã\ej#3ÔäÏK§ÓV«Õ¬T*iÀÎz \ eèe\89¸\.\8bÇã\9a\85Ñ-\85n\8cõ(\14
+É\80Ê\1c\8d\ ec§Ó±h4*\ 5\r\ 3Ûµµ5iA\99\87Öj5iTQªà)\84\16\¯×íõë×Z\ f"\97 K%\93IQ\82 |À·\97Ïçm~~^ee&\93Ñà;\18\fZ&\93±-©/À\87C\9fB"Ç\15\82a8ìDL£¹\Nø\85/ó~ôÚi$ÖøÙÏ~Ö\85qçóù¤ßZ\\\94w D±×ëUn\96ÏçSÍÉ\9d\ 3»A©TR#\84\ eZ¹\¶¥¥%Ûßß×\f\87K6z?ðqp4àÁSR\81Ù*\16\8b\96Éd¤\8a@kÈ]ä\93O>\91W\8cÏ\85ä\86Ù\18ð\1f>; Õ\8b\8b\v\8bÅbr.OOOÛÑÑ\91\94å\18ø\88°%ìÓéØþþ¾\ 5\83A\91ª@\95ÑU}ç\9dwìââÂö÷÷u\8f!¥\93ÙÐää¤\18ÿ½ÙØKKKò5\91á\fi\f¿\e\84-îR4~þÚzT*\15»yó¦5\9bM\v\ 4\ 2Jyáä\ 6\13Þ»\1e\9cô\98Ri&0\vs8\1c\9a}"Øm·Ûöé§\9fڻᆱ{Ûÿ¶\1e\10\981\91â@/\95Jò\7f\11÷Ä|\vÁ8 \99\7fm=¸~0°>>>¶Ç\8f\1f\v[7==mÝn÷¯®Ç?ò~ô®\87ãÉ\93'«üM¹\¶ÃÃCåf¡ºFÝqtt¤K"`\eâRÛí¶ìú¹\Îîß¿¯Ë*ô&äÿP\91Úí¶0Ù^¯W¤'\1a)\be1ÀÕëuI\94B¡\90B\ 3é\12¡¨xöì\99\r\ f\ f[6\9b\95âbppP\8b\86M¦7\ 6\15\11ëøø¸%\12 Q\88é^Ñi\8aF£¶»»kív[§®Ïç\93\89\ f!,\fI0\ 1Ø<\92ɤÅãqóù|öêÕ+»uë\96.ô\80e(ÅQ\83\80³kµZ\16\8fÇ\85F@\9dQ©T\84sè\1dS`LÌçóöàÁ\83K\98pdeÃÃÃ²Ö åã\9e\8a\16\95a:P$²\98Q¹ ¤§\89\ 1\82\ f5ɳgÏlddäïZ\ f\1céà\aÜn·Ö\ 3·2\e°ßïWb\10£\89¿µ\1eccc6::*$\1f\7fÖëׯõ\8commÙòòò% \18ª\90/û~ô®\87ã\a?øÁêÚÚ\9a\ 2áæççÕ\99
+\85B²\9c÷Ö\98øjðQ\1d\1f\1fk\ 2Î\a:==µX,¦öf«ÕÒ\8b\ 3\1f\82Î\10Ãâ^·0¡z\10¢¸tú|>Í>°VÐ%üà\83\ fÔCkÈð\16üZ¥R\11\95\16ùRµZU{\98\b[NeþÝÄÄ\84J
+.Û|\1f\94a4i\10\ 1sÊ\8f\8d\8dY4\1aUøßÍ\9b7mmmͦ§§m}}Ý|>\9fTù\91HÄÖÖÖTÎýõh4\1aÒ>b¶d=è\0³\1e\8c-\80ïÐðøßÖ\83v>\ f.3Ì^êoïz ¥ùÓív¿òz\80\ 6`\f\84\11\16SçW]\ fz\ 6\8b\8b\8b¶¾¾®õðûýj¸°\1e_öýè]\ fÇw¿ûÝU\1cÂ\f\89\a\a\amaaAG4\ f\18júJ¥b\87\87\87
+ \86c\8e\14\88Ù\165/AÖ¨\933\99\8cMMM©\95\1f\8fÇÍårÙÚÚ\9a\1d\1f\1fë\ 1\aÈ200 »\\7f\7f¿$Wù|Þ"\91\882±\882=99\91à\93\12 ¯\19¤%üD½\81ß\ 4Õ\818ÀÞ\81\0øââB-|J\9aL&cwîܱóós5-@\1f°£Á\84÷x<¶¼¼lµZMß\95Ëå²Ï?ÿ\vy\86Ù×ëquÖÃ199¹\8a\10\17Qìàà ÂÀ}>\9fôrÝn×~ýë_K~Ã.¨\99Æ\0\0\ fÕIDATÐÍëõ\8aîK\87\85ú\9edLZ»dôâqBõ\9eN§U6ré$B\94ŤnO¥R:\9eé\ 6\ 5\83Ak6\9b
+xcøMH\ 2]<Ø\82½¡ñØ\1f\80s2sA\7fÉ.\88y\90x×jµªpAÔ\1aÌ©P\ e\8c\8f\8f\v¦ Ú\9a\90\85R©d»»»æp8ìÙ³g¶¶¶¦Ü³ëõ¸:ëáøÆ7¾±zpp`7oÞ\14à\91#\96ä\10p^VKR§ÅÅEé\11\99± Qr¹\R«ß¸qü^¯\8e\\94\ 4äyÑ=\e\19\19±\89\89 \89\82Ù\19\88\19\82©N\17\a\9aQ\7f\7f¿ÝºuK^ µµ5\rA³Ù¬þß\99\99\19]¦=\1e\8fæ^½æ>\ÙápXêï³³3\95\92\0K{\ 3ñ¸[Âqìt:\96ËålqqÑnÞ¼i\1f}ô\91Ô/[[[º\98'\93I«T*6;;k>\9fÏ>ùä\13á\18®×ãj\87ã»ßýîj/\94\ 5\ e|0\18´ééiùØ\r;\9d\8eÍÏÏ[__\9f\1d\1f\1fKõ\ 1^\99\v>L\bò´\18¦¢¦ÀÆ\81ÿ\89\8bÿá᡾,À$0ï\81P6\9bM)E\16\17\17\ 5\1a-\14
+\92f%\93I«Õj\16\89Dìøøø\92¶\8fò\aòñ\9b¹ÃÔøÐ`ý~¿2\80{Cé\80_â$@\19\ f\96lggG\83ÐjµjñxÜ&&&ì¿þë¿ìèèÈâñ¸\1a4tç°Á\¯ÇÕY\ fÇw¾ó\9dUZäänÁt§LÀ\ 1J\13¢ÑhX©T\92\15\82\96<mãh4ª!2Ð\98óós\r&i§ri\ 5D\8a\8b\18È&3\87D"a\93\93\93Â~¡_\f\ 4\ 2Ößß/µ\a\19b\85BÁ<\1e\8f\85B!ÛÚÚÒ°\9b\92ÈétZ8\1c\16 \98ø%,9\\8eQîw:\1dYHÐjRæÐ\9dCU±´´$Å\ 5V\88ããc»sç\8eõõõY*\95\12(ÆëõZµZ\95\9fÌçó)\fâz=®Îz8Þ}÷ÝU\97Ë%\\16P\94\81\81\ 1+\97ËV«Õ,\18\f\9aÇã±ýý}¹>\91¢ \10Èår
+\ e\aÅ]«ÕäÇ¡³\84Ý\9dÝ\13¶\1dCZ\88º\bLóù¼ÍÍÍÙÌÌ\8cJ\17$[\95JŶ··íÆ\8d\eâ\82`íGغ³³£ðt´et¥\18Ê\1e\1d\1dY8\1cV}Ïð¼ÓéHUÍ\94\9fîW4\1aµv»N\1cXî±±1ÛÞÞÖ]¤¿¿ßÆÇÇíððP\88¸¡¡!\ 5\àg\ 3U\87-åz=®Îz8\9e>}ºê÷ûUcÖëuiÜ\98O9\9dNÛØØ°\83\83\ 3!Ô\98\93¸Ýn)\92\1f<x`\8dFC\96\88@ ù\86Ëå\92æëõë×*\ 3(-H(Ä\1c\89«\9a\06\ 6¬\945H\94\0s\86B!]Jiõv:\1dóz½\1a!@/"\97
+&$\97j4\88\10\8dqKïííY(\14Òî>00 {@¯8õôôT¿7_2\96\bJ5\8fÇ£Y\eäb\86»ããã
+\92»^\8f«³\1e\8e\7fÿ÷\7f_×ë\92Ó\1c\1f\1f\vRÙË4$g7\16\8b©Ì\98\9e\9e¶Ï>ûÌFFF,\10\bHlI}\8dM\81ö1ÆG\f\9aÔøÁ`PÙYÌ'P5cã\80¥xrr"z®Ûí\96¤\88\0\ 1.£¨¨÷öö,\16\8bÉÍ\8aÀ\17J1\9f\9b\9d\v \10j\87b±hÙlÖÊå²ÍÍÍɲ\8f¿\výd±X\14\8f\82®\12¤,Z×£££æt:¥&è\9dÍQÛÃr¼^\8f«³\1e\8e\7fý×\7f]å\a>??×\1fÀb¤ÓiÙB\0\85P·Ã«p»Ý644d\85BÁFGGíààÀb±\98h=ggg\8a6e\16C;\17\v\f4^\ 6¢H\8a\90Îð\99
+\85\82Õëu\9b\99\99\91L\86¬âF£aÇÇÇ\16\8dFE=B\83·´´¤äÏD"!f<DX\ 6ìÌ\83
+\85\82:j8²\v\85\82%\12 \v\87Ã:\150)\12`\8e\89\ fÈÎÔÔ\94¢w°Ë0Ó¡T\ 1øBiv½\1eWk=\1c÷ïß_%k\17\8b\amKÄ¿ÀO\82Á D®|ÙÁ`P0\1a.Áh\10Q#3/A\19ÀÔ\1fV\1fØmÒY\ 6\ 6\ 6\84ÁFÊ\83ð\15\v
+\96\ 2lß\80RQò\ f\ e\ eJµ\8fO\8c(X\14õtÞH*\19\1e\1e¶\83\83\ 3Ëd2\97¢\85`\8ct:\1du§¶¶¶\ 4\8ca\91\90^%\12 ;99\91=\ 2õ\ 5h5PoårYpQ\ 6²ÉdÒ®×ãj\87ãÛßþö*_äôô´\f\8a_|ñ\85\ 5\83AAbp53Ü#§ !m§Ó±¹¹9e"ïììH\8e\83¥\829\bG4pS"f¨¯wwwåµj·Û\9aÙ@xeG\ 6ÆÙn·\95˼¶¶fff³³³ªÃ\11\8bòåc3aÇìv»\97ò\9c\19>æóyµ\97Q>\10\15\85O\8b¼/\16Ï̬P(X$\12Ñ\83Ë}¨Ûí*õ£ÕjY«Õ\92Ï\v\98\rì\8bëõ¸:ëáxÿý÷W1!âP\9d\98\98\10!\bµ<\8b\10\8bÅÌáp(/\vÜ\0¾\9cíím\ 5\94cl£s\ 5}\89<+v\rD¥ØÒq`÷\9a8É8æR w\9dèSZÐcccr\b`%á³ãØ\ 54\83£\1aÜZ>\9f7·Ûm\13\13\13"\ fá|mµZ\16
+\85\847s»ÝÖét,\9dN+\r\ 6vúýû÷¥(\1f\1a\1a²½½=K¥R\8aiÂAÌ\1d\ 6\8a-\ 4ãëõ¸Zëáx÷ÝwWÙÝ:\9d\8e¥R)±+ø ìf\b\1f_¿~m\91HDA১§V«Õ\ 4\12¡v\ 5¦Cû\17-\1ae\f:;f\1c\f)'&&d7\18\19\19\11s\ 2Åy·Û\95G«^¯[<\1e·r¹,a1¨m>7\9e) ¨Ìg\90\1cÍÎÎ\8ax\ 4\1d
+\13"¦F\16\11hkµZUÍ\rj\eÎ<\ fùññ±,\19<\1c\ 3\ 3\ 3b\91$\12 q(|>\9f~\8eëõ¸Zëáøá\ f\7f¸\9aÉdlwwWr\90b±(`\ e\1fðþýûV¯×ÅJàH\a\84C\10\1e»\0jn\8eZ\94Ø|q`¾¼^¯\10lX.\.\97.½ü>ÃÃòÍ\93\1dÕ\víÜßßWZýÑÑ\91\0\98 Þ°«\93\16\83ª\1c»\vBU,\14Ü\v0!òsP\7f\13hHK\9bÐsî(иÎÎÎ\14ìÝl6-\1a\8d*\ 6\8aa)ÿ}:\9d¶H$b×ëqµÖÃñäÉ\93Õ\.'U@2\99´`0(¼×ÖÖ\96þ\9aé;"Êóósí\96\84RÓ¶ÅóÃ\11Ì\91N\889ó\97\93\93\13µm\81ÐPÎà?#è\0û\ 2\ 3LPp;;;\ 2Ë øN§ÓÖh4t\99\1e\1d\1d\15\816\9bÍ*\8c\ f$\19öz\9c¼õzÝæçç\95f\82º\ 1«G8\1c\16S±^¯Ë\ 3å÷ûR©X$\12\11\13\83\87ùüü\\0U\18ýP\9bh\8dg³Y»^\8f«µ\1e\8eï|ç;«·nÝ\12cáöíÛr·f2\19\9b\98\98°\9d\9d\1d\rî0£¥Ói+\14
+\8a "\14\9cv&íM¢\88(\19èÈD£Qk4\1aò\16\85Ãa[XXPÈD¯\12\80\19\8bËå\12Ó\ 2æ\ 2ü\f<D\85BA\12 Ü·Løq·2$¤®\1e\1d\1d5\8fÇcÕjÕ\9e?\7fnwîܱÝÝ]kµZv÷î]aÈ©çc±\98U«U¡Õ ×\92êHè]2\99Ô}\84\9d\15\93¡Ëå²\83\83\ 3\95e¸Ä\87\86\86ìz=®Öz8¾ÿýï¯&\12 ÁBÇÆÆ,\91H\88\12L\rL¸\eÃ9¦Ûx\870[R\ fw:\1dÅà s9<<T64¢Ï©©)©\aX$ (½`NÊ\12jaìò´§\ f\ e\ e,\9fÏËß³¸¸(\9b~\7f\7f¿}þùç2NÞ¼yS_(;< \98+++\92Û\9c\9f\9fÛÆÆ\86Rgp
+ã¡êÕÕqÉ\a\1d@©F\12%\\10\18\94¨&NNNDÍ¢ëu½\1eWk=\1cO\9e<Y\ 5B²°° c\13ÄX©T\12v\8d\bÐt:\9d+\10\bX½^\97L\ 5\85@¹\¶x<®\84\96z½.¢\ f\ eRä>½\11J¤\9c ÀFxJîï½{÷l}}]\17vvKêê±±1Ëd2\ 2ÔÀÂh4\1a
+ê\ 6BJè:,óóós;;;\93\ 5\9dÖ5H4ÈL\ÔI]á3ÀÅ Õ\92ò#\18\fZ,\16³ßÿþ÷ffV*\95\94ê922¢ÈX\10Ñ×ëqµÖÃñ½ï}o\95YC>\9f\97}\9a8"\ 2Óè<q\ 1Ìf³¶´´¤.\ fØ/ÂÐ\1e<x`\a\a\aöðáC\85³AX\8aÅbæóùdãÆ\95êp8¬^¯+I1\16\8b\99ßï·µµ5\e\e\e\13´òääD\8b\ 5\95\b©\vw\90Þ09R&ÍÌB¡\90\ 5\83Ak4\1a\ 2\99îïïÛìì¬\1d\1c\1cØÌÌ\8c¼MìØKKKê²¥R)[[[³ÙÙYÍxÀXCa
+\85B2\182\1cþðÃ\ fE\9d\ 2±\r\8f\82Nß[·ìââ®×ãj\87ãéÓ§«ôú777õe:\9dNy\7fzcsHE\f\85BÚèP\8d\8f\8f[¥R\11ùÇãñØóçÏÛí
+jJÙ±··§\ 5\80[\ eC\11:/|Gf\15\884 ¡«V«6::*R0R\9eóós{üø±\9d\9c\9cX¹\\16%\96\14\8f^ÁéÅÅ\85}ñÅ\17
+\a\87]\ 2Q7\1e\8fÛöö¶\1d\1d\1d zS.\97¥PðûýÂ\7f¡ß{õê\95N
+ÚÔffSSS\9a \ 5\ 2\ 1kµZ20\9e\9d\9dY£Ñ°Zf×ëqµÖÃñ/ÿò/«tM\184ÂG'SùøøX»\ 3S~·Ûm©TJ\83¹Þ@êX,f\13\13\13\12g6\1a\rËd2\1aÔa[G\19\80M\1eo\ eÎS\ 6\88\81@@\8b@~\19q¦¨\14\9aͦb\99ÆÆÆä eg%Ð-\93Éèç\84 ±¼¼lcccöÉ'\9fX__\9fݹsG\ 2ZèDggg¶³³#D6s\96l6{)r\96\87\ríZ½^W\1cêùù¹|X\84"\808K¥Rò)]¯ÇÕZ\ fÇ·¿ýíULu¨\92Ýn·\1d\1f\1fÛ§\9f~j\9dNÇîÝ»gÕjÕ\8aÅ¢-..\9aÓéÔ´\9b \ 1ðmpà7775K\b\85BRyÃG\[[S\88:É\95\88G\99=\0ï<::\12;\ fcÞàà ¹Ýnµ\9b\89°¥5L¾\15\1c ¼JHm\18LÂUD¯\aB\1a\96D³Ù´F£aËËËB\8dñÿöÒµNOOí¿ÿû¿-\10\b(X"\9dNËÜǽÇãñØÆÆ\86åóys¹\ò<íììX$\12±þþ~»^\8f«µ\1e\8eo~ó\9b«\v\v\vºÈñ\ 6\92nÈ\1c\85©~·Ûµ½½=ëë볩©)1ó\10\8bb°\83Ö322b\93\93\93¶¼¼,ã\1d\14Z²\9fQ\14\80°\86ý\a¹\b\14\19\81ç´\9f)9¸Ü\1e\1e\1eZ>\9f·\91\91\11u¤èXa\10$A%\10\büß<ßÿ\81\90z<\1e[YYQÇhppP*\ 5¬\17\18ôÀ¡U*\15\v\ 6\83\16\8fÇ-\99LjwëÅi#²\ 5ñ\r\14\95Ü,hÀï¼ó\8e\18\81×ëqµÖÃñoÿöo«;;;\82uîííÙúúº¹Ýn¥g0ÔD&S©T´s`ý&*\ 6>")\19333ff\96H$´H'''ò7Qÿf2\19\ 5ï\91w¼»»k\ 3\ 3\ 3vãÆ\rᢡø²«\96J%ÙÒ].\97>/\89,\äA(cV¤í\9cL&ÍápÈUKH\ 6*pf6ÙlÖNNN¤0@\9eÔn·-\91HØÒÒ\92\88Å@V¹\18\83µ\9e\98\98°íím\e\1e\1e¶¯\7fýërâ\924Ã\æz=®Özôýüç?ïÂ-8??×\97\ 1\ 3\8fð\ 2\¢\ 4Ä5\9bM»}û¶\15\8bEk4\1a\7faW\80©W¯×-\93ÉØ«W¯ìÉ\93'Ößßo~¿_å\b\9e'j~ÂêHí¤Ü\99\9a\9aRkÚåréKæB^(\14¤#cÒOØ\ 2s\10\³p'\90ì\f\ f\ f[V\93Ø\15ùN(\14RÖñìì¬íììhG¤Á@ô-\ 1ô\91HÄ\1c\ e\87Ðk\83\83\836==mûûûbó]\83¤¦Ä\e\1e\1e¶f³i×ëqµÖÃñÞ{ïö\92\84°O×j5ËçóB\r\93\8aQ©T¤Ì\86\ f\81¼\85¤\v\ 2ç\8aÅ¢\95Ëe\9b\98\98°ùùy)ÄÝn·hFì\80\94\ 4\18Þ\86\86\86¤gCKÇ\ 5\95\1dº¯¯O\89\86Ð\84\18H\9e\9e\9eZ4\1a\15Y í\1d._¯×+Í\1c\ f"¨jZß\9dNGVy8\12¸l ;@
+ôüùsóz½
+°óz½655%5w&\93\11[ãôôTv\8d¹¹9ùµ &_¯ÇÕZ\8fÿ\ 3\ 3dDÿÚ³{V\0\0\0\0IEND®B`\82#!/usr/bin/env php
+# autogenerated file; do not edit
+sudo: false
+language: c
+
+addons:
+ apt:
+ packages:
+ - php5-cli
+ - php-pear
+
+env:
+ matrix:
+<?php
+
+$gen = include "./travis/pecl/gen-matrix.php";
+$env = $gen([
+ "PHP" => ["master"],
+ "enable_debug",
+ "enable_maintainer_zts",
+]);
+foreach ($env as $e) {
+ printf(" - %s\n", $e);
+}
+
+?>
+
+before_script:
+ - make -f travis/pecl/Makefile php
+ - make -f travis/pecl/Makefile ext PECL=raphf
+
+script:
+ - make -f travis/pecl/Makefile test
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: raphf |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_raphf.h"
+
+#ifndef PHP_RAPHF_TEST
+# define PHP_RAPHF_TEST 0
+#endif
+
+struct php_persistent_handle_globals {
+ ulong limit;
+ HashTable hash;
+};
+
+ZEND_BEGIN_MODULE_GLOBALS(raphf)
+ struct php_persistent_handle_globals persistent_handle;
+ZEND_END_MODULE_GLOBALS(raphf)
+
+#ifdef ZTS
+# define PHP_RAPHF_G ((zend_raphf_globals *) \
+ (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(raphf_globals_id)])
+#else
+# define PHP_RAPHF_G (&raphf_globals)
+#endif
+
+ZEND_DECLARE_MODULE_GLOBALS(raphf)
+
+#ifndef PHP_RAPHF_DEBUG_PHANDLES
+# define PHP_RAPHF_DEBUG_PHANDLES 0
+#endif
+#if PHP_RAPHF_DEBUG_PHANDLES
+# undef inline
+# define inline
+#endif
+
+php_resource_factory_t *php_resource_factory_init(php_resource_factory_t *f,
+ php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data))
+{
+ if (!f) {
+ f = emalloc(sizeof(*f));
+ }
+ memset(f, 0, sizeof(*f));
+
+ memcpy(&f->fops, fops, sizeof(*fops));
+
+ f->data = data;
+ f->dtor = dtor;
+
+ f->refcount = 1;
+
+ return f;
+}
+
+unsigned php_resource_factory_addref(php_resource_factory_t *rf)
+{
+ return ++rf->refcount;
+}
+
+void php_resource_factory_dtor(php_resource_factory_t *f)
+{
+ if (!--f->refcount) {
+ if (f->dtor) {
+ f->dtor(f->data);
+ }
+ }
+}
+
+void php_resource_factory_free(php_resource_factory_t **f)
+{
+ if (*f) {
+ php_resource_factory_dtor(*f);
+ if (!(*f)->refcount) {
+ efree(*f);
+ *f = NULL;
+ }
+ }
+}
+
+void *php_resource_factory_handle_ctor(php_resource_factory_t *f, void *init_arg)
+{
+ if (f->fops.ctor) {
+ return f->fops.ctor(f->data, init_arg);
+ }
+ return NULL;
+}
+
+void *php_resource_factory_handle_copy(php_resource_factory_t *f, void *handle)
+{
+ if (f->fops.copy) {
+ return f->fops.copy(f->data, handle);
+ }
+ return NULL;
+}
+
+void php_resource_factory_handle_dtor(php_resource_factory_t *f, void *handle)
+{
+ if (f->fops.dtor) {
+ f->fops.dtor(f->data, handle);
+ }
+}
+
+php_resource_factory_t *php_persistent_handle_resource_factory_init(
+ php_resource_factory_t *a, php_persistent_handle_factory_t *pf)
+{
+ return php_resource_factory_init(a,
+ php_persistent_handle_get_resource_factory_ops(), pf,
+ (void(*)(void*)) php_persistent_handle_abandon);
+}
+
+zend_bool php_resource_factory_is_persistent(php_resource_factory_t *a)
+{
+ return a->dtor == (void(*)(void *)) php_persistent_handle_abandon;
+}
+
+static inline php_persistent_handle_list_t *php_persistent_handle_list_init(
+ php_persistent_handle_list_t *list)
+{
+ if (!list) {
+ list = pemalloc(sizeof(*list), 1);
+ }
+ list->used = 0;
+ zend_hash_init(&list->free, 0, NULL, NULL, 1);
+
+ return list;
+}
+
+static int php_persistent_handle_apply_stat(zval *p, int argc, va_list argv,
+ zend_hash_key *key)
+{
+ php_persistent_handle_list_t *list = Z_PTR_P(p);
+ zval zsubentry, *zentry = va_arg(argv, zval *);
+
+ array_init(&zsubentry);
+ add_assoc_long_ex(&zsubentry, ZEND_STRL("used"), list->used);
+ add_assoc_long_ex(&zsubentry, ZEND_STRL("free"),
+ zend_hash_num_elements(&list->free));
+ if (key->key) {
+ add_assoc_zval_ex(zentry, key->key->val, key->key->len, &zsubentry);
+ } else {
+ add_index_zval(zentry, key->h, &zsubentry);
+ }
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static int php_persistent_handle_apply_statall(zval *p, int argc, va_list argv,
+ zend_hash_key *key)
+{
+ php_persistent_handle_provider_t *provider = Z_PTR_P(p);
+ HashTable *ht = va_arg(argv, HashTable *);
+ zval zentry;
+
+ array_init(&zentry);
+
+ zend_hash_apply_with_arguments(&provider->list.free,
+ php_persistent_handle_apply_stat, 1, &zentry);
+
+ if (key->key) {
+ zend_hash_update(ht, key->key, &zentry);
+ } else {
+ zend_hash_index_update(ht, key->h, &zentry);
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static int php_persistent_handle_apply_cleanup_ex(zval *p, void *arg)
+{
+ php_resource_factory_t *rf = arg;
+ void *handle = Z_PTR_P(p);
+
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "DESTROY: %p\n", handle);
+#endif
+ php_resource_factory_handle_dtor(rf, handle);
+ return ZEND_HASH_APPLY_REMOVE;
+}
+
+static int php_persistent_handle_apply_cleanup(zval *p, void *arg)
+{
+ php_resource_factory_t *rf = arg;
+ php_persistent_handle_list_t *list = Z_PTR_P(p);
+
+ zend_hash_apply_with_argument(&list->free,
+ php_persistent_handle_apply_cleanup_ex, rf);
+ if (list->used) {
+ return ZEND_HASH_APPLY_KEEP;
+ }
+ zend_hash_destroy(&list->free);
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "LSTFREE: %p\n", list);
+#endif
+ pefree(list, 1);
+ return ZEND_HASH_APPLY_REMOVE;
+}
+
+static inline void php_persistent_handle_list_dtor(
+ php_persistent_handle_list_t *list,
+ php_persistent_handle_provider_t *provider)
+{
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "LSTDTOR: %p\n", list);
+#endif
+ zend_hash_apply_with_argument(&list->free,
+ php_persistent_handle_apply_cleanup_ex, &provider->rf);
+ zend_hash_destroy(&list->free);
+}
+
+static inline void php_persistent_handle_list_free(
+ php_persistent_handle_list_t **list,
+ php_persistent_handle_provider_t *provider)
+{
+ php_persistent_handle_list_dtor(*list, provider);
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "LSTFREE: %p\n", *list);
+#endif
+ pefree(*list, 1);
+ *list = NULL;
+}
+
+static int php_persistent_handle_list_apply_dtor(zval *p, void *provider)
+{
+ php_persistent_handle_list_t *list = Z_PTR_P(p);
+
+ php_persistent_handle_list_free(&list, provider );
+ ZVAL_PTR(p, NULL);
+ return ZEND_HASH_APPLY_REMOVE;
+}
+
+static inline php_persistent_handle_list_t *php_persistent_handle_list_find(
+ php_persistent_handle_provider_t *provider, zend_string *ident)
+{
+ php_persistent_handle_list_t *list;
+ zval *zlist = zend_symtable_find(&provider->list.free, ident);
+
+ if (zlist && (list = Z_PTR_P(zlist))) {
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "LSTFIND: %p\n", list);
+#endif
+ return list;
+ }
+
+ if ((list = php_persistent_handle_list_init(NULL))) {
+ zval p, *rv;
+ zend_string *id;
+
+ ZVAL_PTR(&p, list);
+ id = zend_string_init(ident->val, ident->len, 1);
+ rv = zend_symtable_update(&provider->list.free, id, &p);
+ zend_string_release(id);
+
+ if (rv) {
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "LSTFIND: %p (new)\n", list);
+#endif
+ return list;
+ }
+ php_persistent_handle_list_free(&list, provider);
+ }
+
+ return NULL;
+}
+
+static int php_persistent_handle_apply_cleanup_all(zval *p, int argc,
+ va_list argv, zend_hash_key *key)
+{
+ php_persistent_handle_provider_t *provider = Z_PTR_P(p);
+ zend_string *ident = va_arg(argv, zend_string *);
+ php_persistent_handle_list_t *list;
+
+ if (ident && ident->len) {
+ if ((list = php_persistent_handle_list_find(provider, ident))) {
+ zend_hash_apply_with_argument(&list->free,
+ php_persistent_handle_apply_cleanup_ex,
+ &provider->rf);
+ }
+ } else {
+ zend_hash_apply_with_argument(&provider->list.free,
+ php_persistent_handle_apply_cleanup, &provider->rf);
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static void php_persistent_handle_hash_dtor(zval *p)
+{
+ php_persistent_handle_provider_t *provider = Z_PTR_P(p);
+
+ zend_hash_apply_with_argument(&provider->list.free,
+ php_persistent_handle_list_apply_dtor, provider);
+ zend_hash_destroy(&provider->list.free);
+ php_resource_factory_dtor(&provider->rf);
+ pefree(provider, 1);
+}
+
+ZEND_RESULT_CODE php_persistent_handle_provide(zend_string *name,
+ php_resource_factory_ops_t *fops, void *data, void (*dtor)(void *))
+{
+ php_persistent_handle_provider_t *provider = pemalloc(sizeof(*provider), 1);
+
+ if (php_persistent_handle_list_init(&provider->list)) {
+ if (php_resource_factory_init(&provider->rf, fops, data, dtor)) {
+ zval p, *rv;
+ zend_string *ns;
+
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "PROVIDE: %p %s\n", PHP_RAPHF_G, name_str);
+#endif
+
+ ZVAL_PTR(&p, provider);
+ ns = zend_string_init(name->val, name->len, 1);
+ rv = zend_symtable_update(&PHP_RAPHF_G->persistent_handle.hash, ns, &p);
+ zend_string_release(ns);
+
+ if (rv) {
+ return SUCCESS;
+ }
+ php_resource_factory_dtor(&provider->rf);
+ }
+ }
+
+ return FAILURE;
+}
+
+
+php_persistent_handle_factory_t *php_persistent_handle_concede(
+ php_persistent_handle_factory_t *a,
+ zend_string *name, zend_string *ident,
+ php_persistent_handle_wakeup_t wakeup,
+ php_persistent_handle_retire_t retire)
+{
+ zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash, name);
+
+ if (zprovider) {
+ zend_bool free_a = 0;
+
+ if ((free_a = !a)) {
+ a = emalloc(sizeof(*a));
+ }
+ memset(a, 0, sizeof(*a));
+
+ a->provider = Z_PTR_P(zprovider);
+ a->ident = zend_string_copy(ident);
+ a->wakeup = wakeup;
+ a->retire = retire;
+ a->free_on_abandon = free_a;
+ } else {
+ a = NULL;
+ }
+
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "CONCEDE: %p %p (%s) (%s)\n", PHP_RAPHF_G,
+ a ? a->provider : NULL, name->val, ident->val);
+#endif
+
+ return a;
+}
+
+void php_persistent_handle_abandon(php_persistent_handle_factory_t *a)
+{
+ zend_bool f = a->free_on_abandon;
+
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "ABANDON: %p\n", a->provider);
+#endif
+
+ zend_string_release(a->ident);
+ memset(a, 0, sizeof(*a));
+ if (f) {
+ efree(a);
+ }
+}
+
+void *php_persistent_handle_acquire(php_persistent_handle_factory_t *a, void *init_arg)
+{
+ int key;
+ zval *p;
+ zend_ulong index;
+ void *handle = NULL;
+ php_persistent_handle_list_t *list;
+
+ list = php_persistent_handle_list_find(a->provider, a->ident);
+ if (list) {
+ zend_hash_internal_pointer_end(&list->free);
+ key = zend_hash_get_current_key(&list->free, NULL, &index);
+ p = zend_hash_get_current_data(&list->free);
+ if (p && HASH_KEY_NON_EXISTENT != key) {
+ handle = Z_PTR_P(p);
+ if (a->wakeup) {
+ a->wakeup(a, &handle);
+ }
+ zend_hash_index_del(&list->free, index);
+ } else {
+ handle = php_resource_factory_handle_ctor(&a->provider->rf, init_arg);
+ }
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "CREATED: %p\n", handle);
+#endif
+ if (handle) {
+ ++a->provider->list.used;
+ ++list->used;
+ }
+ }
+
+ return handle;
+}
+
+void *php_persistent_handle_accrete(php_persistent_handle_factory_t *a, void *handle)
+{
+ void *new_handle = NULL;
+ php_persistent_handle_list_t *list;
+
+ new_handle = php_resource_factory_handle_copy(&a->provider->rf, handle);
+ if (handle) {
+ list = php_persistent_handle_list_find(a->provider, a->ident);
+ if (list) {
+ ++list->used;
+ }
+ ++a->provider->list.used;
+ }
+
+ return new_handle;
+}
+
+void php_persistent_handle_release(php_persistent_handle_factory_t *a, void *handle)
+{
+ php_persistent_handle_list_t *list;
+
+ list = php_persistent_handle_list_find(a->provider, a->ident);
+ if (list) {
+ if (a->provider->list.used >= PHP_RAPHF_G->persistent_handle.limit) {
+#if PHP_RAPHF_DEBUG_PHANDLES
+ fprintf(stderr, "DESTROY: %p\n", handle);
+#endif
+ php_resource_factory_handle_dtor(&a->provider->rf, handle);
+ } else {
+ if (a->retire) {
+ a->retire(a, &handle);
+ }
+ zend_hash_next_index_insert_ptr(&list->free, handle);
+ }
+
+ --a->provider->list.used;
+ --list->used;
+ }
+}
+
+void php_persistent_handle_cleanup(zend_string *name, zend_string *ident)
+{
+ php_persistent_handle_provider_t *provider;
+ php_persistent_handle_list_t *list;
+
+ if (name) {
+ zval *zprovider = zend_symtable_find(&PHP_RAPHF_G->persistent_handle.hash,
+ name);
+
+ if (zprovider && (provider = Z_PTR_P(zprovider))) {
+ if (ident) {
+ list = php_persistent_handle_list_find(provider, ident);
+ if (list) {
+ zend_hash_apply_with_argument(&list->free,
+ php_persistent_handle_apply_cleanup_ex,
+ &provider->rf);
+ }
+ } else {
+ zend_hash_apply_with_argument(&provider->list.free,
+ php_persistent_handle_apply_cleanup,
+ &provider->rf);
+ }
+ }
+ } else {
+ zend_hash_apply_with_arguments(
+ &PHP_RAPHF_G->persistent_handle.hash,
+ php_persistent_handle_apply_cleanup_all, 1, ident);
+ }
+}
+
+HashTable *php_persistent_handle_statall(HashTable *ht)
+{
+ if (zend_hash_num_elements(&PHP_RAPHF_G->persistent_handle.hash)) {
+ if (!ht) {
+ ALLOC_HASHTABLE(ht);
+ zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
+ }
+ zend_hash_apply_with_arguments(
+ &PHP_RAPHF_G->persistent_handle.hash,
+ php_persistent_handle_apply_statall, 1, ht);
+ } else if (ht) {
+ ht = NULL;
+ }
+
+ return ht;
+}
+
+static php_resource_factory_ops_t php_persistent_handle_resource_factory_ops = {
+ (php_resource_factory_handle_ctor_t) php_persistent_handle_acquire,
+ (php_resource_factory_handle_copy_t) php_persistent_handle_accrete,
+ (php_resource_factory_handle_dtor_t) php_persistent_handle_release
+};
+
+php_resource_factory_ops_t *php_persistent_handle_get_resource_factory_ops(void)
+{
+ return &php_persistent_handle_resource_factory_ops;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_raphf_stat_persistent_handles, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_FUNCTION(raphf_stat_persistent_handles)
+{
+ if (SUCCESS == zend_parse_parameters_none()) {
+ object_init(return_value);
+ if (php_persistent_handle_statall(HASH_OF(return_value))) {
+ return;
+ }
+ zval_dtor(return_value);
+ }
+ RETURN_FALSE;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_raphf_clean_persistent_handles, 0, 0, 0)
+ ZEND_ARG_INFO(0, name)
+ ZEND_ARG_INFO(0, ident)
+ZEND_END_ARG_INFO();
+static PHP_FUNCTION(raphf_clean_persistent_handles)
+{
+ zend_string *name = NULL, *ident = NULL;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|S!S!", &name, &ident)) {
+ php_persistent_handle_cleanup(name, ident);
+ }
+}
+
+#if PHP_RAPHF_TEST
+# include "php_raphf_test.c"
+#endif
+
+static const zend_function_entry raphf_functions[] = {
+ ZEND_NS_FENTRY("raphf", stat_persistent_handles,
+ ZEND_FN(raphf_stat_persistent_handles),
+ ai_raphf_stat_persistent_handles, 0)
+ ZEND_NS_FENTRY("raphf", clean_persistent_handles,
+ ZEND_FN(raphf_clean_persistent_handles),
+ ai_raphf_clean_persistent_handles, 0)
+#if PHP_RAPHF_TEST
+ ZEND_NS_FENTRY("raphf", provide, ZEND_FN(raphf_provide), NULL, 0)
+ ZEND_NS_FENTRY("raphf", conceal, ZEND_FN(raphf_conceal), NULL, 0)
+ ZEND_NS_FENTRY("raphf", concede, ZEND_FN(raphf_concede), NULL, 0)
+ ZEND_NS_FENTRY("raphf", dispute, ZEND_FN(raphf_dispute), NULL, 0)
+ ZEND_NS_FENTRY("raphf", handle_ctor, ZEND_FN(raphf_handle_ctor), NULL, 0)
+ ZEND_NS_FENTRY("raphf", handle_copy, ZEND_FN(raphf_handle_copy), NULL, 0)
+ ZEND_NS_FENTRY("raphf", handle_dtor, ZEND_FN(raphf_handle_dtor), NULL, 0)
+#endif
+ {0}
+};
+
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("raphf.persistent_handle.limit", "-1", PHP_INI_SYSTEM,
+ OnUpdateLong, persistent_handle.limit, zend_raphf_globals,
+ raphf_globals)
+PHP_INI_END()
+
+static HashTable *php_persistent_handles_global_hash;
+
+static PHP_GINIT_FUNCTION(raphf)
+{
+ raphf_globals->persistent_handle.limit = -1;
+
+ zend_hash_init(&raphf_globals->persistent_handle.hash, 0, NULL,
+ php_persistent_handle_hash_dtor, 1);
+ if (php_persistent_handles_global_hash) {
+ zend_hash_copy(&raphf_globals->persistent_handle.hash,
+ php_persistent_handles_global_hash, NULL);
+ }
+}
+
+static PHP_GSHUTDOWN_FUNCTION(raphf)
+{
+ zend_hash_destroy(&raphf_globals->persistent_handle.hash);
+}
+
+PHP_MINIT_FUNCTION(raphf)
+{
+ php_persistent_handles_global_hash = &PHP_RAPHF_G->persistent_handle.hash;
+
+#if PHP_RAPHF_TEST
+ PHP_MINIT(raphf_test)(INIT_FUNC_ARGS_PASSTHRU);
+#endif
+
+ REGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(raphf)
+{
+#if PHP_RAPHF_TEST
+ PHP_MSHUTDOWN(raphf_test)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
+#endif
+
+ UNREGISTER_INI_ENTRIES();
+ php_persistent_handles_global_hash = NULL;
+ return SUCCESS;
+}
+
+static int php_persistent_handle_apply_info_ex(zval *p, int argc,
+ va_list argv, zend_hash_key *key)
+{
+ php_persistent_handle_list_t *list = Z_PTR_P(p);
+ zend_hash_key *super_key = va_arg(argv, zend_hash_key *);
+ char used[21], free[21];
+
+ slprintf(used, sizeof(used), "%u", list->used);
+ slprintf(free, sizeof(free), "%d", zend_hash_num_elements(&list->free));
+
+ php_info_print_table_row(4, super_key->key->val, key->key->val, used, free);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static int php_persistent_handle_apply_info(zval *p, int argc,
+ va_list argv, zend_hash_key *key)
+{
+ php_persistent_handle_provider_t *provider = Z_PTR_P(p);
+
+ zend_hash_apply_with_arguments(&provider->list.free,
+ php_persistent_handle_apply_info_ex, 1, key);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+PHP_MINFO_FUNCTION(raphf)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2,
+ "Resource and persistent handle factory support", "enabled");
+ php_info_print_table_row(2, "Extension version", PHP_RAPHF_VERSION);
+ php_info_print_table_end();
+
+ php_info_print_table_start();
+ php_info_print_table_colspan_header(4, "Persistent handles in this "
+#ifdef ZTS
+ "thread"
+#else
+ "process"
+#endif
+ );
+ php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
+ zend_hash_apply_with_arguments(
+ &PHP_RAPHF_G->persistent_handle.hash,
+ php_persistent_handle_apply_info, 0);
+ php_info_print_table_end();
+
+ DISPLAY_INI_ENTRIES();
+}
+
+zend_module_entry raphf_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "raphf",
+ raphf_functions,
+ PHP_MINIT(raphf),
+ PHP_MSHUTDOWN(raphf),
+ NULL,
+ NULL,
+ PHP_MINFO(raphf),
+ PHP_RAPHF_VERSION,
+ ZEND_MODULE_GLOBALS(raphf),
+ PHP_GINIT(raphf),
+ PHP_GSHUTDOWN(raphf),
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX
+};
+/* }}} */
+
+#ifdef COMPILE_DL_RAPHF
+ZEND_GET_MODULE(raphf)
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: raphf |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2013, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_RAPHF_API_H
+#define PHP_RAPHF_API_H
+
+#include "php_raphf.h"
+
+/**
+ * A resource constructor.
+ *
+ * @param opaque is the \a data from php_persistent_handle_provide()
+ * @param init_arg is the \a init_arg from php_resource_factory_init()
+ * @return the created (persistent) handle
+ */
+typedef void *(*php_resource_factory_handle_ctor_t)(void *opaque, void *init_arg);
+
+/**
+ * The copy constructor of a resource.
+ *
+ * @param opaque the factory's data
+ * @param handle the (persistent) handle to copy
+ */
+typedef void *(*php_resource_factory_handle_copy_t)(void *opaque, void *handle);
+
+/**
+ * The destructor of a resource.
+ *
+ * @param opaque the factory's data
+ * @param handle the handle to destroy
+ */
+typedef void (*php_resource_factory_handle_dtor_t)(void *opaque, void *handle);
+
+/**
+ * The resource ops consisting of a ctor, a copy ctor and a dtor.
+ *
+ * Define this ops and register them with php_persistent_handle_provide()
+ * in MINIT.
+ */
+typedef struct php_resource_factory_ops {
+ /** The resource constructor */
+ php_resource_factory_handle_ctor_t ctor;
+ /** The resource's copy constructor */
+ php_resource_factory_handle_copy_t copy;
+ /** The resource's destructor */
+ php_resource_factory_handle_dtor_t dtor;
+} php_resource_factory_ops_t;
+
+/**
+ * The resource factory.
+ */
+typedef struct php_resource_factory {
+ /** The resource ops */
+ php_resource_factory_ops_t fops;
+ /** Opaque user data */
+ void *data;
+ /** User data destructor */
+ void (*dtor)(void *data);
+ /** How often this factory is referenced */
+ unsigned refcount;
+} php_resource_factory_t;
+
+/**
+ * Initialize a resource factory.
+ *
+ * If you register a \a dtor for a resource factory used with a persistent
+ * handle provider, be sure to call php_persistent_handle_cleanup() for your
+ * registered provider in MSHUTDOWN, else the dtor will point to no longer
+ * available memory if the extension has already been unloaded.
+ *
+ * @param f the factory to initialize; if NULL allocated on the heap
+ * @param fops the resource ops to assign to the factory
+ * @param data opaque user data; may be NULL
+ * @param dtor a destructor for the data; may be NULL
+ * @return \a f or an allocated resource factory
+ */
+PHP_RAPHF_API php_resource_factory_t *php_resource_factory_init(
+ php_resource_factory_t *f, php_resource_factory_ops_t *fops, void *data,
+ void (*dtor)(void *data));
+
+/**
+ * Increase the refcount of the resource factory.
+ *
+ * @param rf the resource factory
+ * @return the new refcount
+ */
+PHP_RAPHF_API unsigned php_resource_factory_addref(php_resource_factory_t *rf);
+
+/**
+ * Destroy the resource factory.
+ *
+ * If the factory's refcount reaches 0, the \a dtor for \a data is called.
+ *
+ * @param f the resource factory
+ */
+PHP_RAPHF_API void php_resource_factory_dtor(php_resource_factory_t *f);
+
+/**
+ * Destroy and free the resource factory.
+ *
+ * Calls php_resource_factory_dtor() and frees \a f if the factory's refcount
+ * reached 0.
+ *
+ * @param f the resource factory
+ */
+PHP_RAPHF_API void php_resource_factory_free(php_resource_factory_t **f);
+
+/**
+ * Construct a resource by the resource factory \a f
+ *
+ * @param f the resource factory
+ * @param init_arg for the resource constructor
+ * @return the new resource
+ */
+PHP_RAPHF_API void *php_resource_factory_handle_ctor(php_resource_factory_t *f,
+ void *init_arg);
+
+/**
+ * Create a copy of the resource \a handle
+ *
+ * @param f the resource factory
+ * @param handle the resource to copy
+ * @return the copy
+ */
+PHP_RAPHF_API void *php_resource_factory_handle_copy(php_resource_factory_t *f,
+ void *handle);
+
+/**
+ * Destroy (and free) the resource
+ *
+ * @param f the resource factory
+ * @param handle the resource to destroy
+ */
+PHP_RAPHF_API void php_resource_factory_handle_dtor(php_resource_factory_t *f,
+ void *handle);
+
+/**
+ * Persistent handles storage
+ */
+typedef struct php_persistent_handle_list {
+ /** Storage of free resources */
+ HashTable free;
+ /** Count of acquired resources */
+ ulong used;
+} php_persistent_handle_list_t;
+
+/**
+ * Definition of a persistent handle provider.
+ * Holds a resource factory an a persistent handle list.
+ */
+typedef struct php_persistent_handle_provider {
+ /**
+ * The list of free handles.
+ * Hash of "ident" => array(handles) entries. Persistent handles are
+ * acquired out of this list.
+ */
+ php_persistent_handle_list_t list;
+
+ /**
+ * The resource factory.
+ * New handles are created by this factory.
+ */
+ php_resource_factory_t rf;
+} php_persistent_handle_provider_t;
+
+typedef struct php_persistent_handle_factory php_persistent_handle_factory_t;
+
+/**
+ * Wakeup the persistent handle on re-acquisition.
+ */
+typedef void (*php_persistent_handle_wakeup_t)(
+ php_persistent_handle_factory_t *f, void **handle);
+/**
+ * Retire the persistent handle on release.
+ */
+typedef void (*php_persistent_handle_retire_t)(
+ php_persistent_handle_factory_t *f, void **handle);
+
+/**
+ * Definition of a persistent handle factory.
+ *
+ * php_persistent_handle_concede() will return a pointer to a
+ * php_persistent_handle_factory if a provider for the \a name has
+ * been registered with php_persistent_handle_provide().
+ */
+struct php_persistent_handle_factory {
+ /** The persistent handle provider */
+ php_persistent_handle_provider_t *provider;
+ /** The persistent handle wakeup routine; may be NULL */
+ php_persistent_handle_wakeup_t wakeup;
+ /** The persistent handle retire routine; may be NULL */
+ php_persistent_handle_retire_t retire;
+
+ /** The ident for which this factory manages resources */
+ zend_string *ident;
+
+ /** Whether it has to be free'd on php_persistent_handle_abandon() */
+ unsigned free_on_abandon:1;
+};
+
+/**
+ * Register a persistent handle provider in MINIT.
+ *
+ * Registers a factory provider for \a name_str with \a fops resource factory
+ * ops. Call this in your MINIT.
+ *
+ * A php_resource_factory will be created with \a fops, \a data and \a dtor
+ * and will be stored together with a php_persistent_handle_list in the global
+ * raphf hash.
+ *
+ * A php_persistent_handle_factory can then be retrieved by
+ * php_persistent_handle_concede() at runtime.
+ *
+ * @param name the provider name, e.g. "http\Client\Curl"
+ * @param fops the resource factory ops
+ * @param data opaque user data
+ * @param dtor \a data destructor
+ * @return SUCCESS/FAILURE
+ */
+PHP_RAPHF_API ZEND_RESULT_CODE php_persistent_handle_provide(
+ zend_string *name, php_resource_factory_ops_t *fops,
+ void *data, void (*dtor)(void *));
+
+/**
+ * Retrieve a persistent handle factory at runtime.
+ *
+ * If a persistent handle provider has been registered for \a name, a new
+ * php_persistent_handle_factory creating resources in the \a ident
+ * namespace will be constructed.
+ *
+ * The wakeup routine \a wakeup and the retire routine \a retire will be
+ * assigned to the new php_persistent_handle_factory.
+ *
+ * @param a pointer to a factory; allocated on the heap if NULL
+ * @param name the provider name, e.g. "http\Client\Curl"
+ * @param ident the subsidiary namespace, e.g. "php.net:80"
+ * @param wakeup any persistent handle wakeup routine
+ * @param retire any persistent handle retire routine
+ * @return \a a or an allocated persistent handle factory
+ */
+PHP_RAPHF_API php_persistent_handle_factory_t *php_persistent_handle_concede(
+ php_persistent_handle_factory_t *a,
+ zend_string *name, zend_string *ident,
+ php_persistent_handle_wakeup_t wakeup,
+ php_persistent_handle_retire_t retire);
+
+/**
+ * Abandon the persistent handle factory.
+ *
+ * Destroy a php_persistent_handle_factory created by
+ * php_persistent_handle_concede(). If the memory for the factory was allocated,
+ * it will automatically be free'd.
+ *
+ * @param a the persistent handle factory to destroy
+ */
+PHP_RAPHF_API void php_persistent_handle_abandon(
+ php_persistent_handle_factory_t *a);
+
+/**
+ * Acquire a persistent handle.
+ *
+ * That is, either re-use a resource from the free list or create a new handle.
+ *
+ * If a handle is acquired from the free list, the
+ * php_persistent_handle_factory::wakeup callback will be executed for that
+ * handle.
+ *
+ * @param a the persistent handle factory
+ * @param init_arg the \a init_arg for php_resource_factory_handle_ctor()
+ * @return the acquired resource
+ */
+PHP_RAPHF_API void *php_persistent_handle_acquire(
+ php_persistent_handle_factory_t *a, void *init_arg);
+
+/**
+ * Release a persistent handle.
+ *
+ * That is, either put it back into the free list for later re-use or clean it
+ * up with php_resource_factory_handle_dtor().
+ *
+ * If a handle is put back into the free list, the
+ * php_persistent_handle_factory::retire callback will be executed for that
+ * handle.
+ *
+ * @param a the persistent handle factory
+ * @param handle the handle to release
+ */
+PHP_RAPHF_API void php_persistent_handle_release(
+ php_persistent_handle_factory_t *a, void *handle);
+
+/**
+ * Copy a persistent handle.
+ *
+ * Let the underlying resource factory copy the \a handle.
+ *
+ * @param a the persistent handle factory
+ * @param handle the resource to accrete
+ */
+PHP_RAPHF_API void *php_persistent_handle_accrete(
+ php_persistent_handle_factory_t *a, void *handle);
+
+/**
+ * Retrieve persistent handle resource factory ops.
+ *
+ * These ops can be used to mask a persistent handle factory as
+ * resource factory itself, so you can transparently use the
+ * resource factory API, both for persistent and non-persistent
+ * ressources.
+ *
+ * Example:
+ * \code{.c}
+ * php_resource_factory_t *create_my_rf(zend_string *persistent_id)
+ * {
+ * php_resource_factory_t *rf;
+ *
+ * if (persistent_id) {
+ * php_persistent_handle_factory_t *pf;
+ * php_resource_factory_ops_t *ops;
+ * zend_string *ns = zend_string_init("my", 2, 1);
+ *
+ * ops = php_persistent_handle_get_resource_factory_ops();
+ * pf = php_persistent_handle_concede(NULL, ns, persistent_id, NULL, NULL);
+ * rf = php_persistent_handle_resource_factory_init(NULL, pf);
+ * zend_string_release(ns);
+ * } else {
+ * rf = php_resource_factory_init(NULL, &myops, NULL, NULL);
+ * }
+ * return rf;
+ * }
+ * \endcode
+ */
+PHP_RAPHF_API php_resource_factory_ops_t *
+php_persistent_handle_get_resource_factory_ops(void);
+
+/**
+ * Create a resource factory for persistent handles.
+ *
+ * This will create a resource factory with persistent handle ops, which wraps
+ * the provided reource factory \a pf.
+ *
+ * @param a the persistent handle resource factory to initialize
+ * @param pf the resource factory to wrap
+ */
+PHP_RAPHF_API php_resource_factory_t *
+php_persistent_handle_resource_factory_init(php_resource_factory_t *a,
+ php_persistent_handle_factory_t *pf);
+
+/**
+ * Check whether a resource factory is a persistent handle resource factory.
+ *
+ * @param a the resource factory to check
+ */
+PHP_RAPHF_API zend_bool php_resource_factory_is_persistent(
+ php_resource_factory_t *a);
+
+/**
+ * Clean persistent handles up.
+ *
+ * Destroy persistent handles of provider \a name and in subsidiary
+ * namespace \a ident.
+ *
+ * If \a name is NULL, all persistent handles of all providers with a
+ * matching \a ident will be cleaned up.
+ *
+ * If \a identr is NULL all persistent handles of the provider will be
+ * cleaned up.
+ *
+ * Ergo, if both, \a name and \a ident are NULL, then all
+ * persistent handles will be cleaned up.
+ *
+ * You must call this in MSHUTDOWN, if your resource factory ops hold a
+ * registered php_resource_factory::dtor, else the dtor will point to
+ * memory not any more available if the extension has already been unloaded.
+ *
+ * @param name the provider name; may be NULL
+ * @param ident the subsidiary namespace name; may be NULL
+ */
+PHP_RAPHF_API void php_persistent_handle_cleanup(zend_string *name,
+ zend_string *ident);
+
+/**
+ * Retrieve statistics about the current process/thread's persistent handles.
+ *
+ * @return a HashTable like:
+ * \code
+ * [
+ * "name" => [
+ * "ident" => [
+ * "used" => 1,
+ * "free" => 0,
+ * ]
+ * ]
+ * ]
+ * \endcode
+ */
+PHP_RAPHF_API HashTable *php_persistent_handle_statall(HashTable *ht);
+
+#endif /* PHP_RAPHF_API_H */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+--TEST--
+pecl/http-v2 - general and stat
+--SKIPIF--
+<?php
+if (!extension_loaded("http")) {
+ die("skip pecl/http needed");
+}
+if (!class_exists("http\\Client", false)) {
+ die("skip pecl/http-v2 with curl support needed");
+}
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+$c = new http\Client("curl", "php.net:80");
+do {
+ $c->enqueue(new http\Client\Request("GET", "http://php.net"));
+} while (count($c) < 3);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+unset($c);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+?>
+Done
+--EXPECTF--
+Test
+array(2) {
+ ["http\Client\Curl"]=>
+ array(0) {
+ }
+ ["http\Client\Curl\Request"]=>
+ array(0) {
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(1)
+ ["free"]=>
+ int(0)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(3)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(1)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(3)
+ }
+ }
+}
+Done
+--TEST--
+pecl/http-v2 - clean with name and id
+--SKIPIF--
+<?php
+if (!extension_loaded("http")) {
+ die("skip pecl/http needed");
+}
+if (!class_exists("http\\Client", false)) {
+ die("skip pecl/http-v2 with curl support needed");
+}
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Client("curl", "php.net:80");
+do {
+ $c->enqueue(new http\Client\Request("GET", "http://php.net"));
+} while (count($c) < 3);
+
+unset($c);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+
+raphf\clean_persistent_handles("http\\Client\\Curl");
+raphf\clean_persistent_handles("http\\Client\\Curl\\Request", "php.net:80");
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+?>
+Done
+--EXPECTF--
+Test
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(1)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(3)
+ }
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(0) {
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+Done
+--TEST--
+pecl/http-v2 - clean with id only
+--SKIPIF--
+<?php
+if (!extension_loaded("http")) {
+ die("skip pecl/http needed");
+}
+if (!class_exists("http\\Client", false)) {
+ die("skip pecl/http-v2 with curl support needed");
+}
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$c = new http\Client("curl", "php.net:80");
+do {
+ $c->enqueue(new http\Client\Request("GET", "http://php.net"));
+} while (count($c) < 3);
+
+unset($c);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+raphf\clean_persistent_handles(null, "php.net:80");
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+?>
+Done
+--EXPECTF--
+Test
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(1)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(3)
+ }
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(0)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+Done
+--TEST--
+pecl/http-v2 - partial clean
+--SKIPIF--
+<?php
+if (!extension_loaded("http")) {
+ die("skip pecl/http needed");
+}
+if (!class_exists("http\\Client", false)) {
+ die("skip pecl/http-v2 with curl support needed");
+}
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+$c = new http\Client("curl", "php.net:80");
+$c2 = new http\Client("curl", "php.net:80");
+do {
+ $c->enqueue(new http\Client\Request("GET", "http://php.net"));
+ $c2->enqueue(new http\Client\Request("GET", "http://php.net"));
+} while (count($c) < 3);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+unset($c);
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+raphf\clean_persistent_handles();
+
+$h = (array) raphf\stat_persistent_handles();
+var_dump(array_intersect_key($h, array_flip(preg_grep("/^http/", array_keys($h)))));
+
+?>
+Done
+--EXPECTF--
+Test
+array(2) {
+ ["http\Client\Curl"]=>
+ array(0) {
+ }
+ ["http\Client\Curl\Request"]=>
+ array(0) {
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(2)
+ ["free"]=>
+ int(0)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(6)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(1)
+ ["free"]=>
+ int(1)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(3)
+ ["free"]=>
+ int(3)
+ }
+ }
+}
+array(2) {
+ ["http\Client\Curl"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(1)
+ ["free"]=>
+ int(0)
+ }
+ }
+ ["http\Client\Curl\Request"]=>
+ array(1) {
+ ["php.net:80"]=>
+ array(2) {
+ ["used"]=>
+ int(3)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+Done
+--TEST--
+raphf test
+--SKIPIF--
+<?php
+if (!extension_loaded("raphf")) {
+ die("skip need ext/raphf");
+}
+if (!defined("RAPHF_TEST")) {
+ die("skip need RAPHF_TEST defined (-DPHP_RAPHF_TEST=1)");
+}
+?>
+--INI--
+raphf.persistent_handle.limit=0
+--FILE--
+<?php
+
+function dumper($id) {
+ return function() use ($id) {
+ echo "### back '$id':\n";
+ for ($i=0; $i<func_num_args(); ++$i) {
+ echo "#### arg $i: ";
+ var_dump(func_get_arg($i));
+ }
+ /* relay arguments back */
+ return func_get_args();
+ };
+}
+
+echo "## call provide:\n";
+var_dump(raphf\provide("test",dumper("ctor"),dumper("copy"),dumper("dtor"),"data value",dumper("data_dtor")));
+
+echo "## call concede:\n";
+var_dump($rf = raphf\concede("test","1"));
+
+echo "## call handle_ctor:\n";
+var_dump($h = raphf\handle_ctor($rf, 1));
+
+echo "## call handle_copy:\n";
+var_dump($h2 = raphf\handle_copy($rf, $h));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## call handle_dtor:\n";
+var_dump(raphf\handle_dtor($rf, $h));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## call handle_dtor:\n";
+var_dump(raphf\handle_dtor($rf, $h2));
+var_dump(raphf\stat_persistent_handles());
+
+echo "## cleanup:\n";
+var_dump(raphf\dispute($rf), $rf);
+var_dump(raphf\conceal("test"));
+var_dump(raphf\stat_persistent_handles());
+
+?>
+--EXPECTF--
+## call provide:
+bool(true)
+## call concede:
+resource(4) of type (raphf_user)
+## call handle_ctor:
+### back 'ctor':
+#### arg 0: string(10) "data value"
+#### arg 1: int(1)
+array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ int(1)
+}
+## call handle_copy:
+### back 'copy':
+#### arg 0: string(10) "data value"
+#### arg 1: array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ int(1)
+}
+array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ int(1)
+ }
+}
+object(stdClass)#%d (1) {
+ ["test"]=>
+ array(1) {
+ [1]=>
+ array(2) {
+ ["used"]=>
+ int(2)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+## call handle_dtor:
+### back 'dtor':
+#### arg 0: string(10) "data value"
+#### arg 1: array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ int(1)
+}
+NULL
+object(stdClass)#%d (1) {
+ ["test"]=>
+ array(1) {
+ [1]=>
+ array(2) {
+ ["used"]=>
+ int(1)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+## call handle_dtor:
+### back 'dtor':
+#### arg 0: string(10) "data value"
+#### arg 1: array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ array(2) {
+ [0]=>
+ string(10) "data value"
+ [1]=>
+ int(1)
+ }
+}
+NULL
+object(stdClass)#%d (1) {
+ ["test"]=>
+ array(1) {
+ [1]=>
+ array(2) {
+ ["used"]=>
+ int(0)
+ ["free"]=>
+ int(0)
+ }
+ }
+}
+## cleanup:
+bool(true)
+resource(4) of type (Unknown)
+### back 'data_dtor':
+#### arg 0: string(10) "data value"
+bool(true)
+bool(false)
+\19"\9b
+¬ÅT9GÊ7ðâü\8d\8f©ýO\ 2\0\0\0GBMB
\ No newline at end of file