summaryrefslogtreecommitdiff
path: root/media
diff options
context:
space:
mode:
authormethodus <methodus@web.de>2012-10-29 02:42:08 +0100
committermethodus <methodus@web.de>2012-10-29 02:42:08 +0100
commit2d082611ac1f51f3a0ce86d29b8e3d674ad6e3b0 (patch)
tree541397a1493ff46bffef7c64b2e39fc56ab43148 /media
parent0deea38705627533ab074d51247d37b7a783606a (diff)
downloadvdr-plugin-upnp-2d082611ac1f51f3a0ce86d29b8e3d674ad6e3b0.tar.gz
vdr-plugin-upnp-2d082611ac1f51f3a0ce86d29b8e3d674ad6e3b0.tar.bz2
Added CLI parameter for setting the database directory. Also fixed segfault, if databse file can't be opened
Diffstat (limited to 'media')
-rw-r--r--media/mediaManager.cpp216
1 files changed, 111 insertions, 105 deletions
diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp
index 9649cdc..1c9eaf2 100644
--- a/media/mediaManager.cpp
+++ b/media/mediaManager.cpp
@@ -110,7 +110,7 @@ cMediaManager::cMediaManager()
, pluginDirectory(DEFAULTPLUGINDIR)
, pluginManager(NULL)
{
- SetDatabaseFile(string());
+ SetDatabaseDir(string());
}
cMediaManager::~cMediaManager(){
@@ -478,112 +478,116 @@ bool cMediaManager::Initialise(){
dsyslog("UPNP\tPreparing database structure...");
if(!CheckIntegrity()){
- connection.beginTransaction();
-
- ss.str(string());
-
- ss << "CREATE TABLE " << db::Metadata
- << "("
- << "`" << property::object::KEY_OBJECTID << "` TEXT PRIMARY KEY,"
- << "`" << property::object::KEY_PARENTID << "` TEXT NOT NULL,"
- << "`" << property::object::KEY_TITLE << "` TEXT NOT NULL,"
- << "`" << property::object::KEY_CLASS << "` TEXT NOT NULL,"
- << "`" << property::object::KEY_RESTRICTED << "` INTEGER NOT NULL,"
- << "`" << property::object::KEY_CREATOR << "` TEXT,"
- << "`" << property::object::KEY_DESCRIPTION << "` TEXT,"
- << "`" << property::object::KEY_LONG_DESCRIPTION << "` TEXT,"
- << "`" << property::object::KEY_DATE << "` TEXT,"
- << "`" << property::object::KEY_LANGUAGE << "` TEXT,"
- << "`" << property::object::KEY_CHANNEL_NR << "` INTEGER,"
- << "`" << property::object::KEY_CHANNEL_NAME << "` TEXT,"
- << "`" << property::object::KEY_SCHEDULED_START << "` TEXT,"
- << "`" << property::object::KEY_SCHEDULED_END << "` TEXT,"
- << "`" << property::object::KEY_OBJECT_UPDATE_ID << "` INTEGER"
- << ")";
-
- tntdb::Statement objectTable = connection.prepare(ss.str());
-
- objectTable.execute();
-
- ss.str(string());
-
- ss << "CREATE TABLE " << db::Details
- << "("
- << " `propertyID` INTEGER PRIMARY KEY,"
- << " `" << property::object::KEY_OBJECTID << "` TEXT "
- << " REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
- << " `property` TEXT,"
- << " `value` TEXT"
- << ")";
-
- tntdb::Statement detailsTable = connection.prepare(ss.str());
-
- detailsTable.execute();
-
- ss.str(string());
-
- ss << "CREATE TABLE " << db::Resources
- << "("
- << "`" << property::object::KEY_OBJECTID << "` TEXT "
- << "REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
- << "`" << property::resource::KEY_RESOURCE << "` TEXT,"
- << "`" << property::resource::KEY_PROTOCOL_INFO << "` TEXT NOT NULL,"
- << "`" << property::resource::KEY_SIZE << "` INTEGER,"
- << "`" << property::resource::KEY_DURATION << "` TEXT,"
- << "`" << property::resource::KEY_RESOLUTION << "` TEXT,"
- << "`" << property::resource::KEY_BITRATE << "` INTEGER,"
- << "`" << property::resource::KEY_SAMPLE_FREQUENCY << "` INTEGER,"
- << "`" << property::resource::KEY_BITS_PER_SAMPLE << "` INTEGER,"
- << "`" << property::resource::KEY_NR_AUDIO_CHANNELS << "` INTEGER,"
- << "`" << property::resource::KEY_COLOR_DEPTH << "` INTEGER,"
- << "PRIMARY KEY ("
- << "`" << property::object::KEY_OBJECTID << "`,"
- << "`" << property::resource::KEY_RESOURCE << "`"
- << ")"
- << ")";
-
- tntdb::Statement resourcesTable = connection.prepare(ss.str());
-
- resourcesTable.execute();
-
- ss.str(string());
-
- ss << "INSERT INTO " << db::Metadata << " ("
- << "`" << property::object::KEY_OBJECTID << "`, "
- << "`" << property::object::KEY_PARENTID << "`, "
- << "`" << property::object::KEY_TITLE << "`, "
- << "`" << property::object::KEY_CLASS << "`, "
- << "`" << property::object::KEY_RESTRICTED << "`, "
- << "`" << property::object::KEY_CREATOR << "`, "
- << "`" << property::object::KEY_DESCRIPTION << "`, "
- << "`" << property::object::KEY_LONG_DESCRIPTION << "`) "
- << " VALUES (:objectID, :parentID, :title, :class, :restricted, :creator, :description, :longDescription)";
-
- tntdb::Statement rootContainer = connection.prepare(ss.str());
-
- const cMediaServer::Description desc = cMediaServer::GetInstance()->GetServerDescription();
-
- rootContainer.setString("objectID", "0")
- .setString("parentID", "-1")
- .setString("title", desc.friendlyName)
- .setString("creator", desc.manufacturer)
- .setString("class", "object.container")
- .setBool("restricted", true)
- .setString("description", desc.modelName)
- .setString("longDescription", desc.modelDescription)
- .execute();
+ try {
+
+ connection.beginTransaction();
+
+ ss.str(string());
+
+ ss << "CREATE TABLE " << db::Metadata
+ << "("
+ << "`" << property::object::KEY_OBJECTID << "` TEXT PRIMARY KEY,"
+ << "`" << property::object::KEY_PARENTID << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_TITLE << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_CLASS << "` TEXT NOT NULL,"
+ << "`" << property::object::KEY_RESTRICTED << "` INTEGER NOT NULL,"
+ << "`" << property::object::KEY_CREATOR << "` TEXT,"
+ << "`" << property::object::KEY_DESCRIPTION << "` TEXT,"
+ << "`" << property::object::KEY_LONG_DESCRIPTION << "` TEXT,"
+ << "`" << property::object::KEY_DATE << "` TEXT,"
+ << "`" << property::object::KEY_LANGUAGE << "` TEXT,"
+ << "`" << property::object::KEY_CHANNEL_NR << "` INTEGER,"
+ << "`" << property::object::KEY_CHANNEL_NAME << "` TEXT,"
+ << "`" << property::object::KEY_SCHEDULED_START << "` TEXT,"
+ << "`" << property::object::KEY_SCHEDULED_END << "` TEXT,"
+ << "`" << property::object::KEY_OBJECT_UPDATE_ID << "` INTEGER"
+ << ")";
+
+ tntdb::Statement objectTable = connection.prepare(ss.str());
+
+ objectTable.execute();
+
+ ss.str(string());
+
+ ss << "CREATE TABLE " << db::Details
+ << "("
+ << " `propertyID` INTEGER PRIMARY KEY,"
+ << " `" << property::object::KEY_OBJECTID << "` TEXT "
+ << " REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
+ << " `property` TEXT,"
+ << " `value` TEXT"
+ << ")";
+
+ tntdb::Statement detailsTable = connection.prepare(ss.str());
+
+ detailsTable.execute();
+
+ ss.str(string());
+
+ ss << "CREATE TABLE " << db::Resources
+ << "("
+ << "`" << property::object::KEY_OBJECTID << "` TEXT "
+ << "REFERENCES metadata (`"<< property::object::KEY_OBJECTID <<"`) ON DELETE CASCADE ON UPDATE CASCADE,"
+ << "`" << property::resource::KEY_RESOURCE << "` TEXT,"
+ << "`" << property::resource::KEY_PROTOCOL_INFO << "` TEXT NOT NULL,"
+ << "`" << property::resource::KEY_SIZE << "` INTEGER,"
+ << "`" << property::resource::KEY_DURATION << "` TEXT,"
+ << "`" << property::resource::KEY_RESOLUTION << "` TEXT,"
+ << "`" << property::resource::KEY_BITRATE << "` INTEGER,"
+ << "`" << property::resource::KEY_SAMPLE_FREQUENCY << "` INTEGER,"
+ << "`" << property::resource::KEY_BITS_PER_SAMPLE << "` INTEGER,"
+ << "`" << property::resource::KEY_NR_AUDIO_CHANNELS << "` INTEGER,"
+ << "`" << property::resource::KEY_COLOR_DEPTH << "` INTEGER,"
+ << "PRIMARY KEY ("
+ << "`" << property::object::KEY_OBJECTID << "`,"
+ << "`" << property::resource::KEY_RESOURCE << "`"
+ << ")"
+ << ")";
+
+ tntdb::Statement resourcesTable = connection.prepare(ss.str());
+
+ resourcesTable.execute();
+
+ ss.str(string());
+
+ ss << "INSERT INTO " << db::Metadata << " ("
+ << "`" << property::object::KEY_OBJECTID << "`, "
+ << "`" << property::object::KEY_PARENTID << "`, "
+ << "`" << property::object::KEY_TITLE << "`, "
+ << "`" << property::object::KEY_CLASS << "`, "
+ << "`" << property::object::KEY_RESTRICTED << "`, "
+ << "`" << property::object::KEY_CREATOR << "`, "
+ << "`" << property::object::KEY_DESCRIPTION << "`, "
+ << "`" << property::object::KEY_LONG_DESCRIPTION << "`) "
+ << " VALUES (:objectID, :parentID, :title, :class, :restricted, :creator, :description, :longDescription)";
+
+ tntdb::Statement rootContainer = connection.prepare(ss.str());
+
+ const cMediaServer::Description desc = cMediaServer::GetInstance()->GetServerDescription();
+
+ rootContainer.setString("objectID", "0")
+ .setString("parentID", "-1")
+ .setString("title", desc.friendlyName)
+ .setString("creator", desc.manufacturer)
+ .setString("class", "object.container")
+ .setBool("restricted", true)
+ .setString("description", desc.modelName)
+ .setString("longDescription", desc.modelDescription)
+ .execute();
+
+ connection.commitTransaction();
+
+ } catch (const std::exception& e) {
+ esyslog("UPnP\tException occurred while initializing database '%s': %s", databaseFile.c_str(), e.what());
+ connection.rollbackTransaction();
+
+ return false;
+ }
- connection.commitTransaction();
}
} catch (const std::exception& e) {
-
- if(!connection){
- esyslog("UPnP\tException occurred while connecting to database '%s': %s", databaseFile.c_str(), e.what());
- } else {
- esyslog("UPnP\tException occurred while initializing database '%s': %s", databaseFile.c_str(), e.what());
- connection.rollbackTransaction();
- }
+ esyslog("UPnP\tException occurred while connecting to database '%s': %s", databaseFile.c_str(), e.what());
return false;
}
@@ -707,10 +711,12 @@ cUPnPResourceProvider* cMediaManager::CreateResourceProvider(const string& uri){
return pluginManager->CreateProvider(uri.substr(0, uri.find_first_of(':',0)));
}
-void cMediaManager::SetDatabaseFile(const string& file){
+void cMediaManager::SetDatabaseDir(const string& file){
if(file.empty())
- databaseFile = string(cPlugin::ConfigDirectory(PLUGIN_NAME_I18N)) + "/metadata.db";
+ databaseFile = cPlugin::ConfigDirectory(PLUGIN_NAME_I18N);
else databaseFile = file;
+
+ databaseFile += "/metadata.db";
}
void cMediaManager::SetPluginDirectory(const string& directory){