spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-03-29 22:31:56 +00:00
1 parent a021945cef
commit 3a54126261
143 files changed
+22413 -31567

No files matched your search

@@ -46,12 +46,12 @@ static struct {
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_directory_name, globals.directory_name)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
static void load_config(void)
static void load_config(void)
{
char *cf = "dialplan_directory.conf";
switch_xml_t cfg, xml, settings, param;
@@ -100,19 +100,16 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
caller_profile = switch_channel_get_caller_profile(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
if (! (globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
caller_profile->destination_number);
if (!(globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
return NULL;
}
if (switch_core_directory_open(&dh,
if (switch_core_directory_open(&dh,
globals.directory_name,
globals.host,
globals.dn,
globals.pass,
NULL) != SWITCH_STATUS_SUCCESS) {
globals.host, globals.dn, globals.pass, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
return NULL;
}
@@ -127,10 +124,10 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
while (switch_core_directory_next(&dh) == SWITCH_STATUS_SUCCESS) {
while (switch_core_directory_next_pair(&dh, &var, &val) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DIRECTORY VALUE [%s]=[%s]\n", var, val);
if(!strcasecmp(var, "callflow")) {
if (!strcasecmp(var, "callflow")) {
if (!extension) {
if ((extension = switch_caller_extension_new(session, caller_profile->destination_number,
caller_profile->destination_number)) == 0) {
caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
goto out;
}
@@ -143,11 +140,11 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
}
}
}
out:
out:
switch_core_directory_close(&dh);
if (extension) {
switch_channel_set_state(channel, CS_EXECUTE);
}
@@ -159,7 +156,7 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
static const switch_dialplan_interface_t directory_dialplan_interface = {
/*.interface_name = */ "directory",
/*.hunt_function = */ directory_dialplan_hunt
/*.next = NULL */
/*.next = NULL */
};
static const switch_loadable_module_interface_t directory_dialplan_module_interface = {
@@ -171,7 +168,8 @@ static const switch_loadable_module_interface_t directory_dialplan_module_interf
/*.application_interface = */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
load_config();
@@ -50,7 +50,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
switch_channel_t *channel;
char *exten_name = (char *) switch_xml_attr_soft(xexten, "name");
int proceed = 0;
switch_stream_handle_t stream = {0};
switch_stream_handle_t stream = { 0 };
channel = switch_core_session_get_channel(session);
caller_profile = switch_channel_get_caller_profile(channel);
@@ -63,7 +63,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
switch_regex_t *re = NULL;
int ovector[30];
break_t do_break_i = BREAK_ON_FALSE;
field = (char *) switch_xml_attr(xcond, "field");
expression = (char *) switch_xml_attr_soft(xcond, "expression");
@@ -83,54 +83,58 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
if (field) {
if (*field == '$') {
char *cmd = switch_core_session_strdup(session, field + 1);
char *e, *arg;
field = cmd;
field_data = "";
char *e, *arg;
field = cmd;
field_data = "";
if (*field == '{') {
field++;
if ((e = strchr(field, '}'))) {
*e = '\0';
field_data = switch_channel_get_variable(channel, field);
}
} else {
switch_safe_free(stream.data);
memset(&stream, 0, sizeof(stream));
SWITCH_STANDARD_STREAM(stream);
if (*field == '{') {
field++;
if ((e = strchr(field, '}'))) {
*e = '\0';
field_data = switch_channel_get_variable(channel, field);
}
} else {
switch_safe_free(stream.data);
memset(&stream, 0, sizeof(stream));
SWITCH_STANDARD_STREAM(stream);
if ((arg = strchr(cmd, '('))) {
*arg++ = '\0';
if ((e = strchr(arg, ')'))) {
*e = '\0';
if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
field_data = stream.data;
}
}
}
}
} else {
if ((arg = strchr(cmd, '('))) {
*arg++ = '\0';
if ((e = strchr(arg, ')'))) {
*e = '\0';
if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
field_data = stream.data;
}
}
}
}
} else {
field_data = switch_caller_get_field_by_name(caller_profile, field);
}
if (!field_data) {
field_data = "";
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field,
field_data, expression);
if (!
(proceed =
switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
for (xaction = switch_xml_child(xcond, "anti-action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *application = (char *) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
if (!*extension) {
if ((*extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_caller_extension_new(session, exten_name,
caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
proceed = 0;
goto done;
}
}
switch_caller_extension_add_application(session, *extension, application, data);
}
@@ -145,20 +149,20 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *application = (char *) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
char *substituted = NULL;
uint32_t len = 0;
uint32_t len = 0;
char *app_data = NULL;
if (field && strchr(expression, '(')) {
len = (uint32_t)(strlen(data) + strlen(field_data) + 10);
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
}
memset(substituted, 0, len);
len = (uint32_t) (strlen(data) + strlen(field_data) + 10);
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
app_data = substituted;
} else {
@@ -169,15 +173,15 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
if ((*extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
proceed = 0;
goto done;
}
}
switch_caller_extension_add_application(session, *extension, application, app_data);
switch_safe_free(substituted);
switch_safe_free(substituted);
}
switch_regex_safe_free(re);
if (do_break_i == BREAK_ON_TRUE || do_break_i == BREAK_ALWAYS) {
@@ -185,110 +189,111 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
}
}
done:
switch_safe_free(stream.data);
done:
switch_safe_free(stream.data);
return proceed;
}
static switch_status_t dialplan_xml_locate(switch_core_session_t *session,
switch_caller_profile_t *caller_profile,
switch_xml_t *root,
switch_xml_t *node)
switch_xml_t * root, switch_xml_t * node)
{
switch_status_t status = SWITCH_STATUS_GENERR;
switch_channel_t *channel;
switch_stream_handle_t stream = {0};
switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL;
char *prof[12] = {0}, *prof_names[12] = {0}, *e = NULL;
switch_hash_index_t *hi;
uint32_t x = 0;
switch_stream_handle_t stream = { 0 };
switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL;
char *prof[12] = { 0 }, *prof_names[12] = {
0}, *e = NULL;
switch_hash_index_t *hi;
uint32_t x = 0;
channel = switch_core_session_get_channel(session);
SWITCH_STANDARD_STREAM(stream);
if (!(encode_buf = malloc(encode_len))) {
goto done;
}
prof[0] = caller_profile->context;
prof[1] = caller_profile->destination_number;
prof[2] = caller_profile->caller_id_name;
prof[3] = caller_profile->caller_id_number;
prof[4] = caller_profile->network_addr;
prof[5] = caller_profile->ani;
prof[6] = caller_profile->aniii;
prof[7] = caller_profile->rdnis;
prof[8] = caller_profile->source;
prof[9] = caller_profile->chan_name;
prof[10] = caller_profile->uuid;
SWITCH_STANDARD_STREAM(stream);
prof_names[0] = "context";
prof_names[1] = "destination_number";
prof_names[2] = "caller_id_name";
prof_names[3] = "caller_id_number";
prof_names[4] = "network_addr";
prof_names[5] = "ani";
prof_names[6] = "aniii";
prof_names[7] = "rdnis";
prof_names[8] = "source";
prof_names[9] = "chan_name";
prof_names[10] = "uuid";
if (!(encode_buf = malloc(encode_len))) {
goto done;
}
for (x = 0; prof[x]; x++) {
prof[0] = caller_profile->context;
prof[1] = caller_profile->destination_number;
prof[2] = caller_profile->caller_id_name;
prof[3] = caller_profile->caller_id_number;
prof[4] = caller_profile->network_addr;
prof[5] = caller_profile->ani;
prof[6] = caller_profile->aniii;
prof[7] = caller_profile->rdnis;
prof[8] = caller_profile->source;
prof[9] = caller_profile->chan_name;
prof[10] = caller_profile->uuid;
prof_names[0] = "context";
prof_names[1] = "destination_number";
prof_names[2] = "caller_id_name";
prof_names[3] = "caller_id_number";
prof_names[4] = "network_addr";
prof_names[5] = "ani";
prof_names[6] = "aniii";
prof_names[7] = "rdnis";
prof_names[8] = "source";
prof_names[9] = "chan_name";
prof_names[10] = "uuid";
for (x = 0; prof[x]; x++) {
if (switch_strlen_zero(prof[x])) {
continue;
}
new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_len = new_len;
encode_buf = tmp;
}
switch_url_encode(prof[x], encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
void *val;
const void *var;
switch_hash_this(hi, &var, NULL, &val);
new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_buf = tmp;
}
switch_url_encode((char *) val, encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
encode_buf = tmp;
}
switch_url_encode(prof[x], encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
e = (char *)stream.data + (strlen((char *)stream.data) - 1);
if (e && *e == '&') {
*e = '\0';
}
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi;
hi = switch_hash_next(hi)) {
void *val;
const void *var;
switch_hash_this(hi, &var, NULL, &val);
new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_buf = tmp;
}
switch_url_encode((char *) val, encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
}
e = (char *) stream.data + (strlen((char *) stream.data) - 1);
if (e && *e == '&') {
*e = '\0';
}
status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, stream.data);
done:
done:
switch_safe_free(stream.data);
switch_safe_free(encode_buf);
return status;
@@ -300,7 +305,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel;
switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten;
char *alt_path = (char *) arg;
char *alt_path = (char *) arg;
channel = switch_core_session_get_channel(session);
@@ -319,41 +324,43 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
/* get our handle to the "dialplan" section of the config */
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);
goto done;
}
if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) &&
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);
goto done;
}
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");
goto done;
}
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");
goto done;
}
} else {
if (dialplan_xml_locate(session, caller_profile, &xml, &cfg) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
goto done;
}
}
/* get a handle to the context tag */
}
/* get a handle to the context tag */
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", caller_profile->context))) {
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", caller_profile->context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n",
caller_profile->context);
goto done;
}
}
if (!(xexten = switch_xml_find_child(xcontext, "extension", "name", caller_profile->destination_number))) {
xexten = switch_xml_child(xcontext, "extension");
}
while(xexten) {
while (xexten) {
int proceed = 0;
char *cont = (char *) switch_xml_attr_soft(xexten, "continue");
@@ -374,7 +381,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
switch_channel_set_state(channel, CS_EXECUTE);
}
done:
done:
switch_xml_free(xml);
return extension;
}
@@ -383,7 +390,7 @@ done:
static const switch_dialplan_interface_t dialplan_interface = {
/*.interface_name = */ "XML",
/*.hunt_function = */ dialplan_hunt
/*.next = NULL */
/*.next = NULL */
};
static const switch_loadable_module_interface_t dialplan_module_interface = {
@@ -395,7 +402,8 @@ static const switch_loadable_module_interface_t dialplan_module_interface = {
/*.application_interface = */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */