Commits

Ruslan Osmanov committed 8abc2bb Merge

Merge branch 'develop'

Comments (0)

Files changed (8)

classes/buffer_event.c

 				"Failed to allocate bufferevent for socket");
 		return;
 	}
-
+	bev->_internal = 0;
 	bev->bevent = bevent;
 
 	bev->self = zself;
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
 
 	if (bev->bevent) {
-		bufferevent_free(bev->bevent);
+		if (!bev->_internal) {
+			bufferevent_free(bev->bevent);
+		}
 		bev->bevent = 0;
 
 		/* Do it once */
 		return;
 	}
 #endif
-	
+
 	if (family & ~(AF_INET | AF_INET6 | AF_UNSPEC)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING,
 				"Invalid address family specified");
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OZOl|l",
 				&zbase, php_event_base_ce,
-				&ppzfd, 
+				&ppzfd,
 				&zctx, php_event_ssl_context_ce,
 				&state, &options) == FAILURE) {
 		return;
 
 	e = bufferevent_get_openssl_error(bev->bevent);
 	if (e) {
-		RETURN_STRING(ERR_error_string(e, buf), 1);	
+		RETURN_STRING(ERR_error_string(e, buf), 1);
 	}
 
 	RETVAL_FALSE;

classes/http_request.c

 	zend_fcall_info_cache  fcc      = empty_fcall_info_cache;
 	zval                  *zarg     = NULL;
 	struct evhttp_request *req;
-	
+
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|z",
 				&fci, &fcc, &zarg) == FAILURE) {
 }
 /* }}} */
 
+
+/* {{{ proto EventBufferEvent EventHttpRequest::getEventBufferEvent(void);
+ * Returns EventBufferEvent object. */
+PHP_METHOD(EventHttpRequest, getEventBufferEvent)
+{
+	php_event_http_req_t     *http_req;
+	struct evhttp_connection *conn;
+	php_event_bevent_t       *bev;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_HTTP_REQ(http_req, getThis());
+
+	_check_http_req_ptr(http_req);
+
+	PHP_EVENT_INIT_CLASS_OBJECT(return_value, php_event_bevent_ce);
+	PHP_EVENT_FETCH_BEVENT(bev, return_value);
+	conn = evhttp_request_get_connection(http_req->ptr);
+	bev->bevent = evhttp_connection_get_bufferevent(conn);
+	bev->self = return_value;
+	Z_ADDREF_P(return_value);
+	bev->input = bev->output = NULL;
+	bev->_internal = 1;
+}
+/* }}} */
+
+/* {{{ proto EventHttpConnection EventHttpRequest::getEventHttpConnection(void);
+ * Returns EventHttpConnection object. */
+PHP_METHOD(EventHttpRequest, getEventHttpConnection)
+{
+	php_event_http_req_t     *http_req;
+	struct evhttp_connection *conn;
+	php_event_http_conn_t    *evcon;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_HTTP_REQ(http_req, getThis());
+
+	_check_http_req_ptr(http_req);
+
+	PHP_EVENT_INIT_CLASS_OBJECT(return_value, php_event_http_conn_ce);
+	PHP_EVENT_FETCH_HTTP_CONN(evcon, return_value);
+	conn = evhttp_request_get_connection(http_req->ptr);
+	evcon->conn = conn;
+	evcon->base = NULL;
+	evcon->dns_base = NULL;
+	Z_ADDREF_P(return_value);
+}
+/* }}} */
+
+/* {{{ proto void EventHttpRequest::closeConnection(void);
+ */
+PHP_METHOD(EventHttpRequest, closeConnection)
+{
+	php_event_http_req_t     *http_req;
+	struct evhttp_connection *conn;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_HTTP_REQ(http_req, getThis());
+
+	_check_http_req_ptr(http_req);
+
+	conn = evhttp_request_get_connection(http_req->ptr);
+	evhttp_connection_free(conn);
+}
+/* }}} */
+
+
+
 /* {{{ proto void EventHttpRequest::sendError(int error[, string reason = NULL]);
  * Send an HTML error message to the client.
  */
 /* }}} */
 
 /* {{{ proto void EventHttpRequest::sendReplyEnd(void);
- * Complete a chunked reply, freeing the request as appropriate. 
+ * Complete a chunked reply, freeing the request as appropriate.
  */
 PHP_METHOD(EventHttpRequest, sendReplyEnd)
 {
  *
  * Cancels an ongoing HTTP request. The callback associated with this request
  * is not executed and the request object is freed. If the request is currently
- * being processed, e.g. it is ongoing, the corresponding EventHttpConnection 
+ * being processed, e.g. it is ongoing, the corresponding EventHttpConnection
  * object is going to get reset.
  *
  * A request cannot be canceled if its callback has executed already. A request
     <email>osmanov@php.net</email>
     <active>yes</active>
   </lead>
-  <date>2013-09-15</date>
+  <date>2013-09-24</date>
   <!--{{{ Current version -->
   <version>
-    <release>1.7.8</release>
-    <api>1.7.0</api>
+    <release>1.8.0</release>
+    <api>1.8.0</api>
   </version>
   <stability>
     <release>stable</release>
   </stability>
   <license uri="http://www.php.net/license">PHP</license>
   <notes><![CDATA[
-  Fix: build error on Solaris
-  Introduced negative dependencies: libevent extension, windows OS
+  Add: EventHttpRequest methods: getEventBufferEvent, getEventHttpConnection, closeConnection(thanks to rickysu at Bitbucket)
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
   </extsrcrelease>
   <!--{{{ changelog-->
   <changelog>
+    <!--{{{ 1.8.0 -->
+    <release>
+      <version>
+        <release>1.8.0</release>
+        <api>1.8.0</api>
+      </version>
+      <stability>
+        <release>stable</release>
+        <api>stable</api>
+      </stability>
+      <license uri="http://www.php.net/license">PHP</license>
+      <notes><![CDATA[
+  Add: EventHttpRequest methods: getEventBufferEvent, getEventHttpConnection, closeConnection(thanks to rickysu at Bitbucket)
+  ]]></notes>
+    </release>
+    <!--}}}-->
     <!--{{{ 1.7.8 -->
     <release>
       <version>
 #ifndef PHP_EVENT_H
 #define PHP_EVENT_H
 
-#define PHP_EVENT_VERSION "1.7.8"
+#define PHP_EVENT_VERSION "1.8.0"
 
 #define PHP_EVENT_SUN_PREFIX "unix:"
 
 ZEND_END_ARG_INFO();
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_add, 0, 0, 1)
-	ZEND_ARG_INFO(0, data) 
+	ZEND_ARG_INFO(0, data)
 ZEND_END_ARG_INFO();
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_evbuffer_add_buffer, 0, 0, 1)
 	PHP_MALIAS(Event, delTimer,  del, arginfo_event__void, ZEND_ACC_PUBLIC)
 	PHP_MALIAS(Event, addSignal, add, arginfo_event_add,   ZEND_ACC_PUBLIC)
 	PHP_MALIAS(Event, delSignal, del, arginfo_event__void, ZEND_ACC_PUBLIC)
-													  
+
 	PHP_FE_END
 };
 /* }}} */
 #if LIBEVENT_VERSION_NUMBER >= 0x02010200
 	PHP_ME(EventBase, resume,             arginfo_event__void,              ZEND_ACC_PUBLIC)
 #endif
-														   
+
 	PHP_FE_END
 };
 /* }}} */
 const zend_function_entry php_event_http_req_ce_functions[] = {
 	PHP_ME(EventHttpRequest, __construct, arginfo_event_http_req__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
 
-	PHP_ME(EventHttpRequest, free,             arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getCommand,       arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getHost,          arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getUri,           arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getResponseCode,  arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getInputHeaders,  arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getOutputHeaders, arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getInputBuffer,   arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, getOutputBuffer,  arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, sendError,        arginfo_event_http_req_send_error,       ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, sendReply,        arginfo_event_http_req_send_reply,       ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, sendReplyChunk,   arginfo_event_http_req_send_reply_chunk, ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, sendReplyEnd,     arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, sendReplyStart,   arginfo_event_http_req_send_reply_start, ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, cancel,           arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, addHeader,        arginfo_event_http_req_add_header,       ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, clearHeaders,     arginfo_event__void,                     ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, removeHeader,     arginfo_event_http_req_remove_header,    ZEND_ACC_PUBLIC)
-	PHP_ME(EventHttpRequest, findHeader,       arginfo_event_http_req_remove_header,    ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, free,                   arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getCommand,             arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getHost,                arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getUri,                 arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getResponseCode,        arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getInputHeaders,        arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getOutputHeaders,       arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getInputBuffer,         arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getOutputBuffer,        arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, sendError,              arginfo_event_http_req_send_error,       ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, sendReply,              arginfo_event_http_req_send_reply,       ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, sendReplyChunk,         arginfo_event_http_req_send_reply_chunk, ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, sendReplyEnd,           arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, sendReplyStart,         arginfo_event_http_req_send_reply_start, ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, cancel,                 arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, addHeader,              arginfo_event_http_req_add_header,       ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, clearHeaders,           arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, removeHeader,           arginfo_event_http_req_remove_header,    ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, findHeader,             arginfo_event_http_req_remove_header,    ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getEventBufferEvent,    arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, getEventHttpConnection, arginfo_event__void,                     ZEND_ACC_PUBLIC)
+	PHP_ME(EventHttpRequest, closeConnection,        arginfo_event__void,                     ZEND_ACC_PUBLIC)
 
 	PHP_FE_END
 };
 PHP_METHOD(EventHttpRequest, clearHeaders);
 PHP_METHOD(EventHttpRequest, removeHeader);
 PHP_METHOD(EventHttpRequest, findHeader);
+PHP_METHOD(EventHttpRequest, getEventBufferEvent);
+PHP_METHOD(EventHttpRequest, getEventHttpConnection);
+PHP_METHOD(EventHttpRequest, closeConnection);
+
 /* Extra API END }}} */
 #endif
 
 #endif /* PHP_EVENT_FE_H */
 
-/* 
+/*
  * Local variables:
  * tab-width: 4
  * c-basic-offset: 4
 	PHP_EVENT_PROP_REQUIRE(b->buf);
 
 	MAKE_STD_ZVAL(*retval);
-	ZVAL_LONG(*retval, evbuffer_get_length(b->buf));
+	if (b && b->buf){
+		ZVAL_LONG(*retval, evbuffer_get_length(b->buf));
+	} else {
+		ZVAL_LONG(*retval, 0);
+	}
 
 	return SUCCESS;
 }
 #ifndef PHP_EVENT_STRUCTS_H
 #define PHP_EVENT_STRUCTS_H
 
-/* Thread context. With it we are getting rid of need 
+/* Thread context. With it we are getting rid of need
  * to call the heavy TSRMLS_FETCH() */
 #ifdef ZTS
 # define PHP_EVENT_COMMON_THREAD_CTX void ***thread_ctx
 	PHP_EVENT_OBJECT_HEAD;
 
 	struct bufferevent    *bevent;
+	int                   _internal;
 	zval                  *self;        /* Object itself. For callbacks                   */
 	zval                  *data;        /* User custom data                               */
 	zval                  *input;       /* Input buffer */