[0] | 1 | //commands.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
| 5 | struct roar_command g_commands[COMMAND_MAX_COMMANDS] = { |
---|
| 6 | {ROAR_CMD_NOOP, "NOOP", req_on_noop}, |
---|
| 7 | {ROAR_CMD_IDENTIFY, "IDENTIFY", req_on_identify}, |
---|
| 8 | {ROAR_CMD_AUTH, "AUTH", req_on_auth}, |
---|
| 9 | {ROAR_CMD_NEW_STREAM, "NEW_STREAM", req_on_new_stream}, |
---|
[100] | 10 | |
---|
[0] | 11 | {ROAR_CMD_SET_META, "SET_META", req_on_set_meta}, |
---|
[100] | 12 | {ROAR_CMD_GET_META, "GET_META", req_on_get_meta}, |
---|
[113] | 13 | {ROAR_CMD_LIST_META, "LIST_META", req_on_list_meta}, |
---|
[100] | 14 | |
---|
[0] | 15 | {ROAR_CMD_EXEC_STREAM, "EXEC_STREAM", req_on_exec_stream}, |
---|
| 16 | {ROAR_CMD_QUIT, "QUIT", clients_delete}, |
---|
| 17 | |
---|
[77] | 18 | {ROAR_CMD_CON_STREAM, "CON_STREAM", req_on_con_stream}, |
---|
| 19 | |
---|
[0] | 20 | {ROAR_CMD_SERVER_OINFO, "SERVER_OINFO", req_on_server_oinfo}, |
---|
| 21 | {ROAR_CMD_GET_STANDBY, "GET_STANDBY", req_on_get_standby}, |
---|
| 22 | {ROAR_CMD_SET_STANDBY, "SET_STANDBY", req_on_set_standby}, |
---|
| 23 | {ROAR_CMD_EXIT, "EXIT", req_on_exit}, |
---|
| 24 | |
---|
| 25 | {ROAR_CMD_LIST_CLIENTS, "LIST_CLIENTS", req_on_list_clients}, |
---|
| 26 | {ROAR_CMD_LIST_STREAMS, "LIST_STREAMS", req_on_list_streams}, |
---|
| 27 | {ROAR_CMD_GET_CLIENT, "GET_CLIENT", req_on_get_client}, |
---|
| 28 | {ROAR_CMD_GET_STREAM, "GET_STREAM", req_on_get_stream}, |
---|
| 29 | {ROAR_CMD_KICK, "KICK", req_on_kick}, |
---|
[17] | 30 | {ROAR_CMD_SET_VOL, "SET_VOL", req_on_set_vol}, |
---|
[23] | 31 | {ROAR_CMD_GET_VOL, "GET_VOL", req_on_get_vol}, |
---|
[0] | 32 | |
---|
| 33 | {ROAR_CMD_ADD_DATA, "ADD_DATA", req_on_add_data}, |
---|
| 34 | |
---|
| 35 | {ROAR_CMD_EOL, "END OF LIST", NULL} |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | int command_get_id_by_cmd (int command) { |
---|
| 39 | int i; |
---|
| 40 | int cmd; |
---|
| 41 | |
---|
| 42 | for (i = 0; i < COMMAND_MAX_COMMANDS; i++) { |
---|
| 43 | if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL ) |
---|
| 44 | break; |
---|
| 45 | |
---|
| 46 | if ( cmd == command ) |
---|
| 47 | return i; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | return -1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int command_exec (int client, struct roar_message * mes, char * data) { |
---|
| 54 | int cmd = command_get_id_by_cmd(mes->cmd); |
---|
| 55 | int (*func)(int client, struct roar_message * mes, char * data); |
---|
| 56 | |
---|
| 57 | if ( cmd == -1 ) |
---|
| 58 | return -1; |
---|
| 59 | |
---|
| 60 | if ( (func = g_commands[cmd].handler) == NULL ) |
---|
| 61 | return -1; |
---|
| 62 | |
---|
| 63 | ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func); |
---|
| 64 | |
---|
| 65 | return func(client, mes, data); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | int command_get_name (int command, char ** name) { |
---|
| 69 | int cmd = command_get_id_by_cmd(command); |
---|
| 70 | |
---|
| 71 | if ( cmd == -1 ) { |
---|
| 72 | *name = NULL; |
---|
| 73 | return -1; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | *name = g_commands[cmd].name; |
---|
| 77 | |
---|
| 78 | return 0; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | //ll |
---|