From 695de94a2b5239f2e2cdf295f9868dc6722f67e2 Mon Sep 17 00:00:00 2001 From: marian Date: Mon, 29 Aug 2011 14:09:32 +0000 Subject: [PATCH] The entity capabilities cache file is now configurable. git-svn-id: http://voip.null.ro/svn/yate@4577 acf43c95-373e-0410-b603-e72c3f656dc1 --- conf.d/jabberclient.conf.sample | 8 +++++++ conf.d/jabberserver.conf.sample | 7 ++++++ modules/client/jabberclient.cpp | 41 +++++++++++++++++++++++++++------ modules/jabber/jabberserver.cpp | 37 +++++++++++++++++++++++++---- 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/conf.d/jabberclient.conf.sample b/conf.d/jabberclient.conf.sample index 2a1e5c03..35393956 100644 --- a/conf.d/jabberclient.conf.sample +++ b/conf.d/jabberclient.conf.sample @@ -49,6 +49,14 @@ ; Defaults to enable ;entitycaps=enable +; entitycaps_file: string: Entity capabilities cache file +; This parameter is applied on reload +; If the file changes on reload entity capabilities will be saved in the new +; location, the old file will not be deleted +; Client: defaults to 'jabberentitycaps.xml' located in current user's files directory +; Server: defaults to 'jabberentitycaps.xml' located in current configuration directory +;entitycaps_file= + ; printxml: boolean/string: Print sent/received XML data to output if debug ; level is at least 9 ; Allowed values are boolean values or 'verbose' string diff --git a/conf.d/jabberserver.conf.sample b/conf.d/jabberserver.conf.sample index 0354a7b2..1a2bb241 100644 --- a/conf.d/jabberserver.conf.sample +++ b/conf.d/jabberserver.conf.sample @@ -92,6 +92,13 @@ ; Defaults to enable ;entitycaps=enable +; entitycaps_file: string: Entity capabilities cache file +; This parameter is applied on reload +; If the file changes on reload entity capabilities will be saved in the new +; location, the old file will not be deleted +; Defaults to 'jabberentitycaps.xml' located in current configuration directory +;entitycaps_file= + ; workers: integer: The number of worker threads processing stanzas received by streams ; Minimum allowed value is 1, maximum allowed value is 10 ; Defaults to 1 diff --git a/modules/client/jabberclient.cpp b/modules/client/jabberclient.cpp index bc9cbde5..55920022 100644 --- a/modules/client/jabberclient.cpp +++ b/modules/client/jabberclient.cpp @@ -133,15 +133,18 @@ class YJBEntityCapsList : public JBEntityCapsList public: // Load the entity caps file void load(); + // Set caps file. Save it if changed + void setFile(const char* file); protected: inline void getEntityCapsFile(String& file) { - file = Engine::configPath(Engine::clientMode()); - if (!file.endsWith(Engine::pathSeparator())) - file << Engine::pathSeparator(); - file << "jabberentitycaps.xml"; + Lock mylock(this); + file = m_file; } // Notify changes and save the entity caps file virtual void capsAdded(JBEntityCaps* caps); + // Save the file + void save(); + String m_file; }; /* @@ -694,12 +697,35 @@ void YJBEntityCapsList::load() loadXmlDoc(file,s_jabber); } +// Set caps file +void YJBEntityCapsList::setFile(const char* file) +{ + Lock mylock(this); + String old = m_file; + m_file = file; + if (!m_file) { + m_file = Engine::configPath(Engine::clientMode()); + if (!m_file.endsWith(Engine::pathSeparator())) + m_file << Engine::pathSeparator(); + m_file << "jabberentitycaps.xml"; + } + Engine::self()->runParams().replaceParams(m_file); + bool changed = m_enable && old && m_file && old != m_file; + mylock.drop(); + if (changed) + save(); +} + // Notify changes and save the entity caps file void YJBEntityCapsList::capsAdded(JBEntityCaps* caps) { - if (!caps) - return; - // Save the file + if (caps) + save(); +} + +// Save the file +void YJBEntityCapsList::save() +{ String file; getEntityCapsFile(file); saveXmlDoc(file,s_jabber); @@ -2495,6 +2521,7 @@ void JBModule::initialize() Output("Initializing module Jabber Client"); Configuration cfg(Engine::configFile("jabberclient")); + s_entityCaps.setFile(cfg.getValue("general","entitycaps_file")); if (!m_init) { m_init = true; setup(); diff --git a/modules/jabber/jabberserver.cpp b/modules/jabber/jabberserver.cpp index c672b976..1e6c2af1 100644 --- a/modules/jabber/jabberserver.cpp +++ b/modules/jabber/jabberserver.cpp @@ -176,15 +176,18 @@ public: const char* from, const char* to); // Load the entity caps file void load(); + // Set caps file. Save it if changed + void setFile(const char* file); protected: inline void getEntityCapsFile(String& file) { - file = Engine::configPath(); - if (!file.endsWith(Engine::pathSeparator())) - file << Engine::pathSeparator(); - file << "jabberentitycaps.xml"; + Lock mylock(this); + file = m_file; } // Notify changes and save the entity caps file virtual void capsAdded(JBEntityCaps* caps); + // Save the file + void save(); + String m_file; }; /* @@ -979,6 +982,25 @@ void YJBEntityCapsList::load() loadXmlDoc(file,s_jabber); } +// Set caps file +void YJBEntityCapsList::setFile(const char* file) +{ + Lock mylock(this); + String old = m_file; + m_file = file; + if (!m_file) { + m_file = Engine::configPath(); + if (!m_file.endsWith(Engine::pathSeparator())) + m_file << Engine::pathSeparator(); + m_file << "jabberentitycaps.xml"; + } + Engine::self()->runParams().replaceParams(m_file); + bool changed = m_enable && old && m_file && old != m_file; + mylock.drop(); + if (changed) + save(); +} + // Notify changes and save the entity caps file void YJBEntityCapsList::capsAdded(JBEntityCaps* caps) { @@ -993,6 +1015,12 @@ void YJBEntityCapsList::capsAdded(JBEntityCaps* caps) addCaps(*m,*caps); Engine::enqueue(m); // Save the file + save(); +} + +// Save the file +void YJBEntityCapsList::save() +{ String file; getEntityCapsFile(file); saveXmlDoc(file,s_jabber); @@ -3910,6 +3938,7 @@ void JBModule::initialize() Output("Initializing module Jabber Server"); Configuration cfg(Engine::configFile("jabberserver")); + s_entityCaps.setFile(cfg.getValue("general","entitycaps_file")); if (!m_init) { // Init some globals s_clusterControlSkip.append(new String("targetid"));