Skinny: one function per message type
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16757 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4c1065f7b5
commit
a5dc87ce61
|
@ -906,6 +906,7 @@ static switch_status_t skinny_device_event(listener_t *listener, switch_event_t
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Message handling */
|
||||||
static switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *request)
|
static switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *request)
|
||||||
{
|
{
|
||||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
|
@ -957,7 +958,7 @@ static switch_status_t skinny_handle_register(listener_t *listener, skinny_messa
|
||||||
if(users) {
|
if(users) {
|
||||||
for (user = switch_xml_child(users, "user"); user; user = user->next) {
|
for (user = switch_xml_child(users, "user"); user; user = user->next) {
|
||||||
const char *id = switch_xml_attr_soft(user, "id");
|
const char *id = switch_xml_attr_soft(user, "id");
|
||||||
const char *type = switch_xml_attr_soft(user, "type");
|
//const char *type = switch_xml_attr_soft(user, "type");
|
||||||
//TODO device->line[device->line_last].device = *device;
|
//TODO device->line[device->line_last].device = *device;
|
||||||
strcpy(device->line[device->line_last].name, id);
|
strcpy(device->line[device->line_last].name, id);
|
||||||
strcpy(device->line[device->line_last].shortname, id);
|
strcpy(device->line[device->line_last].shortname, id);
|
||||||
|
@ -998,26 +999,13 @@ end:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t skinny_handle_request(listener_t *listener, skinny_message_t *request)
|
static switch_status_t skinny_handle_capabilities_response(listener_t *listener, skinny_message_t *request)
|
||||||
{
|
{
|
||||||
skinny_message_t *message;
|
skinny_device_t *device = listener->device;
|
||||||
skinny_device_t *device;
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
size_t string_len, string_pos, pos;
|
size_t string_len, string_pos, pos;
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
|
||||||
"Received message (type=%x,length=%d).\n", request->type, request->length);
|
|
||||||
if(!listener->device && request->type != REGISTER_MESSAGE) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
|
||||||
"Device should send a register message first.\n");
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
device = listener->device;
|
|
||||||
switch(request->type) {
|
|
||||||
case REGISTER_MESSAGE:
|
|
||||||
return skinny_handle_register(listener, request);
|
|
||||||
case CAPABILITIES_RES_MESSAGE:
|
|
||||||
n = request->data.cap_res.count;
|
n = request->data.cap_res.count;
|
||||||
if (n > SWITCH_MAX_CODECS) {
|
if (n > SWITCH_MAX_CODECS) {
|
||||||
n = SWITCH_MAX_CODECS;
|
n = SWITCH_MAX_CODECS;
|
||||||
|
@ -1046,10 +1034,23 @@ static switch_status_t skinny_handle_request(listener_t *listener, skinny_messag
|
||||||
device->codec_order_last = n;
|
device->codec_order_last = n;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||||
"Codecs %s supported.\n", device->codec_string);
|
"Codecs %s supported.\n", device->codec_string);
|
||||||
case PORT_MESSAGE:
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static switch_status_t skinny_handle_port_message(listener_t *listener, skinny_message_t *request)
|
||||||
|
{
|
||||||
|
skinny_device_t *device = listener->device;
|
||||||
|
|
||||||
device->port = request->data.as_uint16;
|
device->port = request->data.as_uint16;
|
||||||
break;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
case LINE_STAT_REQ_MESSAGE:
|
}
|
||||||
|
|
||||||
|
static switch_status_t skinny_handle_line_stat_request(listener_t *listener, skinny_message_t *request)
|
||||||
|
{
|
||||||
|
skinny_device_t *device = listener->device;
|
||||||
|
skinny_message_t *message;
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.line_res));
|
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.line_res));
|
||||||
message->type = LINE_STAT_RES_MESSAGE;
|
message->type = LINE_STAT_RES_MESSAGE;
|
||||||
message->length = 4 + sizeof(message->data.line_res);
|
message->length = 4 + sizeof(message->data.line_res);
|
||||||
|
@ -1065,20 +1066,46 @@ static switch_status_t skinny_handle_request(listener_t *listener, skinny_messag
|
||||||
strcpy(message->data.line_res.displayname, "");
|
strcpy(message->data.line_res.displayname, "");
|
||||||
}
|
}
|
||||||
skinny_send_reply(listener, message);
|
skinny_send_reply(listener, message);
|
||||||
break;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
case KEEP_ALIVE_MESSAGE:
|
}
|
||||||
|
|
||||||
|
static switch_status_t skinny_handle_keep_alive_message(listener_t *listener, skinny_message_t *request)
|
||||||
|
{
|
||||||
|
skinny_message_t *message;
|
||||||
|
|
||||||
message = switch_core_alloc(listener->pool, 12);
|
message = switch_core_alloc(listener->pool, 12);
|
||||||
message->type = KEEP_ALIVE_ACK_MESSAGE;
|
message->type = KEEP_ALIVE_ACK_MESSAGE;
|
||||||
message->length = 4;
|
message->length = 4;
|
||||||
keepalive_listener(listener, NULL);
|
keepalive_listener(listener, NULL);
|
||||||
skinny_send_reply(listener, message);
|
skinny_send_reply(listener, message);
|
||||||
break;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
/* TODO */
|
}
|
||||||
|
|
||||||
|
static switch_status_t skinny_handle_request(listener_t *listener, skinny_message_t *request)
|
||||||
|
{
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||||
|
"Received message (type=%x,length=%d).\n", request->type, request->length);
|
||||||
|
if(!listener->device && request->type != REGISTER_MESSAGE) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||||
|
"Device should send a register message first.\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
switch(request->type) {
|
||||||
|
case REGISTER_MESSAGE:
|
||||||
|
return skinny_handle_register(listener, request);
|
||||||
|
case CAPABILITIES_RES_MESSAGE:
|
||||||
|
return skinny_handle_capabilities_response(listener, request);
|
||||||
|
case PORT_MESSAGE:
|
||||||
|
return skinny_handle_port_message(listener, request);
|
||||||
|
case LINE_STAT_REQ_MESSAGE:
|
||||||
|
return skinny_handle_line_stat_request(listener, request);
|
||||||
|
case KEEP_ALIVE_MESSAGE:
|
||||||
|
return skinny_handle_keep_alive_message(listener, request);
|
||||||
default:
|
default:
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||||
"Unknown request type: %d.\n", request->type);
|
"Unknown request type: %x (length=%d).\n", request->type, request->length);
|
||||||
}
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply)
|
static switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply)
|
||||||
|
|
Loading…
Reference in New Issue