[Freeswitch-dev] uuid_bridge issue

Sebastian Replanski sreplans at hotmail.com
Sat Jun 30 19:29:47 EDT 2007


I forgot to change the C code bellow to poin to /tmp/hold.wav (see corrected
bellow under //*FIXED label). but you clever coders would have figure it out
anyhow...

-----Original Message-----
From: freeswitch-dev-bounces at lists.freeswitch.org
[mailto:freeswitch-dev-bounces at lists.freeswitch.org] On Behalf Of Sebastian
Replanski
Sent: Saturday, June 30, 2007 7:21 PM
To: freeswitch-dev at lists.freeswitch.org
Subject: [Freeswitch-dev] uuid_bridge issue

Hi guys,

I've been having a uuid_bridge issue, its very easy to replicate the problem
(sample C module included).

All the C code does is play /tmp/hold.wav file on a loop.  I use sofia and a
voip provider , don't know if it has anything to do with it.

All you have to do to make the bug occur is have 3 calls like these and note
the uuids.  Then just uuid_bridge any 2.  I tried issuing "api break"
commands to stop the music, or park the calls. Same problem.  The call
bridge is unusable after the bug occurs.


1)       originate sofia/gateway/asterlink.com/12125551234 &stpAgent();
2)       originate sofia/gateway/asterlink.com/12125558888 &stpAgent();
3)       originate sofia/gateway/asterlink.com/12125559999 &stpAgent();
 

mod_stpAgent included:
/* 
 * FreeSWITCH Modular Media Switching Software Library / Soft-Switch
Application
 * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
 *
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License
Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is FreeSWITCH Modular Media Switching Software Library
/ Soft-Switch Application
 *
 * The Initial Developer of the Original Code is
 * Anthony Minessale II <anthmct at yahoo.com>
 * Portions created by the Initial Developer are Copyright (C)
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 * 
 * Anthony Minessale II <anthmct at yahoo.com>
 * Neal Horman <neal at wanlink dot com>
 *
 *
 * mod_skel.c -- Framework Demo Module
 *
 */
#include <switch.h>

//SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_stpAgent_shutdown);
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_stpAgent_runtime);

SWITCH_MODULE_LOAD_FUNCTION(mod_stpAgent_load);
SWITCH_MODULE_DEFINITION(mod_stpAgent, mod_stpAgent_load, NULL, NULL);


/*
  dtmf handler function you can hook up to be executed when a digit is
dialed during playback 
   if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
*/
static switch_status_t on_dtmf(switch_core_session_t *session, void *input,
switch_input_type_t itype, void *buf, unsigned int buflen)
{
	switch (itype) {
	case SWITCH_INPUT_TYPE_DTMF: {
		char *dtmf = (char *) input;
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Digits %s\n", dtmf);
	
		switch_copy_string((char *)buf, dtmf, buflen);
		return SWITCH_STATUS_BREAK;
	}
		break;
	default:
		break;
	}
	return SWITCH_STATUS_SUCCESS;
}

static int wait_for_answer(switch_channel_t *channel)
{
    switch_time_t started;
    unsigned int elapsed;
    switch_time_t timeout = 60000000; //2 mins

    assert(channel != NULL);

    started = switch_time_now();


    for (;;) {
        if (((elapsed = (unsigned int) ((switch_time_now() - started) /
1000)) > (switch_time_t) timeout)
            || switch_channel_get_state(channel) >= CS_HANGUP) {
            	printf("Timeout on wait_for_answer.\n");
            	return 0;
            break;
        }

        if (switch_channel_ready(channel) &&
switch_channel_test_flag(channel, CF_ANSWERED)) {
            return 1;
            break;
        }

        switch_yield(1000);
    }

    return 1;
}

//utility functions
switch_status_t playFile(switch_core_session_t *session, char*
sound_dir,char* file,char* buf){
		switch_ivr_sleep (session,250);
		//file could be a single path or multiple like:
stp-live/u_bcst_inf_how_01.gsm,stp-live/u_bcst_inf_how_02.gsm,stp-live/u_bcs
t_inf_how_03.gsm
		char *str=strdup(file);
		char *p=NULL;
		switch_status_t s=SWITCH_STATUS_SUCCESS;
		while((p = strsep(&str,",")) != NULL){
           	char* soundName=malloc(strlen(p)+strlen(sound_dir)+3);
			sprintf(soundName,"%s/%s",sound_dir,p);
			switch_input_args_t args = { 0 };
			args.input_callback = on_dtmf;
            args.buf = buf;
            args.buflen = sizeof(buf);
			memset(buf, 0, sizeof(buf));
			s=switch_ivr_play_file(session, NULL, soundName,
&args);
			if (soundName) free(soundName); soundName=NULL;
		}
		if (str) free(str);
		str=NULL;
		return s;
	}

	void logMsg(char* call_id,char* txt){
		//switch_log_printf(SWITCH_CHANNEL_LOG,
SWITCH_LOG_NOTICE,"[mod_stp_userAgent]:%s",txt);
		if (txt==NULL || call_id==NULL) return;
		printf("[mod_stp_userAgent][%s]:%s\n",call_id,txt);
	}

	void logMsg2(char* call_id,char* txt1,char* txt2){
		
		if (txt1==NULL || txt2==NULL || call_id==NULL) return;
		printf("[mod_stp_userAgent][%s]:%s%s\n",call_id,txt1,txt2);
	}

	

SWITCH_STANDARD_APP(stpAgent_function){
	//passed in *data
///	char* call_id=NULL; 
///	char *sound_dir=NULL;
///	char *user_recordings_dir=NULL;
///	char *ammt=NULL;
///	char *appStr=NULL;
///	int app=0; // App is the ivr script we are running. 0= User,
1=Merchant, 2=UserMatch
///	char *call_id_outb=NULL;

	char buf[10] = "";
	
	
	switch_channel_t *channel;
	//switch_status_t status = SWITCH_STATUS_SUCCESS;
	//switch_codec_t *codec;
	
	channel = switch_core_session_get_channel(session);
    assert(channel != NULL);
	
	//wait till the called party answers
	if (wait_for_answer(channel)==0) 
			goto cleanup; //no answer

	//wait 1 secs
	switch_ivr_sleep (session,500);
	
	switch_channel_answer(channel);

	while (switch_channel_ready(channel)){
	//*FIXED
playFile(session,"/tmp/","hold.wav",buf);
	}
	//goto cleanup;
	
	cleanup: 
///		logMsg(app == 1 ? call_id_outb : call_id,"EXITING APP");

///		logMsg(app == 1 ? call_id_outb : call_id,"*** CLEANUP
*****");
//	if (args) free(args);
//		args=NULL;
	printf("stpAgent done!\n");

		
}

#if 0
static switch_loadable_module_interface_t stpAgent_module_interface = {
	/*.module_name */ modname,
	/*.endpoint_interface */ NULL,
	/*.timer_interface */ NULL,
	/*.dialplan_interface */ NULL,
	/*.codec_interface */ NULL,
	/*.application_interface */ NULL,
	/*.api_interface */ NULL,
	/*.file_interface */ NULL,
	/*.speech_interface */ NULL,
	/*.directory_interface */ NULL
};
#endif
SWITCH_MODULE_LOAD_FUNCTION(mod_stpAgent_load)
{
    
	switch_application_interface_t *app_interface;

	/* connect my internal structure to the blank pointer passed to me
*/
	*module_interface =
switch_loadable_module_create_module_interface(pool, modname);
	SWITCH_ADD_APP(app_interface, "stpAgent", NULL, NULL,
stpAgent_function, NULL, SAF_NONE);

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "stpAgent
loaded!\n");

	/* indicate that the module should continue to be loaded */
	return SWITCH_STATUS_SUCCESS;

}


	
	
/*
  Called when the system shuts down
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_stpAgent_shutdown);
{
	return SWITCH_STATUS_SUCCESS;
}
*/

/*
  If it exists, this is called in it's own thread when the module-load
completes
  If it returns anything but SWITCH_STATUS_TERM it will be called again
automaticly
SWITCH_MODULE_RUNTIME_FUNCTION(mod_stpAgent_runtime);
{
	while(looping)
	{
		switch_yield(1000);
	}
	return SWITCH_STATUS_TERM;
}
*/

/* For Emacs:
 * Local Variables:
 * mode:c
 * indent-tabs-mode:nil
 * tab-width:4
 * c-basic-offset:4
 * End:
 * For VIM:
 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
 */


_______________________________________________
Freeswitch-dev mailing list
Freeswitch-dev at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
http://www.freeswitch.org




More information about the Freeswitch-dev mailing list