summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-11-04 04:37:05 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-11-04 04:37:05 (GMT)
commit7882d05127816e6885268182a3769bc7a091de94 (patch)
tree436160f1e3f2980edc092759e56c617492dae1ba
parent14e460a9bcaadaa2dd206a5c701814cd5e1d4648 (diff)
alias table for switch commands
-rw-r--r--switchctl.c11
-rw-r--r--utils.c4
-rw-r--r--utils.h4
3 files changed, 11 insertions, 8 deletions
diff --git a/switchctl.c b/switchctl.c
index b3150d5..f961f31 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -76,7 +76,7 @@ int send_response(int fd, const char* response)
return ret;
}
-int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst)
+int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
log_printf(DEBUG, "processing command from %d", fd);
@@ -123,7 +123,8 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst)
switch(cmd_id) {
case SWITCH:
case STATUS: {
- int ret = cmd_push(cmd_q, fd, cmd_id, param);
+ char* tmp = key_value_storage_find(&opt->alias_table_, param);
+ int ret = cmd_push(cmd_q, fd, cmd_id, tmp != NULL ? tmp : param);
if(ret)
return ret;
@@ -199,7 +200,7 @@ int process_switch(int switch_fd)
return ret;
}
-int main_loop(int switch_fd, int cmd_listen_fd)
+int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
{
log_printf(NOTICE, "entering main loop");
@@ -271,7 +272,7 @@ int main_loop(int switch_fd, int cmd_listen_fd)
client_t* lst = client_lst;
while(lst) {
if(FD_ISSET(lst->fd, &tmpfds)) {
- return_value = nonblock_recvline(&(lst->buffer), lst->fd, &cmd_q, client_lst);
+ return_value = nonblock_recvline(&(lst->buffer), lst->fd, &cmd_q, client_lst, opt);
if(return_value == 2) {
log_printf(DEBUG, "removing closed command connection (fd=%d)", lst->fd);
client_t* deletee = lst;
@@ -406,7 +407,7 @@ int main(int argc, char* argv[])
if(ret)
ret = 2;
else
- ret = main_loop(switch_fd, cmd_listen_fd);
+ ret = main_loop(switch_fd, cmd_listen_fd, &opt);
}
if(ret == 2) {
diff --git a/utils.c b/utils.c
index 4309118..14d4670 100644
--- a/utils.c
+++ b/utils.c
@@ -87,7 +87,7 @@ int send_string(int fd, const char* string)
return ret;
}
-int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst)
+int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst, options_t* opt)
{
int ret = 0;
for(;;) {
@@ -101,7 +101,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);
+ ret = process_cmd(buffer->buf, fd, cmd_q, client_lst, opt);
buffer->offset = 0;
break;
}
diff --git a/utils.h b/utils.h
index 5e4da89..e34fc88 100644
--- a/utils.h
+++ b/utils.h
@@ -22,9 +22,11 @@
#ifndef _UTILS_H_
#define _UTILS_H_
+#include "options.h"
+
int init_command_socket(const char* path);
int send_string(int fd, const char* string);
-int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst);
+int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* client_lst, options_t* opt);
int setup_tty(int fd);
#endif