2 Copyright 2008 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef VOMPSTANDALONE
24 #include <vdr/recording.h>
25 #include <vdr/channels.h>
26 #include <vdr/videodir.h>
27 #include <vdr/plugin.h>
28 #include <vdr/timers.h>
30 #include "recplayer.h"
31 #include "mvpreceiver.h"
34 #include "vompclientrrproc.h"
35 #include "vompclient.h"
40 VompClientRRProc::VompClientRRProc(VompClient& x)
43 log = Log::getInstance();
48 VompClientRRProc::~VompClientRRProc()
53 bool VompClientRRProc::init()
58 bool VompClientRRProc::recvRequest(RequestPacket* newRequest)
62 Currently only one at once is supported but this
63 could be upgraded to a queueing system
70 log->log("RRProc", Log::ERR, "recvReq err 1");
78 log->log("RRProc", Log::DEBUG, "recvReq set req and signalled");
84 void VompClientRRProc::threadMethod()
87 log->log("RRProc", Log::DEBUG, "threadMethod startup");
93 log->log("RRProc", Log::ERR, "threadMethod err 1");
98 log->log("RRProc", Log::DEBUG, "threadMethod waiting");
99 threadWaitForSignal();
102 log->log("RRProc", Log::INFO, "threadMethod err 2 or quit");
107 log->log("RRProc", Log::DEBUG, "thread woken with req");
113 bool VompClientRRProc::processPacket()
115 resp = new ResponsePacket();
116 if (!resp->init(req->requestID))
118 log->log("RRProc", Log::ERR, "response packet init fail");
128 result = processLogin();
130 #ifndef VOMPSTANDALONE
132 result = processGetRecordingsList();
135 result = processDeleteRecording();
138 result = processGetChannelsList();
141 result = processStartStreamingChannel();
144 result = processGetBlock();
147 result = processStopStreaming();
150 result = processStartStreamingRecording();
154 result = processGetChannelSchedule();
157 result = processConfigSave();
160 result = processConfigLoad();
162 #ifndef VOMPSTANDALONE
164 result = processReScanRecording(); // FIXME obselete
167 result = processGetTimers();
170 result = processSetTimer();
173 result = processPositionFromFrameNumber();
176 result = processFrameNumberFromPosition();
179 result = processMoveRecording();
182 result = processGetIFrame();
185 result = processGetRecInfo();
188 result = processGetMarks();
191 result = processGetChannelPids();
194 result = processDeleteTimer();
198 result = processGetMediaList();
201 result = processGetPicture();
204 result = processGetImageBlock();
207 result = processGetLanguageList();
210 result = processGetLanguageContent();
217 if (req->data) free(req->data);
221 if (result) return true;
225 int VompClientRRProc::processLogin()
227 if (req->dataLength != 6) return 0;
231 char configFileName[PATH_MAX];
232 snprintf(configFileName, PATH_MAX, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", x.configDir, req->data[0], req->data[1], req->data[2], req->data[3], req->data[4], req->data[5]);
233 x.config.init(configFileName);
235 // Send the login reply
237 time_t timeNow = time(NULL);
238 struct tm* timeStruct = localtime(&timeNow);
239 int timeOffset = timeStruct->tm_gmtoff;
241 resp->addULONG(timeNow);
242 resp->addLONG(timeOffset);
244 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
245 log->log("RRProc", Log::DEBUG, "written login reply len %lu", resp->getLen());
251 int VompClientRRProc::processConfigSave()
253 char* section = (char*)req->data;
257 for (UINT k = 0; k < req->dataLength; k++)
259 if (req->data[k] == '\0')
263 key = (char*)&req->data[k+1];
267 value = (char*)&req->data[k+1];
273 // if the last string (value) doesnt have null terminator, give up
274 if (req->data[req->dataLength - 1] != '\0') return 0;
276 log->log("RRProc", Log::DEBUG, "Config save: %s %s %s", section, key, value);
277 if (x.config.setValueString(section, key, value))
287 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
292 int VompClientRRProc::processConfigLoad()
294 char* section = (char*)req->data;
297 for (UINT k = 0; k < req->dataLength; k++)
299 if (req->data[k] == '\0')
301 key = (char*)&req->data[k+1];
306 char* value = x.config.getValueString(section, key);
310 resp->addString(value);
311 log->log("RRProc", Log::DEBUG, "Written config load packet");
317 log->log("RRProc", Log::DEBUG, "Written config load failed packet");
321 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
327 * media List Request:
330 * 4 flags (currently unused)
333 * Media List response:
341 * 4 strlen (incl. 0 Byte)
346 int VompClientRRProc::processGetMediaList()
348 if (req->dataLength < 4) {
349 log->log("RRProc", Log::ERR, "getMediaList packet too short %d", req->dataLength);
353 if (req->dataLength > 4) {
354 //we have a dirname provided
355 dirname=(char *)&req->data[4];
356 log->log("RRProc", Log::DEBUG, "getMediaList for %s", dirname);
359 MediaList * ml=MediaList::readList(x.baseConfig, dirname);
361 log->log("RRProc", Log::ERR, "getMediaList returned NULL");
365 //response code (not yet set)
369 resp->addULONG(ml->size());
371 for (MediaList::iterator nm=ml->begin(); nm<ml->end(); nm++)
374 log->log("RRProc", Log::DEBUG, "found media entry %s, type=%d",m->getFilename(),m->getType());
375 resp->addULONG(m->getType());
377 resp->addULONG(m->getTime());
380 int len=strlen(m->getFilename());
382 resp->addULONG(len+1);
383 resp->addString(m->getFilename());
388 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
390 log->log("RRProc", Log::DEBUG, "Written Media list");
396 * 4 flags (currently unused)
401 * get image response:
407 int VompClientRRProc::processGetPicture()
409 if (req->dataLength < 12) {
410 log->log("RRProc", Log::ERR, "getPicture packet too short %d", req->dataLength);
417 char * filename=NULL;
418 if (req->dataLength > 12) {
419 //we have a dirname provided
420 filename=(char *)&req->data[12];
421 log->log("RRProc", Log::DEBUG, "getPicture %s", filename);
424 log->log("RRProc", Log::ERR, "getPicture empty filename");
427 x.imageFile=fopen(filename,"r");
428 if (!x.imageFile) log->log("RRProc", Log::ERR, "getPicture unable to open %s",filename);
433 if ( fstat(fileno(x.imageFile),&st) == 0) size=st.st_size;
435 //response code (not yet set)
438 resp->addULONG(size);
440 log->log("RRProc", Log::DEBUG, "getPicture size %u", size);
443 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
445 log->log("RRProc", Log::DEBUG, "Written getPicture");
451 int VompClientRRProc::processGetImageBlock()
455 log->log("RRProc", Log::DEBUG, "Get image block called when no image active");
459 UCHAR* data = req->data;
461 ULLONG position = x.ntohll(*(ULLONG*)data);
462 data += sizeof(ULLONG);
463 ULONG amount = ntohl(*(ULONG*)data);
465 log->log("RRProc", Log::DEBUG, "getImageblock pos = %llu length = %lu", position, amount);
467 UCHAR sendBuffer[amount];
468 ULONG amountReceived = 0; // compiler moan.
469 ULLONG cpos=ftell(x.imageFile);
470 if (position != cpos) {
471 fseek(x.imageFile,position-cpos,SEEK_CUR);
473 if (position != (ULLONG)ftell(x.imageFile)) {
474 log->log("RRProc", Log::DEBUG, "getImageblock pos = %llu not available", position);
477 amountReceived=fread(&sendBuffer[0],1,amount,x.imageFile);
483 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
487 resp->copyin(sendBuffer, amount);
488 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
492 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
498 int VompClientRRProc::processGetLanguageList()
500 x.i18n.findLanguages();
501 const I18n::lang_code_list& languages = x.i18n.getLanguageList();
503 I18n::lang_code_list::const_iterator iter;
504 for (iter = languages.begin(); iter != languages.end(); ++iter)
506 resp->addString(iter->first.c_str());
507 resp->addString(iter->second.c_str());
510 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
514 int VompClientRRProc::processGetLanguageContent()
516 if (req->dataLength <= 0) return 0;
517 std::string code, result;
518 code.assign((char*)req->data, req->dataLength - 1);
519 x.i18n.findLanguages();
520 I18n::trans_table texts = x.i18n.getLanguageContent(code);
521 I18n::trans_table::const_iterator iter;
522 for (iter = texts.begin(); iter != texts.end(); ++iter)
524 resp->addString(iter->first.c_str());
525 resp->addString(iter->second.c_str());
528 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
532 #ifndef VOMPSTANDALONE
534 int VompClientRRProc::processGetRecordingsList()
537 int Percent = VideoDiskSpace(&FreeMB);
538 int Total = (FreeMB / (100 - Percent)) * 100;
540 resp->addULONG(Total);
541 resp->addULONG(FreeMB);
542 resp->addULONG(Percent);
544 cRecordings Recordings;
547 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
549 resp->addULONG(recording->start);
550 resp->addString(recording->Name());
551 resp->addString(recording->FileName());
555 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
557 log->log("RRProc", Log::DEBUG, "Written recordings list");
562 int VompClientRRProc::processDeleteRecording()
564 // data is a pointer to the fileName string
566 cRecordings Recordings;
567 Recordings.Load(); // probably have to do this
569 cRecording* recording = Recordings.GetByName((char*)req->data);
571 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
575 log->log("RRProc", Log::DEBUG, "deleting recording: %s", recording->Name());
577 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
580 if (recording->Delete())
582 // Copy svdrp's way of doing this, see if it works
583 #if VDRVERSNUM > 10300
584 ::Recordings.DelByName(recording->FileName());
604 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
609 int VompClientRRProc::processMoveRecording()
611 log->log("RRProc", Log::DEBUG, "Process move recording");
612 char* fileName = (char*)req->data;
613 char* newPath = NULL;
615 for (UINT k = 0; k < req->dataLength; k++)
617 if (req->data[k] == '\0')
619 newPath = (char*)&req->data[k+1];
623 if (!newPath) return 0;
625 cRecordings Recordings;
626 Recordings.Load(); // probably have to do this
628 cRecording* recording = Recordings.GetByName((char*)fileName);
630 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
634 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
637 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->Name());
638 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->FileName());
639 log->log("RRProc", Log::DEBUG, "to: %s", newPath);
641 const char* t = recording->FileName();
643 char* dateDirName = NULL; int k;
644 char* titleDirName = NULL; int j;
646 // Find the datedirname
647 for(k = strlen(t) - 1; k >= 0; k--)
651 log->log("RRProc", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
652 dateDirName = new char[strlen(&t[k+1]) + 1];
653 strcpy(dateDirName, &t[k+1]);
658 // Find the titledirname
660 for(j = k-1; j >= 0; j--)
664 log->log("RRProc", Log::DEBUG, "l2: %i", (k - j - 1) + 1);
665 titleDirName = new char[(k - j - 1) + 1];
666 memcpy(titleDirName, &t[j+1], k - j - 1);
667 titleDirName[k - j - 1] = '\0';
672 log->log("RRProc", Log::DEBUG, "datedirname: %s", dateDirName);
673 log->log("RRProc", Log::DEBUG, "titledirname: %s", titleDirName);
674 log->log("RRProc", Log::DEBUG, "viddir: %s", VideoDirectory);
676 char* newPathConv = new char[strlen(newPath)+1];
677 strcpy(newPathConv, newPath);
678 ExchangeChars(newPathConv, true);
679 log->log("RRProc", Log::DEBUG, "EC: %s", newPathConv);
681 char* newContainer = new char[strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1];
682 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1);
683 sprintf(newContainer, "%s%s%s", VideoDirectory, newPathConv, titleDirName);
684 delete[] newPathConv;
686 log->log("RRProc", Log::DEBUG, "%s", newContainer);
689 int statret = stat(newContainer, &dstat);
690 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
692 log->log("RRProc", Log::DEBUG, "new dir does not exist");
693 int mkdirret = mkdir(newContainer, 0755);
696 delete[] dateDirName;
697 delete[] titleDirName;
698 delete[] newContainer;
702 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
706 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
708 delete[] dateDirName;
709 delete[] titleDirName;
710 delete[] newContainer;
714 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
718 // Ok, the directory container has been made, or it pre-existed.
720 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
721 sprintf(newDir, "%s/%s", newContainer, dateDirName);
723 log->log("RRProc", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
724 int renameret = rename(t, newDir);
727 // Success. Test for remove old dir containter
728 char* oldTitleDir = new char[k+1];
729 memcpy(oldTitleDir, t, k);
730 oldTitleDir[k] = '\0';
731 log->log("RRProc", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
732 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
733 delete[] oldTitleDir;
738 #if VDRVERSNUM > 10311
740 ::Recordings.Update();
742 // Success. Send a different packet from just a ulong
743 resp->addULONG(1); // success
744 resp->addString(newDir);
752 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
754 delete[] dateDirName;
755 delete[] titleDirName;
756 delete[] newContainer;
763 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
770 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
776 int VompClientRRProc::processGetChannelsList()
780 char* chanConfig = x.config.getValueString("General", "Channels");
782 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
784 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
786 #if VDRVERSNUM < 10300
787 if (!channel->GroupSep() && (!channel->Ca() || allChans))
789 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
792 log->log("RRProc", Log::DEBUG, "name: '%s'", channel->Name());
794 if (channel->Vpid()) type = 1;
795 #if VDRVERSNUM < 10300
798 else if (channel->Apid(0)) type = 2;
802 resp->addULONG(channel->Number());
803 resp->addULONG(type);
804 resp->addString(channel->Name());
809 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
811 log->log("RRProc", Log::DEBUG, "Written channels list");
816 int VompClientRRProc::processGetChannelPids()
818 ULONG channelNumber = ntohl(*(ULONG*)req->data);
820 cChannel* channel = x.channelFromNumber(channelNumber);
825 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
834 #if VDRVERSNUM < 10300
836 log->log("RRProc", Log::DEBUG, "Apid1: %i", channel->Apid1());
837 log->log("RRProc", Log::DEBUG, "Apid2: %i", channel->Apid2());
839 if (channel->Apid2())
841 else if (channel->Apid1())
848 for (const int *Apid = channel->Apids(); *Apid; Apid++)
852 for (const int *Dpid = channel->Dpids(); *Dpid; Dpid++)
856 for (const int *Spid = channel->Spids(); *Spid; Spid++)
863 // Format of response
882 resp->addULONG(channel->Vpid());
883 resp->addULONG(numApids);
885 #if VDRVERSNUM < 10300
888 resp->addULONG(channel->Apid1());
893 resp->addULONG(channel->Apid2());
899 for (ULONG i = 0; i < numApids; i++)
901 resp->addULONG(channel->Apid(i));
902 resp->addString(channel->Alang(i));
904 resp->addULONG(numDpids);
905 for (ULONG i = 0; i < numDpids; i++)
907 resp->addULONG(channel->Dpid(i));
908 resp->addString(channel->Dlang(i));
910 resp->addULONG(numSpids);
911 for (ULONG i = 0; i < numSpids; i++)
913 resp->addULONG(channel->Spid(i));
914 resp->addString(channel->Slang(i));
917 resp->addULONG(channel->Tpid());
921 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
923 log->log("RRProc", Log::DEBUG, "Written channels pids");
928 int VompClientRRProc::processStartStreamingChannel()
932 log->log("RRProc", Log::ERR, "Client called start streaming twice");
936 log->log("RRProc", Log::DEBUG, "req->dataLength = %i", req->dataLength);
937 ULONG channelNumber = ntohl(*(ULONG*)req->data);
939 cChannel* channel = x.channelFromNumber(channelNumber);
944 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
948 // get the priority we should use
950 int priority = x.config.getValueLong("General", "Live priority", &fail);
953 log->log("RRProc", Log::DEBUG, "Config: Live TV priority: %i", priority);
957 log->log("RRProc", Log::DEBUG, "Config: Live TV priority config fail");
962 if (priority < 0) priority = 0;
963 if (priority > 99) priority = 99;
965 log->log("RRProc", Log::DEBUG, "Using live TV priority %i", priority);
966 x.lp = MVPReceiver::create(channel, priority);
972 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
976 if (!x.lp->init(&x.tcp, req->requestID))
982 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
988 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
992 int VompClientRRProc::processStopStreaming()
994 log->log("RRProc", Log::DEBUG, "STOP STREAMING RECEIVED");
1000 else if (x.recplayer)
1002 x.writeResumeData();
1005 delete x.recordingManager;
1007 x.recordingManager = NULL;
1012 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1016 int VompClientRRProc::processGetBlock()
1018 if (!x.lp && !x.recplayer)
1020 log->log("RRProc", Log::DEBUG, "Get block called when no streaming happening!");
1024 UCHAR* data = req->data;
1026 ULLONG position = x.ntohll(*(ULLONG*)data);
1027 data += sizeof(ULLONG);
1028 ULONG amount = ntohl(*(ULONG*)data);
1030 log->log("RRProc", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
1032 UCHAR sendBuffer[amount];
1033 ULONG amountReceived = 0; // compiler moan.
1036 log->log("RRProc", Log::DEBUG, "getting from live");
1037 amountReceived = x.lp->getBlock(&sendBuffer[0], amount);
1039 if (!amountReceived)
1041 // vdr has possibly disconnected the receiver
1042 log->log("RRProc", Log::DEBUG, "VDR has disconnected the live receiver");
1047 else if (x.recplayer)
1049 log->log("RRProc", Log::DEBUG, "getting from recording");
1050 amountReceived = x.recplayer->getBlock(&sendBuffer[0], position, amount);
1053 if (!amountReceived)
1056 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
1060 resp->copyin(sendBuffer, amountReceived);
1061 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
1065 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1066 log->log("RRProc", Log::DEBUG, "Finished getblock, have sent %lu", resp->getLen());
1070 int VompClientRRProc::processStartStreamingRecording()
1072 // data is a pointer to the fileName string
1074 x.recordingManager = new cRecordings;
1075 x.recordingManager->Load();
1077 cRecording* recording = x.recordingManager->GetByName((char*)req->data);
1079 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1083 x.recplayer = new RecPlayer(recording);
1085 resp->addULLONG(x.recplayer->getLengthBytes());
1086 resp->addULONG(x.recplayer->getLengthFrames());
1088 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1090 log->log("RRProc", Log::DEBUG, "written totalLength");
1094 delete x.recordingManager;
1095 x.recordingManager = NULL;
1100 int VompClientRRProc::processPositionFromFrameNumber()
1104 ULONG frameNumber = ntohl(*(ULONG*)req->data);
1108 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1112 retval = x.recplayer->positionFromFrameNumber(frameNumber);
1115 resp->addULLONG(retval);
1117 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1119 log->log("RRProc", Log::DEBUG, "Wrote posFromFrameNum reply to client");
1123 int VompClientRRProc::processFrameNumberFromPosition()
1127 ULLONG position = x.ntohll(*(ULLONG*)req->data);
1131 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1135 retval = x.recplayer->frameNumberFromPosition(position);
1138 resp->addULONG(retval);
1140 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1142 log->log("RRProc", Log::DEBUG, "Wrote frameNumFromPos reply to client");
1146 int VompClientRRProc::processGetIFrame()
1148 bool success = false;
1150 ULONG* data = (ULONG*)req->data;
1152 ULONG frameNumber = ntohl(*data);
1154 ULONG direction = ntohl(*data);
1156 ULLONG rfilePosition = 0;
1157 ULONG rframeNumber = 0;
1158 ULONG rframeLength = 0;
1162 log->log("RRProc", Log::DEBUG, "GetIFrame recording called when no recording being played!");
1166 success = x.recplayer->getNextIFrame(frameNumber, direction, &rfilePosition, &rframeNumber, &rframeLength);
1169 // returns file position, frame number, length
1173 resp->addULLONG(rfilePosition);
1174 resp->addULONG(rframeNumber);
1175 resp->addULONG(rframeLength);
1183 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1185 log->log("RRProc", Log::DEBUG, "Wrote GNIF reply to client %llu %lu %lu", rfilePosition, rframeNumber, rframeLength);
1189 int VompClientRRProc::processGetChannelSchedule()
1191 ULONG* data = (ULONG*)req->data;
1193 ULONG channelNumber = ntohl(*data);
1195 ULONG startTime = ntohl(*data);
1197 ULONG duration = ntohl(*data);
1199 log->log("RRProc", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
1201 cChannel* channel = x.channelFromNumber(channelNumber);
1206 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1208 log->log("RRProc", Log::DEBUG, "written 0 because channel = NULL");
1212 log->log("RRProc", Log::DEBUG, "Got channel");
1214 #if VDRVERSNUM < 10300
1215 cMutexLock MutexLock;
1216 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1218 cSchedulesLock MutexLock;
1219 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1225 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1227 log->log("RRProc", Log::DEBUG, "written 0 because Schedule!s! = NULL");
1231 log->log("RRProc", Log::DEBUG, "Got schedule!s! object");
1233 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
1238 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1240 log->log("RRProc", Log::DEBUG, "written 0 because Schedule = NULL");
1244 log->log("RRProc", Log::DEBUG, "Got schedule object");
1246 const char* empty = "";
1247 bool atLeastOneEvent = false;
1250 ULONG thisEventTime;
1251 ULONG thisEventDuration;
1252 const char* thisEventTitle;
1253 const char* thisEventSubTitle;
1254 const char* thisEventDescription;
1256 #if VDRVERSNUM < 10300
1258 const cEventInfo *event;
1259 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1261 event = Schedule->GetEventNumber(eventNumber);
1263 thisEventID = event->GetEventID();
1264 thisEventTime = event->GetTime();
1265 thisEventDuration = event->GetDuration();
1266 thisEventTitle = event->GetTitle();
1267 thisEventSubTitle = event->GetSubtitle();
1268 thisEventDescription = event->GetExtendedDescription();
1272 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
1274 thisEventID = event->EventID();
1275 thisEventTime = event->StartTime();
1276 thisEventDuration = event->Duration();
1277 thisEventTitle = event->Title();
1278 thisEventSubTitle = NULL;
1279 thisEventDescription = event->Description();
1283 //in the past filter
1284 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
1287 if ((thisEventTime + thisEventDuration) <= startTime) continue;
1290 if (thisEventTime >= (startTime + duration)) continue;
1292 if (!thisEventTitle) thisEventTitle = empty;
1293 if (!thisEventSubTitle) thisEventSubTitle = empty;
1294 if (!thisEventDescription) thisEventDescription = empty;
1296 resp->addULONG(thisEventID);
1297 resp->addULONG(thisEventTime);
1298 resp->addULONG(thisEventDuration);
1300 resp->addString(thisEventTitle);
1301 resp->addString(thisEventSubTitle);
1302 resp->addString(thisEventDescription);
1304 atLeastOneEvent = true;
1307 log->log("RRProc", Log::DEBUG, "Got all event data");
1309 if (!atLeastOneEvent)
1312 log->log("RRProc", Log::DEBUG, "Written 0 because no data");
1316 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1318 log->log("RRProc", Log::DEBUG, "written schedules packet");
1323 int VompClientRRProc::processGetTimers()
1326 int numTimers = Timers.Count();
1328 resp->addULONG(numTimers);
1330 for (int i = 0; i < numTimers; i++)
1332 timer = Timers.Get(i);
1334 #if VDRVERSNUM < 10300
1335 resp->addULONG(timer->Active());
1337 resp->addULONG(timer->HasFlags(tfActive));
1339 resp->addULONG(timer->Recording());
1340 resp->addULONG(timer->Pending());
1341 resp->addULONG(timer->Priority());
1342 resp->addULONG(timer->Lifetime());
1343 resp->addULONG(timer->Channel()->Number());
1344 resp->addULONG(timer->StartTime());
1345 resp->addULONG(timer->StopTime());
1346 resp->addULONG(timer->Day());
1347 resp->addULONG(timer->WeekDays());
1348 resp->addString(timer->File());
1352 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1354 log->log("RRProc", Log::DEBUG, "Written timers list");
1359 int VompClientRRProc::processSetTimer()
1361 char* timerString = new char[strlen((char*)req->data) + 1];
1362 strcpy(timerString, (char*)req->data);
1364 #if VDRVERSNUM < 10300
1366 // If this is VDR 1.2 the date part of the timer string must be reduced
1367 // to just DD rather than YYYY-MM-DD
1369 int s = 0; // source
1370 int d = 0; // destination
1372 while(c != 2) // copy up to date section, including the second ':'
1374 timerString[d] = req->data[s];
1375 if (req->data[s] == ':') c++;
1379 // now it has copied up to the date section
1381 while(c != 2) // waste YYYY-MM-
1383 if (req->data[s] == '-') c++;
1386 // now source is at the DD
1387 memcpy(&timerString[d], &req->data[s], req->dataLength - s);
1388 d += req->dataLength - s;
1389 timerString[d] = '\0';
1391 log->log("RRProc", Log::DEBUG, "Timer string after 1.2 conversion:");
1392 log->log("RRProc", Log::DEBUG, "%s", timerString);
1396 cTimer *timer = new cTimer;
1397 if (timer->Parse((char*)timerString))
1399 cTimer *t = Timers.GetTimer(timer);
1403 #if VDRVERSNUM < 10300
1406 Timers.SetModified();
1410 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1417 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1424 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1430 int VompClientRRProc::processDeleteTimer()
1432 log->log("RRProc", Log::DEBUG, "Delete timer called");
1437 INT delChannel = ntohl(*(ULONG*)&req->data[position]); position += 4;
1438 INT delWeekdays = ntohl(*(ULONG*)&req->data[position]); position += 4;
1439 INT delDay = ntohl(*(ULONG*)&req->data[position]); position += 4;
1440 INT delStart = ntohl(*(ULONG*)&req->data[position]); position += 4;
1441 INT delStop = ntohl(*(ULONG*)&req->data[position]); position += 4;
1444 for (ti = Timers.First(); ti; ti = Timers.Next(ti))
1446 if ( (ti->Channel()->Number() == delChannel)
1447 && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay)))
1448 && (ti->StartTime() == delStart)
1449 && (ti->StopTime() == delStop) )
1457 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1461 if (!Timers.BeingEdited())
1463 if (!ti->Recording())
1466 Timers.SetModified();
1469 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1474 log->log("RRProc", Log::ERR, "Unable to delete timer - timer is running");
1477 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1483 log->log("RRProc", Log::ERR, "Unable to delete timer - timers being edited at VDR");
1486 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1491 int VompClientRRProc::processGetRecInfo()
1493 // data is a pointer to the fileName string
1495 cRecordings Recordings;
1496 Recordings.Load(); // probably have to do this
1498 cRecording *recording = Recordings.GetByName((char*)req->data);
1500 time_t timerStart = 0;
1501 time_t timerStop = 0;
1502 char* summary = NULL;
1503 ULONG resumePoint = 0;
1507 log->log("RRProc", Log::ERR, "GetRecInfo found no recording");
1510 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1515 4 bytes: start time for timer
1516 4 bytes: end time for timer
1517 4 bytes: resume point
1519 4 bytes: num components
1529 // Get current timer
1531 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
1534 timerStart = rc->Timer()->StartTime();
1535 timerStop = rc->Timer()->StopTime();
1536 log->log("RRProc", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop);
1539 resp->addULONG(timerStart);
1540 resp->addULONG(timerStop);
1544 char* value = x.config.getValueString("ResumeData", (char*)req->data);
1547 resumePoint = strtoul(value, NULL, 10);
1550 log->log("RRProc", Log::DEBUG, "GRI: RP: %lu", resumePoint);
1552 resp->addULONG(resumePoint);
1557 #if VDRVERSNUM < 10300
1558 summary = (char*)recording->Summary();
1560 const cRecordingInfo *Info = recording->Info();
1561 summary = (char*)Info->ShortText();
1562 if (isempty(summary)) summary = (char*)Info->Description();
1564 log->log("RRProc", Log::DEBUG, "GRI: S: %s", summary);
1567 resp->addString(summary);
1571 resp->addString("");
1576 #if VDRVERSNUM < 10300
1578 // Send 0 for numchannels - this signals the client this info is not available
1582 const cComponents* components = Info->Components();
1584 log->log("RRProc", Log::DEBUG, "GRI: D1: %p", components);
1592 resp->addULONG(components->NumComponents());
1594 tComponent* component;
1595 for (int i = 0; i < components->NumComponents(); i++)
1597 component = components->Component(i);
1599 log->log("RRProc", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description);
1601 resp->addUCHAR(component->stream);
1602 resp->addUCHAR(component->type);
1604 if (component->language)
1606 resp->addString(component->language);
1610 resp->addString("");
1612 if (component->description)
1614 resp->addString(component->description);
1618 resp->addString("");
1628 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1630 log->log("RRProc", Log::DEBUG, "Written getrecinfo");
1640 int VompClientRRProc::processReScanRecording()
1644 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1648 x.recplayer->scan();
1650 resp->addULLONG(x.recplayer->getLengthBytes());
1651 resp->addULONG(x.recplayer->getLengthFrames());
1653 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1654 log->log("RRProc", Log::DEBUG, "Rescan recording, wrote new length to client");
1658 // FIXME without client calling rescan, getblock wont work even tho more data is avail
1660 int VompClientRRProc::processGetMarks()
1662 // data is a pointer to the fileName string
1665 cRecordings Recordings;
1666 Recordings.Load(); // probably have to do this
1668 cRecording *recording = Recordings.GetByName((char*)req->data);
1670 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1674 Marks.Load(recording->FileName());
1677 for (const cMark *m = Marks.First(); m; m = Marks.Next(m))
1679 log->log("RRProc", Log::DEBUG, "found Mark %i", m->position);
1681 resp->addULONG(m->position);
1686 log->log("RRProc", Log::DEBUG, "no marks found, sending 0-mark");
1692 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1694 log->log("RRProc", Log::DEBUG, "Written Marks list");
1699 #endif // !VOMPSTANDALONE