diff options
| author | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2015-07-25 20:39:14 +0300 |
|---|---|---|
| committer | Artyom V. Poptsov <poptsov.artyom@gmail.com> | 2015-07-25 20:39:14 +0300 |
| commit | 695f276a583113667f5a96c528a212719febe299 (patch) | |
| tree | 0a3dbe738ad5409de87ffb94edf0e69004f49f4d /modules/ssh/message.scm | |
| parent | srfi: Move to 'modules' (diff) | |
| download | guile-ssh-695f276a583113667f5a96c528a212719febe299.tar.gz | |
ssh/*.scm: Move to 'modules/ssh'
* ssh/auth.scm, ssh/channel.scm, ssh/dist.scm, ssh/key.scm, ssh/log.scm,
ssh/message.scm, ssh/server.scm, ssh/session.scm, ssh/tunnel.scm,
ssh/version.scm, ssh/dist/Makefile.am, ssh/dist/job.scm, ssh/dist/node.scm:
Move to 'modules/ssh'.
* ssh/Makefile.am: Update.
* modules/Makefile.am (SUBDIRS): Add 'ssh'.
* .gitignore: Ignore *.go files.
* configure.ac (AC_CONFIG_FILES): Add 'modules/ssh/dist/Makefile'.
Diffstat (limited to 'modules/ssh/message.scm')
| -rw-r--r-- | modules/ssh/message.scm | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/modules/ssh/message.scm b/modules/ssh/message.scm new file mode 100644 index 0000000..8805eab --- /dev/null +++ b/modules/ssh/message.scm @@ -0,0 +1,137 @@ +;;; message.scm -- Procedures for working with SSH messages. + +;; Copyright (C) 2013 Artyom V. Poptsov <poptsov.artyom@gmail.com> +;; +;; This file is a part of Guile-SSH. +;; +;; Guile-SSH is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; Guile-SSH is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Guile-SSH. If not, see <http://www.gnu.org/licenses/>. + + +;;; Commentary: + +;; This module contains message parsing utilites for Guile-SSH +;; servers. +;; +;; Messages can be fetched from the client by calling +;; `server-message-get' procedure. The server can get content of the +;; requests by calling `message-get-req' procedure with a message +;; passed as an arguement. +;; +;; `message-get-req' returns the content of a request as a vector +;; which can be parsed by related procedures such as `auth:req:user' +;; and friends. + +;;; Code: + +(define-module (ssh message) + #:use-module (ssh log) + #:use-module (ssh key) + #:export (message + message? + message-reply-default + message-reply-success + message-get-type + message-get-req + message-get-session + + message-service-reply-success + service-req:service + + channel-open-req:orig channel-open-req:orig-port + channel-open-req:dest channel-open-req:dest-port + + message-auth-reply-success + message-auth-reply-public-key-ok + message-auth-set-methods! + auth-req:user auth-req:password auth-req:pubkey + auth-req:pubkey-state + + message-channel-request-reply-success + message-channel-request-open-reply-accept + + pty-req:term pty-req:width pty-req:height pty-req:pxwidth + pty-req:pxheight + + exec-req:cmd + + env-req:name env-req:value + + global-req:addr global-req:port)) + + +(define (service-req:service req) (vector-ref req 0)) + +(define (channel-open-req:orig req) (vector-ref req 0)) +(define (channel-open-req:orig-port req) (vector-ref req 1)) +(define (channel-open-req:dest req) (vector-ref req 2)) +(define (channel-open-req:dest-port req) (vector-ref req 3)) + +(define (auth-req:user req) (vector-ref req 0)) +(define (auth-req:password req) (vector-ref req 1)) +(define (auth-req:pubkey req) (vector-ref req 2)) +(define (auth-req:pubkey-state req) (vector-ref req 3)) + +(define (pty-req:term req) (vector-ref req 0)) +(define (pty-req:width req) (vector-ref req 1)) +(define (pty-req:height req) (vector-ref req 2)) +(define (pty-req:pxwidth req) (vector-ref req 3)) +(define (pty-req:pxheight req) (vector-ref req 4)) + +(define (env-req:name req) (vector-ref req 0)) +(define (env-req:value req) (vector-ref req 1)) + +(define (exec-req:cmd req) (vector-ref req 0)) + +(define (global-req:addr req) (vector-ref req 0)) +(define (global-req:port req) (vector-ref req 1)) + + +(define (message-reply-success msg . args) + "Reply 'success' to the message MSG. This procedure is a convenient +wrapper for other '*-reply-success' procedures. The right procedure +to use will be selected depending on a type of the message MSG." + (let ((msg-type (message-get-type msg))) + (case (car msg-type) + + ((request-auth) + (cond + ((= (length args) 0) + (message-auth-reply-success msg #f)) + ((= (length args) 1) + (if (and (symbol? (car args)) (eq? (car args) 'partial)) + (message-auth-reply-success msg #t) + (error + (string-append "message-reply-success: " + "Wrong argument. Expected: 'partial") + (car args)))) + (else + (error "message-reply-success: Wrong number of arguments." + args)))) + + ((request-service) + (message-service-reply-success msg)) + + ((request-channel-open) + (message-channel-request-reply-success msg)) + + ((request-channel) + (message-channel-request-reply-success msg)) + + ((request-global) + (error "Not implemented yet" (cadr msg-type)))))) + + +(load-extension "libguile-ssh" "init_message") + +;;; message.scm ends here |
