rearrange some things please see conf/freeswitch.xml as there is a significant change to the conf that will break your stuff

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1446 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-05-12 19:28:21 +00:00
parent d314140374
commit d53d9d3997
7 changed files with 130 additions and 56 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<document type="freeswitch/xml"> <document type="freeswitch/xml">
<section name="configuration"> <section name="configuration" description="Various Configuration">
<configuration name="modules.conf" description="Modules"> <configuration name="modules.conf" description="Modules">
<modules> <modules>
<!-- Loggers (I'd load these first) --> <!-- Loggers (I'd load these first) -->
@ -205,14 +205,51 @@
</settings> </settings>
</configuration> </configuration>
<configuration name="extensions.conf" description="Regex/XML Dialplan"> <configuration name="dingaling.conf" description="XMPP Jingle Endpoint">
<!-- any extension starting with a '4' --> <settings>
<!-- strip the '4' and consider the rest a numeric filename --> <param name="debug" value="0"/>
<param name="codec_prefs" value="PCMU"/>
</settings>
<!-- *NOTE* your resource (after the /) MUST contain the string "talk" (upper or lower case is ok) -->
<!-- *NOTE* as of May 2 2006 you must set"auto-login" to"true" if you want to be able to auto-login on startup"/> -->
<interface>
<param name="name" value="jingle"/>
<param name="login" value="myjid@myserver.com/talk"/>
<param name="password" value="mypass"/>
<param name="dialplan" value="XML"/>
<param name="message" value="Jingle all the way"/>
<param name="rtp-ip" value="10.0.0.1"/>
<param name="auto-login" value="true"/>
<!-- or -->
<!-- <param name="rtp-ip" value="my_lan_ip"/> -->
<!-- <param name="ext-rtp-ip" value="stun:stun.server.com"/> -->
<!-- default extension (if one cannot be determined) -->
<param name="exten" value="888"/>
<!-- VAD choose one -->
<!-- <param name="vad" value="in"/> -->
<!-- <param name="vad" value="out"/> -->
<param name="vad" value="both"/>
</interface>
</configuration>
<configuration name="xml_rpc.conf" description="XML RPC">
<settings>
<!-- The port where you want to run the http service (default 8080) -->
<param name="http_port" value="8080"/>
<!-- The url to a gateway cgi that can generate xml similar to
what's in this file only on-the-fly (leave it commented if you dont
need it) -->
<!-- <param name="gateway_url" value="http://www.server.com/gateway.cgi"/> -->
</settings>
</configuration>
</section>
<section name="dialplan" description="Regex/XML Dialplan">
<!-- Valid fields in conditions: <!-- Valid fields in conditions:
"dialplan, caller_id_name, ani, ani2, caller_id_number, "dialplan, caller_id_name, ani, ani2, caller_id_number,
network_addr, rdnis, destination_number, uuid, source, network_addr, rdnis, destination_number, uuid, source,
context, chan_name" --> context, chan_name" -->
<!-- *NOTE* The special context name 'any' will match any context -->
<context name="default"> <context name="default">
<extension name="devconf"> <extension name="devconf">
<condition field="destination_number" expression="^888$"> <condition field="destination_number" expression="^888$">
@ -268,46 +305,9 @@
</condition> </condition>
</extension> </extension>
</context> </context>
</configuration> </section>
<section name="directory" description="User Directory">
<configuration name="dingaling.conf" description="XMPP Jingle Endpoint"> </section>
<settings>
<param name="debug" value="0"/>
<param name="codec_prefs" value="PCMU"/>
</settings>
<!-- *NOTE* your resource (after the /) MUST contain the string "talk" (upper or lower case is ok) -->
<!-- *NOTE* as of May 2 2006 you must set"auto-login" to"true" if you want to be able to auto-login on startup"/> -->
<interface>
<param name="name" value="jingle"/>
<param name="login" value="myjid@myserver.com/talk"/>
<param name="password" value="mypass"/>
<param name="dialplan" value="XML"/>
<param name="message" value="Jingle all the way"/>
<param name="rtp-ip" value="10.0.0.1"/>
<param name="auto-login" value="true"/>
<!-- or -->
<!-- <param name="rtp-ip" value="my_lan_ip"/> -->
<!-- <param name="ext-rtp-ip" value="stun:stun.server.com"/> -->
<!-- default extension (if one cannot be determined) -->
<param name="exten" value="888"/>
<!-- VAD choose one -->
<!-- <param name="vad" value="in"/> -->
<!-- <param name="vad" value="out"/> -->
<param name="vad" value="both"/>
</interface>
</configuration>
<configuration name="xml_rpc.conf" description="XML RPC">
<settings>
<!-- The port where you want to run the http service (default 8080) -->
<param name="http_port" value="8080"/>
<!-- The url to a gateway cgi that can generate xml similar to
what's in this file only on-the-fly (leave it commented if you dont
need it) -->
<!-- <param name="gateway_url" value="http://www.server.com/gateway.cgi"/> -->
</settings>
</configuration>
</section>
</document> </document>

View File

@ -93,6 +93,14 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
#define SWITCH_TRUE 1 #define SWITCH_TRUE 1
#define SWITCH_FALSE 0 #define SWITCH_FALSE 0
typedef enum {
SWITCH_XML_SECTION_RESULT = 0,
SWITCH_XML_SECTION_CONFIG = (1 << 0),
SWITCH_XML_SECTION_DIRECTORY = (1 << 1),
SWITCH_XML_SECTION_DIALPLAN = (1 << 2)
} switch_xml_section_t;
/*! /*!
\enum switch_vad_flag_t \enum switch_vad_flag_t
\brief RTP Related Flags \brief RTP Related Flags

View File

@ -151,7 +151,8 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key);
\param fname the function name to declare \param fname the function name to declare
\param vname the name of the global pointer to modify with the new function \param vname the name of the global pointer to modify with the new function
*/ */
#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (vname) {free(vname); vname = NULL;}vname = strdup(string);} #define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (!string) return;\
if (vname) {free(vname); vname = NULL;}vname = strdup(string);}
/*! /*!
\brief Separate a string into an array based on a character delimeter \brief Separate a string into an array based on a character delimeter

View File

@ -313,9 +313,15 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t *
///\brief bind a search function to an external gateway ///\brief bind a search function to an external gateway
///\param function the search function to bind ///\param function the search function to bind
///\param sections a bitmask of sections you wil service
///\return SWITCH_STATUS_SUCCESS if successful ///\return SWITCH_STATUS_SUCCESS if successful
///\note gateway functions will be executed in the order they were binded until a success is found else the root registry will be used ///\note gateway functions will be executed in the order they were binded until a success is found else the root registry will be used
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function); SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections);
///\brief parse a string for a list of sections
///\param string a | delimited list of section names
///\return the section mask
SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(char *str);
END_EXTERN_C END_EXTERN_C

View File

@ -127,7 +127,6 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
switch_caller_profile_t *caller_profile; switch_caller_profile_t *caller_profile;
switch_caller_extension_t *extension = NULL; switch_caller_extension_t *extension = NULL;
switch_channel_t *channel; switch_channel_t *channel;
char *cf = "extensions.conf";
char *exten_name = NULL; char *exten_name = NULL;
switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond; switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond;
char *context = NULL; char *context = NULL;
@ -145,10 +144,11 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session)
caller_profile->destination_number); caller_profile->destination_number);
snprintf(params, sizeof(params), "dest=%s", caller_profile->destination_number); snprintf(params, sizeof(params), "dest=%s", caller_profile->destination_number);
if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return NULL; return NULL;
} }
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", context))) { if (!(xcontext = switch_xml_find_child(cfg, "context", "name", context))) {

View File

@ -49,9 +49,11 @@ static struct {
uint16_t port; uint16_t port;
uint8_t running; uint8_t running;
char *url; char *url;
char *bindings;
} globals; } globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url) SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings);
struct config_data { struct config_data {
char *name; char *name;
@ -79,8 +81,14 @@ static switch_xml_t xml_url_fetch(char *section,
struct config_data config_data; struct config_data config_data;
switch_xml_t xml = NULL; switch_xml_t xml = NULL;
snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s\n", snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&&key_value=%s%s%s\n",
globals.url, section, tag_name, key_name, key_value, params ? "&" : "", params ? params : ""); globals.url,
section,
tag_name ? tag_name : "",
key_name ? key_name : "",
key_value ? key_value : "",
params ? "&" : "", params ? params : "");
srand((unsigned int)(time(NULL) + strlen(url))); srand((unsigned int)(time(NULL) + strlen(url)));
snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff)); snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff));
curl_handle = curl_easy_init(); curl_handle = curl_easy_init();
@ -142,6 +150,8 @@ static switch_status_t do_config(void)
char *val = (char *) switch_xml_attr(param, "value"); char *val = (char *) switch_xml_attr(param, "value");
if (!strcasecmp(var, "gateway_url")) { if (!strcasecmp(var, "gateway_url")) {
char *bindings = (char *) switch_xml_attr(param, "bindings");
set_global_bindings(bindings);
set_global_url(val); set_global_url(val);
} else if (!strcasecmp(var, "http_port")) { } else if (!strcasecmp(var, "http_port")) {
globals.port = (uint16_t)atoi(val); globals.port = (uint16_t)atoi(val);
@ -167,8 +177,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
if (do_config() == SWITCH_STATUS_SUCCESS) { if (do_config() == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s]\n", globals.url); 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_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(globals.bindings));
} }
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);

View File

@ -84,6 +84,7 @@ char *SWITCH_XML_NIL[] = { NULL }; // empty, null terminated array of strings
struct switch_xml_binding { struct switch_xml_binding {
switch_xml_search_function_t function; switch_xml_search_function_t function;
switch_xml_section_t sections;
struct switch_xml_binding *next; struct switch_xml_binding *next;
}; };
@ -94,7 +95,43 @@ static switch_memory_pool_t *XML_MEMORY_POOL;
static switch_mutex_t *XML_LOCK; static switch_mutex_t *XML_LOCK;
static switch_thread_rwlock_t *RWLOCK; static switch_thread_rwlock_t *RWLOCK;
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function) struct xml_section_t {
const char *name;
switch_xml_section_t section;
};
static struct xml_section_t SECTIONS[] = {
{ "result", SWITCH_XML_SECTION_RESULT},
{ "config", SWITCH_XML_SECTION_CONFIG},
{ "directory", SWITCH_XML_SECTION_DIRECTORY},
{ "dialplan", SWITCH_XML_SECTION_DIALPLAN},
{ NULL, 0}
};
SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(char *str)
{
int x;
char buf[1024] = "";
switch_xml_section_t sections = SWITCH_XML_SECTION_RESULT;
if (str) {
for(x = 0; x < strlen(str); x++) {
buf[x] = tolower(str[x]);
}
for(x = 0;;x++) {
if (!SECTIONS[x].name) {
break;
}
if (strstr(buf, SECTIONS[x].name)) {
sections |= SECTIONS[x].section;
}
}
}
return sections;
}
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections)
{ {
switch_xml_binding_t *binding = NULL, *ptr = NULL; switch_xml_binding_t *binding = NULL, *ptr = NULL;
assert(function != NULL); assert(function != NULL);
@ -104,6 +141,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_searc
} }
binding->function = function; binding->function = function;
binding->sections = sections;
switch_mutex_lock(XML_LOCK); switch_mutex_lock(XML_LOCK);
for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next); for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next);
@ -123,8 +161,13 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_find_child(switch_xml_t node, char *chil
{ {
switch_xml_t p = NULL; switch_xml_t p = NULL;
if (!(childname && attrname && value)) {
return node;
}
for (p = switch_xml_child(node, childname); p; p = p->next) { for (p = switch_xml_child(node, childname); p; p = p->next) {
const char *aname = switch_xml_attr(p, attrname); const char *aname = switch_xml_attr(p, attrname);
if (!strcasecmp(aname, value)) { if (!strcasecmp(aname, value)) {
break; break;
} }
@ -757,6 +800,12 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section,
switch_mutex_lock(XML_LOCK); switch_mutex_lock(XML_LOCK);
for(binding = BINDINGS; binding; binding = binding->next) { for(binding = BINDINGS; binding; binding = binding->next) {
switch_xml_section_t sections = switch_xml_parse_section_string(section);
if (binding->sections && !(sections & binding->sections)) {
continue;
}
if ((xml = binding->function(section, tag_name, key_name, key_value, params))) { if ((xml = binding->function(section, tag_name, key_name, key_value, params))) {
const char *err = NULL; const char *err = NULL;