[Freeswitch-svn] [commit] r13933 - freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc

FreeSWITCH SVN ledr at freeswitch.org
Wed Jun 24 01:11:13 PDT 2009


Author: ledr
Date: Wed Jun 24 03:11:13 2009
New Revision: 13933

Log:
got break-to working


Modified:
   freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/mod_xml_odbc.c
   freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/xml_odbc.conf.xml

Modified: freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/mod_xml_odbc.c
==============================================================================
--- freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/mod_xml_odbc.c	(original)
+++ freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/mod_xml_odbc.c	Wed Jun 24 03:11:13 2009
@@ -124,6 +124,7 @@
 	switch_xml_t xml_out;
 	int *off;
 	switch_event_t *params;
+	int rowcount;
 } xml_odbc_query_helper_t;
 
 
@@ -133,6 +134,8 @@
 	switch_xml_t xml_in_tmp;
 	int i;
 
+	qh->rowcount++;
+
 	for (i = 0; i < argc; i++) {
 		switch_event_del_header(qh->params, columnName[i]);
 		switch_event_add_header_string(qh->params, SWITCH_STACK_BOTTOM, columnName[i], argv[i]);
@@ -154,7 +157,7 @@
 
 	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 *value = NULL, *new_value = NULL;
 		char *empty_result_break_to = NULL;
@@ -165,30 +168,47 @@
 		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");
 
-		if (!switch_strlen_zero(value)) {
-			new_value = switch_event_expand_headers(params, value);
-			if (!strcasecmp(name, "break-to")) { // WHAT TO DO WITH FURTHER RENDERING LOWER ON THE STACK ?!?!?!
-				xml_out = NULL;
-				off = 0; // <- ?
-				if (xml_odbc_render_template(new_value, params, xml_out, off) == SWITCH_STATUS_FALSE) {
-					if (!switch_strlen_zero(no_template_break_to)) {
-						xml_odbc_render_template(no_template_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;
-
-				if (switch_odbc_handle_callback_exec(globals.master_odbc, new_value, xml_odbc_query_callback, &query_helper) == SWITCH_ODBC_SUCCESS) {
-					// nothing
-				} else if (!switch_strlen_zero(empty_result_break_to)) { // if zero rows returned then switch_odbc_handle_callback_exec != SWITCH_ODBC_SUCCESS ??? 
-					xml_out = NULL;
-					off = 0; // <- ?
-					xml_odbc_render_template(empty_result_break_to, params, xml_out, off);
+		if (switch_strlen_zero(name)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do because no name attribute is given\n");
+			goto done;
+		}
+
+		if (switch_strlen_zero(value)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do name=[%s] because no value attr is given\n", name);
+			goto done;
+		}
+
+		new_value = switch_event_expand_headers(params, value);
+
+		if (!strcasecmp(name, "break-to")) {
+//			if (xml_odbc_render_template(new_value, params, xml_out, off) == SWITCH_STATUS_FALSE) {
+//				if (!switch_strlen_zero(no_template_break_to)) {
+/* 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", value);
+					return SWITCH_STATUS_FALSE;
+//				}
+//			}
+		} 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 {
@@ -211,11 +231,14 @@
 
 		/* copy all children and render them */
 		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;
 }
 
@@ -223,17 +246,31 @@
 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;
+	char *next_template_name = NULL;
+
+	if ((template_tag = switch_xml_find_child(globals.templates_tag, "template", "name", template_name))) {
+		for (sub_tag = template_tag->child; sub_tag; sub_tag = sub_tag->ordered) {
+			if (xml_odbc_render_tag(sub_tag, params, xml_out, off) != SWITCH_STATUS_SUCCESS) {
+			}
 
-	for (template_tag = switch_xml_child(globals.templates_tag, "template"); template_tag; template_tag = template_tag->next) {
-		char *template_tag_name = (char*) switch_xml_attr_soft(template_tag, "name");
-		if (!strcmp(template_tag_name, template_name)) {
-			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 @@
 
 	xml_odbc_query_type_t query_type;
 
-
 	int off = 0, ret = 1;
 
 	if (!binding) {

Modified: freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/xml_odbc.conf.xml
==============================================================================
--- freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/xml_odbc.conf.xml	(original)
+++ freeswitch/trunk/scripts/contrib/ledr/mod_xml_odbc/xml_odbc.conf.xml	Wed Jun 24 03:11:13 2009
@@ -10,9 +10,6 @@
     <binding name="directory">
       <param name="odbc-dsn" value="freeswitch:freeswitch:secret"/>
       <param name="template" value="directory"/>
-      <!-- <param name="template" value="not_found"/> -->
-      <!-- <param name="template" value="someuser"/> -->
-      <!-- <param name="template" value="testsql"/> -->
     </binding>
 <!--
     <binding name="dialplan">
@@ -34,7 +31,7 @@
     </template>
 
     <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}">
           <settings>
             <xml-odbc-do name="query" value="
@@ -60,45 +57,6 @@
       </document>
     </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 at 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"/>
 
   </templates>



More information about the Freeswitch-svn mailing list