X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_object.c;h=b40ef8992457e8a9833cf8e23c6324676aa4682c;hp=207ec6c3da02fd4923196b263cead20f22b3824b;hb=5b440d6af3dd3052dde7b137f975692f0aa84603;hpb=5e06e2629f8cbe71bc2985bf7ca4f149bb08d482 diff --git a/http_request_object.c b/http_request_object.c index 207ec6c..b40ef89 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -72,6 +72,13 @@ HTTP_BEGIN_ARGS(addCookies, 1) HTTP_ARG_VAL(cookies, 0) HTTP_END_ARGS; +HTTP_EMPTY_ARGS(enableCookies); +#if HTTP_CURL_VERSION(7,14,1) +HTTP_BEGIN_ARGS(resetCookies, 0) + HTTP_ARG_VAL(session_only, 0) +HTTP_END_ARGS; +#endif + HTTP_EMPTY_ARGS(getUrl); HTTP_BEGIN_ARGS(setUrl, 1) HTTP_ARG_VAL(url, 0) @@ -227,10 +234,12 @@ HTTP_BEGIN_ARGS(methodExists, 1) HTTP_ARG_VAL(method, 0) HTTP_END_ARGS; +#ifdef HAVE_CURL_GETFORMDATA HTTP_BEGIN_ARGS(encodeBody, 2) HTTP_ARG_VAL(fields, 0) HTTP_ARG_VAL(files, 0) HTTP_END_ARGS; +#endif #define OBJ_PROP_CE http_request_object_ce zend_class_entry *http_request_object_ce; @@ -251,6 +260,11 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC) + HTTP_REQUEST_ME(enableCookies, ZEND_ACC_PUBLIC) +#if HTTP_CURL_VERSION(7,14,1) + HTTP_REQUEST_ME(resetCookies, ZEND_ACC_PUBLIC) +#endif + HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC) @@ -311,9 +325,9 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister) HTTP_REQUEST_ALIAS(methodName, http_request_method_name) HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists) - +#ifdef HAVE_CURL_GETFORMDATA HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode) - +#endif EMPTY_FUNCTION_ENTRY }; static zend_object_handlers http_request_object_handlers; @@ -435,18 +449,16 @@ zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, ht zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC) { - zend_object *old_zo; zend_object_value new_ov; http_request_object *new_obj; getObject(http_request_object, old_obj); - old_zo = zend_objects_get_address(this_ptr TSRMLS_CC); - new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj); + new_ov = http_request_object_new_ex(old_obj->zo.ce, NULL, &new_obj); if (old_obj->request->ch) { http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request); } - zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used); phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used); @@ -457,12 +469,8 @@ void _http_request_object_free(zend_object *object TSRMLS_DC) { http_request_object *o = (http_request_object *) object; - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } http_request_free(&o->request); - efree(o); + freeObject(o); } #define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC) @@ -524,7 +532,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ { case HTTP_GET: case HTTP_HEAD: - break; + break; case HTTP_PUT: { @@ -544,8 +552,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ status = FAILURE; } } + break; } - break; case HTTP_POST: default: @@ -571,8 +579,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ } } } + break; } - break; } if (status == SUCCESS) { @@ -772,7 +780,7 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { zval *opts, **options; opts = GET_PROP(options); @@ -868,6 +876,16 @@ PHP_METHOD(HttpRequest, setOptions) zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt); } else if (!strcmp(key, "method")) { zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt); +#if HTTP_CURL_VERSION(7,14,1) + } else if (!strcmp(key, "resetcookies")) { + getObject(http_request_object, obj); + http_request_reset_cookies(obj->request, 0); +#endif + } else if (!strcmp(key, "enablecookies")) { + getObject(http_request_object, obj); + http_request_enable_cookies(obj->request); + } else if (!strcasecmp(key, "recordHistory")) { + UPD_PROP(bool, recordHistory, 1); } else { ZVAL_ADDREF(*opt); add_assoc_zval(add_opts, key, *opt); @@ -900,7 +918,7 @@ PHP_METHOD(HttpRequest, getOptions) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(options); } } @@ -1030,6 +1048,44 @@ PHP_METHOD(HttpRequest, getCookies) } /* }}} */ +/* {{{ proto bool HttpRequest::enableCookies() + * + * Enable automatic sending of received cookies. + * Note that cuutomly set cookies will be sent anyway. + */ +PHP_METHOD(HttpRequest, enableCookies) +{ + NO_ARGS { + getObject(http_request_object, obj); + RETURN_SUCCESS(http_request_enable_cookies(obj->request)); + } + +} +/* }}} */ + +/* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE]) + * + * Reset all automatically received/sent cookies. + * Note that customly set cookies are not affected. + * + * Accepts an optional bool parameter specifying + * whether only session cookies should be reset + * (needs libcurl >= v7.15.4, else libcurl >= v7.14.1). + * + * Returns TRUE on success, or FALSE on failure. + */ +PHP_METHOD(HttpRequest, resetCookies) +{ + zend_bool session_only = 0; + getObject(http_request_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &session_only)) { + RETURN_FALSE; + } + RETURN_SUCCESS(http_request_reset_cookies(obj->request, session_only)); +} +/* }}} */ + /* {{{ proto bool HttpRequest::setUrl(string url) * * Set the request URL. @@ -1062,7 +1118,7 @@ PHP_METHOD(HttpRequest, getUrl) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(url); } } @@ -1100,7 +1156,7 @@ PHP_METHOD(HttpRequest, getMethod) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(method); } } @@ -1143,7 +1199,7 @@ PHP_METHOD(HttpRequest, getContentType) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(contentType); } } @@ -1202,7 +1258,7 @@ PHP_METHOD(HttpRequest, getQueryData) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(queryData); } } @@ -1314,7 +1370,7 @@ PHP_METHOD(HttpRequest, getPostFields) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(postFields); } } @@ -1394,7 +1450,7 @@ PHP_METHOD(HttpRequest, getRawPostData) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(rawPostData); } } @@ -1492,7 +1548,7 @@ PHP_METHOD(HttpRequest, getPostFiles) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(postFiles); } } @@ -1531,7 +1587,7 @@ PHP_METHOD(HttpRequest, getPutFile) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(putFile); } } @@ -1611,7 +1667,7 @@ PHP_METHOD(HttpRequest, getPutData) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(putData); } } @@ -1632,7 +1688,7 @@ PHP_METHOD(HttpRequest, getResponseData) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(responseData); } } @@ -1653,7 +1709,7 @@ PHP_METHOD(HttpRequest, getResponseData) */ PHP_METHOD(HttpRequest, getResponseHeader) { - IF_RETVAL_USED { + if (return_value_used) { zval *data, **headers, **header; char *header_name = NULL; int header_len = 0; @@ -1691,7 +1747,7 @@ PHP_METHOD(HttpRequest, getResponseHeader) */ PHP_METHOD(HttpRequest, getResponseCookies) { - IF_RETVAL_USED { + if (return_value_used) { long flags = 0; zval *allowed_extras_array = NULL, *data, **headers; @@ -1787,7 +1843,7 @@ PHP_METHOD(HttpRequest, getResponseBody) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { zval **body; zval *data = GET_PROP(responseData); @@ -1814,7 +1870,7 @@ PHP_METHOD(HttpRequest, getResponseCode) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(responseCode); } } @@ -1830,7 +1886,7 @@ PHP_METHOD(HttpRequest, getResponseStatus) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { RETURN_PROP(responseStatus); } } @@ -1854,7 +1910,7 @@ PHP_METHOD(HttpRequest, getResponseStatus) */ PHP_METHOD(HttpRequest, getResponseInfo) { - IF_RETVAL_USED { + if (return_value_used) { zval *info, **infop; char *info_name = NULL; int info_len = 0; @@ -1935,7 +1991,7 @@ PHP_METHOD(HttpRequest, getRequestMessage) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { http_message *msg; getObject(http_request_object, obj); @@ -1958,7 +2014,7 @@ PHP_METHOD(HttpRequest, getRawRequestMessage) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { getObject(http_request_object, obj); RETURN_PHPSTR_DUP(&obj->request->conv.request); @@ -1976,7 +2032,7 @@ PHP_METHOD(HttpRequest, getRawResponseMessage) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { getObject(http_request_object, obj); RETURN_PHPSTR_DUP(&obj->request->conv.response); @@ -2003,7 +2059,7 @@ PHP_METHOD(HttpRequest, getHistory) { NO_ARGS; - IF_RETVAL_USED { + if (return_value_used) { zval *hist; SET_EH_THROW_HTTP();