summaryrefslogtreecommitdiff
path: root/vdr-vdrmanager/handler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vdr-vdrmanager/handler.cpp')
-rw-r--r--vdr-vdrmanager/handler.cpp177
1 files changed, 85 insertions, 92 deletions
diff --git a/vdr-vdrmanager/handler.cpp b/vdr-vdrmanager/handler.cpp
index ea15296..4a787c7 100644
--- a/vdr-vdrmanager/handler.cpp
+++ b/vdr-vdrmanager/handler.cpp
@@ -17,104 +17,97 @@ bool cHandler::HandleNewClient(cVdrmanagerClientSocket * sock)
bool cHandler::HandleClientRequest(cVdrmanagerClientSocket * sock)
{
- bool closeSocket = true;
+ while (!sock->IsLineComplete() && sock->Read())
+ ;
- while(sock->Read())
- {
- // get lines
- while (sock->IsLineComplete())
- {
- string line;
- sock->GetLine(line);
+ if (sock->IsLineComplete()) {
- // 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 = "";
- }
+ string line;
+ sock->GetLine(line);
- 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");
- }
- closeSocket = false;
- }
- else if (cmd == "COMPRESS")
- {
- sock->ActivateCompression();
- closeSocket = false;
- }
- 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 == "RECORDINGS")
- {
- string text = cHelpers::GetRecordings(args);
- sock->PutLine(text);
- }
- else if(cmd == "DRECORDING")
- {
- string text = cHelpers::DelRecording(args);
- sock->PutLine(text);
- }
- else if (cmd == "SETCHANNEL")
- {
- string text = cHelpers::SetChannel(args);
- sock->PutLine(text);
- }
- else if (cmd == "QUIT")
- {
- // close socket
- sock->PutLine(string("Good bye! :-)\r\n"));
- sock->Disconnect();
- }
+ isyslog("[vdrmanager] got %s", line.c_str());
- if (closeSocket) {
- sock->Disconnect();
- }
+ // 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 = "";
+ }
- sock->Flush();
+ if (!sock->IsLoggedIn() && cmd != "PASSWD") {
+ sock->Write("!ERROR\r\n");
}
+ else if (cmd == "PASSWD")
+ {
+ if (args != sock->GetPassword()) {
+ sock->Write("!ERROR\r\n");
+ } else {
+ sock->SetLoggedIn();
+ sock->Write("!OK\r\n");
+ }
+ }
+ else if (cmd == "COMPRESS")
+ {
+ sock->ActivateCompression();
+ }
+ else if (cmd == "TIMERS")
+ {
+ string text = cHelpers::GetTimers(args);
+ sock->Write(text);
+ }
+ else if (cmd == "CHANNELS")
+ {
+ string text = cHelpers::GetChannels(args);
+ sock->Write(text);
+ }
+ else if (cmd == "TEVENTS")
+ {
+ string text = cHelpers::GetTimeEvents(args);
+ sock->Write(text);
+ }
+ else if (cmd == "CEVENTS")
+ {
+ string text = cHelpers::GetChannelEvents(args);
+ sock->Write(text);
+ }
+ else if (cmd == "TIMER")
+ {
+ string text = cHelpers::SetTimer(args);
+ sock->Write(text);
+ }
+ else if (cmd == "SEARCH")
+ {
+ string text = cHelpers::SearchEvents(args);
+ sock->Write(text);
+ }
+ else if(cmd == "RECORDINGS")
+ {
+ string text = cHelpers::GetRecordings(args);
+ sock->Write(text);
+ }
+ else if(cmd == "DRECORDING")
+ {
+ string text = cHelpers::DelRecording(args);
+ sock->Write(text);
+ }
+ else if (cmd == "SETCHANNEL")
+ {
+ string text = cHelpers::SetChannel(args);
+ sock->Write(text);
+ }
+ else if (cmd == "QUIT")
+ {
+ // close socket
+ sock->Write(string("Good bye! :-)\r\n"));
+ sock->Disconnect();
+ }
+
+ sock->Flush();
}
return true;