Revision
14776
Author
ledr
Date
2009-09-06 12:05:13 -0500 (Sun, 06 Sep 2009)

Log Message

Added functionality to set-event-header so all values are expanded and so that new events can be set, also
check-event-header now internally calls set-event-header as they are actually the same, except for not changing headers

Added directory-gateways template, as it is apparently necessary to respond to section=directory, purpose=gateways
for making <domain .. alias="true"/> work from a sip profile !!

Modified Paths

Added Paths

Diff

Modified: freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/mod_xml_odbc.c (14775 => 14776)


--- freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/mod_xml_odbc.c	2009-09-05 19:30:18 UTC (rev 14775)
+++ freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/mod_xml_odbc.c	2009-09-06 17:05:13 UTC (rev 14776)
@@ -150,55 +150,58 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t xml_odbc_do_check_event_header(xml_odbc_session_helper_t *helper)
+static switch_status_t xml_odbc_do_set_event_header(xml_odbc_session_helper_t *helper)
 {
-	char *name = (char *) switch_xml_attr_soft(helper->xml_in_cur, "name");
-	char *if_name = (char *) switch_xml_attr_soft(helper->xml_in_cur, "if-name");
-	char *if_value = (char *) switch_xml_attr_soft(helper->xml_in_cur, "if-value");
-	char *tmp_value;
-	switch_status_t status = SWITCH_STATUS_FALSE;
+	char *name = (char *) switch_xml_attr(helper->xml_in_cur, "name"); // the xml-odbc-do name attr
 
-	if (switch_strlen_zero(if_name)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do name=[%s] because no if-name is given\n", name);
-		goto done;
-	}
+	char *if_name = (char *) switch_xml_attr(helper->xml_in_cur, "if-name");
+	if (if_name) { if_name = switch_event_expand_headers_by_pool(helper->pool, helper->event, if_name); }
 
-	if ((tmp_value = switch_event_get_header(helper->event, if_name))) {
-		if (!switch_strlen_zero(tmp_value)) {
-			if (switch_strlen_zero(if_value) || !strcasecmp(if_value, tmp_value)) {
-				status = xml_odbc_render_children(helper);
-			}
-		}
-	}
+	char *if_value = (char *) switch_xml_attr(helper->xml_in_cur, "if-value");
+	if (if_value) { if_value = switch_event_expand_headers_by_pool(helper->pool, helper->event, if_value); }
 
-  done:
-	return status;
-}
+	char *to_name = (char *) switch_xml_attr(helper->xml_in_cur, "to-name");
+	if (to_name) { to_name = switch_event_expand_headers_by_pool(helper->pool, helper->event, to_name); }
 
-static switch_status_t xml_odbc_do_set_event_header(xml_odbc_session_helper_t *helper)
-{
-	char *name = (char *) switch_xml_attr_soft(helper->xml_in_cur, "name");
-	char *if_name = (char *) switch_xml_attr_soft(helper->xml_in_cur, "if-name");
-	char *if_value = (char *) switch_xml_attr_soft(helper->xml_in_cur, "if-value");
+	char *to_value = (char *) switch_xml_attr(helper->xml_in_cur, "to-value");
+	if (to_value) { to_value = switch_event_expand_headers_by_pool(helper->pool, helper->event, to_value); }
+
 	char *old_value = NULL;
-	char *to_value = (char *) switch_xml_attr_soft(helper->xml_in_cur, "to-value");
-	char *new_to_value = switch_event_expand_headers_by_pool(helper->pool, helper->event, to_value);
+
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if (switch_strlen_zero(to_value)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Ignoring xml-odbc-do name=[%s] because no to-value is given\n", name);
+	if (if_value && !if_name) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "xml-odbc-do [%s] if_name is required when if_value given\n", name);
 		goto done;
 	}
 
-	if ((old_value = switch_event_get_header(helper->event, if_name))) {
-		if (switch_strlen_zero(if_value) || !strcasecmp(if_value, old_value)) {
-			switch_event_del_header(helper->event, if_name);
-			switch_event_add_header_string(helper->event, SWITCH_STACK_BOTTOM, if_name, new_to_value);
+	if (!if_name && !to_name) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "xml-odbc-do [%s] either if_name or to_name are required\n", name);
+		goto done;
+	}
+
+	if (if_name) {
+		if (!(old_value = switch_event_get_header(helper->event, if_name))) {
+			status = SWITCH_STATUS_SUCCESS;
+			goto done;
 		}
 	}
 
-	status = SWITCH_STATUS_SUCCESS;
+	if (if_value && old_value && strcasecmp(if_value, old_value)) {
+		status = SWITCH_STATUS_SUCCESS;
+		goto done;
+	}
 
+	if (to_name || to_value) {
+		switch_event_del_header(helper->event, if_name ? if_name : to_name);
+
+		switch_event_add_header_string(helper->event, SWITCH_STACK_BOTTOM,
+					to_name ? to_name : if_name,
+					to_value ? to_value : old_value);
+	}
+
+	status = xml_odbc_render_children(helper);
+
   done:
 	return status;
 }
@@ -246,8 +249,8 @@
 
 		if (!strcasecmp(name, "break-to")) {
 			status = xml_odbc_do_break_to(helper);
-		} else if (!strcasecmp(name, "check-event-header")) {
-			status = xml_odbc_do_check_event_header(helper);
+		} else if (!strcasecmp(name, "check-event-header")) {  // check-event-header is the same as set-event-header
+			status = xml_odbc_do_set_event_header(helper); // except no to-name or to-value are given..
 		} else if (!strcasecmp(name, "set-event-header")) {
 			status = xml_odbc_do_set_event_header(helper);
 		} else if (!strcasecmp(name, "query")) {

Added: freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/xml_odbc_templates/directory-gateways.xml (0 => 14776)


--- freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/xml_odbc_templates/directory-gateways.xml	                        (rev 0)
+++ freeswitch/trunk/contrib/mod/xml_int/mod_xml_odbc/xml_odbc_templates/directory-gateways.xml	2009-09-06 17:05:13 UTC (rev 14776)
@@ -0,0 +1,19 @@
+<include>
+  <!-- purpose=gateways is not only called for getting gateways, but also for getting a list
+       of domains that will be aliased to a profile if <domain .. alias="true"/> is set -->
+  <template name="directory-gateways">
+    <document type="freeswitch/xml">
+      <section name="directory">
+        <xml-odbc-do name="set-event-header" to-name="where-clause" to-value="`${key_name}`='${key_value}'"/>  <!--  bah  -->
+        <xml-odbc-do name="check-event-header" if-name="key_name" if-value="">                                 <!--  but  -->
+          <xml-odbc-do name="set-event-header" to-name="where-clause" to-value="1"/>                           <!--  how  -->
+        </xml-odbc-do>                                                                                         <!-- else? -->
+        <xml-odbc-do name="query" on-empty-result-break-to="not-found"
+                     value="SELECT name AS domain_name FROM dir_domains WHERE ${where-clause};">
+          <domain name="${domain_name}"/>
+          <!-- select all gateways of users within this domain_name here, to make parse=true working -->
+        </xml-odbc-do>
+      </section>
+    </document>
+  </template>
+</include>