summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom V. Poptsov <poptsov.artyom@gmail.com>2017-01-01 08:30:07 +0300
committerArtyom V. Poptsov <poptsov.artyom@gmail.com>2017-01-01 08:30:07 +0300
commitb0ed60594dbfaa9c995d9a9468c894b81dee5cd6 (patch)
tree66a6a841eab95acf3fcc9295576c18f01d485bb5
parentnode.scm (node-loadavg): New procedure (diff)
downloadguile-ssh-wip-session-set-improvement.tar.gz
session.scm (session-set!): Accept keywordswip-session-set-improvement
* modules/ssh/session.scm (session-set!): Add new version that accepts keywords. Export it. (set-config!): New procedure. (make-session): Use the new version of 'session-set!'. * libguile-ssh/session-func.c (guile_ssh_session_set): Rename the Scheme procedure to "%session-set!". * tests/session.scm ("session-set!, invalid values", "session-set!, valid values"): Update.
-rw-r--r--libguile-ssh/session-func.c2
-rw-r--r--modules/ssh/session.scm65
-rw-r--r--tests/session.scm4
3 files changed, 49 insertions, 22 deletions
diff --git a/libguile-ssh/session-func.c b/libguile-ssh/session-func.c
index b552df4..3bc7f4e 100644
--- a/libguile-ssh/session-func.c
+++ b/libguile-ssh/session-func.c
@@ -381,7 +381,7 @@ set_option (SCM scm_session, struct session_data* sd, int type, SCM value)
}
/* Set a SSH option. Return #t on success, #f on error. */
-SCM_DEFINE (guile_ssh_session_set, "session-set!", 3, 0, 0,
+SCM_DEFINE (guile_ssh_session_set, "%session-set!", 3, 0, 0,
(SCM session, SCM option, SCM value),
"\
Set a SSH option OPTION. Throw an guile-ssh-error on error.\n\
diff --git a/modules/ssh/session.scm b/modules/ssh/session.scm
index 96d0f91..273b3af 100644
--- a/modules/ssh/session.scm
+++ b/modules/ssh/session.scm
@@ -53,6 +53,7 @@
session-parse-config!
blocking-flush!
session-set!
+ %session-set!
session-get
get-protocol-version
connect!
@@ -65,19 +66,25 @@
;; Set a SSH option if it is specified by the user
(define-macro (session-set-if-specified! option)
- `(if ,option (session-set! session (quote ,option) ,option)))
+ `(if ,option (%session-set! session (quote ,option) ,option)))
-;; This procedure is more convenient than primitive `%make-session',
-;; but on other hand it should be a bit slower because of additional
-;; checks. I think we can put up with this. -avp
-(define* (make-session #:key host port user ssh-dir identity add-identity
+(define (set-config! session config)
+ (cond
+ ((string? config)
+ (%gssh-session-parse-config! session config))
+ ((boolean? config)
+ (%gssh-session-parse-config! session #f))
+ (else
+ (throw 'guile-ssh-error "Wrong 'config' value" config))))
+
+(define* (session-set! session
+ #:key host port user ssh-dir identity add-identity
knownhosts timeout timeout-usec ssh1 ssh2 log-verbosity
ciphers-c-s ciphers-s-c compression-c-s compression-s-c
proxycommand stricthostkeycheck compression
compression-level callbacks config)
- "Make a new SSH session with specified configuration.\n
-Return a new SSH session."
- (let ((session (%make-session)))
+ "Set a SSH option for a SESSION. Throw an guile-ssh-error on error.
+Return value is undefined."
(session-set-if-specified! host)
(session-set-if-specified! port)
(session-set-if-specified! user)
@@ -99,19 +106,39 @@ Return a new SSH session."
(session-set-if-specified! compression)
(session-set-if-specified! compression-level)
(session-set-if-specified! callbacks)
-
(when config
- (or host
- (throw 'guile-ssh-error
- "'config' is specified, but 'host' option is missed."))
- (cond
- ((string? config)
- (%gssh-session-parse-config! session config))
- ((boolean? config)
- (%gssh-session-parse-config! session #f))
- (else
- (throw 'guile-ssh-error "Wrong 'config' value" config))))
+ (unless host
+ (throw 'guile-ssh-error
+ "'config' is specified, but 'host' option is missed."))
+ (set-config! session config)))
+;; This procedure is more convenient than primitive `%make-session',
+;; but on other hand it should be a bit slower because of additional
+;; checks. I think we can put up with this. -avp
+(define* (make-session #:key host port user ssh-dir identity add-identity
+ knownhosts timeout timeout-usec ssh1 ssh2 log-verbosity
+ ciphers-c-s ciphers-s-c compression-c-s compression-s-c
+ proxycommand stricthostkeycheck compression
+ compression-level callbacks config)
+ "Make a new SSH session with specified configuration.\n
+Return a new SSH session."
+ (let ((session (%make-session)))
+ (session-set! session
+ #:host host #:port port #:user user
+ #:ssh-dir ssh-dir #:identity identity
+ #:add-identity add-identity
+ #:knownhosts knownhosts #:timeout timeout
+ #:timeout-usec timeout-usec #:ssh1 ssh1 #:ssh2 ssh2
+ #:log-verbosity log-verbosity
+ #:ciphers-c-s ciphers-c-s #:ciphers-s-c ciphers-s-c
+ #:compression-c-s compression-c-s
+ #:compression-s-c compression-s-c
+ #:proxycommand proxycommand
+ #:stricthostkeycheck stricthostkeycheck
+ #:compression compression
+ #:compression-level compression-level
+ #:callbacks callbacks
+ #:config config)
session))
(define* (session-parse-config! session #:optional file-name)
diff --git a/tests/session.scm b/tests/session.scm
index bfce279..fb5fa45 100644
--- a/tests/session.scm
+++ b/tests/session.scm
@@ -74,7 +74,7 @@
(lambda (opt)
(for-each
(lambda (val)
- (session-set! session (car opt) val))
+ (%session-set! session (car opt) val))
(cdr opt)))
options)
res))
@@ -101,7 +101,7 @@
(lambda (val)
(catch #t
(lambda ()
- (session-set! session (car opt) val)
+ (%session-set! session (car opt) val)
(let* ((r (test-runner-current))
(l (test-runner-aux-value r)))
(format l " opt: ~a, val: ~a -- passed mistakenly~%"