mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-14 04:54:49 +00:00
FS-2218 --resolve
This commit is contained in:
parent
01785fb31d
commit
07a715928b
@ -1813,6 +1813,7 @@ typedef switch_status_t (*switch_new_say_callback_t) (switch_say_file_handle_t *
|
|||||||
|
|
||||||
typedef struct switch_xml *switch_xml_t;
|
typedef struct switch_xml *switch_xml_t;
|
||||||
typedef struct switch_core_time_duration switch_core_time_duration_t;
|
typedef struct switch_core_time_duration switch_core_time_duration_t;
|
||||||
|
typedef switch_xml_t(*switch_xml_open_root_function_t) (uint8_t reload, const char **err, void *user_data);
|
||||||
typedef switch_xml_t(*switch_xml_search_function_t) (const char *section,
|
typedef switch_xml_t(*switch_xml_search_function_t) (const char *section,
|
||||||
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
|
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
@ -320,6 +320,12 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_insert(_In_ switch_xml_t xml, _In_ switc
|
|||||||
///\brief removes a tag along with all its subtags
|
///\brief removes a tag along with all its subtags
|
||||||
#define switch_xml_remove(xml) switch_xml_free(switch_xml_cut(xml))
|
#define switch_xml_remove(xml) switch_xml_free(switch_xml_cut(xml))
|
||||||
|
|
||||||
|
///\brief set new core xml root
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_xml_set_root(switch_xml_t new_main);
|
||||||
|
|
||||||
|
///\brief Set and alternate function for opening xml root
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_xml_set_open_root_function(switch_xml_open_root_function_t func, void *user_data);
|
||||||
|
|
||||||
///\brief open the Core xml root
|
///\brief open the Core xml root
|
||||||
///\param reload if it's is already open close it and open it again as soon as permissable (blocking)
|
///\param reload if it's is already open close it and open it again as soon as permissable (blocking)
|
||||||
///\param err a pointer to set error strings
|
///\param err a pointer to set error strings
|
||||||
|
@ -141,6 +141,11 @@ static switch_mutex_t *REFLOCK = NULL;
|
|||||||
static switch_mutex_t *FILE_LOCK = NULL;
|
static switch_mutex_t *FILE_LOCK = NULL;
|
||||||
static switch_mutex_t *XML_GEN_LOCK = NULL;
|
static switch_mutex_t *XML_GEN_LOCK = NULL;
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_xml_t) __switch_xml_open_root(uint8_t reload, const char **err, void *user_data);
|
||||||
|
|
||||||
|
static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION = (switch_xml_open_root_function_t)__switch_xml_open_root;
|
||||||
|
static void *XML_OPEN_ROOT_FUNCTION_USER_DATA = NULL;
|
||||||
|
|
||||||
static switch_hash_t *CACHE_HASH = NULL;
|
static switch_hash_t *CACHE_HASH = NULL;
|
||||||
|
|
||||||
struct xml_section_t {
|
struct xml_section_t {
|
||||||
@ -2046,14 +2051,67 @@ SWITCH_DECLARE(void) switch_xml_free_in_thread(switch_xml_t xml, int stacksize)
|
|||||||
|
|
||||||
static char not_so_threadsafe_error_buffer[256] = "";
|
static char not_so_threadsafe_error_buffer[256] = "";
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err)
|
SWITCH_DECLARE(switch_status_t) switch_xml_set_root(switch_xml_t new_main)
|
||||||
|
{
|
||||||
|
switch_xml_t old_root = NULL;
|
||||||
|
|
||||||
|
switch_mutex_lock(REFLOCK);
|
||||||
|
|
||||||
|
old_root = MAIN_XML_ROOT;
|
||||||
|
MAIN_XML_ROOT = new_main;
|
||||||
|
switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT);
|
||||||
|
MAIN_XML_ROOT->refs++;
|
||||||
|
|
||||||
|
if (old_root) {
|
||||||
|
if (old_root->refs) {
|
||||||
|
old_root->refs--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!old_root->refs) {
|
||||||
|
switch_xml_free(old_root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_mutex_unlock(REFLOCK);
|
||||||
|
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_xml_set_open_root_function(switch_xml_open_root_function_t func, void *user_data)
|
||||||
|
{
|
||||||
|
if (XML_LOCK) {
|
||||||
|
switch_mutex_lock(XML_LOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
XML_OPEN_ROOT_FUNCTION = func;
|
||||||
|
XML_OPEN_ROOT_FUNCTION_USER_DATA = user_data;
|
||||||
|
|
||||||
|
if (XML_LOCK) {
|
||||||
|
switch_mutex_unlock(XML_LOCK);
|
||||||
|
}
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err)
|
||||||
|
{
|
||||||
|
switch_xml_t root = NULL;
|
||||||
|
|
||||||
|
switch_mutex_lock(XML_LOCK);
|
||||||
|
|
||||||
|
if (XML_OPEN_ROOT_FUNCTION) {
|
||||||
|
root = XML_OPEN_ROOT_FUNCTION(reload, err, XML_OPEN_ROOT_FUNCTION_USER_DATA);
|
||||||
|
}
|
||||||
|
switch_mutex_unlock(XML_LOCK);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_xml_t) __switch_xml_open_root(uint8_t reload, const char **err, void *user_data)
|
||||||
{
|
{
|
||||||
char path_buf[1024];
|
char path_buf[1024];
|
||||||
uint8_t errcnt = 0;
|
uint8_t errcnt = 0;
|
||||||
switch_xml_t new_main, r = NULL;
|
switch_xml_t new_main, r = NULL;
|
||||||
|
|
||||||
switch_mutex_lock(XML_LOCK);
|
|
||||||
|
|
||||||
if (MAIN_XML_ROOT) {
|
if (MAIN_XML_ROOT) {
|
||||||
if (!reload) {
|
if (!reload) {
|
||||||
r = switch_xml_root();
|
r = switch_xml_root();
|
||||||
@ -2071,27 +2129,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e
|
|||||||
new_main = NULL;
|
new_main = NULL;
|
||||||
errcnt++;
|
errcnt++;
|
||||||
} else {
|
} else {
|
||||||
switch_xml_t old_root;
|
|
||||||
*err = "Success";
|
*err = "Success";
|
||||||
|
switch_xml_set_root(new_main);
|
||||||
switch_mutex_lock(REFLOCK);
|
|
||||||
|
|
||||||
old_root = MAIN_XML_ROOT;
|
|
||||||
MAIN_XML_ROOT = new_main;
|
|
||||||
switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT);
|
|
||||||
MAIN_XML_ROOT->refs++;
|
|
||||||
|
|
||||||
if (old_root) {
|
|
||||||
if (old_root->refs) {
|
|
||||||
old_root->refs--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!old_root->refs) {
|
|
||||||
switch_xml_free(old_root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_mutex_unlock(REFLOCK);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2109,9 +2148,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e
|
|||||||
r = switch_xml_root();
|
r = switch_xml_root();
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
||||||
switch_mutex_unlock(XML_LOCK);
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user