diff options
author | bju <bju@maxi.fritz.box> | 2011-03-31 00:37:16 +0200 |
---|---|---|
committer | bju <bju@maxi.fritz.box> | 2011-03-31 00:37:16 +0200 |
commit | 32ba3fb9f2a1f7b073b3a121762385ac237a2af8 (patch) | |
tree | f3cbdbe2ced3e202d0c1cd3d037a8ed3108817e2 /vdr-vdrmanager/handler.cpp | |
parent | acc1396153d7fb9c22d2b3cee3f2eef383ad681d (diff) | |
download | vdr-manager-32ba3fb9f2a1f7b073b3a121762385ac237a2af8.tar.gz vdr-manager-32ba3fb9f2a1f7b073b3a121762385ac237a2af8.tar.bz2 |
Renamed from androvdr to vdrmanager
Diffstat (limited to 'vdr-vdrmanager/handler.cpp')
-rw-r--r-- | vdr-vdrmanager/handler.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/vdr-vdrmanager/handler.cpp b/vdr-vdrmanager/handler.cpp new file mode 100644 index 0000000..2e5f7bd --- /dev/null +++ b/vdr-vdrmanager/handler.cpp @@ -0,0 +1,92 @@ +/* + * event und message handler + */ + +#include <unistd.h> +#include <vdr/plugin.h> +#include <vdr/timers.h> +#include "sock.h" +#include "select.h" +#include "vdrmanagerthread.h" +#include "helpers.h" + +bool cHandler::HandleNewClient(cVdrmanagerClientSocket * sock) +{ + return true; +} + +bool cHandler::HandleClientRequest(cVdrmanagerClientSocket * sock) +{ + while(sock->Read()) + { + // get lines + while (sock->IsLineComplete()) + { + string line; + sock->GetLine(line); + + // parse request + size_t space = line.find(' '); + string cmd; + string args; + if (space != string::npos) { + cmd = cHelpers::ToUpper(line.substr(0, space)); + args = cHelpers::Trim(line.substr(space+1)); + } else { + cmd = cHelpers::ToUpper(line); + args = ""; + } + + if (!sock->IsLoggedIn() && cmd != "PASSWD") { + sock->PutLine("!ERROR\r\n"); + } + else if (cmd == "PASSWD") + { + if (args != sock->GetPassword()) { + sock->PutLine("!ERROR\r\n"); + } else { + sock->SetLoggedIn(); + sock->PutLine("!OK\r\n"); + } + } + else if (cmd == "TIMERS") + { + string text = cHelpers::GetTimers(args); + sock->PutLine(text); + } + else if (cmd == "CHANNELS") + { + string text = cHelpers::GetChannels(args); + sock->PutLine(text); + } + else if (cmd == "TEVENTS") + { + string text = cHelpers::GetTimeEvents(args); + sock->PutLine(text); + } + else if (cmd == "CEVENTS") + { + string text = cHelpers::GetChannelEvents(args); + sock->PutLine(text); + } + else if (cmd == "TIMER") + { + string text = cHelpers::SetTimer(args); + sock->PutLine(text); + } + else if (cmd == "SEARCH") + { + string text = cHelpers::SearchEvents(args); + sock->PutLine(text); + } + else if (cmd == "QUIT") + { + // close socket + sock->PutLine(string("Good bye! :-)\n")); + sock->Disconnect(); + } + } + } + + return true; +} |