source: roaraudio/roarclients/roarctl.c @ 1782:95be6b012d32

Last change on this file since 1782:95be6b012d32 was 1782:95be6b012d32, checked in by phi, 15 years ago

only use try to get user/group names if possible

File size: 21.5 KB
Line 
1//roarctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarclients 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 <roaraudio.h>
26
27#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
28#define _POSIX_USERS
29#endif
30
31#ifdef _POSIX_USERS
32#include <pwd.h>
33#include <grp.h>
34#endif
35
36#include <sys/time.h>
37#include <time.h>
38
39int g_verbose = 0;
40
41int display_mixer (struct roar_connection * con, int stream);
42int show_meta_all (struct roar_connection * con, int id);
43
44void usage (void) {
45 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
46
47 printf("\nOptions:\n\n");
48
49 printf("  --server SERVER         - Set server hostname\n"
50        "  --help                  - Show this help\n"
51        "  --verbose   -v          - Show verbose output\n"
52       );
53
54 printf("\nCommands:\n\n");
55 printf(
56        "  help                    - Show this help\n"
57        "  sleep TIME              - Sleeps for TIME seconds\n"
58#ifdef ROAR_HAVE_GETTIMEOFDAY
59        "  ping  NUM               - Do NUM pings using NOOP commands\n"
60#endif
61        "\n"
62        "  standby, off            - Go into standby mode\n"
63        "  resume, on              - Go into active mode\n"
64        "  standbymode             - Show current standby mode\n"
65        "  exit                    - Quits the roard (must be used as last command)\n"
66        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
67        "                            new clients cann't connect and the server terminates after the last\n"
68        "                            client disconnected\n"
69        "\n"
70        "  volume ID CHAN V0 V1... - Sets volume for stream ID\n"
71        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
72        "                            if mono or stereo is chosen roarctl trys to set\n"
73        "                            sensfull values for all channels even if the output\n"
74        "                            is has more channels.\n"
75        "                            all other args are the volumes of the channels\n"
76        "                            you may use integer or percent values.\n"
77        "                            percent values can flooding points.\n"
78        "\n"
79        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
80        "                            seperated list of flags.\n"
81        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
82        "\n"
83        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
84        "                            Types: client stream sample source\n"
85        "\n"
86        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
87        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
88        "\n"
89        "  serveroinfo             - Gets Informations about server output\n"
90        "  listclients             - Gets Informations about clients\n"
91        "  liststreams             - Gets Informations about streams\n"
92        "  allinfo                 - Get all infos\n"
93       );
94}
95
96#ifdef ROAR_HAVE_GETTIMEOFDAY
97int ping (struct roar_connection * con, int num) {
98 struct timeval         try, ans;
99 struct roar_message    m;
100 register int           ret;
101 int                    i;
102 double                 cur, min = 3600*1000, max = 0, sum = 0;
103
104 if ( num == 0 )
105  return 0;
106
107 for (i = 0; i < num; i++) {
108  m.cmd = ROAR_CMD_NOOP;
109  m.datalen = 0;
110
111  gettimeofday(&try, NULL);
112  ret = roar_req(con, &m, NULL);
113  gettimeofday(&ans, NULL);
114
115  if ( ret == -1 )
116   return -1;
117
118  while (ans.tv_sec > try.tv_sec) {
119   ans.tv_sec--;
120   ans.tv_usec += 1000000;
121  }
122  ans.tv_usec -= try.tv_usec;
123
124  printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0));
125
126  sum += cur;
127  if ( min > cur )
128   min = cur;
129  if ( cur > max )
130   max = cur;
131
132  if ( i != (num - 1) )
133   sleep(1);
134 }
135
136 printf("\n--- ping statistics ---\n");
137 printf("%i packets transmitted\n", i);
138 printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max);
139
140 return 0;
141}
142#endif
143
144void server_oinfo (struct roar_connection * con) {
145 struct roar_stream s;
146
147 if ( roar_server_oinfo(con, &s) == -1 ) {
148  fprintf(stderr, "Error: can not get server output info\n");
149  return;
150 }
151
152 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
153 printf("Server Output rate    : %i\n", s.info.rate);
154 printf("Server Output bits    : %i\n", s.info.bits);
155 printf("Server Output channels: %i\n", s.info.channels);
156 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
157                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
158// printf("Server Output rate: %i", s.info.rate);
159  if ( g_verbose > 1 )
160   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
161}
162
163const char * proc_name (pid_t pid) {
164 static char ret[80] = "?";
165#ifdef __linux__
166 char file[80], buf[80], *r;
167 int  i;
168
169 snprintf(file, 79, "/proc/%i/exe", pid);
170 file[79] = 0;
171
172 ret[0] = '?';
173 ret[1] = 0;
174
175 if ( (i = readlink(file, buf, 79)) != -1 ) {
176  buf[i] = 0;
177  if ( (r = strrchr(buf, '/')) != NULL ) {
178   r++;
179   if ( *r != 0 )
180    strcpy(ret, r);
181  }
182 }
183#endif
184
185 return ret;
186}
187
188void list_clients (struct roar_connection * con) {
189 int i;
190 int num;
191 int h;
192 int id[ROAR_CLIENTS_MAX];
193 struct roar_client c;
194#ifdef _POSIX_USERS
195 struct group  * grp = NULL;
196 struct passwd * pwd = NULL;
197#endif
198
199 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
200  fprintf(stderr, "Error: can not get client list\n");
201  return;
202 }
203
204 for (i = 0; i < num; i++) {
205  printf("client %i:\n", id[i]);
206  if ( roar_get_client(con, &c, id[i]) == -1 ) {
207   fprintf(stderr, "Error: can not get client info\n");
208   continue;
209  }
210  printf("Player name           : %s\n", c.name);
211  printf("Player PID            : %i(%s)\n", c.pid, proc_name(c.pid));
212  if ( c.uid != -1 ) {
213#ifdef _POSIX_USERS
214   pwd = getpwuid(c.uid);
215   grp = getgrgid(c.gid);
216   printf("Player UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
217#else
218   printf("Player UID/GID        : %i/%i\n", c.uid, c.gid);
219#endif
220  }
221  if ( c.execed != -1 )
222   printf("Execed stream         : %i\n", c.execed);
223
224  for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
225   if ( c.streams[h] != -1 )
226    printf("stream                : %i\n", c.streams[h]);
227 }
228
229}
230
231void list_streams (struct roar_connection * con) {
232 int i;
233 int num;
234 int id[ROAR_STREAMS_MAX];
235 struct roar_stream s;
236 struct roar_stream_info info;
237 char flags[1024];
238
239
240 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
241  fprintf(stderr, "Error: can not get stream list\n");
242  return;
243 }
244
245 for (i = 0; i < num; i++) {
246  printf("stream %i:\n", id[i]);
247  if ( roar_get_stream(con, &s, id[i]) == -1 ) {
248   fprintf(stderr, "Error: can not get stream info\n");
249   continue;
250  }
251  printf("Stream direction      : %s\n", roar_dir2str(s.dir));
252  if ( s.pos_rel_id == -1 ) {
253   printf("Relativ position id   : none (stream not synchronized)\n");
254  } else if ( s.pos_rel_id == id[i] ) {
255   printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
256  } else {
257   printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
258  }
259  if ( g_verbose > 1 )
260   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
261  printf("Input rate            : %i\n", s.info.rate);
262  printf("Input bits            : %i\n", s.info.bits);
263  printf("Input channels        : %i\n", s.info.channels);
264  printf("Input codec           : %2i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
265                                       s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
266  if ( roar_stream_get_info(con, &s, &info) != -1 ) {
267   printf("Input codec (streamed): %2i (%s%s)\n", info.codec, roar_codec2str(info.codec),
268                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
269   if ( g_verbose ) {
270    printf("Input block size      : %i Byte\n", info.block_size);
271    printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
272    if ( g_verbose > 1 )
273     printf("Stream delay          : %ims\n",   (int)info.delay/1000);
274
275    *flags = 0;
276    if ( info.flags & ROAR_FLAG_PRIMARY )
277     strcat(flags, "primary ");
278    if ( info.flags & ROAR_FLAG_SYNC )
279     strcat(flags, "sync ");
280    if ( info.flags & ROAR_FLAG_OUTPUT )
281     strcat(flags, "output ");
282    if ( info.flags & ROAR_FLAG_SOURCE )
283     strcat(flags, "source ");
284    if ( info.flags & ROAR_FLAG_META )
285     strcat(flags, "meta ");
286    if ( info.flags & ROAR_FLAG_AUTOCONF )
287     strcat(flags, "autoconf ");
288    if ( info.flags & ROAR_FLAG_CLEANMETA )
289     strcat(flags, "cleanmeta ");
290    if ( info.flags & ROAR_FLAG_HWMIXER )
291     strcat(flags, "hwmixer ");
292    if ( info.flags & ROAR_FLAG_PAUSE )
293     strcat(flags, "pause ");
294
295    printf("Flags                 : %s\n", flags);
296   }
297  }
298  display_mixer(con, id[i]);
299  show_meta_all(con, id[i]);
300 }
301
302}
303
304int display_mixer (struct roar_connection * con, int stream) {
305 int channels;
306 struct roar_mixer_settings mixer;
307 int i;
308
309 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
310  fprintf(stderr, "Error: can not get stream mixer info\n");
311  return -1;
312 }
313
314 for (i = 0; i < channels; i++)
315  printf("Mixer volume chan %2i  : %i (%.2f%%)\n", i, mixer.mixer[i], (float)mixer.mixer[i]/655.35);
316
317 return 0;
318}
319
320int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
321 int chans = 0;
322 int id;
323 int i;
324 int len;
325 int old_chans;
326 int vol_l, vol_r;
327 char * k;
328 struct roar_mixer_settings mixer;
329 struct roar_mixer_settings old_mixer;
330
331 if (*cur + 2 > max)
332  return -1;
333
334 id = atoi(arg[++(*cur)]);
335
336 k = arg[++(*cur)];
337
338 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
339  fprintf(stderr, "Error: can not get stream mixer info\n");
340  return -1;
341 }
342
343
344// TODO: clean up code here as the % vs. abs code is very duplicate...
345
346 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) {
347  chans = 1;
348
349  if ( *cur + 1 > max )
350   return -1;
351
352  k   = arg[++(*cur)];
353  len = strlen(k);
354
355  if ( k[len - 1] == '%' ) {
356   k[len - 1] = 0;
357   vol_l = (atof(k)*65535)/100;
358  } else {
359   vol_l = atoi(k);
360  }
361
362  for (i = 0; i < old_chans; i++)
363   mixer.mixer[i] = vol_l;
364
365  chans = old_chans;
366
367 } else if ( strcmp(k, "stereo") == 0 && old_chans == 4 ) {
368  chans = 4;
369
370  if ( *cur + 2 > max )
371   return -1;
372
373  k   = arg[++(*cur)];
374  len = strlen(k);
375
376  if ( k[len - 1] == '%' ) {
377   k[len - 1] = 0;
378   vol_l = (atof(k)*65535)/100;
379  } else {
380   vol_l = atoi(k);
381  }
382
383  k   = arg[++(*cur)];
384  len = strlen(k);
385
386  if ( k[len - 1] == '%' ) {
387   k[len - 1] = 0;
388   vol_r = (atof(k)*65535)/100;
389  } else {
390   vol_r = atoi(k);
391  }
392
393  mixer.mixer[0] = vol_l;
394  mixer.mixer[1] = vol_r;
395  mixer.mixer[2] = vol_l;
396  mixer.mixer[3] = vol_r;
397
398 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) {
399  chans = 2;
400//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans);
401  ROAR_ERR("mode stereo not supported");
402  return -1;
403 } else {
404  if ( strcmp(k, "mono") == 0 ) {
405   chans = 1;
406  } else if ( strcmp(k, "stereo") == 0 ) {
407   chans = 2;
408  } else {
409   chans = atoi(k);
410  }
411
412//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans);
413
414  if ( *cur + chans > max )
415   return -1;
416
417  for (i = 0; i < chans; i++) {
418   k   = arg[++(*cur)];
419   len = strlen(k);
420
421   if ( k[len - 1] == '%' ) {
422    k[len - 1] = 0;
423    mixer.mixer[i] = (atof(k)*(int)65535)/100;
424   } else {
425    mixer.mixer[i] = atoi(k);
426   }
427  }
428 }
429
430 mixer.scale = 65535;
431
432 return roar_set_vol(con, id, &mixer, chans);
433}
434
435int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
436 struct roar_meta   meta;
437 struct roar_stream s;
438 int mode_i = ROAR_META_MODE_SET;
439
440 memset(&s, 0, sizeof(s));
441
442 s.id = id;
443
444// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
445
446 if ( strcmp(mode, "add") == 0 ) {
447  mode_i = ROAR_META_MODE_ADD;
448 }
449
450 meta.type   = roar_meta_inttype(type);
451 meta.value  = val;
452 meta.key[0] = 0;
453
454 if ( meta.type == -1 ) {
455  fprintf(stderr, "Error: unknown type: %s\n", type);
456  return -1;
457 }
458
459// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
460
461 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
462  return -1;
463
464 meta.type  = ROAR_META_TYPE_NONE;
465 meta.value = NULL;
466
467 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
468}
469
470int load_meta (struct roar_connection * con, int id, char * file) {
471 struct roar_meta   meta;
472 struct roar_stream s;
473 int mode_i = ROAR_META_MODE_SET;
474 FILE * in;
475 char lion[1024];
476 char * v;
477
478 memset(&s, 0, sizeof(s));
479
480 s.id = id;
481
482 if ( (in = fopen(file, "r")) == NULL )
483  return -1;
484
485 while (fgets(lion, 1024, in) != NULL) {
486  if ( (v = strtok(lion, "\r\n")) != NULL )
487   if ( (v = strtok(NULL, "\r\n")) != NULL )
488    *(v-1) = 0;
489
490  if ( (v = strstr(lion, "=")) == NULL ) {
491   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
492   continue;
493  }
494
495  *v++ = 0;
496
497  meta.type   = roar_meta_inttype(lion);
498  meta.value  = v;
499  meta.key[0] = 0;
500
501  if ( meta.type == -1 ) {
502   fprintf(stderr, "Error: unknown type: %s\n", lion);
503   continue;
504  }
505
506  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
507   return -1;
508 }
509
510 fclose(in);
511
512 meta.type  = ROAR_META_TYPE_NONE;
513 meta.value = NULL;
514
515 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
516}
517
518int show_meta_type (struct roar_connection * con, int id, char * type) {
519 struct roar_meta   meta;
520 struct roar_stream s;
521
522 memset(&s, 0, sizeof(s));
523
524 s.id = id;
525
526 meta.type  = roar_meta_inttype(type);
527
528 if ( meta.type == -1 ) {
529  fprintf(stderr, "Error: unknown type: %s\n", type);
530  return -1;
531 }
532
533 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
534  return -1;
535
536 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
537
538 roar_meta_free(&meta);
539
540 return 0;
541}
542
543int show_meta_all (struct roar_connection * con, int id) {
544 struct roar_stream s;
545 int types[ROAR_META_MAX_PER_STREAM];
546 int i;
547 int len;
548
549 memset(&s, 0, sizeof(s));
550
551 s.id = id;
552
553 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
554  return -1;
555
556 for (i = 0; i < len; i++)
557  show_meta_type(con, id, roar_meta_strtype(types[i]));
558
559 return 0;
560}
561
562int save_meta (struct roar_connection * con, int id, char * file) {
563 struct roar_stream s;
564 struct roar_meta   meta;
565 int types[ROAR_META_MAX_PER_STREAM];
566 int i;
567 int len;
568 FILE * out;
569
570 memset(&s, 0, sizeof(s));
571
572 s.id = id;
573
574 if ( (out = fopen(file, "w")) == NULL )
575  return -1;
576
577 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
578  return -1;
579
580 for (i = 0; i < len; i++) {
581/*
582  show_meta_type(con, id, roar_meta_strtype(types[i]));
583*/
584  meta.type  = types[i];
585
586  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
587   continue;
588
589//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
590
591  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
592
593  roar_meta_free(&meta);
594 }
595
596 fclose(out);
597
598 return 0;
599}
600
601int set_flags (struct roar_connection * con, int id, int reset, char * flags) {
602 int f = ROAR_FLAG_NONE;
603 char * c;
604 struct roar_stream s[1];
605
606 memset(s, 0, sizeof(struct roar_stream));
607
608 s->id = id;
609
610 c = strtok(flags, ",");
611 while (c != NULL) {
612  if ( !strcmp(c, "meta") ) {
613   f |= ROAR_FLAG_META;
614  } else if ( !strcmp(c, "primary") ) {
615   f |= ROAR_FLAG_PRIMARY;
616  } else if ( !strcmp(c, "sync") ) {
617   f |= ROAR_FLAG_SYNC;
618  } else if ( !strcmp(c, "cleanmeta") ) {
619   f |= ROAR_FLAG_CLEANMETA;
620  } else if ( !strcmp(c, "hwmixer") ) {
621   f |= ROAR_FLAG_HWMIXER;
622  } else if ( !strcmp(c, "pause") ) {
623   f |= ROAR_FLAG_PAUSE;
624  } else {
625   fprintf(stderr, "Error: unknown flag: %s\n", c);
626   return -1;
627  }
628
629  c = strtok(NULL, ",");
630 }
631
632 return roar_stream_set_flags(con, s, f, reset);
633}
634
635int main (int argc, char * argv[]) {
636 struct roar_connection con;
637 char * server   = NULL;
638 char * k = NULL;
639 int    i;
640 int    t = 0;
641
642 for (i = 1; i < argc; i++) {
643  k = argv[i];
644
645  if ( strcmp(k, "--server") == 0 ) {
646   server = argv[++i];
647  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
648   g_verbose++;
649  } else if ( strcmp(k, "--help") == 0 ) {
650   usage();
651   return 0;
652  } else if ( *k == '-' ) {
653   fprintf(stderr, "Error: unknown argument: %s\n", k);
654   usage();
655   return 1;
656  } else {
657   break;
658  }
659 }
660
661 // connect
662
663 if ( roar_connect(&con, server) == -1 ) {
664  fprintf(stderr, "Error: Can not connect to server\n");
665  return 1;
666 }
667
668 if ( roar_identify(&con, "roarctl") == -1 ) {
669  fprintf(stderr, "Error: Can not identify to server\n");
670  return 1;
671 }
672
673 if ( i == argc ) {
674  fprintf(stderr, "Error: No Commands given\n");
675  return 0; // this is not a fatal error...
676 }
677
678 for (; i < argc; i++) {
679  k = argv[i];
680  // cmd is in k
681
682  printf("--- [ %s ] ---\n", k);
683
684  if ( !strcmp(k, "help") ) {
685   usage();
686
687  } else if ( !strcmp(k, "sleep") ) {
688   sleep(atoi(argv[++i]));
689
690  } else if ( !strcmp(k, "ping") ) {
691#ifdef ROAR_HAVE_GETTIMEOFDAY
692   if ( ping(&con, atoi(argv[++i])) == -1 ) {
693    fprintf(stderr, "Error: can not ping\n");
694   }
695#else
696    fprintf(stderr, "Error: ping not supported.\n");
697    i++;
698#endif
699
700  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
701   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
702    fprintf(stderr, "Error: can not set mode to standby\n");
703   } else {
704    printf("going into standby\n");
705   }
706  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
707   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
708    fprintf(stderr, "Error: can not set mode to active\n");
709   } else {
710    printf("going into active mode\n");
711   }
712
713  } else if ( !strcmp(k, "exit") ) {
714   if ( roar_exit(&con) == -1 ) {
715    fprintf(stderr, "Error: can not quit server\n");
716   } else {
717    printf("Server quited\n");
718    break;
719   }
720  } else if ( !strcmp(k, "terminate") ) {
721   if ( roar_terminate(&con, 1) == -1 ) {
722    fprintf(stderr, "Error: can not terminate server\n");
723   } else {
724    printf("Server got asked to quited\n");
725    break;
726   }
727
728  } else if ( !strcmp(k, "standbymode") ) {
729   t = roar_get_standby(&con);
730   if ( t == -1 ) {
731    fprintf(stderr, "Error: can not get stanby mode\n");
732   } else if ( t == ROAR_STANDBY_ACTIVE ) {
733    printf("Server is in standby\n");
734   } else if ( t == ROAR_STANDBY_INACTIVE ) {
735    printf("Server is active\n");
736   } else {
737    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
738   }
739
740  } else if ( !strcmp(k, "whoami") ) {
741   printf("My client ID is: %i\n", roar_get_clientid(&con));
742  } else if ( !strcmp(k, "serveroinfo") ) {
743   server_oinfo(&con);
744  } else if ( !strcmp(k, "listclients") ) {
745   list_clients(&con);
746  } else if ( !strcmp(k, "liststreams") ) {
747   list_streams(&con);
748  } else if ( !strcmp(k, "allinfo") ) {
749   server_oinfo(&con);
750   printf("\n");
751   list_clients(&con);
752   printf("\n");
753   list_streams(&con);
754
755  } else if ( !strcmp(k, "kick") ) {
756   k = argv[++i];
757   if ( !strcmp(k, "client") ) {
758    t = ROAR_OT_CLIENT;
759   } else if ( !strcmp(k, "stream") ) {
760    t = ROAR_OT_STREAM;
761   } else if ( !strcmp(k, "sample") ) {
762    t = ROAR_OT_SAMPLE;
763   } else if ( !strcmp(k, "source") ) {
764    t = ROAR_OT_SOURCE;
765   } else {
766    fprintf(stderr, "Error: unknown type: %s\n", k);
767    continue;
768   }
769   //t = atoi(argv[i++]);
770   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
771    fprintf(stderr, "Error: can not kick %s\n", k);
772   } else {
773    printf("%s kicked\n", k);
774   }
775
776  } else if ( !strcmp(k, "volume") ) {
777   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
778    fprintf(stderr, "Error: can not set volume\n");
779   } else {
780    printf("volume changed\n");
781   }
782
783  } else if ( !strcmp(k, "flag") ) {
784   i++;
785   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
786    fprintf(stderr, "Error: can not set flags\n");
787   } else {
788    printf("flags changed\n");
789   }
790   i++;
791  } else if ( !strcmp(k, "unflag") ) {
792   i++;
793   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
794    fprintf(stderr, "Error: can not reset flags\n");
795   } else {
796    printf("flags changed\n");
797   }
798   i++;
799  } else if ( !strcmp(k, "metaset") ) {
800   i++;
801   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
802    fprintf(stderr, "Error: can not set meta data\n");
803   } else {
804    printf("meta data changed\n");
805   }
806   i += 3;
807  } else if ( !strcmp(k, "metaget") ) {
808   i++;
809   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
810    fprintf(stderr, "Error: can not get meta data\n");
811   }
812   i++;
813  } else if ( !strcmp(k, "metasave") ) {
814   i++;
815   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
816    fprintf(stderr, "Error: can not get meta data\n");
817   } else {
818    printf("meta data saved\n");
819   }
820   i++;
821  } else if ( !strcmp(k, "metaload") ) {
822   i++;
823   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
824    fprintf(stderr, "Error: can not set meta data\n");
825   } else {
826    printf("meta data saved\n");
827   }
828   i++;
829
830  } else {
831   fprintf(stderr, "Error: invalid command: %s\n", k);
832  }
833
834 }
835
836 roar_disconnect(&con);
837
838 return 0;
839}
840
841//ll
Note: See TracBrowser for help on using the repository browser.