source: roaraudio/roarclients/roarctl.c @ 5187:30e52659b213

Last change on this file since 5187:30e52659b213 was 5187:30e52659b213, checked in by phi, 13 years ago

added --hash-password

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