Enabled http parser again

This commit is contained in:
Tjerk Meesters 2014-08-21 08:31:25 +08:00
parent 39a7fe3c7e
commit bdaf5a0bb8
6 changed files with 59 additions and 47 deletions

View File

@ -44,7 +44,7 @@ if test $PHP_UV != "no"; then
SOURCES="" SOURCES=""
if test $PHP_HTTPPARSER != "no"; then if test $PHP_HTTPPARSER != "no"; then
SOURCES=" http-parser/http_parser.c" SOURCES=" uv_http_parser.c http-parser/http_parser.c"
AC_DEFINE([ENABLE_HTTPPARSER], [1], [ Enable http parser]) AC_DEFINE([ENABLE_HTTPPARSER], [1], [ Enable http parser])
fi fi
@ -81,15 +81,4 @@ if test $PHP_UV != "no"; then
]) ])
PHP_SUBST(UV_SHARED_LIBADD) PHP_SUBST(UV_SHARED_LIBADD)
# CFLAGS=" $CFLAGS -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement"
# case $host in
# *darwin*)
# ;;
# *linux*)
# CFLAGS="$CFLAGS -lrt"
# esac
# PHP_SUBST([CFLAGS])
fi fi

View File

@ -232,7 +232,6 @@ static int uv_lock_handle;
static int uv_stdio_handle; static int uv_stdio_handle;
char *php_uv_resource_map[IS_UV_MAX] = { char *php_uv_resource_map[IS_UV_MAX] = {
"uv_tcp", "uv_tcp",
"uv_udp", "uv_udp",
@ -2573,9 +2572,12 @@ PHP_MINIT_FUNCTION(uv)
uv_loop_handle = zend_register_list_destructors_ex(destruct_uv_loop, NULL, PHP_UV_LOOP_RESOURCE_NAME, module_number); uv_loop_handle = zend_register_list_destructors_ex(destruct_uv_loop, NULL, PHP_UV_LOOP_RESOURCE_NAME, module_number);
uv_sockaddr_handle = zend_register_list_destructors_ex(destruct_uv_sockaddr, NULL, PHP_UV_SOCKADDR_RESOURCE_NAME, module_number); uv_sockaddr_handle = zend_register_list_destructors_ex(destruct_uv_sockaddr, NULL, PHP_UV_SOCKADDR_RESOURCE_NAME, module_number);
uv_lock_handle = zend_register_list_destructors_ex(destruct_uv_lock, NULL, PHP_UV_LOCK_RESOURCE_NAME, module_number); uv_lock_handle = zend_register_list_destructors_ex(destruct_uv_lock, NULL, PHP_UV_LOCK_RESOURCE_NAME, module_number);
// uv_httpparser_handle = zend_register_list_destructors_ex(destruct_httpparser, NULL, PHP_UV_HTTPPARSER_RESOURCE_NAME, module_number);
uv_stdio_handle = zend_register_list_destructors_ex(destruct_uv_stdio, NULL, PHP_UV_STDIO_RESOURCE_NAME, module_number); uv_stdio_handle = zend_register_list_destructors_ex(destruct_uv_stdio, NULL, PHP_UV_STDIO_RESOURCE_NAME, module_number);
#ifdef ENABLE_HTTPPARSER
register_httpparser(module_number);
#endif
return SUCCESS; return SUCCESS;
} }
@ -6509,10 +6511,14 @@ static zend_function_entry uv_functions[] = {
PHP_FE(uv_signal_init, arginfo_uv_signal_init) PHP_FE(uv_signal_init, arginfo_uv_signal_init)
PHP_FE(uv_signal_start, arginfo_uv_signal_start) PHP_FE(uv_signal_start, arginfo_uv_signal_start)
PHP_FE(uv_signal_stop, arginfo_uv_signal_stop) PHP_FE(uv_signal_stop, arginfo_uv_signal_stop)
#ifdef ENABLE_HTTPPARSER
/* http parser */
PHP_FE(uv_http_parser_init, arginfo_uv_http_parser_init)
PHP_FE(uv_http_parser_execute, arginfo_uv_http_parser_execute)
#endif
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
PHP_MINFO_FUNCTION(uv) PHP_MINFO_FUNCTION(uv)
{ {
char uv_version[20]; char uv_version[20];

View File

@ -32,6 +32,10 @@
#include "php.h" #include "php.h"
#include "uv.h" #include "uv.h"
#ifdef ENABLE_HTTPPARSER
#include "uv_http_parser.h"
#endif
#include "php_network.h" #include "php_network.h"
#include "php_streams.h" #include "php_streams.h"

7
uv.c
View File

@ -183,6 +183,13 @@ static int php_uv_class_init(TSRMLS_D)
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); 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);
zend_declare_class_constant_long(uv_class_entry, "PROCESS_DETACHED", sizeof("PROCESS_DETACHED")-1, UV_PROCESS_DETACHED TSRMLS_CC); zend_declare_class_constant_long(uv_class_entry, "PROCESS_DETACHED", sizeof("PROCESS_DETACHED")-1, UV_PROCESS_DETACHED TSRMLS_CC);
#ifdef ENABLE_HTTPPARSER
/* http parser */
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH")-1, HTTP_BOTH TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);
#endif
#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); #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);
UV_ERRNO_MAP(PHP_UV_ERRNO_GEN) UV_ERRNO_MAP(PHP_UV_ERRNO_GEN)
#undef PHP_UV_ERRNO_GEN #undef PHP_UV_ERRNO_GEN

View File

@ -1,9 +1,13 @@
#include "uv_http_parser.h"
static int uv_httpparser_handle; static int uv_httpparser_handle;
void static destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC) void destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{ {
php_http_parser_context *obj = (php_http_parser_context *)rsrc->ptr; php_http_parser_context *obj = (php_http_parser_context *)rsrc->ptr;
fprintf(stderr, "Destroying http parser\n");
if (obj->headers) { if (obj->headers) {
zval_ptr_dtor(&obj->headers); zval_ptr_dtor(&obj->headers);
} }
@ -14,6 +18,11 @@ void static destruct_httpparser(zend_rsrc_list_entry *rsrc TSRMLS_DC)
efree(obj); efree(obj);
} }
void register_httpparser(int module_number)
{
uv_httpparser_handle = zend_register_list_destructors_ex(destruct_httpparser, NULL, PHP_UV_HTTPPARSER_RESOURCE_NAME, module_number);
}
/* http parser callbacks */ /* http parser callbacks */
static int on_message_begin(http_parser *p) static int on_message_begin(http_parser *p)
{ {
@ -143,17 +152,6 @@ static int on_body_cb(http_parser *p, const char *at, size_t len)
} }
/* end of callback */ /* end of callback */
/* HTTP PARSER */
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_init, 0, 0, 1)
ZEND_ARG_INFO(0, target)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_execute, 0, 0, 3)
ZEND_ARG_INFO(0, resource)
ZEND_ARG_INFO(0, buffer)
ZEND_ARG_INFO(0, setting)
ZEND_END_ARG_INFO()
/* {{{ proto resource uv_http_parser_init(long $target = UV::HTTP_REQUEST) /* {{{ proto resource uv_http_parser_init(long $target = UV::HTTP_REQUEST)
*/ */
PHP_FUNCTION(uv_http_parser_init) PHP_FUNCTION(uv_http_parser_init)
@ -216,7 +214,7 @@ PHP_FUNCTION(uv_http_parser_execute)
size_t nparsed = 0; size_t nparsed = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rs/a",&z_parser, &body, &body_len, &result) == FAILURE) { "rs/a", &z_parser, &body, &body_len, &result) == FAILURE) {
return; return;
} }
@ -253,25 +251,10 @@ PHP_FUNCTION(uv_http_parser_execute)
MAKE_STD_ZVAL(headers); MAKE_STD_ZVAL(headers);
ZVAL_ZVAL(headers, context->headers, 1, 0); ZVAL_ZVAL(headers, context->headers, 1, 0);
add_assoc_zval(headers, "VERSION", version); add_assoc_zval(headers, "VERSION", version);
add_assoc_zval(result, "HEADERS", headers); add_assoc_zval(result, "HEADERS", headers);
if (context->finished == 1) { RETURN_BOOL(context->finished);
RETURN_TRUE;
} else {
RETURN_FALSE;
}
} }
// static zend_function_entry uv_functions[] = {
/* http parser */
PHP_FE(uv_http_parser_init, arginfo_uv_http_parser_init)
PHP_FE(uv_http_parser_execute, arginfo_uv_http_parser_execute)
// php_uv_class_init
zend_declare_class_constant_long(uv_class_entry, "HTTP_BOTH", sizeof("HTTP_BOTH")-1, HTTP_BOTH TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);

View File

@ -1,3 +1,9 @@
#ifndef UV_HTTPPARSER_H
#define UV_HTTPPARSER_H
#include "php.h"
#include "zend_exceptions.h"
#include "http_parser.h" #include "http_parser.h"
typedef struct { typedef struct {
@ -15,3 +21,20 @@ typedef struct {
#define PHP_UV_HTTPPARSER_RESOURCE_NAME "uv_httpparser" #define PHP_UV_HTTPPARSER_RESOURCE_NAME "uv_httpparser"
void register_httpparser(int module_number);
/* HTTP PARSER */
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_init, 0, 0, 1)
ZEND_ARG_INFO(0, target)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_http_parser_execute, 0, 0, 3)
ZEND_ARG_INFO(0, resource)
ZEND_ARG_INFO(0, buffer)
ZEND_ARG_INFO(0, setting)
ZEND_END_ARG_INFO()
PHP_FUNCTION(uv_http_parser_init);
PHP_FUNCTION(uv_http_parser_execute);
#endif