summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client_list.c1
-rw-r--r--client_list.h1
-rw-r--r--switchctl.c49
3 files changed, 34 insertions, 17 deletions
diff --git a/client_list.c b/client_list.c
index 5f26f60..b3be116 100644
--- a/client_list.c
+++ b/client_list.c
@@ -48,7 +48,6 @@ int client_add(client_t** first, int fd)
new_client->fd = fd;
new_client->type = DEFAULT;
new_client->status_listener = 0;
- new_client->error_listener = 0;
new_client->request_listener = 0;
new_client->next = NULL;
new_client->buffer.offset = 0;
diff --git a/client_list.h b/client_list.h
index 8c1d5af..58756a7 100644
--- a/client_list.h
+++ b/client_list.h
@@ -31,7 +31,6 @@ struct client_struct {
int fd;
client_type_t type;
int status_listener;
- int error_listener;
int request_listener;
struct client_struct* next;
read_buffer_t buffer;
diff --git a/switchctl.c b/switchctl.c
index d7a7002..6e2ef08 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -84,11 +84,6 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
return 0;
}
- if(c->type == HEARTBEAT) {
- log_printf(WARNING, "ignoring requests from heartbeat agent");
- return 0;
- }
-
char* cmd_param = NULL;
if(cmd_id == SWITCH) {
if((opt->mode_ == MODE_MASTER && c->type == STANDBY )||
@@ -108,27 +103,50 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
}
else {
const char* ch_name = NULL;
- cmd_param = strdup("*0Fxnn");
+ char* ch_nr = NULL;
if(!strncmp(param, "up ", 3)) {
- cmd_param[3] = 'U';
+ cmd_param = strdup("*0FUii");
ch_name = &(param[3]);
+ ch_nr = &(cmd_param[4]);
}
else if(!strncmp(param, "down ", 5)) {
- cmd_param[3] = 'D';
+ cmd_param = strdup("*0FDii");
ch_name = &(param[5]);
+ ch_nr = &(cmd_param[4]);
+ }
+ else if(!strncmp(param, "on ", 3)) {
+ cmd_param = strdup("*0ii1");
+ ch_name = &(param[3]);
+ ch_nr = &(cmd_param[2]);
+ }
+ else if(!strncmp(param, "off ", 4)) {
+ cmd_param = strdup("*0iiM1");
+ ch_name = &(param[4]);
+ ch_nr = &(cmd_param[2]);
+ }
+ else if(!strncmp(param, "on2 ", 4)) {
+ cmd_param = strdup("*0ii2");
+ ch_name = &(param[4]);
+ ch_nr = &(cmd_param[2]);
+ }
+ else if(!strncmp(param, "off2 ", 5)) {
+ cmd_param = strdup("*0iiM2");
+ ch_name = &(param[4]);
+ ch_nr = &(cmd_param[2]);
}
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) {
+ char* ch_tmp = key_value_storage_find(&opt->alias_table_, ch_name);
+ if(!ch_tmp || ch_tmp[0] == 0 || ch_tmp[1] == 0 || ch_tmp[2] != 0) {
log_printf(ERROR, "invalid channel name or number: %s", ch_name);
+ free(cmd_param);
return 0;
}
- cmd_param[4] = ch_nr[0];
- cmd_param[5] = ch_nr[1];
+ ch_nr[0] = ch_tmp[0];
+ ch_nr[1] = ch_tmp[1];
}
log_printf(DEBUG, "enqueing command to switch: '%s' (request was: '%s')", cmd_param, param);
}
@@ -207,16 +225,17 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
if(listener) {
if(!param) {
listener->status_listener = 1;
- listener->error_listener = 1;
listener->request_listener = 1;
}
else {
if(!strncmp(param, "status", 6))
listener->status_listener = 1;
- else if(!strncmp(param, "error", 5))
- listener->error_listener = 1;
else if(!strncmp(param, "request", 7))
listener->request_listener = 1;
+ else if(!strncmp(param, "none", 4)) {
+ listener->request_listener = 0;
+ listener->status_listener = 0;
+ }
else {
log_printf(DEBUG, "unkown listener type '%s'", param);
return;