[Freeswitch-svn] [commit] r8072 - freeswitch/trunk/src/mod/applications/mod_enum
Freeswitch SVN
anthm at freeswitch.org
Wed Apr 9 20:53:34 EDT 2008
Author: anthm
Date: Wed Apr 9 20:53:33 2008
New Revision: 8072
Modified:
freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
Log:
let enum do forked dial when 2 routes have the same weight
Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c Wed Apr 9 20:53:33 2008
@@ -609,6 +609,8 @@
switch_size_t l = 0, rbl = sizeof(rbuf);
uint32_t cnt = 1;
switch_channel_t *channel = switch_core_session_get_channel(session);
+ int last_order = -1, last_pref = -2;
+ char *last_delim = "|";
if (!(mydata = switch_core_session_strdup(session, data))) {
return;
@@ -633,9 +635,14 @@
for (rp = results; rp; rp = rp->next) {
if (!strcasecmp(rtp->service, rp->service)) {
switch_snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
- switch_channel_set_variable(channel, vbuf, rp->route);
-
+ switch_channel_set_variable(channel, vbuf, rp->route);
+ if (rp->preference == last_pref && rp->order == last_order) {
+ *last_delim = ',';
+ }
switch_snprintf(rbp, rbl, "%s|", rp->route);
+ last_delim = end_of_p(rbp);
+ last_order = rp->order;
+ last_pref = rp->preference;
l = strlen(rp->route) + 1;
rbp += l;
rbl -= l;
@@ -652,6 +659,57 @@
}
+
+SWITCH_STANDARD_API(enum_api)
+{
+ int argc = 0;
+ char *argv[4] = { 0 };
+ char *mydata = NULL;
+ char *dest = NULL, *root = NULL;
+ enum_record_t *results, *rp;
+ enum_route_t *rtp;
+ char rbuf[1024] = "";
+ char *rbp = rbuf;
+ switch_size_t l = 0, rbl = sizeof(rbuf);
+ int last_order = -1, last_pref = -2;
+ char *last_delim = "|";
+
+ if (!(mydata = strdup(cmd))) {
+ abort();
+ }
+
+ if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+ dest = argv[0];
+ root = argv[1];
+ if (enum_lookup(root, dest, &results) == SWITCH_STATUS_SUCCESS) {
+ for (rtp = globals.route_order; rtp; rtp = rtp->next) {
+ for (rp = results; rp; rp = rp->next) {
+ if (!strcasecmp(rtp->service, rp->service)) {
+ if (rp->preference == last_pref && rp->order == last_order) {
+ *last_delim = ',';
+ }
+ switch_snprintf(rbp, rbl, "%s|", rp->route);
+ last_delim = end_of_p(rbp);
+ last_order = rp->order;
+ last_pref = rp->preference;
+ l = strlen(rp->route) + 1;
+ rbp += l;
+ rbl -= l;
+ }
+ }
+ }
+ *(rbuf + strlen(rbuf) - 1) = '\0';
+ stream->write_function(stream, "%s", rbuf);
+ free_results(&results);
+ }
+ }
+
+ switch_safe_free(mydata);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+
SWITCH_STANDARD_API(enum_function)
{
int argc = 0;
@@ -728,6 +786,7 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "enum", "ENUM", enum_function, "");
+ SWITCH_ADD_API(api_interface, "enum_auto", "ENUM", enum_api, "");
SWITCH_ADD_APP(app_interface, "enum", "Perform an ENUM lookup", "Perform an ENUM lookup", enum_app_function, "<number> [<root>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_DIALPLAN(dp_interface, "enum", enum_dialplan_hunt);
More information about the Freeswitch-svn
mailing list