#include "php_http.h"
+#include <zlib.h>
+#include <curl/curl.h>
+#ifdef PHP_HTTP_HAVE_EVENT
+# include <event.h>
+#endif
+
#include <main/php_ini.h>
#include <ext/standard/info.h>
#include <Zend/zend_extensions.h>
return SUCCESS;
}
-
-
PHP_MINFO_FUNCTION(http)
{
php_info_print_table_start();
php_info_print_table_start();
php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
{
-#ifdef PHP_HTTP_HAVE_CURL
curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
+ php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
-#else
- php_info_print_table_row(3, "libcurl", "disabled", "disabled");
-#endif
#ifdef PHP_HTTP_HAVE_EVENT
php_info_print_table_row(3, "libevent", PHP_HTTP_EVENT_VERSION, event_get_version());
#else
php_info_print_table_row(3, "libevent", "disabled", "disabled");
#endif
-#ifdef PHP_HTTP_HAVE_ZLIB
- php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
-#else
php_info_print_table_row(3, "libz", "disabled", "disabled");
-#endif
}
php_info_print_table_end();
#include "php_http.h"
+#include <ext/date/php_date.h>
+
PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC)
{
if (!list) {
-static inline void append_encoded(php_http_buffer *buf, const char *key, size_t key_len, const char *val, size_t val_len)
+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];
PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len TSRMLS_DC)
{
- php_http_buffer buf;
+ php_http_buffer_t buf;
zval **val;
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
HashPosition pos;
#include "php_http.h"
+#include <zlib.h>
+
static inline int eol_match(char **line, int *eol_len)
{
char *ptr = *line;
static inline int php_http_inflate_rounds(z_stream *Z, int flush, char **buf, size_t *len)
{
int status = 0, round = 0;
- php_http_buffer buffer;
+ php_http_buffer_t buffer;
*buf = NULL;
*len = 0;
}
struct dechunk_ctx {
- php_http_buffer buffer;
+ php_http_buffer_t buffer;
ulong hexlen;
unsigned zeroed:1;
};
static STATUS dechunk_update(php_http_encoding_stream_t *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len)
{
- php_http_buffer tmp;
+ php_http_buffer_t tmp;
struct dechunk_ctx *ctx = s->ctx;
TSRMLS_FETCH_FROM_CTX(s->ts);
if (ctx->zeroed) {
+ php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "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)) {
- return FAILURE;
- }
- if (!php_http_buffer_fix(&ctx->buffer)) {
+ if ((PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) || !php_http_buffer_fix(&ctx->buffer)) {
+ /* OOM */
return FAILURE;
}
/* if strtoul() stops at the beginning of the buffered data
there's domething oddly wrong, i.e. bad input */
if (stop == PHP_HTTP_BUFFER_VAL(&ctx->buffer)) {
+ php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to parse chunk len from '%.*s'", MIN(16, ctx->buffer.used), ctx->buffer.data);
php_http_buffer_dtor(&tmp);
return FAILURE;
}
z_streamp ctx = s->ctx;
if (ctx->opaque) {
- php_http_buffer_free((php_http_buffer **) &ctx->opaque);
+ php_http_buffer_free((php_http_buffer_t **) &ctx->opaque);
}
deflateEnd(ctx);
pefree(ctx, (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT));
z_streamp ctx = s->ctx;
if (ctx->opaque) {
- php_http_buffer_free((php_http_buffer **) &ctx->opaque);
+ php_http_buffer_free((php_http_buffer_t **) &ctx->opaque);
}
inflateEnd(ctx);
pefree(ctx, (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT));
#include "php_http.h"
+#include <main/SAPI.h>
+#include <ext/date/php_date.h>
+#include <ext/standard/php_string.h>
+
PHP_RINIT_FUNCTION(http_env)
{
PHP_HTTP_G->env.response.last_modified = 0;
PHP_HTTP_API STATUS php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
{
STATUS status;
- php_http_buffer headers;
+ php_http_buffer_t headers;
php_http_buffer_init(&headers);
zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers TSRMLS_CC);
}
struct output_ctx {
- php_http_buffer *buf;
+ php_http_buffer_t *buf;
zval *container;
};
/* send multipart/byte-ranges message */
HashPosition pos;
zval **chunk, *zct;
- php_http_buffer preface;
+ php_http_buffer_t preface;
int free_ct = 0;
char *content_type = "application/octet-stream";
char boundary[32], *ct_header_str = "Content-Type: multipart/byteranges; boundary= ";
#include "php_http.h"
+#ifdef PHP_HTTP_HAVE_HASH
+# include "php_hash.h"
+#endif
+
#include <ext/standard/crc32.h>
#include <ext/standard/sha1.h>
#include <ext/standard/md5.h>
#include "php_http.h"
+#include <Zend/zend_exceptions.h>
#ifndef PHP_HTTP_DBG_EXCEPTIONS
# define PHP_HTTP_DBG_EXCEPTIONS 0
}
typedef struct _http_chunked_decode_filter_buffer_t {
- php_http_buffer buffer;
+ php_http_buffer_t buffer;
ulong hexlen;
} PHP_HTTP_FILTER_BUFFER(chunked_decode);
/* new data available? */
if (buckets_in->head) {
- php_http_buffer buf;
+ php_http_buffer_t buf;
out_avail = 1;
php_http_buffer_init(&buf);
}
}
-PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg)
+PHP_HTTP_API STATUS 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 0
const char *state[] = {"START", "KEY", "VALUE", "HEADER_DONE", "DONE"};
- fprintf(stderr, "#HP: %s (%d) %zu\n",
- state[php_http_header_parser_state_is(parser)], zend_hash_num_elements(headers), buffer->used);
+ fprintf(stderr, "#HP-%p: %s (%d) %.*s…\n", parser,
+ php_http_header_parser_state_is(parser)<0?"FAILURE":state[php_http_header_parser_state_is(parser)],
+ zend_hash_num_elements(headers), MIN(16,buffer->used), buffer->data);
#endif
switch (php_http_header_parser_state_pop(parser)) {
case PHP_HTTP_HEADER_PARSER_STATE_FAILURE:
return php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_FAILURE);
}
break;
- /*
- if (colon && (!eol_str || colon < eol_str)) {
- parser->_key.str = estrndup(buffer->data, parser->_key.len = colon - buffer->data);
- while (PHP_HTTP_IS_CTYPE(space, *++colon));
- php_http_buffer_cut(buffer, 0, colon - buffer->data);
- php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_VALUE);
- } else if (eol_str) {
- if (eol_str == buffer->data) {
- 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, php_http_buffer_fix(buffer)->data TSRMLS_CC)) {
- if (callback_func) {
- callback_func(callback_arg, &headers, &parser->info TSRMLS_CC);
- }
- php_http_info_dtor(&parser->info);
- php_http_buffer_cut(buffer, 0, eol_str + eol_len - buffer->data);
- php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_HEADER_DONE);
- } else {
- return PHP_HTTP_HEADER_PARSER_STATE_FAILURE;
- }
- } else {
- php_http_header_parser_state_push(parser, 1, PHP_HTTP_HEADER_PARSER_STATE_KEY);
- return PHP_HTTP_HEADER_PARSER_STATE_KEY;
- }
- break;
- */
}
case PHP_HTTP_HEADER_PARSER_STATE_VALUE: {
PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_pop(php_http_header_parser_t *parser);
PHP_HTTP_API void php_http_header_parser_dtor(php_http_header_parser_t *parser);
PHP_HTTP_API void php_http_header_parser_free(php_http_header_parser_t **parser);
-PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg);
+PHP_HTTP_API STATUS 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);
#endif /* PHP_HTTP_HEADER_PARSER_H */
PHP_HTTP_API STATUS php_http_headers_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC)
{
php_http_header_parser_t ctx;
- php_http_buffer buf;
+ php_http_buffer_t buf;
php_http_buffer_from_string_ex(&buf, header, length);
php_http_header_parser_init(&ctx TSRMLS_CC);
#include "php_http.h"
-/* API */
+#include <main/SAPI.h>
+#include <ext/spl/spl_iterators.h>
+#include <Zend/zend_interfaces.h>
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 php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len TSRMLS_DC)
{
php_http_message_parser_t p;
- php_http_buffer buf;
+ php_http_buffer_t buf;
if (!msg) {
msg = php_http_message_init(NULL, 0 TSRMLS_CC);
if (join && Z_TYPE_PP(header) == IS_ARRAY) {
zval *header_str, **val;
HashPosition pos;
- php_http_buffer str;
+ php_http_buffer_t str;
php_http_buffer_init(&str);
MAKE_STD_ZVAL(header_str);
}
}
-static inline void message_headers(php_http_message_t *msg, php_http_buffer *str)
+static inline void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
{
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
HashPosition pos1;
PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
{
- php_http_buffer str;
+ php_http_buffer_t str;
TSRMLS_FETCH_FROM_CTX(msg->ts);
php_http_buffer_init_ex(&str, 0x1000, 0);
PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length)
{
- php_http_buffer str;
+ php_http_buffer_t str;
char *data;
php_http_buffer_init_ex(&str, 0x1000, 0);
{
char *buf;
size_t len;
- php_http_buffer str;
+ php_http_buffer_t str;
php_http_buffer_init(&str);
}
}
-
-/* PHP */
-
#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args)
#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0)
#define PHP_HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, PHP_HTTP_ARGS(HttpMessage, method), visibility)
PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_pop(php_http_message_parser_t *parser);
PHP_HTTP_API void php_http_message_parser_dtor(php_http_message_parser_t *parser);
PHP_HTTP_API void php_http_message_parser_free(php_http_message_parser_t **parser);
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_parser_t *parser, php_http_buffer *buffer, unsigned flags, php_http_message_t **message);
+PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, php_http_message_t **message);
#endif
#include "php_http.h"
+#include <ext/standard/php_lcg.h>
+#include <ext/standard/php_string.h>
+#include <Zend/zend_exceptions.h>
+
/* SLEEP */
PHP_HTTP_API void php_http_sleep(double s)
char *message;
zend_class_entry *ce;
- if (EG(exception_class) && instanceof_function(EG(exception_class), php_http_exception_class_entry)) {
+ if (0&& EG(exception_class) && instanceof_function(EG(exception_class), php_http_exception_class_entry)) {
ce = EG(exception_class);
} else {
ce = php_http_exception_get_for_code(code);
/* PASS CALLBACK */
typedef size_t (*php_http_pass_callback_t)(void *cb_arg, const char *str, size_t len);
-typedef size_t (*php_http_pass_php_http_buffer_callback_t)(void *cb_arg, php_http_buffer *str);
+typedef size_t (*php_http_pass_php_http_buffer_callback_t)(void *cb_arg, php_http_buffer_t *str);
typedef struct php_http_pass_callback_arg {
size_t (*cb_zts)(void *cb_arg, const char *str, size_t len TSRMLS_DC);
#include "php_http.h"
+#include <ext/standard/php_string.h>
+
#ifndef PHP_HTTP_DBG_NEG
# define PHP_HTTP_DBG_NEG 0
#endif
#include "php_http.h"
-/** API **/
+#include <main/php_variables.h>
+#include <ext/spl/spl_array.h>
+#include <Zend/zend_interfaces.h>
+
+#ifdef PHP_HTTP_HAVE_ICONV
+# undef PHP_ATOM_INC
+# include <ext/iconv/php_iconv.h>
+#endif
static inline int php_http_querystring_modify_array_ex(zval *qarray, int key_type, char *key, int keylen, ulong idx, zval *params_entry TSRMLS_DC);
static inline int php_http_querystring_modify_array(zval *qarray, zval *params TSRMLS_DC);
return 1;
}
-/** PHP **/
-
#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpQueryString, method, 0, req_args)
#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpQueryString, method, 0)
#define PHP_HTTP_QUERYSTRING_ME(method, visibility) PHP_ME(HttpQueryString, method, PHP_HTTP_ARGS(HttpQueryString, method), visibility)
#include "php_http.h"
+#include <Zend/zend_interfaces.h>
+
+#if defined(ZTS) && defined(PHP_HTTP_HAVE_SSL)
+# ifdef PHP_WIN32
+# define PHP_HTTP_NEED_OPENSSL_TSL
+# include <openssl/crypto.h>
+# else /* !PHP_WIN32 */
+# if defined(PHP_HTTP_HAVE_OPENSSL)
+# define PHP_HTTP_NEED_OPENSSL_TSL
+# include <openssl/crypto.h>
+# elif defined(PHP_HTTP_HAVE_GNUTLS)
+# define PHP_HTTP_NEED_GNUTLS_TSL
+# include <gcrypt.h>
+# else
+# warning \
+ "libcurl was compiled with SSL support, but configure could not determine which" \
+ "library was used; thus no SSL crypto locking callbacks will be set, which may " \
+ "cause random crashes on SSL requests"
+# endif /* PHP_HTTP_HAVE_OPENSSL || PHP_HTTP_HAVE_GNUTLS */
+# endif /* PHP_WIN32 */
+#endif /* ZTS && PHP_HTTP_HAVE_SSL */
+
+
#ifdef PHP_HTTP_NEED_OPENSSL_TSL
static MUTEX_T *php_http_openssl_tsl = NULL;
else if ((zoption = php_http_request_option(request, options, ZEND_STRS("range"), IS_ARRAY)) && zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
HashPosition pos1, pos2;
zval **rr, **rb, **re;
- php_http_buffer rs;
+ php_http_buffer_t rs;
php_http_buffer_init(&rs);
FOREACH_VAL(pos1, zoption, rr) {
php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
zval **header_val;
HashPosition pos;
- php_http_buffer header;
+ php_http_buffer_t header;
php_http_buffer_init(&header);
FOREACH_KEYVAL(pos, zoption, header_key, header_val) {
/* etag */
if ((zoption = php_http_request_option(request, options, ZEND_STRS("etag"), IS_STRING)) && Z_STRLEN_P(zoption)) {
zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
- php_http_buffer header;
+ php_http_buffer_t header;
php_http_buffer_init(&header);
php_http_buffer_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
{
if (SUCCESS == zend_parse_parameters_none()) {
zval *message = zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("responseMessage"), 0 TSRMLS_CC);
- zval *body = zend_read_property(php_http_message_class_entry, message, ZEND_STRL("body"), 0 TSRMLS_CC);
- RETURN_ZVAL(body, 1, 0);
+ RETURN_OBJVAL(((php_http_message_object_t *)zend_object_store_get_object(message TSRMLS_CC))->body, 1);
}
RETURN_FALSE;
}
struct {
php_http_message_parser_t *ctx;
php_http_message_t *msg;
- php_http_buffer *buf;
+ php_http_buffer_t *buf;
} parser;
struct {
- php_http_buffer cookies;
+ php_http_buffer_t cookies;
HashTable options;
struct curl_slist *headers;
} _cache;
#include "php_http.h"
+#include <ext/spl/spl_iterators.h>
+
static HashTable php_http_request_datashare_options;
static php_http_request_datashare_t php_http_request_datashare_global;
static int php_http_request_datashare_compare_handles(void *h1, void *h2);
#include "php_http.h"
+#include <Zend/zend_interfaces.h>
+
static PHP_HTTP_STRLIST(php_http_request_methods) =
PHP_HTTP_STRLIST_ITEM("UNKNOWN")
/* HTTP/1.1 */
#include "php_http.h"
+#ifdef PHP_HTTP_HAVE_EVENT
+# include <event.h>
+#endif
+
+#include <ext/spl/spl_iterators.h>
+#include <Zend/zend_interfaces.h>
#ifndef PHP_HTTP_DEBUG_REQPOOLS
# define PHP_HTTP_DEBUG_REQPOOLS 0
#include "php_http.h"
+#include <main/SAPI.h>
+#include <ext/standard/php_string.h>
+
static inline char *localhostname(void)
{
char hostname[1024] = {0};
{
char *arg_sep;
size_t arg_sep_len;
- php_http_buffer *qstr = php_http_buffer_new();
+ php_http_buffer_t *qstr = php_http_buffer_new();
if (override_argsep || !(arg_sep_len = strlen(arg_sep = INI_STR("arg_separator.output")))) {
arg_sep = PHP_HTTP_URL_ARGSEP;
return SUCCESS;
}
-PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC)
+PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer_t *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC)
{
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
zval **data = NULL;
FOREACH_HASH_KEYVAL(pos, ht, key, data) {
char *encoded_key;
int encoded_len;
- php_http_buffer new_prefix;
+ php_http_buffer_t new_prefix;
if (!data || !*data) {
php_http_buffer_dtor(str);
#ifndef PHP_HTTP_URL_H
#define PHP_HTTP_URL_H
+#include <ext/standard/url.h>
+
#define PHP_HTTP_URL_REPLACE 0x000
#define PHP_HTTP_URL_JOIN_PATH 0x001
#define PHP_HTTP_URL_JOIN_QUERY 0x002
PHP_HTTP_API char *php_http_url_absolute(const char *url, int flags TSRMLS_DC);
PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, zend_bool override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
-PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC);
+PHP_HTTP_API STATUS php_http_url_encode_hash_recursive(HashTable *ht, php_http_buffer_t *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC);
static inline php_url *php_http_url_from_struct(php_url *url, HashTable *ht TSRMLS_DC)
{