typedef unsigned long ULONG;
typedef unsigned long long ULLONG;
-ULLONG htonll(ULLONG a);
-ULLONG ntohll(ULLONG a);
-
-
#endif
#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
{
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)
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
void Log::upLogLevel()
{
+ if (!initted) return;
+
if (logLevel == Log::DEBUG)
{
log("Log", logLevel, "Log level is at its highest already");
void Log::downLogLevel()
{
+ if (!initted) return;
+
if (logLevel == Log::CRAZY)
{
log("Log", logLevel, "Log level is at its lowest already");
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;
}
}
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];
return 0;
}
-
-int Log::status()
-{
- if (instance && logfile) return 1;
- else return 0;
-}
~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();
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()
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;
return channel;
}
-
void MVPClient::writeResumeData()
{
config.setValueLongLong("ResumeData", (char*)rp->getCurrentRecording()->FileName(), rp->getLastPosition());
*/
-
+/*
void MVPClient::test2()
{
log->log("-", Log::DEBUG, "Timers List");
// 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
#include <stdio.h>
#include <pthread.h>
-//#include <netinet/in.h>
#include <signal.h>
+#include <endian.h>
#include <unistd.h> // sleep
void cleanConfig();
void sendULONG(ULONG ul);
+ ULLONG ntohll(ULLONG a);
+ ULLONG htonll(ULLONG a);
+
void test(int num);
void test2();
};
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;
}
{
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;
}
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
-}
#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
{
private:
void threadMethod();
+ Config config;
Log log;
UDPReplier udpr;
int listeningSocket;
#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;
}
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;
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));
+ }
}
}
virtual ~UDPReplier();
int run(char* tserverName);
- int stop();
+ int shutdown();
private:
void threadMethod();
#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
// 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();
}
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.