[Freeswitch-svn] [commit] r5778 - in freeswitch/trunk/src: . mod/applications/mod_fifo mod/xml_int/mod_xml_cdr

Freeswitch SVN anthm at freeswitch.org
Tue Oct 2 12:38:15 EDT 2007


Author: anthm
Date: Tue Oct  2 12:38:15 2007
New Revision: 5778

Modified:
   freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_ivr.c
   freeswitch/trunk/src/switch_xml.c

Log:
refactor xml cdr and some cleanup

Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	Tue Oct  2 12:38:15 2007
@@ -229,12 +229,13 @@
                 }
 
                 switch_channel_answer(channel);
-				cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(channel));
+				cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
                 assert(cloned_profile);
                 switch_channel_set_originator_caller_profile(other_channel, cloned_profile);
 
-				cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
+				cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(other_channel));
                 assert(cloned_profile);
+                assert(cloned_profile->next == NULL);
                 switch_channel_set_originatee_caller_profile(channel, cloned_profile);
 				
                 switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);

Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
==============================================================================
--- freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	(original)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	Tue Oct  2 12:38:15 2007
@@ -36,8 +36,8 @@
 static struct {
 	char *cred;
 	char *url;
-	char *logDir;
-	char *errLogDir;
+	char *log_dir;
+	char *err_log_dir;
 	uint32_t delay;
 	uint32_t retries;
 	uint32_t shutdown;
@@ -75,7 +75,7 @@
 	if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
 
 		/* build the XML */
-		if(!(xml_text = switch_mprintf("<?xml version=\"1.0\"?>\n%s",switch_xml_toxml(cdr)) )) {
+		if(!(xml_text = switch_xml_toxml(cdr))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 			goto error;
 		}
@@ -84,11 +84,11 @@
 		/* all previous functionality is retained */
 
 		if (!(logdir = switch_channel_get_variable(channel, "xml_cdr_base"))) {
-			logdir = globals.logDir;
+			logdir = globals.log_dir;
 		}
 
 		if(!switch_strlen_zero(logdir)) {
-			if ((path = switch_mprintf("%s/xml_cdr/%s.cdr.xml", logdir, switch_core_session_get_uuid(session)))) {
+			if ((path = switch_mprintf("%s/%s.cdr.xml", logdir, switch_core_session_get_uuid(session)))) {
 				if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
 					int wrote;
 					wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -101,7 +101,7 @@
 #else
 					strerror_r(errno, ebuf, sizeof(ebuf));
 #endif
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error![%s]\n", ebuf);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n", path, ebuf);
 				}
 				switch_safe_free(path);
 			}
@@ -163,7 +163,7 @@
 			/* if we are here the web post failed for some reason */
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
 
-			if ((path = switch_mprintf("%s/%s.cdr.xml", globals.errLogDir, switch_core_session_get_uuid(session)))) {
+			if ((path = switch_mprintf("%s/%s.cdr.xml", globals.err_log_dir, switch_core_session_get_uuid(session)))) {
 				if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
 					int wrote;
 					wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -229,6 +229,9 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		return SWITCH_STATUS_TERM;
 	}
+
+	globals.log_dir = switch_mprintf("%s/xml_cdr", SWITCH_GLOBAL_dirs.log_dir);
+	globals.err_log_dir = strdup(globals.log_dir);
 	
 	if ((settings = switch_xml_child(cfg, "settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -243,14 +246,20 @@
 				globals.delay = (uint32_t) atoi(val);
 			} else if (!strcasecmp(var, "retries")) {
 				globals.retries = (uint32_t) atoi(val);
-			} else if (!strcasecmp(var, "logDir")) {
-				if (switch_strlen_zero(val)) {
-					globals.logDir = SWITCH_GLOBAL_dirs.log_dir;
+			} else if (!strcasecmp(var, "log-dir")) {
+				switch_safe_free(globals.log_dir);
+				if (switch_is_file_path(val)) {
+					globals.log_dir = strdup(val);
+				} else {
+					globals.log_dir = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.log_dir, val);
+				}
+			} else if (!strcasecmp(var, "err-log-dir")) {
+				switch_safe_free(globals.err_log_dir);
+				if (switch_is_file_path(val)) {
+					globals.err_log_dir = strdup(val);
 				} else {
-					globals.logDir = strdup(val);
+					globals.err_log_dir = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.log_dir, val);
 				}
-			} else if (!strcasecmp(var, "errLogDir")) {
-				globals.errLogDir = strdup(val);
 			}
 
 		}
@@ -265,17 +274,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "retries set but delay 0 setting to 5000ms\n");
 		globals.delay = 5000;
 	}
-
-	if(!switch_strlen_zero(globals.url) && switch_strlen_zero(globals.errLogDir)) {
-		if ((globals.errLogDir = switch_mprintf("%s/xml_cdr", SWITCH_GLOBAL_dirs.log_dir))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
-			status = SWITCH_STATUS_FALSE;
-			goto done;
-		}
-	}
-
-
- done:
+	
 	switch_xml_free(xml);
 	return status;
 }

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Tue Oct  2 12:38:15 2007
@@ -886,6 +886,7 @@
 		caller_profile->next = channel->caller_profile->originator_caller_profile;
 		channel->caller_profile->originator_caller_profile = caller_profile;
 	}
+	assert(channel->caller_profile->originator_caller_profile->next != channel->caller_profile->originator_caller_profile);
 	switch_mutex_unlock(channel->profile_mutex);
 }
 
@@ -898,6 +899,7 @@
 		caller_profile->next = channel->caller_profile->originatee_caller_profile;
 		channel->caller_profile->originatee_caller_profile = caller_profile;
 	}
+	assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
 	switch_mutex_unlock(channel->profile_mutex);
 		
 }

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Oct  2 12:38:15 2007
@@ -1275,15 +1275,15 @@
 	}
 	switch_xml_set_txt(param, caller_profile->chan_name);
 
-	return 0;
+	return off;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr)
 {
 	switch_channel_t *channel;
 	switch_caller_profile_t *caller_profile;
-	switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag, 
-		x_application, x_callflow, x_inner_extension, x_apps;
+	switch_xml_t variable, variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag, 
+		x_application, x_callflow, x_inner_extension, x_apps, x_o;
 	switch_app_log_t *app_log;
 	switch_event_header_t *hi;
 	char tmp[512];
@@ -1343,6 +1343,7 @@
 
 	while (caller_profile) {
 		int cf_off = 0;
+		int cp_off = 0;
 
 		if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
 			goto error;
@@ -1356,6 +1357,7 @@
 			if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
 				goto error;
 			}
+			
 			switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name);
 			switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
 			if (caller_profile->caller_extension->current_application) {
@@ -1413,23 +1415,39 @@
 		}
 
 
-		if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
+		if (!(x_main_cp = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
 			goto error;
 		}
-		set_profile_data(x_caller_profile, caller_profile, 0);
+
+		cp_off += set_profile_data(x_main_cp, caller_profile, 0);
 
 		if (caller_profile->originator_caller_profile) {
-			if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "originator_caller_profile", cf_off++))) {
+			switch_caller_profile_t *cp = NULL;
+			int off = 0;
+			if (!(x_o = switch_xml_add_child_d(x_main_cp, "originator", cp_off++))) {
 				goto error;
 			}
-			set_profile_data(x_caller_profile, caller_profile->originator_caller_profile, 0);
+
+			for (cp = caller_profile->originator_caller_profile; cp; cp = cp->next) {
+				if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originator_caller_profile", off++))) {
+					goto error;
+				}
+				set_profile_data(x_caller_profile, cp, 0);
+			}
 		}
 
 		if (caller_profile->originatee_caller_profile) {
-			if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "originatee_caller_profile", cf_off++))) {
+			switch_caller_profile_t *cp = NULL;
+			int off = 0;
+			if (!(x_o = switch_xml_add_child_d(x_main_cp, "originatee", cp_off++))) {
 				goto error;
 			}
-			set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0);
+			for (cp = caller_profile->originatee_caller_profile; cp; cp = cp->next) {
+				if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originatee_caller_profile", off++))) {
+					goto error;
+				}
+				set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0);
+			}
 		}
 
 

Modified: freeswitch/trunk/src/switch_xml.c
==============================================================================
--- freeswitch/trunk/src/switch_xml.c	(original)
+++ freeswitch/trunk/src/switch_xml.c	Tue Oct  2 12:38:15 2007
@@ -1523,8 +1523,9 @@
 	s = malloc(max);
 	assert(s != NULL);
 	memset(s, 0, max);
-	
+	len = sprintf(s, "<?xml version=\"1.0\"?>\n");
 
+	
 	if (!xml || !xml->name) {
 		if (!(r = realloc(s, len + 1))) {
 			abort();



More information about the Freeswitch-svn mailing list