]> git.vomp.tv Git - vompserver.git/commitdiff
New structure
authorChris Tallon <chris@vomp.tv>
Sat, 28 Jan 2006 00:25:58 +0000 (00:25 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 28 Jan 2006 00:25:58 +0000 (00:25 +0000)
12 files changed:
defines.h
dsock.c
dsock.h
log.c
log.h
mvpclient.c
mvpclient.h
mvpserver.c
mvpserver.h
udpreplier.c
udpreplier.h
vompserver.c

index 230f0ee33bb6a77d6ec05a269a1f2f4185771ed4..440ca3d11973a129d5dfbd5df871fd66cb6b7ffb 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -27,8 +27,4 @@ typedef unsigned int UINT;
 typedef unsigned long ULONG;
 typedef unsigned long long ULLONG;
 
-ULLONG htonll(ULLONG a);
-ULLONG ntohll(ULLONG a);
-
-
 #endif
diff --git a/dsock.c b/dsock.c
index 8a1ee53c1efe89ee1269a32933bd0835db6879d9..8c257f97edb64be7bd52b50abab3a7dc9b9b4c28 100644 (file)
--- a/dsock.c
+++ b/dsock.c
 
 #include "dsock.h"
 
-DatagramSocket::DatagramSocket(short port)
+DatagramSocket::DatagramSocket()
 {
-  myPort = port;
   addrlen = sizeof(struct sockaddr);
   log = Log::getInstance();
   initted = 0;
+}
+
+DatagramSocket::~DatagramSocket()
+{
+  if (initted) close(socketnum);
+  initted = 0;
+}
 
+bool DatagramSocket::init(short port)
+{
+  myPort = port;
   if ((socketnum = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
   {
     log->log("UDP", Log::CRIT, "Socket error");
-    return;
+    return false;
   }
 
   myAddr.sin_family = AF_INET;         // host byte order
@@ -41,20 +50,16 @@ DatagramSocket::DatagramSocket(short port)
   {
     log->log("UDP", Log::CRIT, "Bind error");
     close(socketnum);
-    return;
+    return false;
   }
-  initted = 1;
 
   FD_ZERO(&readfds);
   FD_SET(socketnum, &readfds);
   tv.tv_sec = 0;
   tv.tv_usec = 0;
-}
 
-DatagramSocket::~DatagramSocket()
-{
-  if (initted) close(socketnum);
-  initted = 0;
+  initted = 1;
+  return true;
 }
 
 unsigned char DatagramSocket::waitforMessage(unsigned char how)
diff --git a/dsock.h b/dsock.h
index 29389b9401ff23dbf897ed6110a1cb61c6aa0564..33c75dd1008072d1d9a4bf92b5bd58c839315f09 100644 (file)
--- a/dsock.h
+++ b/dsock.h
@@ -41,8 +41,9 @@ typedef unsigned char uchar;
 class DatagramSocket
 {
   public:
-    DatagramSocket(short);             // port
+    DatagramSocket();
     ~DatagramSocket();
+    bool init(short);                 // port
     unsigned char waitforMessage(unsigned char); // int =0-block =1-new wait =2-continue wait
     int getDataLength(void) const;
     char *getData(void);               // returns a pointer to the data
diff --git a/log.c b/log.c
index 1f36bb384cd8e4a274bb9728b90b010f520ac8da..a3cb8ce5b9749722541f039e082a62c4e99c4b97 100755 (executable)
--- a/log.c
+++ b/log.c
@@ -44,6 +44,8 @@ Log* Log::getInstance()
 
 void Log::upLogLevel()
 {
+  if (!initted) return;
+
   if (logLevel == Log::DEBUG)
   {
     log("Log", logLevel, "Log level is at its highest already");
@@ -56,6 +58,8 @@ void Log::upLogLevel()
 
 void Log::downLogLevel()
 {
+  if (!initted) return;
+
   if (logLevel == Log::CRAZY)
   {
     log("Log", logLevel, "Log level is at its lowest already");
@@ -66,22 +70,18 @@ void Log::downLogLevel()
   log("Log", logLevel, "Log level is now %i", logLevel);
 }
 
-int Log::init(int startLogLevel, char* fileName, int tenabled)
+int Log::init(int startLogLevel, char* fileName)
 {
-  initted = 1;
   logLevel = startLogLevel;
-  enabled = tenabled;
-
-  if (!enabled) return 1;
 
   logfile = fopen(fileName, "a");
   if (logfile)
   {
+    initted = 1;
     return 1;
   }
   else
   {
-    enabled = 0;
     return 0;
   }
 }
@@ -89,15 +89,15 @@ int Log::init(int startLogLevel, char* fileName, int tenabled)
 int Log::shutdown()
 {
   if (!initted) return 1;
+  initted = 0;
   if (logfile) fclose(logfile);
   return 1;
 }
 
 int Log::log(char *fromModule, int level, char* message, ...)
 {
-  if (!instance || !logfile) return 0;
+  if (!initted) return 0;
 
-  if (!enabled) return 1;
   if (level > logLevel) return 1;
 
   char buffer[151];
@@ -149,9 +149,3 @@ int Log::log(char *fromModule, int level, char* message, ...)
     return 0;
 
 }
-
-int Log::status()
-{
-  if (instance && logfile) return 1;
-  else return 0;
-}
diff --git a/log.h b/log.h
index bf45f42d3c3c31b2a3e38d47d792f0b226dcb925..6e4316b09121f7114b49b4d1f6ef0116a7a53b2e 100755 (executable)
--- a/log.h
+++ b/log.h
@@ -35,10 +35,9 @@ class Log
     ~Log();
     static Log* getInstance();
 
-    int init(int defaultLevel, char* fileName, int enabled);
+    int init(int defaultLevel, char* fileName);
     int shutdown();
     int log(char *fromModule, int level, char *message, ...);
-    int status();
     void upLogLevel();
     void downLogLevel();
 
index 7f24e9adc4aa58263e3d8b65d6961057ee181d36..d3c49c52e0f9549a0de0d4fe03e1471a58dc5427 100644 (file)
@@ -28,41 +28,6 @@ MVPClient::MVPClient(int tsocket)
   recordingManager = NULL;
   log = Log::getInstance();
   loggedIn = false;
-
-/*
-  // Get IP address of client for config module
-
-  char ipa[20];
-  struct sockaddr_in peer;
-  socklen_t salen = sizeof(struct sockaddr);
-  if(getpeername(tsocket, (struct sockaddr*)&peer, &salen) == 0)
-  {
-    strcpy(ipa, inet_ntoa(peer.sin_addr));
-  }
-  else
-  {
-    ipa[0] = '\0';
-    log->log("Client", Log::DEBUG, "Cannot get peer name!");
-  }
-
-  const char* configDir = cPlugin::ConfigDirectory();
-  if (!configDir)
-  {
-    log->log("Client", Log::DEBUG, "No config dir!");
-    return;
-  }
-
-  char configFileName[PATH_MAX];
-  snprintf(configFileName, PATH_MAX - strlen(configDir) - strlen(ipa) - 20, "%s/vomp-%s.conf", configDir, ipa);
-  config.init(configFileName);
-
-  log->log("Client", Log::DEBUG, "Config file name: %s", configFileName);
-*/
-
-//test(14);
-
-  test2();
-
 }
 
 MVPClient::~MVPClient()
@@ -86,6 +51,31 @@ MVPClient::~MVPClient()
   if (loggedIn) cleanConfig();
 }
 
+ULLONG MVPClient::ntohll(ULLONG a)
+{
+  return htonll(a);
+}
+
+ULLONG MVPClient::htonll(ULLONG a)
+{
+  #if BYTE_ORDER == BIG_ENDIAN
+    return a;
+  #else
+    ULLONG b = 0;
+
+    b = ((a << 56) & 0xFF00000000000000ULL)
+      | ((a << 40) & 0x00FF000000000000ULL)
+      | ((a << 24) & 0x0000FF0000000000ULL)
+      | ((a <<  8) & 0x000000FF00000000ULL)
+      | ((a >>  8) & 0x00000000FF000000ULL)
+      | ((a >> 24) & 0x0000000000FF0000ULL)
+      | ((a >> 40) & 0x000000000000FF00ULL)
+      | ((a >> 56) & 0x00000000000000FFULL) ;
+
+    return b;
+  #endif
+}
+
 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
 {
   cChannel* channel = NULL;
@@ -118,7 +108,6 @@ cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
   return channel;
 }
 
-
 void MVPClient::writeResumeData()
 {
   config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
@@ -1172,7 +1161,7 @@ IsPresent ? easy to work out tho. Oh it doesn't always work
 
 */
 
-
+/*
 void MVPClient::test2()
 {
   log->log("-", Log::DEBUG, "Timers List");
@@ -1195,7 +1184,7 @@ void MVPClient::test2()
 //            active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
 //            PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
 }
-
+*/
 
 /*
 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
index b069f573e7107aa49bb5c7e0349c1c58c89b67f8..55d6835d4349101fdc3f4844547135535f6d9fa4 100644 (file)
@@ -23,8 +23,8 @@
 
 #include <stdio.h>
 #include <pthread.h>
-//#include <netinet/in.h>
 #include <signal.h>
+#include <endian.h>
 
 #include <unistd.h> // sleep
 
@@ -83,6 +83,9 @@ class MVPClient
     void cleanConfig();
     void sendULONG(ULONG ul);
 
+    ULLONG ntohll(ULLONG a);
+    ULLONG htonll(ULLONG a);
+
     void test(int num);
     void test2();
 };
index c02e75ebba0f7791b57228de0304dc75c2dcc884..63d75f76856b54ed79a743b82ef32e712a333f39 100644 (file)
@@ -26,20 +26,20 @@ MVPServer::MVPServer()
 
 MVPServer::~MVPServer()
 {
-  if (threadIsActive()) stop();
+  stop();
 }
 
 int MVPServer::stop()
 {
-  if (!threadIsActive()) return 0;
+  if (threadIsActive()) threadCancel();
+  close(listeningSocket);
 
-  threadCancel();
-  log.log("MVPServer", Log::INFO, "Stopped MVPServer thread");
+  udpr.shutdown();
 
-  udpr.stop();
+  log.log("Main", Log::INFO, "Stopped main server thread");
   log.shutdown();
 
-  close(listeningSocket);
+  config.shutdown();
 
   return 1;
 }
@@ -48,63 +48,70 @@ int MVPServer::run()
 {
   if (threadIsActive()) return 1;
 
-  log.init(Log::DEBUG, "/tmp/vompserver.log", 1);
-
-  char serverName[1024];
-  bool nameSuccess = false;
-
-  // Try to get a server name from vomp.conf
+  // Start config
   const char* configDir = cPlugin::ConfigDirectory();
   if (!configDir)
   {
-    log.log("Client", Log::DEBUG, "No config dir!");
+    dsyslog("VOMP: Could not get config dir from VDR");
   }
   else
   {
     char configFileName[PATH_MAX];
     snprintf(configFileName, PATH_MAX, "%s/vomp.conf", configDir);
-
-    Config c;
-    if (c.init(configFileName))
+    if (config.init(configFileName))
     {
-      char* fc = c.getValueString("General", "Server name");
-      if (fc)
-      {
-        strncpy(serverName, fc, 1024);
-        delete[] fc;
-        nameSuccess = true;
-      }
+      dsyslog("VOMP: Config file found");
+    }
+    else
+    {
+      dsyslog("VOMP: Config file not found");
     }
-    c.shutdown();
   }
 
-  if (!nameSuccess)
+  // Start logging
+
+  char* cfgLogFilename = config.getValueString("General", "Log file");
+  if (cfgLogFilename)
   {
-    if (gethostname(serverName, 1024)) // if fail
+    log.init(Log::DEBUG, cfgLogFilename);
+    delete[] cfgLogFilename;
+  }
+
+  // Work out a name for this server
+
+  char* serverName;
+
+  // Try to get from vomp.conf
+  serverName = config.getValueString("General", "Server name");
+  if (!serverName) // If not, get the hostname
+  {
+    serverName = new char[1024];
+    if (gethostname(serverName, 1024)) // if not, just use "-"
     {
       strcpy(serverName, "-");
     }
   }
 
-  serverName[1023] = '\0';
+  int udpSuccess = udpr.run(serverName);
+
+  delete[] serverName;
 
-  if (!udpr.run(serverName))
+  if (!udpSuccess)
   {
-    log.log("MVPServer", Log::CRIT, "Could not start UDP replier");
-    log.shutdown();
+    log.log("Main", Log::CRIT, "Could not start UDP replier");
+    stop();
     return 0;
   }
 
   // start thread here
   if (!threadStart())
   {
-    log.log("MVPServer", Log::CRIT, "Could not start MVPServer thread");
-    udpr.stop();
-    log.shutdown();
+    log.log("Main", Log::CRIT, "Could not start MVPServer thread");
+    stop();
     return 0;
   }
 
-  log.log("MVPServer", Log::DEBUG, "MVPServer run success");
+  log.log("Main", Log::DEBUG, "MVPServer run success");
   return 1;
 }
 
@@ -148,29 +155,3 @@ void MVPServer::threadMethod()
     m->run();
   }
 }
-
-
-ULLONG ntohll(ULLONG a)
-{
-  return htonll(a);
-}
-
-ULLONG htonll(ULLONG a)
-{
-  #if BYTE_ORDER == BIG_ENDIAN
-    return a;
-  #else
-    ULLONG b = 0;
-
-    b = ((a << 56) & 0xFF00000000000000ULL)
-      | ((a << 40) & 0x00FF000000000000ULL)
-      | ((a << 24) & 0x0000FF0000000000ULL)
-      | ((a <<  8) & 0x000000FF00000000ULL)
-      | ((a >>  8) & 0x00000000FF000000ULL)
-      | ((a >> 24) & 0x0000000000FF0000ULL)
-      | ((a >> 40) & 0x000000000000FF00ULL)
-      | ((a >> 56) & 0x00000000000000FFULL) ;
-
-    return b;
-  #endif
-}
index d64268d77311dd5fda7f46f52990ac3235da21f9..d6d9da834ff09819f1492cbdd2951d3966a42bc8 100644 (file)
 #include <stdio.h>
 #include <pthread.h>
 #include <unistd.h>
-#include <endian.h>
 
 #include "defines.h"
 #include "udpreplier.h"
 #include "mvpclient.h"
 #include "thread.h"
+#include "config.h"
 
 class MVPServer : public Thread
 {
@@ -43,6 +43,7 @@ class MVPServer : public Thread
   private:
     void threadMethod();
 
+    Config config;
     Log log;
     UDPReplier udpr;
     int listeningSocket;
index ed3bf8421edc8c25a8e512f62a9a5c12d0ed73a4..c4b743640dbd7c08cde5245c056e61721306d798 100644 (file)
 #include "udpreplier.h"
 
 UDPReplier::UDPReplier()
- : ds(3024)
 {
   serverName = NULL;
 }
 
 UDPReplier::~UDPReplier()
 {
-  if (threadIsActive()) stop();
-  if (serverName) delete[] serverName;
-  serverName = NULL;
+  shutdown();
 }
 
-int UDPReplier::stop()
+int UDPReplier::shutdown()
 {
-  if (!threadIsActive()) return 0;
-  threadCancel();
+  if (threadIsActive()) threadCancel();
+
+  if (serverName) delete[] serverName;
+  serverName = NULL;
   return 1;
 }
 
@@ -47,7 +46,17 @@ int UDPReplier::run(char* tserverName)
   serverName = new char[strlen(tserverName)+1];
   strcpy(serverName, tserverName);
 
-  if (!threadStart()) return 0;
+  if (!ds.init(3024))
+  {
+    shutdown();
+    return 0;
+  }
+
+  if (!threadStart())
+  {
+    shutdown();
+    return 0;
+  }
 
   Log::getInstance()->log("UDP", Log::DEBUG, "UDP replier started");
   return 1;
@@ -62,6 +71,9 @@ void UDPReplier::threadMethod()
     if (retval == 1) continue;
 
     if (!strcmp(ds.getData(), "VOMP"))
+    {
+      Log::getInstance()->log("UDP", Log::DEBUG, "UDP request from %s", ds.getFromIPA());
       ds.send(ds.getFromIPA(), 3024, serverName, strlen(serverName));
+    }
   }
 }
index 371e5a1008c07852c625e4fadcec2a0982e9209a..a16af545deb9e6a38b03caa830bf01f6ee5df0e4 100644 (file)
@@ -35,7 +35,7 @@ class UDPReplier : public Thread
     virtual ~UDPReplier();
 
     int run(char* tserverName);
-    int stop();
+    int shutdown();
 
   private:
     void threadMethod();
index 45792f29e0ca1166ea736bee7c43419adaa8b1ec..23e290a4a5c4d4da9269287d5f0b200d661b4299 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "mvpserver.h"
 
-static const char *VERSION        = "0.0.1";
+static const char *VERSION        = "0.1.2";
 static const char *DESCRIPTION    = "VDR on MVP plugin by Chris Tallon";
 
 class cPluginVompserver : public cPlugin
@@ -58,10 +58,17 @@ cPluginVompserver::cPluginVompserver(void)
   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
 }
 
+bool cPluginVompserver::Start(void)
+{
+  // Start any background activities the plugin shall perform.
+  int success = mvpserver.run();
+  if (success) return true;
+  else return false;
+}
+
 cPluginVompserver::~cPluginVompserver()
 {
   // Clean up after yourself!
-
   mvpserver.stop();
 }
 
@@ -83,14 +90,6 @@ bool cPluginVompserver::Initialize(void)
   return true;
 }
 
-bool cPluginVompserver::Start(void)
-{
-  // Start any background activities the plugin shall perform.
-  int success = mvpserver.run();
-  if (success) return true;
-  else return false;
-}
-
 bool cPluginVompserver::SetupParse(const char *Name, const char *Value)
 {
   // Parse your own setup parameters and store their values.