diff options
author | thlo <smarttv640@gmail.com> | 2016-01-31 19:47:35 +0100 |
---|---|---|
committer | thlo <smarttv640@gmail.com> | 2016-01-31 19:47:35 +0100 |
commit | 4b3f684999d715d636a3d3a385fc06487c93149e (patch) | |
tree | 96cd25996b42dbc05e2cb05c38de7cb0cdc55f0b | |
parent | d05f6c86e38b97fbf685361809fa6d733cfdf699 (diff) | |
download | vdr-plugin-smarttvweb-4b3f684999d715d636a3d3a385fc06487c93149e.tar.gz vdr-plugin-smarttvweb-4b3f684999d715d636a3d3a385fc06487c93149e.tar.bz2 |
Add (optional) support for CORS HTTP response header.
-rwxr-xr-x | responsebase.c | 6 | ||||
-rwxr-xr-x | smarttvweb.conf | 5 | ||||
-rwxr-xr-x | stvw_cfg.c | 10 | ||||
-rwxr-xr-x | stvw_cfg.h | 5 |
4 files changed, 25 insertions, 1 deletions
diff --git a/responsebase.c b/responsebase.c index 1ca526a..5ee657e 100755 --- a/responsebase.c +++ b/responsebase.c @@ -87,6 +87,12 @@ void cResponseBase::sendHeaders(int status, const char *title, const char *extra hdr += f; snprintf(f, sizeof(f), "Server: %s\r\n", SERVER); hdr += f; + + if (mRequest->mFactory->getConfig()->addCorsHeader()) { + snprintf(f, sizeof(f), "Access-Control-Allow-Origin: %s\r\n", (mRequest->mFactory->getConfig()->getCorsHeader().c_str())); + hdr += f; + } + now = time(NULL); strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now)); snprintf(f, sizeof(f), "Date: %s\r\n", timebuf); diff --git a/smarttvweb.conf b/smarttvweb.conf index 0fac880..97849ec 100755 --- a/smarttvweb.conf +++ b/smarttvweb.conf @@ -39,3 +39,8 @@ GroupSeparators Ignore # Only used, when UseStreamDev4Live is false # Buffer duration in the plugin for live (in milliseconds) BuiltInLiveBufDur 600 + +# In case, the server should add a Cross Origin Resource Sharing Header +# Value of the access-control-allow-origin HTTP response header +#CorsHeader http://192.168.1.122 http://teefax:8000 + @@ -34,7 +34,8 @@ cSmartTvConfig::cSmartTvConfig(string d): mConfigDir(d), mLog(NULL), mCfgFile(NULL), mLogFile(), mMediaFolder(), mSegmentDuration(), mHasMinBufferTime(), mHasBitrateCorrection(), mLiveChannels(), mGroupSep(IGNORE), mServerAddress(""), mServerPort(8000), mCmds(false), mUseStreamDev4Live(true), - mBuiltInLiveStartMode (4), mBuiltInLivePktBuf4Hd(150), mBuiltInLivePktBuf4Sd(75), mBuiltInLiveBufDur(0.6) { + mBuiltInLiveStartMode (4), mBuiltInLivePktBuf4Hd(150), mBuiltInLivePktBuf4Sd(75), mBuiltInLiveBufDur(0.6), + mAddCorsHeader(false), mCorsHeaderPyld() { #ifndef STANDALONE mLogFile= ""; @@ -82,6 +83,7 @@ void cSmartTvConfig::printConfig() { // *(mLog->log()) << " BuiltInLivePktBuf4Hd: " << mBuiltInLivePktBuf4Hd << endl; // *(mLog->log()) << " BuiltInLivePktBuf4Sd: " << mBuiltInLivePktBuf4Sd << endl; *(mLog->log()) << " BuiltInLiveBufDur: " << mBuiltInLiveBufDur << endl; + *(mLog->log()) << " CorsHdrPyld: " << mCorsHeaderPyld << endl; } @@ -197,6 +199,12 @@ void cSmartTvConfig::readConfig() { mBuiltInLiveBufDur = 0.5; continue; } + + if (strcmp(attr, "CorsHeader") == 0) { + mAddCorsHeader = true; + mCorsHeaderPyld = value; + continue; + } #ifndef STANDALONE esyslog("WARNING in SmartTvWeb: Attribute= %s with value= %s was not processed, thus ignored.", attr, value); @@ -63,6 +63,9 @@ class cSmartTvConfig { int mBuiltInLivePktBuf4Sd; double mBuiltInLiveBufDur; + bool mAddCorsHeader; + string mCorsHeaderPyld; + public: cSmartTvConfig(string dir); ~cSmartTvConfig(); @@ -87,6 +90,8 @@ class cSmartTvConfig { int getBuiltInLivePktBuf4Sd() { return mBuiltInLivePktBuf4Sd; }; double getBuiltInLiveBufDur() { return mBuiltInLiveBufDur; }; + bool addCorsHeader() { return mAddCorsHeader; }; + string getCorsHeader() {return mCorsHeaderPyld; }; }; #endif |