void VDR::setReceiveWindow(size_t size)
{
- tcp->setReceiveWindow(size);
+ if (connected) tcp->setReceiveWindow(size);
}
///////////////////////////////////////////////////////
int VDR::doLogin()
{
- if (!connected) return 0;
-
UCHAR buffer[14];
*(unsigned long*)&buffer[0] = htonl(10);
tcp->getMAC((char*)&buffer[8]);
-
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 14);
if (a != 14)
{
Directory* VDR::getRecordingsList()
{
- if (!connected) return 0;
-
UCHAR buffer[8];
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
int VDR::deleteRecording(char* fileName)
{
- if (!connected) return 0;
-
unsigned long totalLength = 8 + strlen(fileName) + 1;
UCHAR buffer[totalLength];
strcpy((char*)&buffer[8], fileName);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
char* VDR::getRecordingSummary(char* fileName)
{
- if (!connected) return 0;
-
unsigned long totalLength = 8 + strlen(fileName) + 1;
UCHAR buffer[totalLength];
strcpy((char*)&buffer[8], fileName);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
ChannelList* VDR::getChannelsList(ULONG type)
{
- if (!connected) return 0;
-
UCHAR buffer[8];
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
int VDR::streamChannel(ULONG number)
{
- if (!connected) return 0;
-
UCHAR buffer[12];
*(unsigned long*)&buffer[0] = htonl(8);
*(unsigned long*)&buffer[8] = htonl(number);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 12);
if (a != 12)
int VDR::stopStreaming()
{
- if (!connected) return 0;
-
UCHAR buffer[8];
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
{
- if (!connected) return 0;
-
UCHAR buffer[20];
*(unsigned long*)&buffer[0] = htonl(16);
*(unsigned long*)&buffer[16] = htonl(maxAmount);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 20);
if (a != 20)
{
return NULL;
}
+ if (serverError())
+ {
+ Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
+ freePacket();
+ pthread_mutex_unlock(&mutex);
+ return NULL;
+ }
+
UCHAR* toReturn = packet;
*amountReceived = packetLength;
// Manually clean up instead of running freePacket to keep the block
ULLONG VDR::streamRecording(Recording* rec)
{
- if (!connected) return 0;
-
unsigned long totalLength = 8 + strlen(rec->fileName) + 1;
UCHAR buffer[totalLength];
strcpy((char*)&buffer[8], rec->fileName);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
ULLONG VDR::rescanRecording()
{
- if (!connected) return 0;
-
unsigned long totalLength = 8;
UCHAR buffer[totalLength];
*(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
{
- if (!connected) return 0;
-
unsigned long totalLength = 12;
UCHAR buffer[totalLength];
*(unsigned long*)&buffer[8] = htonl(frameNumber);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
{
// retrieve event list (vector of events) from vdr within filter window. duration is in seconds
- if (!connected) return 0;
-
UCHAR buffer[20];
*(unsigned long*)&buffer[0] = htonl(16);
*(unsigned long*)&buffer[16] = htonl(duration);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 20);
if (a != 20)
return NULL;
}
+ // received a ulong(0) - schedules error in the plugin
if (serverError())
{
freePacket();
- disconnect();
pthread_mutex_unlock(&mutex);
return NULL;
}
int VDR::configSave(char* section, char* key, const char* value)
{
- if (!connected) return 0;
-
ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
UCHAR buffer[totalLength];
strcpy((char*)&buffer[position], value);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
char* VDR::configLoad(char* section, char* key)
{
- if (!connected) return 0;
-
ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
UCHAR buffer[totalLength];
strcpy((char*)&buffer[position], key);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{
freePacket();
pthread_mutex_unlock(&mutex);
- printf("%p %s\n", toReturn, toReturn);
-
return toReturn;
}
RecTimerList* VDR::getRecTimersList()
{
- if (!connected) return NULL;
-
UCHAR buffer[8];
*(unsigned long*)&buffer[0] = htonl(4);
*(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
int a = tcp->sendPacket(buffer, 8);
if (a != 8)
{
ULONG VDR::setEventTimer(char* timerString)
{
- if (!connected) return false;
-
unsigned long totalLength = 8 + strlen(timerString) + 1;
UCHAR buffer[totalLength];
strcpy((char*)&buffer[8], timerString);
pthread_mutex_lock(&mutex);
+ if (!connected) { pthread_mutex_unlock(&mutex); return 0; }
+
unsigned int a = tcp->sendPacket(buffer, totalLength);
if (a != totalLength)
{