diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-09 14:44:23 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-09 14:44:23 (GMT) |
commit | 0f18348db735efb6abbedf30b0ed8c48880b03c0 (patch) | |
tree | b2f71afff17aad366b1968716a93edf5431d4c50 | |
parent | a328c855ccd5c8d86eaef2439a73b73c348925ca (diff) |
process_cmd_request should work now
added a sample switchctl.conf
-rw-r--r-- | switchctl.c | 66 | ||||
-rw-r--r-- | switchctl.conf | 6 |
2 files changed, 68 insertions, 4 deletions
diff --git a/switchctl.c b/switchctl.c index b293015..5d98b0b 100644 --- a/switchctl.c +++ b/switchctl.c @@ -78,11 +78,67 @@ int send_response(int fd, const char* response) int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt) { - char* tmp = key_value_storage_find(&opt->alias_table_, param); - int ret = cmd_push(cmd_q, fd, cmd_id, tmp != NULL ? tmp : param); + client_t* c = client_find(client_lst, fd); + if(!c) { + log_printf(WARNING, "ignoring request form unknown client"); + return 0; + } + + if(c->type == HEARTBEAT) { + log_printf(WARNING, "ignoring requests form heartbeat agent"); + return 0; + } + + char* cmd_param = NULL; + if(cmd_id == SWITCH) { + if((opt->mode_ == MODE_MASTER && c->type == STANDBY )|| + (opt->mode_ == MODE_STANDBY && c->type == MASTER )) + { + log_printf(INFO, "ignoring request from inactive system (%s)", c->type == MASTER ? "master" : "standby"); + return 0; + } + + if(!param) { + log_printf(INFO, "ignoring switch command without parameter"); + return 0; + } + + if(param[0] == '*') { + cmd_param = strdup(param); + } + else { + const char* ch_name = NULL; + cmd_param = strdup("*0Fxnn"); + if(!strncmp(param, "up ", 3)) { + cmd_param[3] = 'U'; + ch_name = &(param[3]); + } + else if(!strncmp(param, "down ", 5)) { + cmd_param[3] = 'D'; + ch_name = &(param[5]); + } + else { + log_printf(INFO, "ignoring invalid switch command: '%s'", param); + return 0; + } + char* ch_nr = key_value_storage_find(&opt->alias_table_, ch_name); + if(!ch_nr || ch_nr[0] == 0 || ch_nr[1] == 0 || ch_nr[2] != 0) { + log_printf(ERROR, "invalid channel name or number: %s", ch_name); + return 0; + } + + cmd_param[4] = ch_nr[0]; + cmd_param[5] = ch_nr[1]; + } + log_printf(DEBUG, "enqueing command to switch: '%s' (request was: '%s')", cmd_param, param); + } + + int ret = cmd_push(cmd_q, fd, cmd_id, cmd_param); + if(cmd_param) + free(cmd_param); if(ret) return ret; - + if(cmd_id == STATUS) { char buf[30]; snprintf(buf, 30, "Current Mode: %s", opt->mode_ == MODE_MASTER ? "Master" : "Standby"); @@ -96,7 +152,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int } log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt); } - + log_printf(NOTICE, "command: %s", cmd); return 0; @@ -141,6 +197,8 @@ void process_cmd_mode(const char* param, options_t* opt) } else log_printf(ERROR, "unable to set mode: empty parameter"); + + log_printf(NOTICE, "new mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby"); } void process_cmd_listen(const char* param, int fd, client_t* client_lst) diff --git a/switchctl.conf b/switchctl.conf new file mode 100644 index 0000000..0364e0d --- /dev/null +++ b/switchctl.conf @@ -0,0 +1,6 @@ +master_main 01 +master_music 02 +standby_main 03 +standby_music 04 +studio 05 +ext_studio 06 |