Skinny: config cleaning and refactorisation
- removed unused globals: codecèprefs, codec_master, codec_rates - moved global debug to profile - store button type as id in DB (avoid case-sensitivity problem) - git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16794 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
9f870bd311
commit
1b988b2267
|
@ -44,9 +44,6 @@ static switch_memory_pool_t *module_pool = NULL;
|
|||
|
||||
skinny_globals_t globals;
|
||||
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* SQL TABLES */
|
||||
/*****************************************************************************/
|
||||
|
@ -66,7 +63,7 @@ static char buttons_sql[] =
|
|||
"CREATE TABLE skinny_buttons (\n"
|
||||
" device_name VARCHAR(16),\n"
|
||||
" position INTEGER,\n"
|
||||
" type VARCHAR(10),\n"
|
||||
" type INTEGER,\n"
|
||||
" label VARCHAR(40),\n"
|
||||
" value VARCHAR(24),\n"
|
||||
" settings VARCHAR(44)\n"
|
||||
|
@ -89,8 +86,8 @@ static switch_status_t dump_profile(const skinny_profile_t *profile, switch_stre
|
|||
stream->write_function(stream, "Context \t%s\n", profile->context);
|
||||
stream->write_function(stream, "Keep-Alive \t%d\n", profile->keep_alive);
|
||||
stream->write_function(stream, "Date-Format \t%s\n", profile->date_format);
|
||||
/* db */
|
||||
stream->write_function(stream, "DBName \t%s\n", profile->dbname ? profile->dbname : switch_str_nil(profile->odbc_dsn));
|
||||
stream->write_function(stream, "Debug \t%d\n", profile->debug);
|
||||
/* stats */
|
||||
stream->write_function(stream, "CALLS-IN \t%d\n", profile->ib_calls);
|
||||
stream->write_function(stream, "FAILED-CALLS-IN \t%d\n", profile->ib_failed_calls);
|
||||
|
@ -1102,7 +1099,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
|||
switch_socket_opt_set(listener->sock, SWITCH_SO_TCP_NODELAY, TRUE);
|
||||
switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, TRUE);
|
||||
|
||||
if (globals.debug > 0) {
|
||||
if (listener->profile->debug > 0) {
|
||||
if (zstr(listener->remote_ip)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
|
||||
} else {
|
||||
|
@ -1138,7 +1135,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
|||
|
||||
remove_listener(listener);
|
||||
|
||||
if (globals.debug > 0) {
|
||||
if (listener->profile->debug > 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session complete, waiting for children\n");
|
||||
}
|
||||
|
||||
|
@ -1151,7 +1148,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
|||
|
||||
switch_thread_rwlock_unlock(listener->rwlock);
|
||||
|
||||
if (globals.debug > 0) {
|
||||
if (listener->profile->debug > 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n");
|
||||
}
|
||||
|
||||
|
@ -1315,6 +1312,8 @@ static void skinny_profile_set(skinny_profile_t *profile, char *var, char *val)
|
|||
profile->dialplan = switch_core_strdup(module_pool, val);
|
||||
} else if (!strcasecmp(var, "context")) {
|
||||
profile->context = switch_core_strdup(module_pool, 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(module_pool, val);
|
||||
|
@ -1333,7 +1332,7 @@ static void skinny_profile_set(skinny_profile_t *profile, char *var, char *val)
|
|||
static switch_status_t load_skinny_config(void)
|
||||
{
|
||||
char *cf = "skinny.conf";
|
||||
switch_xml_t xcfg, xml, xsettings, xprofiles, xprofile, xparam;
|
||||
switch_xml_t xcfg, xml, xprofiles, xprofile;
|
||||
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
globals.running = 1;
|
||||
|
@ -1347,27 +1346,6 @@ static switch_status_t load_skinny_config(void)
|
|||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if ((xsettings = switch_xml_child(xcfg, "settings"))) {
|
||||
for (xparam = switch_xml_child(xsettings, "param"); xparam; xparam = xparam->next) {
|
||||
char *var = (char *) switch_xml_attr_soft(xparam, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(xparam, "value");
|
||||
|
||||
if (!strcmp(var, "debug")) {
|
||||
globals.debug = atoi(val);
|
||||
} else if (!strcmp(var, "codec-prefs")) {
|
||||
set_global_codec_string(val);
|
||||
globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
|
||||
} else if (!strcmp(var, "codec-master")) {
|
||||
if (!strcasecmp(val, "us")) {
|
||||
switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
|
||||
}
|
||||
} else if (!strcmp(var, "codec-rates")) {
|
||||
set_global_codec_rates_string(val);
|
||||
globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
|
||||
}
|
||||
} /* param */
|
||||
} /* settings */
|
||||
|
||||
if ((xprofiles = switch_xml_child(xcfg, "profiles"))) {
|
||||
for (xprofile = switch_xml_child(xprofiles, "profile"); xprofile; xprofile = xprofile->next) {
|
||||
char *profile_name = (char *) switch_xml_attr_soft(xprofile, "name");
|
||||
|
@ -1403,7 +1381,11 @@ static switch_status_t load_skinny_config(void)
|
|||
} else if (!strcmp(var, "keep-alive")) {
|
||||
profile->keep_alive = atoi(val);
|
||||
} else if (!strcmp(var, "date-format")) {
|
||||
memcpy(profile->date_format, val, 6);
|
||||
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);
|
||||
}
|
||||
} /* param */
|
||||
|
||||
|
@ -1415,7 +1397,7 @@ static switch_status_t load_skinny_config(void)
|
|||
skinny_profile_set(profile, "context","public");
|
||||
}
|
||||
|
||||
if (!profile->port) {
|
||||
if (profile->port == 0) {
|
||||
profile->port = 2000;
|
||||
}
|
||||
|
||||
|
@ -1514,7 +1496,7 @@ static switch_status_t cmd_profile_device_send_lamp_message(const char *profile_
|
|||
listener_t *listener = NULL;
|
||||
skinny_profile_find_listener_by_device_name(profile, device_name, &listener);
|
||||
if(listener) {
|
||||
set_lamp(listener, skinny_str2stimulus(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode));
|
||||
set_lamp(listener, skinny_str2button(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode));
|
||||
} else {
|
||||
stream->write_function(stream, "Listener not found!\n");
|
||||
}
|
||||
|
@ -1920,9 +1902,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skinny_shutdown)
|
|||
}
|
||||
}
|
||||
|
||||
switch_safe_free(globals.codec_string);
|
||||
switch_safe_free(globals.codec_rates_string);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,15 +44,6 @@
|
|||
#define SKINNY_EVENT_ALARM "skinny::alarm"
|
||||
|
||||
struct skinny_globals {
|
||||
/* prefs */
|
||||
int debug;
|
||||
char *codec_string;
|
||||
char *codec_order[SWITCH_MAX_CODECS];
|
||||
int codec_order_last;
|
||||
char *codec_rates_string;
|
||||
char *codec_rates[SWITCH_MAX_CODECS];
|
||||
int codec_rates_last;
|
||||
unsigned int flags;
|
||||
/* data */
|
||||
int calls;
|
||||
switch_mutex_t *calls_mutex;
|
||||
|
@ -74,6 +65,7 @@ struct skinny_profile {
|
|||
char *context;
|
||||
uint32_t keep_alive;
|
||||
char date_format[6];
|
||||
int debug;
|
||||
/* db */
|
||||
char *dbname;
|
||||
char *odbc_dsn;
|
||||
|
|
|
@ -134,7 +134,7 @@ struct skinny_table SKINNY_RING_MODES[] = {
|
|||
SKINNY_DECLARE_ID2STR(skinny_ring_mode2str, SKINNY_RING_MODES, "RingModeUnknown")
|
||||
SKINNY_DECLARE_STR2ID(skinny_str2ring_mode, SKINNY_RING_MODES, -1)
|
||||
|
||||
struct skinny_table SKINNY_STIMULI[] = {
|
||||
struct skinny_table SKINNY_BUTTONS[] = {
|
||||
{"LastNumberRedial", SKINNY_BUTTON_LAST_NUMBER_REDIAL},
|
||||
{"SpeedDial", SKINNY_BUTTON_SPEED_DIAL},
|
||||
{"Line", SKINNY_BUTTON_LINE},
|
||||
|
@ -142,8 +142,8 @@ struct skinny_table SKINNY_STIMULI[] = {
|
|||
{"Undefined", SKINNY_BUTTON_UNDEFINED},
|
||||
{NULL, 0}
|
||||
};
|
||||
SKINNY_DECLARE_ID2STR(skinny_stimulus2str, SKINNY_STIMULI, "Unknown")
|
||||
SKINNY_DECLARE_STR2ID(skinny_str2stimulus, SKINNY_STIMULI, -1)
|
||||
SKINNY_DECLARE_ID2STR(skinny_button2str, SKINNY_BUTTONS, "Unknown")
|
||||
SKINNY_DECLARE_STR2ID(skinny_str2button, SKINNY_BUTTONS, -1)
|
||||
|
||||
struct skinny_table SKINNY_LAMP_MODES[] = {
|
||||
{"Off", SKINNY_LAMP_OFF},
|
||||
|
@ -656,10 +656,11 @@ void skinny_line_get(listener_t *listener, uint32_t instance, struct line_stat_r
|
|||
|
||||
if ((sql = switch_mprintf(
|
||||
"SELECT '%d' AS wanted_position, position, label, value, settings "
|
||||
"FROM skinny_buttons WHERE device_name='%s' AND type='line' "
|
||||
"FROM skinny_buttons WHERE device_name='%s' AND type=%d "
|
||||
"ORDER BY position",
|
||||
instance,
|
||||
listener->device_name
|
||||
listener->device_name,
|
||||
SKINNY_BUTTON_LINE
|
||||
))) {
|
||||
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_line_get_callback, &helper);
|
||||
switch_safe_free(sql);
|
||||
|
@ -698,10 +699,11 @@ void skinny_speed_dial_get(listener_t *listener, uint32_t instance, struct speed
|
|||
|
||||
if ((sql = switch_mprintf(
|
||||
"SELECT '%d' AS wanted_position, position, label, value, settings "
|
||||
"FROM skinny_buttons WHERE device_name='%s' AND type='speed-dial' "
|
||||
"FROM skinny_buttons WHERE device_name='%s' AND type=%d "
|
||||
"ORDER BY position",
|
||||
instance,
|
||||
listener->device_name
|
||||
listener->device_name,
|
||||
SKINNY_BUTTON_SPEED_DIAL
|
||||
))) {
|
||||
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_speed_dial_get_callback, &helper);
|
||||
switch_safe_free(sql);
|
||||
|
@ -1121,15 +1123,15 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
|||
xbuttons = switch_xml_child(xskinny, "buttons");
|
||||
if (xbuttons) {
|
||||
for (xbutton = switch_xml_child(xbuttons, "button"); xbutton; xbutton = xbutton->next) {
|
||||
const char *position = switch_xml_attr_soft(xbutton, "position");
|
||||
const char *type = switch_xml_attr_soft(xbutton, "type");
|
||||
uint32_t position = atoi(switch_xml_attr_soft(xbutton, "position"));
|
||||
uint32_t type = skinny_str2button(switch_xml_attr_soft(xbutton, "type"));
|
||||
const char *label = switch_xml_attr_soft(xbutton, "label");
|
||||
const char *value = switch_xml_attr_soft(xbutton, "value");
|
||||
const char *settings = switch_xml_attr_soft(xbutton, "settings");
|
||||
if ((sql = switch_mprintf(
|
||||
"INSERT INTO skinny_buttons "
|
||||
"(device_name, position, type, label, value, settings) "
|
||||
"VALUES('%s', '%s', '%s', '%s', '%s', '%s')",
|
||||
"VALUES('%s', %d, %d, '%s', '%s', '%s')",
|
||||
request->data.reg.device_name,
|
||||
position,
|
||||
type,
|
||||
|
@ -1221,11 +1223,13 @@ switch_status_t skinny_handle_config_stat_request(listener_t *listener, skinny_m
|
|||
|
||||
if ((sql = switch_mprintf(
|
||||
"SELECT name, user_id, instance, '' AS user_name, '' AS server_name, "
|
||||
"(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type='line') AS number_lines, "
|
||||
"(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type='speed-dial') AS number_speed_dials "
|
||||
"(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type='%s') AS number_lines, "
|
||||
"(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type='%s') AS number_speed_dials "
|
||||
"FROM skinny_devices WHERE name='%s' ",
|
||||
listener->device_name,
|
||||
skinny_button2str(SKINNY_BUTTON_LINE),
|
||||
listener->device_name,
|
||||
skinny_button2str(SKINNY_BUTTON_SPEED_DIAL),
|
||||
listener->device_name
|
||||
))) {
|
||||
skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_config_stat_res_callback, message);
|
||||
|
@ -1321,16 +1325,16 @@ switch_status_t skinny_handle_port_message(listener_t *listener, skinny_message_
|
|||
|
||||
struct button_template_helper {
|
||||
skinny_message_t *message;
|
||||
int count[0xff+1];
|
||||
int count[0xffff+1];
|
||||
};
|
||||
|
||||
int skinny_handle_button_template_request_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
struct button_template_helper *helper = pArg;
|
||||
skinny_message_t *message = helper->message;
|
||||
char *device_name = argv[0];
|
||||
/* char *device_name = argv[0]; */
|
||||
int position = atoi(argv[1]);
|
||||
char *type = argv[2];
|
||||
uint32_t type = atoi(argv[2]);
|
||||
int i;
|
||||
|
||||
/* fill buttons between previous one and current one */
|
||||
|
@ -1341,17 +1345,9 @@ int skinny_handle_button_template_request_callback(void *pArg, int argc, char **
|
|||
message->data.button_template.total_button_count++;
|
||||
}
|
||||
|
||||
message->data.button_template.btn[i].instance_number = ++helper->count[type];
|
||||
message->data.button_template.btn[position-1].button_definition = type;
|
||||
|
||||
if (!strcasecmp(type, "line")) {
|
||||
message->data.button_template.btn[i].instance_number = ++helper->count[SKINNY_BUTTON_LINE];
|
||||
message->data.button_template.btn[position-1].button_definition = SKINNY_BUTTON_LINE;
|
||||
} else if (!strcasecmp(type, "speed-dial")) {
|
||||
message->data.button_template.btn[i].instance_number = ++helper->count[SKINNY_BUTTON_SPEED_DIAL];
|
||||
message->data.button_template.btn[position-1].button_definition = SKINNY_BUTTON_SPEED_DIAL;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||
"Unknown button type %s for device %s.\n", type, device_name);
|
||||
}
|
||||
message->data.button_template.button_count++;
|
||||
message->data.button_template.total_button_count++;
|
||||
|
||||
|
|
|
@ -664,10 +664,10 @@ enum skinny_button_definition {
|
|||
SKINNY_BUTTON_VOICEMAIL = 0x0F,
|
||||
SKINNY_BUTTON_UNDEFINED = 0xFF,
|
||||
};
|
||||
struct skinny_table SKINNY_STIMULI[6];
|
||||
const char *skinny_stimulus2str(uint32_t id);
|
||||
uint32_t skinny_str2stimulus(const char *str);
|
||||
#define SKINNY_PUSH_STIMULI SKINNY_DECLARE_PUSH_MATCH(SKINNY_STIMULI)
|
||||
struct skinny_table SKINNY_BUTTONS[6];
|
||||
const char *skinny_button2str(uint32_t id);
|
||||
uint32_t skinny_str2button(const char *str);
|
||||
#define SKINNY_PUSH_STIMULI SKINNY_DECLARE_PUSH_MATCH(SKINNY_BUTTONS)
|
||||
|
||||
enum skinny_soft_key_event {
|
||||
SOFTKEY_REDIAL = 0x01,
|
||||
|
|
Loading…
Reference in New Issue