Newer
Older
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
#ifndef SLD_HH
# define SLD_HH
# include <cassert>
# include <ios>
# include <iostream>
# include <fstream>
# include <sstream>
# include <map>
# include "error.hh"
typedef std::string string;
typedef std::stringstream sstream;
typedef std::ostream ostream;
typedef std::ifstream ifstream;
enum {
EXIT_OK = 0,
EXIT_USAGE = 1,
EXIT_BADPARAM = 2,
EXIT_FILE = 3,
EXIT_NET = 4,
EXIT_PROTO = 5,
EXIT_NOMEM = 41,
EXIT_UNKNOWN = 42
};
// -----------------------------------------------------------------------------
// Gonstant
// -----------------------------------------------------------------------------
const string VERSION = "1";
const int RECV_BUF_SIZE = 512;
// -----------------------------------------------------------------------------
// SLDAEMON CLASS
// -----------------------------------------------------------------------------
class SLDaemon
{
public:
static const string version;
struct options {
options();
string host;
int port;
string user;
string pass;
int verbose; //0=false, 1=true, 3=undef
string scriptdir;
string conffile;
};
options *getoptions(int argc, char *argv[]) const;
options *getoptions(const string file) const;
void applyoptions(const options *opt);
void run();
protected:
// parsed options
options options_;
// current socket
int socket_;
// receive buffer
int recv_buf_[RECV_BUF_SIZE];
char *recv_line_;
size_t recv_offset_;
size_t recv_size_;
// functions
void usage(const char *argv0) const;
void check_options() const;
void connect();
void send(const char *data, size_t len);
void send(const string str);
char *recv();
void bufferize(char **str, const char *append, size_t n);
void protocol_violation();
void auth();
inline bool verbose() const { return options_.verbose == 1; }
void cmd_version();
void cmd_exit();
void cmd_update();
void cmd_exec(const char *line);
void cmd_file(const char *line);
};
#endif