]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Skinny: more API
authorMathieu Parent <math.parent@gmail.com>
Wed, 28 Jul 2010 17:41:00 +0000 (19:41 +0200)
committerMathieu Parent <math.parent@gmail.com>
Wed, 28 Jul 2010 17:42:59 +0000 (19:42 +0200)
- 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
src/mod/endpoints/mod_skinny/mod_skinny.h
src/mod/endpoints/mod_skinny/skinny_api.c
src/mod/endpoints/mod_skinny/skinny_protocol.c
src/mod/endpoints/mod_skinny/skinny_server.c

index 79906f63026a7f79c13e4233466e71d39432ea1f..e506f142af59c4c7bbe7e1eb24c176f0ff8316d5 100644 (file)
@@ -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 */
                
index f8cd92619e3c61cd47ab67cf8dac3e74ec17abc5..68f3fddf87477906be7cf9ffd5e0542e4edbfe05 100644 (file)
@@ -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 */
 
index 79ebcfe12291f43afbbfed72c47e2f0a72d854e6..cf54deb8b8d811e511354d06a9b0c0f6fd459e2c 100644 (file)
@@ -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 <profile_name> device <device_name> send SetLampMessage <stimulus> <instance> <lamp_mode>\n"
            "skinny profile <profile_name> device <device_name> send SetSpeakerModeMessage <speaker_mode>\n"
            "skinny profile <profile_name> device <device_name> send CallStateMessage <call_state> <line_instance> <call_id>\n"
+           "skinny profile <profile_name> set <name> <value>\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 <profile_name> */
            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 <profile_name> set <name> <value> */
+           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;
 }
 
index 9486c5c869796646d17df0f1c1281f999582ad0e..ba4cba70db62ccd3eec58023bcdb547f18cec571 100644 (file)
@@ -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,
index d8ccc6d53bdccdfe128f8a5699ad026ae6a7a9c1..4de568b72c16f0726f5ebbe7b9a5f9909df40b70 100644 (file)
@@ -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");