/* make functions that return SUCCESS|FAILURE more obvious */
typedef int STATUS;
+/* inline doc */
+#define _RETURNS(type)
+
#if (defined(HAVE_ICONV) || defined(PHP_HTTP_HAVE_EXT_ICONV)) && (PHP_HTTP_SHARED_DEPS || !defined(COMPILE_DL_ICONV))
# define PHP_HTTP_HAVE_ICONV
#endif
if ((msg = *response)) {
php_http_message_object_t *msg_obj;
zval *info, *zresponse, *zrequest;
+ HashTable *info_ht;
if (i_zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
handle_history(&zclient, *request, *response TSRMLS_CC);
php_http_message_object_prepend(zresponse, zrequest, 1 TSRMLS_CC);
MAKE_STD_ZVAL(info);
- array_init(info);
- php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &Z_ARRVAL_P(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);
zval_ptr_dtor(&info);
obj->client->responses.dtor = response_dtor;
}
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_FACTORY, "Failed to locate \"%s\" client request handler", driver_str);
+ php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to locate \"%s\" client request handler", driver_str);
}
}
} end_error_handling();
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, send)
{
- RETVAL_FALSE;
-
with_error_handling(EH_THROW, php_http_exception_class_entry) {
if (SUCCESS == zend_parse_parameters_none()) {
with_error_handling(EH_THROW, php_http_exception_class_entry) {
if (SUCCESS == zend_parse_parameters_none()) {
php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (0 < php_http_client_once(obj->client)) {
- RETURN_TRUE;
- }
+ RETURN_BOOL(0 < php_http_client_once(obj->client));
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_wait, 0, 0, 0)
RETURN_BOOL(SUCCESS == php_http_client_wait(obj->client, timeout > 0 ? &timeout_val : NULL));
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enablePipelining, 0, 0, 0)
with_error_handling(EH_THROW, php_http_exception_class_entry) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
+ HashTable *info;
php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
- array_init(return_value);
- php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &Z_ARRVAL_P(return_value));
+ object_init(return_value);
+ info = HASH_OF(return_value);
+ php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &info);
}
} end_error_handling();
}
/* catch progress */
switch (type) {
case CURLINFO_TEXT:
- if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
+ if (data[0] == '-') {
+ } else if (php_memnstr(data, ZEND_STRL("Adding handle:"), data + length)) {
+ h->progress.info = "setup";
+ } else if (php_memnstr(data, ZEND_STRL("addHandle"), data + length)) {
+ h->progress.info = "setup";
+ } else if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
h->progress.info = "resolve";
} else if (php_memnstr(data, ZEND_STRL("Trying"), data + length)) {
h->progress.info = "connect";
h->progress.info = "connected";
} else if (php_memnstr(data, ZEND_STRL("Re-using existing connection!"), data + length)) {
h->progress.info = "connected";
+ } else if (php_memnstr(data, ZEND_STRL("blacklisted"), data + length)) {
+ h->progress.info = "blacklist check";
+ } else if (php_memnstr(data, ZEND_STRL("SSL"), data + length)) {
+ h->progress.info = "ssl negotiation";
} else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
h->progress.info = "not disconnected";
} else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
} else if (php_memnstr(data, ZEND_STRL("Operation timed out"), data + length)) {
h->progress.info = "timeout";
} else {
+#if PHP_DEBUG
h->progress.info = data;
+#endif
}
if (h->client->callback.progress.func) {
h->client->callback.progress.func(h->client->callback.progress.arg, h->client, &h->queue, &h->progress);
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("unrestrictedauth"), 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_BOOL);
-#else
- php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POST301, IS_BOOL);
+ php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_LONG);
#endif
/* retries */
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
}
php_http_option_register(registry, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE, IS_STRING);
- php_http_option_register(registry, ZEND_STRL("certpasswd"), CURLOPT_SSLCERTPASSWD, IS_STRING);
if ((opt = php_http_option_register(registry, ZEND_STRL("key"), CURLOPT_SSLKEY, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
with_error_handling(EH_THROW, php_http_exception_class_entry) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!O!", &meth_str, &meth_len, &url_str, &url_len, &zheaders, &zbody, 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 *body_obj = NULL;
-
- if (zbody) {
- php_http_message_object_set_body(obj, zbody TSRMLS_CC);
- }
if (obj->message) {
php_http_message_set_type(obj->message, PHP_HTTP_REQUEST);
- if (body_obj) {
- php_http_message_body_free(&obj->message->body);
- obj->message->body = body_obj->body;
- }
} else {
- obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, body_obj ? body_obj->body : NULL TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC);
}
+ if (zbody) {
+ php_http_message_object_set_body(obj, zbody TSRMLS_CC);
+ }
if (meth_str && meth_len) {
PHP_HTTP_INFO(obj->message).request.method = estrndup(meth_str, meth_len);
}
{
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
+ zval *zct;
- RETURN_ZVAL(zct, 0, 1);
+ php_http_message_update_headers(obj->message);
+ zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
+ if (zct) {
+ RETURN_ZVAL(zct, 0, 1);
+ }
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setQuery, 0, 0, 0)
{
long flags = 0;
zval *allowed_extras_array = NULL;
+ int i = 0;
+ char **allowed_extras = NULL;
+ zval *header = NULL, **entry = NULL;
+ HashPosition pos;
+ php_http_message_object_t *msg;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
- int i = 0;
- char **allowed_extras = NULL;
- zval *header = NULL, **entry = NULL;
- HashPosition pos;
- php_http_message_object_t *msg = zend_object_store_get_object(getThis() TSRMLS_CC);
-
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
+ return;
+ }
- array_init(return_value);
+ msg = zend_object_store_get_object(getThis() TSRMLS_CC);
+ array_init(return_value);
- if (allowed_extras_array) {
- 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);
- }
+ if (allowed_extras_array) {
+ 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);
}
+ }
- if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
- php_http_cookie_list_t *list;
-
- if (Z_TYPE_P(header) == IS_ARRAY) {
- zval **single_header;
+ if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) {
+ php_http_cookie_list_t *list;
- FOREACH_VAL(pos, header, single_header) {
- zval *data = php_http_ztyp(IS_STRING, *single_header);
+ if (Z_TYPE_P(header) == IS_ARRAY) {
+ zval **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;
+ FOREACH_VAL(pos, header, single_header) {
+ zval *data = php_http_ztyp(IS_STRING, *single_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);
- }
- zval_ptr_dtor(&data);
- }
- } 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;
}
zval_ptr_dtor(&data);
}
- zval_ptr_dtor(&header);
- }
-
- if (allowed_extras) {
- for (i = 0; allowed_extras[i]; ++i) {
- efree(allowed_extras[i]);
+ } 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;
+
+ 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);
}
- efree(allowed_extras);
+ zval_ptr_dtor(&data);
}
+ zval_ptr_dtor(&header);
+ }
- return;
+ if (allowed_extras) {
+ for (i = 0; allowed_extras[i]; ++i) {
+ efree(allowed_extras[i]);
+ }
+ efree(allowed_extras);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo, 0, 0, 0)
{
char *info_name = NULL;
int info_len = 0;
+ zval *infop, *info;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
- zval **infop, *info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
+ return;
+ }
- /* request completed? */
- if (Z_TYPE_P(info) == IS_ARRAY) {
- if (info_len && info_name) {
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(info), php_http_pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
- RETURN_ZVAL(*infop, 1, 0);
- } else {
- php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name);
- }
+ info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
+
+ /* request completed? */
+ if (Z_TYPE_P(info) == IS_OBJECT) {
+ if (info_len && info_name) {
+ infop = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
+
+ if (infop) {
+ RETURN_ZVAL(infop, 1, 0);
} else {
- RETURN_ZVAL(info, 1, 0);
+ php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name);
}
+ } else {
+ RETURN_ZVAL(info, 1, 0);
}
}
RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getExtras, 0, 0, 0)
-ZEND_END_ARG_INFO();;
+ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, getExtras)
{
if (SUCCESS == zend_parse_parameters_none()) {
array_init(return_value);
array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
- return;
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtras, 0, 0, 0)
RETURN_ZVAL(zvalue, 1, 0);
}
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setCookie, 0, 0, 1)
RETVAL_ZVAL(getThis(), 1, 0);
}
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookie, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookie, 0, 0, 2)
ZEND_ARG_INFO(0, cookie_name)
ZEND_ARG_INFO(0, cookie_value)
ZEND_END_ARG_INFO();
char *name_str, *value_str;
int name_len, value_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
RETURN_ZVAL(zvalue, 1, 0);
}
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtra, 0, 0, 1)
RETVAL_ZVAL(getThis(), 1, 0);
}
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtra, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtra, 0, 0, 2)
ZEND_ARG_INFO(0, extra_name)
ZEND_ARG_INFO(0, extra_value)
ZEND_END_ARG_INFO();
char *name_str, *value_str;
int name_len, value_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
PHP_HTTP_COOKIE_OBJECT_INIT(obj);
}
RETURN_NULL();
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setDomain, 0, 0, 0)
}
RETURN_NULL();
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setPath, 0, 0, 0)
RETURN_LONG(obj->list->expires);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExpires, 0, 0, 0)
RETURN_LONG(obj->list->max_age);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setMaxAge, 0, 0, 0)
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getFlags, 0, 0, 0)
-ZEND_END_ARG_INFO();;
+ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, getFlags)
{
if (SUCCESS == zend_parse_parameters_none()) {
RETURN_LONG(obj->list->flags);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setFlags, 0, 0, 0)
php_stream *input = php_stream_open_wrapper("php://input", "r", 0, NULL);
/* php://input does not support stat */
- php_stream_copy_to_stream(input, s, -1);
+ 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) {
char *header_name_str = NULL;
int header_name_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
- 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);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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);
- if (header_value) {
- RETURN_STRINGL(header_value, header_length, 0);
- }
- RETURN_NULL();
- } else {
- array_init(return_value);
- php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
- return;
+ if (header_value) {
+ RETURN_STRINGL(header_value, header_length, 0);
}
+ } else {
+ array_init(return_value);
+ php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestBody, 0, 0, 0)
{
long code;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
- RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ return;
}
- RETURN_FALSE;
+ RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes, 0, 0, 0)
php_http_strlist_iterator_t i;
if (SUCCESS != zend_parse_parameters_none()) {
- RETURN_FALSE;
+ return;
}
array_init(return_value);
char *header_name_str = NULL;
int header_name_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
- if (header_name_str && header_name_len) {
- char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|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);
- if (header_value) {
- RETURN_STRING(header_value, 0);
- }
- RETURN_NULL();
- } else {
- array_init(return_value);
- php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
- return;
+ if (header_value) {
+ RETURN_STRING(header_value, 0);
}
+ } else {
+ array_init(return_value);
+ php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseCode, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, getResponseCode)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
- RETURN_FALSE;
+ RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader, 0, 0, 1)
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)) {
- RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
+ return;
}
- RETURN_FALSE;
+ RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1)
{
long code;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
- RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ return;
}
- RETURN_FALSE;
+ RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC));
}
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 (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
-
- PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array);
- } else {
- RETURN_FALSE;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
}
+ if (rs_array) {
+ zval_dtor(rs_array);
+ array_init(rs_array);
+ }
+
+ PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateCharset, 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 (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
- PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array);
- } else {
- RETURN_FALSE;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
+ }
+ if (rs_array) {
+ zval_dtor(rs_array);
+ array_init(rs_array);
}
+ PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateEncoding, 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 (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
- PHP_HTTP_DO_NEGOTIATE(encoding, supported, rs_array);
- } else {
- RETURN_FALSE;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
}
+ if (rs_array) {
+ zval_dtor(rs_array);
+ array_init(rs_array);
+ }
+ PHP_HTTP_DO_NEGOTIATE(encoding, supported, rs_array);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateContentType, 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 (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
- PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
- } else {
- RETURN_FALSE;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
+ }
+ if (rs_array) {
+ zval_dtor(rs_array);
+ array_init(rs_array);
}
+ PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiate, 0, 0, 2)
- ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, params)
ZEND_ARG_INFO(0, supported)
ZEND_ARG_INFO(0, primary_type_separator)
ZEND_ARG_INFO(1, result_array)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, negotiate)
{
- HashTable *supported;
+ HashTable *supported, *rs;
zval *rs_array = NULL;
char *value_str, *sep_str = NULL;
int 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)) {
- HashTable *rs;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|s!z", &value_str, &value_len, &supported, &sep_str, &sep_len, &rs_array)) {
+ return;
+ }
- if (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))) {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
- } else {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
- }
+ if (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))) {
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
} else {
- RETURN_FALSE;
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
}
}
#if PHP_VERSION_ID >= 50600
php_http_message_body_to_string(php_http_env_get_request_body(TSRMLS_C),
- &json_str, &json_len, 0, -1 TSRMLS_CC);
+ &json_str, &json_len, 0, -1);
#else
json_str = SG(request_info).raw_post_data;
json_len = SG(request_info).raw_post_data_length;
{
char *val_str;
int val_len;
- long flags = 0;
+ long flags = PHP_HTTP_MATCH_LOOSE;
zval *zvalue;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &val_str, &val_len, &flags)) {
- RETURN_NULL();
+ return;
}
zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
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 (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
+ }
+ if (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")) {
- sep_str = "/";
- sep_len = 1;
- } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
- sep_str = "-";
- sep_len = 1;
- }
- zval_ptr_dtor(&zname);
+ 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")) {
+ sep_str = "/";
+ sep_len = 1;
+ } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
+ sep_str = "-";
+ sep_len = 1;
+ }
+ 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 ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
- } else {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
- }
- zval_ptr_dtor(&zvalue);
+ 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))) {
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
} else {
- RETURN_FALSE;
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
}
+ zval_ptr_dtor(&zvalue);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_getParams, 0, 0, 0)
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_parse, 0, 0, 1)
ZEND_ARG_INFO(0, string)
- ZEND_ARG_INFO(0, flags)
+ ZEND_ARG_INFO(0, header_class)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, parse)
{
php_stream *s;
TSRMLS_FETCH_FROM_CTX(body->ts);
- s = php_http_message_body_stream(body);
+ if (!(s = php_http_message_body_stream(body))) {
+ return -1;
+ }
+
php_stream_seek(s, 0, SEEK_END);
return php_stream_write(s, buf, len);
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, toArray)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- zval *zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC);
- RETURN_ZVAL(zparams, 1, 0);
+ zval *zparams;
+
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
- RETURN_FALSE;
+ zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC);
+ RETURN_ZVAL(zparams, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toString, 0, 0, 0)
PHP_METHOD(HttpQueryString, toString)
{
if (SUCCESS != zend_parse_parameters_none()) {
- RETURN_FALSE;
+ return;
}
php_http_querystring_str(getThis(), return_value TSRMLS_CC);
}
zval *zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
RETURN_ZVAL(zqa, 1, 0);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_get, 0, 0, 0)
PHP_METHOD(HttpQueryString, serialize)
{
if (SUCCESS != zend_parse_parameters_none()) {
- RETURN_FALSE;
+ return;
}
php_http_querystring_str(getThis(), return_value TSRMLS_CC);
}
ZEND_END_ARG_INFO();
PHP_METHOD(HttpUrl, toArray)
{
+ php_url *purl;
+
if (SUCCESS != zend_parse_parameters_none()) {
- RETURN_FALSE;
+ return;
}
- array_init(return_value);
- array_copy(HASH_OF(getThis()), HASH_OF(return_value));
+
+ /* strip any non-URL properties */
+ purl = php_http_url_from_struct(NULL, HASH_OF(getThis()) TSRMLS_CC);
+ php_http_url_to_struct(purl, return_value TSRMLS_CC);
+ php_url_free(purl);
}
static zend_function_entry php_http_url_methods[] = {
return true;
}
-if (!strlen($ext = $argv[1]))
- die(sprintf("Usage: %s <ext>\n", $argv[0]));
+ob_start(function($s) {
+ // redirect any output to stderr
+ fwrite(STDERR, $s);
+ return true;
+});
+
+$out = STDOUT;
+switch ($argc) {
+ default:
+ case 3:
+ $out = fopen($argv[2], "w") or die;
+ case 2:
+ $ext = $argv[1];
+ break;
+
+ case 1:
+ die(sprintf($out, "Usage: %s <ext>\n", $argv[0]));
+}
-printf("<?php\n\n");
+fprintf($out, "<?php\n\n");
$ext = new ReflectionExtension($ext);
+
+$constants = array();
+$functions = array();
+$structures = array();
+
+// split up by namespace first
foreach ($ext->getConstants() as $constant => $value) {
- printf("define('%s', '%s');\n", $constant, $value);
+ $ns = ($nsend = strrpos($constant, "\\")) ? substr($constant, 0, $nsend++) : "";
+ $cn = substr($constant, $nsend);
+ $constants[$ns][$cn] = $value;
}
-printf("\n");
-
foreach ($ext->getFunctions() as $f) {
- printf("function %s(", $f->getName());
- $ps = array();
- foreach ($f->getParameters() as $p) {
- $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName());
- if ($p->isOptional()) {
- if ($p->isDefaultValueAvailable()) {
- $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true));
- } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
- $p1 .= " = NULL";
- } elseif ($p->isArray()) {
- $p1 .= " = array()";
- }
- }
- $ps[] = $p1;
- }
- printf("%s) {\n}\n", implode(", ", $ps));
+ /* @var $f ReflectionFunction */
+ $ns = $f->inNamespace() ? $f->getNamespaceName() : "";
+ $functions[$ns][$f->getShortName()] = $f;
+}
+foreach ($ext->getClasses() as $c) {
+ /* @var $c ReflectionClass */
+ $ns = $c->inNamespace() ? $c->getNamespaceName() : "";
+ $structures[$ns][$c->getShortName()] = $c;
}
-printf("\n");
-$classes = $ext->getClasses();
-usort($classes, function($a,$b) {
- $cmp = strcmp($a->getNamespaceName(), $b->getNamespaceName());
- if (!$cmp) {
- $cmp = strcmp($a->getShortName(), $b->getShortName());
- }
- return $cmp;
- }
-);
+$namespaces = array_unique(array_merge(
+ array_keys($constants),
+ array_keys($functions),
+ array_keys($structures)
+));
-foreach ($classes as $class) {
+// simple sort
+natsort($namespaces);
- if ($class->inNamespace()) {
- printf("namespace %s\n{\n", $class->getNamespaceName());
+foreach ($namespaces as $ns) {
+ fprintf($out, "namespace %s%s\n{\n", $ns, strlen($ns) ? " " : "");
+ //
+ if (isset($constants[$ns])) {
+ ksort($constants[$ns], SORT_NATURAL);
+ foreach ($constants[$ns] as $cn => $value) {
+ fprintf($out, "\tconst %s = %s;\n", $cn, var_export($value, true));
+ }
}
- printf("\t%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getShortName());
- if ($p = $class->getParentClass()) {
- printf("extends \\%s ", $p->getName());
- }
- if ($i = $class->getInterfaceNames()) {
- printf("implements \\%s ", implode(", \\", array_filter($i,function($v){return$v!="Traversable";})));
- }
- printf("\n\t{\n");
-
- $_=0;
- foreach ($class->getConstants() as $n => $v) {
- c($n, $class) and $_+=printf("\t\tconst %s = %s;\n", $n, var_export($v, true));
- }
- $_ and printf("\n");
- $_=0;
- foreach ($class->getProperties() as $p) {
- if ($p->getDeclaringClass()->getName() == $class->getName()) {
- $_+=printf("\t\t%s\$%s;\n", m($p->getModifiers()), $p->getName());
- }
- }
- $_ and printf("\n");
-
- foreach ($class->getMethods() as $m) {
- if ($m->getDeclaringClass()->getName() == $class->getName()) {
- printf("\t\t%sfunction %s(", m($m->getModifiers()), $m->getName());
- $ps = array();
- foreach ($m->getParameters() as $p) {
- $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName());
+ //
+ if (isset($functions[$ns])) {
+ ksort($functions[$ns], SORT_NATURAL);
+ foreach ($functions[$ns] as $fn => $f) {
+ /* @var $f ReflectionFunction */
+ fprintf($out, "\n\tfunction %s(", $fn);
+ $ps = array();
+ foreach ($f->getParameters() as $p) {
+ $p1 = sfprintf($out, "%s%s\$%s", t($p),
+ $p->isPassedByReference()?"&":"", $p->getName());
if ($p->isOptional()) {
if ($p->isDefaultValueAvailable()) {
- $p1 .= sprintf(" = %s", var_export($p->getDefaultValue(), true));
+ $p1 .= sfprintf($out, " = %s",
+ var_export($p->getDefaultValue(), true));
} elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
- $p1 .= sprintf(" = NULL");
+ $p1 .= " = NULL";
} elseif ($p->isArray()) {
$p1 .= " = array()";
}
}
- $ps[] = $p1;
- }
- printf("%s)", implode(", ", $ps));
- if ($m->isAbstract()) {
- printf(";\n\n");
- } else {
- printf(" {\n\t\t}\n\n");
- }
- }
- }
+ $ps[] = $p1;
+ }
+ fprintf($out, "%s) {\n\t}\n", implode(", ", $ps));
+ }
+ }
+ //
+ if (isset($structures[$ns])) {
+ uasort($structures[$ns], function ($a, $b) {
+ /* @var $a ReflectionClass */
+ /* @var $b ReflectionClass */
+ $score = array_sum([
+ -!$a->isInterface()+
+ -!$a->isAbstract()+
+ -!$a->isTrait()+
+ -!substr_compare($a->getShortName(), "Exception", -strlen("Exception")),
+ +!$b->isInterface()+
+ +!$b->isAbstract()+
+ +!$b->isTrait()+
+ -!substr_compare($b->getShortName(), "Exception", -strlen("Exception")),
+ ]);
+
+ if ($score) {
+ return -$score;
+ }
+ return strnatcmp($a->getShortName(), $b->getShortName());
+ });
+ foreach ($structures[$ns] as $cn => $c) {
+ fprintf($out, "\n\t%s%s %s ", m($c->getModifiers()),
+ $c->isInterface() ? "interface":"class", $c->getShortName());
+ if ($p = $c->getParentClass()) {
+ fprintf($out, "extends \\%s ", $p->getName());
+ }
+ if ($i = $c->getInterfaceNames()) {
+ fprintf($out, "implements \\%s ",
+ implode(", \\", array_filter($i, function($v) {
+ return $v != "Traversable";
+
+ }))
+ );
+ }
+ fprintf($out, "\n\t{\n");
+
+ $_=0;
+ foreach ($c->getConstants() as $n => $v) {
+ c($n, $c) and $_+=fprintf($out, "\t\tconst %s = %s;\n", $n,
+ var_export($v, true));
+ }
+ $_ and fprintf($out, "\n");
+ $_=0;
+ foreach ($c->getProperties() as $p) {
+ if ($p->getDeclaringClass()->getName() == $c->getName()) {
+ $_+=fprintf($out, "\t\t%s\$%s;\n", m($p->getModifiers()),
+ $p->getName());
+ }
+ }
+ $_ and fprintf($out, "\n");
- printf("\t}\n");
- if ($class->inNamespace()) {
- printf("}\n");
+ foreach ($c->getMethods() as $m) {
+ if ($m->getDeclaringClass()->getName() == $c->getName()) {
+ fprintf($out, "\t\t%sfunction %s(", m($m->getModifiers()),
+ $m->getName());
+ $ps = array();
+ foreach ($m->getParameters() as $p) {
+ $p1 = sprintf("%s%s\$%s", t($p),
+ $p->isPassedByReference()?"&":"", $p->getName());
+ if ($p->isOptional()) {
+ if ($p->isDefaultValueAvailable()) {
+ $p1 .= sprintf(" = %s",
+ var_export($p->getDefaultValue(), true));
+ } elseif (!($p->isArray() || $p->getClass()) || $p->allowsNull()) {
+ $p1 .= sprintf(" = NULL");
+ } elseif ($p->isArray()) {
+ $p1 .= " = array()";
+ }
+ }
+ $ps[] = $p1;
+ }
+ fprintf($out, "%s)", implode(", ", $ps));
+ if ($m->isAbstract()) {
+ fprintf($out, ";\n\n");
+ } else {
+ fprintf($out, " {\n\t\t}\n\n");
+ }
+ }
+ }
+
+ fprintf($out, "\t}\n");
+
+ }
}
- printf("\n");
+ //
+ fprintf($out, "}\n\n");
}
-
$client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/"));
$client->send();
-$ti = $client->getTransferInfo($req);
+$ti = (array) $client->getTransferInfo($req);
var_dump(array_key_exists("ssl_engines", $ti));
var_dump(0 < count($ti["ssl_engines"]));
?>
$client = new http\Client($driver);
$response = $client->enqueue($request)->send()->getResponse();
var_dump($response->getTransferInfo("response_code"));
- var_dump(count($response->getTransferInfo()));
+ var_dump(count((array)$response->getTransferInfo()));
}
?>
Done