2 Copyright 2004-2005 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mvpclient.h"
23 // This is here else it causes compile errors with something in libdvbmpeg
26 MVPClient::MVPClient(char* tconfigDirExtra, int tsocket)
31 recordingManager = NULL;
32 log = Log::getInstance();
34 configDirExtra = tconfigDirExtra;
37 MVPClient::~MVPClient()
39 log->log("Client", Log::DEBUG, "MVP client destructor");
50 delete recordingManager;
52 recordingManager = NULL;
55 if (loggedIn) cleanConfig();
58 ULLONG MVPClient::ntohll(ULLONG a)
63 ULLONG MVPClient::htonll(ULLONG a)
65 #if BYTE_ORDER == BIG_ENDIAN
70 b = ((a << 56) & 0xFF00000000000000ULL)
71 | ((a << 40) & 0x00FF000000000000ULL)
72 | ((a << 24) & 0x0000FF0000000000ULL)
73 | ((a << 8) & 0x000000FF00000000ULL)
74 | ((a >> 8) & 0x00000000FF000000ULL)
75 | ((a >> 24) & 0x0000000000FF0000ULL)
76 | ((a >> 40) & 0x000000000000FF00ULL)
77 | ((a >> 56) & 0x00000000000000FFULL) ;
83 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
85 cChannel* channel = NULL;
87 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
89 if (!channel->GroupSep())
91 log->log("Client", Log::DEBUG, "Looking for channel %lu::: number: %i name: '%s'", channelNumber, channel->Number(), channel->Name());
93 if (channel->Number() == (int)channelNumber)
95 int vpid = channel->Vpid();
96 #if VDRVERSNUM < 10300
97 int apid1 = channel->Apid1();
99 int apid1 = channel->Apid(0);
101 log->log("Client", Log::DEBUG, "Found channel number %lu, vpid = %i, apid1 = %i", channelNumber, vpid, apid1);
109 log->log("Client", Log::DEBUG, "Channel not found");
115 void MVPClient::writeResumeData()
117 config.setValueLong("ResumeData",
118 (char*)rp->getCurrentRecording()->FileName(),
119 rp->frameNumberFromPosition(rp->getLastPosition()) );
122 void MVPClient::sendULONG(ULONG ul)
125 *(ULONG*)&sendBuffer[0] = htonl(4);
126 *(ULONG*)&sendBuffer[4] = htonl(ul);
128 tcp.sendPacket(sendBuffer, 8);
129 log->log("Client", Log::DEBUG, "written ULONG %lu", ul);
132 void MVPClientStartThread(void* arg)
134 MVPClient* m = (MVPClient*)arg;
136 // Nothing external to this class has a reference to it
137 // This is the end of the thread.. so delete m
144 if (pthread_create(&runThread, NULL, (void*(*)(void*))MVPClientStartThread, (void *)this) == -1) return 0;
145 log->log("Client", Log::DEBUG, "MVPClient run success");
149 void MVPClient::run2()
154 pthread_sigmask(SIG_BLOCK, &sigset, NULL);
155 pthread_detach(runThread); // Detach
157 tcp.disableReadTimeout();
159 tcp.setSoKeepTime(3);
160 tcp.setNonBlocking();
170 log->log("Client", Log::DEBUG, "Waiting");
171 buffer = (UCHAR*)tcp.receivePacket();
172 log->log("Client", Log::DEBUG, "Received packet, length = %u", tcp.getDataLength());
175 log->log("Client", Log::DEBUG, "Detected connection closed");
179 packetLength = tcp.getDataLength() - 4;
180 opcode = ntohl(*(ULONG*)buffer);
183 if (!loggedIn && (opcode != 1))
189 log->log("Client", Log::DEBUG, "SwitchOp");
193 result = processLogin(data, packetLength);
196 result = processGetRecordingsList(data, packetLength);
199 result = processDeleteRecording(data, packetLength);
202 result = processGetChannelsList(data, packetLength);
205 result = processStartStreamingChannel(data, packetLength);
208 result = processGetBlock(data, packetLength);
211 result = processStopStreaming(data, packetLength);
214 result = processStartStreamingRecording(data, packetLength);
217 result = processGetChannelSchedule(data, packetLength);
220 result = processConfigSave(data, packetLength);
223 result = processConfigLoad(data, packetLength);
226 result = processReScanRecording(data, packetLength); // FIXME obselete
229 result = processGetTimers(data, packetLength);
232 result = processSetTimer(data, packetLength);
235 result = processPositionFromFrameNumber(data, packetLength);
238 result = processFrameNumberFromPosition(data, packetLength);
241 result = processMoveRecording(data, packetLength);
244 result = processGetIFrame(data, packetLength);
247 result = processGetRecInfo(data, packetLength);
250 result = processGetMarks(data, packetLength);
253 result = processGetChannelPids(data, packetLength);
262 int MVPClient::processLogin(UCHAR* buffer, int length)
264 if (length != 6) return 0;
268 const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
271 log->log("Client", Log::DEBUG, "No config dir!");
275 char configFileName[PATH_MAX];
276 snprintf(configFileName, PATH_MAX, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", configDir, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
277 config.init(configFileName);
279 // Send the login reply
281 time_t timeNow = time(NULL);
282 struct tm* timeStruct = localtime(&timeNow);
283 int timeOffset = timeStruct->tm_gmtoff;
285 UCHAR sendBuffer[12];
286 *(ULONG*)&sendBuffer[0] = htonl(8);
287 *(ULONG*)&sendBuffer[4] = htonl(timeNow);
288 *(signed int*)&sendBuffer[8] = htonl(timeOffset);
290 tcp.sendPacket(sendBuffer, 12);
291 log->log("Client", Log::DEBUG, "written login reply");
297 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
299 UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
300 int count = 4; // leave space for the packet length
305 int Percent = VideoDiskSpace(&FreeMB);
306 int Total = (FreeMB / (100 - Percent)) * 100;
308 *(ULONG*)&sendBuffer[count] = htonl(Total);
309 count += sizeof(ULONG);
310 *(ULONG*)&sendBuffer[count] = htonl(FreeMB);
311 count += sizeof(ULONG);
312 *(ULONG*)&sendBuffer[count] = htonl(Percent);
313 count += sizeof(ULONG);
316 cRecordings Recordings;
319 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
321 if (count > 49000) break; // just how big is that hard disk?!
322 *(ULONG*)&sendBuffer[count] = htonl(recording->start);// + timeOffset);
325 point = (char*)recording->Name();
326 strcpy((char*)&sendBuffer[count], point);
327 count += strlen(point) + 1;
329 point = (char*)recording->FileName();
330 strcpy((char*)&sendBuffer[count], point);
331 count += strlen(point) + 1;
334 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
336 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
338 tcp.sendPacket(sendBuffer, count);
340 log->log("Client", Log::DEBUG, "Written list");
345 int MVPClient::processDeleteRecording(UCHAR* data, int length)
347 // data is a pointer to the fileName string
349 cRecordings Recordings;
350 Recordings.Load(); // probably have to do this
352 cRecording* recording = Recordings.GetByName((char*)data);
354 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
358 log->log("Client", Log::DEBUG, "deleting recording: %s", recording->Name());
360 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
363 if (recording->Delete())
365 // Copy svdrp's way of doing this, see if it works
366 #if VDRVERSNUM > 10300
367 ::Recordings.DelByName(recording->FileName());
389 int MVPClient::processMoveRecording(UCHAR* data, int length)
391 log->log("Client", Log::DEBUG, "Process move recording");
392 char* fileName = (char*)data;
393 char* newPath = NULL;
395 for (int k = 0; k < length; k++)
399 newPath = (char*)&data[k+1];
403 if (!newPath) return 0;
405 cRecordings Recordings;
406 Recordings.Load(); // probably have to do this
408 cRecording* recording = Recordings.GetByName((char*)fileName);
410 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
414 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
417 log->log("Client", Log::DEBUG, "moving recording: %s", recording->Name());
418 log->log("Client", Log::DEBUG, "moving recording: %s", recording->FileName());
419 log->log("Client", Log::DEBUG, "to: %s", newPath);
421 const char* t = recording->FileName();
423 char* dateDirName = NULL; int k;
424 char* titleDirName = NULL; int j;
426 // Find the datedirname
427 for(k = strlen(t) - 1; k >= 0; k--)
431 log->log("Client", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
432 dateDirName = new char[strlen(&t[k+1]) + 1];
433 strcpy(dateDirName, &t[k+1]);
438 // Find the titledirname
440 for(j = k-1; j >= 0; j--)
444 log->log("Client", Log::DEBUG, "l2: %i", (k - j - 1) + 1);
445 titleDirName = new char[(k - j - 1) + 1];
446 memcpy(titleDirName, &t[j+1], k - j - 1);
447 titleDirName[k - j - 1] = '\0';
452 log->log("Client", Log::DEBUG, "datedirname: %s", dateDirName);
453 log->log("Client", Log::DEBUG, "titledirname: %s", titleDirName);
455 log->log("Client", Log::DEBUG, "viddir: %s", VideoDirectory);
457 char* newContainer = new char[strlen(VideoDirectory) + strlen(newPath) + strlen(titleDirName) + 1];
458 log->log("Client", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPath) + strlen(titleDirName) + 1);
459 sprintf(newContainer, "%s%s%s", VideoDirectory, newPath, titleDirName);
461 // FIXME Check whether this already exists before mkdiring it
463 log->log("Client", Log::DEBUG, "%s", newContainer);
467 int statret = stat(newContainer, &dstat);
468 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
470 log->log("Client", Log::DEBUG, "new dir does not exist");
471 int mkdirret = mkdir(newContainer, 0755);
474 delete[] dateDirName;
475 delete[] titleDirName;
476 delete[] newContainer;
481 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
483 delete[] dateDirName;
484 delete[] titleDirName;
485 delete[] newContainer;
490 // Ok, the directory container has been made, or it pre-existed.
492 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
493 sprintf(newDir, "%s/%s", newContainer, dateDirName);
495 log->log("Client", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
496 int renameret = rename(t, newDir);
499 // Success. Test for remove old dir containter
500 char* oldTitleDir = new char[k+1];
501 memcpy(oldTitleDir, t, k);
502 oldTitleDir[k] = '\0';
503 log->log("Client", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
504 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
505 delete[] oldTitleDir;
510 #if VDRVERSNUM > 10311
512 ::Recordings.Update();
514 // Success. Send a different packet from just a ulong
515 int totalLength = 4 + 4 + strlen(newDir) + 1;
516 UCHAR* sendBuffer = new UCHAR[totalLength];
517 *(ULONG*)&sendBuffer[0] = htonl(totalLength - 4);
518 *(ULONG*)&sendBuffer[4] = htonl(1); // success
519 strcpy((char*)&sendBuffer[8], newDir);
520 tcp.sendPacket(sendBuffer, totalLength);
528 delete[] dateDirName;
529 delete[] titleDirName;
530 delete[] newContainer;
546 int MVPClient::processGetChannelsList(UCHAR* data, int length)
548 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
549 int count = 4; // leave space for the packet length
553 char* chanConfig = config.getValueString("General", "Channels");
555 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
557 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
559 #if VDRVERSNUM < 10300
560 if (!channel->GroupSep() && (!channel->Ca() || allChans))
562 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
565 log->log("Client", Log::DEBUG, "name: '%s'", channel->Name());
567 if (channel->Vpid()) type = 1;
568 #if VDRVERSNUM < 10300
571 else if (channel->Apid(0)) type = 2;
575 if (count > 49000) break;
576 *(ULONG*)&sendBuffer[count] = htonl(channel->Number());
579 *(ULONG*)&sendBuffer[count] = htonl(type);
582 point = (char*)channel->Name();
583 strcpy((char*)&sendBuffer[count], point);
584 count += strlen(point) + 1;
588 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
590 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
592 tcp.sendPacket(sendBuffer, count);
594 log->log("Client", Log::DEBUG, "Written channels list");
599 int MVPClient::processGetChannelPids(UCHAR* data, int length)
601 ULONG channelNumber = ntohl(*(ULONG*)data);
603 cChannel* channel = channelFromNumber(channelNumber);
611 ULONG spaceRequired = 12; // 4 for length field, 4 for vpid, 4 for number of apids
612 // Work out space required and number of Apids
614 #if VDRVERSNUM < 10300
616 log->log("Client", Log::DEBUG, "Apid1: %i", channel->Apid1());
617 log->log("Client", Log::DEBUG, "Apid2: %i", channel->Apid2());
619 if (channel->Apid2())
622 spaceRequired += 10; // 8 + 2 nulls
624 else if (channel->Apid1())
627 spaceRequired += 5; // 4 + 1 null
636 for (const int *Apid = channel->Apids(); *Apid; Apid++)
638 spaceRequired += 4 + strlen(channel->Alang(numApids)) + 1; // 4 for pid, length of string + \0
644 // Format of response
652 UCHAR* sendBuffer = new UCHAR[spaceRequired];
654 *(ULONG*)&sendBuffer[point] = htonl(spaceRequired - 4); point += 4; // take off first 4 bytes
655 *(ULONG*)&sendBuffer[point] = htonl(channel->Vpid()); point += 4;
656 *(ULONG*)&sendBuffer[point] = htonl(numApids); point += 4;
658 #if VDRVERSNUM < 10300
661 *(ULONG*)&sendBuffer[point] = htonl(channel->Apid1()); point += 4;
662 sendBuffer[point] = '\0'; point += 1;
666 *(ULONG*)&sendBuffer[point] = htonl(channel->Apid2()); point += 4;
667 sendBuffer[point] = '\0'; point += 1;
670 for (ULONG i = 0; i < numApids; i++)
672 *(ULONG*)&sendBuffer[point] = htonl(channel->Apid(i)); point += 4;
673 strcpy((char*)&sendBuffer[point], channel->Alang(i)); point += strlen(channel->Alang(i)) + 1;
677 // printf("About to send getchannelpids response. length = %u\n", spaceRequired);
678 tcp.dump(sendBuffer, spaceRequired);
680 tcp.sendPacket(sendBuffer, spaceRequired);
682 log->log("Client", Log::DEBUG, "Written channels pids");
687 int MVPClient::processStartStreamingChannel(UCHAR* data, int length)
689 log->log("Client", Log::DEBUG, "length = %i", length);
690 ULONG channelNumber = ntohl(*(ULONG*)data);
692 cChannel* channel = channelFromNumber(channelNumber);
699 // get the priority we should use
701 int priority = config.getValueLong("General", "Live priority", &fail);
704 log->log("Client", Log::DEBUG, "Config: Live TV priority: %i", priority);
708 log->log("Client", Log::DEBUG, "Config: Live TV priority config fail");
713 if (priority < 0) priority = 0;
714 if (priority > 99) priority = 99;
716 log->log("Client", Log::DEBUG, "Using live TV priority %i", priority);
717 lp = MVPReceiver::create(channel, priority);
737 int MVPClient::processStopStreaming(UCHAR* data, int length)
739 log->log("Client", Log::DEBUG, "STOP STREAMING RECEIVED");
750 delete recordingManager;
752 recordingManager = NULL;
759 int MVPClient::processGetBlock(UCHAR* data, int length)
763 log->log("Client", Log::DEBUG, "Get block called when no streaming happening!");
767 ULLONG position = ntohll(*(ULLONG*)data);
768 data += sizeof(ULLONG);
769 ULONG amount = ntohl(*(ULONG*)data);
771 log->log("Client", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
773 UCHAR sendBuffer[amount + 4];
774 ULONG amountReceived = 0; // compiler moan.
777 log->log("Client", Log::DEBUG, "getting from live");
778 amountReceived = lp->getBlock(&sendBuffer[4], amount);
782 // vdr has possibly disconnected the receiver
783 log->log("Client", Log::DEBUG, "VDR has disconnected the live receiver");
790 log->log("Client", Log::DEBUG, "getting from recording");
791 amountReceived = rp->getBlock(&sendBuffer[4], position, amount);
797 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
801 *(ULONG*)&sendBuffer[0] = htonl(amountReceived);
802 tcp.sendPacket(sendBuffer, amountReceived + 4);
803 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
809 int MVPClient::processStartStreamingRecording(UCHAR* data, int length)
811 // data is a pointer to the fileName string
813 recordingManager = new cRecordings;
814 recordingManager->Load();
816 cRecording* recording = recordingManager->GetByName((char*)data);
818 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
822 rp = new RecPlayer(recording);
824 UCHAR sendBuffer[16];
825 *(ULONG*)&sendBuffer[0] = htonl(12);
826 *(ULLONG*)&sendBuffer[4] = htonll(rp->getLengthBytes());
827 *(ULONG*)&sendBuffer[12] = htonl(rp->getLengthFrames());
829 tcp.sendPacket(sendBuffer, 16);
830 log->log("Client", Log::DEBUG, "written totalLength");
834 delete recordingManager;
835 recordingManager = NULL;
840 int MVPClient::processPositionFromFrameNumber(UCHAR* data, int length)
844 ULONG frameNumber = ntohl(*(ULONG*)data);
849 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
853 retval = rp->positionFromFrameNumber(frameNumber);
856 UCHAR sendBuffer[12];
857 *(ULONG*)&sendBuffer[0] = htonl(8);
858 *(ULLONG*)&sendBuffer[4] = htonll(retval);
860 tcp.sendPacket(sendBuffer, 12);
861 log->log("Client", Log::DEBUG, "Wrote posFromFrameNum reply to client");
865 int MVPClient::processFrameNumberFromPosition(UCHAR* data, int length)
869 ULLONG position = ntohll(*(ULLONG*)data);
874 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
878 retval = rp->frameNumberFromPosition(position);
882 *(ULONG*)&sendBuffer[0] = htonl(4);
883 *(ULONG*)&sendBuffer[4] = htonl(retval);
885 tcp.sendPacket(sendBuffer, 8);
886 log->log("Client", Log::DEBUG, "Wrote frameNumFromPos reply to client");
890 int MVPClient::processGetIFrame(UCHAR* data, int length)
892 bool success = false;
894 ULONG frameNumber = ntohl(*(ULONG*)data);
896 ULONG direction = ntohl(*(ULONG*)data);
899 ULLONG rfilePosition = 0;
900 ULONG rframeNumber = 0;
901 ULONG rframeLength = 0;
905 log->log("Client", Log::DEBUG, "GetIFrame recording called when no recording being played!");
909 success = rp->getNextIFrame(frameNumber, direction, &rfilePosition, &rframeNumber, &rframeLength);
912 // returns file position, frame number, length
914 UCHAR sendBuffer[20];
920 *(ULONG*)&sendBuffer[0] = htonl(16);
921 *(ULLONG*)&sendBuffer[4] = htonll(rfilePosition);
922 *(ULONG*)&sendBuffer[12] = htonl(rframeNumber);
923 *(ULONG*)&sendBuffer[16] = htonl(rframeLength);
928 *(ULONG*)&sendBuffer[0] = htonl(4);
929 *(ULONG*)&sendBuffer[4] = 0;
932 log->log("Client", Log::DEBUG, "%llu %lu %lu", rfilePosition, rframeNumber, rframeLength);
934 tcp.sendPacket(sendBuffer, packetLength);
935 log->log("Client", Log::DEBUG, "Wrote GNIF reply to client");
939 int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
941 ULONG channelNumber = ntohl(*(ULONG*)data);
943 ULONG startTime = ntohl(*(ULONG*)data);
945 ULONG duration = ntohl(*(ULONG*)data);
947 log->log("Client", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
949 cChannel* channel = channelFromNumber(channelNumber);
953 log->log("Client", Log::DEBUG, "written 0 because channel = NULL");
957 log->log("Client", Log::DEBUG, "Got channel");
959 #if VDRVERSNUM < 10300
960 cMutexLock MutexLock;
961 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
963 cSchedulesLock MutexLock;
964 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
969 log->log("Client", Log::DEBUG, "written 0 because Schedule!s! = NULL");
973 log->log("Client", Log::DEBUG, "Got schedule!s! object");
975 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
979 log->log("Client", Log::DEBUG, "written 0 because Schedule = NULL");
983 log->log("Client", Log::DEBUG, "Got schedule object");
985 UCHAR* sendBuffer = (UCHAR*)malloc(100000);
986 ULONG sendBufferLength = 100000;
987 ULONG sendBufferUsed = sizeof(ULONG); // leave a hole for the entire packet length
991 // assign all the event info to temp vars then we know exactly what size they are
994 ULONG thisEventDuration;
995 const char* thisEventTitle;
996 const char* thisEventSubTitle;
997 const char* thisEventDescription;
999 ULONG constEventLength = sizeof(thisEventID) + sizeof(thisEventTime) + sizeof(thisEventDuration);
1000 ULONG thisEventLength;
1002 #if VDRVERSNUM < 10300
1004 const cEventInfo *event;
1005 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1007 event = Schedule->GetEventNumber(eventNumber);
1009 thisEventID = event->GetEventID();
1010 thisEventTime = event->GetTime();
1011 thisEventDuration = event->GetDuration();
1012 thisEventTitle = event->GetTitle();
1013 thisEventSubTitle = event->GetSubtitle();
1014 thisEventDescription = event->GetExtendedDescription();
1018 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
1020 thisEventID = event->EventID();
1021 thisEventTime = event->StartTime();
1022 thisEventDuration = event->Duration();
1023 thisEventTitle = event->Title();
1024 thisEventSubTitle = NULL;
1025 thisEventDescription = event->Description();
1029 log->log("Client", Log::DEBUG, "Got an event object %p", event);
1031 //in the past filter
1032 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
1035 if ((thisEventTime + thisEventDuration) <= startTime) continue;
1038 if (thisEventTime >= (startTime + duration)) continue;
1040 if (!thisEventTitle) thisEventTitle = empty;
1041 if (!thisEventSubTitle) thisEventSubTitle = empty;
1042 if (!thisEventDescription) thisEventDescription = empty;
1044 thisEventLength = constEventLength + strlen(thisEventTitle) + 1 + strlen(thisEventSubTitle) + 1 + strlen(thisEventDescription) + 1;
1046 log->log("Client", Log::DEBUG, "Done s1");
1048 // now extend the buffer if necessary
1049 if ((sendBufferUsed + thisEventLength) > sendBufferLength)
1051 log->log("Client", Log::DEBUG, "Extending buffer");
1052 sendBufferLength += 100000;
1053 UCHAR* temp = (UCHAR*)realloc(sendBuffer, sendBufferLength);
1057 UCHAR sendBuffer2[8];
1058 *(ULONG*)&sendBuffer2[0] = htonl(4);
1059 *(ULONG*)&sendBuffer2[4] = htonl(0);
1060 tcp.sendPacket(sendBuffer2, 8);
1061 log->log("Client", Log::DEBUG, "written 0 because failed to realloc packet");
1067 log->log("Client", Log::DEBUG, "Done s2");
1069 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventID); sendBufferUsed += sizeof(ULONG);
1070 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventTime); sendBufferUsed += sizeof(ULONG);
1071 *(ULONG*)&sendBuffer[sendBufferUsed] = htonl(thisEventDuration); sendBufferUsed += sizeof(ULONG);
1073 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventTitle); sendBufferUsed += strlen(thisEventTitle) + 1;
1074 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventSubTitle); sendBufferUsed += strlen(thisEventSubTitle) + 1;
1075 strcpy((char*)&sendBuffer[sendBufferUsed], thisEventDescription); sendBufferUsed += strlen(thisEventDescription) + 1;
1077 log->log("Client", Log::DEBUG, "Done s3 %lu", sendBufferUsed);
1080 log->log("Client", Log::DEBUG, "Got all event data");
1082 if (sendBufferUsed == sizeof(ULONG))
1086 log->log("Client", Log::DEBUG, "Written 0 because no data");
1090 // Write the length into the first 4 bytes. It's sendBufferUsed - 4 because of the hole!
1091 *(ULONG*)&sendBuffer[0] = htonl(sendBufferUsed - sizeof(ULONG));
1092 tcp.sendPacket(sendBuffer, sendBufferUsed);
1093 log->log("Client", Log::DEBUG, "written %lu schedules packet", sendBufferUsed);
1101 int MVPClient::processConfigSave(UCHAR* buffer, int length)
1103 char* section = (char*)buffer;
1107 for (int k = 0; k < length; k++)
1109 if (buffer[k] == '\0')
1113 key = (char*)&buffer[k+1];
1117 value = (char*)&buffer[k+1];
1123 // if the last string (value) doesnt have null terminator, give up
1124 if (buffer[length - 1] != '\0') return 0;
1126 log->log("Client", Log::DEBUG, "Config save: %s %s %s", section, key, value);
1127 if (config.setValueString(section, key, value))
1139 int MVPClient::processConfigLoad(UCHAR* buffer, int length)
1141 char* section = (char*)buffer;
1144 for (int k = 0; k < length; k++)
1146 if (buffer[k] == '\0')
1148 key = (char*)&buffer[k+1];
1153 char* value = config.getValueString(section, key);
1157 UCHAR sendBuffer[4 + strlen(value) + 1];
1158 *(ULONG*)&sendBuffer[0] = htonl(strlen(value) + 1);
1159 strcpy((char*)&sendBuffer[4], value);
1160 tcp.sendPacket(sendBuffer, 4 + strlen(value) + 1);
1162 log->log("Client", Log::DEBUG, "Written config load packet");
1167 UCHAR sendBuffer[8];
1168 *(ULONG*)&sendBuffer[0] = htonl(4);
1169 *(ULONG*)&sendBuffer[4] = htonl(0);
1170 tcp.sendPacket(sendBuffer, 8);
1172 log->log("Client", Log::DEBUG, "Written config load failed packet");
1178 void MVPClient::cleanConfig()
1180 log->log("Client", Log::DEBUG, "Clean config");
1182 cRecordings Recordings;
1187 char* resumes = config.getSectionKeyNames("ResumeData", numReturns, length);
1188 char* position = resumes;
1189 for(int k = 0; k < numReturns; k++)
1191 log->log("Client", Log::DEBUG, "EXAMINING: %i %i %p %s", k, numReturns, position, position);
1193 cRecording* recording = Recordings.GetByName(position);
1196 // doesn't exist anymore
1197 log->log("Client", Log::DEBUG, "Found a recording that doesn't exist anymore");
1198 config.deleteValue("ResumeData", position);
1202 log->log("Client", Log::DEBUG, "This recording still exists");
1205 position += strlen(position) + 1;
1217 event = Schedule->GetPresentEvent();
1219 fprintf(f, "\n\nCurrent event\n\n");
1221 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
1222 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
1223 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
1224 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
1226 event = Schedule->GetFollowingEvent();
1228 fprintf(f, "\n\nFollowing event\n\n");
1230 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", 0, event->GetEventID(), event->GetTime(), event->GetDuration());
1231 fprintf(f, "Event %i title = %s subtitle = %s\n", 0, event->GetTitle(), event->GetSubtitle());
1232 fprintf(f, "Event %i extendeddescription = %s\n", 0, event->GetExtendedDescription());
1233 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", 0, event->IsFollowing(), event->IsPresent());
1239 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1240 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1241 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1242 fprintf(f, "Event %i isFollowing = %i, isPresent = %i\n", eventNumber, event->IsFollowing(), event->IsPresent());
1250 void MVPClient::test2()
1252 FILE* f = fopen("/tmp/s.txt", "w");
1254 #if VDRVERSNUM < 10300
1255 cMutexLock MutexLock;
1256 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1258 cSchedulesLock MutexLock;
1259 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1264 fprintf(f, "Schedules = NULL\n");
1269 fprintf(f, "Schedules dump:\n");
1273 const cSchedule *Schedule;
1274 int scheduleNumber = 0;
1277 cChannel *thisChannel;
1279 #if VDRVERSNUM < 10300
1280 const cEventInfo *event;
1281 int eventNumber = 0;
1283 const cEvent *event;
1286 // Schedule = Schedules->GetSchedule(channel->GetChannelID());
1287 // Schedule = Schedules->GetSchedule();
1288 Schedule = Schedules->First();
1291 fprintf(f, "First Schedule = NULL\n");
1298 fprintf(f, "Schedule #%i\n", scheduleNumber);
1299 fprintf(f, "-------------\n\n");
1301 #if VDRVERSNUM < 10300
1302 tchid = Schedule->GetChannelID();
1304 tchid = Schedule->ChannelID();
1307 #if VDRVERSNUM < 10300
1308 fprintf(f, "ChannelID.ToString() = %s\n", tchid.ToString());
1309 fprintf(f, "NumEvents() = %i\n", Schedule->NumEvents());
1311 // put the count at the end.
1314 thisChannel = Channels.GetByChannelID(tchid, true);
1317 fprintf(f, "Channel Number: %p %i\n", thisChannel, thisChannel->Number());
1321 fprintf(f, "thisChannel = NULL for tchid\n");
1324 #if VDRVERSNUM < 10300
1325 for (eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1327 event = Schedule->GetEventNumber(eventNumber);
1328 fprintf(f, "Event %i tableid = %i timestring = %s endtimestring = %s\n", eventNumber, event->GetTableID(), event->GetTimeString(), event->GetEndTimeString());
1329 fprintf(f, "Event %i date = %s isfollowing = %i ispresent = %i\n", eventNumber, event->GetDate(), event->IsFollowing(), event->IsPresent());
1330 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1331 fprintf(f, "Event %i subtitle = %s title = %s\n", eventNumber, event->GetSubtitle(), event->GetTitle());
1332 fprintf(f, "Event %i eventid = %u duration = %li time = %lu channelnumber = %i\n", eventNumber, event->GetEventID(), event->GetDuration(), event->GetTime(), event->GetChannelNumber());
1333 fprintf(f, "Event %u dump:\n", eventNumber);
1338 // This whole section needs rewriting to walk the list.
1339 event = Schedule->Events()->First();
1341 event = Schedule->Events()->Next(event);
1346 fprintf(f, "\nDump from object:\n");
1348 fprintf(f, "\nEND\n");
1358 fprintf(f, "End of current Schedule\n\n\n");
1360 Schedule = (const cSchedule *)Schedules->Next(Schedule);
1374 const cEventInfo *GetPresentEvent(void) const;
1375 const cEventInfo *GetFollowingEvent(void) const;
1376 const cEventInfo *GetEvent(unsigned short uEventID, time_t tTime = 0) const;
1377 const cEventInfo *GetEventAround(time_t tTime) const;
1378 const cEventInfo *GetEventNumber(int n) const { return Events.Get(n); }
1381 const unsigned char GetTableID(void) const;
1382 const char *GetTimeString(void) const;
1383 const char *GetEndTimeString(void) const;
1384 const char *GetDate(void) const;
1385 bool IsFollowing(void) const;
1386 bool IsPresent(void) const;
1387 const char *GetExtendedDescription(void) const;
1388 const char *GetSubtitle(void) const;
1389 const char *GetTitle(void) const;
1390 unsigned short GetEventID(void) const;
1391 long GetDuration(void) const;
1392 time_t GetTime(void) const;
1393 tChannelID GetChannelID(void) const;
1394 int GetChannelNumber(void) const { return nChannelNumber; }
1395 void SetChannelNumber(int ChannelNumber) const { ((cEventInfo *)this)->nChannelNumber = ChannelNumber; } // doesn't modify the EIT data, so it's ok to make it 'const'
1396 void Dump(FILE *f, const char *Prefix = "") const;
1402 void MVPClient::test(int channelNumber)
1404 FILE* f = fopen("/tmp/test.txt", "w");
1406 cMutexLock MutexLock;
1407 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1411 fprintf(f, "Schedules = NULL\n");
1416 fprintf(f, "Schedules dump:\n");
1417 // Schedules->Dump(f);
1419 const cSchedule *Schedule;
1420 cChannel *thisChannel;
1421 const cEventInfo *event;
1423 thisChannel = channelFromNumber(channelNumber);
1426 fprintf(f, "thisChannel = NULL\n");
1431 Schedule = Schedules->GetSchedule(thisChannel->GetChannelID());
1432 // Schedule = Schedules->GetSchedule();
1433 // Schedule = Schedules->First();
1436 fprintf(f, "First Schedule = NULL\n");
1441 fprintf(f, "NumEvents() = %i\n\n", Schedule->NumEvents());
1443 // For some channels VDR seems to pick a random point in time to
1444 // start dishing out events, but they are in order
1445 // at some point in the list the time snaps to the current event
1450 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1452 event = Schedule->GetEventNumber(eventNumber);
1453 fprintf(f, "Event %i eventid = %u time = %lu duration = %li\n", eventNumber, event->GetEventID(), event->GetTime(), event->GetDuration());
1454 fprintf(f, "Event %i title = %s subtitle = %s\n", eventNumber, event->GetTitle(), event->GetSubtitle());
1455 fprintf(f, "Event %i extendeddescription = %s\n", eventNumber, event->GetExtendedDescription());
1459 fprintf(f, "\nEND\n");
1473 Schedules = the collection of all the Schedule objects
1474 Schedule = One schedule, contants all the events for a channel
1475 Event = One programme
1484 Subtitle (used for "Programmes resume at ...")
1487 IsPresent ? easy to work out tho. Oh it doesn't always work
1492 void MVPClient::test2()
1494 log->log("-", Log::DEBUG, "Timers List");
1496 for (int i = 0; i < Timers.Count(); i++)
1498 cTimer *timer = Timers.Get(i);
1499 //Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, timer->ToText());
1500 log->log("-", Log::DEBUG, "i=%i count=%i index=%d", i, Timers.Count(), timer->Index() + 1);
1501 #if VDRVERSNUM < 10300
1502 log->log("-", Log::DEBUG, "active=%i recording=%i pending=%i start=%li stop=%li priority=%i lifetime=%i", timer->Active(), timer->Recording(), timer->Pending(), timer->StartTime(), timer->StopTime(), timer->Priority(), timer->Lifetime());
1504 log->log("-", Log::DEBUG, "active=%i recording=%i pending=%i start=%li stop=%li priority=%i lifetime=%i", timer->HasFlags(tfActive), timer->Recording(), timer->Pending(), timer->StartTime(), timer->StopTime(), timer->Priority(), timer->Lifetime());
1506 log->log("-", Log::DEBUG, "channel=%i file=%s summary=%s", timer->Channel()->Number(), timer->File(), timer->Summary());
1507 log->log("-", Log::DEBUG, "");
1510 // asprintf(&buffer, "%d:%s:%s :%04d:%04d:%d:%d:%s:%s\n",
1511 // active, (UseChannelID ? Channel()->GetChannelID().ToString() : itoa(Channel()->Number())),
1512 // PrintDay(day, firstday), start, stop, priority, lifetime, file, summary ? summary : "");
1517 Active seems to be a bool - whether the timer should be done or not. If set to inactive it stays around after its time
1518 recording is a bool, 0 for not currently recording, 1 for currently recording
1519 pending is a bool, 0 for would not be trying to record this right now, 1 for would/is trying to record this right now
1523 int MVPClient::processGetTimers(UCHAR* buffer, int length)
1525 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1526 int count = 4; // leave space for the packet length
1528 const char* fileName;
1530 int numTimers = Timers.Count();
1532 *(ULONG*)&sendBuffer[count] = htonl(numTimers); count += 4;
1534 for (int i = 0; i < numTimers; i++)
1536 if (count > 49000) break;
1538 timer = Timers.Get(i);
1540 #if VDRVERSNUM < 10300
1541 *(ULONG*)&sendBuffer[count] = htonl(timer->Active()); count += 4;
1543 *(ULONG*)&sendBuffer[count] = htonl(timer->HasFlags(tfActive)); count += 4;
1545 *(ULONG*)&sendBuffer[count] = htonl(timer->Recording()); count += 4;
1546 *(ULONG*)&sendBuffer[count] = htonl(timer->Pending()); count += 4;
1547 *(ULONG*)&sendBuffer[count] = htonl(timer->Priority()); count += 4;
1548 *(ULONG*)&sendBuffer[count] = htonl(timer->Lifetime()); count += 4;
1549 *(ULONG*)&sendBuffer[count] = htonl(timer->Channel()->Number()); count += 4;
1550 *(ULONG*)&sendBuffer[count] = htonl(timer->StartTime()); count += 4;
1551 *(ULONG*)&sendBuffer[count] = htonl(timer->StopTime()); count += 4;
1553 fileName = timer->File();
1554 strcpy((char*)&sendBuffer[count], fileName);
1555 count += strlen(fileName) + 1;
1558 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1560 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1562 tcp.sendPacket(sendBuffer, count);
1563 delete[] sendBuffer;
1564 log->log("Client", Log::DEBUG, "Written timers list");
1569 int MVPClient::processSetTimer(UCHAR* buffer, int length)
1571 char* timerString = new char[strlen((char*)buffer) + 1];
1572 strcpy(timerString, (char*)buffer);
1574 #if VDRVERSNUM < 10300
1576 // If this is VDR 1.2 the date part of the timer string must be reduced
1577 // to just DD rather than YYYY-MM-DD
1579 int s = 0; // source
1580 int d = 0; // destination
1582 while(c != 2) // copy up to date section, including the second ':'
1584 timerString[d] = buffer[s];
1585 if (buffer[s] == ':') c++;
1589 // now it has copied up to the date section
1591 while(c != 2) // waste YYYY-MM-
1593 if (buffer[s] == '-') c++;
1596 // now source is at the DD
1597 memcpy(&timerString[d], &buffer[s], length - s);
1599 timerString[d] = '\0';
1601 log->log("Client", Log::DEBUG, "Timer string after 1.2 conversion:");
1602 log->log("Client", Log::DEBUG, "%s", timerString);
1606 cTimer *timer = new cTimer;
1607 if (timer->Parse((char*)timerString))
1609 cTimer *t = Timers.GetTimer(timer);
1613 #if VDRVERSNUM < 10300
1616 Timers.SetModified();
1634 int MVPClient::processGetRecInfo(UCHAR* data, int length)
1636 // data is a pointer to the fileName string
1638 cRecordings Recordings;
1639 Recordings.Load(); // probably have to do this
1641 cRecording *recording = Recordings.GetByName((char*)data);
1643 time_t timerStart = 0;
1644 time_t timerStop = 0;
1645 char* summary = NULL;
1646 ULONG resumePoint = 0;
1650 log->log("Client", Log::ERR, "GetRecInfo found no recording");
1655 ULONG sendBufferSize = 10000;
1656 UCHAR* sendBuffer = (UCHAR*)malloc(sendBufferSize);
1657 ULONG pos = 4; // leave first 4 bytes for size field
1661 4 bytes: start time for timer
1662 4 bytes: end time for timer
1663 4 bytes: resume point
1665 4 bytes: num components
1675 // Get current timer
1677 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
1680 timerStart = rc->Timer()->StartTime();
1681 timerStop = rc->Timer()->StopTime();
1682 log->log("Client", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop);
1685 *(time_t*)&sendBuffer[pos] = htonl(timerStart); pos += 4;
1686 *(time_t*)&sendBuffer[pos] = htonl(timerStop); pos += 4;
1690 char* value = config.getValueString("ResumeData", (char*)data);
1693 resumePoint = strtoul(value, NULL, 10);
1696 log->log("Client", Log::DEBUG, "GRI: RP: %lu", resumePoint);
1698 *(ULONG*)&sendBuffer[pos] = htonl(resumePoint); pos += 4;
1703 #if VDRVERSNUM < 10300
1704 summary = (char*)recording->Summary();
1706 const cRecordingInfo *Info = recording->Info();
1707 summary = (char*)Info->ShortText();
1708 if (isempty(summary)) summary = (char*)Info->Description();
1710 log->log("Client", Log::DEBUG, "GRI: S: %s", summary);
1713 // memory insanity...
1714 if ((sendBufferSize - pos) < (strlen(summary) + 500)) // random
1716 UCHAR* newBuffer = (UCHAR*)realloc(sendBuffer, sendBufferSize + strlen(summary) + 10000);
1719 sendBuffer = newBuffer;
1720 sendBufferSize += strlen(summary) + 10000;
1730 strcpy((char*)&sendBuffer[pos], summary);
1731 pos += strlen(summary) + 1;
1735 strcpy((char*)&sendBuffer[pos], "");
1742 #if VDRVERSNUM < 10300
1744 // Send 0 for numchannels - this signals the client this info is not available
1745 *(ULONG*)&sendBuffer[pos] = 0; pos += 4;
1748 const cComponents* components = Info->Components();
1750 log->log("Client", Log::DEBUG, "GRI: D1: %p", components);
1754 *(ULONG*)&sendBuffer[pos] = htonl(0); pos += 4;
1758 *(ULONG*)&sendBuffer[pos] = htonl(components->NumComponents()); pos += 4;
1760 tComponent* component;
1761 for (int i = 0; i < components->NumComponents(); i++)
1763 component = components->Component(i);
1765 // memory insanity...
1766 ULONG extraNeeded = 2 + (component->language ? strlen(component->language) : 0)
1767 + (component->description ? strlen(component->description) : 0) + 2;
1769 if ((sendBufferSize - pos) < extraNeeded)
1771 UCHAR* newBuffer = (UCHAR*)realloc(sendBuffer, sendBufferSize + extraNeeded + 10000);
1774 sendBuffer = newBuffer;
1775 sendBufferSize += extraNeeded + 10000;
1785 log->log("Client", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description);
1786 sendBuffer[pos] = component->stream; pos += 1;
1787 sendBuffer[pos] = component->type; pos += 1;
1788 if (component->language)
1790 strcpy((char*)&sendBuffer[pos], component->language);
1791 pos += strlen(component->language) + 1;
1795 strcpy((char*)&sendBuffer[pos], "");
1798 if (component->description)
1800 strcpy((char*)&sendBuffer[pos], component->description);
1801 pos += strlen(component->description) + 1;
1805 strcpy((char*)&sendBuffer[pos], "");
1816 *(ULONG*)&sendBuffer[0] = htonl(pos - 4); // -4 : take off the size field
1818 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1820 tcp.sendPacket(sendBuffer, pos);
1821 delete[] sendBuffer;
1822 log->log("Client", Log::DEBUG, "Written getrecinfo");
1832 int MVPClient::processReScanRecording(UCHAR* data, int length)
1836 log->log("Client", Log::DEBUG, "Rescan recording called when no recording being played!");
1842 UCHAR sendBuffer[16];
1843 *(ULONG*)&sendBuffer[0] = htonl(12);
1844 *(ULLONG*)&sendBuffer[4] = htonll(rp->getLengthBytes());
1845 *(ULONG*)&sendBuffer[12] = htonl(rp->getLengthFrames());
1847 tcp.sendPacket(sendBuffer, 16);
1848 log->log("Client", Log::DEBUG, "Rescan recording, wrote new length to client");
1852 // FIXME without client calling rescan, getblock wont work even tho more data is avail
1855 int MVPClient::processGetMarks(UCHAR* data, int length)
1857 // data is a pointer to the fileName string
1859 UCHAR* sendBuffer = new UCHAR[50000]; // FIXME hope this is enough
1860 int count = 4; // leave space for the packet length
1864 cRecordings Recordings;
1865 Recordings.Load(); // probably have to do this
1867 cRecording *recording = Recordings.GetByName((char*)data);
1869 log->log("Client", Log::DEBUG, "recording pointer %p", recording);
1873 Marks.Load(recording->FileName());
1876 for (const cMark *m = Marks.First(); m; m = Marks.Next(m))
1878 log->log("Client", Log::DEBUG, "found Mark %i", m->position);
1880 if (count > 49000) break;
1881 *(ULONG*)&sendBuffer[count] = htonl(m->position);
1887 log->log("Client", Log::DEBUG, "no marks found, sending 0-mark");
1888 *(ULONG*)&sendBuffer[count] = htonl(0);
1893 *(ULONG*)&sendBuffer[0] = htonl(count - 4); // -4 : take off the size field
1895 log->log("Client", Log::DEBUG, "recorded size as %u", ntohl(*(ULONG*)&sendBuffer[0]));
1897 tcp.sendPacket(sendBuffer, count);
1898 delete[] sendBuffer;
1899 log->log("Client", Log::DEBUG, "Written Marks list");