From 7eec05736ade197a6d7ce04ecc1194a797effa1d Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Wed, 28 Jul 2010 19:41:00 +0200 Subject: [PATCH] Skinny: more API - allow to set most settings at runtime (all but ip, port and odbc-dsn) - little rewrite of the config load - don't print Keepalive and KeepaliveAck messages unless profile debug is >=10 - print usage when incorrect parameters --- src/mod/endpoints/mod_skinny/mod_skinny.c | 72 +++++++++---------- src/mod/endpoints/mod_skinny/mod_skinny.h | 1 + src/mod/endpoints/mod_skinny/skinny_api.c | 48 ++++++++++++- .../endpoints/mod_skinny/skinny_protocol.c | 10 +-- src/mod/endpoints/mod_skinny/skinny_server.c | 8 ++- 5 files changed, 93 insertions(+), 46 deletions(-) diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.c b/src/mod/endpoints/mod_skinny/mod_skinny.c index 79906f6302..e506f142af 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.c +++ b/src/mod/endpoints/mod_skinny/mod_skinny.c @@ -1586,38 +1586,55 @@ switch_endpoint_interface_t *skinny_get_endpoint_interface() return skinny_endpoint_interface; } -static void skinny_profile_set(skinny_profile_t *profile, char *var, char *val) +switch_status_t skinny_profile_set(skinny_profile_t *profile, const char *var, const char *val) { if (!var) - return; + return SWITCH_STATUS_FALSE; + + if (profile->sock && (!strcasecmp(var, "ip") || !strcasecmp(var, "port") || !strcasecmp(var, "odbc-dsn"))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "Skinny profile settings 'ip', 'port' and 'odbc-dsn' can't be changed while running\n"); + return SWITCH_STATUS_FALSE; + } if (!strcasecmp(var, "domain")) { profile->domain = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "ip")) { profile->ip = switch_core_strdup(profile->pool, val); - } else if (!strcasecmp(var, "dialplan")) { - profile->dialplan = switch_core_strdup(profile->pool, val); - } else if (!strcasecmp(var, "context")) { - profile->context = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "port")) { + profile->port = atoi(val); } else if (!strcasecmp(var, "patterns-dialplan")) { profile->patterns_dialplan = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "patterns-context")) { profile->patterns_context = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "dialplan")) { + profile->dialplan = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "context")) { + profile->context = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "keep-alive")) { + profile->keep_alive = atoi(val); } else if (!strcasecmp(var, "date-format")) { strncpy(profile->date_format, val, 6); - } else if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) { - if (switch_odbc_available()) { - profile->odbc_dsn = switch_core_strdup(profile->pool, val); - if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) { - *profile->odbc_user++ = '\0'; - if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) { - *profile->odbc_pass++ = '\0'; + } else if (!strcasecmp(var, "odbc-dsn")) { + if (!zstr(val)) { + if (switch_odbc_available()) { + profile->odbc_dsn = switch_core_strdup(profile->pool, val); + if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) { + *profile->odbc_user++ = '\0'; + if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) { + *profile->odbc_pass++ = '\0'; + } } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n"); } + } else if (!strcasecmp(var, "debug")) { + profile->debug = atoi(val); + } else { + return SWITCH_STATUS_FALSE; } + return SWITCH_STATUS_SUCCESS; } static switch_status_t load_skinny_config(void) @@ -1663,28 +1680,9 @@ static switch_status_t load_skinny_config(void) char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); - if (!strcmp(var, "domain")) { - skinny_profile_set(profile, "domain", val); - } else if (!strcmp(var, "ip")) { - skinny_profile_set(profile, "ip", val); - } else if (!strcmp(var, "port")) { - profile->port = atoi(val); - } else if (!strcmp(var, "dialplan")) { - skinny_profile_set(profile, "dialplan", val); - } else if (!strcmp(var, "context")) { - skinny_profile_set(profile, "context", val); - } else if (!strcmp(var, "patterns-dialplan")) { - skinny_profile_set(profile, "patterns-dialplan", val); - } else if (!strcmp(var, "patterns-context")) { - skinny_profile_set(profile, "patterns-context", val); - } else if (!strcmp(var, "keep-alive")) { - profile->keep_alive = atoi(val); - } else if (!strcmp(var, "date-format")) { - skinny_profile_set(profile, "date-format", val); - } else if (!strcmp(var, "odbc-dsn")) { - skinny_profile_set(profile, "odbc-dsn", val); - } else if (!strcmp(var, "debug")) { - profile->debug = atoi(val); + if (skinny_profile_set(profile, var, val) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Unable to set skinny setting '%s'. Does it exists?\n", var); } } /* param */ diff --git a/src/mod/endpoints/mod_skinny/mod_skinny.h b/src/mod/endpoints/mod_skinny/mod_skinny.h index f8cd92619e..68f3fddf87 100644 --- a/src/mod/endpoints/mod_skinny/mod_skinny.h +++ b/src/mod/endpoints/mod_skinny/mod_skinny.h @@ -252,6 +252,7 @@ switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); /* MODULE FUNCTIONS */ /*****************************************************************************/ switch_endpoint_interface_t *skinny_get_endpoint_interface(); +switch_status_t skinny_profile_set(skinny_profile_t *profile, const char *var, const char *val); #endif /* _MOD_SKINNY_H */ diff --git a/src/mod/endpoints/mod_skinny/skinny_api.c b/src/mod/endpoints/mod_skinny/skinny_api.c index 79ebcfe122..cf54deb8b8 100644 --- a/src/mod/endpoints/mod_skinny/skinny_api.c +++ b/src/mod/endpoints/mod_skinny/skinny_api.c @@ -214,6 +214,30 @@ static switch_status_t skinny_api_list_call_ids(const char *line, const char *cu return status; } +static switch_status_t skinny_api_list_settings(const char *line, const char *cursor, switch_console_callback_match_t **matches) +{ + switch_status_t status = SWITCH_STATUS_FALSE; + switch_console_callback_match_t *my_matches = NULL; + + switch_console_push_match(&my_matches, "domain"); + switch_console_push_match(&my_matches, "ip"); + switch_console_push_match(&my_matches, "port"); + switch_console_push_match(&my_matches, "patterns-dialplan"); + switch_console_push_match(&my_matches, "patterns-context"); + switch_console_push_match(&my_matches, "dialplan"); + switch_console_push_match(&my_matches, "context"); + switch_console_push_match(&my_matches, "keep-alive"); + switch_console_push_match(&my_matches, "date-format"); + switch_console_push_match(&my_matches, "odbc-dsn"); + switch_console_push_match(&my_matches, "debug"); + + if (my_matches) { + *matches = my_matches; + status = SWITCH_STATUS_SUCCESS; + } + return status; +} + /*****************************************************************************/ /* skinny_api_cmd_* */ /*****************************************************************************/ @@ -336,6 +360,21 @@ static switch_status_t skinny_api_cmd_profile_device_send_reset_message(const ch return SWITCH_STATUS_SUCCESS; } +static switch_status_t skinny_api_cmd_profile_set(const char *profile_name, const char *name, const char *value, switch_stream_handle_t *stream) +{ + skinny_profile_t *profile; + + if ((profile = skinny_find_profile(profile_name))) { + if (skinny_profile_set(profile, name, value) != SWITCH_STATUS_SUCCESS) { + stream->write_function(stream, "Unable to set skinny setting '%s'. Does it exists?\n", name); + } + } else { + stream->write_function(stream, "Profile not found!\n"); + } + + return SWITCH_STATUS_SUCCESS; +} + /*****************************************************************************/ /* API */ /*****************************************************************************/ @@ -355,6 +394,7 @@ SWITCH_STANDARD_API(skinny_function) "skinny profile device send SetLampMessage \n" "skinny profile device send SetSpeakerModeMessage \n" "skinny profile device send CallStateMessage \n" + "skinny profile set \n" "--------------------------------------------------------------------------------\n"; if (session) { return SWITCH_STATUS_FALSE; @@ -377,7 +417,6 @@ SWITCH_STANDARD_API(skinny_function) if (!strcasecmp(argv[0], "help")) {/* skinny help */ stream->write_function(stream, "%s", usage_string); - goto done; } else if (argc == 3 && !strcasecmp(argv[0], "status") && !strcasecmp(argv[1], "profile")) { /* skinny status profile */ status = skinny_api_cmd_status_profile(argv[2], stream); @@ -420,8 +459,11 @@ SWITCH_STANDARD_API(skinny_function) default: stream->write_function(stream, "Unhandled message %s\n", argv[5]); } + } else if (argc == 5 && !strcasecmp(argv[0], "profile") && !strcasecmp(argv[2], "set")) { + /* skinny profile set */ + status = skinny_api_cmd_profile_set(argv[1], argv[3], argv[4], stream); } else { - stream->write_function(stream, "Unknown Command [%s]\n", argv[0]); + stream->write_function(stream, "%s", usage_string); } done: @@ -444,6 +486,7 @@ switch_status_t skinny_api_register(switch_loadable_module_interface_t **module_ switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetLampMessage ::skinny::list_stimuli ::skinny::list_stimulus_instances ::skinny::list_stimulus_modes"); switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send SetSpeakerModeMessage ::skinny::list_speaker_modes"); switch_console_set_complete("add skinny profile ::skinny::list_profiles device ::skinny::list_devices send CallStateMessage ::skinny::list_call_states ::skinny::list_line_instances ::skinny::list_call_ids"); + switch_console_set_complete("add skinny profile ::skinny::list_profiles set ::skinny::list_settings"); switch_console_add_complete_func("::skinny::list_profiles", skinny_api_list_profiles); switch_console_add_complete_func("::skinny::list_devices", skinny_api_list_devices); @@ -457,6 +500,7 @@ switch_status_t skinny_api_register(switch_loadable_module_interface_t **module_ switch_console_add_complete_func("::skinny::list_call_states", skinny_api_list_call_states); switch_console_add_complete_func("::skinny::list_line_instances", skinny_api_list_line_instances); switch_console_add_complete_func("::skinny::list_call_ids", skinny_api_list_call_ids); + switch_console_add_complete_func("::skinny::list_settings", skinny_api_list_settings); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c index 9486c5c869..ba4cba70db 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.c +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c @@ -915,10 +915,12 @@ switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file ptr = (char *) reply; if (listener_is_ready(listener)) { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, - "Sending %s (type=%x,length=%d) to %s:%d.\n", - skinny_message_type2str(reply->type), reply->type, reply->length, - listener->device_name, listener->device_instance); + if (listener->profile->debug >= 10 || reply->type != KEEP_ALIVE_ACK_MESSAGE) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, + "Sending %s (type=%x,length=%d) to %s:%d.\n", + skinny_message_type2str(reply->type), reply->type, reply->length, + listener->device_name, listener->device_instance); + } return switch_socket_send(listener->sock, ptr, &len); } else { switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING, diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index d8ccc6d53b..4de568b72c 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -1926,9 +1926,11 @@ switch_status_t skinny_handle_feature_stat_request(listener_t *listener, skinny_ switch_status_t skinny_handle_request(listener_t *listener, skinny_message_t *request) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, - "Received %s (type=%x,length=%d) from %s:%d.\n", skinny_message_type2str(request->type), request->type, request->length, - listener->device_name, listener->device_instance); + if (listener->profile->debug >= 10 || request->type != KEEP_ALIVE_MESSAGE) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "Received %s (type=%x,length=%d) from %s:%d.\n", skinny_message_type2str(request->type), request->type, request->length, + listener->device_name, listener->device_instance); + } 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");