| 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: 231 $"
|
|---|
| 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 | pthread_mutex_t Mutex;
|
|---|
| 29 | std::string Name;
|
|---|
| 30 | DimInfo *Service;
|
|---|
| 31 | int ConfigTimeStamp;
|
|---|
| 32 | std::string CurrentItem;
|
|---|
| 33 | pthread_t ThreadID;
|
|---|
| 34 |
|
|---|
| 35 | struct Item {
|
|---|
| 36 | std::string Value;
|
|---|
| 37 | int Time;
|
|---|
| 38 | };
|
|---|
| 39 | std::map<std::string, struct Item> List;
|
|---|
| 40 |
|
|---|
| 41 | public:
|
|---|
| 42 | Config(std::string);
|
|---|
| 43 | ~Config();
|
|---|
| 44 |
|
|---|
| 45 | std::string GetConfig(std::string, std::string);
|
|---|
| 46 | void Lock();
|
|---|
| 47 | void Unlock();
|
|---|
| 48 | void infoHandler();
|
|---|
| 49 | void rpcInfoHandler();
|
|---|
| 50 | };
|
|---|
| 51 |
|
|---|
| 52 | struct Message {
|
|---|
| 53 | int Severity;
|
|---|
| 54 | char Text[];
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | std::string Name;
|
|---|
| 58 | DimService *MessageService;
|
|---|
| 59 | struct Message *MessageData;
|
|---|
| 60 | class Config *ConfClass;
|
|---|
| 61 | static int ConfigSignal; // static since accessed in signal handler
|
|---|
| 62 |
|
|---|
| 63 | static void SignalHandler(int); // static for signal()
|
|---|
| 64 | static void Terminate(); // static for set_terminate()
|
|---|
| 65 | void errorHandler(int, int, char *);
|
|---|
| 66 | void exitHandler(int);
|
|---|
| 67 | virtual void ConfigChanged() {};
|
|---|
| 68 |
|
|---|
| 69 | public:
|
|---|
| 70 | EvidenceServer(const char *);
|
|---|
| 71 | ~EvidenceServer();
|
|---|
| 72 |
|
|---|
| 73 | enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};
|
|---|
| 74 |
|
|---|
| 75 | void Message(MessageType, const char *, ...);
|
|---|
| 76 | void SendToLog(const char *, ...);
|
|---|
| 77 | std::string GetConfig(std::string, std::string = std::string());
|
|---|
| 78 | void ActivateSignal(int);
|
|---|
| 79 | static std::string ToString(DimInfo *);
|
|---|
| 80 | static bool ServiceOK(DimInfo *);
|
|---|
| 81 | static bool ServiceOK(DimRpcInfo *);
|
|---|
| 82 | static std::vector<std::string> Tokenize(const std::string &, const std::string & = " ");
|
|---|
| 83 |
|
|---|
| 84 | bool ExitRequest;
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | class EvidenceHistory {
|
|---|
| 88 |
|
|---|
| 89 | public:
|
|---|
| 90 | struct Item {
|
|---|
| 91 | int Time;
|
|---|
| 92 | int Size;
|
|---|
| 93 | char Data[]; // Size bytes follow
|
|---|
| 94 | } __attribute__((packed));
|
|---|
| 95 |
|
|---|
| 96 | static const struct Item WrapMark;
|
|---|
| 97 | static const struct Item EndMark;
|
|---|
| 98 |
|
|---|
| 99 | private:
|
|---|
| 100 | std::string Name;
|
|---|
| 101 | char *Buffer;
|
|---|
| 102 | int BufferSize;
|
|---|
| 103 | char *DataStart;
|
|---|
| 104 | struct Item *Pointer;
|
|---|
| 105 |
|
|---|
| 106 | public:
|
|---|
| 107 | EvidenceHistory(std::string);
|
|---|
| 108 | ~EvidenceHistory();
|
|---|
| 109 |
|
|---|
| 110 | bool GetHistory();
|
|---|
| 111 | char *GetFormat();
|
|---|
| 112 | const struct Item *Next();
|
|---|
| 113 | void Rewind();
|
|---|
| 114 | };
|
|---|
| 115 | #endif
|
|---|