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:
Mathieu Parent 2010-02-24 11:59:10 +00:00
parent 4c1065f7b5
commit a5dc87ce61
1 changed files with 87 additions and 60 deletions

View File

@ -906,6 +906,7 @@ static switch_status_t skinny_device_event(listener_t *listener, switch_event_t
return SWITCH_STATUS_SUCCESS;
}
/* Message handling */
static switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *request)
{
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) {
for (user = switch_xml_child(users, "user"); user; user = user->next) {
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;
strcpy(device->line[device->line_last].name, id);
strcpy(device->line[device->line_last].shortname, id);
@ -998,26 +999,13 @@ end:
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;
skinny_device_t *device = listener->device;
uint32_t i = 0;
uint32_t n = 0;
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;
if (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;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"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;
break;
case LINE_STAT_REQ_MESSAGE:
return SWITCH_STATUS_SUCCESS;
}
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->type = LINE_STAT_RES_MESSAGE;
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, "");
}
skinny_send_reply(listener, message);
break;
case KEEP_ALIVE_MESSAGE:
return SWITCH_STATUS_SUCCESS;
}
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->type = KEEP_ALIVE_ACK_MESSAGE;
message->length = 4;
keepalive_listener(listener, NULL);
skinny_send_reply(listener, message);
break;
/* TODO */
return SWITCH_STATUS_SUCCESS;
}
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:
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;
}
}
static switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply)