提交 831e3e49 authored 作者: Leon de Rooij's avatar Leon de Rooij

got break-to working


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/scripts/contrib@13933 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 4a6fdfa5
...@@ -124,6 +124,7 @@ typedef struct xml_odbc_query_helper { ...@@ -124,6 +124,7 @@ typedef struct xml_odbc_query_helper {
switch_xml_t xml_out; switch_xml_t xml_out;
int *off; int *off;
switch_event_t *params; switch_event_t *params;
int rowcount;
} xml_odbc_query_helper_t; } xml_odbc_query_helper_t;
...@@ -133,6 +134,8 @@ static int xml_odbc_query_callback(void *pArg, int argc, char **argv, char **col ...@@ -133,6 +134,8 @@ static int xml_odbc_query_callback(void *pArg, int argc, char **argv, char **col
switch_xml_t xml_in_tmp; switch_xml_t xml_in_tmp;
int i; int i;
qh->rowcount++;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
switch_event_del_header(qh->params, columnName[i]); switch_event_del_header(qh->params, columnName[i]);
switch_event_add_header_string(qh->params, SWITCH_STACK_BOTTOM, columnName[i], argv[i]); switch_event_add_header_string(qh->params, SWITCH_STACK_BOTTOM, columnName[i], argv[i]);
...@@ -154,7 +157,7 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t * ...@@ -154,7 +157,7 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t *
xml_odbc_query_helper_t query_helper; xml_odbc_query_helper_t query_helper;
if (!strcasecmp(xml_in->name, "xml-odbc-do")) { if (!strcasecmp(xml_in->name, "xml-odbc-do")) {
char *name = NULL; char *name = NULL;
char *value = NULL, *new_value = NULL; char *value = NULL, *new_value = NULL;
char *empty_result_break_to = NULL; char *empty_result_break_to = NULL;
...@@ -165,30 +168,47 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t * ...@@ -165,30 +168,47 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t *
empty_result_break_to = (char *) switch_xml_attr_soft(xml_in, "on-empty-result-break-to"); empty_result_break_to = (char *) switch_xml_attr_soft(xml_in, "on-empty-result-break-to");
no_template_break_to = (char *) switch_xml_attr_soft(xml_in, "on-no-template-break-to"); no_template_break_to = (char *) switch_xml_attr_soft(xml_in, "on-no-template-break-to");
if (!switch_strlen_zero(value)) { if (switch_strlen_zero(name)) {
new_value = switch_event_expand_headers(params, value); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do because no name attribute is given\n");
if (!strcasecmp(name, "break-to")) { // WHAT TO DO WITH FURTHER RENDERING LOWER ON THE STACK ?!?!?! goto done;
xml_out = NULL; }
off = 0; // <- ?
if (xml_odbc_render_template(new_value, params, xml_out, off) == SWITCH_STATUS_FALSE) { if (switch_strlen_zero(value)) {
if (!switch_strlen_zero(no_template_break_to)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do name=[%s] because no value attr is given\n", name);
xml_odbc_render_template(no_template_break_to, params, xml_out, off); goto done;
} }
}
} else if (!strcasecmp(name, "query")) { new_value = switch_event_expand_headers(params, value);
query_helper.xml_in = xml_in;
query_helper.xml_out = xml_out; if (!strcasecmp(name, "break-to")) {
query_helper.off = off; // if (xml_odbc_render_template(new_value, params, xml_out, off) == SWITCH_STATUS_FALSE) {
query_helper.params = params; // if (!switch_strlen_zero(no_template_break_to)) {
/* have a look at this again, not too happy about this next_template_name thing.. */
if (switch_odbc_handle_callback_exec(globals.master_odbc, new_value, xml_odbc_query_callback, &query_helper) == SWITCH_ODBC_SUCCESS) { switch_event_del_header(params, "next_template_name");
// nothing switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "next_template_name", value);
} else if (!switch_strlen_zero(empty_result_break_to)) { // if zero rows returned then switch_odbc_handle_callback_exec != SWITCH_ODBC_SUCCESS ??? return SWITCH_STATUS_FALSE;
xml_out = NULL; // }
off = 0; // <- ? // }
xml_odbc_render_template(empty_result_break_to, params, xml_out, off); } else if (!strcasecmp(name, "query")) {
query_helper.xml_in = xml_in;
query_helper.xml_out = xml_out;
query_helper.off = off;
query_helper.params = params;
query_helper.rowcount = 0;
if (switch_odbc_handle_callback_exec(globals.master_odbc, new_value, xml_odbc_query_callback, &query_helper) != SWITCH_ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error running this query: [%s]\n", new_value);
} else {
if (!switch_strlen_zero(empty_result_break_to) && query_helper.rowcount == 0) {
/* have a look at this again, not too happy about this next_template_name thing.. */
switch_event_del_header(params, "next_template_name");
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "next_template_name", empty_result_break_to);
return SWITCH_STATUS_FALSE;
} }
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring unknown xml-odbc-do name=[%s]\n", name);
} }
} else { } else {
...@@ -211,11 +231,14 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t * ...@@ -211,11 +231,14 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t *
/* copy all children and render them */ /* copy all children and render them */
for (xml_in_tmp = xml_in->child; xml_in_tmp; xml_in_tmp = xml_in_tmp->ordered) { for (xml_in_tmp = xml_in->child; xml_in_tmp; xml_in_tmp = xml_in_tmp->ordered) {
xml_odbc_render_tag(xml_in_tmp, params, xml_out, off); if (xml_odbc_render_tag(xml_in_tmp, params, xml_out, off) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
} }
} }
done:
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -223,17 +246,31 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t * ...@@ -223,17 +246,31 @@ static switch_status_t xml_odbc_render_tag(switch_xml_t xml_in, switch_event_t *
static switch_status_t xml_odbc_render_template(char *template_name, switch_event_t *params, switch_xml_t xml_out, int *off) static switch_status_t xml_odbc_render_template(char *template_name, switch_event_t *params, switch_xml_t xml_out, int *off)
{ {
switch_xml_t template_tag = NULL, sub_tag = NULL; switch_xml_t template_tag = NULL, sub_tag = NULL;
char *next_template_name = NULL;
for (template_tag = switch_xml_child(globals.templates_tag, "template"); template_tag; template_tag = template_tag->next) { if ((template_tag = switch_xml_find_child(globals.templates_tag, "template", "name", template_name))) {
char *template_tag_name = (char*) switch_xml_attr_soft(template_tag, "name"); for (sub_tag = template_tag->child; sub_tag; sub_tag = sub_tag->ordered) {
if (!strcmp(template_tag_name, template_name)) { if (xml_odbc_render_tag(sub_tag, params, xml_out, off) != SWITCH_STATUS_SUCCESS) {
for (sub_tag = template_tag->child; sub_tag; sub_tag = sub_tag->ordered) {
xml_odbc_render_tag(sub_tag, params, xml_out, off);
return SWITCH_STATUS_SUCCESS;
} }
if ((next_template_name = switch_event_get_header(params, "next_template_name"))) {
goto rewind;
}
} }
goto done;
} }
return SWITCH_STATUS_FALSE;
next_template_name = "not_found";
rewind:
/* have a look at this again, not too happy about this next_template_name thing.. */
switch_event_del_header(params, "next_template_name");
xml_out->name = "";
xml_odbc_render_template(next_template_name, params, xml_out, off);
done:
return SWITCH_STATUS_SUCCESS;
} }
...@@ -249,7 +286,6 @@ static switch_xml_t xml_odbc_search(const char *section, const char *tag_name, c ...@@ -249,7 +286,6 @@ static switch_xml_t xml_odbc_search(const char *section, const char *tag_name, c
xml_odbc_query_type_t query_type; xml_odbc_query_type_t query_type;
int off = 0, ret = 1; int off = 0, ret = 1;
if (!binding) { if (!binding) {
......
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
<binding name="directory"> <binding name="directory">
<param name="odbc-dsn" value="freeswitch:freeswitch:secret"/> <param name="odbc-dsn" value="freeswitch:freeswitch:secret"/>
<param name="template" value="directory"/> <param name="template" value="directory"/>
<!-- <param name="template" value="not_found"/> -->
<!-- <param name="template" value="someuser"/> -->
<!-- <param name="template" value="testsql"/> -->
</binding> </binding>
<!-- <!--
<binding name="dialplan"> <binding name="dialplan">
...@@ -34,7 +31,7 @@ ...@@ -34,7 +31,7 @@
</template> </template>
<template name="simple_configuration"> <template name="simple_configuration">
<document type="freeswitch/xml"> <!-- should this tag be automatically rendered first on xml_out and left out here ? --> <document type="freeswitch/xml">
<configuration name="${section}"> <configuration name="${section}">
<settings> <settings>
<xml-odbc-do name="query" value=" <xml-odbc-do name="query" value="
...@@ -60,45 +57,6 @@ ...@@ -60,45 +57,6 @@
</document> </document>
</template> </template>
<template name="testsql"> <!-- for testing only -->
<document type="freeswitch/xml">
<xml-odbc-do name="query" value="SELECT name, value FROM dir_user_params WHERE dir_user_id='1';">
<param name="${name}" value="${value}"/>
</xml-odbc-do>
</document>
</template>
<template name="someuser"> <!-- for testing only -->
<document type="freeswitch/xml">
<section name="directory">
<domain name="${domain}">
<params>
<param name="some_domain_param" value="some_domain_value"/>
</params>
<variables>
</variables>
<groups>
<group name="default">
<users>
<user id="someuser" mailbox="leon@toyos.nl" cidr="" number-alias="0031320227470">
<params>
<param name="password" value="secret"/>
</params>
<variables>
<variable name="accountcode" value="1234"/>
</variables>
</user>
</users>
</group>
<group name="prepay">
<user id="someuser" type="pointer"/>
</group>
</groups>
</domain>
</section>
</document>
</template>
<X-PRE-PROCESS cmd="include" data="xml_odbc_templates/*.xml"/> <X-PRE-PROCESS cmd="include" data="xml_odbc_templates/*.xml"/>
</templates> </templates>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论