}
}
-
-
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_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 **zcookie)
{
- zval **cookie = NULL;
+ zval **cookie;
if ((SUCCESS != zend_symtable_find(&list->cookies, name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
return NULL;
}
+ if (zcookie) {
+ *zcookie = *cookie;
+ }
return Z_STRVAL_PP(cookie);
}
-
-
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_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 **zextra)
{
- zval **extra = NULL;
+ zval **extra;
+
if ((SUCCESS != zend_symtable_find(&list->extras, name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) {
return NULL;
}
+ if (zextra) {
+ *zextra = *extra;
+ }
return Z_STRVAL_PP(extra);
}
-
-
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)
{
zval *cookie_value;
zend_symtable_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
}
-
-
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)
{
zval *cookie_value;
return list;
}
-
PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
{
zval array, *cookies, *extras;
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];
efree(enc_str[1]);
}
-
-
PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
{
php_http_buffer_t buf;
return ov;
}
+#define PHP_HTTP_COOKIE_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->list) { \
+ obj->list = php_http_cookie_list_init(NULL TSRMLS_CC); \
+ } \
+ } while(0)
+
zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC)
{
php_http_cookie_object_t *new_obj, *old_obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zend_object_value ov;
- if (!old_obj->list) {
- old_obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(old_obj);
+
ov = php_http_cookie_object_new_ex(old_obj->o.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);
PHP_METHOD(HttpCookie, __construct)
{
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+ php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zval *zcookie = NULL;
long flags = 0;
HashTable *allowed_extras = NULL;
if (zcookie) {
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
char **ae = NULL;
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
if (allowed_extras && zend_hash_num_elements(allowed_extras)) {
char **ae_ptr = safe_emalloc(zend_hash_num_elements(allowed_extras) + 1, sizeof(char *), 0);
} end_error_handling();
}
}
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
} end_error_handling();
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
array_init(return_value);
array_copy(&obj->list->cookies, Z_ARRVAL_P(return_value));
return;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &cookies)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
zend_hash_clean(&obj->list->cookies);
if (cookies) {
array_copy(cookies, &obj->list->cookies);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &cookies)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY);
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
array_init(return_value);
array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
return;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &extras)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
zend_hash_clean(&obj->list->extras);
if (extras) {
array_copy(extras, &obj->list->extras);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &extras)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY);
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval **zvalue;
+ zval *zvalue;
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
- if (SUCCESS == zend_symtable_find(&obj->list->cookies, name_str, name_len + 1, (void *) &zvalue)) {
- RETURN_ZVAL(*zvalue, 1, 0);
+ 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_FALSE;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
if (!value_str) {
- zend_symtable_del(&obj->list->cookies, name_str, name_len + 1);
+ php_http_cookie_list_del_cookie(obj->list, name_str, name_len);
} else {
- zval *zvalue;
-
- MAKE_STD_ZVAL(zvalue);
- ZVAL_STRINGL(zvalue, value_str, value_len, 1);
- zend_symtable_update(&obj->list->cookies, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+ php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
}
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zvalue;
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
- MAKE_STD_ZVAL(zvalue);
- ZVAL_STRINGL(zvalue, value_str, value_len, 1);
- zend_symtable_update(&obj->list->cookies, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval **zvalue;
+ zval *zvalue;
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
- if (SUCCESS == zend_symtable_find(&obj->list->extras, name_str, name_len + 1, (void *) &zvalue)) {
- RETURN_ZVAL(*zvalue, 1, 0);
+ 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_FALSE;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
if (!value_str) {
- zend_symtable_del(&obj->list->extras, name_str, name_len + 1);
+ php_http_cookie_list_del_extra(obj->list, name_str, name_len);
} else {
- zval *zvalue;
-
- MAKE_STD_ZVAL(zvalue);
- ZVAL_STRINGL(zvalue, value_str, value_len, 1);
- zend_symtable_update(&obj->list->extras, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+ php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
}
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &name_str, &name_len, &value_str, &value_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zvalue;
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
- MAKE_STD_ZVAL(zvalue);
- ZVAL_STRINGL(zvalue, value_str, value_len, 1);
- zend_symtable_update(&obj->list->extras, name_str, name_len + 1, &zvalue, sizeof(zval *), NULL);
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
if (obj->list->domain) {
RETURN_STRING(obj->list->domain, 1);
}
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &domain_str, &domain_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
STR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
if (obj->list->path) {
RETURN_STRING(obj->list->path, 1);
}
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &path_str, &path_len)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
STR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
RETURN_LONG(obj->list->expires);
}
RETURN_FALSE;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
obj->list->expires = ts;
}
RETVAL_ZVAL(getThis(), 1, 0);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
RETURN_LONG(obj->list->flags);
}
RETURN_FALSE;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
obj->list->flags = flags;
}
RETVAL_ZVAL(getThis(), 1, 0);
char *str;
size_t len;
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
php_http_cookie_list_to_string(obj->list, &str, &len);
RETURN_STRINGL(str, len, 0);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->list) {
- obj->list = php_http_cookie_list_init(NULL TSRMLS_CC);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
array_init(return_value);
php_http_cookie_list_to_struct(obj->list, return_value);
}
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)
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);
+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)
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);
+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);
if (SUCCESS == zend_hash_find(&SG(known_post_content_types), key_str, key_len, (void *) &post_entry)) {
zval *files = PG(http_globals)[TRACK_VARS_FILES];
- zend_is_auto_global(ZEND_STRL("_POST") TSRMLS_CC);
-
if (post_entry) {
SG(request_info).post_entry = post_entry;
static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler)
{
if (SG(request_info).raw_post_data) {
+ zval_dtor(arg);
+ ((zval *) arg)->type = IS_NULL;
php_json_decode(arg, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1, PG(max_input_nesting_level) TSRMLS_CC);
}
}
return ZEND_HASH_APPLY_KEEP;
}
+#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); \
+ } \
+ } while(0)
+
PHP_METHOD(HttpEnvRequest, __construct)
{
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zval *zsg, *zqs;
obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC);
zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
zval_ptr_dtor(&zqs);
}
+ PHP_HTTP_ENV_REQUEST_OBJECT_INIT(obj);
} end_error_handling();
}
EMPTY_FUNCTION_ENTRY
};
+#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); \
+ } \
+ } while (0)
PHP_METHOD(HttpEnvResponse, __construct)
{
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- 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 = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters_none()) {
with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC);
} end_error_handling();
}
+ PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
} end_error_handling();
}
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);
+ PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
+
if (obj->body.handle || SUCCESS == php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), NULL TSRMLS_CC)) {
php_http_message_body_append(obj->message->body, ob_str, ob_len);
RETURN_TRUE;
return SUCCESS;
}
+#define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->message) { \
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); \
+ } \
+ } while(0)
+
+
void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC)
{
int i = 0;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
/* count */
php_http_message_count(i, obj->message);
msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
msg_obj->body = Z_OBJVAL_P(zbody);
+ if (tmp) {
+ FREE_ZVAL(tmp);
+ }
return SUCCESS;
}
php_http_message_object_prophandler_t *handler;
zval *return_value, *copy = php_http_ztyp(IS_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)) {
if (type == BP_VAR_R) {
ALLOC_ZVAL(return_value);
php_http_message_object_prophandler_t *handler;
zval *copy = php_http_ztyp(IS_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);
} else {
zval array, *parent, *body;
char *version;
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
INIT_PZVAL_ARRAY(&array, props);
#define ASSOC_PROP(array, ptype, name, val) \
}
}
}
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
} end_error_handling();
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
if (!obj->body.handle) {
php_http_message_body_addref(obj->message->body);
php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, NULL TSRMLS_CC);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_get_class_entry())) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC);
}
RETVAL_ZVAL(getThis(), 1, 0);
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);
+ 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);
}
RETVAL_ZVAL(getThis(), 1, 0);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zval *header;
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) {
RETURN_ZVAL(header, 1, 1);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
array_init(return_value);
array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value));
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!zvalue) {
zend_symtable_del(&obj->message->hdrs, name, name_len + 1);
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 (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
zend_hash_clean(&obj->message->hdrs);
if (new_headers) {
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
zval *header;
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
Z_ADDREF_P(zvalue);
if ((header = php_http_message_header(obj->message, name, name_len, 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 (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
RETURN_LONG(obj->message->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 (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_set_type(obj->message, type);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
&& php_http_info_parse(&inf, str TSRMLS_CC)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_set_info(obj->message, &inf);
php_http_info_dtor(&inf);
size_t len;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ 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_t version;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (php_http_version_parse(&version, v_str TSRMLS_CC)) {
obj->message->http.version = version;
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
RETURN_LONG(obj->message->http.info.response.code);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
if (strict && (code < 100 || code > 599)) {
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
if (obj->message->http.info.response.status) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
if (obj->message->http.info.request.method) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
if (method_len < 1) {
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
if (obj->message->http.info.request.url) {
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url_str, &url_len)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
if (url_len < 1) {
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (obj->message->parent) {
RETVAL_OBJVAL(obj->parent, 1);
char *string;
size_t length;
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (include_parent) {
php_http_message_serialize(obj->message, &string, &length);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_stream *s;
- php_stream_from_zval(s, &zstream);
-
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_stream_from_zval(s, &zstream);
php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
}
}
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);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
fcd.fcz = getThis();
Z_ADDREF_P(fcd.fcz);
TSRMLS_SET_CTX(fcd.ts);
char *string;
size_t length;
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_serialize(obj->message, &string, &length);
RETURN_STRINGL(string, length, 0);
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ 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);
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
if (!prepend_obj->message) {
prepend_obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
char *boundary = NULL;
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
RETVAL_BOOL(php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL));
if (zboundary && boundary) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
char *boundary = NULL;
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
if (php_http_message_is_multipart(obj->message, &boundary)) {
php_http_message_t *msg;
long i = 0;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_count(i, obj->message);
RETURN_LONG(i);
efree(obj);
}
+#define PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->body) { \
+ obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC); \
+ } \
+ } while(0)
+
PHP_METHOD(HttpMessageBody, __construct)
{
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
obj->body = php_http_message_body_init(NULL, stream TSRMLS_CC);
}
}
- if (!obj->body) {
- obj->body = php_http_message_body_init(NULL, NULL TSRMLS_CC);
- }
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
}
} end_error_handling();
}
char *str;
size_t len;
+ 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);
php_stream *stream;
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
php_stream_from_zval(stream, &zstream);
php_http_message_body_to_stream(obj->body, stream, offset, forlen);
RETURN_TRUE;
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);
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
fcd.fcz = getThis();
Z_ADDREF_P(fcd.fcz);
TSRMLS_SET_CTX(fcd.ts);
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_INIT(obj);
+
zend_list_addref(obj->body->stream_id);
RETVAL_RESOURCE(obj->body->stream_id);
}
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
RETURN_LONG(php_http_message_body_append(obj->body, str, len));
}
RETURN_FALSE;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h!h!", &fields, &files)) {
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
RETURN_SUCCESS(php_http_message_body_add_form(obj->body, fields, files));
}
RETURN_FALSE;
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_object_t *mobj = zend_object_store_get_object(zobj TSRMLS_CC);
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
php_http_message_body_add_part(obj->body, mobj->message);
RETURN_TRUE;
}
{
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- char *etag = php_http_message_body_etag(obj->body);
+ char *etag;
- if (etag) {
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+ if ((etag = php_http_message_body_etag(obj->body))) {
RETURN_STRING(etag, 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);
- const php_stream_statbuf *sb = php_http_message_body_stat(obj->body);
+ const php_stream_statbuf *sb;
+
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- if (sb) {
+ if ((sb = php_http_message_body_stat(obj->body))) {
if (field_str && field_len) {
switch (*field_str) {
case 's':
}
function testCurl() {
- $client = new http\Curl\Client;
+ $client = new http\Curl\Client(array("connecttimeout" => 10));
$client->setRequest(new http\Client\Request("GET", "https://twitter.com/"));
$share = new http\Curl\Client\DataShare;
$share->ssl = $share->dns = $share->cookie = true;