| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
| 4 |
|
|
* |
| 5 |
|
|
* This file is part of the pdserv library. |
| 6 |
|
|
* |
| 7 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
| 8 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
| 9 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
| 10 |
|
|
* your option) any later version. |
| 11 |
|
|
* |
| 12 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
| 13 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 15 |
|
|
* License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
| 18 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
|
* |
| 20 |
|
|
****************************************************************************/ |
| 21 |
|
|
|
| 22 |
|
|
#ifndef MAIN_H |
| 23 |
|
|
#define MAIN_H |
| 24 |
|
|
|
| 25 |
|
|
#include <map> |
| 26 |
|
|
#include <set> |
| 27 |
|
|
#include <list> |
| 28 |
|
|
#include <memory> |
| 29 |
|
|
#include <string> |
| 30 |
|
|
#include <vector> |
| 31 |
|
|
#include <stdint.h> |
| 32 |
|
|
#include <log4cplus/logger.h> |
| 33 |
|
|
|
| 34 |
|
|
#include "PThread.h" |
| 35 |
|
|
#include "Config.h" |
| 36 |
|
|
#include "Event.h" |
| 37 |
|
|
#include "config.h" |
| 38 |
|
|
|
| 39 |
|
|
#ifdef GNUTLS_FOUND |
| 40 |
|
|
#include <gnutls/gnutls.h> |
| 41 |
|
|
#include "TLS.h" |
| 42 |
|
|
#endif |
| 43 |
|
|
|
| 44 |
|
|
struct timespec; |
| 45 |
|
|
class TlsSessionDB; |
| 46 |
|
|
|
| 47 |
|
|
namespace MsrProto { |
| 48 |
|
|
class Server; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
struct Blacklist; |
| 52 |
|
|
class TlsSessionDB; |
| 53 |
|
|
|
| 54 |
|
|
namespace PdServ { |
| 55 |
|
|
|
| 56 |
|
|
class Signal; |
| 57 |
|
|
class Event; |
| 58 |
|
|
class Parameter; |
| 59 |
|
|
class ProcessParameter; |
| 60 |
|
|
class Variable; |
| 61 |
|
|
class Task; |
| 62 |
|
|
class Session; |
| 63 |
|
|
struct SessionStatistics; |
| 64 |
|
|
|
| 65 |
|
|
class Main { |
| 66 |
|
|
public: |
| 67 |
|
|
struct RtProcessExited {}; |
| 68 |
|
|
|
| 69 |
|
|
Main(const std::string& name, const std::string& version); |
| 70 |
|
|
virtual ~Main(); |
| 71 |
|
|
|
| 72 |
|
|
const std::string name; /**< Application name */ |
| 73 |
|
|
const std::string version; /**< Application version */ |
| 74 |
|
|
|
| 75 |
|
|
void startServers(); |
| 76 |
|
|
void stopServers(); |
| 77 |
|
|
|
| 78 |
|
|
bool loginMandatory() const; |
| 79 |
|
|
|
| 80 |
|
|
#ifdef GNUTLS_FOUND |
| 81 |
|
|
bool tlsReady() const; |
| 82 |
|
|
void initTlsSessionData(gnutls_session_t) const; |
| 83 |
|
27 |
const Blacklist& getBlacklist() const { return blacklist; } |
| 84 |
|
|
#endif |
| 85 |
|
|
|
| 86 |
|
|
// Get the current system time. |
| 87 |
|
|
// Reimplement this method in the class specialization |
| 88 |
|
|
virtual int gettime(struct timespec *) const; |
| 89 |
|
|
|
| 90 |
|
|
virtual std::list<const Task*> getTasks() const = 0; |
| 91 |
|
|
virtual std::list<const Event*> getEvents() const = 0; |
| 92 |
|
|
virtual std::list<const Parameter*> getParameters() const = 0; |
| 93 |
|
|
virtual void prepare(Session *session) const; |
| 94 |
|
|
virtual void cleanup(const Session *session) const; |
| 95 |
|
|
virtual Config config(const char* section) const = 0; |
| 96 |
|
|
|
| 97 |
|
|
void getActiveEvents(std::list<EventData>*) const; |
| 98 |
|
|
EventData getEvent(uint32_t id) const; |
| 99 |
|
|
uint32_t getCurrentEventId() const; |
| 100 |
|
|
|
| 101 |
|
|
// Setting a parameter has various steps: |
| 102 |
|
|
// 1) client calls parameter->setValue(session, ...) |
| 103 |
|
|
// This virtual method is implemented by ProcessParameter |
| 104 |
|
|
// 2) ProcessParameter calls |
| 105 |
|
|
// main->setValue(processParameter, session, ...) |
| 106 |
|
|
// so that main can check whether session is allowed to set it |
| 107 |
|
|
// 3) main calls Main::setValue(...) virtual method to do the setting |
| 108 |
|
|
// 4) on success, main can do various functions, e.g. |
| 109 |
|
|
// - inform clients of a value change |
| 110 |
|
|
// - save persistent parameter |
| 111 |
|
|
// - etc |
| 112 |
|
|
int setValue(const ProcessParameter* p, const Session *session, |
| 113 |
|
|
const char* buf, size_t offset, size_t count); |
| 114 |
|
|
|
| 115 |
|
|
protected: |
| 116 |
|
|
int setupLogging(const std::string& configFile); |
| 117 |
|
|
|
| 118 |
|
|
static int localtime(struct timespec *); |
| 119 |
|
|
|
| 120 |
|
|
void savePersistent(); |
| 121 |
|
|
unsigned int setupPersistent(); |
| 122 |
|
|
|
| 123 |
|
|
void newEvent(const Event* event, |
| 124 |
|
|
size_t element, int state, const struct timespec* time); |
| 125 |
|
|
|
| 126 |
|
|
// virtual functions to be implemented in derived classes |
| 127 |
|
|
virtual void initializeParameter(Parameter* p, |
| 128 |
|
|
const char* data, const struct timespec* mtime, |
| 129 |
|
|
const Signal* s) = 0; |
| 130 |
|
|
virtual bool getPersistentSignalValue(const Signal *s, |
| 131 |
|
|
char* buf, struct timespec* time) = 0; |
| 132 |
|
|
virtual Parameter* findParameter(const std::string& path) const = 0; |
| 133 |
|
|
virtual int setValue(const ProcessParameter* p, |
| 134 |
|
|
const char* buf, size_t offset, size_t count, |
| 135 |
|
|
const char** value, const struct timespec**) = 0; |
| 136 |
|
|
|
| 137 |
|
|
private: |
| 138 |
|
|
struct EventInstance; |
| 139 |
|
|
|
| 140 |
|
|
EventInstance* eventPtr; |
| 141 |
|
|
std::vector<EventInstance> eventInstance; |
| 142 |
|
|
std::set<EventInstance*> danglingInstances; |
| 143 |
|
|
|
| 144 |
|
|
typedef std::vector<EventInstance*> EventInstanceVector; |
| 145 |
|
|
typedef std::map<const Event*, EventInstanceVector*> EventInstanceMap; |
| 146 |
|
|
EventInstanceMap eventMap; |
| 147 |
|
|
|
| 148 |
|
|
mutable pthread::RWLock eventMutex; |
| 149 |
|
|
uint32_t eventSeqNo; |
| 150 |
|
|
|
| 151 |
|
|
const log4cplus::Logger parameterLog; |
| 152 |
|
|
const log4cplus::Logger eventLog; |
| 153 |
|
|
|
| 154 |
|
|
bool persistentLogTraceOn; |
| 155 |
|
|
log4cplus::Logger persistentLog; |
| 156 |
|
|
log4cplus::Logger persistentLogTrace; |
| 157 |
|
|
PdServ::Config persistentConfig; |
| 158 |
|
|
typedef std::map<const Parameter*, const Signal*> PersistentMap; |
| 159 |
|
|
PersistentMap persistentMap; |
| 160 |
|
|
|
| 161 |
|
|
MsrProto::Server *msrproto; |
| 162 |
|
|
|
| 163 |
|
|
void consoleLogging(); |
| 164 |
|
|
void syslogLogging(); |
| 165 |
|
|
const EventInstance* m_getEventInstance(uint32_t seqNo) const; |
| 166 |
|
|
|
| 167 |
|
|
void setupAccessControl(const Config&); |
| 168 |
|
|
bool m_loginMandatory; |
| 169 |
|
|
bool m_write; |
| 170 |
|
|
|
| 171 |
|
|
#ifdef GNUTLS_FOUND |
| 172 |
|
|
pthread::Mutex tls_mutex; |
| 173 |
|
|
bool verifyClient; |
| 174 |
|
|
std::unique_ptr<gnutls_certificate_credentials_st, TlsDeleter> tls; |
| 175 |
|
|
std::unique_ptr<gnutls_priority_st, TlsDeleter> priority_cache; |
| 176 |
|
|
std::unique_ptr<gnutls_dh_params_int, TlsDeleter> dh_params; |
| 177 |
|
|
|
| 178 |
|
|
mutable TlsSessionDB tlsSessionDB; |
| 179 |
|
|
Blacklist blacklist; |
| 180 |
|
|
|
| 181 |
|
|
int setupTLS(Config, log4cplus::Logger&); |
| 182 |
|
|
void destroyTLS(); |
| 183 |
|
|
void loadTrustFile(log4cplus::Logger&, const char* cafile); |
| 184 |
|
|
void loadCrlFile(log4cplus::Logger&, const char* cafile); |
| 185 |
|
|
void parseCertConfigDir(log4cplus::Logger&, const char* path, |
| 186 |
|
|
void (Main::*func)(log4cplus::Logger&, const char*)); |
| 187 |
|
|
void parseCertConfigItem(log4cplus::Logger&, Config config, |
| 188 |
|
|
void (Main::*func)(log4cplus::Logger&, const char*)); |
| 189 |
|
|
#endif |
| 190 |
|
|
}; |
| 191 |
|
|
|
| 192 |
|
|
} |
| 193 |
|
|
#endif // MAIN_H |
| 194 |
|
|
|