source: roaraudio/roard/req.c @ 4343:a67cbb88fbe0

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

added support for wait command

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