Skip to content

Commit fd61f69

Browse files
committed
Another big commit (tm).
Main Changes: - Implement a socket transport layer for use by all code that needs to open some kind of "special" socket for network or IPC. - Extensions can register (and override) transports. - Implement ftruncate() on streams via the ioctl-alike option interface. - Implement mmap() on streams via the ioctl-alike option interface. - Implement generic crypto API via the ioctl-alike option interface. (currently only supports OpenSSL, but could support other SSL toolkits, and other crypto transport protocols). Impact: - tcp sockets can be overloaded by the openssl capable sockets at runtime, removing the link-time requirement for ssl:// and https:// sockets and streams. - checking stream types using PHP_STREAM_IS_SOCKET is deprecated, since there are now a range of possible socket-type streams. Working towards: - socket servers using the new transport layer - mmap support under win32 - Cleaner code. # I will be updating the win32 build to add the new files shortly # after this commit.
1 parent 560e339 commit fd61f69

24 files changed

+2232
-927
lines changed

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ PHP_ADD_SOURCES(main, main.c snprintf.c spprintf.c php_sprintf.c \
11131113
output.c )
11141114

11151115
PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \
1116-
plain_wrapper.c userspace.c)
1116+
plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c)
11171117

11181118
PHP_ADD_SOURCES(/main, internal_functions.c,, sapi)
11191119
PHP_ADD_SOURCES(/main, internal_functions_cli.c,, cli)

ext/dba/libinifile/inifile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC)
8787
int fd = 0;
8888

8989
if (!readonly) {
90-
if (php_stream_is(fp, PHP_STREAM_IS_SOCKET)) {
91-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate sockets");
90+
if (!php_stream_truncate_supported(fp)) {
91+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream");
9292
return NULL;
9393
}
9494
if (SUCCESS != php_stream_cast(fp, PHP_STREAM_AS_FD, (void*)&fd, 1)) {
@@ -320,7 +320,7 @@ static int inifile_truncate(inifile *dba, size_t size TSRMLS_DC)
320320
{
321321
int res;
322322

323-
if ((res=ftruncate(dba->fd, size)) != 0) {
323+
if ((res=php_stream_truncate_set_size(dba->fp, size)) != 0) {
324324
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in ftruncate: %d", res);
325325
return FAILURE;
326326
}

ext/openssl/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dnl $Id$
33
dnl
44

55
if test "$PHP_OPENSSL" != "no"; then
6-
PHP_NEW_EXTENSION(openssl, openssl.c, $ext_openssl_shared)
6+
PHP_NEW_EXTENSION(openssl, openssl.c xp_ssl.c, $ext_openssl_shared)
77
OPENSSL_SHARED_LIBADD="-lcrypto -lssl"
88
PHP_SUBST(OPENSSL_SHARED_LIBADD)
99
AC_DEFINE(HAVE_OPENSSL_EXT,1,[ ])

ext/openssl/openssl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ PHP_MINIT_FUNCTION(openssl)
608608
} else {
609609
strlcpy(default_ssl_conf_filename, config_filename, sizeof(default_ssl_conf_filename));
610610
}
611+
612+
php_stream_xport_register("ssl", php_openssl_ssl_socket_factory TSRMLS_CC);
613+
php_stream_xport_register("tls", php_openssl_ssl_socket_factory TSRMLS_CC);
614+
615+
/* override the default tcp socket provider */
616+
php_stream_xport_register("tcp", php_openssl_ssl_socket_factory TSRMLS_CC);
617+
611618
return SUCCESS;
612619
}
613620
/* }}} */
@@ -628,6 +635,13 @@ PHP_MINFO_FUNCTION(openssl)
628635
PHP_MSHUTDOWN_FUNCTION(openssl)
629636
{
630637
EVP_cleanup();
638+
639+
php_stream_xport_unregister("ssl" TSRMLS_CC);
640+
php_stream_xport_unregister("tls" TSRMLS_CC);
641+
642+
/* reinstate the default tcp handler */
643+
php_stream_xport_register("tcp", php_stream_generic_socket_factory TSRMLS_CC);
644+
631645
return SUCCESS;
632646
}
633647
/* }}} */

ext/openssl/php_openssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
extern zend_module_entry openssl_module_entry;
2727
#define phpext_openssl_ptr &openssl_module_entry
2828

29+
php_stream_transport_factory_func php_openssl_ssl_socket_factory;
30+
2931
PHP_MINIT_FUNCTION(openssl);
3032
PHP_MSHUTDOWN_FUNCTION(openssl);
3133
PHP_MINFO_FUNCTION(openssl);

0 commit comments

Comments
 (0)