source: roaraudio/roard/req.c @ 4441:f874513f7f15

Last change on this file since 4441:f874513f7f15 was 4441:f874513f7f15, checked in by phi, 14 years ago

get large data support in server_info working

File size: 35.1 KB
Line 
1//req.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28// include for uname() used by req_on_server_info()
29#ifdef ROAR_HAVE_UNAME
30#include <sys/utsname.h>
31#endif
32
33static void * _dataspace(struct roar_message * mes, char ** data, uint32_t flags[2], size_t len) {
34 if ( len <= LIBROAR_BUFFER_MSGDATA )
35  return mes->data;
36
37 if ( *data != NULL )
38  free(*data);
39
40 *data = malloc(len);
41
42 ROAR_DBG("_dataspace(mes=%p, data=%p, flags=%p, len=%llu): *data=%p", mes, data, flags, (long long unsigned int)len, *data);
43
44 if ( *data == NULL )
45  return NULL;
46
47 flags[1] |= COMMAND_FLAG_OUT_LONGDATA;
48
49 return *data;
50}
51
52int req_on_noop        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
53 mes->cmd     = ROAR_CMD_OK;
54 mes->pos     = g_pos;
55 mes->datalen = 0;
56 return 0;
57}
58
59int req_on_identify    (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
60 struct roar_client * c;
61 int max_len;
62
63 if ( mes->datalen < 1 )
64  return -1;
65
66 clients_get(client, &c);
67
68 if ( mes->data[0] == 1 ) {
69  if ( c->pid == -1 ) {
70   c->pid       = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1));
71   ROAR_DBG("req_on_identify(): new PID: c->pid = %i", c->pid);
72  }
73
74  ROAR_DBG("req_on_identify(): final PID: c->pid = %i", c->pid);
75
76  max_len = (mes->datalen - 5) < (ROAR_BUFFER_NAME-1) ? (mes->datalen - 5) : (ROAR_BUFFER_NAME-1);
77
78  strncpy(c->name, mes->data + 5, max_len);
79  c->name[max_len] = 0;
80
81  mes->cmd     = ROAR_CMD_OK;
82  mes->pos     = g_pos;
83  mes->datalen = 0;
84
85  ROAR_DBG("req_on_identify(*): client=%i, pid=%i", client, c->pid);
86  ROAR_DBG("req_on_identify(*) = 0");
87  return 0;
88 }
89
90 return -1;
91}
92
93int req_on_auth        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
94 // TODO: add code to support some auth.
95 mes->cmd     = ROAR_CMD_OK;
96 mes->pos     = g_pos;
97 mes->datalen = 0;
98 return 0;
99}
100
101
102int req_on_whoami      (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
103 mes->cmd     = ROAR_CMD_OK;
104 mes->pos     = g_pos;
105 mes->datalen = 1;
106 mes->data[0] = client;
107 return 0;
108}
109
110
111int req_on_new_stream  (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
112 int stream;
113 struct roar_stream * s;
114 struct roar_stream * source_stream;
115 struct roar_audio_info * info;
116 struct roar_audio_info * source_info;
117
118 ROAR_DBG("req_on_new_stream(client=%i, ...): creating stream...", client);
119 if ((stream = streams_new()) == -1 )
120  return -1;
121
122 ROAR_DBG("req_on_new_stream(client=%i, ...): stream=%i", client, stream);
123
124 ROAR_DBG("req_on_new_stream(client=%i, ...): getting stream...", client);
125 if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) {
126  streams_delete(stream);
127  return -1;
128 }
129
130 ROAR_DBG("req_on_new_stream(client=%i, ...): set client of stream...", client);
131 if ( client_stream_add(client, stream) == -1 ) {
132  streams_delete(stream);
133  return -1;
134 }
135
136 ROAR_DBG("req_on_new_stream(client=%i, ...): loading stream from message...", client);
137 if ( roar_stream_m2s(s, mes) == -1 ) {
138  streams_delete(stream);
139  return -1;
140 }
141
142 ROAR_DBG("req_on_new_stream(client=%i, ...): setting id and codec of stream...", client);
143 ROAR_STREAM(s)->id = stream; // roar_stream_m2s() resets this
144 ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM(s)->info.codec;
145
146 ROAR_DBG("req_on_new_stream(client=%i, ...): setting direction stream...", client);
147 // int streams_set_dir    (int id, int dir, int defaults)
148 if ( streams_set_dir(stream, ROAR_STREAM(s)->dir, 1) == -1 ) {
149  streams_delete(stream);
150  return -1;
151 }
152
153 ROAR_DBG("req_on_new_stream(client=%i, ...): setting up direction specific stream settings...", client);
154 switch (ROAR_STREAM(s)->dir) {
155  case ROAR_DIR_LIGHT_IN:
156  case ROAR_DIR_LIGHT_OUT:
157#ifndef ROAR_WITHOUT_DCOMP_LIGHT
158    info = &(ROAR_STREAM(s)->info);
159
160    info->channels = 0;
161    info->bits     = 0;
162    info->rate     = 0;
163#else
164    streams_delete(stream);
165    return -1;
166#endif
167
168   break;
169  case ROAR_DIR_MIDI_IN:
170  case ROAR_DIR_MIDI_OUT:
171#ifndef ROAR_WITHOUT_DCOMP_MIDI
172    info = &(ROAR_STREAM(s)->info);
173
174    info->channels = ROAR_MIDI_CHANNELS_DEFAULT;
175    info->bits     = ROAR_MIDI_BITS;
176    info->rate     = 0;
177#else
178    streams_delete(stream);
179    return -1;
180#endif
181
182   break;
183
184  case ROAR_DIR_RAW_IN:
185#ifndef ROAR_WITHOUT_DCOMP_RAW
186    if ( ROAR_STREAM(s)->pos_rel_id == -1     ||
187         ROAR_STREAM(s)->pos_rel_id == stream ||
188         streams_get_dir(ROAR_STREAM(s)->pos_rel_id) != ROAR_DIR_RAW_OUT
189       ) {
190     ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting
191                                      // in case rel_id == stream
192     streams_delete(stream);
193     return -1;
194    }
195#else
196  case ROAR_DIR_RAW_OUT:
197    streams_delete(stream);
198    return -1;
199#endif
200
201   break;
202  case ROAR_DIR_THRU:
203
204    if ( ROAR_STREAM(s)->pos_rel_id == -1 || ROAR_STREAM(s)->pos_rel_id == stream ) {
205     ROAR_STREAM(s)->pos_rel_id = -1; // force this here as it will try to delete itself while deleting
206                                      // in case rel_id == stream
207     streams_delete(stream);
208     return -1;
209    }
210
211    if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) {
212     streams_delete(stream);
213     return -1;
214    }
215
216    info        = &(ROAR_STREAM(s)->info);
217    source_info = &(ROAR_STREAM(source_stream)->info);
218
219    info->channels = source_info->channels;
220    info->bits     = source_info->bits;
221    info->rate     = source_info->rate;
222    info->codec    = source_info->codec;
223    ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM_SERVER(source_stream)->codec_orgi;
224
225   break;
226  case ROAR_DIR_FILTER:
227    info        = &(ROAR_STREAM(s)->info);
228
229    if ( ROAR_STREAM(s)->pos_rel_id == -1 ) {
230     source_info = g_sa;
231    } else {
232     if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) {
233      streams_delete(stream);
234      return -1;
235     }
236     source_info = &(ROAR_STREAM(source_stream)->info);
237    }
238
239    if ( info->channels != source_info->channels || info->bits != source_info->bits ||
240         info->codec    != source_info->codec    || info->rate != source_info->rate ) {
241     // the stream parameters don't match the one of the stream being filtered.
242     // -> delete and reject the stream.
243     streams_delete(stream);
244     return -1;
245    }
246   break;
247 }
248
249 ROAR_DBG("req_on_new_stream(client=%i, ...): returning (OK, stream=%i)...", client, stream);
250
251 mes->cmd     = ROAR_CMD_OK;
252 mes->stream  = stream;
253 mes->datalen = 0;
254
255 return 0;
256}
257
258int req_on_exec_stream (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
259 int r;
260
261 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): execing stream", client, mes->stream);
262
263
264 if ( streams_is_ready(mes->stream) ) {
265  flags[1] |= COMMAND_FLAG_OUT_CLOSECON;
266 } else {
267  if ( (r = client_stream_exec(client, mes->stream)) == -1 )
268   return -1;
269 }
270
271 ROAR_DBG("req_on_exec_stream(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream);
272 mes->cmd     = ROAR_CMD_OK;
273 mes->datalen = 0;
274
275 return 0;
276}
277
278int req_on_con_stream  (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
279 char   host[80] = {0};
280 int    port = 0;
281 int    type;
282 int    fh;
283 int    len;
284
285 if ( mes->datalen < 4 )
286  return -1;
287
288 if ( *(mes->data) != 0 )
289  return -1;
290
291 if ( mes->datalen > 80 ) // we do not support long messages here
292  return -1;
293
294 type = (unsigned)mes->data[1];
295 port = ROAR_NET2HOST16(((uint16_t*)mes->data)[1]);
296
297 len = mes->datalen - 4;
298
299 strncpy(host, &(mes->data[4]), len);
300 host[len] = 0;
301
302 if ( type > ROAR_SOCKET_TYPE_MAX )
303  return -1;
304
305 if ( type == ROAR_SOCKET_TYPE_FILE ) // disabled because of security resons
306  return -1;
307
308 if ( type == ROAR_SOCKET_TYPE_FORK ) // why should we connect to ourself?
309  return -1;
310
311 ROAR_DBG("req_on_con_stream(*): CONNECT(type=%i, host='%s', port=%i)", type, host, port);
312
313 if ( (fh = roar_socket_open(ROAR_SOCKET_MODE_CONNECT, type, host, port)) == -1 )
314  return -1;
315
316 if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
317  close(fh);
318  return 1;
319 }
320
321 mes->datalen = 0;
322 mes->cmd     = ROAR_CMD_OK;
323
324 return 0;
325}
326
327int req_on_passfh      (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
328 int sock = clients_get_fh(client);
329 int16_t * d = (int16_t*)mes->data;
330 struct roard_listen * lsock;
331 int listening;
332 int fh;
333 int i;
334
335 ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...) = ?", client, mes->stream);
336
337 if ( (fh = roar_socket_recv_fh(sock, NULL, NULL)) == -1 ) {
338  ROAR_WARN("req_on_passfh(client=%i, mes={stream=%i,...},...): was unabled to get filehandle from remote end. bad.", client, mes->stream);
339  ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): returning (ERROR)...", client, mes->stream);
340  return -1;
341 }
342
343 ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): fh=%i", client, mes->stream, fh);
344
345 if ( mes->stream != -1 ) { // stream pass:
346  ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): This is a stream passfh", client, mes->stream);
347
348  if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
349   close(fh);
350   ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): returning (ERROR)...", client, mes->stream);
351   return -1;
352  }
353
354  ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream);
355
356  mes->datalen = 0;
357  mes->cmd     = ROAR_CMD_OK;
358
359  return 0;
360 }
361
362// non-stream pass:
363
364 ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): This is a client passfh", client, mes->stream);
365
366/*
367 0: Version,   16
368 1: Flags,     16
369 2: Protocol,  16
370 3: Byteorder, 16
371 Options...
372*/
373
374 if ( mes->datalen < 4*2 )
375  return -1;
376
377 for (i = 0; i < 4; i++) {
378  d[i] = ROAR_NET2HOST16(d[i]);
379 }
380
381 if ( d[0] != 0 ) // version
382  return -1;
383
384 listening = d[1] & ROAR_CLIENTPASS_FLAG_LISTEN;
385
386 if ( listening )
387  d[1] -= ROAR_CLIENTPASS_FLAG_LISTEN;
388
389 if ( d[1] != 0 ) // flags
390  return -1;
391
392 if ( listening ) {
393  if ( get_listen(&lsock, NULL) == -1 ) {
394   close(fh);
395   return -1;
396  }
397
398  roar_vio_open_fh_socket(&(lsock->sock), fh);
399  lsock->used   = 1;
400  lsock->proto  = d[2];
401 } else {
402  if ( clients_new_from_fh(fh, d[2], d[3], 1) == -1 )
403   return -1;
404 }
405
406 ROAR_DBG("req_on_passfh(client=%i, mes={stream=%i,...},...): returning (OK)...", client, mes->stream);
407
408 mes->datalen = 0;
409 mes->cmd     = ROAR_CMD_OK;
410
411 return 0;
412}
413
414#ifdef ROAR_SUPPORT_META
415int req_on_set_meta    (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
416 int type;
417 int mode;
418 int namelen, vallen;
419 char   val[255+1];
420 char   name[ROAR_META_MAX_NAMELEN+1];
421
422 if ( mes->datalen < 3 )
423  return -1;
424
425 if ( mes->data[0] != 0 ) // version
426  return -1;
427
428 mode = (unsigned) mes->data[1];
429 type = (unsigned) mes->data[2];
430
431 ROAR_DBG("req_on_set_meta(*): mode=%i, type=%i", mode, type);
432
433 if ( mode == ROAR_META_MODE_CLEAR ) {
434  stream_meta_clear(mes->stream);
435  mes->datalen = 0;
436  mes->cmd     = ROAR_CMD_OK;
437  return 0;
438 } else if ( mode == ROAR_META_MODE_DELETE ) { // unsuppoerted at the moment
439  return -1;
440 } else if ( mode == ROAR_META_MODE_FINALIZE ) {
441  stream_meta_finalize(mes->stream);
442  mes->datalen = 0;
443  mes->cmd     = ROAR_CMD_OK;
444  return 0;
445 } else if ( mode == ROAR_META_MODE_SET || mode == ROAR_META_MODE_ADD ) {
446  if ( mes->datalen < 5 )
447   return -1;
448
449  namelen = (unsigned) mes->data[3];
450  vallen  = (unsigned) mes->data[4];
451
452  ROAR_DBG("req_on_set_meta(*): namelen=%i, vallen=%i", namelen, vallen);
453
454  if ( mes->datalen < (5 + namelen + vallen) )
455   return -1;
456
457  if ( namelen > ROAR_META_MAX_NAMELEN )
458   return -1;
459
460  strncpy(name, &(mes->data[5]), namelen);
461  name[namelen] = 0;
462
463  if ( vallen > 255 )
464   return -1;
465
466  strncpy(val, &(mes->data[5+namelen]), vallen);
467  val[vallen] = 0;
468
469  if ( mode == ROAR_META_MODE_SET ) {
470   if ( stream_meta_set(mes->stream, type, name, val) == -1 )
471    return -1;
472  } else {
473   if ( stream_meta_add(mes->stream, type, name, val) == -1 )
474    return -1;
475  }
476
477  mes->datalen = 0;
478  mes->cmd     = ROAR_CMD_OK;
479  return 0;
480 } else { // unknown mode!
481  return -1;
482 }
483
484 return -1;
485}
486
487int req_on_get_meta    (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
488 int vallen;
489 int type;
490 char val[LIBROAR_BUFFER_MSGDATA-1];
491
492 if ( mes->datalen != 2 )
493  return -1;
494
495 if ( mes->data[0] != 0 ) // version
496  return -1;
497
498 type = (unsigned) mes->data[1];
499
500 if ( stream_meta_get(mes->stream, type, NULL, val, LIBROAR_BUFFER_MSGDATA-2) == -1 )
501  return -1;
502
503 vallen = strlen(val);
504
505 mes->cmd     = ROAR_CMD_OK;
506 mes->datalen = 2 + vallen;
507
508 mes->data[0] = 0;
509 mes->data[1] = (unsigned char) vallen;
510
511 val[vallen] = 0;
512
513 strncpy(&(mes->data[2]), val, vallen+1);
514
515 return 0;
516}
517
518int req_on_list_meta   (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
519 int i;
520 int len = 0;
521 int types[ROAR_META_MAX_PER_STREAM];
522
523 if ( mes->datalen != 1 )
524  return -1;
525
526 if ( mes->data[0] != 0 ) // version
527  return -1;
528
529 if ( (len = stream_meta_list(mes->stream, types, ROAR_META_MAX_PER_STREAM)) == -1 )
530  return -1;
531
532 mes->cmd     = ROAR_CMD_OK;
533 mes->datalen = 1 + len;
534 mes->data[0] = 0;
535
536 for (i = 0; i < len; i++)
537  mes->data[i+1] = types[i];
538
539 return 0;
540}
541#endif
542
543int req_on_server_info (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
544#ifdef ROAR_HAVE_UNAME
545 struct utsname utsname;
546#endif
547 struct roar_server_info info;
548 uint16_t * d16;
549
550 if ( mes->datalen != 4 )
551  return -1;
552
553 d16 = (uint16_t*)mes->data;
554
555 // check version.
556 if ( ROAR_NET2HOST16(d16[0]) != 0 )
557  return -1;
558
559 switch (ROAR_NET2HOST16(d16[1])) {
560  case ROAR_IT_SERVER:
561   memset(&info, 0, sizeof(info));
562
563   info.version = "roard/" PACKAGE_VERSION " <" DEVICE_VENDOR_STRING ">";
564   info.location = g_config->location;
565   info.description = g_config->description;
566
567#ifdef ROAR_HAVE_UNAME
568   if ( uname(&utsname) == 0 ) {
569    info.un.sysname  = utsname.sysname;
570    info.un.release  = utsname.release;
571    info.un.nodename = utsname.nodename;
572    info.un.machine  = utsname.machine;
573   }
574#endif
575
576   *data = NULL;
577
578   if ( roar_server_info_to_mes(mes, &info, data) == -1 )
579    return -1;
580
581   if ( *data != NULL )
582    flags[1] |= COMMAND_FLAG_OUT_LONGDATA;
583  break;
584  default: /* unknown request */
585    return -1;
586   break;
587 }
588
589 mes->cmd = ROAR_CMD_OK;
590
591 return 0;
592}
593
594int req_on_server_oinfo    (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
595 struct roar_stream s;
596//ROAR_DIR_OUTPUT
597
598 memset(&s, 0, sizeof(struct roar_stream));
599
600 s.dir           = ROAR_DIR_MIXING;
601 s.pos_rel_id    = -1;
602 s.info.rate     = g_sa->rate;
603 s.info.bits     = g_sa->bits;
604 s.info.channels = g_sa->channels;
605 s.info.codec    = g_sa->codec;
606 s.pos           = g_pos;
607
608 if ( roar_stream_s2m(&s, mes) == -1 )
609  return -1;
610
611 mes->cmd = ROAR_CMD_OK;
612
613 return 0;
614}
615
616
617int req_on_get_standby (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
618 mes->cmd     = ROAR_CMD_OK;
619 mes->pos     = g_pos;
620 mes->datalen = 2;
621
622 *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby);
623
624 return 0;
625}
626
627int req_on_set_standby (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
628 if ( mes->datalen != 2 )
629  return -1;
630
631 g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data));
632
633 mes->cmd     = ROAR_CMD_OK;
634 mes->pos     = g_pos;
635 mes->datalen = 0;
636
637 return 0;
638}
639
640int req_on_exit      (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
641 int term = 0;
642
643 if ( mes->datalen == 1 )
644  term = mes->data[0];
645
646 mes->cmd     = ROAR_CMD_OK;
647 mes->pos     = g_pos;
648 mes->datalen = 0;
649
650 ROAR_DBG("req_on_exit(*): term=%i", term);
651
652 if ( term ) {
653  cleanup_listen_socket(1);
654 } else {
655  alive = 0;
656 }
657
658 return 0;
659}
660
661int req_on_list_clients(int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
662 unsigned char filter, cmp;
663 uint32_t id;
664 int clients[ROAR_CLIENTS_MAX];
665 int i, c = 0;
666
667 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
668  return -1;
669
670 // TODO: add code to support filter
671 if ( filter != ROAR_CTL_FILTER_ANY )
672  return -1;
673
674 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
675  if ( g_clients[i] != NULL ) {
676   clients[c++] = i;
677  }
678 }
679
680 roar_ctl_ia2m(mes, clients, c);
681
682 mes->cmd = ROAR_CMD_OK;
683
684 return 0;
685}
686int req_on_list_streams(int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
687 unsigned char filter, cmp;
688 uint32_t id;
689 int streams[ROAR_STREAMS_MAX];
690 int i, c = 0;
691 int match;
692
693 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
694  return -1;
695
696 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
697  if ( g_streams[i] == NULL )
698   continue;
699
700  match = 0;
701
702  switch (filter) {
703   case ROAR_CTL_FILTER_ANY:
704     match = 1;
705    break;
706   case ROAR_CTL_FILTER_DIR:
707     match = roar_filter_match(cmp, id, ROAR_STREAM(g_streams[i])->dir);
708    break;
709   default: // unsupported filter...
710     return -1;
711    break;
712  }
713
714  if ( match )
715   streams[c++] = i;
716 }
717
718 roar_ctl_ia2m(mes, streams, c);
719
720 mes->cmd = ROAR_CMD_OK;
721
722 return 0;
723}
724
725int req_on_get_client  (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
726 struct roar_client * c;
727
728 if ( mes->datalen != 1 )
729  return -1;
730
731 if ( clients_get(mes->data[0], &c) == -1 )
732  return -1;
733
734 mes->cmd = ROAR_CMD_OK;
735
736 return roar_ctl_c2m(mes, c);
737}
738
739int req_on_get_stream  (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
740 struct roar_stream_server * s;
741
742 if ( mes->datalen != 1 )
743  return -1;
744
745 if ( streams_get(mes->data[0], &s) == -1 )
746  return -1;
747
748 mes->cmd = ROAR_CMD_OK;
749 mes->stream = mes->data[0];
750
751 return roar_stream_s2m(ROAR_STREAM(s), mes);
752}
753
754int req_on_get_stream_para (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
755 struct roar_stream * s;
756 struct roar_stream_server * ss;
757 struct roar_audio_info * audio_info;
758 struct roar_stream_ltm * ltm;
759 uint16_t * d  = (uint16_t *) mes->data;
760 int64_t * d64 = ( int64_t *) mes->data;
761 int64_t * d64ptr;
762 int i, h, k;
763 char * str;
764 size_t needed;
765 int test, bits;
766
767 ROAR_DBG("req_on_get_stream_para(client=%i, mes=%p{.stream=%i, .datalen=%i,...}, data=%p, flags=%p) = ?", client, mes, (int)mes->stream, (int)mes->datalen, data, flags);
768
769 if ( mes->datalen < 4 )
770  return -1;
771
772 for (i = 0; i < 2; i++) {
773  d[i] = ROAR_NET2HOST16(d[i]);
774 }
775
776 if ( d[0] != 0 ) {
777  ROAR_WARN("req_on_get_stream_para(*): unsupported command version: %i, %i", (int)d[0], (int)d[1]);
778  return -1;
779 }
780
781 switch (d[1]) {
782  case ROAR_STREAM_PARA_INFO:
783    if ( streams_get(mes->stream, &ss) == -1 ) {
784     ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream);
785     return -1;
786    }
787
788    if ( streams_calc_delay(mes->stream) == -1 ) {
789     ROAR_WARN("req_on_get_stream_para(*): can not calc delay for stream %i", mes->stream);
790    }
791
792    s = ROAR_STREAM(ss);
793
794    audio_info = &(s->info);
795
796    mes->datalen = 2*12;
797
798    d[ 2] = ROAR_OUTPUT_CALC_OUTBUFSIZE(audio_info);
799    d[ 3] = ss->pre_underruns;
800    d[ 4] = ss->post_underruns;
801    d[ 5] = ss->codec_orgi;
802    d[ 6] = (ss->flags & 0xFFFF) | (ss->primary ? ROAR_FLAG_PRIMARY : 0) | (ss->driver_id != -1 ? ROAR_FLAG_OUTPUT : 0);
803    d[ 7] = ss->delay/1000;
804    d[ 8] = ss->state;
805    d[ 9] = (ss->flags & 0xFFFF0000) >> 16;
806    d[10] = ss->mixer_stream;
807    d[11] = ss->role;
808
809    ROAR_DBG("req_on_get_stream_para(*): ss->driver_id=%i", ss->driver_id);
810
811    ROAR_DBG("req_on_get_stream_para(*): delay=%i, send delay=%i", ss->delay, d[7]);
812
813    for (i = 0; i < mes->datalen/2; i++) {
814     d[i] = ROAR_HOST2NET16(d[i]);
815    }
816
817    mes->pos = s->pos;
818   break;
819
820  case ROAR_STREAM_PARA_NAME:
821   str = streams_get_name(mes->stream);
822
823   if ( str == NULL )
824    return -1;
825
826    mes->datalen = 4 + strlen(str);
827
828    if ( mes->datalen > LIBROAR_BUFFER_MSGDATA )
829     return -1;
830
831    strncpy(((char*)&(mes->data))+4, str, mes->datalen);
832
833    d[0] = ROAR_HOST2NET16(d[0]);
834    d[1] = ROAR_HOST2NET16(d[1]);
835   break;
836
837  case ROAR_STREAM_PARA_CHANMAP:
838    if ( streams_get(mes->stream, &ss) == -1 ) {
839     ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream);
840     return -1;
841    }
842
843    s = ROAR_STREAM(ss);
844
845    memcpy(&(mes->data[4]), ss->chanmap.in, s->info.channels);
846    mes->datalen = 2*2 + s->info.channels;
847
848    d[0] = ROAR_HOST2NET16(d[0]);
849    d[1] = ROAR_HOST2NET16(d[1]);
850   break;
851
852  case ROAR_STREAM_PARA_LTM:
853    ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM request...", client);
854
855    if ( mes->datalen < (6 * 2) ) {
856     ROAR_ERR("req_on_get_stream_para(client=%i, ...): LTM request of client is corruped: message too short", client);
857     return -1;
858    }
859
860    for (i = 2; i < mes->datalen/2; i++) {
861     d[i] = ROAR_NET2HOST16(d[i]);
862    }
863
864    if ( d[2] != ROAR_LTM_SST_GET_RAW ) {
865     ROAR_ERR("req_on_get_stream_para(client=%i, ...): LTM request of client is corruped: unknown LTM subtype: %i", client, (int)d[2]);
866     return -1;
867    }
868
869    ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM request of type GET_RAW", client);
870
871    test = d[5];
872    bits = 0;
873    while (test) {
874     if ( test & 0x1 )
875      bits++;
876
877     test >>= 1;
878    }
879
880    needed = 0;
881
882    if ( mes->stream == -1 ) {
883     ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM multi-stream request...", client);
884
885     for (i = 6; i < mes->datalen/2; i++) {
886      if ( (ltm = streams_ltm_get(d[i], d[5], d[3])) == NULL )
887       return -1;
888
889      needed += ltm->channels;
890     }
891    } else {
892     ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM single-stream request for stream %i...", client, mes->stream);
893     if ( (ltm = streams_ltm_get(mes->stream, d[5], d[3])) == NULL )
894      return -1;
895
896     needed = ltm->channels;
897    }
898
899    needed *= bits;
900
901    needed += mes->stream == -1 ? (mes->datalen/2) - 6 : 1;
902
903    ROAR_DBG("req_on_get_stream_para(client=%i, ...): data size for answer is %i 64 bit sub-packets", client, (int)needed);
904
905    ROAR_DBG("req_on_get_stream_para(client=%i, ...): mes->datalen=%i, data=%p{%p}", client, (int)mes->datalen, data, *data);
906    d64 = _dataspace(mes, data, flags, needed * 8);
907    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
908
909    if ( (d = roar_mm_malloc(mes->datalen)) == NULL )
910     return -1;
911
912    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d=%p, data=%p{%p}", client, d, data, *data);
913
914
915    ROAR_DBG("req_on_get_stream_para(client=%i, ...): mes->datalen=%i, data=%p{%p}", client, (int)mes->datalen, data, *data);
916    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
917    memcpy(d, mes->data, mes->datalen);
918    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
919
920    d64ptr = d64;
921
922    ROAR_DBG("req_on_get_stream_para(client=%i, ...): mes->datalen=%i, data=%p{%p}", client, (int)mes->datalen, data, *data);
923    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
924
925    if ( mes->stream == -1 ) {
926     for (i = 6; i < mes->datalen/2; i++) {
927      ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
928
929      if ( (ltm = streams_ltm_get(d[i], d[5], d[3])) == NULL )
930       return -1;
931
932      *d64ptr = ltm->channels & 0xFFFF;
933       d64ptr++;
934
935      for (h = 0; h < ltm->channels; h++) {
936       for (k = 0; k < ROAR_LTM_MTBITS; k++) {
937        if ( d[5] & (1<<k) ) {
938         switch (1<<k) {
939          case ROAR_LTM_MT_RMS:
940            *d64ptr = ltm->cur[h].rms;
941           break;
942          default:
943            ROAR_ERR("req_on_get_stream_para(client=%i, ...): client requets unknown MT for LTM: bit %i", client, k);
944         }
945         d64ptr++;
946        }
947       }
948      }
949     }
950    } else {
951     if ( (ltm = streams_ltm_get(mes->stream, d[5], d[3])) == NULL )
952      return -1;
953
954     *d64ptr = ltm->channels & 0xFFFF;
955      d64ptr++;
956
957     for (h = 0; h < ltm->channels; h++) {
958      for (k = 0; k < ROAR_LTM_MTBITS; k++) {
959       if ( d[5] & (1<<k) ) {
960        switch (1<<k) {
961         case ROAR_LTM_MT_RMS:
962           *d64ptr = ltm->cur[h].rms;
963           ROAR_DBG("req_on_get_stream_para(client=%i, ...): rms=%lli to %p", client, (long long int)*d64ptr, d64ptr);
964          break;
965         default:
966           ROAR_ERR("req_on_get_stream_para(client=%i, ...): client requets unknown MT for LTM: bit %i", client, k);
967        }
968        d64ptr++;
969       }
970      }
971     }
972    }
973
974    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
975
976    roar_mm_free(d);
977
978    for (i = 0; i < needed; i++) {
979     d64[i] = ROAR_HOST2NET64(d64[i]);
980    }
981
982    mes->datalen = needed * 8;
983    ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM d64=%p, d64ptr=%p", client, d64, d64ptr);
984    ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM final message has %i byte of data", client, (int)mes->datalen);
985    ROAR_DBG("req_on_get_stream_para(client=%i, ...): d64=%p, data=%p{%p}", client, d64, data, *data);
986    ROAR_DBG("req_on_get_stream_para(client=%i, ...): LTM GET_RAW request: OK. returning...", client);
987   break;
988
989  default:
990    ROAR_WARN("req_on_get_stream_para(*): unsupported command: %i", d[1]);
991    return -1;
992 }
993
994 ROAR_DBG("req_on_get_stream_para(client=%i, mes=%p{.stream=%i, .datalen=%i,...}, data=%p, flags=%p) = 0 // returning OK", client, mes, (int)mes->stream, (int)mes->datalen, data, flags);
995 mes->cmd = ROAR_CMD_OK;
996 return 0;
997}
998
999int req_on_set_stream_para (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1000 uint16_t * d = (uint16_t *) mes->data;
1001 int i;
1002
1003 if ( mes->datalen < 2*2 )
1004  return -1;
1005
1006 for (i = 0; i < 2; i++) {
1007  d[i] = ROAR_NET2HOST16(d[i]);
1008 }
1009
1010 if ( d[0] != 0 )
1011  return -1;
1012
1013 switch (d[1]) {
1014  case ROAR_STREAM_PARA_FLAGS:
1015    if ( mes->datalen != 2*4 )
1016     return -1;
1017
1018    d[2] = ROAR_NET2HOST16(d[2]);
1019    d[3] = ROAR_NET2HOST16(d[3]);
1020
1021    ROAR_DBG("req_on_set_stream_para(*): request seems to be valid");
1022
1023    if ( d[2] == ROAR_RESET_FLAG ) {
1024     if ( streams_reset_flag(mes->stream, d[3]) == -1 )
1025      return -1;
1026    } else {
1027     if ( streams_set_flag(mes->stream, d[3]) == -1 )
1028      return -1;
1029    }
1030   break;
1031  case ROAR_STREAM_PARA_CHANMAP:
1032    if ( streams_set_map(mes->stream, &(mes->data[4]), mes->datalen - 4) == -1 )
1033     return -1;
1034   break;
1035  case ROAR_STREAM_PARA_ROLE:
1036    if ( mes->datalen != 2*3 )
1037     return -1;
1038
1039    d[2] = ROAR_NET2HOST16(d[2]);
1040
1041    if ( streams_set_role(mes->stream, d[2]) == -1 )
1042     return -1;
1043   break;
1044  case ROAR_STREAM_PARA_LTM:
1045    if ( mes->datalen < (6 * 2) )
1046     return -1;
1047
1048    for (i = 2; i < mes->datalen/2; i++) {
1049     d[i] = ROAR_NET2HOST16(d[i]);
1050    }
1051
1052    if ( mes->stream == -1 ) {
1053     for (i = 6; i < mes->datalen/2; i++)
1054      if ( streams_ltm_ctl(d[i], d[5], d[3], d[2]) == -1 )
1055       return -1;
1056    } else {
1057     if ( streams_ltm_ctl(mes->stream, d[5], d[3], d[2]) == -1 )
1058      return -1;
1059    }
1060   break;
1061  default:
1062    ROAR_WARN("req_on_set_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
1063    return -1;
1064   break;
1065 }
1066
1067 mes->cmd     = ROAR_CMD_OK;
1068 mes->datalen = 0;
1069
1070 return 0;
1071}
1072
1073int req_on_kick (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1074 struct roar_stream_server * ss;
1075 uint16_t * info = (uint16_t *) mes->data;
1076 int is_stream = 0;
1077
1078 if ( mes->datalen != 4 )
1079  return -1;
1080
1081 info[0] = ROAR_NET2HOST16(info[0]);
1082 info[1] = ROAR_NET2HOST16(info[1]);
1083
1084 switch (info[0]) {
1085  case ROAR_OT_CLIENT:
1086    clients_delete(info[1]);
1087   break;
1088  case ROAR_OT_STREAM:
1089    is_stream = 1;
1090   break;
1091  case ROAR_OT_SOURCE:
1092    if ( streams_get_flag(info[1], ROAR_FLAG_SOURCE) != 1 )
1093     return -1;
1094    is_stream = 1;
1095   break;
1096  case ROAR_OT_OUTPUT:
1097    if ( streams_get(info[1], &ss) == -1 )
1098     return -1;
1099
1100    if ( ss->driver_id == -1 )
1101     return -1;
1102
1103    is_stream = 1;
1104   break;
1105  case ROAR_OT_MIXER:
1106    if ( streams_get(info[1], &ss) == -1 )
1107     return -1;
1108
1109    if ( ROAR_STREAM(ss)->dir != ROAR_DIR_MIXING )
1110     return -1;
1111
1112    is_stream = 1;
1113   break;
1114  case ROAR_OT_BRIDGE:
1115    if ( streams_get(info[1], &ss) == -1 )
1116     return -1;
1117
1118    if ( ROAR_STREAM(ss)->dir != ROAR_DIR_BRIDGE )
1119     return -1;
1120
1121    is_stream = 1;
1122   break;
1123  default:
1124/* TODO: those types should be handled, too:
1125#define ROAR_OT_SAMPLE    4
1126#define ROAR_OT_LISTEN    8
1127#define ROAR_OT_ACTION    9
1128#define ROAR_OT_MSGQUEUE 10
1129#define ROAR_OT_MSGBUS   11
1130*/
1131    return -1;
1132   break;
1133 }
1134
1135 if ( is_stream ) {
1136  if ( streams_get_flag(info[1], ROAR_FLAG_IMMUTABLE) == 1 )
1137   return -1;
1138
1139  streams_delete(info[1]);
1140 }
1141
1142 mes->cmd     = ROAR_CMD_OK;
1143 mes->datalen = 0;
1144
1145 return 0;
1146}
1147
1148int req_on_attach      (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1149 uint16_t * info = (uint16_t *) mes->data;
1150
1151 if ( mes->datalen < 6 )
1152  return -1;
1153
1154 info[0] = ROAR_NET2HOST16(info[0]);
1155 info[1] = ROAR_NET2HOST16(info[1]);
1156 info[2] = ROAR_NET2HOST16(info[2]);
1157
1158 if ( info[0] != 0 )
1159  return -1;
1160
1161 if ( info[1] == ROAR_ATTACH_SIMPLE ) {
1162  if ( client_stream_move(info[2], mes->stream) == -1 )
1163   return -1;
1164 } else {
1165  return -1;
1166 }
1167
1168 mes->cmd     = ROAR_CMD_OK;
1169 mes->datalen = 0;
1170
1171 return 0;
1172}
1173
1174int req_on_set_vol (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1175 struct roar_stream_server * s;
1176 uint16_t * info = (uint16_t *) mes->data;
1177 uint16_t   version;
1178 uint16_t   scale = 65535;
1179 int stream;
1180 int i;
1181 int chans;
1182
1183 ROAR_DBG("req_on_set_vol(*) = ?");
1184 ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen);
1185
1186 if ( mes->datalen < (4*2) )
1187  return -1;
1188
1189 version = ROAR_NET2HOST16(info[0]);
1190 ROAR_DBG("req_on_set_vol(*): version=%i", (int)version);
1191
1192 switch (version) {
1193  case 0:
1194    stream = ROAR_NET2HOST16(info[1]);
1195   break;
1196  case 1:
1197    stream = mes->stream;
1198    scale  = ROAR_NET2HOST16(info[1]);
1199   break;
1200  default:
1201    return -1;
1202   break;
1203 }
1204 ROAR_DBG("req_on_set_vol(*): stream=%i", stream);
1205
1206 if ( scale == 0 )
1207  return -1;
1208
1209 // TODO: change this code.
1210 //       we should not directly change the stream object but use some stream_*()-func
1211 //       for that job.
1212
1213 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
1214  return -1;
1215
1216 s = g_streams[stream];
1217
1218 if ( s == NULL )
1219  return -1;
1220
1221 ROAR_DBG("req_on_set_vol(*): s=%p", s);
1222
1223 info[2] = ROAR_NET2HOST16(info[2]);
1224
1225 if ( info[2] == ROAR_SET_VOL_ALL ) {
1226  chans = (mes->datalen/2) - 3;
1227  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans);
1228
1229  if ( chans >= ROAR_MAX_CHANNELS )
1230   return -1;
1231
1232  ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer);
1233
1234  for (i = 0; i < chans; i++) {
1235   s->mixer.mixer[i] = ROAR_NET2HOST16(info[i+3]);
1236   ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, ROAR_NET2HOST16(info[i+3]));
1237  }
1238
1239  s->mixer.scale = scale;
1240
1241  ROAR_DBG("req_on_set_vol(*): mixer changed!");
1242
1243 } else if ( info[2] == ROAR_SET_VOL_ONE ) {
1244  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE");
1245  if ( ROAR_NET2HOST16(info[3]) >= ROAR_MAX_CHANNELS )
1246   return -1;
1247
1248  s->mixer.mixer[ROAR_NET2HOST16(info[3])] = ROAR_NET2HOST16(info[4]);
1249
1250  s->mixer.scale = scale;
1251 } else {
1252  return -1;
1253 }
1254
1255 if ( streams_set_mixer(stream) == -1 )
1256  return -1;
1257
1258 mes->cmd     = ROAR_CMD_OK;
1259 mes->datalen = 0;
1260
1261 return 0;
1262}
1263
1264int req_on_get_vol (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1265 uint16_t * info = (uint16_t *) mes->data;
1266 uint16_t   version = -1;
1267 int stream;
1268 struct roar_stream_server * s;
1269 int i;
1270 int chans;
1271
1272 ROAR_DBG("req_on_get_vol(*) = ?");
1273 ROAR_DBG("req_on_get_vol(*): mes->datalen=%i", mes->datalen);
1274
1275 if ( mes->datalen < 2 ) {
1276  return -1;
1277 }
1278
1279 version = ROAR_NET2HOST16(info[0]);
1280
1281 switch (version) {
1282  case 0:
1283    if ( mes->datalen < (2*2) )
1284     return -1;
1285
1286    stream = ROAR_NET2HOST16(info[1]);
1287   break;
1288  case 1:
1289    stream = mes->stream;
1290   break;
1291  default:
1292    return -1;
1293   break;
1294 }
1295
1296 ROAR_DBG("req_on_get_vol(*): stream=%i", stream);
1297
1298 // TODO: change this code.
1299 //       we should not directly change the stream object but use some stream_*()-func
1300 //       for that job.
1301
1302 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
1303  return -1;
1304
1305 s = g_streams[stream];
1306
1307 if ( s == NULL )
1308  return -1;
1309
1310 ROAR_DBG("req_on_get_vol(*): s=%p", s);
1311
1312 // ok, we have everything
1313
1314 info[0] = ROAR_HOST2NET16(version);
1315
1316 switch (version) {
1317  case 0:
1318    info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels);
1319
1320    for (i = 0; i < chans; i++)
1321     info[2+i] = ROAR_HOST2NET16(s->mixer.mixer[i]);
1322
1323     mes->datalen = (2 + chans)*2;
1324   break;
1325  case 1:
1326    info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels);
1327    info[2] = ROAR_HOST2NET16(s->mixer.scale);
1328    info[3] = ROAR_HOST2NET16(s->mixer.rpg_mul);
1329    info[4] = ROAR_HOST2NET16(s->mixer.rpg_div);
1330
1331    for (i = 0; i < chans; i++)
1332     info[5+i] = ROAR_HOST2NET16(s->mixer.mixer[i]);
1333
1334     mes->datalen = (5 + chans)*2;
1335   break;
1336  default:
1337    return -1;
1338   break;
1339 }
1340
1341 mes->cmd = ROAR_CMD_OK;
1342
1343 return 0;
1344}
1345
1346int req_on_add_data (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1347 struct roar_buffer * b;
1348 char               * buf;
1349
1350 if ( roar_buffer_new_data(&b, mes->datalen, (void **)&buf) == -1 ) {
1351  ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!");
1352  ROAR_DBG("req_on_add_data(*) = -1");
1353  return -1;
1354 }
1355
1356 if ( data == NULL ) {
1357  memcpy(buf, mes->data, mes->datalen);
1358 } else {
1359  memcpy(buf, *data, mes->datalen);
1360 }
1361
1362 if ( stream_add_buffer(mes->stream, b) == -1 ) {
1363  roar_buffer_free(b);
1364  return -1;
1365 }
1366
1367 mes->cmd     = ROAR_CMD_OK_STOP;
1368 mes->datalen = 0;
1369
1370 return 0;
1371}
1372
1373int req_on_beep        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1374 struct roar_beep bs;
1375 int16_t * info = (int16_t*)mes->data;
1376 int stream;
1377
1378 memset(&bs, 0, sizeof(bs));
1379
1380 if ( mes->datalen > 0 ) {
1381  if ( mes->datalen < 2 )
1382   return -1;
1383
1384  if ( ROAR_NET2HOST16(info[0]) != 0 ) /* version */
1385   return -1;
1386
1387  if ( mes->datalen != 8*2 )
1388   return -1;
1389
1390  bs.vol  = ROAR_NET2HOST16(info[1]);
1391  bs.time = ROAR_NET2HOST16(info[2]);
1392  bs.freq = ROAR_NET2HOST16(info[3]);
1393  bs.type = ROAR_NET2HOST16(info[4]);
1394  bs.x    = ROAR_NET2HOST16(info[5]);
1395  bs.y    = ROAR_NET2HOST16(info[6]);
1396  bs.z    = ROAR_NET2HOST16(info[7]);
1397 }
1398
1399 if ( (stream = beep_start(client, &bs)) == -1 )
1400  return -1;
1401
1402 mes->stream  = stream;
1403 mes->cmd     = ROAR_CMD_OK_STOP;
1404 mes->datalen = 0;
1405
1406 return 0;
1407}
1408
1409int req_on_wait        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) {
1410 uint16_t * u16 = (uint16_t*)mes->data;
1411 struct roar_event events[4];
1412 size_t left, tmp;
1413 size_t num = 0;
1414 void * vp = mes->data;
1415
1416 vp += 4;
1417
1418 // check for complet header...
1419 if ( mes->datalen < 4 )
1420  return -1;
1421
1422 u16[0] = ROAR_NET2HOST16(u16[0]);
1423 u16[1] = ROAR_NET2HOST16(u16[1]);
1424
1425 // do we support version and flags?
1426 if ( u16[0] != 0 || u16[1] != 0 )
1427  return -1;
1428
1429 memset(events, 0, sizeof(events));
1430
1431 left = mes->datalen - 4;
1432
1433 while (left) {
1434  tmp = left;
1435  if ( roar_event_from_blob(&(events[num]), vp, &tmp) == -1 )
1436   return -1;
1437
1438  vp   += tmp;
1439  left -= tmp;
1440  num++;
1441 }
1442
1443 if ( clients_wait(client, events, num) == -1 )
1444  return -1;
1445
1446 flags[1] |= COMMAND_FLAG_OUT_NOSEND;
1447
1448 return 0;
1449}
1450
1451//ll
Note: See TracBrowser for help on using the repository browser.