Commits

Ruslan Osmanov  committed 885c29e

Add: EventBufferEvent methods: sslError, sslRenegotiate
and allow_ssl_dirty_shutdown property

  • Participants
  • Parent commits a54d9a9

Comments (0)

Files changed (5)

File classes/buffer_event.c

 	Z_ADDREF_P(return_value);
 }
 /* }}} */
+
+/* {{{ proto string EventBufferEvent::sslError(void);
+ *
+ * Returns most recent OpenSSL error reported on the buffer event. The function
+ * returns FALSE, if there is no more error to return. */
+PHP_METHOD(EventBufferEvent, sslError)
+{
+	zval               *zbevent  = getThis();
+	php_event_bevent_t *bev;
+	char                buf[512];
+	unsigned long       e;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+
+	e = bufferevent_get_openssl_error(bev->bevent);
+	if (e) {
+		RETURN_STRING(ERR_error_string(e, buf), 1);	
+	}
+
+	RETVAL_FALSE;
+}
+/* }}} */
+
+/* {{{ proto void EventBufferEvent::sslRenegotiate(void);
+ *
+ * Tells a bufferevent to begin SSL renegotiation.
+ *
+ * Warning. Calling this function tells the SSL to renegotiate, and the
+ * bufferevent to invoke appropriate callbacks. This is an advanced topic; you
+ * should generally avoid it unless you really know what you’re doing,
+ * especially since many SSL versions have had known security issues related to
+ * renegotiation.
+ **/
+PHP_METHOD(EventBufferEvent, sslRenegotiate)
+{
+	zval               *zbevent  = getThis();
+	php_event_bevent_t *bev;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+
+	bufferevent_ssl_renegotiate(bev->bevent);
+}
+/* }}} */
 #endif /* HAVE_EVENT_OPENSSL_LIB }}} */
 
 /*
   setPosition methods
   Add: EventBufferPosition class
   Fix: configure error in FreeBSD
-  Add: OpenSSL support: EventBufferEvent methods: sslFilter, sslSocket, EventSslContext class
-  Add: EventBuffer::pullup
+  Add: OpenSSL support: EventBufferEvent methods: sslFilter, sslSocket, sslError, sslRenegotiate; EventSslContext class
+  Add: EventBuffer::pullup method
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
   setPosition methods
   Add: EventBufferPosition class
   Fix: configure error in FreeBSD
-  Add: OpenSSL support: EventBufferEvent methods: sslFilter, sslSocket, EventSslContext class
-  Add: EventBuffer::pullup
+  Add: OpenSSL support: EventBufferEvent methods: sslFilter, sslSocket, sslError, sslRenegotiate; EventSslContext class
+  Add: EventBuffer::pullup method
   ]]></notes>
   </release>
   <!--}}}-->
 #ifdef HAVE_EVENT_OPENSSL_LIB
 	PHP_ME(EventBufferEvent, sslFilter,         arginfo_bufferevent_ssl_filter,              ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
 	PHP_ME(EventBufferEvent, sslSocket,         arginfo_bufferevent_ssl_socket,              ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
+	PHP_ME(EventBufferEvent, sslError,          arginfo_event__void,                         ZEND_ACC_PUBLIC)
+	PHP_ME(EventBufferEvent, sslRenegotiate,    arginfo_event__void,                         ZEND_ACC_PUBLIC)
 #endif
 
 	PHP_FE_END
 #ifdef HAVE_EVENT_OPENSSL_LIB
 PHP_METHOD(EventBufferEvent, sslFilter);
 PHP_METHOD(EventBufferEvent, sslSocket);
+PHP_METHOD(EventBufferEvent, sslError);
+PHP_METHOD(EventBufferEvent, sslRenegotiate);
 #endif
 
 PHP_METHOD(EventBuffer, __construct);
 }
 /* }}} */
 
+
+#if LIBEVENT_VERSION_NUMBER >= 0x02010100
+/* {{{ event_bevent_allow_ssl_dirty_shutdown_prop_write*/
+static int event_bevent_allow_ssl_dirty_shutdown_prop_write(php_event_abstract_object_t *obj, zval *value TSRMLS_DC)
+{
+	php_event_bevent_t *bev      = (php_event_bevent_t *) obj;
+	int allow_ssl_dirty_shutdown = (int) Z_BVAL_P(value);
+
+	bufferevent_openssl_set_allow_dirty_shutdown(bev->bevent, allow_ssl_dirty_shutdown);
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ event_bevent_allow_ssl_dirty_shutdown_prop_read */
+static int event_bevent_allow_ssl_dirty_shutdown_prop_read(php_event_abstract_object_t *obj, zval **retval TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *)obj;
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_BOOL(*retval, (zend_bool) bufferevent_openssl_get_allow_dirty_shutdown(bev->bevent));
+	return SUCCESS;
+}
+/* }}} */
+#endif
+
+
 const php_event_property_entry_t event_property_entries[] = {
 	{"timer_pending",           sizeof("timer_pending") - 1, event_timer_pending_prop_read, NULL, NULL},
     {NULL, 0, NULL, NULL, NULL}
 };
 const php_event_property_entry_t event_bevent_property_entries[] = {
 	{"priority", sizeof("priority") - 1, event_bevent_priority_prop_read, event_bevent_priority_prop_write, NULL },
+
+#if LIBEVENT_VERSION_NUMBER >= 0x02010100
+	{"allow_ssl_dirty_shutdown", sizeof("allow_ssl_dirty_shutdown") - 1,
+		event_bevent_allow_ssl_dirty_shutdown_prop_read,
+		event_bevent_allow_ssl_dirty_shutdown_prop_write, NULL },
+#endif
     {NULL, 0, NULL, NULL, NULL}
 };
 const php_event_property_entry_t event_buffer_property_entries[] = {
 };
 const zend_property_info event_bevent_property_entry_info[] = {
 	{ZEND_ACC_PUBLIC, "priority", sizeof("priority") - 1, -1, 0, NULL, 0, NULL},
+#if LIBEVENT_VERSION_NUMBER >= 0x02010100
+	{ZEND_ACC_PUBLIC, "allow_ssl_dirty_shutdown", sizeof("allow_ssl_dirty_shutdown") - 1, -1, 0, NULL, 0, NULL},
+#endif
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 const zend_property_info event_buffer_property_entry_info[] = {