php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63702
Patch patch.63702 revision 2014-01-08 07:55 UTC by aaron at servergrove dot com

Patch patch.63702 for ssh2 Bug #63702

Patch version 2014-01-08 07:55 UTC

Return to Bug #63702 | Download this patch
Patch Revisions:

Developer: aaron@servergrove.com

diff --git a/php_ssh2.h b/php_ssh2.h
index a760f4e..50fab9c 100644
--- a/php_ssh2.h
+++ b/php_ssh2.h
@@ -178,6 +178,7 @@ PHP_FUNCTION(ssh2_tunnel);
 PHP_FUNCTION(ssh2_scp_recv);
 PHP_FUNCTION(ssh2_scp_send);
 PHP_FUNCTION(ssh2_fetch_stream);
+PHP_FUNCTION(ssh2_shell_resize);
 
 /* In ssh2_sftp.c */
 PHP_FUNCTION(ssh2_sftp);
diff --git a/ssh2.c b/ssh2.c
index f232c41..1b35346 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -1372,6 +1372,7 @@ zend_function_entry ssh2_functions[] = {
 	PHP_FE(ssh2_scp_send,						NULL)
 	PHP_FE(ssh2_fetch_stream,					NULL)
 	PHP_FE(ssh2_poll,							php_ssh2_first_arg_force_ref)
+	PHP_FE(ssh2_shell_resize,						NULL)
 
 	/* SFTP Stuff */
 	PHP_FE(ssh2_sftp,							NULL)
diff --git a/ssh2_fopen_wrappers.c b/ssh2_fopen_wrappers.c
index 39e196c..883ee76 100644
--- a/ssh2_fopen_wrappers.c
+++ b/ssh2_fopen_wrappers.c
@@ -532,6 +532,29 @@ static php_stream *php_ssh2_shell_open(LIBSSH2_SESSION *session, int resource_id
 }
 /* }}} */
 
+/* {{{ php_ssh2_shell_resize
+ * Resize the shell for a stream
+ */
+static int php_ssh2_shell_resize(php_stream *stream, long width, long height, long type TSRMLS_DC)
+{
+	php_ssh2_channel_data *abstract = (php_ssh2_channel_data*)stream->abstract;
+
+	if (type == PHP_SSH2_TERM_UNIT_CHARS) {
+		if (libssh2_channel_request_pty_size_ex(abstract->channel, width, height, 0, 0)) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed resizing pty to %ldx%ld characters", width, height);
+			return -1;
+		}
+	} else {
+		if (libssh2_channel_request_pty_size_ex(abstract->channel, 0, 0, width, height)) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed resizing pty tot %ldx%ld pixels", width, height);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+/* }}} */
+
 /* {{{ php_ssh2_fopen_wrapper_shell
  * ssh2.shell:// fopen wrapper
  */
@@ -695,6 +718,33 @@ PHP_FUNCTION(ssh2_shell)
 }
 /* }}} */
 
+/* {{{ proto stream ssh2_shell_resize(resource stream[, int width, int height[, int width_height_type]])
+ * Resize an open shell
+ */
+PHP_FUNCTION(ssh2_shell_resize)
+{
+	php_stream *stream;
+	zval *zstream;
+	long width = PHP_SSH2_DEFAULT_TERM_WIDTH;
+	long height = PHP_SSH2_DEFAULT_TERM_HEIGHT;
+	long type = PHP_SSH2_DEFAULT_TERM_UNIT;
+	int argc = ZEND_NUM_ARGS();
+
+	if (argc == 2) {
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "width specified without height parameter");
+		RETURN_FALSE;
+	}
+
+	if (zend_parse_parameters(argc TSRMLS_CC, "r|ll|l", &zstream, &width, &height, &type) == FAILURE) {
+		return;
+	}
+
+	php_stream_from_zval(stream, &zstream);
+
+	RETURN_BOOL(php_ssh2_shell_resize(stream, width, height, type)); 
+}
+/* }}} */
+
 /* ****************
    * Exec Wrapper *
    **************** */
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 05:01:26 2024 UTC