source: roaraudio/roard/commands.c @ 1200:7ab8a2d1c9a5

Last change on this file since 1200:7ab8a2d1c9a5 was 1162:d9b136a87245, checked in by phi, 15 years ago

added whoami call

File size: 3.5 KB
Line 
1//commands.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27struct roar_command g_commands[COMMAND_MAX_COMMANDS] = {
28  {ROAR_CMD_NOOP,         "NOOP",         req_on_noop},
29  {ROAR_CMD_IDENTIFY,     "IDENTIFY",     req_on_identify},
30  {ROAR_CMD_AUTH,         "AUTH",         req_on_auth},
31  {ROAR_CMD_WHOAMI,       "WHOAMI",       req_on_whoami},
32
33
34  {ROAR_CMD_NEW_STREAM,   "NEW_STREAM",   req_on_new_stream},
35
36  {ROAR_CMD_SET_META,     "SET_META",     req_on_set_meta},
37  {ROAR_CMD_GET_META,     "GET_META",     req_on_get_meta},
38  {ROAR_CMD_LIST_META,    "LIST_META",    req_on_list_meta},
39
40  {ROAR_CMD_EXEC_STREAM,  "EXEC_STREAM",  req_on_exec_stream},
41  {ROAR_CMD_QUIT,         "QUIT",         (int(*)(int client, struct roar_message * mes, char * data))clients_delete},
42
43  {ROAR_CMD_CON_STREAM,   "CON_STREAM",   req_on_con_stream},
44  {ROAR_CMD_PASSFH,       "PASSFH",       req_on_passfh},
45
46  {ROAR_CMD_SERVER_OINFO, "SERVER_OINFO", req_on_server_oinfo},
47  {ROAR_CMD_GET_STANDBY,  "GET_STANDBY",  req_on_get_standby},
48  {ROAR_CMD_SET_STANDBY,  "SET_STANDBY",  req_on_set_standby},
49  {ROAR_CMD_EXIT,         "EXIT",         req_on_exit},
50
51  {ROAR_CMD_LIST_CLIENTS, "LIST_CLIENTS", req_on_list_clients},
52  {ROAR_CMD_LIST_STREAMS, "LIST_STREAMS", req_on_list_streams},
53  {ROAR_CMD_GET_CLIENT,   "GET_CLIENT",   req_on_get_client},
54  {ROAR_CMD_GET_STREAM,   "GET_STREAM",   req_on_get_stream},
55  {ROAR_CMD_KICK,         "KICK",         req_on_kick},
56  {ROAR_CMD_ATTACH,       "ATTACH",       req_on_attach},
57  {ROAR_CMD_SET_VOL,      "SET_VOL",      req_on_set_vol},
58  {ROAR_CMD_GET_VOL,      "GET_VOL",      req_on_get_vol},
59  {ROAR_CMD_GET_STREAM_PARA, "GET_STREAM_PARA", req_on_get_stream_para},
60  {ROAR_CMD_SET_STREAM_PARA, "SET_STREAM_PARA", req_on_set_stream_para},
61
62  {ROAR_CMD_ADD_DATA,     "ADD_DATA",     req_on_add_data},
63
64  {ROAR_CMD_EOL,          "END OF LIST",  NULL}
65 };
66
67int command_get_id_by_cmd (int command) {
68 int i;
69 int cmd;
70
71 for (i = 0; i < COMMAND_MAX_COMMANDS; i++) {
72  if ( (cmd = g_commands[i].cmd) == ROAR_CMD_EOL )
73   break;
74
75  if ( cmd == command )
76   return i;
77 }
78
79 return -1;
80}
81
82int command_exec (int client, struct roar_message * mes, char * data) {
83 int cmd = command_get_id_by_cmd(mes->cmd);
84 int (*func)(int client, struct roar_message * mes, char * data);
85
86 if ( cmd == -1 )
87  return -1;
88
89 if ( (func = g_commands[cmd].handler) == NULL )
90  return -1;
91
92 ROAR_DBG("command_exec(*): Execing command %i(%s) via %p", cmd, g_commands[cmd].name, func);
93
94 return func(client, mes, data);
95}
96
97int command_get_name (int command, char ** name) {
98 int cmd = command_get_id_by_cmd(command);
99
100 if ( cmd == -1 ) {
101  *name = NULL;
102  return -1;
103 }
104
105 *name = g_commands[cmd].name;
106
107 return 0;
108}
109
110
111//ll
Note: See TracBrowser for help on using the repository browser.