summaryrefslogtreecommitdiff
path: root/vdr-smarttvweb
diff options
context:
space:
mode:
authorthlo <t.lohmar@gmx.de>2012-12-27 11:17:44 +0100
committerthlo <t.lohmar@gmx.de>2012-12-27 11:17:44 +0100
commit8f0bf44fd3f08c837a8409378afd09dfb5b12f0f (patch)
tree3b5f99c5ab413f28d0a600ca4c8987365258343e /vdr-smarttvweb
parent86fe990eb0641f74cee509e51079d7a5cab27d6f (diff)
downloadvdr-plugin-smarttvweb-8f0bf44fd3f08c837a8409378afd09dfb5b12f0f.tar.gz
vdr-plugin-smarttvweb-8f0bf44fd3f08c837a8409378afd09dfb5b12f0f.tar.bz2
Limit HTTP server to Media Folder. Reduction of log output
Diffstat (limited to 'vdr-smarttvweb')
-rw-r--r--vdr-smarttvweb/httpresource.c83
-rw-r--r--vdr-smarttvweb/smarttvfactory.c9
2 files changed, 63 insertions, 29 deletions
diff --git a/vdr-smarttvweb/httpresource.c b/vdr-smarttvweb/httpresource.c
index 8ca689a..bd83d80 100644
--- a/vdr-smarttvweb/httpresource.c
+++ b/vdr-smarttvweb/httpresource.c
@@ -310,7 +310,7 @@ int cHttpResource::processRequest() {
if (strcasecmp(mMethod.c_str(), "GET") != 0){
sendError(501, "Not supported", NULL, "Method is not supported.");
- return ERROR;
+ return OKAY;
}
#ifndef STANDALONE
@@ -323,8 +323,8 @@ int cHttpResource::processRequest() {
ret = sendRecordingsHtml( &statbuf);
return OKAY;
}
- if (mPath.compare("/recordings.xml") == 0) {
+ if (mPath.compare("/recordings.xml") == 0) {
ret = sendRecordingsXml( &statbuf);
return OKAY;
}
@@ -339,67 +339,89 @@ int cHttpResource::processRequest() {
return OKAY;
}
#endif
+
if (mPath.compare("/media.xml") == 0) {
ret = sendMediaXml( &statbuf);
return OKAY;
}
- if (mPath.compare(mPath.size() -8, 8, "-seg.mpd") == 0) {
- ret = sendManifest( &statbuf, false);
- return OKAY;
+ if (mPath.compare("/widget.conf") == 0) {
+ mPath = mFactory->getConfigDir() + "/widget.conf";
}
- if (mPath.compare(mPath.size() -9, 9, "-seg.m3u8") == 0) {
- ret = sendManifest( &statbuf, true);
- return OKAY;
+ if (mPath.size() > 8) {
+ if (mPath.compare(mPath.size() -8, 8, "-seg.mpd") == 0) {
+ ret = sendManifest( &statbuf, false);
+ return OKAY;
+ }
}
- if (mPath.compare(mPath.size() -7, 7, "-seg.ts") == 0) {
- ret = sendMediaSegment( &statbuf);
- return OKAY;
+ if (mPath.size() > 9) {
+ if (mPath.compare(mPath.size() -9, 9, "-seg.m3u8") == 0) {
+ ret = sendManifest( &statbuf, true);
+ return OKAY;
+ }
}
- if (mPath.compare("/widget.conf") == 0) {
- mPath = mFactory->getConfigDir() + "/widget.conf";
+ if (mPath.size() > 7) {
+ if (mPath.compare(mPath.size() -7, 7, "-seg.ts") == 0) {
+ ret = sendMediaSegment( &statbuf);
+ return OKAY;
+ }
}
if (stat(mPath.c_str(), &statbuf) < 0) {
+ // checking, whether the file or directory exists
sendError(404, "Not Found", NULL, "File not found.");
- return ERROR;
+ return OKAY;
}
if (S_ISDIR(statbuf.st_mode)) {
-
+ // Do Folder specific checkings
#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX
<< " processRequest: isDir - mPath: " << mPath.c_str() << endl;
#endif
-
if (mPath.size() >4) {
if (mPath.compare(mPath.size() - 4, 4, ".rec") == 0) {
+ // Handle any recording directory specifically
mContentType = VDRDIR;
return sendVdrDir( &statbuf);
}
}
- // else {
+
+ if (mPath.compare(0, (mFactory->getConfig()->getMediaFolder()).size(), mFactory->getConfig()->getMediaFolder()) != 0) {
+ // No directory access outside of MediaFolder
+ *(mLog->log())<< DEBUGPREFIX
+ << " Directory request is not for MediaFolde ("
+ << mFactory->getConfig()->getMediaFolder() << ")"
+ << endl;
+ sendError(404, "Not Found", NULL, "File not found.");
+ return OKAY;
+ }
+
sendDir( &statbuf);
mContentType = MEMBLOCK;
- return OKAY;
- // }
+ return OKAY;
}
else {
+ // mPath is not a folder, thus it is a file
#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX
<< " processRequest: file send\n";
#endif
+ // Check, if requested file is in Media Directory
+ if (mPath.compare(0, (mFactory->getConfig()->getMediaFolder()).size(), mFactory->getConfig()->getMediaFolder()) != 0) {
+ sendError(404, "Not Found", NULL, "File not found.");
+ return OKAY;
+ }
mFileSize = statbuf.st_size;
-
mContentType = SINGLEFILE;
-
return sendFile(&statbuf);
}
+
#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX
<< " processRequest: Not Handled SHOULD not be here\n";
@@ -523,8 +545,10 @@ int cHttpResource::fillDataBlk() {
case MEMBLOCK:
int rem_len = mResponseMessage->size() - mResponseMessagePos;
if (rem_len == 0) {
- *(mLog->log())<< DEBUGPREFIX
- << " fillDataBlock: MEMBLOCK done" << endl;
+
+#ifndef DEBUG
+ *(mLog->log())<< DEBUGPREFIX << " fillDataBlock: MEMBLOCK done" << endl;
+#endif
delete mResponseMessage;
mResponseMessagePos = 0;
mConnState = TOCLOSE;
@@ -857,12 +881,14 @@ int cHttpResource::parseFiles(vector<sFileEntry> *entries, string prefix, string
string dir_comp;
dir_comp = dir_base + dir_name + "/";
+#ifndef DEBUG
*(mLog->log()) << DEBUGPREFIX
<< " parseFiles: Prefix= " << prefix
<< " base= " << dir_base
<< " dir= " << dir_name
<< " comp= " << dir_comp
<< endl;
+#endif
dir = opendir(dir_comp.c_str());
while ((de = readdir(dir)) != NULL) {
@@ -870,7 +896,6 @@ int cHttpResource::parseFiles(vector<sFileEntry> *entries, string prefix, string
continue;
}
- // *(mLog->log()) << DEBUGPREFIX << " " << de->d_name << endl;
strcpy(pathbuf, dir_comp.c_str());
strcat(pathbuf, de->d_name);
@@ -890,8 +915,10 @@ int cHttpResource::parseFiles(vector<sFileEntry> *entries, string prefix, string
t.tm_sec = 0;
start = mktime(&t);
+#ifndef DEBUG
*(mLog->log()) << DEBUGPREFIX
<< " Vdr Folder Found: " << pathbuf << " start= " << start << endl;
+#endif
entries->push_back(sFileEntry(dir_name, pathbuf, start));
}
@@ -1237,8 +1264,10 @@ int cHttpResource::sendMediaXml (struct stat *statbuf) {
mConnState = SERVING;
- *(mLog->log()) << DEBUGPREFIX << " sendMedia " << endl;
-
+#ifndef DEBUG
+ *(mLog->log()) << DEBUGPREFIX << " sendMedia " << endl;
+#endif
+
vector<sFileEntry> entries;
parseFiles(&entries, "", media_folder, "", statbuf);
@@ -1586,10 +1615,12 @@ int cHttpResource::sendRecordingsXml(struct stat *statbuf) {
}
}
+#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX
<< " Found " << act_rec.size()
<< " running timers"
<< endl;
+#endif
int rec_dur = 0;
for (cRecording *recording = recordings->First(); recording; recording = recordings->Next(recording)) {
diff --git a/vdr-smarttvweb/smarttvfactory.c b/vdr-smarttvweb/smarttvfactory.c
index 12a24bc..a57310a 100644
--- a/vdr-smarttvweb/smarttvfactory.c
+++ b/vdr-smarttvweb/smarttvfactory.c
@@ -144,7 +144,8 @@ void SmartTvServer::loop() {
write_set = mWriteState;
if (ret != handeled_fds) {
- *(mLog.log()) << "ERROR: Select-ret= " << ret
+ // Only ok, when the server has closed a handing HTTP connection
+ *(mLog.log()) << "WARNING: Select-ret= " << ret
<< " != handeled_fds= " << handeled_fds << endl;
/* FD_ZERO(&mReadState);
FD_ZERO(&mWriteState);
@@ -168,10 +169,10 @@ void SmartTvServer::loop() {
timeout.tv_sec = 5;
timeout.tv_usec = 0;
-
ret = select(maxfd + 1, &read_set, &write_set, NULL, &timeout);
if (ret == 0) {
+ // timeout: Check for dead TCP connections
for (uint idx= 0; idx < clientList.size(); idx++) {
if (clientList[idx] != NULL)
if (clientList[idx]->checkStatus() == ERROR) {
@@ -194,9 +195,9 @@ void SmartTvServer::loop() {
// new accept
if (FD_ISSET(mServerFd, &read_set)) {
+ handeled_fds ++;
if((rfd = accept(mServerFd, (sockaddr*)&sadr, &addr_size))!= -1){
req_id ++;
- handeled_fds ++;
#ifndef DEBUG
*(mLog.log()) << "fd= " << rfd
@@ -268,7 +269,9 @@ void SmartTvServer::loop() {
continue;
}
if ( clientList[rfd]->handleWrite() < 0){
+#ifndef DEBUG
*(mLog.log()) << "fd= " << rfd << " --------------------- Check Write: Closing ---------------------" << endl;
+#endif
close(rfd);
delete clientList[rfd];
clientList[rfd] = NULL;