source: roaraudio/roard/req.c @ 1840:704916b77c41

Last change on this file since 1840:704916b77c41 was 1840:704916b77c41, checked in by phi, 15 years ago

of cause it need to be source_stream not source_info where to take codec_orgi from

File size: 17.2 KB
Line 
1//req.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int 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
33int 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 ) {
43  if ( c->pid == -1 ) {
44   c->pid       = ROAR_NET2HOST32(*(uint32_t*)((mes->data)+1));
45   ROAR_DBG("req_on_identify(): new PID: c->pid = %i", c->pid);
46  }
47
48  ROAR_DBG("req_on_identify(): final PID: c->pid = %i", c->pid);
49
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
66int 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
74int req_on_whoami      (int client, struct roar_message * mes, char * data) {
75 mes->cmd     = ROAR_CMD_OK;
76 mes->datalen = 1;
77 mes->data[0] = client;
78 return 0;
79}
80
81
82int req_on_new_stream  (int client, struct roar_message * mes, char * data) {
83 int stream;
84 struct roar_stream * s;
85 struct roar_stream * source_stream;
86 struct roar_audio_info * info;
87 struct roar_audio_info * source_info;
88
89 if ((stream = streams_new()) == -1 )
90  return -1;
91
92 if ( streams_get(stream, (struct roar_stream_server **)&s) == -1 ) {
93  streams_delete(stream);
94  return -1;
95 }
96
97 if ( client_stream_add(client, stream) == -1 ) {
98  streams_delete(stream);
99  return -1;
100 }
101
102 if ( roar_stream_m2s(s, mes) == -1 ) {
103  streams_delete(stream);
104  return -1;
105 }
106
107 ROAR_STREAM(s)->id = stream; // roar_stream_m2s() resets this
108 ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM(s)->info.codec;
109
110 switch (ROAR_STREAM(s)->dir) {
111  case ROAR_DIR_LIGHT_IN:
112  case ROAR_DIR_LIGHT_OUT:
113    info = &(ROAR_STREAM(s)->info);
114
115    info->channels = 0;
116    info->bits     = 0;
117    info->rate     = 0;
118
119   break;
120  case ROAR_DIR_THRU:
121
122    if ( ROAR_STREAM(s)->pos_rel_id == -1 || ROAR_STREAM(s)->pos_rel_id == stream ) {
123     streams_delete(stream);
124     return -1;
125    }
126
127    if ( streams_get(ROAR_STREAM(s)->pos_rel_id, (struct roar_stream_server **)&source_stream) == -1 ) {
128     streams_delete(stream);
129     return -1;
130    }
131
132    info        = &(ROAR_STREAM(s)->info);
133    source_info = &(ROAR_STREAM(source_stream)->info);
134
135    info->channels = source_info->channels;
136    info->bits     = source_info->bits;
137    info->rate     = source_info->rate;
138    info->codec    = source_info->codec;
139    ROAR_STREAM_SERVER(s)->codec_orgi = ROAR_STREAM_SERVER(source_stream)->codec_orgi;
140
141   break;
142 }
143
144 mes->cmd     = ROAR_CMD_OK;
145 mes->stream  = stream;
146 mes->datalen = 0;
147
148 return 0;
149}
150
151int req_on_exec_stream (int client, struct roar_message * mes, char * data) {
152 int r;
153
154 if ( (r = client_stream_exec(client, mes->stream)) == -1 )
155  return -1;
156
157 mes->cmd     = ROAR_CMD_OK;
158 mes->datalen = 0;
159
160 return 0;
161}
162
163int req_on_con_stream  (int client, struct roar_message * mes, char * data) {
164 char   host[80] = {0};
165 int    port = 0;
166 int    type;
167 int    fh;
168 int    len;
169
170 if ( mes->datalen < 4 )
171  return -1;
172
173 if ( *(mes->data) != 0 )
174  return -1;
175
176 if ( mes->datalen > 80 ) // we do not support long messages here
177  return -1;
178
179 type = (unsigned)mes->data[1];
180 port = ROAR_NET2HOST16(((uint16_t*)mes->data)[1]);
181
182 len = mes->datalen - 4;
183
184 strncpy(host, &(mes->data[4]), len);
185 host[len] = 0;
186
187 if ( type > ROAR_SOCKET_TYPE_MAX )
188  return -1;
189
190 if ( type == ROAR_SOCKET_TYPE_FILE ) // disabled because of security resons
191  return -1;
192
193 if ( type == ROAR_SOCKET_TYPE_FORK ) // why should we connect to ourself?
194  return -1;
195
196 ROAR_DBG("req_on_con_stream(*): CONNECT(type=%i, host='%s', port=%i)", type, host, port);
197
198 if ( (fh = roar_socket_open(ROAR_SOCKET_MODE_CONNECT, type, host, port)) == -1 )
199  return -1;
200
201 if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
202  close(fh);
203  return 1;
204 }
205
206 mes->datalen = 0;
207 mes->cmd     = ROAR_CMD_OK;
208
209 return 0;
210}
211
212int req_on_passfh      (int client, struct roar_message * mes, char * data) {
213 int fh;
214 int sock = clients_get_fh(client);
215
216 if ( (fh = roar_socket_recv_fh(sock, NULL, NULL)) == -1 )
217  return -1;
218
219 if ( client_stream_set_fh(client, mes->stream, fh) == -1 ) {
220  close(fh);
221  return 1;
222 }
223
224
225 mes->datalen = 0;
226 mes->cmd     = ROAR_CMD_OK;
227
228 return 0;
229}
230
231#ifdef ROAR_SUPPORT_META
232int req_on_set_meta    (int client, struct roar_message * mes, char * data) {
233 int type;
234 int mode;
235 int namelen, vallen;
236 char   val[255+1];
237 char   name[ROAR_META_MAX_NAMELEN+1];
238
239 if ( mes->datalen < 3 )
240  return -1;
241
242 if ( mes->data[0] != 0 ) // version
243  return -1;
244
245 mode = (unsigned) mes->data[1];
246 type = (unsigned) mes->data[2];
247
248 ROAR_DBG("req_on_set_meta(*): mode=%i, type=%i", mode, type);
249
250 if ( mode == ROAR_META_MODE_CLEAR ) {
251  stream_meta_clear(mes->stream);
252  mes->datalen = 0;
253  mes->cmd     = ROAR_CMD_OK;
254  return 0;
255 } else if ( mode == ROAR_META_MODE_DELETE ) { // unsuppoerted at the moment
256  return -1;
257 } else if ( mode == ROAR_META_MODE_FINALIZE ) {
258  stream_meta_finalize(mes->stream);
259  mes->datalen = 0;
260  mes->cmd     = ROAR_CMD_OK;
261  return 0;
262 } else if ( mode == ROAR_META_MODE_SET || mode == ROAR_META_MODE_ADD ) {
263  if ( mes->datalen < 5 )
264   return -1;
265
266  namelen = (unsigned) mes->data[3];
267  vallen  = (unsigned) mes->data[4];
268
269  ROAR_DBG("req_on_set_meta(*): namelen=%i, vallen=%i", namelen, vallen);
270
271  if ( mes->datalen < (5 + namelen + vallen) )
272   return -1;
273
274  if ( namelen > ROAR_META_MAX_NAMELEN )
275   return -1;
276
277  strncpy(name, &(mes->data[5]), namelen);
278  name[namelen] = 0;
279
280  if ( vallen > 255 )
281   return -1;
282
283  strncpy(val, &(mes->data[5+namelen]), vallen);
284  val[vallen] = 0;
285
286  if ( mode == ROAR_META_MODE_SET ) {
287   if ( stream_meta_set(mes->stream, type, name, val) == -1 )
288    return -1;
289  } else {
290   if ( stream_meta_add(mes->stream, type, name, val) == -1 )
291    return -1;
292  }
293
294  mes->datalen = 0;
295  mes->cmd     = ROAR_CMD_OK;
296  return 0;
297 } else { // unknown mode!
298  return -1;
299 }
300
301 return -1;
302}
303
304int req_on_get_meta    (int client, struct roar_message * mes, char * data) {
305 int vallen;
306 int type;
307 char val[LIBROAR_BUFFER_MSGDATA-1];
308
309 if ( mes->datalen != 2 )
310  return -1;
311
312 if ( mes->data[0] != 0 ) // version
313  return -1;
314
315 type = (unsigned) mes->data[1];
316
317 if ( stream_meta_get(mes->stream, type, NULL, val, LIBROAR_BUFFER_MSGDATA-2) == -1 )
318  return -1;
319
320 vallen = strlen(val);
321
322 mes->cmd     = ROAR_CMD_OK;
323 mes->datalen = 2 + vallen;
324
325 mes->data[0] = 0;
326 mes->data[1] = (unsigned char) vallen;
327
328 val[vallen] = 0;
329
330 strncpy(&(mes->data[2]), val, vallen+1);
331
332 return 0;
333}
334
335int req_on_list_meta   (int client, struct roar_message * mes, char * data) {
336 int i;
337 int len = 0;
338 int types[ROAR_META_MAX_PER_STREAM];
339
340 if ( mes->datalen != 1 )
341  return -1;
342
343 if ( mes->data[0] != 0 ) // version
344  return -1;
345
346 if ( (len = stream_meta_list(mes->stream, types, ROAR_META_MAX_PER_STREAM)) == -1 )
347  return -1;
348
349 mes->cmd     = ROAR_CMD_OK;
350 mes->datalen = 1 + len;
351 mes->data[0] = 0;
352
353 for (i = 0; i < len; i++)
354  mes->data[i+1] = types[i];
355
356 return 0;
357}
358#endif
359
360int req_on_server_oinfo    (int client, struct roar_message * mes, char * data) {
361 struct roar_stream s;
362//ROAR_DIR_OUTPUT
363
364 memset(&s, 0, sizeof(struct roar_stream));
365
366 s.dir           = ROAR_DIR_MIXING;
367 s.pos_rel_id    = -1;
368 s.info.rate     = g_sa->rate;
369 s.info.bits     = g_sa->bits;
370 s.info.channels = g_sa->channels;
371 s.info.codec    = g_sa->codec;
372 s.pos           = g_pos;
373
374 if ( roar_stream_s2m(&s, mes) == -1 )
375  return -1;
376
377 mes->cmd = ROAR_CMD_OK;
378
379 return 0;
380}
381
382
383int req_on_get_standby (int client, struct roar_message * mes, char * data) {
384 mes->cmd = ROAR_CMD_OK;
385 mes->datalen = 2;
386
387 *((uint16_t*)mes->data) = ROAR_HOST2NET16((unsigned) g_standby);
388
389 return 0;
390}
391
392int req_on_set_standby (int client, struct roar_message * mes, char * data) {
393 if ( mes->datalen != 2 )
394  return -1;
395
396 g_standby = ROAR_NET2HOST16(*((uint16_t*)mes->data));
397
398 mes->cmd     = ROAR_CMD_OK;
399 mes->datalen = 0;
400
401 return 0;
402}
403
404int req_on_exit      (int client, struct roar_message * mes, char * data) {
405 int term = 0;
406
407 if ( mes->datalen == 1 )
408  term = mes->data[0];
409
410 mes->cmd     = ROAR_CMD_OK;
411 mes->datalen = 0;
412
413 ROAR_DBG("req_on_exit(*): term=%i", term);
414
415 if ( term ) {
416  cleanup_listen_socket(1);
417 } else {
418  alive = 0;
419 }
420
421 return 0;
422}
423
424int req_on_list_clients(int client, struct roar_message * mes, char * data) {
425 unsigned char filter, cmp;
426 uint32_t id;
427 int clients[ROAR_CLIENTS_MAX];
428 int i, c = 0;
429
430 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
431  return -1;
432
433 // TODO: add code to support filter
434 if ( filter != ROAR_CTL_FILTER_ANY )
435  return -1;
436
437 for (i = 0; i < ROAR_CLIENTS_MAX; i++) {
438  if ( g_clients[i] != NULL ) {
439   clients[c++] = i;
440  }
441 }
442
443 roar_ctl_ia2m(mes, clients, c);
444
445 mes->cmd = ROAR_CMD_OK;
446
447 return 0;
448}
449int req_on_list_streams(int client, struct roar_message * mes, char * data) {
450 unsigned char filter, cmp;
451 uint32_t id;
452 int streams[ROAR_STREAMS_MAX];
453 int i, c = 0;
454
455 if ( roar_ctl_m2f(mes, &filter, &cmp, &id) == -1 )
456  return -1;
457
458 // TODO: add code to support filter
459 if ( filter != ROAR_CTL_FILTER_ANY )
460  return -1;
461
462 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
463  if ( g_streams[i] != NULL ) {
464   streams[c++] = i;
465  }
466 }
467
468 roar_ctl_ia2m(mes, streams, c);
469
470 mes->cmd = ROAR_CMD_OK;
471
472 return 0;
473}
474
475int req_on_get_client  (int client, struct roar_message * mes, char * data) {
476 struct roar_client * c;
477
478 if ( mes->datalen != 1 )
479  return -1;
480
481 if ( clients_get(mes->data[0], &c) == -1 )
482  return -1;
483
484 mes->cmd = ROAR_CMD_OK;
485
486 return roar_ctl_c2m(mes, c);
487}
488
489int req_on_get_stream  (int client, struct roar_message * mes, char * data) {
490 struct roar_stream_server * s;
491
492 if ( mes->datalen != 1 )
493  return -1;
494
495 if ( streams_get(mes->data[0], &s) == -1 )
496  return -1;
497
498 mes->cmd = ROAR_CMD_OK;
499 mes->stream = mes->data[0];
500
501 return roar_stream_s2m(ROAR_STREAM(s), mes);
502}
503
504int req_on_get_stream_para (int client, struct roar_message * mes, char * data) {
505 struct roar_stream * s;
506 struct roar_stream_server * ss;
507 struct roar_audio_info * audio_info;
508 uint16_t * d = (uint16_t *) mes->data;
509 int i;
510
511 if ( mes->datalen != 4 )
512  return -1;
513
514 for (i = 0; i < mes->datalen/2; i++) {
515  d[i] = ROAR_NET2HOST16(d[i]);
516 }
517
518 if ( streams_get(mes->stream, &ss) == -1 ) {
519  ROAR_WARN("req_on_get_stream_para(*): request on non existing (or other error?) stream %i", mes->stream);
520  return -1;
521 }
522
523 if ( streams_calc_delay(mes->stream) == -1 ) {
524  ROAR_WARN("req_on_get_stream_para(*): can not calc delay for stream %i", mes->stream);
525 }
526
527 s = ROAR_STREAM(ss);
528
529 audio_info = &(s->info);
530
531 if ( d[0] != 0 || d[1] != 1 ) {
532  ROAR_WARN("req_on_get_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
533  return -1;
534 }
535
536 mes->datalen = 2*8;
537
538 d[2] = ROAR_OUTPUT_CALC_OUTBUFSIZE(audio_info);
539 d[3] = ss->pre_underruns;
540 d[4] = ss->post_underruns;
541 d[5] = ss->codec_orgi;
542 d[6] = ss->flags | (ss->primary ? ROAR_FLAG_PRIMARY : 0) | (ss->driver_id != -1 ? ROAR_FLAG_OUTPUT : 0);
543 d[7] = ss->delay/1000;
544
545 ROAR_DBG("req_on_get_stream_para(*): ss->driver_id=%i", ss->driver_id);
546
547 ROAR_DBG("req_on_get_stream_para(*): delay=%i, send delay=%i", ss->delay, d[7]);
548
549 for (i = 0; i < mes->datalen/2; i++) {
550  d[i] = ROAR_HOST2NET16(d[i]);
551 }
552
553 mes->pos = s->pos;
554
555 mes->cmd = ROAR_CMD_OK;
556 return 0;
557}
558
559int req_on_set_stream_para (int client, struct roar_message * mes, char * data) {
560 uint16_t * d = (uint16_t *) mes->data;
561 int i;
562
563 if ( mes->datalen != 8 )
564  return -1;
565
566 for (i = 0; i < mes->datalen/2; i++) {
567  d[i] = ROAR_NET2HOST16(d[i]);
568 }
569
570 if ( d[0] != 0 || d[1] != 2 ) {
571  ROAR_WARN("req_on_set_stream_para(*): unsupported command version: %i, %i", d[0], d[1]);
572  return -1;
573 }
574
575 mes->cmd     = ROAR_CMD_OK;
576 mes->datalen = 0;
577
578 ROAR_DBG("req_on_set_stream_para(*): request seems to be valid");
579
580 if ( d[2] == ROAR_RESET_FLAG ) {
581  return streams_reset_flag(mes->stream, d[3]);
582 } else {
583  return streams_set_flag(mes->stream, d[3]);
584 }
585
586 return -1;
587}
588
589int req_on_kick (int client, struct roar_message * mes, char * data) {
590 uint16_t * info = (uint16_t *) mes->data;
591
592 if ( mes->datalen != 4 )
593  return -1;
594
595 info[0] = ROAR_NET2HOST16(info[0]);
596 info[1] = ROAR_NET2HOST16(info[1]);
597
598 if ( info[0] == ROAR_OT_CLIENT ) {
599  clients_delete(info[1]);
600 } else if ( info[0] == ROAR_OT_STREAM ) {
601  streams_delete(info[1]);
602 } else if ( info[0] == ROAR_OT_SOURCE ) {
603  if ( streams_get_flag(info[1], ROAR_FLAG_SOURCE) == 1 ) {
604   streams_delete(info[1]);
605  } else {
606   return -1;
607  }
608 } else {
609  return -1;
610 }
611
612 mes->cmd     = ROAR_CMD_OK;
613 mes->datalen = 0;
614
615 return 0;
616}
617
618int req_on_attach      (int client, struct roar_message * mes, char * data) {
619 uint16_t * info = (uint16_t *) mes->data;
620
621 if ( mes->datalen < 6 )
622  return -1;
623
624 info[0] = ROAR_NET2HOST16(info[0]);
625 info[1] = ROAR_NET2HOST16(info[1]);
626 info[2] = ROAR_NET2HOST16(info[2]);
627
628 if ( info[0] != 0 )
629  return -1;
630
631 if ( info[1] == ROAR_ATTACH_SIMPLE ) {
632  if ( client_stream_move(info[2], mes->stream) == -1 )
633   return -1;
634 } else {
635  return -1;
636 }
637
638 mes->cmd     = ROAR_CMD_OK;
639 mes->datalen = 0;
640
641 return 0;
642}
643
644int req_on_set_vol (int client, struct roar_message * mes, char * data) {
645 uint16_t * info = (uint16_t *) mes->data;
646 int stream;
647 struct roar_stream_server * s;
648 int i;
649 int chans;
650
651 ROAR_DBG("req_on_set_vol(*) = ?");
652 ROAR_DBG("req_on_set_vol(*): mes->datalen=%i", mes->datalen);
653
654 if ( mes->datalen < (4*2) )
655  return -1;
656
657 if ( info[0] != 0 ) // version
658  return -1;
659
660 stream = ROAR_NET2HOST16(info[1]);
661 ROAR_DBG("req_on_set_vol(*): stream=%i", stream);
662
663 // TODO: change this code.
664 //       we should not directly change the stream object but use some stream_*()-func
665 //       for that job.
666
667 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
668  return -1;
669
670 s = g_streams[stream];
671
672 if ( s == NULL )
673  return -1;
674
675 ROAR_DBG("req_on_set_vol(*): s=%p", s);
676
677 info[2] = ROAR_NET2HOST16(info[2]);
678
679 if ( info[2] == ROAR_SET_VOL_ALL ) {
680  chans = (mes->datalen/2) - 3;
681  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ALL, channes=%i", chans);
682
683  if ( chans >= ROAR_MAX_CHANNELS )
684   return -1;
685
686  ROAR_DBG("req_on_set_vol(*): mixer at %p", s->mixer.mixer);
687
688  for (i = 0; i < chans; i++) {
689   s->mixer.mixer[i] = ROAR_NET2HOST16(info[i+3]);
690   ROAR_DBG("req_on_set_vol(*): channel %i: %i", i, ROAR_NET2HOST16(info[i+3]));
691  }
692
693  ROAR_DBG("req_on_set_vol(*): mixer changed!");
694
695 } else if ( info[2] == ROAR_SET_VOL_ONE ) {
696  ROAR_DBG("req_on_set_vol(*): mode is ROAR_SET_VOL_ONE");
697  if ( ROAR_NET2HOST16(info[3]) >= ROAR_MAX_CHANNELS )
698   return -1;
699
700  s->mixer.mixer[ROAR_NET2HOST16(info[3])] = ROAR_NET2HOST16(info[4]);
701 } else {
702  return -1;
703 }
704
705 if ( streams_set_mixer(stream) == -1 )
706  return -1;
707
708 mes->cmd     = ROAR_CMD_OK;
709 mes->datalen = 0;
710
711 return 0;
712}
713
714int req_on_get_vol (int client, struct roar_message * mes, char * data) {
715 uint16_t * info = (uint16_t *) mes->data;
716 int stream;
717 struct roar_stream_server * s;
718 int i;
719 int chans;
720
721 ROAR_DBG("req_on_get_vol(*) = ?");
722 ROAR_DBG("req_on_get_vol(*): mes->datalen=%i", mes->datalen);
723
724 if ( mes->datalen < (2*2) )
725  return -1;
726
727 if ( info[0] != 0 ) // version
728  return -1;
729
730 stream = ROAR_NET2HOST16(info[1]);
731 ROAR_DBG("req_on_get_vol(*): stream=%i", stream);
732
733 // TODO: change this code.
734 //       we should not directly change the stream object but use some stream_*()-func
735 //       for that job.
736
737 if ( stream < 0 || stream >= ROAR_STREAMS_MAX )
738  return -1;
739
740 s = g_streams[stream];
741
742 if ( s == NULL )
743  return -1;
744
745 ROAR_DBG("req_on_get_vol(*): s=%p", s);
746
747 // ok, we have everything
748
749 info[0] = 0;
750 info[1] = ROAR_HOST2NET16(chans = ROAR_STREAM(s)->info.channels);
751
752 for (i = 0; i < chans; i++)
753  info[2+i] = ROAR_HOST2NET16(s->mixer.mixer[i]);
754
755 mes->datalen = (2 + chans)*2;
756 mes->cmd = ROAR_CMD_OK;
757
758 return 0;
759}
760
761int req_on_add_data (int client, struct roar_message * mes, char * data) {
762 struct roar_buffer * b;
763 char               * buf;
764
765 if ( roar_buffer_new(&b, mes->datalen) == -1 ) {
766  ROAR_ERR("req_on_add_data(*): Can not alloc buffer space!");
767  ROAR_DBG("req_on_add_data(*) = -1");
768  return -1;
769 }
770
771 roar_buffer_get_data(b, (void **)&buf);
772
773 if ( data == NULL ) {
774  memcpy(buf, mes->data, mes->datalen);
775 } else {
776  memcpy(buf, data, mes->datalen);
777 }
778
779 if ( stream_add_buffer(mes->stream, b) == -1 ) {
780  roar_buffer_free(b);
781  return -1;
782 }
783
784 mes->cmd     = ROAR_CMD_OK_STOP;
785 mes->datalen = 0;
786
787 return 0;
788}
789
790//ll
Note: See TracBrowser for help on using the repository browser.