00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 #include "config.h"
00019 #endif
00020 #include "global.h"
00021
00022 #define PID_FILE PID_DIR "/ddt/ddtd.pid"
00023 #define LOG_FILE LOG_DIR "/ddtd.log"
00024 #define CONF_FILE CONF_DIR "/ddtd.conf"
00025
00026 #define TIMEOUT (5 * 60)
00027
00028 #include <pwd.h>
00029 #include <grp.h>
00030 #include <fcntl.h>
00031 #include <pthread.h>
00032 #include <signal.h>
00033 #include <string.h>
00034 #include <sys/types.h>
00035 #include <sys/stat.h>
00036 #include <unistd.h>
00037
00038 #include <sys/socket.h>
00039 #include <netinet/in.h>
00040 #include <arpa/inet.h>
00041
00042 #include <errno.h>
00043 #include <opt.h>
00044
00045 #include "Exception.h"
00046 #include "Logger.h"
00047
00048 #include "DdtManager.h"
00049 #include "DbPsql.h"
00050 #include "DnsBind.h"
00051
00052 #include "Options.h"
00053 #include "Thread.h"
00054 #include "UDP.h"
00055 #include "packets.h"
00056 #include "DdtMD.h"
00057 #include "DdtCipher.h"
00058 #include "Packet.h"
00059
00060 #ifndef DDTD_H
00061 #define DDTD_H
00062
00063 class Server;
00064
00065 class SendThread : public Thread
00066 {
00067 public:
00068 SendThread(Server*);
00069
00070 void *run (void *);
00071 void cleanUp();
00072
00073 private:
00074 };
00075
00076 class Server
00077 {
00078 public:
00079 Server();
00080 ~Server();
00081
00082 int alreadyRunning ();
00083 int parseArgs(int *argc, char ***argv);
00084 int becomeDaemon();
00085 int run();
00086
00091 int receiver();
00092
00097 void validateActiveAccounts();
00098
00099 private:
00100 static void processActiveAccount (int accountId,
00101 unsigned long addr,
00102 time_t lastAccessTime);
00103
00104 int processReceivedPacket (DdtpPacket* pkt,
00105 int accountId,
00106 char* db_password);
00107 int processDDTPv1UpdateQuery (DDTPv1UpdateQuery* updateQuery,
00108 DDTPv1UpdateReply* updateReply,
00109 int accountId,
00110 char* db_password);
00111
00112 int processDDTPv1AliveReply (DDTPv1AliveReply* aliveReply,
00113 int accountId);
00114
00115 static void atexit_handler ();
00116 static void signal_handler (int signum);
00117
00118 static Logger *log;
00119 static Options *opts;
00120 static UDP *udp;
00121
00122 static DdtManager *manager;
00123 static Db *db;
00124 static Dns *dns;
00125
00126 static Mutex *mutex;
00127
00128 SendThread *sendThread;
00129 };
00130
00131 #endif // DDTD_H