summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/switchctl.c b/switchctl.c
index f961f31..9bf0612 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -86,6 +86,10 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
cmd_id_t cmd_id;
if(!strncmp(cmd, "switch", 6))
cmd_id = SWITCH;
+ else if(!strncmp(cmd, "type", 4))
+ cmd_id = TYPE;
+ else if(!strncmp(cmd, "mode", 4))
+ cmd_id = MODE;
else if(!strncmp(cmd, "status", 6))
cmd_id = STATUS;
else if(!strncmp(cmd, "log", 3))
@@ -121,7 +125,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
}
switch(cmd_id) {
- case SWITCH:
+ case SWITCH:
case STATUS: {
char* tmp = key_value_storage_find(&opt->alias_table_, param);
int ret = cmd_push(cmd_q, fd, cmd_id, tmp != NULL ? tmp : param);
@@ -131,6 +135,46 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
log_printf(NOTICE, "command: %s", cmd);
break;
}
+ case TYPE: {
+ if(param) {
+ client_t* client = client_find(client_lst, fd);
+ if(client) {
+ if(!strncmp(param, "master", 6))
+ client->type = MASTER;
+ else if(!strncmp(param, "standby", 7))
+ client->type = STANDBY;
+ else if(!strncmp(param, "heartbeat", 9))
+ client->type = HEARTBEAT;
+ else {
+ log_printf(DEBUG, "unkown client type '%s'", param);
+ break;
+ }
+ log_printf(DEBUG, "client %d type set to %s", fd, param);
+ }
+ else
+ log_printf(ERROR, "unable to set client type for %d: client not found", fd);
+ }
+ else
+ log_printf(ERROR, "unable to set client type for %d: empty parameter", fd);
+
+ break;
+ }
+ case MODE: {
+ if(param) {
+ if(!strncmp(param, "master", 6))
+ opt->mode_ = MODE_MASTER;
+ else if(!strncmp(param, "standby", 7))
+ opt->mode_ = MODE_STANDBY;
+ else {
+ log_printf(DEBUG, "unkown mode '%s'", param);
+ break;
+ }
+ }
+ else
+ log_printf(ERROR, "unable to set mode: empty parameter", fd);
+
+ break;
+ }
case LOG: {
if(param && param[0])
log_printf(NOTICE, "ext msg: %s", param);