[668] | 1 | //req.c: |
---|
[486] | 2 | |
---|
[668] | 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 | */ |
---|
[0] | 24 | |
---|
| 25 | #include "roard.h" |
---|
| 26 | |
---|
| 27 | int req_on_noop (int client, struct roar_message * mes, char * data) { |
---|
| 28 | mes->cmd = ROAR_CMD_OK; |
---|
| 29 | mes->datalen = 0; |
---|
| 30 | return 0; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | int req_on_identify (int client, struct roar_message * mes, char * data) { |
---|
| 34 | struct roar_client * c; |
---|
| 35 | int max_len; |
---|
| 36 | |
---|
| 37 | if ( mes->datalen < 1 ) |
---|
| 38 | return -1; |
---|
| 39 | |
---|
| 40 | clients_get(client, &c); |
---|
| 41 | |
---|
| 42 | if ( mes->data[0] == 1 ) { |
---|
[436] | 43 | if ( c->pid == -1 ) { |
---|
| 44 | c->pid = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1)); |
---|
[443] | 45 | ROAR_DBG("req_on_identify(): new PID: c->pid = %i", c->pid); |
---|
[436] | 46 | } |
---|
[0] | 47 | |
---|
[443] | 48 | ROAR_DBG("req_on_identify(): final PID: c->pid = %i", c->pid); |
---|
| 49 | |
---|
[0] | 50 | max_len = (mes->datalen - 5) < (ROAR_BUFFER_NAME-1) ? (mes->datalen - 5) : (ROAR_BUFFER_NAME-1); |
---|
| 51 | |
---|
| 52 | strncpy(c->name, mes->data + 5, max_len); |
---|
| 53 | c->name[max_len] = 0; |
---|
| 54 | |
---|
| 55 | mes->cmd = ROAR_CMD_OK; |
---|
| 56 | mes->datalen = 0; |
---|
| 57 | |
---|
| 58 | ROAR_DBG("req_on_identify(*): client=%i, pid=%i", client, c->pid); |
---|
| 59 | ROAR_DBG("req_on_identify(*) = 0"); |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | return -1; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | int req_on_auth (int client, struct roar_message * mes, char * data) { |
---|
| 67 | // TODO: add code to support some auth. |
---|
| 68 | mes->cmd = ROAR_CMD_OK; |
---|
| 69 | mes->datalen = 0; |
---|
| 70 | return 0; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | int req_on_new_stream (int client, struct roar_message * mes, char * data) { |
---|
| 75 | int stream; |
---|
| 76 | struct roar_stream * s; |
---|
| 77 | |
---|
| 78 | if ((stream = streams_new()) == -1 ) |
---|
| 79 | return -1; |
---|
| 80 | |
---|
| 81 | if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) { |
---|
| 82 | streams_delete(stream); |
---|
| 83 | return -1; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if ( client_stream_add(client, stream) == -1 ) { |
---|
| 87 | streams_delete(stream); |
---|
| 88 | return -1; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if ( roar_stream_m2s(s, mes) == -1 ) { |
---|
| 92 | streams_delete(stream); |
---|
| 93 | return -1; |
---|
| 94 | } |
---|
| 95 | |
---|
[486] | 96 | ROAR_STREAM(s)->id = stream; // roar_stream_m2s() resets this |
---|
[539] | 97 | ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM(s)->info.codec; |
---|
[486] | 98 | |
---|
[0] | 99 | mes->cmd = ROAR_CMD_OK; |
---|
| 100 | mes->stream = stream; |
---|
| 101 | mes->datalen = 0; |
---|
| 102 | |
---|
| 103 | return 0; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | int req_on_exec_stream (int client, struct roar_message * mes, char * data) { |
---|
| 107 | int r; |
---|
| 108 | |
---|
| 109 | if ( (r = client_stream_exec(client, mes->stream)) == -1 ) |
---|
| 110 | return -1; |
---|
| 111 | |
---|
| 112 | mes->cmd = ROAR_CMD_OK; |
---|
| 113 | mes->datalen = 0; |
---|
| 114 | |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
[77] | 118 | int req_on_con_stream (int client, struct roar_message * mes, char * data) { |
---|
| 119 | char host[80] = {0}; |
---|
| 120 | int port = 0; |
---|
| 121 | int type; |
---|
| 122 | int fh; |
---|
| 123 | int len; |
---|
| 124 | |
---|
| 125 | if ( mes->datalen < 4 ) |
---|
| 126 | return -1; |
---|
| 127 | |
---|
| 128 | if ( *(mes->data) != 0 ) |
---|
| 129 | return -1; |
---|
| 130 | |
---|
[80] | 131 | if ( mes->datalen > 80 ) // we do not support long messages here |
---|
| 132 | return -1; |
---|
| 133 | |
---|
[77] | 134 | type = (unsigned)mes->data[1]; |
---|
[79] | 135 | port = ROAR_NET2HOST16(((uint16_t*)mes->data)[1]); |
---|
[77] | 136 | |
---|
[80] | 137 | len = mes->datalen - 4; |
---|
[77] | 138 | |
---|
[84] | 139 | strncpy(host, &(mes->data[4]), len); |
---|
[77] | 140 | host[len] = 0; |
---|
| 141 | |
---|
| 142 | if ( type > ROAR_SOCKET_TYPE_MAX ) |
---|
| 143 | return -1; |
---|
| 144 | |
---|
| 145 | if ( type == ROAR_SOCKET_TYPE_FILE ) // disabled because of security resons |
---|
| 146 | return -1; |
---|
| 147 | |
---|
| 148 | if ( type == ROAR_SOCKET_TYPE_FORK ) // why should we connect to ourself? |
---|
| 149 | return -1; |
---|
| 150 | |
---|
[525] | 151 | ROAR_DBG("req_on_con_stream(*): CONNECT(type=%i, host='%s', port=%i)", type, host, port); |
---|
| 152 | |
---|
[77] | 153 | if ( (fh = roar_socket_open(ROAR_SOCKET_MODE_CONNECT, type, host, port)) == -1 ) |
---|
| 154 | return -1; |
---|
| 155 | |
---|
[78] | 156 | if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) { |
---|
| 157 | close(fh); |
---|
| 158 | return 1; |
---|
| 159 | } |
---|
| 160 | |
---|
[757] | 161 | mes->datalen = 0; |
---|
| 162 | mes->cmd = ROAR_CMD_OK; |
---|
| 163 | |
---|
[78] | 164 | return 0; |
---|
[757] | 165 | } |
---|
| 166 | |
---|
| 167 | int req_on_passfh (int client, struct roar_message * mes, char * data) { |
---|
| 168 | int fh; |
---|
| 169 | int sock = clients_get_fh(client); |
---|
| 170 | |
---|
| 171 | if ( (fh = roar_socket_recv_fh(sock, NULL, NULL)) == -1 ) |
---|
| 172 | return -1; |
---|
| 173 | |
---|
| 174 | if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) { |
---|
| 175 | close(fh); |
---|
| 176 | return 1; |
---|
| 177 | } |
---|
| 178 | |
---|
[78] | 179 | |
---|
| 180 | mes->datalen = 0; |
---|
| 181 | mes->cmd = ROAR_CMD_OK; |
---|
[757] | 182 | |
---|
| 183 | return 0; |
---|
[77] | 184 | } |
---|
| 185 | |
---|
[0] | 186 | int req_on_set_meta (int client, struct roar_message * mes, char * data) { |
---|
[92] | 187 | int type; |
---|
| 188 | int mode; |
---|
| 189 | int namelen, vallen; |
---|
[99] | 190 | char val[255+1]; |
---|
[92] | 191 | char name[ROAR_META_MAX_NAMELEN+1]; |
---|
| 192 | |
---|
| 193 | if ( mes->datalen < 3 ) |
---|
| 194 | return -1; |
---|
| 195 | |
---|
| 196 | if ( mes->data[0] != 0 ) // version |
---|
| 197 | return -1; |
---|
| 198 | |
---|
| 199 | mode = (unsigned) mes->data[1]; |
---|
| 200 | type = (unsigned) mes->data[2]; |
---|
| 201 | |
---|
[99] | 202 | ROAR_DBG("req_on_set_meta(*): mode=%i, type=%i", mode, type); |
---|
| 203 | |
---|
[92] | 204 | if ( mode == ROAR_META_MODE_CLEAR ) { |
---|
| 205 | stream_meta_clear(mes->stream); |
---|
| 206 | mes->datalen = 0; |
---|
| 207 | mes->cmd = ROAR_CMD_OK; |
---|
| 208 | return 0; |
---|
| 209 | } else if ( mode == ROAR_META_MODE_DELETE ) { // unsuppoerted at the moment |
---|
| 210 | } else if ( mode == ROAR_META_MODE_SET || mode == ROAR_META_MODE_ADD ) { |
---|
| 211 | if ( mes->datalen < 5 ) |
---|
| 212 | return -1; |
---|
| 213 | |
---|
| 214 | namelen = (unsigned) mes->data[3]; |
---|
| 215 | vallen = (unsigned) mes->data[4]; |
---|
| 216 | |
---|
[99] | 217 | ROAR_DBG("req_on_set_meta(*): namelen=%i, vallen=%i", namelen, vallen); |
---|
| 218 | |
---|
[92] | 219 | if ( mes->datalen < (5 + namelen + vallen) ) |
---|
| 220 | return -1; |
---|
| 221 | |
---|
| 222 | if ( namelen > ROAR_META_MAX_NAMELEN ) |
---|
| 223 | return -1; |
---|
| 224 | |
---|
| 225 | strncpy(name, &(mes->data[5]), namelen); |
---|
| 226 | name[namelen] = 0; |
---|
| 227 | |
---|
[99] | 228 | if ( vallen > 255 ) |
---|
[92] | 229 | return -1; |
---|
| 230 | |
---|
| 231 | strncpy(val, &(mes->data[5+namelen]), vallen); |
---|
| 232 | val[vallen] = 0; |
---|
| 233 | |
---|
| 234 | if ( mode == ROAR_META_MODE_SET ) { |
---|
| 235 | if ( stream_meta_set(mes->stream, type, name, val) == -1 ) |
---|
| 236 | return -1; |
---|
| 237 | } else { |
---|
| 238 | if ( stream_meta_add(mes->stream, type, name, val) == -1 ) |
---|
| 239 | return -1; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | mes->datalen = 0; |
---|
| 243 | mes->cmd = ROAR_CMD_OK; |
---|
| 244 | return 0; |
---|
| 245 | } else { // unknown mode! |
---|
| 246 | return -1; |
---|
| 247 | } |
---|
| 248 | |
---|
[0] | 249 | return -1; |
---|
| 250 | } |
---|
| 251 | |
---|
[100] | 252 | int req_on_get_meta (int client, struct roar_message * mes, char * data) { |
---|
[101] | 253 | int vallen; |
---|
| 254 | int type; |
---|
[107] | 255 | char val[LIBROAR_BUFFER_MSGDATA-1]; |
---|
[101] | 256 | |
---|
| 257 | if ( mes->datalen != 2 ) |
---|
| 258 | return -1; |
---|
| 259 | |
---|
| 260 | if ( mes->data[0] != 0 ) // version |
---|
| 261 | return -1; |
---|
| 262 | |
---|
| 263 | type = (unsigned) mes->data[1]; |
---|
| 264 | |
---|
| 265 | if ( stream_meta_get(mes->stream, type, NULL, val, LIBROAR_BUFFER_MSGDATA-2) == -1 ) |
---|
| 266 | return -1; |
---|
| 267 | |
---|
| 268 | vallen = strlen(val); |
---|
| 269 | |
---|
| 270 | mes->cmd = ROAR_CMD_OK; |
---|
| 271 | mes->datalen = 2 + vallen; |
---|
| 272 | |
---|
| 273 | mes->data[0] = 0; |
---|
| 274 | mes->data[1] = (unsigned char) vallen; |
---|
| 275 | |
---|
[107] | 276 | val[vallen] = 0; |
---|
| 277 | |
---|
| 278 | strncpy(&(mes->data[2]), val, vallen+1); |
---|
[101] | 279 | |
---|
| 280 | return 0; |
---|
[100] | 281 | } |
---|
[0] | 282 | |
---|
[113] | 283 | int req_on_list_meta (int client, struct roar_message * mes, char * data) { |
---|
| 284 | int i; |
---|
| 285 | int len = 0; |
---|
| 286 | int types[ROAR_META_MAX_PER_STREAM]; |
---|
| 287 | |
---|
| 288 | if ( mes->datalen != 1 ) |
---|
| 289 | return -1; |
---|
| 290 | |
---|
| 291 | if ( mes->data[0] != 0 ) // version |
---|
| 292 | return -1; |
---|
| 293 | |
---|
| 294 | if ( (len = stream_meta_list(mes->stream, types, ROAR_META_MAX_PER_STREAM)) == -1 ) |
---|
| 295 | return -1; |
---|
| 296 | |
---|
| 297 | mes->cmd = ROAR_CMD_OK; |
---|
| 298 | mes->datalen = 1 + len; |
---|
| 299 | mes->data[0] = 0; |
---|
| 300 | |
---|
| 301 | for (i = 0; i < len; i++) |
---|
| 302 | mes->data[i+1] = types[i]; |
---|
| 303 | |
---|
| 304 | return 0; |
---|
| 305 | } |
---|
| 306 | |
---|
[0] | 307 | int req_on_server_oinfo (int client, struct roar_message * mes, char * data) { |
---|
| 308 | struct roar_stream s; |
---|
| 309 | //ROAR_DIR_OUTPUT |
---|
| 310 | |
---|
| 311 | s.dir = ROAR_DIR_OUTPUT; |
---|
| 312 | s.pos_rel_id = -1; |
---|
| 313 | s.info.rate = g_sa->rate; |
---|
| 314 | s.info.bits = g_sa->bits; |
---|
| 315 | s.info.channels = g_sa->channels; |
---|
| 316 | s.info.codec = g_sa->codec; |
---|
| 317 | |
---|
| 318 | if ( roar_stream_s2m(&s, mes) == -1 ) |
---|
| 319 | return -1; |
---|
| 320 | |
---|
| 321 | mes->cmd = ROAR_CMD_OK; |
---|
| 322 | |
---|
| 323 | return 0; |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | |
---|
| 327 | int req_on_get_standby (int client, struct roar_message * mes, char * data) { |
---|
| 328 | mes->cmd = ROAR_CMD_OK; |
---|
| 329 | mes->datalen = 2; |
---|
| 330 | |
---|
| 331 | *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby); |
---|
| 332 | |
---|
| 333 | return 0; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | int req_on_set_standby (int client, struct roar_message * mes, char * data) { |
---|
| 337 | if ( mes->datalen != 2 ) |
---|
| 338 | return -1; |
---|
| 339 | |
---|
| 340 | g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data)); |
---|
| 341 | |
---|
| 342 | mes->cmd = ROAR_CMD_OK; |
---|
| 343 | mes->datalen = 0; |
---|
| 344 | |
---|
| 345 | return 0; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | int req_on_exit (int client, struct roar_message * mes, char * data) { |
---|
[575] | 349 | int term = 0; |
---|
| 350 | |
---|
| 351 | if ( mes->datalen == 1 ) |
---|
| 352 | term = mes->data[0]; |
---|
| 353 | |
---|
[0] | 354 | mes->cmd = ROAR_CMD_OK; |
---|
| 355 | mes->datalen = 0; |
---|
| 356 | |
---|
[576] | 357 | ROAR_DBG("req_on_exit(*): term=%i", term); |
---|
| 358 | |
---|
[575] | 359 | if ( term ) { |
---|
| 360 | cleanup_listen_socket(1); |
---|
| 361 | } else { |
---|
| 362 | alive = 0; |
---|
| 363 | } |
---|
[0] | 364 | |
---|
| 365 | return 0; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | int req_on_list_clients(int client, struct roar_message * mes, char * data) { |
---|
| 369 | unsigned char filter, cmp; |
---|
| 370 | uint32_t id; |
---|
| 371 | int clients[ROAR_CLIENTS_MAX]; |
---|
| 372 | int i, c = 0; |
---|
| 373 | |
---|
| 374 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 375 | return -1; |
---|
| 376 | |
---|
| 377 | // TODO: add code to support filter |
---|
| 378 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 379 | return -1; |
---|
| 380 | |
---|
| 381 | for (i = 0; i < ROAR_CLIENTS_MAX; i++) { |
---|
| 382 | if ( g_clients[i] != NULL ) { |
---|
| 383 | clients[c++] = i; |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | roar_ctl_ia2m(mes, clients, c); |
---|
| 388 | |
---|
| 389 | mes->cmd = ROAR_CMD_OK; |
---|
| 390 | |
---|
| 391 | return 0; |
---|
| 392 | } |
---|
| 393 | int req_on_list_streams(int client, struct roar_message * mes, char * data) { |
---|
| 394 | unsigned char filter, cmp; |
---|
| 395 | uint32_t id; |
---|
| 396 | int streams[ROAR_STREAMS_MAX]; |
---|
| 397 | int i, c = 0; |
---|
| 398 | |
---|
| 399 | if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 ) |
---|
| 400 | return -1; |
---|
| 401 | |
---|
| 402 | // TODO: add code to support filter |
---|
| 403 | if ( filter != ROAR_CTL_FILTER_ANY ) |
---|
| 404 | return -1; |
---|
| 405 | |
---|
| 406 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 407 | if ( g_streams[i] != NULL ) { |
---|
| 408 | streams[c++] = i; |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | roar_ctl_ia2m(mes, streams, c); |
---|
| 413 | |
---|
| 414 | mes->cmd = ROAR_CMD_OK; |
---|
| 415 | |
---|
| 416 | return 0; |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | int req_on_get_client (int client, struct roar_message * mes, char * data) { |
---|
| 420 | struct roar_client * c; |
---|
| 421 | |
---|
| 422 | if ( mes->datalen != 1 ) |
---|
| 423 | return -1; |
---|
| 424 | |
---|
| 425 | if ( clients_get(mes->data[0], &c) == -1 ) |
---|
| 426 | return -1; |
---|
| 427 | |
---|
| 428 | mes->cmd = ROAR_CMD_OK; |
---|
| 429 | |
---|
| 430 | return roar_ctl_c2m(mes, c); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | int req_on_get_stream (int client, struct roar_message * mes, char * data) { |
---|
| 434 | struct roar_stream_server * s; |
---|
| 435 | |
---|
| 436 | if ( mes->datalen != 1 ) |
---|
| 437 | return -1; |
---|
| 438 | |
---|
| 439 | if ( streams_get(mes->data[0], &s) == -1 ) |
---|
| 440 | return -1; |
---|
| 441 | |
---|
| 442 | mes->cmd = ROAR_CMD_OK; |
---|
[465] | 443 | mes->stream = mes->data[0]; |
---|
[0] | 444 | |
---|
| 445 | return roar_stream_s2m(ROAR_STREAM(s), mes); |
---|
| 446 | } |
---|
| 447 | |
---|
[465] | 448 | int req_on_get_stream_para (int client, struct roar_message * mes, char * data) { |
---|
| 449 | struct roar_stream * s; |
---|
| 450 | struct roar_audio_info * audio_info; |
---|
| 451 | uint16_t * d = (uint16_t *) mes->data; |
---|
| 452 | int i; |
---|
| 453 | |
---|
| 454 | if ( mes->datalen != 4 ) |
---|
| 455 | return -1; |
---|
| 456 | |
---|
| 457 | for (i = 0; i < mes->datalen/2; i++) { |
---|
| 458 | d[i] = ROAR_NET2HOST16(d[i]); |
---|
| 459 | } |
---|
| 460 | |
---|
[490] | 461 | if ( streams_get(mes->stream, (struct roar_stream_server **)&s) == -1 ) { |
---|
[465] | 462 | ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream); |
---|
| 463 | return -1; |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | audio_info = &(s->info); |
---|
| 467 | |
---|
| 468 | if ( d[0] != 0 || d[1] != 1 ) { |
---|
| 469 | ROAR_WARN("req_on_get_stream_para(*): unsupported command version: %i, %i", d[0], d[1]); |
---|
| 470 | return -1; |
---|
| 471 | } |
---|
| 472 | |
---|
[539] | 473 | mes->datalen = 2*6; |
---|
[465] | 474 | |
---|
| 475 | d[2] = ROAR_OUTPUT_CALC_OUTBUFSIZE(audio_info); |
---|
[496] | 476 | d[3] = ROAR_STREAM_SERVER(s)->pre_underruns; |
---|
| 477 | d[4] = ROAR_STREAM_SERVER(s)->post_underruns; |
---|
[540] | 478 | d[5] = ROAR_STREAM_SERVER(s)->codec_orgi; |
---|
[465] | 479 | |
---|
| 480 | for (i = 0; i < mes->datalen/2; i++) { |
---|
| 481 | d[i] = ROAR_HOST2NET16(d[i]); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | mes->cmd = ROAR_CMD_OK; |
---|
| 485 | return 0; |
---|
| 486 | } |
---|
| 487 | |
---|
[0] | 488 | int req_on_kick (int client, struct roar_message * mes, char * data) { |
---|
[17] | 489 | uint16_t * info = (uint16_t *) mes->data; |
---|
[0] | 490 | |
---|
| 491 | if ( mes->datalen != 4 ) |
---|
| 492 | return -1; |
---|
| 493 | |
---|
[251] | 494 | info[0] = ROAR_NET2HOST16(info[0]); |
---|
| 495 | info[1] = ROAR_NET2HOST16(info[1]); |
---|
| 496 | |
---|
[0] | 497 | if ( info[0] == ROAR_OT_CLIENT ) { |
---|
| 498 | clients_delete(info[1]); |
---|
| 499 | } else if ( info[0] == ROAR_OT_STREAM ) { |
---|
| 500 | streams_delete(info[1]); |
---|
| 501 | } else { |
---|
| 502 | return -1; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | mes->cmd = ROAR_CMD_OK; |
---|
| 506 | mes->datalen = 0; |
---|
| 507 | |
---|
| 508 | return 0; |
---|
| 509 | } |
---|
| 510 | |
---|
[768] | 511 | int req_on_attach (int client, struct roar_message * mes, char * data) { |
---|
[769] | 512 | uint16_t * info = (uint16_t *) mes->data; |
---|
| 513 | |
---|
| 514 | if ( mes->datalen < 6 ) |
---|
| 515 | return -1; |
---|
| 516 | |
---|
| 517 | info[0] = ROAR_NET2HOST16(info[0]); |
---|
| 518 | info[1] = ROAR_NET2HOST16(info[1]); |
---|
| 519 | info[2] = ROAR_NET2HOST16(info[2]); |
---|
| 520 | |
---|
| 521 | if ( info[0] != 0 ) |
---|
| 522 | return -1; |
---|
| 523 | |
---|
| 524 | if ( info[1] == ROAR_ATTACH_SIMPLE ) { |
---|
| 525 | if ( client_stream_move(info[2], mes->stream) == -1 ) |
---|
| 526 | return -1; |
---|
| 527 | } else { |
---|
| 528 | return -1; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | mes->cmd = ROAR_CMD_OK; |
---|
| 532 | mes->datalen = 0; |
---|
| 533 | |
---|
| 534 | return 0; |
---|
[768] | 535 | } |
---|
| 536 | |
---|
[17] | 537 | int req_on_set_vol (int client, struct roar_message * mes, char * data) { |
---|
| 538 | uint16_t * info = (uint16_t *) mes->data; |
---|
| 539 | int stream; |
---|
| 540 | struct roar_stream_server * s; |
---|
| 541 | int i; |
---|
| 542 | int chans; |
---|
| 543 | |
---|
| 544 | ROAR_DBG("req_on_set_vol(*) = ?"); |
---|
| 545 | ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen); |
---|
| 546 | |
---|
| 547 | if ( mes->datalen < (4*2) ) |
---|
| 548 | return -1; |
---|
| 549 | |
---|
| 550 | if ( info[0] != 0 ) // version |
---|
| 551 | return -1; |
---|
| 552 | |
---|
[252] | 553 | stream = ROAR_NET2HOST16(info[1]); |
---|
[17] | 554 | ROAR_DBG("req_on_set_vol(*): stream=%i", stream); |
---|
| 555 | |
---|
| 556 | // TODO: change this code. |
---|
| 557 | // we should not directly change the stream object but use some stream_*()-func |
---|
| 558 | // for that job. |
---|
| 559 | |
---|
| 560 | if ( stream < 0 || stream >= ROAR_STREAMS_MAX ) |
---|
| 561 | return -1; |
---|
| 562 | |
---|
| 563 | s = g_streams[stream]; |
---|
| 564 | |
---|
| 565 | if ( s == NULL ) |
---|
| 566 | return -1; |
---|
| 567 | |
---|
| 568 | ROAR_DBG("req_on_set_vol(*): s=%p", s); |
---|
| 569 | |
---|
[252] | 570 | info[2] = ROAR_NET2HOST16(info[2]); |
---|
| 571 | |
---|
[17] | 572 | if ( info[2] == ROAR_SET_VOL_ALL ) { |
---|
| 573 | chans = (mes->datalen/2) - 3; |
---|
| 574 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans); |
---|
| 575 | |
---|
| 576 | if ( chans >= ROAR_MAX_CHANNELS ) |
---|
| 577 | return -1; |
---|
| 578 | |
---|
[18] | 579 | ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer); |
---|
| 580 | |
---|
[17] | 581 | for (i = 0; i < chans; i++) { |
---|
[252] | 582 | s->mixer.mixer[i] = ROAR_NET2HOST16(info[i+3]); |
---|
| 583 | ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, ROAR_NET2HOST16(info[i+3])); |
---|
[17] | 584 | } |
---|
| 585 | |
---|
| 586 | ROAR_DBG("req_on_set_vol(*): mixer changed!"); |
---|
| 587 | |
---|
| 588 | } else if ( info[2] == ROAR_SET_VOL_ONE ) { |
---|
| 589 | ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE"); |
---|
[252] | 590 | if ( ROAR_NET2HOST16(info[3]) >= ROAR_MAX_CHANNELS ) |
---|
[17] | 591 | return -1; |
---|
| 592 | |
---|
[252] | 593 | s->mixer.mixer[ROAR_NET2HOST16(info[3])] = ROAR_NET2HOST16(info[4]); |
---|
[17] | 594 | } else { |
---|
| 595 | return -1; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | mes->cmd = ROAR_CMD_OK; |
---|
| 599 | mes->datalen = 0; |
---|
| 600 | |
---|
| 601 | return 0; |
---|
| 602 | } |
---|
[0] | 603 | |
---|
[23] | 604 | int req_on_get_vol (int client, struct roar_message * mes, char * data) { |
---|
| 605 | uint16_t * info = (uint16_t *) mes->data; |
---|
| 606 | int stream; |
---|
| 607 | struct roar_stream_server * s; |
---|
| 608 | int i; |
---|
| 609 | int chans; |
---|
| 610 | |
---|
| 611 | ROAR_DBG("req_on_get_vol(*) = ?"); |
---|
| 612 | ROAR_DBG("req_on_get_vol(*): mes->datalen=%i", mes->datalen); |
---|
| 613 | |
---|
| 614 | if ( mes->datalen < (2*2) ) |
---|
| 615 | return -1; |
---|
| 616 | |
---|
| 617 | if ( info[0] != 0 ) // version |
---|
| 618 | return -1; |
---|
| 619 | |
---|
[252] | 620 | stream = ROAR_NET2HOST16(info[1]); |
---|
[23] | 621 | ROAR_DBG("req_on_get_vol(*): stream=%i", stream); |
---|
| 622 | |
---|
| 623 | // TODO: change this code. |
---|
| 624 | // we should not directly change the stream object but use some stream_*()-func |
---|
| 625 | // for that job. |
---|
| 626 | |
---|
| 627 | if ( stream < 0 || stream >= ROAR_STREAMS_MAX ) |
---|
| 628 | return -1; |
---|
| 629 | |
---|
| 630 | s = g_streams[stream]; |
---|
| 631 | |
---|
| 632 | if ( s == NULL ) |
---|
| 633 | return -1; |
---|
| 634 | |
---|
| 635 | ROAR_DBG("req_on_get_vol(*): s=%p", s); |
---|
| 636 | |
---|
| 637 | // ok, we have everything |
---|
| 638 | |
---|
| 639 | info[0] = 0; |
---|
[252] | 640 | info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels); |
---|
[23] | 641 | |
---|
| 642 | for (i = 0; i < chans; i++) |
---|
[252] | 643 | info[2+i] = ROAR_HOST2NET16(s->mixer.mixer[i]); |
---|
[23] | 644 | |
---|
| 645 | mes->datalen = (2 + chans)*2; |
---|
| 646 | mes->cmd = ROAR_CMD_OK; |
---|
| 647 | |
---|
| 648 | return 0; |
---|
| 649 | } |
---|
| 650 | |
---|
[0] | 651 | int req_on_add_data (int client, struct roar_message * mes, char * data) { |
---|
| 652 | struct roar_buffer * b; |
---|
| 653 | char * buf; |
---|
| 654 | |
---|
| 655 | if ( roar_buffer_new(&b, mes->datalen) == -1 ) { |
---|
| 656 | ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!"); |
---|
| 657 | ROAR_DBG("req_on_add_data(*) = -1"); |
---|
| 658 | return -1; |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | roar_buffer_get_data(b, (void **)&buf); |
---|
| 662 | |
---|
| 663 | if ( data == NULL ) { |
---|
| 664 | memcpy(buf, mes->data, mes->datalen); |
---|
| 665 | } else { |
---|
| 666 | memcpy(buf, data, mes->datalen); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | if ( stream_add_buffer(mes->stream, b) == -1 ) { |
---|
| 670 | roar_buffer_free(b); |
---|
| 671 | return -1; |
---|
| 672 | } |
---|
| 673 | |
---|
[498] | 674 | mes->cmd = ROAR_CMD_OK_STOP; |
---|
[0] | 675 | mes->datalen = 0; |
---|
| 676 | |
---|
| 677 | return 0; |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | //ll |
---|