Ejemplo n.º 1
0
SWITCH_DECLARE(void) CoreSession::hangup(const char *cause)
{
	this_check_void();
	sanity_check_noreturn;	
    switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "CoreSession::hangup\n");
	this->begin_allow_threads();
    switch_channel_hangup(channel, switch_channel_str2cause(cause));
	this->end_allow_threads();
}
Ejemplo n.º 2
0
SWITCH_DECLARE(void) switch_core_session_reporting_state(switch_core_session_t *session)
{
	switch_channel_state_t state = switch_channel_get_state(session->channel), midstate = state;
	const switch_endpoint_interface_t *endpoint_interface;
	const switch_state_handler_table_t *driver_state_handler = NULL;
	const switch_state_handler_table_t *application_state_handler = NULL;
	int proceed = 1;
	int global_proceed = 1;
	int do_extra_handlers = 1;
	int silly = 0;
	int index = 0;
	const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE);
	const char *skip_var = switch_channel_get_variable(session->channel, SWITCH_SKIP_CDR_CAUSES_VARIABLE);
	const char *hook_var;
	int use_session = 0;
	switch_event_t *event;
	switch_call_cause_t cause = switch_channel_get_cause(session->channel);

	if (switch_channel_test_flag(session->channel, CF_REPORTING)) {
		return;
	}

	switch_channel_set_flag(session->channel, CF_REPORTING);

	switch_assert(session != NULL);

	endpoint_interface = session->endpoint_interface;
	switch_assert(endpoint_interface != NULL);

	driver_state_handler = endpoint_interface->state_handler;
	switch_assert(driver_state_handler != NULL);

	if (!zstr(var)) {
		if (!strcasecmp(var, "a_only")) {
			if (switch_channel_get_originator_caller_profile(session->channel)) {
				do_extra_handlers = 0;
			}
		} else if (!strcasecmp(var, "b_only")) {
			if (switch_channel_get_originatee_caller_profile(session->channel)) {
				do_extra_handlers = 0;
			}
		} else if (!switch_true(var)) {
			do_extra_handlers = 0;
		}
	}


	if (!zstr(skip_var)) {
		int x, ttl = 0;
		char *list[128] = { 0 };
		char *dup = switch_core_session_strdup(session, skip_var);

		ttl = switch_split(dup, '|', list);

		for(x = 0; x < ttl; x++) {
			if (switch_channel_str2cause(list[x]) == cause) {
				do_extra_handlers = 0;
				break;
			}
		}
	}

	if (switch_channel_test_flag(session->channel, CF_NO_CDR)) {
		do_extra_handlers = 0;
	}


	STATE_MACRO(reporting, "REPORTING");

	if ((hook_var = switch_channel_get_variable(session->channel, SWITCH_API_REPORTING_HOOK_VARIABLE))) {

		if (switch_true(switch_channel_get_variable(session->channel, SWITCH_SESSION_IN_HANGUP_HOOK_VARIABLE))) {
			use_session = 1;
		}

		api_hook(session, hook_var, use_session);
	}

	if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE) == SWITCH_STATUS_SUCCESS) {
		switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", switch_channel_cause2str(cause));
		switch_channel_event_set_data(session->channel, event);
		if (switch_true(switch_channel_get_variable(session->channel, "hangup_complete_with_xml"))) {
			switch_xml_t cdr = NULL;
			char *xml_cdr_text;
			
			if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
				xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "CDR-Attached", "xml");
				switch_event_add_body(event, "%s", xml_cdr_text);
				switch_xml_free(cdr);
				switch_safe_free(xml_cdr_text);
			}
		}
		switch_event_fire(&event);
	}



	return;
}
Ejemplo n.º 3
0
void fs_channel_hangup(switch_core_session_t *session, char *cause)
{
	switch_channel_t *channel = switch_core_session_get_channel(session);
	switch_channel_hangup(channel, switch_channel_str2cause(cause));
}
Ejemplo n.º 4
0
static switch_status_t fire_cdr_event(switch_channel_t *channel){
	
	switch_status_t status = SWITCH_STATUS_FALSE;
	switch_event_t *event = NULL;

	const char *desc = NULL;
	const char *caller_id_name = NULL;
	const char *caller_id_number = NULL;

	const char *destination_number = NULL;
	const char *dialed_extension = NULL;

	const char *context = NULL;
	const char *context_extension = NULL;

	const char *start_epoch = NULL;
	const char *answer_epoch = NULL;
	const char *end_epoch = NULL;

	const char *start_stamp = NULL;
	const char *answer_stamp = NULL;
	const char *end_stamp = NULL;
	const char *duration = NULL;
	const char *billsec = NULL;
	
	const char *originate_disposition = NULL;
	const char *hangup_cause = NULL;
	const char *uuid = NULL;
	const char *bleg_uuid = NULL;

	const char *read_codec = NULL;
	const char *write_codec = NULL;

	if(!channel){
		return status;
	}
	get_var(desc);
	get_var(caller_id_name);
	get_var(caller_id_number);
	//caller_id_name = switch_channel_get_variable(channel,"caller_id_name");
	//caller_id_number = switch_channel_get_variable(channel,"caller_id_number");
	get_var(destination_number);
	get_var(dialed_extension);
	get_var(context);
	get_var(context_extension);
	get_var(start_epoch);
	get_var(answer_epoch);
	get_var(end_epoch);
	get_var(start_stamp);
	get_var(answer_stamp);
	get_var(end_stamp);
	get_var(duration);
	get_var(billsec);
	get_var(hangup_cause);
	get_var(originate_disposition);
	get_var(uuid);
	get_var(bleg_uuid);
	get_var(read_codec);
	get_var(write_codec);

	
    if(!caller_id_number || !destination_number ||
	   !start_epoch  || !start_stamp || !uuid){
		return status;
	}

	if(switch_event_create_subclass(&event,SWITCH_EVENT_CUSTOM,CDR_EVENT) == SWITCH_STATUS_SUCCESS){
		event_add_header(caller_id_number);
		if(desc){
			caller_id_name = desc;
		}
		//if(!caller_id_name){
		//caller_id_name = caller_id_number;
		//}
		if(caller_id_name){
			event_add_header(caller_id_name);
		}

		event_add_header(destination_number);
		if(dialed_extension && strstr(dialed_extension,"$1") == NULL){
			event_add_header(dialed_extension);//dialed_extension = destination_number;
		}
		
		if(context){
			event_add_header(context);
		}
		if(context_extension){
			event_add_header(context_extension);
		}
		event_add_header(start_epoch);
		if(switch_strlen_zero(end_epoch)){
			end_epoch = start_epoch;
		}
		event_add_header(end_epoch);

		if(switch_strlen_zero(answer_epoch)){
			answer_epoch = end_epoch;
		}
		event_add_header(answer_epoch);

		
		event_add_header(start_stamp);

		if(switch_strlen_zero(end_stamp)){
			end_stamp = start_stamp;
		}
		event_add_header(end_stamp);

		if(switch_strlen_zero(answer_stamp)){
			answer_stamp = end_stamp;
		}
		event_add_header(answer_stamp);
		
		if(switch_strlen_zero(duration)){
			duration = "0";
		}
		event_add_header(duration);
		if(switch_strlen_zero(billsec)){
			billsec = "0";
		}
		event_add_header(billsec);
		//if(originate_disposition){
		//event_add_header(originate_disposition);
		//}

		if(originate_disposition){

			if(hangup_cause){
				switch_call_cause_t originate = switch_channel_str2cause(originate_disposition);
				switch_call_cause_t hangup = switch_channel_str2cause(hangup_cause);
				if((hangup == SWITCH_CAUSE_NORMAL_CLEARING || hangup == SWITCH_CAUSE_NONE)
				   && (originate != SWITCH_CAUSE_NORMAL_CLEARING)
				   && (originate != SWITCH_CAUSE_NONE)){
					hangup_cause = originate_disposition;
				}
			}
			else{
				hangup_cause = originate_disposition;
			}
		}
		if(!hangup_cause){
			hangup_cause = "NONE";
		}

		if(hangup_cause){
			event_add_header(hangup_cause);
		}

		event_add_header(uuid);
		if(bleg_uuid){
			event_add_header(bleg_uuid);
		}
		if(read_codec){
			event_add_header(read_codec);
		}
		if(write_codec){
			event_add_header(write_codec);
		}
    
		status = switch_event_fire(&event);
		//switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_DEBUG,"fire cdr event for %s\n",caller_id_number); 
	}

	return status;
}