source: roaraudio/roarclients/roarctl.c @ 5379:2a383aaf4b1b

Last change on this file since 5379:2a383aaf4b1b was 5379:2a383aaf4b1b, checked in by phi, 12 years ago
  • Cleanup,
  • Set ISIT_BUILD in roard,
  • Test for more alternatives for ssh-askpass,
  • Display more infors in "allinfo" command in roarctl,
  • Display server time using ctime_r() in roarctl.
File size: 39.8 KB
Line 
1//roarctl.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26/* ckport options:
27 * ckport: ignore-symbol: roar_req of target libroar0 -- Used within ping command.
28 */
29
30#define _UNITS_T_BASE_USEC
31
32#include <roaraudio.h>
33#include <roaraudio/units.h>
34#include <libroardsp/libroardsp.h>
35
36#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
37#define _POSIX_USERS
38#endif
39
40#ifdef _POSIX_USERS
41#include <pwd.h>
42#include <grp.h>
43#endif
44
45#include <sys/time.h>
46#include <time.h>
47
48#ifdef ROAR_HAVE_LIBM
49#include <math.h>
50#endif
51
52int g_verbose = 0;
53
54void display_client (struct roar_connection * con, int id);
55void display_stream (struct roar_connection * con, int id);
56int display_mixer (struct roar_connection * con, int stream);
57int show_meta_all (struct roar_connection * con, int id);
58
59void usage (void) {
60 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
61
62 printf("\nOptions:\n\n");
63
64 printf("  --server SERVER         - Set server hostname\n"
65        "  --help                  - Show this help\n"
66        "  --verbose   -v          - Show verbose output\n"
67        "  --list-aiprofiles       - Show audio info profiles and exit\n"
68        "  --list-libstandards     - Gets list of library (libroar) supported standards\n"
69        "  --enum-servers          - Show a list of possible servers\n"
70        "  --hash-password         - Hash a password and exit\n"
71       );
72
73 printf("\nCommands:\n\n");
74 printf(
75        "  help                    - Show this help\n"
76        "  sleep TIME              - Sleeps for TIME seconds\n"
77#ifdef ROAR_HAVE_GETTIMEOFDAY
78        "  ping  NUM               - Do NUM pings using NOOP commands\n"
79#endif
80        "  whoami                  - Get own client ID\n"
81        "\n"
82        "  listaiprofiles          - list audio info profiles\n"
83        "  aiprofileget PROFILE    - show audio info profile PROFILE\n"
84        "\n"
85        "  standby, off            - Go into standby mode\n"
86        "  resume, on              - Go into active mode\n"
87        "  standbymode             - Show current standby mode\n"
88        "  exit                    - Quits the roard (must be used as last command)\n"
89        "  terminate               - Like exit but let the server up to serve still connected clients,\n"
90        "                            new clients cann't connect and the server terminates after the last\n"
91        "                            client disconnected\n"
92        "\n"
93        "  volume ID CHAN [scale S] V0 V1...\n"
94        "                          - Sets volume for stream ID\n"
95        "                            CHAN is the number of channels or 'mono' or 'stereo'\n"
96        "                            if mono or stereo is chosen roarctl trys to set\n"
97        "                            sensfull values for all channels even if the output\n"
98        "                            is has more channels.\n"
99        "                            An optional scale can be given using S.\n"
100        "                            all other args are the volumes of the channels\n"
101        "                            you may use integer or percent values.\n"
102        "                            percent values can floating points.\n"
103        "\n"
104        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
105        "                            separated list of flags.\n"
106        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
107        "  toogleflag ID FLAGS     - Toggels flags on a stream. See flag.\n"
108        "  protectflag ID FLAGS    - Protects flags on a stream. Those flags can not be\n"
109        "                            changed anymore after the they got protected. See flag.\n"
110        "\n"
111        "  role ID ROLE            - Set role ROLE on stream ID.\n"
112        "\n"
113        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
114        "                            Types: client stream sample source\n"
115        "  newvirtual P D E R B C  - Adds a new virtual (child) stream\n"
116        "                            Parameters:\n"
117        "                             P: Parent stream ID, D: Direction,\n"
118        "                             E: codEc, R: sample Rate,\n"
119        "                             B: bits per sample, C: nummer of channels\n"
120        "\n"
121        "  metaget  ID TYPE        - Read meta date of type TYPE from stream ID\n"
122// TODO: document metaset here.
123        "  metasave ID FILE        - Saves meta data of stream ID to file FILE\n"
124        "  metaload ID FILE        - Loads meta data from file FILE and set it on stream ID\n"
125        "\n"
126        "  serverinfo              - Gets general information about the server\n"
127        "  servertime              - Gets server's time\n"
128        "  serveroinfo             - Gets Information about server output\n"
129        "  serveroinfo2 DIR        - Gets Information about server output for stream direction dir\n"
130        "\n"
131        "  serverstandards         - Gets list of server supported standards\n"
132        "  libstandards            - Gets list of library (libroar) supported standards\n"
133        "\n"
134        "  listclients             - Gets Information about clients\n"
135        "  clientinfo ID           - Gets Information about client ID\n"
136        "  liststreams             - Gets Information about streams\n"
137        "  streaminfo ID           - Gets Information about stream ID\n"
138        "  allinfo                 - Get all infos\n"
139       );
140}
141
142static void _bin2hex(char * out, char * in, size_t inlen, int uppercase) {
143 const char * tab = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
144 unsigned char c;
145 int nib0, nib1;
146
147 for (; inlen; inlen--) {
148  c = *(in++);
149  nib0 = (c & 0x0F) >> 0;
150  nib1 = (c & 0xF0) >> 4;
151//  printf("inlen=%zu, c=%u, nibs={%i, %i}\n", inlen, (unsigned)c, nib1, nib0);
152  *(out++) = tab[nib1];
153  *(out++) = tab[nib0];
154 }
155 *out = 0;
156}
157
158int hash_password (void) {
159 char * pw = NULL;
160 char salt[8];
161 char digest[24];
162 char out[2*(8+24)+3+5+1] = "tiger:";
163
164 if ( roar_passwd_simple_ask_pw(&pw, "Password to hash?", NULL) == -1 )
165  return -1;
166
167 roar_random_gen_nonce(salt, sizeof(salt));
168
169 roar_hash_salted_buffer(digest, pw, roar_mm_strlen(pw), ROAR_HT_TIGER, salt, sizeof(salt));
170
171 roar_mm_free(pw);
172
173 _bin2hex(out+6, salt, sizeof(salt), 0);
174 out[6+16] = ':';
175 _bin2hex(out+6+16+1, digest, sizeof(digest), 0);
176
177 out[sizeof(out)-1] = 0;
178
179 printf("Password: %s\n", out);
180
181 return 0;
182}
183
184int enum_servers (void) {
185 struct roar_server * list;
186 struct roar_server * c;
187 int flags    = ROAR_ENUM_FLAG_DESC|ROAR_ENUM_FLAG_LOCATION;
188 int dir      = -1;
189 int socktype = -1;
190 int i;
191
192 if ( (list = roar_enum_servers(flags, dir, socktype)) == NULL )
193  return -1;
194
195 printf("Server           Location         Description\n");
196 printf("----------------------------------------------------------------------\n");
197
198 for (i = 0; ; i++) {
199  c = &(list[i]);
200  printf("%-16s %-16s %s\n",
201             c->server      == NULL ? "(default)" : c->server,
202             c->location    == NULL ? ""          : c->location,
203             c->description == NULL ? ""          : c->description
204        );
205  if ( c->server == NULL )
206   break;
207 }
208
209 roar_enum_servers_free(list);
210
211 return 0;
212}
213
214#ifdef ROAR_HAVE_GETTIMEOFDAY
215int ping (struct roar_connection * con, int num) {
216 struct timeval         try, ans;
217 struct roar_message    m;
218 register int           ret;
219 int                    i;
220 double                 cur, min = 3600*1000, max = 0, sum = 0;
221
222 if ( num == 0 )
223  return 0;
224
225 for (i = 0; i < num; i++) {
226  memset(&m, 0, sizeof(m));
227
228  m.cmd = ROAR_CMD_NOOP;
229  m.stream  = -1;
230  m.datalen =  0;
231
232  // we use roar_req() directly here because of speed.
233  // roar_noop() does basicly the same but is a bit slower.
234
235  gettimeofday(&try, NULL);
236  ret = roar_req(con, &m, NULL);
237  gettimeofday(&ans, NULL);
238
239  if ( ret == -1 )
240   return -1;
241
242  while (ans.tv_sec > try.tv_sec) {
243   ans.tv_sec--;
244   ans.tv_usec += 1000000;
245  }
246  ans.tv_usec -= try.tv_usec;
247
248  printf("Pong from server: seq=%i time=%.3fms\n", i, (cur = ans.tv_usec/1000.0));
249
250  sum += cur;
251  if ( min > cur )
252   min = cur;
253  if ( cur > max )
254   max = cur;
255
256  if ( i != (num - 1) )
257   roar_sleep(1);
258 }
259
260 printf("\n--- ping statistics ---\n");
261 printf("%i packets transmitted\n", i);
262 printf("rtt min/avg/max = %.3f/%.3f/%.3f ms\n", min, sum/(double)i, max);
263
264 return 0;
265}
266#endif
267
268#define _pm(m,n) if ( info->m != NULL ) printf("Server %-15s: %s\n", (n), (info->m));
269void server_info (struct roar_connection * con) {
270 struct roar_server_info * info = roar_server_info(con);
271 long hostid;
272
273 if ( info == NULL ) {
274  fprintf(stderr, "Error: can not get server info\n");
275  return;
276 }
277
278 _pm(version, "Version");
279 _pm(location, "Location");
280 _pm(description, "Description");
281 _pm(contact, "Contact");
282 _pm(serial, "Serial");
283 _pm(address, "Address");
284 _pm(uiurl, "UI URL");
285 _pm(license, "License");
286// _pm(hostid, "HostID");
287 if ( info->hostid != NULL ) {
288  if ( sscanf(info->hostid, "0x%lx", &hostid) != 1 )
289   hostid = 0;
290
291  if ( hostid ) {
292   printf("Server %-15s: %s (%li.%li.%li.%li)\n", "HostID", info->hostid,
293           ((hostid & 0x00FF0000UL) >> 16UL),
294           ((hostid & 0xFF000000UL) >> 24UL),
295           ((hostid & 0x000000FFUL) >>  0UL),
296           ((hostid & 0x0000FF00UL) >>  8UL)
297         );
298  } else {
299   printf("Server %-15s: %s\n", "HostID", info->hostid);
300  }
301 }
302 _pm(build, "Build");
303 _pm(un.sysname, "System sysname");
304 _pm(un.release, "System release");
305 _pm(un.nodename, "System nodename");
306 _pm(un.machine, "System machine");
307
308 roar_server_info_free(info);
309}
310#undef _pm
311
312void server_time (struct roar_connection * con) {
313 struct roar_time time;
314#ifdef ROAR_HAVE_CTIME_R
315 time_t server_time;
316 char server_time_buf[32];
317#endif
318
319
320 if ( roar_get_time(con, &time) == -1 ) {
321  fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error));
322  return;
323 }
324
325#ifdef ROAR_HAVE_CTIME_R
326 server_time = time.t_sec;
327 if ( ctime_r(&server_time, server_time_buf) == NULL )
328  server_time_buf[0] = 0;
329
330 if ( server_time_buf[0] )
331  if ( server_time_buf[strlen(server_time_buf)-1] == '\n' )
332   server_time_buf[strlen(server_time_buf)-1] = 0;
333#endif
334
335 if ( g_verbose ) {
336  printf("Server time           : %s%s%s%llu.%06llu [+%llu/2^64] sec\n",
337#ifdef ROAR_HAVE_CTIME_R
338         "\"",
339         server_time_buf,
340         "\" ",
341#else
342         "", "", "",
343#endif
344         (long long unsigned int)time.t_sec,
345         (long long unsigned int) time.t_ssec / 18446744073709LLU,
346         (long long unsigned int) time.t_ssec);
347 } else {
348  if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) {
349   printf("Server time           : %s%s%s%llu sec\n",
350#ifdef ROAR_HAVE_CTIME_R
351         "\"",
352         server_time_buf,
353         "\" ",
354#else
355         "", "", "",
356#endif
357          (long long unsigned int)time.t_sec);
358  } else {
359   printf("Server time           : %s%s%s%llu.%06llu sec\n",
360#ifdef ROAR_HAVE_CTIME_R
361         "\"",
362         server_time_buf,
363         "\" ",
364#else
365         "", "", "",
366#endif
367          (long long unsigned int)time.t_sec,
368          (long long unsigned int) time.t_ssec / 18446744073709LLU);
369  }
370 }
371 if ( time.c_freq )
372  printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.));
373 if ( time.c_drift ) {
374#ifdef ROAR_HAVE_LIBM
375  printf("Server clock drift    : %llu:2^64 (~10^%f)\n",
376         (long long unsigned int)time.c_drift, logf((float)time.c_drift)/2.302585f);
377#else
378  printf("Server clock drift    : %llu:2^64\n",
379         (long long unsigned int)time.c_drift);
380#endif
381 }
382}
383
384void server_oinfo (struct roar_connection * con, int dir) {
385 struct roar_stream s;
386
387 if ( roar_server_oinfo(con, &s, dir) == -1 ) {
388  fprintf(stderr, "Error: can not get server output info\n");
389  return;
390 }
391
392 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
393 printf("Server Output rate    : %i Hz\n", s.info.rate);
394 printf("Server Output bits    : %i\n", s.info.bits);
395 printf("Server Output channels: %i\n", s.info.channels);
396 printf("Server Output codec   : %i (%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
397                                     s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "");
398// printf("Server Output rate: %i", s.info.rate);
399  if ( g_verbose > 1 && s.pos != (uint32_t)-1 )
400   printf("Server Position       : %lu S (%.3fs)\n", (unsigned long int) s.pos, (float)s.pos/(s.info.rate*s.info.channels));
401}
402
403static void print_stds (const struct roar_stds * stds) {
404 size_t i;
405 int vendor, standard, version;
406 char numbuf[2][8];
407 const char * vendor_name;
408
409 for (i = 0; i < stds->stds_len; i++) {
410  vendor   = ROAR_STD_VENDOR(stds->stds[i]);
411  standard = ROAR_STD_STD(stds->stds[i]);
412  version  = ROAR_STD_VERSION(stds->stds[i]);
413
414  if ( (vendor_name = roar_stds_vendor2str(vendor)) == NULL ) {
415   snprintf(numbuf[0], sizeof(numbuf[0]), "%i", vendor);
416   numbuf[0][sizeof(numbuf[0])-1] = 0;
417   vendor_name = numbuf[0];
418  }
419
420  if ( version == 0 ) {
421   numbuf[1][0] = 0;
422  } else {
423   snprintf(numbuf[1], sizeof(numbuf[1]), "-%i", version);
424   numbuf[1][sizeof(numbuf[1])-1] = 0;
425  }
426
427  printf("Server standard       : %s-%i%s\n", vendor_name, standard, numbuf[1]);
428 }
429}
430
431void server_standards (struct roar_connection * con) {
432 struct roar_stds * stds;
433
434 if ( roar_caps_stds(con, &stds, NULL, -1) == -1 ) {
435  fprintf(stderr, "Error: can not get server standards\n");
436  return;
437 }
438
439 print_stds(stds);
440
441 roar_stds_free(stds);
442}
443
444void lib_standards (void) {
445 print_stds(libroar_libstds());
446}
447
448const char * proc_name (pid_t pid) {
449 static char ret[80] = "?";
450#ifdef __linux__
451 char file[80], buf[80], *r;
452 int  i;
453
454 snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid);
455 file[sizeof(file)-1] = 0;
456
457 ret[0] = '?';
458 ret[1] = 0;
459
460 if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) {
461  buf[i] = 0;
462  if ( (r = strrchr(buf, '/')) != NULL ) {
463   r++;
464   if ( *r != 0 ) {
465    strncpy(ret, r, sizeof(ret)-1);
466    ret[sizeof(ret)-1] = 0;
467   }
468  }
469 }
470#else
471 (void)pid;
472#endif
473
474 return ret;
475}
476
477void list_clients (struct roar_connection * con) {
478 int i;
479 int num;
480 int id[ROAR_CLIENTS_MAX];
481
482 if ( (num = roar_list_clients(con, id, ROAR_CLIENTS_MAX)) == -1 ) {
483  fprintf(stderr, "Error: can not get client list\n");
484  return;
485 }
486
487 for (i = 0; i < num; i++) {
488  display_client(con, id[i]);
489 }
490}
491
492void display_client (struct roar_connection * con, int id) {
493 static int self_id = -1;
494 static struct roar_client   self_client_store;
495 static struct roar_client * self_client = NULL;
496 struct roar_client c;
497 char tmp[80];
498 int h;
499#ifdef _POSIX_USERS
500 struct group  * grp = NULL;
501 struct passwd * pwd = NULL;
502#endif
503
504 if ( self_id == -1 ) {
505  if ( (self_id = roar_get_clientid(con)) != -1 ) {
506   if ( roar_get_client(con, &self_client_store, self_id) == -1 ) {
507    self_id = -1;
508   } else {
509    self_client = &self_client_store;
510   }
511  }
512 }
513
514 printf("client %i:\n", id);
515 if ( roar_get_client(con, &c, id) == -1 ) {
516  fprintf(stderr, "Error: can not get client info\n");
517  return;
518 }
519
520 if ( c.name[0] != '\0' )
521  printf("Client name           : %s\n", c.name);
522  if ( roar_nnode_get_socktype(&(c.nnode)) != ROAR_SOCKET_TYPE_UNKNOWN ) {
523  if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) {
524   printf("Client network node   : %s\n", tmp);
525  }
526 }
527
528 if ( c.pid != -1 ) {
529  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
530   printf("Client PID            : %i(%s)\n", c.pid, proc_name(c.pid));
531  } else {
532   printf("Client PID            : %i\n", c.pid);
533  }
534 }
535 if ( c.uid != -1 ) {
536#ifdef _POSIX_USERS
537  if ( self_id != -1 && roar_nnode_cmp(&(self_client->nnode), &(c.nnode)) == 0 ) {
538   pwd = getpwuid(c.uid);
539   grp = getgrgid(c.gid);
540   printf("Client UID/GID        : %i(%s)/%i(%s)\n", c.uid, pwd ? pwd->pw_name : "?", c.gid, grp ? grp->gr_name : "?");
541  } else {
542#else
543  if ( 1 ) {
544#endif
545   printf("Client UID/GID        : %i/%i\n", c.uid, c.gid);
546  }
547 }
548
549 if ( g_verbose && c.proto != ROAR_PROTO_NONE ) {
550  printf("Client Protocol       : %s\n", roar_proto2str(c.proto));
551 }
552
553 if ( g_verbose && c.byteorder != ROAR_BYTEORDER_UNKNOWN ) {
554  if ( c.byteorder == ROAR_BYTEORDER_NETWORK ) {
555   roar_mm_strscpy(tmp, " (network byteorder");
556  } else {
557   *tmp = 0;
558  }
559
560  if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) {
561   if ( *tmp ) {
562    roar_mm_strscat(tmp, ", native");
563   } else {
564    roar_mm_strscpy(tmp, " (native");
565   }
566  }
567
568  if ( *tmp )
569   roar_mm_strscat(tmp, ")");
570
571  printf("Client Byteorder      : %s%s\n", roar_byteorder2str(c.byteorder), tmp);
572 }
573
574 if ( c.execed != -1 )
575  printf("Execed stream         : %i\n", c.execed);
576
577 for (h = 0; h < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; h++)
578  if ( c.streams[h] != -1 )
579   printf("stream                : %i\n", c.streams[h]);
580}
581
582void list_streams (struct roar_connection * con) {
583 int i;
584 int num;
585 int id[ROAR_STREAMS_MAX];
586
587 if ( (num = roar_list_streams(con, id, ROAR_STREAMS_MAX)) == -1 ) {
588  fprintf(stderr, "Error: can not get stream list\n");
589  return;
590 }
591
592 for (i = 0; i < num; i++) {
593  display_stream(con, id[i]);
594 }
595}
596
597void display_stream (struct roar_connection * con, int id) {
598 char chanmap[ROAR_MAX_CHANNELS];
599 struct roar_stream s;
600 struct roar_stream_info info;
601 char buffer[1024];
602 char * flags = buffer;
603 char * name  = buffer;
604 char * infotext;
605 const char * mime;
606 size_t len;
607
608 printf("stream %i:\n", id);
609 if ( roar_get_stream(con, &s, id) == -1 ) {
610  fprintf(stderr, "Error: can not get stream info\n");
611  return;
612 }
613 printf("Stream direction      : %s\n", roar_dir2str(s.dir));
614
615 if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 )
616  printf("Stream name           : %s\n", name);
617
618 if ( (int)s.pos_rel_id == -1 ) {
619  printf("Relativ position id   : none (stream not synchronized)\n");
620 } else if ( (int)s.pos_rel_id == id ) {
621  printf("Relativ position id   : %i (self synchronized)\n", s.pos_rel_id);
622 } else {
623  printf("Relativ position id   : %i (synchronized)\n", s.pos_rel_id);
624 }
625 if ( g_verbose > 1 && s.pos != (uint32_t)-1 ) {
626  if ( s.info.rate && s.info.channels ) {
627   printf("Position              : %lu S (%.3fs)\n", (unsigned long int) s.pos,
628                                   (float)s.pos/(s.info.rate*s.info.channels));
629  } else {
630   printf("Position              : %lu S\n", (unsigned long int) s.pos);
631  }
632 }
633
634 switch (s.dir) {
635  case ROAR_DIR_MIDI_IN:
636  case ROAR_DIR_MIDI_OUT:
637    infotext = " ticks/s";
638   break;
639  case ROAR_DIR_LIGHT_IN:
640  case ROAR_DIR_LIGHT_OUT:
641    infotext = " updates/s";
642   break;
643  default:
644    infotext = " Hz";
645 }
646 if ( s.info.rate )
647  printf("Stream sample rate    : %i%s\n", s.info.rate, infotext);
648 if ( s.info.bits )
649  printf("Stream bits           : %i\n", s.info.bits);
650 if ( s.info.channels )
651  printf("Stream channels       : %i\n", s.info.channels);
652
653 mime = roar_codec2mime(s.info.codec);
654 printf("Stream codec          : %2i (%s%s%s%s)\n", s.info.codec, roar_codec2str(s.info.codec),
655                                      s.info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
656                                      mime == NULL ? "" : " mimetype:",
657                                      mime == NULL ? "" : mime
658                                     );
659 if ( roar_stream_get_info(con, &s, &info) != -1 ) {
660  if ( info.codec != s.info.codec ) {
661   mime = roar_codec2mime(info.codec);
662   printf("Streamed codec        : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
663                                      info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
664                                      mime == NULL ? "" : " mimetype:",
665                                      mime == NULL ? "" : mime
666                                     );
667  }
668
669  if ( g_verbose ) {
670   if ( info.block_size )
671    printf("Stream block size     : %i Byte\n", info.block_size);
672
673   printf("Underruns pre/post    : %i/%i\n",   info.pre_underruns, info.post_underruns);
674   if ( g_verbose > 1 )
675    printf("Stream delay          : %ims (%.2fm)\n",   (int)info.delay/1000, (info.delay*(float)_SPEED_OF_SOUND));
676
677   if ( g_verbose > 1 )
678    printf("Stream mixer          : %i\n",   info.mixer);
679
680   if ( g_verbose > 1 )
681    printf("Stream state          : %s\n",   roar_streamstate2str(info.state));
682
683   if ( g_verbose > 1 )
684    printf("Stream role           : %s\n",   roar_role2str(info.role));
685
686   *flags = 0;
687#define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer))
688   if ( info.flags & ROAR_FLAG_PRIMARY )
689    _strcat(flags, "primary ");
690   if ( info.flags & ROAR_FLAG_SYNC )
691    _strcat(flags, "sync ");
692   if ( info.flags & ROAR_FLAG_OUTPUT )
693    _strcat(flags, "output ");
694   if ( info.flags & ROAR_FLAG_SOURCE )
695    _strcat(flags, "source ");
696   if ( info.flags & ROAR_FLAG_META )
697    _strcat(flags, "meta ");
698   if ( info.flags & ROAR_FLAG_AUTOCONF )
699    _strcat(flags, "autoconf ");
700   if ( info.flags & ROAR_FLAG_CLEANMETA )
701    _strcat(flags, "cleanmeta ");
702   if ( info.flags & ROAR_FLAG_HWMIXER )
703    _strcat(flags, "hwmixer ");
704   if ( info.flags & ROAR_FLAG_PAUSE )
705    _strcat(flags, "pause ");
706   if ( info.flags & ROAR_FLAG_MUTE )
707    _strcat(flags, "mute ");
708   if ( info.flags & ROAR_FLAG_MMAP )
709    _strcat(flags, "mmap ");
710   if ( info.flags & ROAR_FLAG_ANTIECHO )
711    _strcat(flags, "antiecho ");
712   if ( info.flags & ROAR_FLAG_VIRTUAL )
713    _strcat(flags, "virtual ");
714   if ( info.flags & ROAR_FLAG_RECSOURCE )
715    _strcat(flags, "recsource ");
716   if ( info.flags & ROAR_FLAG_PASSMIXER )
717    _strcat(flags, "passmixer ");
718   if ( info.flags & ROAR_FLAG_PRETHRU )
719    _strcat(flags, "prethru ");
720   if ( info.flags & ROAR_FLAG_IMMUTABLE )
721    _strcat(flags, "immutable ");
722   if ( info.flags & ROAR_FLAG_ENHANCE )
723    _strcat(flags, "enhance ");
724   if ( info.flags & ROAR_FLAG_SINGLESINK )
725    _strcat(flags, "singlesink ");
726#undef _strcat
727
728   printf("Flags                 : %s\n", flags);
729  }
730 }
731
732 if ( g_verbose ) {
733  len = ROAR_MAX_CHANNELS;
734  if ( roar_stream_get_chanmap(con, &s, chanmap, &len) == -1 ) {
735   fprintf(stderr, "Error: can not get stream channel map\n");
736  } else {
737   if ( roardsp_chanlist2str(chanmap, len, buffer, 1024) == -1 ) {
738    fprintf(stderr, "Error: can not convert channel map into string\n");
739   } else {
740    printf("Channel Map           : %s\n", buffer);
741   }
742  }
743 }
744
745 if ( s.dir != ROAR_DIR_THRU ) {
746  display_mixer(con, id);
747  show_meta_all(con, id);
748 }
749}
750
751int display_mixer (struct roar_connection * con, int stream) {
752 struct roar_mixer_settings mixer;
753 int channels;
754 int i;
755 float fs;
756
757 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
758  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream);
759  return -1;
760 }
761
762#ifdef ROAR_HAVE_LIBM
763#define _DB ", %.2fdB"
764#else
765#define _DB ""
766#endif
767
768 fs = (float)mixer.scale / 100.;
769
770 if ( channels ) { // we hide RPG info for zero-channel streams
771  printf("Mixer ReplayGain      : %i/%i (%.2f%%" _DB ")\n", mixer.rpg_mul, mixer.rpg_div,
772                                                          100.*(float)mixer.rpg_mul/((float)mixer.rpg_div)
773#ifdef ROAR_HAVE_LIBM
774                           , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div)
775#endif
776        );
777 }
778
779 for (i = 0; i < channels; i++)
780  printf("Mixer volume chan %2i  : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale,
781                           (float)mixer.mixer[i]/fs
782#ifdef ROAR_HAVE_LIBM
783                          , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale)
784#endif
785        );
786
787 return 0;
788}
789
790static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) {
791 float fs = scale;
792
793 switch (k[len - 1]) {
794  case '%':
795    k[len - 1] = 0;
796    return (atof(k)*fs)/100.;
797   break;
798#ifdef ROAR_HAVE_LIBM
799  case 'b':
800  case 'B':
801    // TODO: can we hanle the error better?
802    if ( len < 2 )
803     return 0;
804
805    k[len - 2] = 0;
806    return powf(10, atof(k)/20.f)*fs;
807   break;
808#endif
809 }
810
811 return atoi(k);
812}
813
814int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
815 uint16_t scale = 65535;
816 int chans = 0;
817 int id;
818 int i;
819 int len;
820 int old_chans;
821 char * k;
822 struct roar_mixer_settings mixer;
823 struct roar_mixer_settings old_mixer;
824 int mode = ROAR_SET_VOL_ALL;
825
826 if (*cur + 2 > max)
827  return -1;
828
829 id = atoi(arg[++(*cur)]);
830
831 k = arg[++(*cur)];
832
833 if ( !strcmp(arg[*cur + 1], "scale") ) {
834  (*cur)++; // 'scale'
835  (*cur)++;
836  scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535);
837 }
838
839 mixer.scale = scale;
840
841 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) {
842  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id);
843  return -1;
844 }
845
846 if ( strcmp(k, "mono") == 0 ) {
847  chans = 1;
848  mode  = ROAR_SET_VOL_UNMAPPED;
849 } else if ( strcmp(k, "stereo") == 0 ) {
850  chans = 2;
851  mode  = ROAR_SET_VOL_UNMAPPED;
852 } else {
853  chans = atoi(k);
854 }
855
856 // ensure most simple mode:
857 if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED )
858  mode = ROAR_SET_VOL_ALL;
859
860 if ( *cur + chans > max )
861  return -1;
862
863 for (i = 0; i < chans; i++) {
864  k   = arg[++(*cur)];
865  len = strlen(k);
866
867  mixer.mixer[i] = set_mixer_parse_volume(k, len, scale);
868 }
869
870 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
871  return 0;
872
873 // no fallback if already using ROAR_SET_VOL_ALL:
874 if ( mode == ROAR_SET_VOL_ALL )
875  return -1;
876
877 if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 )
878  return -1;
879
880 chans = old_chans;
881 mode  = ROAR_SET_VOL_ALL;
882
883 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
884  return 0;
885
886 return -1;
887}
888
889
890int newvirtual (struct roar_connection * con, char *p_s, char *d_s, char *e_s, char *r_s, char *b_s, char *c_s) {
891 struct roar_stream s;
892 int dir    = roar_str2dir(d_s);
893 int parent = atoi(p_s);
894
895 ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent);
896
897 if ( roar_stream_new(&s, atoi(r_s), atoi(c_s), atoi(b_s), roar_str2codec(e_s)) == -1 )
898  return -1;
899
900 return roar_simple_connect_virtual(con, &s, parent, dir);
901}
902
903int set_meta (struct roar_connection * con, int id, char * mode, char * type, char * val) {
904 struct roar_meta   meta;
905 struct roar_stream s;
906 int mode_i = ROAR_META_MODE_SET;
907
908 if ( roar_stream_new_by_id(&s, id) == -1 )
909  return -1;
910
911// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
912
913 if ( strcmp(mode, "add") == 0 ) {
914  mode_i = ROAR_META_MODE_ADD;
915 }
916
917 meta.type   = roar_meta_inttype(type);
918 meta.value  = val;
919 meta.key[0] = 0;
920
921 if ( meta.type == -1 ) {
922  fprintf(stderr, "Error: unknown type: %s\n", type);
923  return -1;
924 }
925
926// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
927
928 if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 )
929  return -1;
930
931 meta.type  = ROAR_META_TYPE_NONE;
932 meta.value = NULL;
933
934 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
935}
936
937int load_meta (struct roar_connection * con, int id, char * file) {
938 struct roar_meta   meta;
939 struct roar_stream s;
940 int mode_i = ROAR_META_MODE_SET;
941 FILE * in;
942 char lion[1024];
943 char * v;
944
945 if ( roar_stream_new_by_id(&s, id) == -1 )
946  return -1;
947
948 if ( (in = fopen(file, "r")) == NULL )
949  return -1;
950
951 while (fgets(lion, 1024, in) != NULL) {
952  if ( (v = strtok(lion, "\r\n")) != NULL )
953   if ( (v = strtok(NULL, "\r\n")) != NULL )
954    *(v-1) = 0;
955
956  if ( (v = strstr(lion, "=")) == NULL ) {
957   fprintf(stderr, "Error: can not parse meta data lion: %s\n", lion);
958   continue;
959  }
960
961  *v++ = 0;
962
963  meta.type   = roar_meta_inttype(lion);
964  meta.value  = v;
965  meta.key[0] = 0;
966
967  if ( meta.type == -1 ) {
968   fprintf(stderr, "Error: unknown type: %s\n", lion);
969   continue;
970  }
971
972  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) {
973   fclose(in);
974   return -1;
975  }
976 }
977
978 fclose(in);
979
980 meta.type  = ROAR_META_TYPE_NONE;
981 meta.value = NULL;
982
983 return roar_stream_meta_set(con, &s, ROAR_META_MODE_FINALIZE, &meta);
984}
985
986int show_meta_type (struct roar_connection * con, int id, char * type) {
987 struct roar_meta   meta;
988 struct roar_stream s;
989
990 if ( roar_stream_new_by_id(&s, id) == -1 )
991  return -1;
992
993 meta.type  = roar_meta_inttype(type);
994
995 if ( meta.type == -1 ) {
996  fprintf(stderr, "Error: unknown type: %s\n", type);
997  return -1;
998 }
999
1000 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
1001  return -1;
1002
1003 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
1004
1005 roar_meta_free(&meta);
1006
1007 return 0;
1008}
1009
1010int show_meta_all (struct roar_connection * con, int id) {
1011 struct roar_stream s;
1012 int types[ROAR_META_MAX_PER_STREAM];
1013 int i;
1014 int len;
1015
1016 if ( roar_stream_new_by_id(&s, id) == -1 )
1017  return -1;
1018
1019 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
1020  return -1;
1021
1022 for (i = 0; i < len; i++)
1023  show_meta_type(con, id, roar_meta_strtype(types[i]));
1024
1025 return 0;
1026}
1027
1028int save_meta (struct roar_connection * con, int id, char * file) {
1029 struct roar_stream s;
1030 struct roar_meta   meta;
1031 int types[ROAR_META_MAX_PER_STREAM];
1032 int i;
1033 int len;
1034 FILE * out;
1035
1036 if ( roar_stream_new_by_id(&s, id) == -1 )
1037  return -1;
1038
1039 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
1040  return -1;
1041
1042 if ( (out = fopen(file, "w")) == NULL )
1043  return -1;
1044
1045 for (i = 0; i < len; i++) {
1046/*
1047  show_meta_type(con, id, roar_meta_strtype(types[i]));
1048*/
1049  meta.type  = types[i];
1050
1051  if ( roar_stream_meta_get(con, &s, &meta) == -1 )
1052   continue;
1053
1054//  printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
1055
1056  fprintf(out, "%s=%s\n", roar_meta_strtype(meta.type), meta.value);
1057
1058  roar_meta_free(&meta);
1059 }
1060
1061 fclose(out);
1062
1063 return 0;
1064}
1065
1066int set_flags (struct roar_connection * con, int id, int action, char * flags) {
1067 uint32_t f = ROAR_FLAG_NONE;
1068 char * c;
1069 struct roar_stream s[1];
1070
1071 if ( roar_stream_new_by_id(s, id) == -1 )
1072  return -1;
1073
1074 c = strtok(flags, ",");
1075 while (c != NULL) {
1076  if ( !strcmp(c, "meta") ) {
1077   f |= ROAR_FLAG_META;
1078  } else if ( !strcmp(c, "primary") ) {
1079   f |= ROAR_FLAG_PRIMARY;
1080  } else if ( !strcmp(c, "sync") ) {
1081   f |= ROAR_FLAG_SYNC;
1082  } else if ( !strcmp(c, "cleanmeta") ) {
1083   f |= ROAR_FLAG_CLEANMETA;
1084  } else if ( !strcmp(c, "hwmixer") ) {
1085   f |= ROAR_FLAG_HWMIXER;
1086  } else if ( !strcmp(c, "pause") ) {
1087   f |= ROAR_FLAG_PAUSE;
1088  } else if ( !strcmp(c, "mute") ) {
1089   f |= ROAR_FLAG_MUTE;
1090  } else if ( !strcmp(c, "mmap") ) {
1091   f |= ROAR_FLAG_MMAP;
1092  } else if ( !strcmp(c, "antiecho") ) {
1093   f |= ROAR_FLAG_ANTIECHO;
1094  } else if ( !strcmp(c, "recsource") ) {
1095   f |= ROAR_FLAG_RECSOURCE;
1096  } else if ( !strcmp(c, "passmixer") ) {
1097   f |= ROAR_FLAG_PASSMIXER;
1098  } else if ( !strcmp(c, "virtual") ) {
1099   f |= ROAR_FLAG_VIRTUAL;
1100  } else if ( !strcmp(c, "prethru") ) {
1101   f |= ROAR_FLAG_PRETHRU;
1102  } else if ( !strcmp(c, "immutable") ) {
1103   f |= ROAR_FLAG_IMMUTABLE;
1104  } else if ( !strcmp(c, "enhance") ) {
1105   f |= ROAR_FLAG_ENHANCE;
1106  } else if ( !strcmp(c, "singlesink") ) {
1107   f |= ROAR_FLAG_SINGLESINK;
1108  } else {
1109   fprintf(stderr, "Error: unknown flag: %s\n", c);
1110   return -1;
1111  }
1112
1113  c = strtok(NULL, ",");
1114 }
1115
1116 return roar_stream_set_flags(con, s, f, action);
1117}
1118
1119int set_role (struct roar_connection * con, int id, int role) {
1120 struct roar_stream s;
1121
1122 if ( id == -1 )
1123  return -1;
1124
1125 if ( roar_stream_new_by_id(&s, id) == -1 )
1126  return -1;
1127
1128 if ( roar_stream_set_role(con, &s, role) == -1 )
1129  return -1;
1130
1131 return 0;
1132}
1133
1134int show_aiprofile (const char * profile) {
1135 struct roar_audio_info info;
1136 const char * mime;
1137
1138 if ( roar_profile2info(&info, profile) == -1 ) {
1139  fprintf(stderr, "Error: unknown profile: %s\n", profile);
1140  return -1;
1141 }
1142
1143 mime = roar_codec2mime(info.codec);
1144
1145 printf("Profile Name          : %s\n", profile);
1146
1147 if ( info.rate )
1148  printf("Profile sample rate   : %i\n", info.rate);
1149 if ( info.bits )
1150  printf("Profile bits          : %i\n", info.bits);
1151 if ( info.channels )
1152  printf("Profile channels      : %i\n", info.channels);
1153
1154 printf("Profile codec         : %2i (%s%s%s%s)\n", info.codec, roar_codec2str(info.codec),
1155                                       info.codec == ROAR_CODEC_DEFAULT ? " native" : "",
1156                                       mime == NULL ? "" : " mimetype:",
1157                                       mime == NULL ? "" : mime);
1158
1159 return 0;
1160}
1161
1162int list_aiprofiles (void) {
1163 const char * list[1024];
1164 ssize_t ret;
1165 ssize_t i;
1166
1167 ret = roar_profiles_list(list, 1024, 0);
1168
1169 if ( ret == -1 ) {
1170  fprintf(stderr, "Error: can not read list of profiles\n");
1171  return -1;
1172 }
1173
1174 for (i = 0; i < ret; i++) {
1175  printf("profile %lli:\n", (long long signed int)i);
1176  show_aiprofile(list[i]);
1177 }
1178
1179 return 0;
1180}
1181
1182int main (int argc, char * argv[]) {
1183 struct roar_connection con;
1184 char * server   = NULL;
1185 char * k = NULL;
1186 int    i;
1187 int    t = 0;
1188
1189 for (i = 1; i < argc; i++) {
1190  k = argv[i];
1191
1192  if ( strcmp(k, "--server") == 0 ) {
1193   server = argv[++i];
1194  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
1195   g_verbose++;
1196  } else if ( strcmp(k, "--help") == 0 ) {
1197   usage();
1198   return 0;
1199  } else if ( strcmp(k, "--list-aiprofiles") == 0 ) {
1200   list_aiprofiles();
1201   return 0;
1202  } else if ( strcmp(k, "--list-libstandards") == 0 ) {
1203   lib_standards();
1204   return 0;
1205  } else if ( strcmp(k, "--enum-servers") == 0 ) {
1206   enum_servers();
1207   return 0;
1208  } else if ( strcmp(k, "--hash-password") == 0 ) {
1209   hash_password();
1210   return 0;
1211  } else if ( *k == '-' ) {
1212   fprintf(stderr, "Error: unknown argument: %s\n", k);
1213   usage();
1214   return 1;
1215  } else {
1216   break;
1217  }
1218 }
1219
1220 // connect
1221
1222 if ( roar_simple_connect(&con, server, "roarctl") == -1 ) {
1223  fprintf(stderr, "Error: Can not connect to server: %s: %s(%i)\n",
1224          server == NULL ? "(default)" : server, roar_vs_strerr(roar_error), roar_error);
1225  return 1;
1226 }
1227
1228 if ( i == argc ) {
1229  fprintf(stderr, "Error: No Commands given\n");
1230  return 0; // this is not a fatal error...
1231 }
1232
1233 for (; i < argc; i++) {
1234  k = argv[i];
1235  // cmd is in k
1236
1237  printf("--- [ %s ] ---\n", k);
1238
1239  if ( !strcmp(k, "help") ) {
1240   usage();
1241
1242  } else if ( !strcmp(k, "sleep") ) {
1243   roar_sleep(atoi(argv[++i]));
1244
1245  } else if ( !strcmp(k, "ping") ) {
1246#ifdef ROAR_HAVE_GETTIMEOFDAY
1247   if ( ping(&con, atoi(argv[++i])) == -1 ) {
1248    fprintf(stderr, "Error: can not ping\n");
1249   }
1250#else
1251    fprintf(stderr, "Error: ping not supported.\n");
1252    i++;
1253#endif
1254
1255  } else if ( !strcmp(k, "standby") || !strcmp(k, "off") ) {
1256   if ( roar_set_standby(&con, ROAR_STANDBY_ACTIVE) == -1 ) {
1257    fprintf(stderr, "Error: can not set mode to standby\n");
1258   } else {
1259    printf("going into standby\n");
1260   }
1261  } else if ( !strcmp(k, "resume") || !strcmp(k, "on") ) {
1262   if ( roar_set_standby(&con, ROAR_STANDBY_INACTIVE) == -1 ) {
1263    fprintf(stderr, "Error: can not set mode to active\n");
1264   } else {
1265    printf("going into active mode\n");
1266   }
1267
1268  } else if ( !strcmp(k, "exit") ) {
1269   if ( roar_terminate(&con, 0) == -1 ) {
1270    fprintf(stderr, "Error: can not quit server\n");
1271   } else {
1272    printf("Server quited\n");
1273    break;
1274   }
1275  } else if ( !strcmp(k, "terminate") ) {
1276   if ( roar_terminate(&con, 1) == -1 ) {
1277    fprintf(stderr, "Error: can not terminate server\n");
1278   } else {
1279    printf("Server got asked to quited\n");
1280    break;
1281   }
1282
1283  } else if ( !strcmp(k, "standbymode") ) {
1284   t = roar_get_standby(&con);
1285   if ( t == -1 ) {
1286    fprintf(stderr, "Error: can not get stanby mode\n");
1287   } else if ( t == ROAR_STANDBY_ACTIVE ) {
1288    printf("Server is in standby\n");
1289   } else if ( t == ROAR_STANDBY_INACTIVE ) {
1290    printf("Server is active\n");
1291   } else {
1292    fprintf(stderr, "Error: unknown standby mode: %i\n", t);
1293   }
1294
1295  } else if ( !strcmp(k, "whoami") ) {
1296   printf("My client ID is: %i\n", roar_get_clientid(&con));
1297  } else if ( !strcmp(k, "serverinfo") ) {
1298   server_info(&con);
1299  } else if ( !strcmp(k, "servertime") ) {
1300   server_time(&con);
1301  } else if ( !strcmp(k, "serveroinfo") ) {
1302   server_oinfo(&con, -1);
1303  } else if ( !strcmp(k, "serveroinfo2") ) {
1304   t = roar_str2dir(argv[++i]);
1305   if ( t == -1 ) {
1306    fprintf(stderr, "Error: unknown stream direction: %s\n", argv[i]);
1307   } else {
1308    server_oinfo(&con, t);
1309   }
1310  } else if ( !strcmp(k, "serverstandards") ) {
1311   server_standards(&con);
1312  } else if ( !strcmp(k, "libstandards") ) {
1313   lib_standards();
1314  } else if ( !strcmp(k, "listclients") ) {
1315   list_clients(&con);
1316  } else if ( !strcmp(k, "clientinfo") ) {
1317   display_client(&con, atoi(argv[++i]));
1318  } else if ( !strcmp(k, "liststreams") ) {
1319   list_streams(&con);
1320  } else if ( !strcmp(k, "streaminfo") ) {
1321   display_stream(&con, atoi(argv[++i]));
1322  } else if ( !strcmp(k, "allinfo") ) {
1323   server_info(&con);
1324   printf("\n");
1325   server_time(&con);
1326   printf("\n");
1327   lib_standards();
1328   printf("\n");
1329   server_oinfo(&con, -1);
1330   printf("\n");
1331   list_clients(&con);
1332   printf("\n");
1333   list_streams(&con);
1334
1335  } else if ( !strcmp(k, "kick") ) {
1336   t = roar_str2ot((k = argv[++i]));
1337   if ( t == -1 ) {
1338    fprintf(stderr, "Error: unknown type: %s\n", k);
1339    continue;
1340   }
1341   //t = atoi(argv[i++]);
1342   if ( roar_kick(&con, t, atoi(argv[++i])) == -1 ) {
1343    fprintf(stderr, "Error: can not kick %s\n", k);
1344   } else {
1345    printf("%s kicked\n", k);
1346   }
1347
1348  } else if ( !strcmp(k, "newvirtual") ) {
1349   if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) {
1350    fprintf(stderr, "Error: can not create new virtual stream\n");
1351   } else {
1352    printf("virtual stream created\n");
1353   }
1354   i += 6;
1355
1356  } else if ( !strcmp(k, "volume") ) {
1357   if ( set_mixer(&con, &i, argc, argv) == -1 ) {
1358    fprintf(stderr, "Error: can not set volume\n");
1359   } else {
1360    printf("volume changed\n");
1361   }
1362
1363  } else if ( !strcmp(k, "flag") ) {
1364   i++;
1365   if ( set_flags(&con, atoi(argv[i]), ROAR_SET_FLAG, argv[i+1]) == -1 ) {
1366    fprintf(stderr, "Error: can not set flags\n");
1367   } else {
1368    printf("flags changed\n");
1369   }
1370   i++;
1371  } else if ( !strcmp(k, "unflag") ) {
1372   i++;
1373   if ( set_flags(&con, atoi(argv[i]), ROAR_RESET_FLAG, argv[i+1]) == -1 ) {
1374    fprintf(stderr, "Error: can not reset flags\n");
1375   } else {
1376    printf("flags changed\n");
1377   }
1378   i++;
1379  } else if ( !strcmp(k, "toggleflag") ) {
1380   i++;
1381   if ( set_flags(&con, atoi(argv[i]), ROAR_TOGGLE_FLAG, argv[i+1]) == -1 ) {
1382    fprintf(stderr, "Error: can not toggle flags\n");
1383   } else {
1384    printf("flags changed\n");
1385   }
1386   i++;
1387  } else if ( !strcmp(k, "protectflag") ) {
1388   i++;
1389   if ( set_flags(&con, atoi(argv[i]), ROAR_NOOP_FLAG|ROAR_PROTECT_FLAG, argv[i+1]) == -1 ) {
1390    fprintf(stderr, "Error: can not protect flags\n");
1391   } else {
1392    printf("flags protected\n");
1393   }
1394   i++;
1395
1396  } else if ( !strcmp(k, "role") ) {
1397   i++;
1398   if ( set_role(&con, atoi(argv[i]), roar_str2role(argv[i+1])) == -1 ) {
1399    fprintf(stderr, "Error: can not set stream role\n");
1400   } else {
1401    printf("stream role set\n");
1402   }
1403   i++;
1404
1405  } else if ( !strcmp(k, "metaset") ) {
1406   i++;
1407   if ( set_meta(&con, atoi(argv[i]), argv[i+1], argv[i+2], argv[i+3]) == -1 ) {
1408    fprintf(stderr, "Error: can not set meta data\n");
1409   } else {
1410    printf("meta data changed\n");
1411   }
1412   i += 3;
1413  } else if ( !strcmp(k, "metaget") ) {
1414   i++;
1415   if ( show_meta_type(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1416    fprintf(stderr, "Error: can not get meta data\n");
1417   }
1418   i++;
1419  } else if ( !strcmp(k, "metasave") ) {
1420   i++;
1421   if ( save_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1422    fprintf(stderr, "Error: can not get meta data\n");
1423   } else {
1424    printf("meta data saved\n");
1425   }
1426   i++;
1427  } else if ( !strcmp(k, "metaload") ) {
1428   i++;
1429   if ( load_meta(&con, atoi(argv[i]), argv[i+1]) == -1 ) {
1430    fprintf(stderr, "Error: can not set meta data\n");
1431   } else {
1432    printf("meta data saved\n");
1433   }
1434   i++;
1435
1436
1437  } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) {
1438   if ( list_aiprofiles() == -1 ) {
1439    fprintf(stderr, "Error: can not list profiles\n");
1440   }
1441  } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) {
1442   i++;
1443   if ( show_aiprofile(argv[i]) == -1 ) {
1444    fprintf(stderr, "Error: can not get profile data\n");
1445   }
1446  } else {
1447   fprintf(stderr, "Error: invalid command: %s\n", k);
1448  }
1449
1450 }
1451
1452 roar_disconnect(&con);
1453
1454 return 0;
1455}
1456
1457//ll
Note: See TracBrowser for help on using the repository browser.