http_request_reset(obj->request);
HTTP_CHECK_CURL_INIT(obj->request->ch, curl_easy_init(), return FAILURE);
- obj->request->url = http_absolute_url(Z_STRVAL_P(GET_PROP(obj, url)));
+ obj->request->url = http_absolute_url(Z_STRVAL_P(GET_PROP(url)));
- switch (obj->request->meth = Z_LVAL_P(GET_PROP(obj, method)))
+ switch (obj->request->meth = Z_LVAL_P(GET_PROP(method)))
{
case HTTP_GET:
case HTTP_HEAD:
case HTTP_PUT:
{
php_stream_statbuf ssb;
- php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
+ php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
if (stream && !php_stream_stat(stream, &ssb)) {
obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
default:
{
/* check for raw post data */
- zval *raw_data = GET_PROP(obj, rawPostData);
+ zval *raw_data = GET_PROP(rawPostData);
if (Z_STRLEN_P(raw_data)) {
- zval *ctype = GET_PROP(obj, contentType);
+ zval *ctype = GET_PROP(contentType);
if (Z_STRLEN_P(ctype)) {
- zval **headers, *opts = GET_PROP(obj, options);
+ zval **headers, *opts = GET_PROP(options);
if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
(SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) &&
estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1);
} else {
- zval *zfields = GET_PROP(obj, postFields), *zfiles = GET_PROP(obj, postFiles);
+ zval *zfields = GET_PROP(postFields), *zfiles = GET_PROP(postFiles);
HashTable *fields;
HashTable *files;
}
if (status == SUCCESS) {
- zval *qdata = GET_PROP(obj, queryData);
- zval *options = GET_PROP(obj, options);
+ zval *qdata = GET_PROP(queryData);
+ zval *options = GET_PROP(options);
if (Z_STRLEN_P(qdata)) {
if (!strchr(obj->request->url, '?')) {
size_t body_len;
zval *headers, *message, *resp, *info;
- if (zval_is_true(GET_PROP(obj, recordHistory))) {
+ if (zval_is_true(GET_PROP(recordHistory))) {
/* we need to act like a zipper, as we'll receive
* the requests and the responses in separate chains
* for redirects
phpstr_fix(&obj->history);
}
- UPD_PROP(obj, long, responseCode, msg->http.info.response.code);
+ UPD_PROP(long, responseCode, msg->http.info.response.code);
MAKE_STD_ZVAL(resp);
array_init(resp);
add_assoc_zval(resp, "headers", headers);
phpstr_data(PHPSTR(msg), &body, &body_len);
add_assoc_stringl(resp, "body", body, body_len, 0);
- SET_PROP(obj, responseData, resp);
+ SET_PROP(responseData, resp);
zval_ptr_dtor(&resp);
MAKE_STD_ZVAL(message);
ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL));
- SET_PROP(obj, responseMessage, message);
+ SET_PROP(responseMessage, message);
zval_ptr_dtor(&message);
MAKE_STD_ZVAL(info);
array_init(info);
http_request_info(obj->request, Z_ARRVAL_P(info));
- SET_PROP(obj, responseInfo, info);
+ SET_PROP(responseInfo, info);
zval_ptr_dtor(&info);
return SUCCESS;
MAKE_STD_ZVAL(new_opts);
array_init(new_opts);
- old_opts = GET_PROP(obj, options);
+ old_opts = GET_PROP(options);
if (Z_TYPE_P(old_opts) == IS_ARRAY) {
array_copy(old_opts, new_opts);
}
ZVAL_ADDREF(opts);
add_assoc_zval(new_opts, key, opts);
}
- SET_PROP(obj, options, new_opts);
+ SET_PROP(options, new_opts);
zval_ptr_dtor(&new_opts);
RETURN_TRUE;
zval *opts, **options;
getObject(http_request_object, obj);
- opts = GET_PROP(obj, options);
+ opts = GET_PROP(options);
array_init(return_value);
SET_EH_THROW_HTTP();
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla", &URL, &URL_len, &meth, &options)) {
if (URL) {
- UPD_STRL(obj, url, URL, URL_len);
+ UPD_STRL(url, URL, URL_len);
}
if (meth > -1) {
- UPD_PROP(obj, long, method, meth);
+ UPD_PROP(long, method, meth);
}
if (options) {
zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
array_init(new_opts);
if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
- SET_PROP(obj, options, new_opts);
+ SET_PROP(options, new_opts);
zval_ptr_dtor(&new_opts);
RETURN_TRUE;
}
}
}
- old_opts = GET_PROP(obj, options);
+ old_opts = GET_PROP(options);
if (Z_TYPE_P(old_opts) == IS_ARRAY) {
array_copy(old_opts, new_opts);
}
array_merge(add_opts, new_opts);
- SET_PROP(obj, options, new_opts);
+ SET_PROP(options, new_opts);
zval_ptr_dtor(&new_opts);
zval_ptr_dtor(&add_opts);
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *options = GET_PROP(obj, options);
-
- RETURN_ZVAL(options, 1, 0);
+ RETURN_PROP(options);
}
}
/* }}} */
RETURN_FALSE;
}
- UPD_STRL(obj, url, URL, URL_len);
+ UPD_STRL(url, URL, URL_len);
RETURN_TRUE;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *url = GET_PROP(obj, url);
-
- RETURN_ZVAL(url, 1, 0);
+ RETURN_PROP(url);
}
}
/* }}} */
RETURN_FALSE;
}
- UPD_PROP(obj, long, method, meth);
+ UPD_PROP(long, method, meth);
RETURN_TRUE;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *method = GET_PROP(obj, method);
-
- RETURN_ZVAL(method, 1, 0);
+ RETURN_PROP(method);
}
}
/* }}} */
}
HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
- UPD_STRL(obj, contentType, ctype, ct_len);
+ UPD_STRL(contentType, ctype, ct_len);
RETURN_TRUE;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *ctype = GET_PROP(obj, contentType);
-
- RETURN_ZVAL(ctype, 1, 0);
+ RETURN_PROP(contentType);
}
}
/* }}} */
}
if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
- UPD_STRL(obj, queryData, "", 0);
+ UPD_STRL(queryData, "", 0);
} else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
char *query_data = NULL;
RETURN_FALSE;
}
- UPD_PROP(obj, string, queryData, query_data);
+ UPD_PROP(string, queryData, query_data);
efree(query_data);
} else {
zval *orig = qdata;
convert_to_string_ex(&qdata);
- UPD_STRL(obj, queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata));
+ UPD_STRL(queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata));
if (orig != qdata) {
zval_ptr_dtor(&qdata);
}
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *qdata = GET_PROP(obj, queryData);
-
- RETURN_ZVAL(qdata, 1, 0);
+ RETURN_PROP(queryData);
}
}
/* }}} */
RETURN_FALSE;
}
- old_qdata = GET_PROP(obj, queryData);
+ old_qdata = GET_PROP(queryData);
if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) {
RETURN_FALSE;
}
- UPD_STRL(obj, queryData, query_data, query_data_len);
+ UPD_STRL(queryData, query_data, query_data_len);
efree(query_data);
RETURN_TRUE;
if (zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
MAKE_STD_ZVAL(new_post);
array_init(new_post);
- old_post = GET_PROP(obj, postFields);
+ old_post = GET_PROP(postFields);
if (Z_TYPE_P(old_post) == IS_ARRAY) {
array_copy(old_post, new_post);
}
array_merge(post_data, new_post);
- SET_PROP(obj, postFields, new_post);
+ SET_PROP(postFields, new_post);
zval_ptr_dtor(&new_post);
}
if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
array_copy(post_data, post);
}
- SET_PROP(obj, postFields, post);
+ SET_PROP(postFields, post);
zval_ptr_dtor(&post);
RETURN_TRUE;
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *post = GET_PROP(obj, postFields);
-
- RETURN_ZVAL(post, 1, 0);
+ RETURN_PROP(postFields);
}
}
/* }}} */
raw_data = "";
}
- UPD_STRL(obj, rawPostData, raw_data, data_len);
+ UPD_STRL(rawPostData, raw_data, data_len);
RETURN_TRUE;
}
/* }}} */
}
if (data_len) {
- zval *data = zval_copy(IS_STRING, GET_PROP(obj, rawPostData));
+ zval *data = zval_copy(IS_STRING, GET_PROP(rawPostData));
Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len);
- SET_PROP(obj, rawPostData, data);
+ SET_PROP(rawPostData, data);
zval_free(&data);
}
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *post = GET_PROP(obj, rawPostData);
-
- RETURN_ZVAL(post, 1, 0);
+ RETURN_PROP(rawPostData);
}
}
/* }}} */
MAKE_STD_ZVAL(new_post);
array_init(new_post);
- old_post = GET_PROP(obj, postFiles);
+ old_post = GET_PROP(postFiles);
if (Z_TYPE_P(old_post) == IS_ARRAY) {
array_copy(old_post, new_post);
}
add_next_index_zval(new_post, entry);
- SET_PROP(obj, postFiles, new_post);
+ SET_PROP(postFiles, new_post);
zval_ptr_dtor(&new_post);
RETURN_TRUE;
if (files && (Z_TYPE_P(files) == IS_ARRAY)) {
array_copy(files, post);
}
- SET_PROP(obj, postFiles, post);
+ SET_PROP(postFiles, post);
zval_ptr_dtor(&post);
RETURN_TRUE;
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *files = GET_PROP(obj, postFiles);
-
- RETURN_ZVAL(files, 1, 0);
+ RETURN_PROP(postFiles);
}
}
/* }}} */
RETURN_FALSE;
}
- UPD_STRL(obj, putFile, file, file_len);
+ UPD_STRL(putFile, file, file_len);
RETURN_TRUE;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *file = GET_PROP(obj, putFile);
-
- RETVAL_ZVAL(file, 1, 0);
+ RETURN_PROP(putFile);
}
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *data = GET_PROP(obj, responseData);
-
- RETURN_ZVAL(data, 1, 0);
+ RETURN_PROP(responseData);
}
}
/* }}} */
RETURN_FALSE;
}
- data = GET_PROP(obj, responseData);
+ data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
(SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
(Z_TYPE_PP(headers) == IS_ARRAY)) {
array_init(return_value);
- data = GET_PROP(obj, responseData);
+ data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
(SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) &&
(Z_TYPE_PP(headers) == IS_ARRAY)) {
IF_RETVAL_USED {
zval **body;
getObject(http_request_object, obj);
- zval *data = GET_PROP(obj, responseData);
+ zval *data = GET_PROP(responseData);
if ( (Z_TYPE_P(data) == IS_ARRAY) &&
(SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body))) {
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *code = GET_PROP(obj, responseCode);
-
- RETVAL_ZVAL(code, 1, 0);
+ RETURN_PROP(responseCode);
}
}
/* }}} */
RETURN_FALSE;
}
- info = GET_PROP(obj, responseInfo);
+ info = GET_PROP(responseInfo);
if (Z_TYPE_P(info) != IS_ARRAY) {
RETURN_FALSE;
getObject(http_request_object, obj);
SET_EH_THROW_HTTP();
- message = GET_PROP(obj, responseMessage);
+ message = GET_PROP(responseMessage);
if (Z_TYPE_P(message) == IS_OBJECT) {
RETVAL_OBJECT(message);
} else {
} else if (SUCCESS == http_request_object_requesthandler(obj, getThis())) {
http_request_exec(obj->request);
if (SUCCESS == http_request_object_responsehandler(obj, getThis())) {
- RETVAL_OBJECT(GET_PROP(obj, responseMessage));
+ RETVAL_OBJECT(GET_PROP(responseMessage));
}
}
#define ZVAL_OBJVAL(zv, ov) \
(zv)->type = IS_OBJECT; \
(zv)->value.obj = (ov);
-
+/* return property */
+#define RETVAL_PROP(n) RETVAL_PROP_EX(getThis(), n)
+#define RETURN_PROP(n) RETURN_PROP_EX(getThis(), n)
+#define RETVAL_PROP_EX(this, n) \
+ { \
+ zval *__prop = GET_PROP_EX(this, n); \
+ RETVAL_ZVAL(__prop, 1, 0); \
+ }
+#define RETURN_PROP_EX(this, n) \
+ { \
+ zval *__prop = GET_PROP_EX(this, n); \
+ RETURN_ZVAL(__prop, 1, 0); \
+ }
+
/* function accepts no args */
#define NO_ARGS \
if (ZEND_NUM_ARGS()) { \
# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n)-1, (v), (ZEND_ACC_ ##a) TSRMLS_CC)
# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n)-1, (ZEND_ACC_ ##a) TSRMLS_CC)
-# define UPD_PROP(o, t, n, v) UPD_PROP_EX(o, getThis(), t, n, v)
-# define UPD_PROP_EX(o, this, t, n, v) zend_update_property_ ##t(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
-# define UPD_STRL(o, n, v, l) zend_update_property_stringl(OBJ_PROP_CE, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC)
-# define SET_PROP(o, n, z) SET_PROP_EX(o, getThis(), n, z)
-# define SET_PROP_EX(o, this, n, z) zend_update_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
-# define GET_PROP(o, n) GET_PROP_EX(o, getThis(), n)
-# define GET_PROP_EX(o, this, n) zend_read_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
+# define UPD_PROP(t, n, v) UPD_PROP_EX(getThis(), t, n, v)
+# define UPD_PROP_EX(this, t, n, v) zend_update_property_ ##t(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (v) TSRMLS_CC)
+# define UPD_STRL(n, v, l) zend_update_property_stringl(OBJ_PROP_CE, getThis(), (#n), sizeof(#n)-1, (v), (l) TSRMLS_CC)
+# define SET_PROP(n, z) SET_PROP_EX(getThis(), n, z)
+# define SET_PROP_EX(this, n, z) zend_update_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, (z) TSRMLS_CC)
+# define GET_PROP(n) GET_PROP_EX(getThis(), n)
+# define GET_PROP_EX(this, n) zend_read_property(OBJ_PROP_CE, this, (#n), sizeof(#n)-1, 0 TSRMLS_CC)
# define DCL_CONST(t, n, v) zend_declare_class_constant_ ##t(ce, (n), sizeof(n)-1, (v) TSRMLS_CC)