summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--NEWS1
-rw-r--r--doc/api-sessions.texi14
-rw-r--r--ssh/session-func.c34
-rw-r--r--ssh/session-func.h1
-rw-r--r--ssh/session.scm2
-rw-r--r--tests/session.scm16
7 files changed, 78 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b7f81bd..adbc3eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-06-22 Artyom Poptsov <poptsov.artyom@gmail.com>
+
+ * ssh/session-func.c (guile_ssh_session_get): New procedure.
+ * ssh/session-func.h (guile_ssh_session_get): Likewise.
+ * ssh/session.scm (session-get): New procedure.
+ * tests/session.scm ("session-get"): New TC.
+ * doc/api-sessions.texi (Sessions): Add description of `session-get'
+ procedure.
+ * NEWS: Update.
+
2014-06-21 Artyom Poptsov <poptsov.artyom@gmail.com>
* tests/client-server.scm (spawn-server-thread): Catch all exceptions
diff --git a/NEWS b/NEWS
index 1372676..d270410 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ Copyright (C) Artyom V. Poptsov <poptsov.artyom@gmail.com>
** Rename `userauth-pubkey-auto!' to `userauth-public-key/auto!'
** New `userauth-public-key/try' procedure in (ssh auth)
** New `bytevector->hex-string' procedure in (ssh key)
+** New `session-get' procedure in (ssh session)
** Changes in tests
*** Add tests for Guile-SSH keys
*** Add tests for `authenticate-server' procedure
diff --git a/doc/api-sessions.texi b/doc/api-sessions.texi
index e1b3ef8..ed2dcea 100644
--- a/doc/api-sessions.texi
+++ b/doc/api-sessions.texi
@@ -212,7 +212,21 @@ is expected to be a number from 1 to 9, 9 being the most efficient but
slower.
@end table
+@end deffn
+
+@deffn {Scheme Procedure} session-get session option
+Get value of the @var{option} for @var{session}. The @var{option} is expected
+to be a symbol.
+
+Please not that currently not all the possible session options can be gotten
+with this procedure. Here is the list of allowed options:
+@table @samp
+@item host
+@item user
+@item identity
+@item proxycommand
+@end table
@end deffn
@deffn {Scheme Procedure} connect! session
diff --git a/ssh/session-func.c b/ssh/session-func.c
index b719e6f..bc23256 100644
--- a/ssh/session-func.c
+++ b/ssh/session-func.c
@@ -269,6 +269,40 @@ SCM_DEFINE (guile_ssh_session_set, "session-set!", 3, 0, 0,
}
#undef FUNC_NAME
+
+/* Options whose values can be requested through `session-get' */
+static struct symbol_mapping session_options_getable[] = {
+ { "host", SSH_OPTIONS_HOST },
+ { "user", SSH_OPTIONS_USER },
+ { "identity", SSH_OPTIONS_IDENTITY },
+ { "proxycommand", SSH_OPTIONS_PROXYCOMMAND },
+ { NULL, -1 }
+};
+
+SCM_DEFINE (guile_ssh_session_get, "session-get", 2, 0, 0,
+ (SCM session, SCM option),
+ "")
+#define FUNC_NAME s_guile_ssh_session_get
+{
+ struct session_data*sd = _scm_to_ssh_session (session);
+ struct symbol_mapping *opt = NULL;
+ char *value = NULL; /* Value of the option */
+ int res;
+
+ SCM_ASSERT (scm_is_symbol (option), option, SCM_ARG2, FUNC_NAME);
+
+ opt = _scm_to_ssh_const (session_options_getable, option);
+ if (! opt)
+ guile_ssh_error1 (FUNC_NAME, "Wrong option", option);
+
+ res = ssh_options_get (sd->ssh_session, opt->value, &value);
+ if (res == SSH_ERROR)
+ guile_ssh_error1 (FUNC_NAME, "Unable to get value of the option", option);
+
+ return scm_from_locale_string (value);
+}
+#undef FUNC_NAME
+
/* Connect to the SSH server.
Return one of the following symbols: 'ok, 'again */
diff --git a/ssh/session-func.h b/ssh/session-func.h
index db7fc84..a18a263 100644
--- a/ssh/session-func.h
+++ b/ssh/session-func.h
@@ -23,6 +23,7 @@
extern SCM guile_ssh_blocking_flush (SCM arg1, SCM arg2);
extern SCM guile_ssh_session_set (SCM arg1, SCM arg2, SCM arg3);
+extern SCM guile_ssh_session_get (SCM arg1, SCM arg2);
extern SCM guile_ssh_get_version (SCM arg1);
extern SCM guile_ssh_is_connected_p (SCM arg1);
extern SCM guile_ssh_connect_x (SCM arg1);
diff --git a/ssh/session.scm b/ssh/session.scm
index d5be9eb..c1b072f 100644
--- a/ssh/session.scm
+++ b/ssh/session.scm
@@ -29,6 +29,7 @@
;; make-session
;; blocking-flush!
;; session-set!
+;; session-get
;; get-protocol-version
;; connect!
;; disconnect!
@@ -49,6 +50,7 @@
make-session
blocking-flush!
session-set!
+ session-get
get-protocol-version
connect!
disconnect!
diff --git a/tests/session.scm b/tests/session.scm
index 5a62649..0175ad1 100644
--- a/tests/session.scm
+++ b/tests/session.scm
@@ -22,6 +22,9 @@
(test-begin "session")
+(define %topdir (getenv "abs_top_srcdir"))
+(define %rsakey (format #f "~a/tests/rsakey" %topdir))
+
(test-assert "%make-session"
(%make-session))
@@ -93,6 +96,19 @@
options)
res))
+(test-assert "session-get"
+ (let* ((host "example.com")
+ (user "alice")
+ (proxycommand "test")
+ (session (make-session #:host host
+ #:user user
+ #:identity %rsakey
+ #:proxycommand proxycommand)))
+ (and (string=? (session-get session 'host) host)
+ (string=? (session-get session 'user) user)
+ (string=? (session-get session 'identity) %rsakey)
+ (string=? (session-get session 'proxycommand) proxycommand))))
+
(test-assert "make-session"
(make-session #:host "localhost"
#:port 22