[Freeswitch-branches] [commit] r3509 - freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr

Freeswitch SVN mishehu at freeswitch.org
Fri Dec 1 13:46:43 EST 2006


Author: mishehu
Date: Fri Dec  1 13:46:41 2006
New Revision: 3509

Modified:
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/README
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.h
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h
   freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp

Log:
Fixed mod_cdr for changes to switch_channel_t effected by anthm today.  Also added in the ability to manually pause and unpause the popping of BaseCDR objects from the queue.

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/README
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/README	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/README	Fri Dec  1 13:46:41 2006
@@ -85,9 +85,14 @@
 Q: What would an example configuration look like?
 A: Here is an excerpt from the freeswitch XML configuration file:
 
+Q: What about one-legged calls, such as calls to voicemail or playback?
+A:  With the current changes in place (as of 2006-12-01), the value of originated will always be set to 0, but destuuid will always be blank.  This will provide you with a method to bill for specific applications and/or calls if you so desire.
+				
 Q: What happened to the ani2 field?
 A: Oops, you caught us.  The real name for is it aniii.  You will need to update any database schemas or external handlers for this change.
 
+Example configuration:
+		
 	<configuration name="mod_cdr.conf" description="CDR Configuration">
 		<pddcdr>
 			<param name="path" value="/work/temp/pddcdr"/>

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.cpp	Fri Dec  1 13:46:41 2006
@@ -76,13 +76,17 @@
 		memset(aniii,0,80);
 		memset(lastapp,0,80);
 		memset(lastdata,0,255);
-
+		
+		switch_channel_timetable_t *timetable;
+		
 		coresession = newchannel->session;
-		callstartdate= newchannel->timetable->created;
-		callanswerdate = newchannel->timetable->answered;
-		callenddate = newchannel->timetable->hungup;
+		timetable = switch_channel_get_timetable(newchannel->channel->caller_profile);
+		callstartdate= timetable->created;
+		callanswerdate = timetable->answered;
+		callenddate = timetable->hungup;
 	
-		if (newchannel->callerprofile) {
+		if (newchannel->callerprofile)
+		{
 			if(newchannel->callerprofile->caller_id_name != 0)
 			{
 				strncpy(clid,newchannel->callerprofile->caller_id_name,strlen(newchannel->callerprofile->caller_id_name));
@@ -104,34 +108,39 @@
 			if(newchannel->callerprofile->network_addr != 0)
 				strncpy(network_addr,newchannel->callerprofile->network_addr,strlen(newchannel->callerprofile->network_addr));
 		}
-
-		originated = newchannel->originate;
-	
-		if(newchannel->originateprofile && newchannel->originateprofile->uuid != 0)
-			strncpy(destuuid,newchannel->originateprofile->uuid,strlen(newchannel->originateprofile->uuid));
-	
-		// We still need to check if this is originated or not
-		if(originated == 0)
+		
+		switch_caller_profile_t *originateprofile = switch_channel_get_originator_caller_profile(newchannel->channel->callerprofile);
+		
+		// Were we the receiver of the call?
+		if(originateprofile)
 		{
-			if (newchannel->callerprofile) {
-				if(newchannel->callerprofile->destination_number != 0)
+			originated = 0;
+			if(newchannel->originateprofile->uuid != 0)
+				strncpy(destuuid,originateprofile->uuid,strlen(originateprofile->uuid));
+			if(newchannel->callerprofile)
+			{
+				if(newchannel->callerprofile->destination_number)
 					strncpy(src,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number));
 				if(newchannel->callerprofile->caller_id_number != 0)
 					strncpy(dst,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number));
 			}
-			if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
-				strncpy(dstchannel,newchannel->originateprofile->chan_name,strlen(newchannel->originateprofile->chan_name));
 		}
 		else
 		{
-			if (newchannel->callerprofile) {
-				if(newchannel->callerprofile->caller_id_number != 0)
-					strncpy(src,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number));
-				if(newchannel->callerprofile->destination_number != 0)
-					strncpy(dst,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number));
+			originateprofile = switch_channel_get_originatee_profile(newchannel->channel->callerprofile);
+			// Or were we maybe we were the caller?
+			if(originateprofile)
+			{
+				originated = 1;
+				if (newchannel->callerprofile) {
+					if(newchannel->callerprofile->caller_id_number != 0)
+						strncpy(src,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number));
+					if(newchannel->callerprofile->destination_number != 0)
+						strncpy(dst,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number));
+				}
+				if(originateprofile->chan_name != 0)
+					strncpy(dstchannel,newchannel->originateprofile->chan_name,strlen(newchannel->originateprofile->chan_name));
 			}
-			if(newchannel->originateprofile && newchannel->originateprofile->chan_name != 0)
-				strncpy(dstchannel,newchannel->originateprofile->chan_name,strlen(newchannel->originateprofile->chan_name));
 		}
 		
 		strncpy(myuuid,newchannel->callerprofile->uuid,strlen(newchannel->callerprofile->uuid));
@@ -140,7 +149,7 @@
 		if(switch_channel_test_flag(newchannel->channel,CF_ANSWERED))
 		{
 			disposition=1;
-			billusec = newchannel->timetable->hungup - newchannel->timetable->answered;
+			billusec = timetable->hungup - timetable->answered;
 		}
 		else
 		{

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.h	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/basecdr.h	Fri Dec  1 13:46:41 2006
@@ -50,11 +50,11 @@
 {
 	switch_core_session_t *session;
 	switch_channel_t *channel;
-	switch_channel_timetable_t *timetable;
+	//switch_channel_timetable_t *timetable;
 	switch_caller_extension_t *callerextension;
 	switch_caller_profile_t *callerprofile;
-	switch_caller_profile_t *originateprofile;
-	bool originate;
+	//switch_caller_profile_t *originateprofile;
+	//bool originate;
 };
 
 enum switch_mod_cdr_sql_types_t { CDR_INTEGER,CDR_STRING,CDR_DECIMAL,CDR_DOUBLE,CDR_TINY };

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.cpp	Fri Dec  1 13:46:41 2006
@@ -45,6 +45,8 @@
 	// Create the APR threadsafe queue, though I don't know if this is the current memory pool.
 	switch_queue_create(&cdrqueue,5224288, module_pool);
 	
+	queue_paused = 0;
+	
 	strcpy(configfile,"mod_cdr.conf");
 	
 	switch_mod_cdr_newchannel_t *newchannel; // = new switch_mod_cdr_newchannel_t;
@@ -90,8 +92,14 @@
 	switch_console_printf(SWITCH_CHANNEL_LOG,"mod_cdr shutdown gracefully.");
 }
 
-void CDRContainer::reload()
+void CDRContainer::reload(switch_stream_handle_t *stream)
 {
+	// The queue can't be paused otherwise it will never be able to reload safely.
+	if(queue_paused)
+	{
+		stream->write_function(stream,"The queue is currently paused, resuming it.\n");
+		queue_resume(stream);
+	}
 	// Something tells me I still need to figure out what to do if there are items still in queue after reload that are no longer active in the configuration.
 	switch_queue_isempty(cdrqueue); // Waits for the queue to be empty
 	
@@ -138,6 +146,31 @@
 	switch_console_printf(SWITCH_CHANNEL_LOG,"mod_cdr configuration reloaded.");
 }
 
+void CDRContainer::queue_pause(switch_stream_handle_t *stream)
+{
+	if(queue_paused)
+		stream->write_function(stream,"Queue is already paused.\n");
+	else
+	{
+		queue_paused = 1;
+		switch_queue_blockpop(cdrqueue);
+		stream->write_function(stream,"CDR queue is now paused.  Beware that this can waste resources the longer you keep it paused.\n");
+	}
+}
+
+void CDRContainer::queue_resume(switch_stream_handle_t *stream)
+{
+	if(!queue_paused)
+		stream->write_function(stream,"Queue is currently running, no need to resume it.\n");
+	else
+	{
+		queue_paused = 0;
+		switch_queue_unblockpop(cdrqueue);
+		stream->write_function(stream,"CDR queue has now resumed processing CDR records.\n");
+	}
+
+}
+
 void CDRContainer::add_cdr(switch_core_session_t *session)
 {
 	switch_mod_cdr_newchannel_t *newchannel = new switch_mod_cdr_newchannel_t;
@@ -146,60 +179,31 @@
 	newchannel->channel = switch_core_session_get_channel(session);
 	assert(newchannel->channel != 0);
 
+	// Need to fix this up a bit so that it reflects a change to switch_caller_profile_t
+	// switch_channel_t will contain caller_profile, and caller_profile will contain
+	// the originator and originatee profile
 	newchannel->session = session;
-	newchannel->timetable = switch_channel_get_timetable(newchannel->channel);
+	//newchannel->timetable = switch_channel_get_timetable(newchannel->channel);
 	newchannel->callerextension = switch_channel_get_caller_extension(newchannel->channel);
 	newchannel->callerprofile = switch_channel_get_caller_profile(newchannel->channel);
-	newchannel->originateprofile = switch_channel_get_originator_caller_profile(newchannel->channel);	
+	//newchannel->originateprofile = switch_channel_get_originator_caller_profile(newchannel->channel);	
 	
 	BaseRegistry& registry(BaseRegistry::get());
 	for(BaseRegistry::iterator it = registry.active_begin(); it != registry.active_end(); ++it)
 	{
-		/* 
-		   First time it might be originator profile, or originatee.  Second and 
-		   after is always going to be originatee profile.
-		*/
-		
 		basecdr_creator func = *it;
 		
-		if(newchannel->originateprofile != 0 )
+		do 
 		{
 			BaseCDR* newloggerobject = func(newchannel);
 			switch_console_printf(SWITCH_CHANNEL_LOG,"Adding a new logger object to the queue.\n");
 			switch_queue_push(cdrqueue,newloggerobject);
-			
-			if(newchannel->timetable->next != 0)
-			{
-				newchannel->originateprofile = switch_channel_get_originatee_caller_profile(newchannel->channel);
-				newchannel->originate = 1;
-			}	
-		}
-		else
-		{
-			newchannel->originateprofile = switch_channel_get_originatee_caller_profile(newchannel->channel);
-			if(newchannel->originateprofile != 0)
-			{
-				newchannel->originate = 1;
-			
-				BaseCDR* newloggerobject = func(newchannel);
-				switch_console_printf(SWITCH_CHANNEL_LOG,"Adding a new logger object to the queue.\n");
-				switch_queue_push(cdrqueue,newloggerobject);
-			}
-		}
-		
-		while (newchannel->timetable->next != 0 && newchannel->callerextension->next != 0 && newchannel->callerprofile->next != 0 && newchannel->originateprofile->next != 0 ) 
-		{			
-			newchannel->timetable = newchannel->timetable->next;
 			newchannel->callerprofile = newchannel->callerprofile->next;
 			newchannel->callerextension = newchannel->callerextension->next;
-			newchannel->originateprofile = newchannel->originateprofile->next;
-			
-			BaseCDR* newloggerobject = func(newchannel);
-			switch_console_printf(SWITCH_CHANNEL_LOG,"Adding a new logger object to the queue.\n");
-			switch_queue_push(cdrqueue,newloggerobject);
-		}
+		} while (newchannel->callerprofile && newchannel->callerextension);
+		
 	}
-	
+		
 	delete newchannel;
 }
 

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/cdrcontainer.h	Fri Dec  1 13:46:41 2006
@@ -58,13 +58,16 @@
 		~CDRContainer();
 		void add_cdr(switch_core_session_t *session);
 		void process_records();
-		void reload();
+		void reload(switch_stream_handle_t *stream);
+		void queue_pause(switch_stream_handle_t *stream);
+		void queue_resume(switch_stream_handle_t *stream);
 	protected:
 	private:
 		switch_xml_t cfg, xml, settings, param;
 		switch_queue_t *cdrqueue;
 		std::string tempfilepath;
 		char configfile[13];
+		bool queue_paused;
 };
 
 #ifdef __cplusplus

Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp	(original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/mod_cdr.cpp	Fri Dec  1 13:46:41 2006
@@ -64,6 +64,22 @@
 	/*.desc */ "Reload mod_cdr's configuration",
 	/*.function */ modcdr_reload,
 	/*.syntax */ "modcdr_reload",
+	/*.next */ &modcdr_queue_pause
+};
+
+static switch_api_interface_t modcdr_queue_pause = {
+	/*.interface_name */ "modcdr_queue_pause",
+	/*.desc */ "Manually pauses the popping of objects from the queue. (DANGER: Can suck your memory away rather quickly.)",
+	/*.function */ modcdr_queue_pause,
+	/*.syntax */ "modcdr_queue_pause",
+	/*.next */ &modcdr_queue_resume
+};
+
+static switch_api_interface_t modcdr_queue_resume = {
+	/*.interface_name */ "modcdr_queue_pause",
+	/*.desc */ "Manually resumes the popping of objects from the queue.",
+	/*.function */ modcdr_queue_resume,
+	/*.syntax */ "modcdr_queue_resume",
 	/*.next */ 0
 };
 
@@ -117,9 +133,21 @@
 static switch_status_t modcdr_reload(char *dest=0, switch_core_session_t *isession=0, switch_stream_handle_t *stream=0)
 {
 	switch_thread_rwlock_wrlock(cdr_rwlock);
-	newcdrcontainer->reload();
+	newcdrcontainer->reload(stream);
 	switch_thread_rwlock_unlock(cdr_rwlock);
 	stream->write_function(stream, "XML Reloaded and mod_cdr reloaded.\n");
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t modcdr_queue_pause(char *dest=0, switch_core_session_t *isession=0, switch_stream_handle_t *stream=0)
+{
+	newcdrcontainer->queue_pause(stream);
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t modcdr_queue_resume(char *dest=0, switch_core_session_t *isession=0, switch_stream_handle_t *stream=0)
+{
+	newcdrcontainer->queue_resume(stream);
 	return SWITCH_STATUS_SUCCESS;
 }
 



More information about the Freeswitch-branches mailing list