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
RevLine 
[0]1//roarctl.c:
2
[669]3/*
[5381]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
[669]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[669]23 *
24 */
25
[4885]26/* ckport options:
[4922]27 * ckport: ignore-symbol: roar_req of target libroar0 -- Used within ping command.
[4885]28 */
29
[3211]30#define _UNITS_T_BASE_USEC
31
[0]32#include <roaraudio.h>
[3211]33#include <roaraudio/units.h>
[3539]34#include <libroardsp/libroardsp.h>
[1782]35
36#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID)
37#define _POSIX_USERS
38#endif
39
40#ifdef _POSIX_USERS
[445]41#include <pwd.h>
42#include <grp.h>
[1782]43#endif
44
[1630]45#include <sys/time.h>
46#include <time.h>
[445]47
[2916]48#ifdef ROAR_HAVE_LIBM
49#include <math.h>
50#endif
51
[963]52int g_verbose = 0;
[0]53
[4818]54void display_client (struct roar_connection * con, int id);
55void display_stream (struct roar_connection * con, int id);
[25]56int display_mixer (struct roar_connection * con, int stream);
[112]57int show_meta_all (struct roar_connection * con, int id);
[25]58
[0]59void usage (void) {
[233]60 printf("roarctl [OPTIONS]... COMMAND [OPTS] [COMMAND [OPTS] [COMMAND [OPTS] [...]]]\n");
[0]61
62 printf("\nOptions:\n\n");
63
[86]64 printf("  --server SERVER         - Set server hostname\n"
65        "  --help                  - Show this help\n"
[963]66        "  --verbose   -v          - Show verbose output\n"
[3961]67        "  --list-aiprofiles       - Show audio info profiles and exit\n"
[5149]68        "  --list-libstandards     - Gets list of library (libroar) supported standards\n"
[4413]69        "  --enum-servers          - Show a list of possible servers\n"
[5187]70        "  --hash-password         - Hash a password and exit\n"
[0]71       );
72
73 printf("\nCommands:\n\n");
74 printf(
[86]75        "  help                    - Show this help\n"
[1204]76        "  sleep TIME              - Sleeps for TIME seconds\n"
[1781]77#ifdef ROAR_HAVE_GETTIMEOFDAY
[1630]78        "  ping  NUM               - Do NUM pings using NOOP commands\n"
[1781]79#endif
[2700]80        "  whoami                  - Get own client ID\n"
[0]81        "\n"
[5384]82        "  beep                    - Ask the server to beep.\n"
83        "\n"
[3961]84        "  listaiprofiles          - list audio info profiles\n"
85        "  aiprofileget PROFILE    - show audio info profile PROFILE\n"
86        "\n"
[86]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"
[577]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"
[0]94        "\n"
[3560]95        "  volume ID CHAN [scale S] V0 V1...\n"
96        "                          - Sets volume for stream ID\n"
[86]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"
[3560]101        "                            An optional scale can be given using S.\n"
[86]102        "                            all other args are the volumes of the channels\n"
103        "                            you may use integer or percent values.\n"
[3846]104        "                            percent values can floating points.\n"
[0]105        "\n"
[1123]106        "  flag   ID FLAGS         - Sets flags FLAGS on stream ID. FLAGS may be a comma\n"
[4012]107        "                            separated list of flags.\n"
[1123]108        "  unflag ID FLAGS         - Unsets flags on a stream. See flag.\n"
[4552]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"
[1123]112        "\n"
[4933]113        "  role ID ROLE            - Set role ROLE on stream ID.\n"
114        "\n"
[86]115        "  kick TYPE ID            - Kicks object of TYPE with id ID\n"
116        "                            Types: client stream sample source\n"
[2698]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"
[86]122        "\n"
[2700]123        "  metaget  ID TYPE        - Read meta date of type TYPE from stream ID\n"
124// TODO: document metaset here.
[1160]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"
[4443]128        "  serverinfo              - Gets general information about the server\n"
[5387]129        "  libinfo                 - Gets general information about the library (libroar)\n"
[5031]130        "  servertime              - Gets server's time\n"
[4012]131        "  serveroinfo             - Gets Information about server output\n"
[4614]132        "  serveroinfo2 DIR        - Gets Information about server output for stream direction dir\n"
[4818]133        "\n"
[4501]134        "  serverstandards         - Gets list of server supported standards\n"
[5149]135        "  libstandards            - Gets list of library (libroar) supported standards\n"
[4818]136        "\n"
[4012]137        "  listclients             - Gets Information about clients\n"
[4818]138        "  clientinfo ID           - Gets Information about client ID\n"
[4012]139        "  liststreams             - Gets Information about streams\n"
[4818]140        "  streaminfo ID           - Gets Information about stream ID\n"
[86]141        "  allinfo                 - Get all infos\n"
[0]142       );
143}
144
[5187]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
[4413]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
[1781]217#ifdef ROAR_HAVE_GETTIMEOFDAY
[1630]218int ping (struct roar_connection * con, int num) {
219 struct timeval         try, ans;
220 struct roar_message    m;
221 register int           ret;
[1631]222 int                    i;
223 double                 cur, min = 3600*1000, max = 0, sum = 0;
224
225 if ( num == 0 )
226  return 0;
[1630]227
228 for (i = 0; i < num; i++) {
[3875]229  memset(&m, 0, sizeof(m));
230
[1630]231  m.cmd = ROAR_CMD_NOOP;
[5144]232  m.stream  = -1;
233  m.datalen =  0;
[1630]234
[3875]235  // we use roar_req() directly here because of speed.
236  // roar_noop() does basicly the same but is a bit slower.
237
[1630]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
[5384]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');
[1631]254
255  sum += cur;
256  if ( min > cur )
257   min = cur;
258  if ( cur > max )
259   max = cur;
[1630]260
261  if ( i != (num - 1) )
[4914]262   roar_sleep(1);
[1630]263 }
264
[1631]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
[1630]269 return 0;
270}
[1781]271#endif
[1630]272
[5387]273#define _pm(m,n) if ( info->m != NULL ) printf(con != NULL ? "Server %-15s: %s\n" : "Library %-14s: %s\n", (n), (info->m));
[4432]274void server_info (struct roar_connection * con) {
[5387]275 struct roar_server_info * info = con != NULL ? roar_server_info(con) : roar_library_info();
[5279]276 long hostid;
[4432]277
278 if ( info == NULL ) {
279  fprintf(stderr, "Error: can not get server info\n");
280  return;
281 }
282
[5279]283 _pm(version, "Version");
284 _pm(location, "Location");
285 _pm(description, "Description");
286 _pm(contact, "Contact");
287 _pm(serial, "Serial");
288 _pm(address, "Address");
[4434]289 _pm(uiurl, "UI URL");
[5279]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 ) {
[5387]297   printf(con != NULL ? "Server %-15s: %s (%li.%li.%li.%li)\n"
298                      : "Library %-14s: %s (%li.%li.%li.%li)\n", "HostID", info->hostid,
[5279]299           ((hostid & 0x00FF0000UL) >> 16UL),
300           ((hostid & 0xFF000000UL) >> 24UL),
301           ((hostid & 0x000000FFUL) >>  0UL),
302           ((hostid & 0x0000FF00UL) >>  8UL)
303         );
304  } else {
[5387]305   _pm(hostid, "HostID");
[5279]306  }
307 }
[5372]308 _pm(build, "Build");
[4434]309 _pm(un.sysname, "System sysname");
310 _pm(un.release, "System release");
311 _pm(un.nodename, "System nodename");
312 _pm(un.machine, "System machine");
[4432]313
314 roar_server_info_free(info);
315}
[4434]316#undef _pm
[4432]317
[5031]318void server_time (struct roar_connection * con) {
319 struct roar_time time;
[5379]320#ifdef ROAR_HAVE_CTIME_R
321 time_t server_time;
322 char server_time_buf[32];
323#endif
324
[5031]325
326 if ( roar_get_time(con, &time) == -1 ) {
[5185]327  fprintf(stderr, "Error: can not get server time: %s\n", roar_vs_strerr(roar_error));
[5031]328  return;
329 }
330
[5379]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
[5031]341 if ( g_verbose ) {
[5379]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
[5031]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 {
[5087]354  if ( time.c_freq == 1000000000LL && time.t_ssec == 0 ) {
[5379]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
[5087]363          (long long unsigned int)time.t_sec);
364  } else {
[5379]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
[5087]373          (long long unsigned int)time.t_sec,
374          (long long unsigned int) time.t_ssec / 18446744073709LLU);
375  }
[5031]376 }
377 if ( time.c_freq )
[5067]378  printf("Server clock frequency: %f Hz\n", (float)((double)time.c_freq / (double)1000000000.));
[5209]379 if ( time.c_drift ) {
380#ifdef ROAR_HAVE_LIBM
[5031]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);
[5209]383#else
384  printf("Server clock drift    : %llu:2^64\n",
385         (long long unsigned int)time.c_drift);
386#endif
387 }
[5031]388}
389
[4614]390void server_oinfo (struct roar_connection * con, int dir) {
[0]391 struct roar_stream s;
392
[5236]393 if ( roar_server_oinfo(con, &s, dir) == -1 ) {
[0]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));
[4591]399 printf("Server Output rate    : %i Hz\n", s.info.rate);
[0]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);
[5386]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  }
[0]412}
413
[5149]414static void print_stds (const struct roar_stds * stds) {
[4501]415 size_t i;
416 int vendor, standard, version;
[4503]417 char numbuf[2][8];
418 const char * vendor_name;
[4501]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]);
[4503]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]);
[4501]439 }
440}
441
[5149]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
[449]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
[4047]465 snprintf(file, sizeof(file)-1, "/proc/%i/exe", pid);
466 file[sizeof(file)-1] = 0;
[449]467
468 ret[0] = '?';
469 ret[1] = 0;
470
[4047]471 if ( (i = readlink(file, buf, sizeof(buf)-1)) != -1 ) {
[449]472  buf[i] = 0;
473  if ( (r = strrchr(buf, '/')) != NULL ) {
474   r++;
[4047]475   if ( *r != 0 ) {
476    strncpy(ret, r, sizeof(ret)-1);
477    ret[sizeof(ret)-1] = 0;
478   }
[449]479  }
480 }
[3787]481#else
482 (void)pid;
[449]483#endif
484
485 return ret;
486}
487
[0]488void list_clients (struct roar_connection * con) {
489 int i;
490 int num;
491 int id[ROAR_CLIENTS_MAX];
[2814]492
[0]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++) {
[4818]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 ) {
[5005]534  if ( roar_nnode_to_str(&(c.nnode), tmp, sizeof(tmp)) == 0 ) {
[4818]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 ) {
[5005]566   roar_mm_strscpy(tmp, " (network byteorder");
[4818]567  } else {
568   *tmp = 0;
[0]569  }
[3845]570
[4818]571  if ( c.byteorder == ROAR_BYTEORDER_NATIVE ) {
572   if ( *tmp ) {
[5005]573    roar_mm_strscat(tmp, ", native");
[4818]574   } else {
[5005]575    roar_mm_strscpy(tmp, " (native");
[2814]576   }
577  }
578
[4818]579  if ( *tmp )
[5005]580   roar_mm_strscat(tmp, ")");
[2550]581
[4818]582  printf("Client Byteorder      : %s%s\n", roar_byteorder2str(c.byteorder), tmp);
[0]583 }
584
[4818]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]);
[0]591}
592
593void list_streams (struct roar_connection * con) {
594 int i;
595 int num;
596 int id[ROAR_STREAMS_MAX];
[4818]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) {
[3539]609 char chanmap[ROAR_MAX_CHANNELS];
[0]610 struct roar_stream s;
[465]611 struct roar_stream_info info;
[3539]612 char buffer[1024];
613 char * flags = buffer;
614 char * name  = buffer;
[2399]615 char * infotext;
[4603]616 const char * mime;
[3539]617 size_t len;
[0]618
[4818]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));
[0]625
[5005]626 if ( roar_stream_get_name(con, &s, name, sizeof(buffer)) == 0 )
[4818]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  }
[0]643 }
644
[4818]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 )
[2399]662  printf("Stream channels       : %i\n", s.info.channels);
[1810]663
[4818]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                                     );
[465]678  }
[1811]679
[3539]680  if ( g_verbose ) {
[4818]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));
[3539]696
[4818]697   *flags = 0;
[5005]698#define _strcat(dst,src) roar_mm_strlcat((dst),(src), sizeof(buffer))
[4818]699   if ( info.flags & ROAR_FLAG_PRIMARY )
[5005]700    _strcat(flags, "primary ");
[4818]701   if ( info.flags & ROAR_FLAG_SYNC )
[5005]702    _strcat(flags, "sync ");
[4818]703   if ( info.flags & ROAR_FLAG_OUTPUT )
[5005]704    _strcat(flags, "output ");
[4818]705   if ( info.flags & ROAR_FLAG_SOURCE )
[5005]706    _strcat(flags, "source ");
[4818]707   if ( info.flags & ROAR_FLAG_META )
[5005]708    _strcat(flags, "meta ");
[4818]709   if ( info.flags & ROAR_FLAG_AUTOCONF )
[5005]710    _strcat(flags, "autoconf ");
[4818]711   if ( info.flags & ROAR_FLAG_CLEANMETA )
[5005]712    _strcat(flags, "cleanmeta ");
[4818]713   if ( info.flags & ROAR_FLAG_HWMIXER )
[5005]714    _strcat(flags, "hwmixer ");
[4818]715   if ( info.flags & ROAR_FLAG_PAUSE )
[5005]716    _strcat(flags, "pause ");
[4818]717   if ( info.flags & ROAR_FLAG_MUTE )
[5005]718    _strcat(flags, "mute ");
[4818]719   if ( info.flags & ROAR_FLAG_MMAP )
[5005]720    _strcat(flags, "mmap ");
[4818]721   if ( info.flags & ROAR_FLAG_ANTIECHO )
[5005]722    _strcat(flags, "antiecho ");
[4818]723   if ( info.flags & ROAR_FLAG_VIRTUAL )
[5005]724    _strcat(flags, "virtual ");
[4818]725   if ( info.flags & ROAR_FLAG_RECSOURCE )
[5005]726    _strcat(flags, "recsource ");
[4818]727   if ( info.flags & ROAR_FLAG_PASSMIXER )
[5005]728    _strcat(flags, "passmixer ");
[4818]729   if ( info.flags & ROAR_FLAG_PRETHRU )
[5005]730    _strcat(flags, "prethru ");
[4818]731   if ( info.flags & ROAR_FLAG_IMMUTABLE )
[5005]732    _strcat(flags, "immutable ");
[4818]733   if ( info.flags & ROAR_FLAG_ENHANCE )
[5005]734    _strcat(flags, "enhance ");
[4818]735   if ( info.flags & ROAR_FLAG_SINGLESINK )
[5005]736    _strcat(flags, "singlesink ");
737#undef _strcat
[4818]738
739   printf("Flags                 : %s\n", flags);
[1811]740  }
[0]741 }
742
[5386]743 if ( g_verbose && (s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS) ) {
[4818]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 ) {
[5386]757  if ( s.info.channels != 0 && s.info.channels <= ROAR_MAX_CHANNELS ) {
758   display_mixer(con, id);
759  }
[4818]760  show_meta_all(con, id);
761 }
[0]762}
763
[25]764int display_mixer (struct roar_connection * con, int stream) {
[5624]765 struct roar_stream_rpg rpg;
[3529]766 struct roar_mixer_settings mixer;
[5624]767 struct roar_stream s;
[25]768 int channels;
769 int i;
[3529]770 float fs;
[25]771
772 if ( roar_get_vol(con, stream, &mixer, &channels) == -1 ) {
[3530]773  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", stream);
[25]774  return -1;
775 }
776
[5624]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
[2916]782#ifdef ROAR_HAVE_LIBM
783#define _DB ", %.2fdB"
784#else
785#define _DB ""
786#endif
787
[3529]788 fs = (float)mixer.scale / 100.;
789
[3531]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)
[3529]793#ifdef ROAR_HAVE_LIBM
[3531]794                           , 20*log10f((float)mixer.rpg_mul/(float)mixer.rpg_div)
[3529]795#endif
[3531]796        );
797 }
[3529]798
[25]799 for (i = 0; i < channels; i++)
[3529]800  printf("Mixer volume chan %2i  : %i/%i (%.2f%%" _DB ")\n", i, mixer.mixer[i], mixer.scale,
801                           (float)mixer.mixer[i]/fs
[2916]802#ifdef ROAR_HAVE_LIBM
[3529]803                          , 20*log10f((float)mixer.mixer[i]/(float)mixer.scale)
[2916]804#endif
805        );
[25]806
807 return 0;
808}
[0]809
[3530]810static unsigned int set_mixer_parse_volume (char * k, int len, uint16_t scale) {
811 float fs = scale;
812
[2916]813 switch (k[len - 1]) {
814  case '%':
815    k[len - 1] = 0;
[3530]816    return (atof(k)*fs)/100.;
[2916]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;
[3530]826    return powf(10, atof(k)/20.f)*fs;
[2916]827   break;
828#endif
829 }
830
831 return atoi(k);
832}
833
[85]834int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) {
[3530]835 uint16_t scale = 65535;
[85]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;
[4740]844 int mode = ROAR_SET_VOL_ALL;
[85]845
846 if (*cur + 2 > max)
847  return -1;
848
849 id = atoi(arg[++(*cur)]);
850
851 k = arg[++(*cur)];
852
[3530]853 if ( !strcmp(arg[*cur + 1], "scale") ) {
854  (*cur)++; // 'scale'
[3559]855  (*cur)++;
856  scale = set_mixer_parse_volume(arg[*cur], strlen(arg[*cur]), 65535);
[3530]857 }
[85]858
[4740]859 mixer.scale = scale;
[85]860
[4740]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 }
[85]865
[4740]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 }
[1203]875
[4740]876 // ensure most simple mode:
877 if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED )
878  mode = ROAR_SET_VOL_ALL;
[1203]879
[4740]880 if ( *cur + chans > max )
881  return -1;
[1203]882
[4740]883 for (i = 0; i < chans; i++) {
[1203]884  k   = arg[++(*cur)];
885  len = strlen(k);
886
[4740]887  mixer.mixer[i] = set_mixer_parse_volume(k, len, scale);
[85]888 }
889
[5236]890 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
[4740]891  return 0;
892
893 // no fallback if already using ROAR_SET_VOL_ALL:
894 if ( mode == ROAR_SET_VOL_ALL )
895  return -1;
[85]896
[4740]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
[5236]903 if ( roar_set_vol(con, id, &mixer, chans, mode) == 0 )
[4740]904  return 0;
905
906 return -1;
[85]907}
908
[2698]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
[2699]915 ROAR_DBG("newvirtual(*): dir=%i, parent=%i", dir, parent);
916
[5537]917 if ( roar_stream_new(&s, roar_str2rate(r_s), roar_str2channels(c_s), roar_str2bits(b_s), roar_str2codec(e_s)) == -1 )
[2698]918  return -1;
919
920 return roar_simple_connect_virtual(con, &s, parent, dir);
921}
922
[99]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
[3072]928 if ( roar_stream_new_by_id(&s, id) == -1 )
929  return -1;
[99]930
[106]931// printf("set_meta(*): mode='%s', type='%s', val='%s'\n", mode, type, val);
[99]932
933 if ( strcmp(mode, "add") == 0 ) {
934  mode_i = ROAR_META_MODE_ADD;
935 }
936
[109]937 meta.type   = roar_meta_inttype(type);
[106]938 meta.value  = val;
939 meta.key[0] = 0;
[99]940
[109]941 if ( meta.type == -1 ) {
942  fprintf(stderr, "Error: unknown type: %s\n", type);
943  return -1;
944 }
945
[106]946// printf("D: type=%i, mode=%i\n", meta.type, mode_i);
[99]947
[1127]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);
[99]955}
956
[1126]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
[3072]965 if ( roar_stream_new_by_id(&s, id) == -1 )
966  return -1;
[1126]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
[4014]992  if ( roar_stream_meta_set(con, &s, mode_i, &meta) == -1 ) {
993   fclose(in);
[1126]994   return -1;
[4014]995  }
[1126]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
[5625]1006int show_meta_type (struct roar_connection * con, int id, const char * type) {
[106]1007 struct roar_meta   meta;
1008 struct roar_stream s;
1009
[3072]1010 if ( roar_stream_new_by_id(&s, id) == -1 )
1011  return -1;
[106]1012
[109]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 }
[106]1019
1020 if ( roar_stream_meta_get(con, &s, &meta) == -1 )
1021  return -1;
1022
[112]1023 printf("Meta %-17s: %s\n", roar_meta_strtype(meta.type), meta.value);
[106]1024
1025 roar_meta_free(&meta);
1026
1027 return 0;
1028}
1029
[112]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
[3072]1036 if ( roar_stream_new_by_id(&s, id) == -1 )
1037  return -1;
[112]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
[1126]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
[3072]1056 if ( roar_stream_new_by_id(&s, id) == -1 )
1057  return -1;
[1126]1058
[4014]1059 if ( (len = roar_stream_meta_list(con, &s, types, ROAR_META_MAX_PER_STREAM)) == -1 )
[1126]1060  return -1;
1061
[4014]1062 if ( (out = fopen(file, "w")) == NULL )
[1126]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
[4552]1086int set_flags (struct roar_connection * con, int id, int action, char * flags) {
1087 uint32_t f = ROAR_FLAG_NONE;
[1043]1088 char * c;
1089 struct roar_stream s[1];
1090
[3072]1091 if ( roar_stream_new_by_id(s, id) == -1 )
1092  return -1;
[1043]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;
[1116]1100  } else if ( !strcmp(c, "sync") ) {
1101   f |= ROAR_FLAG_SYNC;
[1219]1102  } else if ( !strcmp(c, "cleanmeta") ) {
1103   f |= ROAR_FLAG_CLEANMETA;
[1585]1104  } else if ( !strcmp(c, "hwmixer") ) {
1105   f |= ROAR_FLAG_HWMIXER;
1106  } else if ( !strcmp(c, "pause") ) {
1107   f |= ROAR_FLAG_PAUSE;
[1883]1108  } else if ( !strcmp(c, "mute") ) {
1109   f |= ROAR_FLAG_MUTE;
[1926]1110  } else if ( !strcmp(c, "mmap") ) {
1111   f |= ROAR_FLAG_MMAP;
[2154]1112  } else if ( !strcmp(c, "antiecho") ) {
1113   f |= ROAR_FLAG_ANTIECHO;
[2412]1114  } else if ( !strcmp(c, "recsource") ) {
1115   f |= ROAR_FLAG_RECSOURCE;
1116  } else if ( !strcmp(c, "passmixer") ) {
1117   f |= ROAR_FLAG_PASSMIXER;
[2627]1118  } else if ( !strcmp(c, "virtual") ) {
1119   f |= ROAR_FLAG_VIRTUAL;
[2814]1120  } else if ( !strcmp(c, "prethru") ) {
1121   f |= ROAR_FLAG_PRETHRU;
[2953]1122  } else if ( !strcmp(c, "immutable") ) {
1123   f |= ROAR_FLAG_IMMUTABLE;
1124  } else if ( !strcmp(c, "enhance") ) {
1125   f |= ROAR_FLAG_ENHANCE;
[4536]1126  } else if ( !strcmp(c, "singlesink") ) {
1127   f |= ROAR_FLAG_SINGLESINK;
[1043]1128  } else {
1129   fprintf(stderr, "Error: unknown flag: %s\n", c);
1130   return -1;
1131  }
1132
1133  c = strtok(NULL, ",");
1134 }
1135
[5238]1136 return roar_stream_set_flags(con, s, f, action);
[1043]1137}
1138
[4933]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
[3942]1154int show_aiprofile (const char * profile) {
1155 struct roar_audio_info info;
[4882]1156 const char * mime;
[3942]1157
1158 if ( roar_profile2info(&info, profile) == -1 ) {
1159  fprintf(stderr, "Error: unknown profile: %s\n", profile);
1160  return -1;
1161 }
1162
[4882]1163 mime = roar_codec2mime(info.codec);
1164
[3942]1165 printf("Profile Name          : %s\n", profile);
[3944]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
[4882]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);
[3942]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
[0]1202int main (int argc, char * argv[]) {
1203 struct roar_connection con;
[5534]1204 const char * server   = NULL;
1205 const char * k = NULL;
[0]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 ) {
[58]1213   server = argv[++i];
[963]1214  } else if ( strcmp(k, "-v") == 0 || strcmp(k, "--verbose") == 0 ) {
1215   g_verbose++;
[0]1216  } else if ( strcmp(k, "--help") == 0 ) {
1217   usage();
1218   return 0;
[3960]1219  } else if ( strcmp(k, "--list-aiprofiles") == 0 ) {
1220   list_aiprofiles();
1221   return 0;
[5149]1222  } else if ( strcmp(k, "--list-libstandards") == 0 ) {
1223   lib_standards();
1224   return 0;
[4413]1225  } else if ( strcmp(k, "--enum-servers") == 0 ) {
1226   enum_servers();
1227   return 0;
[5187]1228  } else if ( strcmp(k, "--hash-password") == 0 ) {
1229   hash_password();
1230   return 0;
[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
[3510]1242 if ( roar_simple_connect(&con, server, "roarctl") == -1 ) {
[5185]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);
[0]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
[1202]1262  } else if ( !strcmp(k, "sleep") ) {
[4914]1263   roar_sleep(atoi(argv[++i]));
[0]1264
[1630]1265  } else if ( !strcmp(k, "ping") ) {
[1781]1266#ifdef ROAR_HAVE_GETTIMEOFDAY
[1630]1267   if ( ping(&con, atoi(argv[++i])) == -1 ) {
1268    fprintf(stderr, "Error: can not ping\n");
1269   }
[1781]1270#else
1271    fprintf(stderr, "Error: ping not supported.\n");
1272    i++;
1273#endif
[1630]1274
[0]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") ) {
[4047]1289   if ( roar_terminate(&con, 0) == -1 ) {
[0]1290    fprintf(stderr, "Error: can not quit server\n");
1291   } else {
1292    printf("Server quited\n");
1293    break;
1294   }
[577]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   }
[0]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
[1162]1315  } else if ( !strcmp(k, "whoami") ) {
1316   printf("My client ID is: %i\n", roar_get_clientid(&con));
[5384]1317  } else if ( !strcmp(k, "beep") ) {
1318   roar_beep(&con, NULL);
[4432]1319  } else if ( !strcmp(k, "serverinfo") ) {
1320   server_info(&con);
[5387]1321  } else if ( !strcmp(k, "libinfo") ) {
1322   server_info(NULL);
[5031]1323  } else if ( !strcmp(k, "servertime") ) {
1324   server_time(&con);
[0]1325  } else if ( !strcmp(k, "serveroinfo") ) {
[4614]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   }
[4501]1334  } else if ( !strcmp(k, "serverstandards") ) {
1335   server_standards(&con);
[5149]1336  } else if ( !strcmp(k, "libstandards") ) {
1337   lib_standards();
[0]1338  } else if ( !strcmp(k, "listclients") ) {
1339   list_clients(&con);
[4818]1340  } else if ( !strcmp(k, "clientinfo") ) {
1341   display_client(&con, atoi(argv[++i]));
[0]1342  } else if ( !strcmp(k, "liststreams") ) {
1343   list_streams(&con);
[4818]1344  } else if ( !strcmp(k, "streaminfo") ) {
1345   display_stream(&con, atoi(argv[++i]));
[0]1346  } else if ( !strcmp(k, "allinfo") ) {
[5379]1347   server_info(&con);
1348   printf("\n");
1349   server_time(&con);
1350   printf("\n");
[5383]1351   server_standards(&con);
[5379]1352   printf("\n");
[4614]1353   server_oinfo(&con, -1);
[0]1354   printf("\n");
1355   list_clients(&con);
1356   printf("\n");
1357   list_streams(&con);
1358
1359  } else if ( !strcmp(k, "kick") ) {
[4328]1360   t = roar_str2ot((k = argv[++i]));
1361   if ( t == -1 ) {
[0]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
[2698]1372  } else if ( !strcmp(k, "newvirtual") ) {
[2699]1373   if ( newvirtual(&con, argv[i+1], argv[i+2], argv[i+3], argv[i+4], argv[i+5], argv[i+6]) == -1 ) {
[2698]1374    fprintf(stderr, "Error: can not create new virtual stream\n");
1375   } else {
1376    printf("virtual stream created\n");
1377   }
[2699]1378   i += 6;
[2698]1379
[85]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
[1043]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++;
[4552]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++;
[4933]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 {
[4935]1425    printf("stream role set\n");
[4933]1426   }
1427   i++;
1428
[106]1429  } else if ( !strcmp(k, "metaset") ) {
[99]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;
[106]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++;
[1126]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++;
[99]1459
[3942]1460
[3961]1461  } else if ( !strcmp(k, "listaiprofiles") || !strcmp(k, "listprofiles") ) {
[3942]1462   if ( list_aiprofiles() == -1 ) {
1463    fprintf(stderr, "Error: can not list profiles\n");
1464   }
[3961]1465  } else if ( !strcmp(k, "aiprofileget") || !strcmp(k, "profileget") ) {
[3942]1466   i++;
1467   if ( show_aiprofile(argv[i]) == -1 ) {
1468    fprintf(stderr, "Error: can not get profile data\n");
1469   }
[0]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.