1+ #include "uv_http_parser.h"
2+
13static 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 */
1827static 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*/
159157PHP_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-
0 commit comments