summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/contentDirectory.cpp4
-rw-r--r--server/server.cpp76
-rw-r--r--server/service.cpp4
-rw-r--r--server/webserver.cpp53
4 files changed, 75 insertions, 62 deletions
diff --git a/server/contentDirectory.cpp b/server/contentDirectory.cpp
index b7d11ce..c014804 100644
--- a/server/contentDirectory.cpp
+++ b/server/contentDirectory.cpp
@@ -108,6 +108,10 @@ void cContentDirectory::Action(){
}
}
+void cContentDirectory::Stop(){
+ this->Cancel(2);
+}
+
int cContentDirectory::Execute(Upnp_Action_Request* request){
if (request == NULL) {
esyslog("UPnP\tCMS Action Handler - request is null");
diff --git a/server/server.cpp b/server/server.cpp
index 32c584d..acfe7a1 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -27,11 +27,11 @@ cMediaServer::serviceMap cMediaServer::mServices;
cMediaServer::cMediaServer()
: mServerDescription("VDR UPnP/DLNA MS", "Denis Loh", "http://upnp.vdr-developer.org",
DESCRIPTION, "VDR UPnP-DLNA MS", VERSION,
- "http://projects.vdr-developer.org/projects/plg-upnp/files", VERSION)
+ "http://projects.vdr-developer.org/projects/plg-upnp/files", VERSION,
+ "deviceDescription.xml")
, mDeviceHandle(0)
, mAnnounceMaxAge(1800)
, mMaxContentLength(KB(20))
-, mIsRunning(false)
, mWebserver(NULL)
, mMediaManager(NULL)
{
@@ -46,10 +46,6 @@ cMediaServer::~cMediaServer(){
delete mMediaManager;
}
-bool cMediaServer::IsRunning() const {
- return mIsRunning;
-}
-
bool cMediaServer::Start(){
isyslog("UPnP\tStarting UPnP media server");
@@ -114,19 +110,20 @@ bool cMediaServer::Start(){
return false;
}
-
-
- mIsRunning = true;
-
- return IsRunning();
+ return true;
}
bool cMediaServer::Stop(){
- isyslog("UPnP\tStopping UPnP media server");
-
int ret = 0;
+ isyslog("UPnP\tStopping services...");
+ for(serviceMap::iterator it = cMediaServer::mServices.begin(); it != cMediaServer::mServices.end(); ++it){
+ isyslog("UPnP\t...%s", (*it).second->GetServiceDescription().serviceType.c_str());
+ (*it).second->Stop();
+ }
+
+ isyslog("UPnP\tStopping UPnP media server");
UpnpUnRegisterRootDevice(mDeviceHandle);
if (ret != UPNP_E_SUCCESS) {
esyslog("UPnP\tError while sending first advertisments - Errorcode: %d", ret);
@@ -135,6 +132,7 @@ bool cMediaServer::Stop(){
UpnpFinish();
+ isyslog("UPnP\tStopping web server...");
if(mWebserver){
mWebserver->Stop();
@@ -147,23 +145,32 @@ bool cMediaServer::Stop(){
mMediaManager = NULL;
}
- mIsRunning = false;
-
- return !IsRunning();
+ return true;
}
bool cMediaServer::Initialize(){
- isyslog("UPnP\tInitializing UPnP media server");
+ string address;
+ uint16_t port = 0;
+
+ if(mCurrentConfiguration.expertSettings){
+ address = mCurrentConfiguration.bindToAddress
+ ? mCurrentConfiguration.address
+ : tools::GetAddressByInterface(mCurrentConfiguration.interface);
- string address = mCurrentConfiguration.bindToAddress
- ? mCurrentConfiguration.address
- : tools::GetAddressByInterface(mCurrentConfiguration.interface);
+ if(address.empty() || !address.compare("0.0.0.0")){
+ address = tools::GetAddressByInterface(tools::GetNetworkInterfaceByIndex(0, true));
+ }
- if(!address.compare("0.0.0.0"))
+ port = mCurrentConfiguration.port;
+ } else {
address = tools::GetAddressByInterface(tools::GetNetworkInterfaceByIndex(0, true));
+ port = 0;
+ }
int ret = 0;
+ isyslog("UPnP\tInitializing UPnP media server on %s:%d", address.c_str(), port);
+
ret = UpnpInit(address.c_str(), mCurrentConfiguration.port);
if(ret != UPNP_E_SUCCESS && ret != UPNP_E_INIT){
@@ -182,9 +189,21 @@ bool cMediaServer::Initialize(){
SetAnnounceMaxAge(mCurrentConfiguration.announceMaxAge);
if(!mCurrentConfiguration.webServerRoot.empty())
- mWebserver->SetWebserverRootDir(mCurrentConfiguration.webServerRoot,
- mCurrentConfiguration.staticContentURL,
- mCurrentConfiguration.presentationURL);
+ mWebserver->SetWebserverRootDir(mCurrentConfiguration.webServerRoot);
+
+ if(!mCurrentConfiguration.useLive){
+ if(!mCurrentConfiguration.presentationURL.empty())
+ mWebserver->SetPresentationUrl(mCurrentConfiguration.presentationURL);
+ } else {
+ stringstream ss;
+
+ uint16_t port = mCurrentConfiguration.livePort ? mCurrentConfiguration.livePort : 8008;
+
+ ss << "http://" << GetServerIPAddress() << ":" << port << "/";
+
+ mWebserver->SetPresentationUrl(ss.str());
+ }
+
if(mCurrentConfiguration.webServerPort)
mWebserver->SetListenerPort(mCurrentConfiguration.webServerPort);
@@ -239,7 +258,7 @@ uint16_t cMediaServer::GetServerPort() const {
}
string cMediaServer::GetDeviceDescriptionUrl() const {
- return mWebserver->GetBaseUrl() + mCurrentConfiguration.serviceURL + "deviceDescription.xml";
+ return mWebserver->GetServiceUrl() + mServerDescription.descriptionFile;
}
void cMediaServer::RegisterService(cUPnPService* service){
@@ -309,10 +328,6 @@ int cMediaServer::ActionCallback(Upnp_EventType eventtype, void *event, void *co
}
-const char* cMediaServer::RuntimeException::what() const throw() {
- return "Runtime error: media server is not running";
-}
-
bool cMediaServer::CheckDeviceUUID(string deviceUUID) const {
return deviceUUID.find(mCurrentConfiguration.deviceUUID) != string::npos;
}
@@ -320,7 +335,7 @@ bool cMediaServer::CheckDeviceUUID(string deviceUUID) const {
cMediaServer::Description::Description(
string fn, string m, string murl,
string mod, string mon, string mono,
- string mourl, string sno)
+ string mourl, string sno, string desc)
: friendlyName(fn)
, manufacturer(m)
, manufacturerURL(murl)
@@ -329,6 +344,7 @@ cMediaServer::Description::Description(
, modelNumber(mono)
, modelURL(mourl)
, serialNumber(sno)
+, descriptionFile(desc)
{
}
diff --git a/server/service.cpp b/server/service.cpp
index 14a0bb6..d127e59 100644
--- a/server/service.cpp
+++ b/server/service.cpp
@@ -28,6 +28,10 @@ void cUPnPService::Init(cMediaServer* server, UpnpDevice_Handle deviceHandle){
mDeviceHandle = deviceHandle;
}
+void cUPnPService::Stop(){
+ return;
+}
+
void cUPnPService::SetError(Upnp_Action_Request* request, int error){
request->ErrCode = error;
switch(error){
diff --git a/server/webserver.cpp b/server/webserver.cpp
index b67076b..d2a25f0 100644
--- a/server/webserver.cpp
+++ b/server/webserver.cpp
@@ -8,20 +8,24 @@
#include "../include/webserver.h"
#include "../upnp.h"
#include <sstream>
+#include <tnt/job.h>
namespace upnp {
cWebserver::cWebserver(std::string address)
: mListenerAddress(address)
, mListenerPort(7649)
+, mStaticContentUrl("http/")
+, mServiceUrl("services/")
, mWebserverThread(*this)
{
- SetWebserverRootDir(string(), string(), string());
- SetServiceUrl(string(), string());
+ SetWebserverRootDir(string());
+ SetPresentationUrl(string());
}
cWebserver::~cWebserver(){
-
+ mApplication.shutdown();
+ mWebserverThread.Stop();
}
bool cWebserver::Start(){
@@ -87,18 +91,17 @@ void cWebserver::SetListenerPort(uint16_t port){
mListenerPort = port ? port : 7649;
}
-void cWebserver::SetWebserverRootDir(std::string rootDirectory, std::string staticContentUrl, std::string presentationUrl){
+void cWebserver::SetWebserverRootDir(std::string rootDirectory){
if(mWebserverThread.Active()) return;
if(rootDirectory.empty())
mWebserverRootDir = std::string(cPluginUpnp::ConfigDirectory(PLUGIN_NAME_I18N)) + "/httpdocs/";
else
mWebserverRootDir = rootDirectory;
+}
- if(staticContentUrl.empty())
- mStaticContentUrl = "http/";
- else
- mStaticContentUrl = staticContentUrl;
+void cWebserver::SetPresentationUrl(std::string presentationUrl){
+ if(mWebserverThread.Active()) return;
if(presentationUrl.empty())
mPresentationUrl = "index.html";
@@ -106,25 +109,6 @@ void cWebserver::SetWebserverRootDir(std::string rootDirectory, std::string stat
mPresentationUrl = presentationUrl;
}
-void cWebserver::SetServiceUrl(std::string descriptionUrl, std::string controlUrl){
- if(mWebserverThread.Active()) return;
-
- if(descriptionUrl.empty()){
- mServiceUrl = "services/";
- }
- else
- mServiceUrl = descriptionUrl;
-
- if(controlUrl.empty()){
- stringstream s;
- s << "http://" << UpnpGetServerIpAddress() << ":" << UpnpGetServerPort() << "/" << "services/";
-
- mControlUrl = s.str();
- } else {
- mControlUrl = controlUrl;
- }
-}
-
const std::string cWebserver::GetBaseUrl() const {
stringstream s;
s << "http://" << mListenerAddress << ":" << mListenerPort << "/";
@@ -133,25 +117,26 @@ const std::string cWebserver::GetBaseUrl() const {
}
const std::string cWebserver::GetServiceUrl() const {
- return mServiceUrl;
+ return GetBaseUrl() + mServiceUrl;
}
const std::string cWebserver::GetControlUrl() const {
- return mControlUrl;
+ stringstream s;
+ s << "http://" << UpnpGetServerIpAddress() << ":" << UpnpGetServerPort() << "/" << "services/";
+ return s.str();
}
const std::string cWebserver::GetPresentationUrl() const {
- return mPresentationUrl;
+ return (mPresentationUrl.find("http://",0) == 0) ? mPresentationUrl : (GetBaseUrl() + mPresentationUrl);
}
const std::string cWebserver::GetStaticContentUrl() const {
- return mStaticContentUrl;
+ return GetBaseUrl() + mStaticContentUrl;
}
cWebserver::cWSThread::cWSThread(cWebserver& webServer)
: mWebserver(webServer)
{
-
}
void cWebserver::cWSThread::Action(){
@@ -162,6 +147,10 @@ void cWebserver::cWSThread::Action(){
}
}
+void cWebserver::cWSThread::Stop(){
+ Cancel(5);
+}
+
} // namespace upnp