~ubuntu-branches/ubuntu/oneiric/procserv/oneiric

« back to all changes in this revision

Viewing changes to telnetStateMachine.h

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Lange
  • Date: 2010-01-04 16:19:35 UTC
  • Revision ID: james.westby@ubuntu.com-20100104161935-uaosvjyry3zc5l5l
Tags: upstream-2.5.0
ImportĀ upstreamĀ versionĀ 2.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Process server for soft ioc
 
2
// David H. Thompson 8/29/2003
 
3
// Ralph Lange 04/25/2008
 
4
// GNU Public License (GPLv3) applies - see www.gnu.org
 
5
 
 
6
#ifndef telnetStateMachineH
 
7
#define telnetStateMachineH
 
8
 
 
9
#include <arpa/telnet.h>
 
10
int TelnetStateMachine(char * buf,int len); // Returns new length
 
11
#define OPT_STRING_LEN 32
 
12
 
 
13
class telnetStateMachine
 
14
{
 
15
public:
 
16
    telnetStateMachine();
 
17
    void SetConnectionItem(connectionItem * item)
 
18
    {
 
19
        _item=item;
 
20
        sendInitialRequests();
 
21
    }
 
22
    int OnReceive(char * buf,int len,bool priority=false);
 
23
 
 
24
 
 
25
private:
 
26
    signed char _buf[128]; // Where to put data after an IAC
 
27
    int _count; // This is normally -1, after IAC it is 0 + chars received
 
28
    int _expected; // When to process the command
 
29
    connectionItem * _item; // This is the client that owns us
 
30
 
 
31
    // 0==> I don't care
 
32
    // The constructor will set the ones that I want to negotiate
 
33
    // If the server wants to negotiate then he will probably get a wont or dont
 
34
    unsigned char _myOpts[NTELOPTS]; // Either I will, I wont, I do, I dont
 
35
    unsigned char _otherOpts[NTELOPTS]; // Will he, wont he, he does, he does not.
 
36
    unsigned char _myOptArg[NTELOPTS][OPT_STRING_LEN]; // Either I will, I wont, I do, I dont
 
37
    unsigned char _otherOptArg[NTELOPTS][OPT_STRING_LEN]; // Will he, wont he, he does, he does not.
 
38
    unsigned char _myOptArgLen[NTELOPTS]; // Either I will, I wont, I do, I dont
 
39
    unsigned char _otherOptArgLen[NTELOPTS]; // Will he, wont he, he does, he does not.
 
40
 
 
41
private: // Methods
 
42
    void sendReply( int opt0, int opt1=-1,int opt2=-1, int opt3=-1,int opt4=-1);
 
43
    void doCommand(); // The state is in _buf[]/_count;
 
44
    void sendInitialRequests();
 
45
 
 
46
    bool onChar(unsigned char c);
 
47
    void onDo(unsigned char opt);
 
48
    void onDont(unsigned char opt);
 
49
    void onWill(unsigned char opt);
 
50
    void onWont(unsigned char opt);
 
51
    void onOpt(unsigned char opt);
 
52
    
 
53
    enum state
 
54
    {
 
55
        ON_START,
 
56
        ON_IAC,
 
57
        ON_DO,
 
58
        ON_DONT,
 
59
        ON_WILL,
 
60
        ON_WONT,
 
61
        ON_SB,
 
62
        ON_SE,
 
63
        ON_DATA,
 
64
        ON_END  
 
65
    } _myState;
 
66
    unsigned char _workingOpt; // Used in state ON_OPT
 
67
};
 
68
 
 
69
#endif /*#ifndef telnetStateMachineH */