1 module libssh.message;
2 
3 import libssh.c_bindings.libssh;
4 import libssh.c_bindings.server;
5 import libssh.utils;
6 import libssh.errors;
7 import libssh.session;
8 import libssh.key;
9 
10 class SSHMessage : Disposable {
11 
12     @property int type() {
13         auto rc = ssh_message_type(this._message);
14         if (rc < 0) {
15             throw new SSHException(this._parent._session);
16         }
17         return rc;
18     }
19 
20     @property int subtype() {
21         auto rc = ssh_message_subtype(this._message);
22         if (rc < 0) {
23             throw new SSHException(this._parent._session);
24         }
25         return rc;
26     }
27 
28 
29 
30     @property string authUser() {
31         auto result = ssh_message_auth_user(this._message);
32         if (result is null) {
33             throw new SSHException(this._parent._session);
34         }
35         return fromStrZ(result);
36     }
37 
38     @property string authPassword() {
39         auto result = ssh_message_auth_password(this._message);
40         if (result is null) {
41             throw new SSHException(this._parent._session);
42         }
43         return fromStrZ(result);
44     }    
45 
46     @property SSHKey authPubKey() {
47         auto result = ssh_message_auth_pubkey(this._message);
48         return result is null ? null : new SSHKey(result);
49     }
50 
51     @property void authMethods(AuthMethod m) {
52         ssh_message_auth_set_methods(this._message, cast(int) m);
53     }
54 
55     void replyDefault() {
56         auto rc = ssh_message_reply_default(this._message);
57         if (rc != SSH_OK) {
58             throw new SSHException(this._parent._session);
59         }
60     }
61 
62 
63     override void dispose() {
64         this._dispose(false);
65     }
66     
67     ~this() {
68         this._dispose(true);
69     }
70     
71     package {
72         this(SSHSession parent, ssh_message message) {
73             this._parent = parent;
74             this._message = message;
75         }
76 
77         SSHSession _parent;
78         ssh_message _message;
79     }
80     
81     private {
82         void _dispose(bool fromDtor) {
83             if (this._message !is null) {
84                 ssh_message_free(this._message);
85                 this._message = null;
86             }
87         }
88     }
89 }