source: roaraudio/roarclients/roarctl.c @ 1219:c15f4cac425f

Last change on this file since 1219:c15f4cac425f was 1219:c15f4cac425f, checked in by phi, 15 years ago

added flags autoconf and cleanmeta

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