Esempio n. 1
0
/**
 * Forward CPA signal to client
 */
static void rayo_cpa_detector_event(const char *jid, void *user_data)
{
    struct rayo_actor *component = RAYO_LOCATE(jid);
    if (component) {
        if (CPA_COMPONENT(component)->ready) {
            switch_event_t *event = (switch_event_t *)user_data;
            const char *signal_type = switch_event_get_header(event, "signal-type");
            struct cpa_signal *cpa_signal = switch_core_hash_find(CPA_COMPONENT(component)->signals, signal_type);
            switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_COMPONENT(component)->parent->id), SWITCH_LOG_DEBUG, "Handling CPA event\n");
            if (cpa_signal) {
                const char *value = switch_event_get_header(event, "value");
                const char *duration = switch_event_get_header(event, "duration");
                if (cpa_signal->terminate) {
                    iks *complete_event;
                    iks *signal_xml;

                    stop_cpa_detectors(CPA_COMPONENT(component));

                    /* send complete event to client */
                    complete_event = rayo_component_create_complete_event(RAYO_COMPONENT(component), "signal", RAYO_CPA_NS);
                    signal_xml = iks_find(complete_event, "complete");
                    signal_xml = iks_find(signal_xml, "signal");
                    iks_insert_attrib(signal_xml, "type", signal_type);
                    if (!zstr(value)) {
                        iks_insert_attrib(signal_xml, "value", value);
                    }
                    if (!zstr(duration)) {
                        iks_insert_attrib(signal_xml, "duration", duration);
                    }
                    rayo_component_send_complete_event(RAYO_COMPONENT(component), complete_event);
                } else {
                    /* send event to client */
                    iks *signal_event = iks_new_presence("signal", RAYO_CPA_NS, RAYO_JID(component), RAYO_COMPONENT(component)->client_jid);
                    iks *signal_xml = iks_find(signal_event, "signal");
                    iks_insert_attrib(signal_xml, "type", signal_type);
                    if (!zstr(value)) {
                        iks_insert_attrib(signal_xml, "value", value);
                    }
                    if (!zstr(duration)) {
                        iks_insert_attrib(signal_xml, "duration", duration);
                    }
                    RAYO_SEND_REPLY(component, RAYO_COMPONENT(component)->client_jid, signal_event);
                }
            }
        } else {
            switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_COMPONENT(component)->parent->id), SWITCH_LOG_DEBUG, "Skipping CPA event\n");
        }
        RAYO_UNLOCK(component);
    }
}
Esempio n. 2
0
/**
 * Handle completion event
 */
static iks *prompt_component_handle_input_complete(struct rayo_actor *prompt, struct rayo_message *msg, void *data)
{
	iks *presence = msg->payload;
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) input complete\n",
		RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state));

	switch (PROMPT_COMPONENT(prompt)->state) {
		case PCS_INPUT_OUTPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_DONE_STOP_OUTPUT;
			presence = iks_copy(presence);
			iks_insert_attrib(presence, "from", RAYO_JID(prompt));
			iks_insert_attrib(presence, "to", RAYO_COMPONENT(prompt)->client_jid);
			PROMPT_COMPONENT(prompt)->complete = presence;
			rayo_component_send_stop(prompt, PROMPT_COMPONENT(prompt)->output_jid);
			break;
		case PCS_STOP_OUTPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_DONE_STOP_OUTPUT;
			presence = iks_copy(presence);
			iks_insert_attrib(presence, "from", RAYO_JID(prompt));
			iks_insert_attrib(presence, "to", RAYO_COMPONENT(prompt)->client_jid);
			PROMPT_COMPONENT(prompt)->complete = presence;
			break;
		case PCS_INPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_DONE;
			/* pass through */
		case PCS_DONE:
			presence = iks_copy(presence);
			iks_insert_attrib(presence, "from", RAYO_JID(prompt));
			iks_insert_attrib(presence, "to", RAYO_COMPONENT(prompt)->client_jid);
			iks_delete(PROMPT_COMPONENT(prompt)->iq);
			rayo_component_send_complete_event(RAYO_COMPONENT(prompt), presence);
			break;
		case PCS_OUTPUT:
		case PCS_START_OUTPUT:
		case PCS_START_OUTPUT_BARGE:
		case PCS_START_INPUT:
		case PCS_START_INPUT_OUTPUT:
		case PCS_START_INPUT_TIMERS:
		case PCS_DONE_STOP_OUTPUT:
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output error event\n", RAYO_JID(prompt));
			break;
	}

	return NULL;
}
/**
 * Handle completion event
 */
static iks *prompt_component_handle_output_complete(struct rayo_actor *prompt, struct rayo_message *msg, void *data)
{
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s) output complete\n",
		RAYO_JID(prompt), prompt_component_state_to_string(PROMPT_COMPONENT(prompt)->state));

	switch (PROMPT_COMPONENT(prompt)->state) {
		case PCS_OUTPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_START_INPUT;
			/* start input with timers enabled and barge events disabled */
			start_input(PROMPT_COMPONENT(prompt), 1, 0);
			iks_delete(PROMPT_COMPONENT(prompt)->iq);
			break;
		case PCS_START_INPUT_OUTPUT:
			/* output finished before input started */
			PROMPT_COMPONENT(prompt)->state = PCS_START_INPUT_TIMERS;
			break;
		case PCS_INPUT_OUTPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_INPUT;
			start_input_timers(PROMPT_COMPONENT(prompt));
			break;
		case PCS_STOP_OUTPUT:
			PROMPT_COMPONENT(prompt)->state = PCS_INPUT;
			start_input_timers(PROMPT_COMPONENT(prompt));
			break;
		case PCS_DONE_STOP_OUTPUT:
			if (PROMPT_COMPONENT(prompt)->complete) {
				rayo_component_send_complete_event(RAYO_COMPONENT(prompt), PROMPT_COMPONENT(prompt)->complete);
			}
			break;
		case PCS_INPUT:
		case PCS_START_OUTPUT:
		case PCS_START_OUTPUT_BARGE:
		case PCS_START_INPUT:
		case PCS_START_INPUT_TIMERS:
		case PCS_DONE:
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, unexpected start output error event\n", RAYO_JID(prompt));
			break;
	}

	return NULL;
}
Esempio n. 4
0
/**
 * Handle fax completion event from FreeSWITCH core
 * @param event received from FreeSWITCH core.  It will be destroyed by the core after this function returns.
 */
static void on_execute_complete_event(switch_event_t *event)
{
	const char *application = switch_event_get_header(event, "Application");
	
	if (!zstr(application) && (!strcmp(application, "rxfax") || !strcmp(application, "txfax"))) {
		int is_rxfax = !strcmp(application, "rxfax");
		const char *uuid = switch_event_get_header(event, "Unique-ID");
		const char *fax_jid = switch_event_get_header(event, "variable_rayo_fax_jid");
		struct rayo_actor *component;
		if (!zstr(fax_jid) && (component = RAYO_LOCATE(fax_jid))) {
			iks *result;
			iks *complete;
			iks *fax;
			int have_fax_document = 1;
			switch_core_session_t *session;
			switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Got result for %s\n", fax_jid);

			/* clean up channel */
			session = switch_core_session_locate(uuid);
			if (session) {
				switch_channel_set_variable(switch_core_session_get_channel(session), "rayo_read_frame_interrupt", NULL);
				switch_core_session_rwunlock(session);
			}

			/* RX only: transfer HTTP document and delete local copy */
			if (is_rxfax && RECEIVEFAX_COMPONENT(component)->http_put_after_receive && switch_file_exists(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component)) == SWITCH_STATUS_SUCCESS) {
				switch_stream_handle_t stream = { 0 };
				SWITCH_STANDARD_STREAM(stream);
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s PUT fax to %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->filename);
				switch_api_execute("http_put", RECEIVEFAX_COMPONENT(component)->filename, NULL, &stream);
				/* check if successful */
				if (!zstr(stream.data) && strncmp(stream.data, "+OK", 3)) {
					/* PUT failed */
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s PUT fax to %s failed: %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->filename, (char *)stream.data);
					have_fax_document = 0;
				}
				switch_safe_free(stream.data)
				switch_file_remove(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component));
			}

			/* successful fax? */
			if (have_fax_document && switch_true(switch_event_get_header(event, "variable_fax_success"))) {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), FAX_FINISH);
			} else if (have_fax_document && FAX_COMPONENT(component)->stop)  {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_STOP);
			} else {
				result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_ERROR);
			}
			complete = iks_find(result, "complete");

			/* RX only: add fax document information */
			if (is_rxfax && have_fax_document) {
				const char *pages = switch_event_get_header(event, "variable_fax_document_transferred_pages");
				if (!zstr(pages) && switch_is_number(pages) && atoi(pages) > 0) {
					const char *resolution = switch_event_get_header(event, "variable_fax_file_image_resolution");
					const char *size = switch_event_get_header(event, "variable_fax_image_size");

					fax = iks_insert(complete, "fax");
					iks_insert_attrib(fax, "xmlns", RAYO_FAX_COMPLETE_NS);

					if (RECEIVEFAX_COMPONENT(component)->http_put_after_receive) {
						iks_insert_attrib(fax, "url", RECEIVEFAX_COMPONENT(component)->filename);
					} else {
						/* convert absolute path to file:// URI */
						iks_insert_attrib_printf(fax, "url", "file://%s", RECEIVEFAX_COMPONENT(component)->filename);
					}

					if (!zstr(resolution)) {
						iks_insert_attrib(fax, "resolution", resolution);
					}
					if (!zstr(size)) {
						iks_insert_attrib(fax, "size", size);
					}
					iks_insert_attrib(fax, "pages", pages);
				}
			}

			/* add metadata from event */
			insert_fax_metadata(event, "fax_success", complete);
			insert_fax_metadata(event, "fax_result_code", complete);
			insert_fax_metadata(event, "fax_result_text", complete);
			insert_fax_metadata(event, "fax_document_transferred_pages", complete);
			insert_fax_metadata(event, "fax_document_total_pages", complete);
			insert_fax_metadata(event, "fax_image_resolution", complete);
			insert_fax_metadata(event, "fax_image_size", complete);
			insert_fax_metadata(event, "fax_bad_rows", complete);
			insert_fax_metadata(event, "fax_transfer_rate", complete);
			insert_fax_metadata(event, "fax_ecm_used", complete);
			insert_fax_metadata(event, "fax_local_station_id", complete);
			insert_fax_metadata(event, "fax_remote_station_id", complete);

			/* flag faxing as done */
			rayo_call_set_faxing(RAYO_CALL(RAYO_COMPONENT(component)->parent), 0);

			rayo_component_send_complete_event(RAYO_COMPONENT(component), result);

			RAYO_UNLOCK(component);
		}
	}
}
Esempio n. 5
0
/**
 * Send rayo complete
 */
void rayo_component_send_complete_with_metadata(struct rayo_component *component, const char *reason, const char *reason_namespace, iks *meta, int child_of_complete)
{
	rayo_component_send_complete_event(component, rayo_component_create_complete_event_with_metadata(component, reason, reason_namespace, meta, child_of_complete));
}
Esempio n. 6
0
/**
 * Send rayo complete
 */
void rayo_component_send_complete(struct rayo_component *component, const char *reason, const char *reason_namespace)
{
	rayo_component_send_complete_event(component, rayo_component_create_complete_event(component, reason, reason_namespace));
}