Skip to content

Commit bdaf5a0

Browse files
committed
Enabled http parser again
1 parent 39a7fe3 commit bdaf5a0

File tree

6 files changed

+59
-47
lines changed

6 files changed

+59
-47
lines changed

config.m4

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if test $PHP_UV != "no"; then
4444
SOURCES=""
4545

4646
if test $PHP_HTTPPARSER != "no"; then
47-
SOURCES=" http-parser/http_parser.c"
47+
SOURCES=" uv_http_parser.c http-parser/http_parser.c"
4848
AC_DEFINE([ENABLE_HTTPPARSER], [1], [ Enable http parser])
4949
fi
5050

@@ -81,15 +81,4 @@ if test $PHP_UV != "no"; then
8181
])
8282

8383
PHP_SUBST(UV_SHARED_LIBADD)
84-
85-
# CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement"
86-
87-
# case $host in
88-
# *darwin*)
89-
# ;;
90-
# *linux*)
91-
# CFLAGS="$CFLAGS -lrt"
92-
# esac
93-
94-
# PHP_SUBST([CFLAGS])
9584
fi

php_uv.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ static int uv_lock_handle;
232232

233233
static int uv_stdio_handle;
234234

235-
236235
char *php_uv_resource_map[IS_UV_MAX] = {
237236
"uv_tcp",
238237
"uv_udp",
@@ -2573,9 +2572,12 @@ PHP_MINIT_FUNCTION(uv)
25732572
uv_loop_handle = zend_register_list_destructors_ex(destruct_uv_loop, NULL, PHP_UV_LOOP_RESOURCE_NAME, module_number);
25742573
uv_sockaddr_handle = zend_register_list_destructors_ex(destruct_uv_sockaddr, NULL, PHP_UV_SOCKADDR_RESOURCE_NAME, module_number);
25752574
uv_lock_handle = zend_register_list_destructors_ex(destruct_uv_lock, NULL, PHP_UV_LOCK_RESOURCE_NAME, module_number);
2576-
// uv_httpparser_handle = zend_register_list_destructors_ex(destruct_httpparser, NULL, PHP_UV_HTTPPARSER_RESOURCE_NAME, module_number);
25772575
uv_stdio_handle = zend_register_list_destructors_ex(destruct_uv_stdio, NULL, PHP_UV_STDIO_RESOURCE_NAME, module_number);
25782576

2577+
#ifdef ENABLE_HTTPPARSER
2578+
register_httpparser(module_number);
2579+
#endif
2580+
25792581
return SUCCESS;
25802582
}
25812583

@@ -6509,10 +6511,14 @@ static zend_function_entry uv_functions[] = {
65096511
PHP_FE(uv_signal_init, arginfo_uv_signal_init)
65106512
PHP_FE(uv_signal_start, arginfo_uv_signal_start)
65116513
PHP_FE(uv_signal_stop, arginfo_uv_signal_stop)
6514+
#ifdef ENABLE_HTTPPARSER
6515+
/* http parser */
6516+
PHP_FE(uv_http_parser_init, arginfo_uv_http_parser_init)
6517+
PHP_FE(uv_http_parser_execute, arginfo_uv_http_parser_execute)
6518+
#endif
65126519
{NULL, NULL, NULL}
65136520
};
65146521

6515-
65166522
PHP_MINFO_FUNCTION(uv)
65176523
{
65186524
char uv_version[20];

php_uv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "php.h"
3333
#include "uv.h"
3434

35+
#ifdef ENABLE_HTTPPARSER
36+
#include "uv_http_parser.h"
37+
#endif
38+
3539
#include "php_network.h"
3640
#include "php_streams.h"
3741

uv.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ static int php_uv_class_init(TSRMLS_D)
183183
zend_declare_class_constant_long(uv_class_entry, "PROCESS_WINDOWS_VERBATIM_ARGUMENTS", sizeof("PROCESS_WINDOWS_VERBATIM_ARGUMENTS")-1, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS TSRMLS_CC);
184184
zend_declare_class_constant_long(uv_class_entry, "PROCESS_DETACHED", sizeof("PROCESS_DETACHED")-1, UV_PROCESS_DETACHED TSRMLS_CC);
185185

186+
#ifdef ENABLE_HTTPPARSER
187+
/* http parser */
188+
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH")-1, HTTP_BOTH TSRMLS_CC);
189+
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
190+
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);
191+
#endif
192+
186193
#define PHP_UV_ERRNO_GEN(code_notused, name, msg_notused) zend_declare_class_constant_long(uv_class_entry, #name, sizeof(#name)-1, UV_##name TSRMLS_CC);
187194
UV_ERRNO_MAP(PHP_UV_ERRNO_GEN)
188195
#undef PHP_UV_ERRNO_GEN

uv_http_parser.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
#include "uv_http_parser.h"
2+
13
static int uv_httpparser_handle;
24

3-
void static destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
5+
void destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
46
{
57
php_http_parser_context *obj = (php_http_parser_context *)rsrc->ptr;
6-
8+
9+
fprintf(stderr, "Destroying http parser\n");
10+
711
if (obj->headers) {
812
zval_ptr_dtor(&obj->headers);
913
}
@@ -14,6 +18,11 @@ void static destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
1418
efree(obj);
1519
}
1620

21+
void register_httpparser(int module_number)
22+
{
23+
uv_httpparser_handle = zend_register_list_destructors_ex(destruct_httpparser, NULL, PHP_UV_HTTPPARSER_RESOURCE_NAME, module_number);
24+
}
25+
1726
/* http parser callbacks */
1827
static int on_message_begin(http_parser *p)
1928
{
@@ -143,17 +152,6 @@ static int on_body_cb(http_parser *p, const char *at, size_t len)
143152
}
144153
/* end of callback */
145154

146-
/* HTTP PARSER */
147-
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_init, 0, 0, 1)
148-
ZEND_ARG_INFO(0, target)
149-
ZEND_END_ARG_INFO()
150-
151-
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_execute, 0, 0, 3)
152-
ZEND_ARG_INFO(0, resource)
153-
ZEND_ARG_INFO(0, buffer)
154-
ZEND_ARG_INFO(0, setting)
155-
ZEND_END_ARG_INFO()
156-
157155
/* {{{ proto resource uv_http_parser_init(long $target = UV::HTTP_REQUEST)
158156
*/
159157
PHP_FUNCTION(uv_http_parser_init)
@@ -216,10 +214,10 @@ PHP_FUNCTION(uv_http_parser_execute)
216214
size_t nparsed = 0;
217215

218216
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
219-
"rs/a",&z_parser, &body, &body_len, &result) == FAILURE) {
217+
"rs/a", &z_parser, &body, &body_len, &result) == FAILURE) {
220218
return;
221219
}
222-
220+
223221
ZEND_FETCH_RESOURCE(context, php_http_parser_context*, &z_parser, -1, PHP_UV_HTTPPARSER_RESOURCE_NAME, uv_httpparser_handle);
224222

225223
if (context->finished == 1) {
@@ -253,25 +251,10 @@ PHP_FUNCTION(uv_http_parser_execute)
253251

254252
MAKE_STD_ZVAL(headers);
255253
ZVAL_ZVAL(headers, context->headers, 1, 0);
254+
256255
add_assoc_zval(headers, "VERSION", version);
257256
add_assoc_zval(result, "HEADERS", headers);
258257

259-
if (context->finished == 1) {
260-
RETURN_TRUE;
261-
} else {
262-
RETURN_FALSE;
263-
}
258+
RETURN_BOOL(context->finished);
264259
}
265260

266-
// static zend_function_entry uv_functions[] = {
267-
268-
/* http parser */
269-
PHP_FE(uv_http_parser_init, arginfo_uv_http_parser_init)
270-
PHP_FE(uv_http_parser_execute, arginfo_uv_http_parser_execute)
271-
272-
// php_uv_class_init
273-
274-
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH")-1, HTTP_BOTH TSRMLS_CC);
275-
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
276-
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);
277-

uv_http_parser.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#ifndef UV_HTTPPARSER_H
2+
#define UV_HTTPPARSER_H
3+
4+
#include "php.h"
5+
#include "zend_exceptions.h"
6+
17
#include "http_parser.h"
28

39
typedef struct {
@@ -15,3 +21,20 @@ typedef struct {
1521

1622
#define PHP_UV_HTTPPARSER_RESOURCE_NAME "uv_httpparser"
1723

24+
void register_httpparser(int module_number);
25+
26+
/* HTTP PARSER */
27+
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_init, 0, 0, 1)
28+
ZEND_ARG_INFO(0, target)
29+
ZEND_END_ARG_INFO()
30+
31+
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_execute, 0, 0, 3)
32+
ZEND_ARG_INFO(0, resource)
33+
ZEND_ARG_INFO(0, buffer)
34+
ZEND_ARG_INFO(0, setting)
35+
ZEND_END_ARG_INFO()
36+
37+
PHP_FUNCTION(uv_http_parser_init);
38+
PHP_FUNCTION(uv_http_parser_execute);
39+
40+
#endif

0 commit comments

Comments
 (0)