1 | #ifndef EVIDENCE_H_SEEN
|
---|
2 | #define EVIDENCE_H_SEEN
|
---|
3 |
|
---|
4 | #include <stdio.h>
|
---|
5 | #include <stdarg.h>
|
---|
6 | #include <string>
|
---|
7 | #include <errno.h>
|
---|
8 | #include <vector>
|
---|
9 | #include <exception>
|
---|
10 | #include <cxxabi.h>
|
---|
11 |
|
---|
12 | #include "dis.hxx"
|
---|
13 | #include "dic.hxx"
|
---|
14 |
|
---|
15 | #define NO_LINK (char *) "__&DIM&NOLINK&__" // Data if no link available
|
---|
16 | #define STATUS_SIZE 1000 // Bytes for status service string
|
---|
17 | #define EVIDENCE_REVISION "$Revision: 224 $"
|
---|
18 |
|
---|
19 | // Class declation of Evidence server
|
---|
20 | class EvidenceServer: public DimServer {
|
---|
21 |
|
---|
22 | private:
|
---|
23 | // This class will contain in LastModifyTime always
|
---|
24 | // the unix time of the last config file update
|
---|
25 | class ConfigUpdate: public DimClient, public DimRpcInfo {
|
---|
26 | DimInfo *ModifyInfo;
|
---|
27 |
|
---|
28 | public:
|
---|
29 | ConfigUpdate(): DimRpcInfo("ConfigRequest", NO_LINK) {
|
---|
30 | LastModifyTime = 0;
|
---|
31 | ModifyInfo = new DimInfo("Config/ModifyTime", NO_LINK, this);
|
---|
32 | }
|
---|
33 | ~ConfigUpdate() {
|
---|
34 | delete ModifyInfo;
|
---|
35 | }
|
---|
36 | void Request(const char *What){
|
---|
37 | setData((char *) What);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void infoHandler(){
|
---|
41 | if (EvidenceServer::ServiceOK(getInfo())) LastModifyTime = getInfo()->getInt();
|
---|
42 | }
|
---|
43 |
|
---|
44 | void rpcInfoHandler(){
|
---|
45 | //printf("Received %s\n", getString());
|
---|
46 | }
|
---|
47 |
|
---|
48 | int LastModifyTime;
|
---|
49 | };
|
---|
50 |
|
---|
51 | private:
|
---|
52 |
|
---|
53 | struct ConfigItem {
|
---|
54 | std::string Name;
|
---|
55 | char *Value;
|
---|
56 | int Time;
|
---|
57 | };
|
---|
58 | std::vector<struct ConfigItem> ConfigList;
|
---|
59 |
|
---|
60 | struct Message {
|
---|
61 | int Severity;
|
---|
62 | char Text[];
|
---|
63 | };
|
---|
64 |
|
---|
65 | std::string ServerName;
|
---|
66 | DimService *MessageService;
|
---|
67 | struct Message *MessageData;
|
---|
68 | class ConfigUpdate *ModifyInfo;
|
---|
69 |
|
---|
70 | static void SignalHandler(int); // static for signal()
|
---|
71 | static void Terminate(); // static for set_terminate()
|
---|
72 | void errorHandler(int, int, char *);
|
---|
73 | void exitHandler(int);
|
---|
74 |
|
---|
75 | public:
|
---|
76 | EvidenceServer(const char *);
|
---|
77 | ~EvidenceServer();
|
---|
78 |
|
---|
79 | enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};
|
---|
80 |
|
---|
81 | void Message(MessageType, const char *, ...);
|
---|
82 | void SendToLog(const char *, ...);
|
---|
83 | char* GetConfig(std::string, const char * = NULL);
|
---|
84 | static char* ToString(DimInfo *);
|
---|
85 | static bool ServiceOK(DimInfo *);
|
---|
86 | static bool ServiceOK(DimRpcInfo *);
|
---|
87 |
|
---|
88 | bool ExitRequest;
|
---|
89 | };
|
---|
90 |
|
---|
91 | class EvidenceHistory {
|
---|
92 |
|
---|
93 | public:
|
---|
94 | struct Item {
|
---|
95 | int Time;
|
---|
96 | int Size;
|
---|
97 | char Data[]; // Size bytes follow
|
---|
98 | } __attribute__((packed));
|
---|
99 |
|
---|
100 | static const struct Item WrapMark;
|
---|
101 | static const struct Item EndMark;
|
---|
102 |
|
---|
103 | private:
|
---|
104 | std::string Name;
|
---|
105 | char *Buffer;
|
---|
106 | int BufferSize;
|
---|
107 | char *DataStart;
|
---|
108 | struct Item *Pointer;
|
---|
109 |
|
---|
110 | public:
|
---|
111 | EvidenceHistory(std::string);
|
---|
112 | ~EvidenceHistory();
|
---|
113 |
|
---|
114 | bool GetHistory();
|
---|
115 | char *GetFormat();
|
---|
116 | const struct Item *Next();
|
---|
117 | void Rewind();
|
---|
118 | };
|
---|
119 | #endif
|
---|