source: roaraudio/roarclients/roarctl.c @ 5625:722bbc6d4930

Last change on this file since 5625:722bbc6d4930 was 5625:722bbc6d4930, checked in by phi, 12 years ago

Fixed compiler warnings about roar_meta_strtype(3) (Closes: #305)

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