From 834a28ff7f14fc7c367f70f41a9b22692be22f68 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 24 Feb 2010 12:05:34 +0000 Subject: [PATCH] Skinny: House cleaning - Print message types and softkey states instead of their code - Show line number of calling function - Replace the remaining send_select_soft_keys by skinny_line_set_state (to keep proper state) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16788 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_skinny/mod_skinny.c | 19 +-- .../endpoints/mod_skinny/skinny_protocol.c | 161 +++++++++++++++++- .../endpoints/mod_skinny/skinny_protocol.h | 16 +- 3 files changed, 177 insertions(+), 19 deletions(-) diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.c b/src/mod/endpoints/mod_skinny/mod_skinny.c index 48c7572a26..1ab90a8c4c 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.c +++ b/src/mod/endpoints/mod_skinny/mod_skinny.c @@ -242,13 +242,12 @@ uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, c { switch_assert(listener); - if(listener->session[instance]) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session[instance]), SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d\n", - listener->device_name, instance, listener->line_state[instance], state); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d (no session)\n", - listener->device_name, instance, listener->line_state[instance], state); - } + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, + "Device %s, line %d State Change %s (%d) -> %s (%d) (no session)\n", + listener->device_name, instance, + skinny_soft_key_set2str(listener->line_state[instance]), listener->line_state[instance], + skinny_soft_key_set2str(state), state); + send_select_soft_keys(listener, instance, call_id, state, 0xffff); listener->line_state[instance] = state; @@ -523,8 +522,7 @@ switch_status_t channel_on_hangup(switch_core_session_t *session) SKINNY_ON_HOOK, tech_pvt->line, tech_pvt->call_id); - send_select_soft_keys(listener, tech_pvt->line, tech_pvt->call_id, - SKINNY_KEY_SET_ON_HOOK, 0xffff); + skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_ON_HOOK, tech_pvt->call_id); /* TODO: DefineTimeDate */ set_speaker_mode(listener, SKINNY_SPEAKER_OFF); set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0); @@ -828,8 +826,7 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi } tech_pvt->listener->session[tech_pvt->line] = nsession; send_call_state(tech_pvt->listener, SKINNY_RING_IN, tech_pvt->line, tech_pvt->call_id); - send_select_soft_keys(tech_pvt->listener, tech_pvt->line, tech_pvt->call_id, - SKINNY_KEY_SET_RING_IN, 0xffff); + skinny_line_set_state(tech_pvt->listener, tech_pvt->line, SKINNY_KEY_SET_RING_IN, tech_pvt->call_id); display_prompt_status(tech_pvt->listener, 0, "\200\027tel", tech_pvt->line, tech_pvt->call_id); /* displayprinotifiymessage */ skinny_send_call_info(nsession); diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c index 08ef0550d8..9874177775 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.c +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c @@ -35,6 +35,66 @@ skinny_globals_t globals; +struct skinny_message_type_table { + const char *name; + uint32_t type; +}; + +static struct skinny_message_type_table SKINNY_MESSAGE_TYPES[] = { + {"KEEP_ALIVE_MESSAGE", KEEP_ALIVE_MESSAGE}, + {"REGISTER_MESSAGE", REGISTER_MESSAGE}, + {"PORT_MESSAGE", PORT_MESSAGE}, + {"KEYPAD_BUTTON_MESSAGE", KEYPAD_BUTTON_MESSAGE}, + {"STIMULUS_MESSAGE", STIMULUS_MESSAGE}, + {"OFF_HOOK_MESSAGE", OFF_HOOK_MESSAGE}, + {"ON_HOOK_MESSAGE", ON_HOOK_MESSAGE}, + {"SPEED_DIAL_STAT_REQ_MESSAGE", SPEED_DIAL_STAT_REQ_MESSAGE}, + {"LINE_STAT_REQ_MESSAGE", LINE_STAT_REQ_MESSAGE}, + {"CONFIG_STAT_REQ_MESSAGE", CONFIG_STAT_REQ_MESSAGE}, + {"TIME_DATE_REQ_MESSAGE", TIME_DATE_REQ_MESSAGE}, + {"BUTTON_TEMPLATE_REQ_MESSAGE", BUTTON_TEMPLATE_REQ_MESSAGE}, + {"CAPABILITIES_RES_MESSAGE", CAPABILITIES_RES_MESSAGE}, + {"ALARM_MESSAGE", ALARM_MESSAGE}, + {"OPEN_RECEIVE_CHANNEL_ACK_MESSAGE", OPEN_RECEIVE_CHANNEL_ACK_MESSAGE}, + {"SOFT_KEY_SET_REQ_MESSAGE", SOFT_KEY_SET_REQ_MESSAGE}, + {"SOFT_KEY_EVENT_MESSAGE", SOFT_KEY_EVENT_MESSAGE}, + {"UNREGISTER_MESSAGE", UNREGISTER_MESSAGE}, + {"SOFT_KEY_TEMPLATE_REQ_MESSAGE", SOFT_KEY_TEMPLATE_REQ_MESSAGE}, + {"HEADSET_STATUS_MESSAGE", HEADSET_STATUS_MESSAGE}, + {"REGISTER_AVAILABLE_LINES_MESSAGE", REGISTER_AVAILABLE_LINES_MESSAGE}, + {"REGISTER_ACK_MESSAGE", REGISTER_ACK_MESSAGE}, + {"START_TONE_MESSAGE", START_TONE_MESSAGE}, + {"STOP_TONE_MESSAGE", STOP_TONE_MESSAGE}, + {"SET_RINGER_MESSAGE", SET_RINGER_MESSAGE}, + {"SET_LAMP_MESSAGE", SET_LAMP_MESSAGE}, + {"SET_SPEAKER_MODE_MESSAGE", SET_SPEAKER_MODE_MESSAGE}, + {"START_MEDIA_TRANSMISSION_MESSAGE", START_MEDIA_TRANSMISSION_MESSAGE}, + {"STOP_MEDIA_TRANSMISSION_MESSAGE", STOP_MEDIA_TRANSMISSION_MESSAGE}, + {"CALL_INFO_MESSAGE", CALL_INFO_MESSAGE}, + {"SPEED_DIAL_STAT_RES_MESSAGE", SPEED_DIAL_STAT_RES_MESSAGE}, + {"LINE_STAT_RES_MESSAGE", LINE_STAT_RES_MESSAGE}, + {"CONFIG_STAT_RES_MESSAGE", CONFIG_STAT_RES_MESSAGE}, + {"DEFINE_TIME_DATE_MESSAGE", DEFINE_TIME_DATE_MESSAGE}, + {"BUTTON_TEMPLATE_RES_MESSAGE", BUTTON_TEMPLATE_RES_MESSAGE}, + {"CAPABILITIES_REQ_MESSAGE", CAPABILITIES_REQ_MESSAGE}, + {"REGISTER_REJ_MESSAGE", REGISTER_REJ_MESSAGE}, + {"KEEP_ALIVE_ACK_MESSAGE", KEEP_ALIVE_ACK_MESSAGE}, + {"OPEN_RECEIVE_CHANNEL_MESSAGE", OPEN_RECEIVE_CHANNEL_MESSAGE}, + {"CLOSE_RECEIVE_CHANNEL_MESSAGE", CLOSE_RECEIVE_CHANNEL_MESSAGE}, + {"SOFT_KEY_TEMPLATE_RES_MESSAGE", SOFT_KEY_TEMPLATE_RES_MESSAGE}, + {"SOFT_KEY_SET_RES_MESSAGE", SOFT_KEY_SET_RES_MESSAGE}, + {"SELECT_SOFT_KEYS_MESSAGE", SELECT_SOFT_KEYS_MESSAGE}, + {"CALL_STATE_MESSAGE", CALL_STATE_MESSAGE}, + {"DISPLAY_PROMPT_STATUS_MESSAGE", DISPLAY_PROMPT_STATUS_MESSAGE}, + {"CLEAR_PROMPT_STATUS_MESSAGE", CLEAR_PROMPT_STATUS_MESSAGE}, + {"ACTIVATE_CALL_PLANE_MESSAGE", ACTIVATE_CALL_PLANE_MESSAGE}, + {"DIALED_NUMBER_MESSAGE", DIALED_NUMBER_MESSAGE}, + {"SKINNY_MESSAGE_FIELD_SIZE", SKINNY_MESSAGE_FIELD_SIZE}, + {"SKINNY_MESSAGE_HEADERSIZE", SKINNY_MESSAGE_HEADERSIZE}, + {"SKINNY_MESSAGE_MAXSIZE", SKINNY_MESSAGE_MAXSIZE}, + {NULL, 0} +}; + struct soft_key_template_definition soft_key_template_default[] = { { "\200\001", SOFTKEY_REDIAL }, { "\200\002", SOFTKEY_NEWCALL }, @@ -58,10 +118,96 @@ struct soft_key_template_definition soft_key_template_default[] = { { "\200\120", SOFTKEY_IDIVERT }, }; +struct skinny_key_set_table { + const char *name; + uint32_t id; +}; + +static struct skinny_key_set_table SKINNY_KEY_SETS[] = { + {"SKINNY_KEY_SET_ON_HOOK", 0}, + {"SKINNY_KEY_SET_CONNECTED", 1}, + {"SKINNY_KEY_SET_ON_HOLD", 2}, + {"SKINNY_KEY_SET_RING_IN", 3}, + {"SKINNY_KEY_SET_OFF_HOOK", 4}, + {"SKINNY_KEY_SET_CONNECTED_WITH_TRANSFER", 5}, + {"SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT", 6}, + {"SKINNY_KEY_SET_CONNECTED_WITH_CONFERENCE", 7}, + {"SKINNY_KEY_SET_RING_OUT", 8}, + {"SKINNY_KEY_SET_OFF_HOOK_WITH_FEATURES", 9}, + {NULL, 0} +}; + /*****************************************************************************/ /* SKINNY FUNCTIONS */ /*****************************************************************************/ +const char *skinny_message_type2str(uint32_t type) +{ + uint8_t x; + const char *str = "UNKNOWN_MESSAGE"; + for (x = 0; x < (sizeof(SKINNY_MESSAGE_TYPES) / sizeof(struct skinny_message_type_table)) - 1; x++) { + if (SKINNY_MESSAGE_TYPES[x].type == type) { + str = SKINNY_MESSAGE_TYPES[x].name; + break; + } + } + + return str; +} + +uint32_t skinny_str2message_type(const char *str) +{ + uint8_t x; + uint32_t type = -1; + + if (*str > 47 && *str < 58) { + type = atoi(str); + } else { + for (x = 0; x < (sizeof(SKINNY_MESSAGE_TYPES) / sizeof(struct skinny_message_type_table)) - 1 && SKINNY_MESSAGE_TYPES[x].name; x++) { + if (!strcasecmp(SKINNY_MESSAGE_TYPES[x].name, str)) { + type = SKINNY_MESSAGE_TYPES[x].type; + break; + } + } + } + return type; +} + +/*****************************************************************************/ +const char *skinny_soft_key_set2str(uint32_t id) +{ + uint8_t x; + const char *str = "UNKNOWN_SOFT_KEY_SET"; + + for (x = 0; x < (sizeof(SKINNY_KEY_SETS) / sizeof(struct skinny_key_set_table)) - 1; x++) { + if (SKINNY_KEY_SETS[x].id == id) { + str = SKINNY_KEY_SETS[x].name; + break; + } + } + + return str; +} + +uint32_t skinny_str2soft_key_set(const char *str) +{ + uint8_t x; + uint32_t id = -1; + + if (*str > 47 && *str < 58) { + id = atoi(str); + } else { + for (x = 0; x < (sizeof(SKINNY_KEY_SETS) / sizeof(struct skinny_key_set_table)) - 1 && SKINNY_KEY_SETS[x].name; x++) { + if (!strcasecmp(SKINNY_KEY_SETS[x].name, str)) { + id = SKINNY_KEY_SETS[x].id; + break; + } + } + } + return id; +} + +/*****************************************************************************/ char* skinny_codec2string(enum skinny_codecs skinnycodec) { switch (skinnycodec) { @@ -171,9 +317,11 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) do_sleep = 0; ptr += mlen; memcpy(request, mbuf, bytes); +#ifdef SKINNY_MEGA_DEBUG switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got request: length=%d,reserved=%x,type=%x\n", request->length,request->reserved,request->type); +#endif if(request->length < SKINNY_MESSAGE_FIELD_SIZE) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Skinny client sent invalid data. Length should be greater than 4 but got %d.\n", @@ -188,9 +336,11 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) } if(bytes >= request->length + 2*SKINNY_MESSAGE_FIELD_SIZE) { /* Message body */ +#ifdef SKINNY_MEGA_DEBUG switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got complete request: length=%d,reserved=%x,type=%x,data=%d\n", request->length,request->reserved,request->type,request->data.as_char); +#endif *req = request; return SWITCH_STATUS_SUCCESS; } @@ -1567,7 +1717,7 @@ switch_status_t skinny_handle_unregister(listener_t *listener, skinny_message_t 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); + "Received %s (type=%x,length=%d).\n", skinny_message_type2str(request->type), request->type, request->length); if(zstr(listener->device_name) && request->type != REGISTER_MESSAGE && request->type != ALARM_MESSAGE) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Device should send a register message first.\n"); @@ -1624,16 +1774,19 @@ switch_status_t skinny_handle_request(listener_t *listener, skinny_message_t *re } } -switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply) +switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file, const char *func, int line, skinny_message_t *reply) { char *ptr; switch_size_t len; switch_assert(reply != NULL); len = reply->length+8; ptr = (char *) reply; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Sending reply (type=%x,length=%d).\n", - reply->type, reply->length); + + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, + "Sending %s (type=%x,length=%d).\n", + skinny_message_type2str(reply->type), reply->type, reply->length); switch_socket_send(listener->sock, ptr, &len); + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.h b/src/mod/endpoints/mod_skinny/skinny_protocol.h index 1df04fa31e..f3de02ed56 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.h +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.h @@ -594,9 +594,9 @@ union skinny_data { * body is type+data */ struct skinny_message { - int length; - int reserved; - int type; + uint32_t length; + uint32_t reserved; + uint32_t type; union skinny_data data; }; typedef struct skinny_message skinny_message_t; @@ -652,13 +652,21 @@ typedef switch_status_t (*skinny_command_t) (char **argv, int argc, switch_strea return SWITCH_STATUS_FALSE;\ } + +const char *skinny_message_type2str(uint32_t type); +uint32_t skinny_str2message_type(const char *str); + +const char *skinny_soft_key_set2str(uint32_t id); +uint32_t skinny_str2soft_key_set(const char *str); + switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req); switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, switch_event_types_t event_id, const char *subclass_name); switch_status_t skinny_send_call_info(switch_core_session_t *session); -switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply); +switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file, const char *func, int line, skinny_message_t *reply); +#define skinny_send_reply(listener, reply) skinny_perform_send_reply(listener, __FILE__, __SWITCH_FUNC__, __LINE__, reply) switch_status_t skinny_handle_request(listener_t *listener, skinny_message_t *request);