diff options
Diffstat (limited to 'switchctl.c')
-rw-r--r-- | switchctl.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/switchctl.c b/switchctl.c index ba81c46..b003909 100644 --- a/switchctl.c +++ b/switchctl.c @@ -432,6 +432,10 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst) else if(!strncmp(param, "none", 4)) { listener->request_listener = 0; listener->status_listener = 0; + listener->gpi_listener = 0; + listener->oc_listener = 0; + listener->relay_listener = 0; + listener->silence_listener = 0; } else { log_printf(DEBUG, "unkown listener type '%s'", param); @@ -532,6 +536,19 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op return 0; } + +#define SEND_TO_LISTENER(STRING, LEN, FLAG) \ + if(!strncmp(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); \ + listener_cnt++; \ + } \ + log_printf(DEBUG, "sent message to %d additional listeners", listener_cnt); \ + } \ + int process_switch(read_buffer_t* buffer, int switch_fd, cmd_t **cmd_q, client_t* client_lst) { int ret = 0; @@ -572,17 +589,12 @@ int process_switch(read_buffer_t* buffer, int switch_fd, cmd_t **cmd_q, client_t send_response(cmd_fd, buffer->buf); } - if(!strncmp(buffer->buf, "S0L", 3)) { - client_t* client; - int listener_cnt = 0; - for(client = client_lst; client; client = client->next) - if(client->status_listener && client->fd != cmd_fd) { - send_response(client->fd, buffer->buf); - listener_cnt++; - } - log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt); - } - + 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))) cmd_pop(cmd_q); |