X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_functions.c;h=869442d38238d458a9597b2a6f84d6adeea84356;hp=33c1e4a34a3a856826ae94ae6fe3cab0b721d1fe;hb=76d11ef7477a1caf622ac9823da6b2b098c9b86c;hpb=2655b1c8838edb32ef8ac67376f123e8d613a9af diff --git a/http_functions.c b/http_functions.c index 33c1e4a..869442d 100644 --- a/http_functions.c +++ b/http_functions.c @@ -62,6 +62,10 @@ PHP_FUNCTION(http_date) } /* }}} */ +#if PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION < 10 +# define php_url_parse_ex(u, l) php_url_parse(u) +#endif + /* {{{ proto string http_build_url([mixed url[, mixed parts[, int flags = HTTP_URL_REPLACE[, array &new_url]]]]) * * Build an URL. @@ -820,14 +824,14 @@ PHP_FUNCTION(http_redirect) */ PHP_FUNCTION(http_send_data) { - zval *zdata; + int data_len; + char *data_buf; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_buf, &data_len) != SUCCESS) { RETURN_FALSE; } - convert_to_string_ex(&zdata); - RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata))); + RETURN_SUCCESS(http_send_data(data_buf, data_len)); } /* }}} */ @@ -1059,7 +1063,7 @@ PHP_FUNCTION(http_parse_cookie) HashPosition pos; http_cookie_list list; - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la", &cookie, &cookie_len, &flags, &allowed_extras_array)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la!", &cookie, &cookie_len, &flags, &allowed_extras_array)) { RETURN_FALSE; } @@ -1068,7 +1072,7 @@ PHP_FUNCTION(http_parse_cookie) FOREACH_VAL(pos, allowed_extras_array, entry) { ZVAL_ADDREF(*entry); convert_to_string_ex(entry); - allowed_extras[i] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); + allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); zval_ptr_dtor(entry); } } @@ -1088,6 +1092,30 @@ PHP_FUNCTION(http_parse_cookie) efree(allowed_extras); } } +/* }}} */ + +/* {{{ proto string http_build_cookie(array cookie) + * + * Build a cookie string from an array/object like returned by http_parse_cookie(). + */ +PHP_FUNCTION(http_build_cookie) +{ + char *str = NULL; + size_t len = 0; + zval *strct; + http_cookie_list list; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &strct)) { + RETURN_FALSE; + } + + http_cookie_list_fromstruct(&list, strct); + http_cookie_list_tostring(&list, &str, &len); + http_cookie_list_dtor(&list); + + RETURN_STRINGL(str, len, 0); +} +/* }}} */ /* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT]) * @@ -1127,7 +1155,7 @@ PHP_FUNCTION(http_get_request_headers) NO_ARGS; array_init(return_value); - http_get_request_headers(return_value); + http_get_request_headers(Z_ARRVAL_P(return_value)); } /* }}} */ @@ -1452,17 +1480,17 @@ PHP_FUNCTION(http_post_data) */ PHP_FUNCTION(http_post_fields) { - zval *options = NULL, *info = NULL, *fields, *files = NULL; + zval *options = NULL, *info = NULL, *fields = NULL, *files = NULL; char *URL; int URL_len; http_request_body body; http_request request; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|aa/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa!|a!a/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) { RETURN_FALSE; } - if (!http_request_body_fill(&body, Z_ARRVAL_P(fields), files ? Z_ARRVAL_P(files) : NULL)) { + if (!http_request_body_fill(&body, fields ? Z_ARRVAL_P(fields) : NULL, files ? Z_ARRVAL_P(files) : NULL)) { RETURN_FALSE; }