summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/switchctl.c b/switchctl.c
index cb54077..7463eb7 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -41,14 +41,15 @@ int send_command(int switch_fd, cmd_t* cmd)
{
if(!cmd)
return -1;
-
+
char* c = NULL;
switch(cmd->cmd) {
case SWITCH:
case CHANNEL: c = cmd->param; break;
case STATUS: c = "*0SL"; break;
+ default: break;
}
-
+
if(c == NULL)
return 0;
@@ -97,7 +98,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
log_printf(INFO, "silently ignoring request from inactive system (%s)", c->type == MASTER ? "master" : "standby");
return 0;
}
-
+
if(!param) {
log_printf(INFO, "ignoring switch command without parameter");
send_response(fd, "EEE: switch: missing parameter");
@@ -172,7 +173,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
free(cmd_param);
return 0;
}
-
+
ch_nr[0] = ch_tmp[0];
ch_nr[1] = ch_tmp[1];
}
@@ -180,7 +181,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
}
int ret = cmd_push(cmd_q, fd, cmd_id, cmd_param);
- if(cmd_param)
+ if(cmd_param)
free(cmd_param);
if(ret)
return ret;
@@ -204,7 +205,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);
+ log_printf(NOTICE, "command: %s", cmd);
return 0;
}
@@ -262,7 +263,7 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_
return 0;
}
- channel_t old_channel;
+ switchctl_channel_t old_channel;
if(c->type == MASTER)
old_channel = opt->channel_master_;
else
@@ -319,7 +320,7 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_
return ret;
}
- log_printf(NOTICE, "command: %s", cmd);
+ log_printf(NOTICE, "command: %s", cmd);
return 0;
}
@@ -359,7 +360,7 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, client_t* client_lst)
{
- mode_t old_mode = opt->mode_;
+ switchctl_mode_t old_mode = opt->mode_;
if(param) {
if(!strncmp(param, "master", 6))
@@ -388,7 +389,7 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
log_printf(ERROR, "EEE: mode: old config is illegal?!");
return 0;
}
-
+
char* ch_to = NULL;
if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN)
ch_to = "master_main";
@@ -403,13 +404,13 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
log_printf(ERROR, "EEE: mode: current config is illegal?!");
return 0;
}
-
+
int ret = crossfade(ch_from, ch_to, fd, cmd_q, opt);
if(ret) {
opt->mode_ = old_mode;
if(ret > 0)
return 0;
-
+
return ret;
}
}
@@ -421,8 +422,8 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
if(old_mode != opt->mode_) {
char* mode_str;
- asprintf(&mode_str, "new Mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
- if(mode_str) {
+ int len = asprintf(&mode_str, "new Mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
+ if(len > 0) {
log_printf(NOTICE, "%s", mode_str);
client_t* client;
int listener_cnt = 0;
@@ -439,7 +440,7 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
return 0;
}
-
+
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
{
client_t* listener = client_find(client_lst, fd);
@@ -497,7 +498,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
if(!cmd_q || !cmd)
return -1;
-
+
cmd_id_t cmd_id;
if(!strncmp(cmd, "switch", 6))
cmd_id = SWITCH;
@@ -520,13 +521,13 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
return 0;
}
char* param = strchr(cmd, ' ');
- if(param)
+ if(param)
param++;
if(cmd_id == SWITCH || cmd_id == CHANNEL || cmd_id == MODE) {
char* resp;
- asprintf(&resp, "Request: %s", cmd);
- if(resp) {
+ int len = asprintf(&resp, "Request: %s", cmd);
+ if(len > 0) {
char* linefeed = strchr(resp, '\n');
if(linefeed) linefeed[0] = 0;
client_t* client;
@@ -543,7 +544,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: {
int ret = process_cmd_request(cmd, cmd_id, param, fd, cmd_q, client_lst, opt);
if(ret)
@@ -565,14 +566,14 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
}
case LOG: {
if(param && param[0])
- log_printf(NOTICE, "ext msg: %s", param);
+ log_printf(NOTICE, "ext msg: %s", param);
else
log_printf(DEBUG, "ignoring empty ext log message");
break;
}
case LISTEN: process_cmd_listen(param, fd, client_lst); break;
}
-
+
return 0;
}
@@ -590,7 +591,7 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
if(buffer->buf[buffer->offset] == '\n') {
buffer->buf[buffer->offset] = 0;
- ret = process_cmd(buffer->buf, fd, cmd_q, client_lst, opt);
+ ret = process_cmd((char *)(buffer->buf), fd, cmd_q, client_lst, opt);
buffer->offset = 0;
break;
}
@@ -607,12 +608,12 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
}
#define SEND_TO_LISTENER(STRING, LEN, FLAG) \
- if(!strncmp(buffer->buf, STRING, LEN)) { \
+ if(!strncmp((char *)(buffer->buf), STRING, LEN)) { \
client_t* client; \
int listener_cnt = 0; \
for(client = client_lst; client; client = client->next) \
if(client->FLAG && client->fd != cmd_fd) { \
- send_response(client->fd, buffer->buf); \
+ send_response(client->fd, (char *)(buffer->buf)); \
listener_cnt++; \
} \
log_printf(DEBUG, "sent message to %d additional listeners", listener_cnt); \
@@ -649,26 +650,26 @@ int process_switch(read_buffer_t* buffer, int switch_fd, cmd_t **cmd_q, client_t
if(buffer->offset > 0 && buffer->buf[buffer->offset-1] == '\r')
buffer->buf[buffer->offset-1] = 0;
- if(strlen(buffer->buf)) {
- log_printf(NOTICE, "switch-firmware: '%s'", buffer->buf);
-
+ if(strlen((char *)(buffer->buf))) {
+ log_printf(NOTICE, "switch-firmware: '%s'", (char *)(buffer->buf));
+
int cmd_fd = -1;
if(cmd_q && (*cmd_q)) {
cmd_fd = (*cmd_q)->fd;
- send_response(cmd_fd, buffer->buf);
+ send_response(cmd_fd, (char *)(buffer->buf));
}
-
+
SEND_TO_LISTENER("S0L", 3, status_listener);
SEND_TO_LISTENER("S0P", 3, gpi_listener);
SEND_TO_LISTENER("S0O", 3, oc_listener);
SEND_TO_LISTENER("S0R", 3, relay_listener);
SEND_TO_LISTENER("S0S", 3, silence_listener);
- if((!strncmp(buffer->buf, "RRR", 3)) ||
- (!strncmp(buffer->buf, "EEE", 3)))
+ if((!strncmp((char *)(buffer->buf), "RRR", 3)) ||
+ (!strncmp((char *)(buffer->buf), "EEE", 3)))
cmd_pop(cmd_q);
}
-
+
buffer->offset = 0;
return 0;
}
@@ -707,12 +708,12 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
int return_value = 0;
- char* channel;
+ char* channel = "unknown";
if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN) channel = "master_main";
else if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MUSIC) channel = "master_music";
else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MAIN) channel = "standby_main";
else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MUSIC) channel = "standby_music";
-
+
char* cmd_param = strdup("*0M1*0ii1");
char* ch_nr = key_value_storage_find(&opt->alias_table_, channel);
if(!ch_nr || ch_nr[0] == 0 || ch_nr[1] == 0 || ch_nr[2] != 0) {
@@ -757,7 +758,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
break;
}
}
-
+
if(FD_ISSET(switch_fd, &tmpfds)) {
return_value = process_switch(&switch_buffer, switch_fd, &cmd_q, client_lst);
if(return_value)
@@ -770,7 +771,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
log_printf(ERROR, "accept returned with error: %s", strerror(errno));
return_value = -1;
break;
- }
+ }
log_printf(DEBUG, "new command connection (fd=%d)", new_fd);
FD_SET(new_fd, &readfds);
max_fd = (max_fd < new_fd) ? new_fd : max_fd;
@@ -853,7 +854,7 @@ int main(int argc, char* argv[])
case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
}
-
+
options_clear(&opt);
log_close();
exit(ret);
@@ -915,7 +916,7 @@ int main(int argc, char* argv[])
log_close();
exit(-1);
}
-
+
int switch_fd = 0;
for(;;) {
switch_fd = open(opt.switch_dev_, O_RDWR | O_NOCTTY);