projects
/
m6w6
/
ext-http
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
since we use the curl write handler we can use curl's decoder
[m6w6/ext-http]
/
php_http_message.c
diff --git
a/php_http_message.c
b/php_http_message.c
index 3141065f8353466ff9edb9003a0400397daa2ed3..8a7e564a761990743270c2e7c736de49cc2471ce 100644
(file)
--- a/
php_http_message.c
+++ b/
php_http_message.c
@@
-69,7
+69,7
@@
php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_h
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
}
if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
}
if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
- message->http.info.request.url =
estrdup(Z_STRVAL_P(sval)
);
+ message->http.info.request.url =
php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), ~0 TSRMLS_CC
);
}
php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
}
php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
@@
-253,12
+253,12
@@
void php_http_message_set_type(php_http_message_t *message, php_http_message_typ
/* free request info */
switch (message->type) {
case PHP_HTTP_REQUEST:
/* free request info */
switch (message->type) {
case PHP_HTTP_REQUEST:
-
S
TR_FREE(message->http.info.request.method);
-
S
TR_FREE(message->http.info.request.url);
+
P
TR_FREE(message->http.info.request.method);
+
P
TR_FREE(message->http.info.request.url);
break;
case PHP_HTTP_RESPONSE:
break;
case PHP_HTTP_RESPONSE:
-
S
TR_FREE(message->http.info.response.status);
+
P
TR_FREE(message->http.info.response.status);
break;
default:
break;
default:
@@
-276,13
+276,13
@@
void php_http_message_set_info(php_http_message_t *message, php_http_info_t *inf
message->http.version = info->http.version;
switch (message->type) {
case PHP_HTTP_REQUEST:
message->http.version = info->http.version;
switch (message->type) {
case PHP_HTTP_REQUEST:
-
STR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? estrdup(PHP_HTTP_INFO(info).request.url
) : NULL);
-
S
TR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
+
PTR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? php_http_url_copy(PHP_HTTP_INFO(info).request.url, 0
) : NULL);
+
P
TR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
break;
case PHP_HTTP_RESPONSE:
PHP_HTTP_INFO(message).response.code = PHP_HTTP_INFO(info).response.code;
break;
case PHP_HTTP_RESPONSE:
PHP_HTTP_INFO(message).response.code = PHP_HTTP_INFO(info).response.code;
-
S
TR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
+
P
TR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
break;
default:
break;
default:
@@
-332,15
+332,18
@@
void php_http_message_update_headers(php_http_message_t *msg)
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
{
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
{
+ char *tmp = NULL;
TSRMLS_FETCH_FROM_CTX(msg->ts);
switch (msg->type) {
case PHP_HTTP_REQUEST:
TSRMLS_FETCH_FROM_CTX(msg->ts);
switch (msg->type) {
case PHP_HTTP_REQUEST:
- php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
+ php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
+ PTR_FREE(tmp);
break;
case PHP_HTTP_RESPONSE:
break;
case PHP_HTTP_RESPONSE:
- php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
+ php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
+ PTR_FREE(tmp);
break;
default:
break;
default:
@@
-496,12
+499,12
@@
void php_http_message_dtor(php_http_message_t *message)
switch (message->type) {
case PHP_HTTP_REQUEST:
switch (message->type) {
case PHP_HTTP_REQUEST:
-
S
TR_SET(message->http.info.request.method, NULL);
-
S
TR_SET(message->http.info.request.url, NULL);
+
P
TR_SET(message->http.info.request.method, NULL);
+
P
TR_SET(message->http.info.request.url, NULL);
break;
case PHP_HTTP_RESPONSE:
break;
case PHP_HTTP_RESPONSE:
-
S
TR_SET(message->http.info.response.status, NULL);
+
P
TR_SET(message->http.info.response.status, NULL);
break;
default:
break;
default:
@@
-561,22
+564,23
@@
static void php_http_message_object_prophandler_get_request_method(php_http_mess
static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
zval *cpy = php_http_ztyp(IS_STRING, value);
static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
zval *cpy = php_http_ztyp(IS_STRING, value);
-
S
TR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
+
P
TR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
zval_ptr_dtor(&cpy);
}
}
static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
zval_ptr_dtor(&cpy);
}
}
static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
- if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url) {
- RETVAL_STRING(obj->message->http.info.request.url, 1);
+ char *url_str;
+ size_t url_len;
+
+ if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url && php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0)) {
+ RETVAL_STRINGL(url_str, url_len, 0);
} else {
RETVAL_NULL();
}
}
static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
} else {
RETVAL_NULL();
}
}
static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- STR_SET(obj->message->http.info.request.url, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0 TSRMLS_CC));
}
}
static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
}
}
static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
@@
-589,7
+593,7
@@
static void php_http_message_object_prophandler_get_response_status(php_http_mes
static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
zval *cpy = php_http_ztyp(IS_STRING, value);
static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
zval *cpy = php_http_ztyp(IS_STRING, value);
-
S
TR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
+
P
TR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
zval_ptr_dtor(&cpy);
}
}
zval_ptr_dtor(&cpy);
}
}
@@
-604,7
+608,7
@@
static void php_http_message_object_prophandler_set_response_code(php_http_messa
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
zval *cpy = php_http_ztyp(IS_LONG, value);
obj->message->http.info.response.code = Z_LVAL_P(cpy);
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
zval *cpy = php_http_ztyp(IS_LONG, value);
obj->message->http.info.response.code = Z_LVAL_P(cpy);
-
S
TR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
+
P
TR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
zval_ptr_dtor(&cpy);
}
}
zval_ptr_dtor(&cpy);
}
}
@@
-939,8
+943,8
@@
static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC)
php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC);
zval array, *parent, *body;
php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC);
zval array, *parent, *body;
- char *ver
sion
;
-
int verlen
;
+ char *ver
_str, *url_str = NULL
;
+
size_t ver_len, url_len = 0
;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
INIT_PZVAL_ARRAY(&array, props);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
INIT_PZVAL_ARRAY(&array, props);
@@
-964,15
+968,21
@@
static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC)
} while(0)
ASSOC_PROP(long, "type", obj->message->type);
} while(0)
ASSOC_PROP(long, "type", obj->message->type);
- ver
len = spprintf(&version
, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor);
- ASSOC_STRINGL_EX("httpVersion", ver
sion, ver
len, 0);
+ ver
_len = spprintf(&ver_str
, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor);
+ ASSOC_STRINGL_EX("httpVersion", ver
_str, ver_
len, 0);
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
ASSOC_PROP(long, "responseCode", 0);
ASSOC_STRINGL("responseStatus", "", 0);
ASSOC_STRING("requestMethod", STR_PTR(obj->message->http.info.request.method));
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
ASSOC_PROP(long, "responseCode", 0);
ASSOC_STRINGL("responseStatus", "", 0);
ASSOC_STRING("requestMethod", STR_PTR(obj->message->http.info.request.method));
- ASSOC_STRING("requestUrl", STR_PTR(obj->message->http.info.request.url));
+ if (obj->message->http.info.request.url) {
+ php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
+ ASSOC_STRINGL_EX("requestUrl", url_str, url_len, 0);
+ } else {
+ ASSOC_STRINGL("requestUrl", "", 0);
+ }
+
break;
case PHP_HTTP_RESPONSE:
break;
case PHP_HTTP_RESPONSE:
@@
-1041,13
+1051,15
@@
static PHP_METHOD(HttpMessage, __construct)
if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
+ php_http_buffer_t buf;
- if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, s, flags, &msg)) {
+ php_http_buffer_init_ex(&buf, 0x1000, PHP_HTTP_BUFFER_INIT_PREALLOC);
+ if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, &buf, s, flags, &msg)) {
if (!EG(exception)) {
php_http_throw(bad_message, "Could not parse message from stream", NULL);
}
}
if (!EG(exception)) {
php_http_throw(bad_message, "Could not parse message from stream", NULL);
}
}
-
+ php_http_buffer_dtor(&buf);
php_http_message_parser_dtor(&p);
}
php_http_message_parser_dtor(&p);
}
@@
-1318,16
+1330,19
@@
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, getInfo)
{
if (SUCCESS == zend_parse_parameters_none()) {
static PHP_METHOD(HttpMessage, getInfo)
{
if (SUCCESS == zend_parse_parameters_none()) {
+ char *tmp = NULL;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
switch (obj->message->type) {
case PHP_HTTP_REQUEST:
- Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, ""));
+ Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, ""));
+ PTR_FREE(tmp);
break;
case PHP_HTTP_RESPONSE:
break;
case PHP_HTTP_RESPONSE:
- Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, ""));
+ Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
+ PTR_FREE(tmp);
break;
default:
RETURN_NULL();
break;
default:
RETURN_NULL();
@@
-1447,7
+1462,7
@@
static PHP_METHOD(HttpMessage, setResponseCode)
}
obj->message->http.info.response.code = code;
}
obj->message->http.info.response.code = code;
-
S
TR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+
P
TR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
RETVAL_ZVAL(getThis(), 1, 0);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
@@
-1492,7
+1507,7
@@
static PHP_METHOD(HttpMessage, setResponseStatus)
php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
}
php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
}
-
S
TR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
+
P
TR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
@@
-1543,7
+1558,7
@@
static PHP_METHOD(HttpMessage, setRequestMethod)
return;
}
return;
}
-
S
TR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+
P
TR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
@@
-1562,7
+1577,11
@@
static PHP_METHOD(HttpMessage, getRequestUrl)
}
if (obj->message->http.info.request.url) {
}
if (obj->message->http.info.request.url) {
- RETURN_STRING(obj->message->http.info.request.url, 1);
+ char *url_str;
+ size_t url_len;
+
+ php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
+ RETURN_STRINGL(url_str, url_len, 0);
} else {
RETURN_EMPTY_STRING();
}
} else {
RETURN_EMPTY_STRING();
}
@@
-1574,11
+1593,12
@@
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestUrl, 0, 0, 1)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, setRequestUrl)
{
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, setRequestUrl)
{
-
char *url_str
;
-
int url_len
;
+
zval *zurl
;
+
php_http_url_t *url
;
php_http_message_object_t *obj;
php_http_message_object_t *obj;
+ zend_error_handling zeh;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "
s", &url_str, &url_len
), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "
z", &zurl
), invalid_arg, return);
obj = zend_object_store_get_object(getThis() TSRMLS_CC);
obj = zend_object_store_get_object(getThis() TSRMLS_CC);
@@
-1589,12
+1609,17
@@
static PHP_METHOD(HttpMessage, setRequestUrl)
return;
}
return;
}
- if (url_len < 1) {
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
+ url = php_http_url_from_zval(zurl, ~0 TSRMLS_CC);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (php_http_url_is_empty(url)) {
+ php_http_url_free(&url);
php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
- return;
+ } else {
+ PTR_SET(obj->message->http.info.request.url, url);
}
}
- STR_SET(obj->message->http.info.request.url, estrndup(url_str, url_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
@@
-1829,7
+1854,7
@@
static PHP_METHOD(HttpMessage, splitMultipartBody)
php_http_expect(msg = php_http_message_body_split(obj->message->body, boundary), bad_message, return);
php_http_expect(msg = php_http_message_body_split(obj->message->body, boundary), bad_message, return);
-
S
TR_FREE(boundary);
+
P
TR_FREE(boundary);
RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
}
RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
}