From 96546a74b285fccc8822d819f6ef57f21b2c5150 Mon Sep 17 00:00:00 2001 From: Bernhard Valenti Date: Thu, 6 Jan 2011 13:14:29 +0100 Subject: [PATCH] fix one-off bug in evhttp_request_body() --- demos/zf-apiserver/bin/main.php | 2 +- demos/zf/bin/main.php | 28 ++++++++++++++-------------- event.c | 11 ++++++----- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/demos/zf-apiserver/bin/main.php b/demos/zf-apiserver/bin/main.php index 1318889..1cb6770 100644 --- a/demos/zf-apiserver/bin/main.php +++ b/demos/zf-apiserver/bin/main.php @@ -84,7 +84,7 @@ public function processRequest($r) try { printf("Used script-land memory %.2f MB\n", memory_get_usage()/(1024*1024)); - $uri = evhttp_request_uri($r); + $uri = evhttp_request_get_uri($r); $parts = parse_url($uri); // let's process the request with the chosen webservice protocol diff --git a/demos/zf/bin/main.php b/demos/zf/bin/main.php index 19406f6..735b176 100644 --- a/demos/zf/bin/main.php +++ b/demos/zf/bin/main.php @@ -14,7 +14,7 @@ class AppServer private $logger = null; private $base = null; private $config = null; - + private function _startupSuperGlobal() { @@ -28,30 +28,30 @@ private function _startupSuperGlobal() $_SERVER[ "SERVER_SOFTWARE" ] = "EvHttp ZF Application Server 0.1"; $_SERVER[ "SERVER_PROTOCOL" ] = 'HTTP 1.1'; } - + public function __construct($addr="127.0.0.1", $port=8080) { $this->port = $port; $this->addr = $addr; $this->_startupSuperGlobal(); - + // Setup basic stuff error_reporting(E_ALL & ~E_NOTICE); $base = realpath(dirname(__FILE__) . '/../'); $paths = array( - '.', + '.', realpath($base . '/library'), get_include_path(), ); $this->base = $base; - + // Setup autoloading ... set_include_path(implode(PATH_SEPARATOR, $paths)); require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('EvHttp_'); - + $resourceLoader = new Zend_Loader_Autoloader_Resource(array( 'basePath' => realpath($base . '/application'), 'namespace' => '', @@ -66,11 +66,11 @@ public function __construct($addr="127.0.0.1", $port=8080) ), ), )); - + // Load config $this->config = new Zend_Config_Ini($this->base . '/deploy/config.ini', 'default'); Zend_Registry::set('config', $this->config); - + // Connect database $dbType = $this->config->database->type; $params = $this->config->database->toArray(); @@ -92,12 +92,12 @@ private function _initRequest($r) { $_SERVER[ "REQUEST_METHOD" ] = evhttp_request_method($r); $_SERVER[ "REQUEST_TIME" ] = time(); - $_SERVER[ "argv" ] = $_SERVER[ "REQUEST_URI" ] = evhttp_request_uri($r); - + $_SERVER[ "argv" ] = $_SERVER[ "REQUEST_URI" ] = evhttp_request_get_uri($r); + $parts = parse_url($_SERVER["REQUEST_URI"]); $_SERVER['QUERY_STRING'] = $parts['query']; parse_str($_SERVER['QUERY_STRING'], $_GET); - + $headers = evhttp_request_headers($r); // normalize to php way foreach ($headers as $name => $value) @@ -105,17 +105,17 @@ private function _initRequest($r) echo "script-land memory: ".memory_get_usage()."\n"; } - + public function processRequest($r) { try - { + { $this->_initRequest($r); $response = $this->controller->dispatch(); } catch(Exception $e) { - return $e->__toString(); + return $e->__toString(); } return evhttp_response_set($response->getBody(), $response->getHttpResponseCode(), "OK"); } diff --git a/event.c b/event.c index f5f0d25..546b912 100644 --- a/event.c +++ b/event.c @@ -802,12 +802,12 @@ PHP_FUNCTION(evhttp_request_method) RETURN_STRING("PUT", 1); case EVHTTP_REQ_DELETE: RETURN_STRING("DELETE", 1); -/* case EVHTTP_REQ_OPTIONS: + case EVHTTP_REQ_OPTIONS: RETURN_STRING("OPTIONS", 1); case EVHTTP_REQ_TRACE: RETURN_STRING("TRACE", 1); case EVHTTP_REQ_CONNECT: - RETURN_STRING("CONNECT", 1); */ + RETURN_STRING("CONNECT", 1); default: RETURN_NULL(); } @@ -955,7 +955,7 @@ PHP_FUNCTION(evhttp_request_body) ZEND_FETCH_RESOURCE(req, struct evhttp_request*, &res_req, -1, PHP_EVHTTP_REQUEST_RES_NAME, le_evhttp_request); - body_len = evbuffer_get_length(req->input_buffer); + body_len = EVBUFFER_LENGTH(req->input_buffer); if (req->input_buffer == NULL || body_len == 0) { @@ -963,7 +963,8 @@ PHP_FUNCTION(evhttp_request_body) } body = emalloc(body_len + 1); - status = evbuffer_remove(req->input_buffer, (void *) body, body_len + 1); + status = evbuffer_remove(req->input_buffer, (void *) body, body_len); + body[body_len] = '\0'; if (status == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not get data from resource"); RETURN_FALSE; @@ -1651,7 +1652,7 @@ PHP_FUNCTION(evhttp_make_request) zval *con_res, *req_res; struct evhttp_connection *con; struct evhttp_request *req; - long type; + long type; int url_len; char *url; int ret;