mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-26 13:14:14 +00:00
A few changes:
1) The xml_curl now has a more enterprise config where it can have more than 1 url configured so you could have failover. (*note the syntax change*) 2) dialplan modules now take an extra arguement making it possible to pass runtime params to them. This is now used in mod_dialplan_xml to allow an alternate file path to be specified. dialplans were already stackable meaning you can configure a sofia profile, for example, to use enum followed by the default XML dialplan. e.g. <param name="dialplan" value="enum,XML"/> From now on, you can also specify :param after each dialplan name to allow param to be passed to the module. mod_dialplan_xml uses this param as a way to override where it looks for the dialplan making it possible to stack mutiple calls to the XML dialplan. e.g. <param name="dialplan" value="XML:/some/xml/file.xml,XML"/> With this you can search the local file file.xml first and if there is still no match the hunt will move on to the standard XML using the onboard XML registry and or the external gateways. *NOTE* this alternate path does not use the external bindings but it does parse the #includes etc. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4066 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
f17eece9e3
commit
85dab893d9
10 files changed
+132
-48
No files matched your search
@@ -514,7 +514,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
|
||||
}
|
||||
|
||||
|
||||
static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *session)
|
||||
static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *session, void *arg)
|
||||
{
|
||||
switch_caller_extension_t *extension = NULL;
|
||||
switch_caller_profile_t *caller_profile;
|
||||
|
||||
@@ -83,7 +83,7 @@ static void load_config(void)
|
||||
switch_xml_free(xml);
|
||||
}
|
||||
|
||||
static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t *session)
|
||||
static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t *session, void *arg)
|
||||
{
|
||||
switch_caller_profile_t *caller_profile;
|
||||
switch_caller_extension_t *extension = NULL;
|
||||
|
||||
@@ -193,12 +193,12 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
|
||||
return proceed;
|
||||
}
|
||||
|
||||
static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
|
||||
static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session, void *arg)
|
||||
{
|
||||
switch_caller_profile_t *caller_profile;
|
||||
switch_caller_extension_t *extension = NULL;
|
||||
switch_channel_t *channel;
|
||||
switch_xml_t cfg, xml, xcontext, xexten;
|
||||
switch_xml_t alt_root = NULL, cfg, xml, xcontext, xexten;
|
||||
char *context = NULL;
|
||||
switch_stream_handle_t stream = {0};
|
||||
switch_size_t encode_len = 1024, new_len = 0;
|
||||
@@ -206,6 +206,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
|
||||
char *prof[11] = {0}, *prof_names[11] = {0}, *e = NULL;
|
||||
switch_hash_index_t *hi;
|
||||
uint32_t x = 0;
|
||||
char *alt_path = (char *) arg;
|
||||
|
||||
channel = switch_core_session_get_channel(session);
|
||||
if ((caller_profile = switch_channel_get_caller_profile(channel))) {
|
||||
@@ -296,11 +297,28 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
|
||||
if (e && *e == '&') {
|
||||
*e = '\0';
|
||||
}
|
||||
|
||||
if (!switch_strlen_zero(alt_path)) {
|
||||
switch_xml_t conf = NULL, tag = NULL;
|
||||
if (!(alt_root = switch_xml_parse_file(alt_path))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, stream.data) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
|
||||
return NULL;
|
||||
}
|
||||
if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) &&
|
||||
(tag = switch_xml_find_child(conf, "dialplan", NULL, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting dialplan from alternate path: %s\n", alt_path);
|
||||
xml = alt_root;
|
||||
cfg = tag;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
|
||||
return NULL;
|
||||
}
|
||||
} else if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, stream.data) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
switch_safe_free(stream.data);
|
||||
switch_safe_free(encode_buf);
|
||||
|
||||
@@ -33,15 +33,13 @@
|
||||
|
||||
static const char modname[] = "mod_xml_curl";
|
||||
|
||||
static struct {
|
||||
struct xml_binding {
|
||||
char *url;
|
||||
char *bindings;
|
||||
char *cred;
|
||||
} globals;
|
||||
};
|
||||
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cred, globals.cred);
|
||||
typedef struct xml_binding xml_binding_t;
|
||||
|
||||
struct config_data {
|
||||
char *name;
|
||||
@@ -62,7 +60,8 @@ static switch_xml_t xml_url_fetch(char *section,
|
||||
char *tag_name,
|
||||
char *key_name,
|
||||
char *key_value,
|
||||
char *params)
|
||||
char *params,
|
||||
void *user_data)
|
||||
{
|
||||
char filename[512] = "";
|
||||
CURL *curl_handle = NULL;
|
||||
@@ -71,6 +70,22 @@ static switch_xml_t xml_url_fetch(char *section,
|
||||
char *data = NULL;
|
||||
switch_uuid_t uuid;
|
||||
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
|
||||
xml_binding_t *binding = (xml_binding_t *) user_data;
|
||||
char *file_url;
|
||||
|
||||
if (!binding) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (file_url = strstr(binding->url, "file:")) {
|
||||
file_url += 5;
|
||||
|
||||
if (!(xml = switch_xml_parse_file(file_url))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
|
||||
}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
|
||||
section,
|
||||
@@ -88,20 +103,20 @@ static switch_xml_t xml_url_fetch(char *section,
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s%s.tmp.xml", SWITCH_GLOBAL_dirs.temp_dir, uuid_str);
|
||||
curl_handle = curl_easy_init();
|
||||
if (!strncasecmp(globals.url, "https", 5)) {
|
||||
if (!strncasecmp(binding->url, "https", 5)) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
config_data.name = filename;
|
||||
if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC)) > -1) {
|
||||
if (!switch_strlen_zero(globals.cred)) {
|
||||
if (!switch_strlen_zero(binding->cred)) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, globals.cred);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
|
||||
}
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, globals.url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, binding->url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
|
||||
@@ -140,31 +155,71 @@ static switch_loadable_module_interface_t xml_curl_module_interface = {
|
||||
static switch_status_t do_config(void)
|
||||
{
|
||||
char *cf = "xml_curl.conf";
|
||||
switch_xml_t cfg, xml, settings, param;
|
||||
switch_xml_t cfg, xml, bindings_tag, binding_tag, param;
|
||||
xml_binding_t *binding = NULL;
|
||||
int x = 0;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if ((settings = switch_xml_child(cfg, "settings"))) {
|
||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
||||
if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
for (binding_tag = switch_xml_child(bindings_tag, "binding"); binding_tag; binding_tag = binding_tag->next) {
|
||||
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
|
||||
char *url = NULL;
|
||||
char *bind_cred = NULL;
|
||||
char *bind_mask = NULL;
|
||||
|
||||
for (param = switch_xml_child(binding_tag, "param"); param; param = param->next) {
|
||||
char *var = (char *) switch_xml_attr_soft(param, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||
|
||||
if (!strcasecmp(var, "gateway-url")) {
|
||||
char *bindings = (char *) switch_xml_attr_soft(param, "bindings");
|
||||
set_global_bindings(bindings);
|
||||
set_global_url(val);
|
||||
bind_mask = (char *) switch_xml_attr_soft(param, "bindings");
|
||||
if (val) {
|
||||
url = val;
|
||||
}
|
||||
} else if (!strcasecmp(var, "gateway-credentials")) {
|
||||
set_global_cred(val);
|
||||
bind_cred = var;
|
||||
}
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(binding = malloc(sizeof(*binding)))) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
memset(binding, 0, sizeof(*binding));
|
||||
|
||||
binding->url = strdup(url);
|
||||
|
||||
if (bind_mask) {
|
||||
binding->bindings = strdup(bind_mask);
|
||||
}
|
||||
|
||||
if (bind_cred) {
|
||||
binding->cred = strdup(bind_cred);
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
|
||||
switch_strlen_zero(bname) ? "N/A" : bname,
|
||||
binding->url,
|
||||
binding->bindings ? binding->bindings : "all");
|
||||
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);
|
||||
x++;
|
||||
binding = NULL;
|
||||
}
|
||||
|
||||
switch_xml_free(xml);
|
||||
|
||||
return globals.url ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
return x ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,10 +230,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
|
||||
|
||||
if (do_config() == SWITCH_STATUS_SUCCESS) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s] [%s]\n",
|
||||
globals.url, globals.bindings ? globals.bindings : "all");
|
||||
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(globals.bindings));
|
||||
} else {
|
||||
} else {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user