Пример #1
0
static switch_status_t skinny_device_status_show(switch_stream_handle_t *stream, const char *profile_name)
{
	struct device_show_helper h = { 0 };
	char *sql;
	const int ind = 4;									// temporary - suppose to be changed - number of values from DB
	int i;
	skinny_profile_t *profile = NULL;
	switch_console_callback_device_node_t *it;
	listener_t *listener = NULL;
	
	char *fmt[] = {"|%-30s", "|%-14s", "|%-5s", "|%-16s", "|%-5s|\n"};

	profile = skinny_find_profile(profile_name);
	
	if(profile)
	{
		if((sql = switch_mprintf("SELECT skinny_lines.caller_name, skinny_devices.ip, "
				"skinny_devices.port, skinny_devices.name from skinny_lines "
				"LEFT JOIN skinny_devices "
				"ON skinny_lines.device_name = skinny_devices.name")))
			{
				skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_api_list_devices_show_callback, &h);
				switch_safe_free(sql);
			}
	}
	if(h.my_devices != NULL)		// Print values received from sql
	{
		stream->write_function(stream, fmt[0], "Caller");
		stream->write_function(stream, fmt[1], "IP");
		stream->write_function(stream, fmt[2], "Port");
		stream->write_function(stream, fmt[3], "MAC");
		stream->write_function(stream, fmt[4], "DND");
		
		stream->write_function(stream, "----------------------------------------------------------------------------\n");

		for(it = h.my_devices->head, i = 1; it != NULL; it = it->next, i++)
		{
			stream->write_function(stream, fmt[i-1], it->val);
			
			if(i%ind == 0)
				{					
					skinny_profile_find_listener_by_device_name(profile, (const char*)(it->val), &listener);
					if(listener)
						stream->write_function(stream, fmt[i++], listener->dnd?"Y":"N");
					else
						stream->write_function(stream, "|listener not found|\n");
					i = 0;
				}			
		}
	}
	else
	{
		stream->write_function(stream, "*** No phones registered! ***\n");
	}
	return SWITCH_STATUS_SUCCESS;
}
Пример #2
0
static switch_status_t skinny_api_cmd_profile_device_send_data(const char *profile_name, const char *device_name, const char *message_type, char *params, const char *body, switch_stream_handle_t *stream)
{
	skinny_profile_t *profile;

	if ((profile = skinny_find_profile(profile_name))) {
		listener_t *listener = NULL;
		skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
		if(listener) {
			switch_event_t *event = NULL;
			char *argv[64] = { 0 };
			int argc = 0;
			int x = 0;
			/* skinny::user_to_device event */
			skinny_device_event(listener, &event, SWITCH_EVENT_CUSTOM, SKINNY_EVENT_USER_TO_DEVICE);
			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Message-Id-String", "%s", message_type);
			argc = switch_separate_string(params, ';', argv, (sizeof(argv) / sizeof(argv[0])));
			for (x = 0; x < argc; x++) {
				char *var_name, *var_value = NULL;
				var_name = argv[x];
				if (var_name && (var_value = strchr(var_name, '='))) {
					*var_value++ = '\0';
				}
				if (zstr(var_name)) {
					stream->write_function(stream, "-ERR No variable specified\n");
				} else {
					char *tmp = switch_mprintf("Skinny-UserToDevice-%s", var_name);
					switch_event_add_header(event, SWITCH_STACK_BOTTOM, tmp, "%s", var_value);
					switch_safe_free(tmp);
					/*
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Application-Id", "%d", request->data.extended_data.application_id);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Line-Instance", "%d", request->data.extended_data.line_instance);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Call-Id", "%d", request->data.extended_data.call_id);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Transaction-Id", "%d", request->data.extended_data.transaction_id);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Data-Length", "%d", request->data.extended_data.data_length);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Sequence-Flag", "%d", request->data.extended_data.sequence_flag);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Display-Priority", "%d", request->data.extended_data.display_priority);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Conference-Id", "%d", request->data.extended_data.conference_id);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-App-Instance-Id", "%d", request->data.extended_data.app_instance_id);
					   switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Skinny-UserToDevice-Routing-Id", "%d", request->data.extended_data.routing_id);
					 */
				}
			}
			switch_event_add_body(event, "%s", body);
			switch_event_fire(&event);
			stream->write_function(stream, "+OK\n");
		} else {
			stream->write_function(stream, "Listener not found!\n");
		}
	} else {
		stream->write_function(stream, "Profile not found!\n");
	}

	return SWITCH_STATUS_SUCCESS;
}
Пример #3
0
static switch_status_t skinny_api_cmd_profile_device_send_reset_message(const char *profile_name, const char *device_name, const char *reset_type, switch_stream_handle_t *stream)
{
    skinny_profile_t *profile;

    if ((profile = skinny_find_profile(profile_name))) {
	    listener_t *listener = NULL;
	    skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
	    if(listener) {
		    send_reset(listener, skinny_str2device_reset_type(reset_type));
	    } else {
		    stream->write_function(stream, "Listener not found!\n");
	    }
    } else {
	    stream->write_function(stream, "Profile not found!\n");
    }

    return SWITCH_STATUS_SUCCESS;
}
Пример #4
0
static switch_status_t skinny_api_cmd_profile_device_send_call_state_message(const char *profile_name, const char *device_name, const char *call_state, const char *line_instance, const char *call_id, switch_stream_handle_t *stream)
{
    skinny_profile_t *profile;

    if ((profile = skinny_find_profile(profile_name))) {
	    listener_t *listener = NULL;
	    skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
	    if(listener) {
		    send_call_state(listener, skinny_str2call_state(call_state), atoi(line_instance), atoi(call_id));
	    } else {
		    stream->write_function(stream, "Listener not found!\n");
	    }
    } else {
	    stream->write_function(stream, "Profile not found!\n");
    }

    return SWITCH_STATUS_SUCCESS;
}
Пример #5
0
static switch_status_t skinny_api_cmd_profile_device_send_lamp_message(const char *profile_name, const char *device_name, const char *stimulus, const char *instance, const char *lamp_mode, switch_stream_handle_t *stream)
{
    skinny_profile_t *profile;

    if ((profile = skinny_find_profile(profile_name))) {
	    listener_t *listener = NULL;
	    skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
	    if(listener) {
		    send_set_lamp(listener, skinny_str2button(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode));
	    } else {
		    stream->write_function(stream, "Listener not found!\n");
	    }
    } else {
	    stream->write_function(stream, "Profile not found!\n");
    }

    return SWITCH_STATUS_SUCCESS;
}
Пример #6
0
static switch_status_t skinny_api_cmd_profile_device_kill(const char *profile_name, const char *device_name, switch_stream_handle_t *stream)
{
	skinny_profile_t *profile;

	if ((profile = skinny_find_profile(profile_name))) {
		listener_t *listener = NULL;
		skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
		if(listener) {
			kill_listener(listener, NULL);
			stream->write_function(stream, "+OK\n");
		} else {
			stream->write_function(stream, "Listener not found!\n");
		}
	} else {
		stream->write_function(stream, "Profile not found!\n");
	}

	return SWITCH_STATUS_SUCCESS;
}
Пример #7
0
static switch_status_t skinny_api_set_dnd(switch_stream_handle_t *stream, const char *profile_name, const char* state, const char *device_name)
{
	skinny_profile_t *profile = skinny_find_profile(profile_name);
	listener_t *listener = NULL;
	if(profile)
	{
		skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
		if(listener)
			{
				if(!strcasecmp(state, "ON")) {
					listener->dnd = 1;
					send_display_prompt_status(listener, 0, "DND ON", 0, 0);
				} else if (!strcasecmp(state, "OFF")) {
					listener->dnd = 0;
					send_display_prompt_status(listener, 2, "DND OFF", 0, 0);
				}

			}
	}
	return SWITCH_STATUS_SUCCESS;
}