File: nxsession.h

package info (click to toggle)
nxcl 0.9-3.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 560 kB
  • ctags: 412
  • sloc: cpp: 3,149; makefile: 114
file content (187 lines) | stat: -rw-r--r-- 6,011 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/***************************************************************************
                                 nxsession.h
                             -------------------
    begin                : Sat 22nd July 2006
    modifications        : July 2007
    copyright            : (C) 2006 by George Wright
    modifications        : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
                         :     Author: Sebastian James
                         : (C) 2008 Defuturo Ltd
                         :     Author: George Wright
    email                : seb@esfnet.co.uk, gwright@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _NXSESSION_H_
#define _NXSESSION_H_

#include <sstream>
#include <fstream>
#include <fcntl.h>
#include <unistd.h>
#include "nxdata.h"
#include <list>

namespace nxcl {

    /*!
     * Virtual Callback class. These callbacks are called based on
     * the output which we get from the nxssh process.
     */
    class NXSessionCallbacks
    {
        public:
            NXSessionCallbacks() {}
            virtual ~NXSessionCallbacks() {}
            virtual void noSessionsSignal (void) {}
            virtual void loginFailedSignal (void) {}
            virtual void readyForProxySignal (void) {}
            /*!
             * Emitted when the initial public key authentication
             * is successful 
             */
            virtual void authenticatedSignal (void) {}
            virtual void sessionsSignal (list<NXResumeData>) {}
    };

    /*!
     * This class is used to parse the output from the nxssh
     * session to the server.
     */
    class NXSession
    {
        public:
            NXSession();
            ~NXSession();

            string parseSSH (string);
            int parseResponse (string);
            void parseResumeSessions (list<string>);
            void resetSession (void);
            void wipeSessions (void);
            bool chooseResumable (int n);
            bool terminateSession (int n);
            string generateCookie (void);
            void runSession (void) { sessionDataSet = true; }

            /*!
             * Accessors
             */
            //@{
            void setUsername (string& user) { nxUsername = user; }
            void setPassword (string& pass) { nxPassword = pass; }
            void setResolution (int x, int y) 
            {
                this->sessionData->xRes = x;
                this->sessionData->yRes = y;
            }

            void setDepth (int d) 
            {
                this->sessionData->depth = d;
            }

            void setRender (bool isRender)
            {
                if (this->sessionDataSet) {
                    this->sessionData->render = isRender;
                }
            }

            void setEncryption (bool enc)
            {
                if (this->sessionDataSet) {
                    this->sessionData->encryption = enc;
                }
            }

            void setContinue (bool allow)
            {
                doSSH = allow;
            }

            void setSessionData (NXSessionData*);

            NXSessionData* getSessionData()
            {
                return this->sessionData;
            }

            bool getSessionDataSet (void)
            {
                return this->sessionDataSet;
            }

            void setCallbacks (NXSessionCallbacks * cb) 
            {
                this->callbacks = cb;
            }
            //@}

        private:
            void reset (void);
            void fillRand(unsigned char *, size_t);

            /*!
             * This is the answer to give to the ssh server if it
             * asks whether we want to continue (say, if we're
             * connecting for the first time and we don't
             * necessarily trust its SSL key).
             */
            bool doSSH;
            /*!
             * Set to true if there are suspended sessions on the
             * server which are owned by nxUsername.
             */
            bool suspendedSessions;
            /*!
             * Set to true of sessionData has been populated
             */
            bool sessionDataSet;
            /*!
             * Holds the stage of the process which we have
             * reached as we go through the process of
             * authenticating with the NX Server.
             */
            int stage;
            /*!
             * File descriptor for the random number device
             */
            int devurand_fd;
            /*!
             * Holds the username for this session
             */
            string nxUsername;
            /*!
             * Holds the password for this session
             */
            string nxPassword;
            /*!
             * A list of sessions which can be resumed, as strings.
             */
            list<string> resumeSessions;
            /*!
             * A list of running sessions, held as NXResumeData
             * structures.
             */
            list<NXResumeData> runningSessions;
            /*!
             * Data for this session.
             */
            NXSessionData *sessionData;
            /*!
             * Pointer to a class containing callback methods.
             */
            NXSessionCallbacks * callbacks;
    };

} // namespace
#endif