mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 16:39:14 +00:00
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,14 +999,90 @@ 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;
|
||||||
|
|
||||||
|
n = request->data.cap_res.count;
|
||||||
|
if (n > SWITCH_MAX_CODECS) {
|
||||||
|
n = SWITCH_MAX_CODECS;
|
||||||
|
}
|
||||||
|
string_len = -1;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
char *codec = skinny_codec2string(request->data.cap_res.caps[i].codec);
|
||||||
|
device->codec_order[i] = codec;
|
||||||
|
string_len += strlen(codec)+1;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
pos = 0;
|
||||||
|
device->codec_string = realloc(device->codec_string, string_len+1);
|
||||||
|
for (string_pos = 0; string_pos < string_len; string_pos++) {
|
||||||
|
char *codec = device->codec_order[i];
|
||||||
|
switch_assert(i < n);
|
||||||
|
if(pos == strlen(codec)) {
|
||||||
|
device->codec_string[string_pos] = ',';
|
||||||
|
i++;
|
||||||
|
pos = 0;
|
||||||
|
} else {
|
||||||
|
device->codec_string[string_pos] = codec[pos++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
device->codec_string[string_len] = '\0';
|
||||||
|
device->codec_order_last = n;
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||||
|
"Codecs %s supported.\n", device->codec_string);
|
||||||
|
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;
|
||||||
|
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);
|
||||||
|
i = request->data.line_req.number;
|
||||||
|
if(i > 0 && i <= device->line_last) {
|
||||||
|
message->data.line_res.number = i;
|
||||||
|
strcpy(message->data.line_res.name, device->line[i-1].name);
|
||||||
|
strcpy(message->data.line_res.shortname, device->line[i-1].shortname);
|
||||||
|
strcpy(message->data.line_res.displayname, device->line[i-1].displayname);
|
||||||
|
} else {
|
||||||
|
strcpy(message->data.line_res.name, "");
|
||||||
|
strcpy(message->data.line_res.shortname, "");
|
||||||
|
strcpy(message->data.line_res.displayname, "");
|
||||||
|
}
|
||||||
|
skinny_send_reply(listener, 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);
|
||||||
|
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,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||||
"Received message (type=%x,length=%d).\n", request->type, request->length);
|
"Received message (type=%x,length=%d).\n", request->type, request->length);
|
||||||
if(!listener->device && request->type != REGISTER_MESSAGE) {
|
if(!listener->device && request->type != REGISTER_MESSAGE) {
|
||||||
@ -1013,72 +1090,22 @@ static switch_status_t skinny_handle_request(listener_t *listener, skinny_messag
|
|||||||
"Device should send a register message first.\n");
|
"Device should send a register message first.\n");
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
device = listener->device;
|
|
||||||
switch(request->type) {
|
switch(request->type) {
|
||||||
case REGISTER_MESSAGE:
|
case REGISTER_MESSAGE:
|
||||||
return skinny_handle_register(listener, request);
|
return skinny_handle_register(listener, request);
|
||||||
case CAPABILITIES_RES_MESSAGE:
|
case CAPABILITIES_RES_MESSAGE:
|
||||||
n = request->data.cap_res.count;
|
return skinny_handle_capabilities_response(listener, request);
|
||||||
if (n > SWITCH_MAX_CODECS) {
|
|
||||||
n = SWITCH_MAX_CODECS;
|
|
||||||
}
|
|
||||||
string_len = -1;
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
char *codec = skinny_codec2string(request->data.cap_res.caps[i].codec);
|
|
||||||
device->codec_order[i] = codec;
|
|
||||||
string_len += strlen(codec)+1;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
pos = 0;
|
|
||||||
device->codec_string = realloc(device->codec_string, string_len+1);
|
|
||||||
for (string_pos = 0; string_pos < string_len; string_pos++) {
|
|
||||||
char *codec = device->codec_order[i];
|
|
||||||
switch_assert(i < n);
|
|
||||||
if(pos == strlen(codec)) {
|
|
||||||
device->codec_string[string_pos] = ',';
|
|
||||||
i++;
|
|
||||||
pos = 0;
|
|
||||||
} else {
|
|
||||||
device->codec_string[string_pos] = codec[pos++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
device->codec_string[string_len] = '\0';
|
|
||||||
device->codec_order_last = n;
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
|
||||||
"Codecs %s supported.\n", device->codec_string);
|
|
||||||
case PORT_MESSAGE:
|
case PORT_MESSAGE:
|
||||||
device->port = request->data.as_uint16;
|
return skinny_handle_port_message(listener, request);
|
||||||
break;
|
|
||||||
case LINE_STAT_REQ_MESSAGE:
|
case LINE_STAT_REQ_MESSAGE:
|
||||||
message = switch_core_alloc(listener->pool, 12+sizeof(message->data.line_res));
|
return skinny_handle_line_stat_request(listener, request);
|
||||||
message->type = LINE_STAT_RES_MESSAGE;
|
|
||||||
message->length = 4 + sizeof(message->data.line_res);
|
|
||||||
i = request->data.line_req.number;
|
|
||||||
if(i > 0 && i <= device->line_last) {
|
|
||||||
message->data.line_res.number = i;
|
|
||||||
strcpy(message->data.line_res.name, device->line[i-1].name);
|
|
||||||
strcpy(message->data.line_res.shortname, device->line[i-1].shortname);
|
|
||||||
strcpy(message->data.line_res.displayname, device->line[i-1].displayname);
|
|
||||||
} else {
|
|
||||||
strcpy(message->data.line_res.name, "");
|
|
||||||
strcpy(message->data.line_res.shortname, "");
|
|
||||||
strcpy(message->data.line_res.displayname, "");
|
|
||||||
}
|
|
||||||
skinny_send_reply(listener, message);
|
|
||||||
break;
|
|
||||||
case KEEP_ALIVE_MESSAGE:
|
case KEEP_ALIVE_MESSAGE:
|
||||||
message = switch_core_alloc(listener->pool, 12);
|
return skinny_handle_keep_alive_message(listener, request);
|
||||||
message->type = KEEP_ALIVE_ACK_MESSAGE;
|
|
||||||
message->length = 4;
|
|
||||||
keepalive_listener(listener, NULL);
|
|
||||||
skinny_send_reply(listener, message);
|
|
||||||
break;
|
|
||||||
/* TODO */
|
|
||||||
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…
x
Reference in New Issue
Block a user