| 1 | #ifndef EVIDENCE_H_SEEN
|
|---|
| 2 | #define EVIDENCE_H_SEEN
|
|---|
| 3 |
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include <stdarg.h>
|
|---|
| 6 | #include <string>
|
|---|
| 7 | #include <sstream>
|
|---|
| 8 | #include <iomanip>
|
|---|
| 9 | #include <errno.h>
|
|---|
| 10 | #include <vector>
|
|---|
| 11 | #include <map>
|
|---|
| 12 |
|
|---|
| 13 | #include <exception>
|
|---|
| 14 | #include <cxxabi.h>
|
|---|
| 15 |
|
|---|
| 16 | #include "dis.hxx"
|
|---|
| 17 | #include "dic.hxx"
|
|---|
| 18 |
|
|---|
| 19 | #define NO_LINK (char *) "__&DIM&NOLINK&__" // Data if no link available
|
|---|
| 20 | #define EVIDENCE_REVISION "$Revision: 232 $"
|
|---|
| 21 |
|
|---|
| 22 | // Class declation of Evidence server
|
|---|
| 23 | class EvidenceServer: public DimServer {
|
|---|
| 24 |
|
|---|
| 25 | // Internal class for configuration requests
|
|---|
| 26 | class Config: public DimClient, public DimRpcInfo {
|
|---|
| 27 |
|
|---|
| 28 | std::string Name;
|
|---|
| 29 | DimInfo *Service;
|
|---|
| 30 | int ConfigTimeStamp;
|
|---|
| 31 | std::string CurrentItem;
|
|---|
| 32 | pthread_t ThreadID;
|
|---|
| 33 |
|
|---|
| 34 | struct Item {
|
|---|
| 35 | std::string Value;
|
|---|
| 36 | int Time;
|
|---|
| 37 | };
|
|---|
| 38 | std::map<std::string, struct Item> List;
|
|---|
| 39 |
|
|---|
| 40 | public:
|
|---|
| 41 | Config(std::string);
|
|---|
| 42 | ~Config();
|
|---|
| 43 |
|
|---|
| 44 | std::string GetConfig(std::string, std::string);
|
|---|
| 45 | void infoHandler();
|
|---|
| 46 | void rpcInfoHandler();
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | struct Message {
|
|---|
| 50 | int Severity;
|
|---|
| 51 | char Text[];
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | std::string Name;
|
|---|
| 55 | DimService *MessageService;
|
|---|
| 56 | struct Message *MessageData;
|
|---|
| 57 | class Config *ConfClass;
|
|---|
| 58 | static int ConfigSignal; // static since accessed in signal handler
|
|---|
| 59 | pthread_mutex_t Mutex;
|
|---|
| 60 | static EvidenceServer *This;
|
|---|
| 61 |
|
|---|
| 62 | static void SignalHandler(int); // static for signal()
|
|---|
| 63 | static void Terminate(); // static for set_terminate()
|
|---|
| 64 | void errorHandler(int, int, char *);
|
|---|
| 65 | void exitHandler(int);
|
|---|
| 66 | virtual void ConfigChanged() {};
|
|---|
| 67 |
|
|---|
| 68 | public:
|
|---|
| 69 | EvidenceServer(const char *);
|
|---|
| 70 | ~EvidenceServer();
|
|---|
| 71 |
|
|---|
| 72 | enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};
|
|---|
| 73 |
|
|---|
| 74 | void Message(MessageType, const char *, ...);
|
|---|
| 75 | void SendToLog(const char *, ...);
|
|---|
| 76 | std::string GetConfig(std::string, std::string = std::string());
|
|---|
| 77 | void ActivateSignal(int);
|
|---|
| 78 | void Lock();
|
|---|
| 79 | void Unlock();
|
|---|
| 80 | static std::string ToString(char *, void *, int);
|
|---|
| 81 | static bool ServiceOK(DimInfo *);
|
|---|
| 82 | static bool ServiceOK(DimRpcInfo *);
|
|---|
| 83 | static std::vector<std::string> Tokenize(const std::string &, const std::string & = " ");
|
|---|
| 84 |
|
|---|
| 85 | bool ExitRequest;
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | // Class declaration of EvidenceHistory
|
|---|
| 89 | class EvidenceHistory {
|
|---|
| 90 |
|
|---|
| 91 | public:
|
|---|
| 92 | struct Item {
|
|---|
| 93 | int Time;
|
|---|
| 94 | int Size;
|
|---|
| 95 | char Data[]; // Size bytes follow
|
|---|
| 96 | } __attribute__((packed));
|
|---|
| 97 |
|
|---|
| 98 | static const struct Item WrapMark;
|
|---|
| 99 | static const struct Item EndMark;
|
|---|
| 100 |
|
|---|
| 101 | private:
|
|---|
| 102 | std::string Name;
|
|---|
| 103 | char *Buffer;
|
|---|
| 104 | int BufferSize;
|
|---|
| 105 | char *DataStart;
|
|---|
| 106 | struct Item *Pointer;
|
|---|
| 107 |
|
|---|
| 108 | public:
|
|---|
| 109 | EvidenceHistory(std::string);
|
|---|
| 110 | ~EvidenceHistory();
|
|---|
| 111 |
|
|---|
| 112 | bool GetHistory();
|
|---|
| 113 | char *GetFormat();
|
|---|
| 114 | const struct Item *Next();
|
|---|
| 115 | void Rewind();
|
|---|
| 116 | };
|
|---|
| 117 | #endif
|
|---|