source: roaraudio/roard/roard.c @ 3373:97166aec67ab

Last change on this file since 3373:97166aec67ab was 3373:97166aec67ab, checked in by phi, 14 years ago

added X11 support

File size: 49.3 KB
Line 
1//roard.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
5 *
6 *  This file is part of roard 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 "roard.h"
26
27#ifdef ROAR_SUPPORT_LISTEN
28char * server[ROAR_MAX_LISTEN_SOCKETS];
29#endif
30
31#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
32#define SUPPORT_PIDFILE
33char * pidfile = NULL;
34#endif
35
36#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
37 int    setids    = 0;
38#endif
39
40#ifdef ROAR_HAVE_MAIN_ARGS
41void usage (void) {
42 printf("Usage: roard [OPTIONS]...\n\n");
43
44 printf("Misc Options:\n\n");
45 printf(
46        " --daemon              - Bring the server into background after init\n"
47        " --verbose             - Be more verbose, can be used multiple times\n"
48        " --terminate           - Terminate after last client quited\n"
49        " --start               - No op parameter (starting roard is default operation)\n"
50        " --restart             - Trys to stop an old instance and start a new with new settings\n"
51        " --stop                - Stops a running roard (provide --pidfile!)\n"
52        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
53        " --realtime            - Trys to get realtime priority,\n"
54        "                         give multible times for being more realtime\n"
55        " --chroot DIR          - chroots to the given dir\n"
56        " --setgid              - GroupID to the audio group as specified via -G\n"
57        " --setuid              - UserID to the audio user as specified via -U\n"
58        " --sysclocksync        - calculate exact sample rate using the system clock\n"
59        " --location  LOC       - Set lion readable location of server\n"
60#ifdef SUPPORT_PIDFILE
61        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
62#endif
63       );
64
65 printf("\nPlugin Options:\n\n");
66 printf(
67        " --plugin-load FILE    - Load plugin FILE\n"
68       );
69
70 printf("\nAudio Options:\n\n");
71 printf(
72        " -R  --rate   RATE     - Set server rate\n"
73        " -B  --bits   BITS     - Set server bits\n"
74        " -C  --chans  CHANNELS - Set server channels\n"
75       );
76
77 printf("\nStream Options:\n\n");
78 printf(
79        " --stream-flags D=F    - Set default flags for stream directions\n"
80        "                         D is the stream direction and F is a comma seperated\n"
81        "                         list of flags in form +flag or -flag to set or unset\n"
82        "                         a flag as default or remove it from the default\n"
83       );
84
85 printf("\nDriver Options: (obsolete, do not use, Use Ouput Options)\n\n");
86 printf(" -d  --driver DRV      - Set the driver (default: %s)\n", ROAR_DRIVER_DEFAULT);
87 printf(" -D  --device DEV      - Set the device\n");
88 printf(" -dO OPTS              - Set output options\n");
89 printf(" --list-driver         - List all drivers\n");
90
91 printf("\nOutput Options:\n\n");
92 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
93 printf(" -O  --odevice DEV     - Set the device\n");
94 printf(" -oO OPTS              - Set output options\n");
95 printf(" -oN                   - Adds another output\n");
96 printf(" -oP                   - Mark output as primary\n");
97
98#ifndef ROAR_WITHOUT_DCOMP_SOURCES
99 printf("\nSource Options:\n\n");
100 printf(" -s  --source DRV      - Use DRV as input driver\n"
101        " -S           DEV      - Use DEV as input device\n"
102        " -sO          OPTS     - Use OPTS as input options\n"
103        " -sN                   - Adds another source\n"
104        " -sP                   - Make souce as primary\n"
105       );
106 printf(" --list-sources        - List all sources\n");
107#endif
108
109 printf("\nCodec Filter Options:\n\n");
110 printf(" --list-cf             - List all codec filter\n"
111       );
112
113#ifndef ROAR_WITHOUT_DCOMP_MIDI
114 printf("\nMIDI Options:\n\n");
115 printf(" --midi-no-console     - Disable console based MIDI synth\n"
116        " --midi-console-enable - Enables the console based MIDI synth\n"
117        " --midi-console DEV    - Set device for MIDI console\n"
118#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
119        " --ssynth-enable       - Enable simple software synth\n"
120        " --ssynth-disable      - Disable simple software synth\n"
121#endif
122       );
123#endif
124
125#ifndef ROAR_WITHOUT_DCOMP_LIGHT
126 printf("\nLight Control Options:\n\n");
127 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
128                                  LIGHT_CHANNELS_DEFAULT
129       );
130#endif
131
132#ifndef ROAR_WITHOUT_DCOMP_RDTCS
133 printf("\nRadio Data and Transmitter Control System Options:\n\n");
134 printf(" --rds-pi   PI         - Sets the RDS Programme Identification (PI)\n"
135        " --rds-ps   PS         - Sets the RDS Programme Service Name (PS)\n"
136        " --rds-pty  PTY        - Sets the RDS Programme Type (PTY)\n"
137        " --rds-tp              - Sets the RDS Traffic Programme (TP) flag\n"
138        " --rds-ct              - Enables sending of RDS Clock Time (CT)\n"
139       );
140#endif
141
142 printf("\nServer Options:\n\n");
143 printf(" -t  --tcp             - Use TCP listen socket\n"
144        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
145#ifdef ROAR_HAVE_LIBDNET
146        " -n  --decnet          - use DECnet listen socket\n"
147#endif
148        " -4                    - Use IPv4 connections (implies -t)\n"
149#ifdef PF_INET6
150        " -6                    - Use IPv6 connections (implies -t)\n"
151#endif
152#ifdef IPV6_ADDRFORM
153        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
154        "                         this is normaly not usefull.\n"
155#endif
156        " -p  --port            - TCP Port to bind to\n"
157        " -b  --bind            - IP/Hostname to bind to\n"
158        "     --sock            - Filename for UNIX Domain Socket\n"
159        "     --proto PROTO     - Use PROTO as protocol on Socket\n"
160        "     --proto-dir DIR   - Set direction parameter for protocol\n"
161        "     --proto-rate RATE - Set sample rate parameter for protocol\n"
162        "     --proto-bits BITS - Set bits per sample parameter for protocol\n"
163        "     --proto-codec E   - Set codec parameter for protocol\n"
164        "     --proto-chans C   - Set number of channels paramter for protocol\n"
165        "     --list-proto      - List supported protocols\n"
166        "     --new-sock        - Parameters for new socket follows\n"
167#ifdef ROAR_HAVE_LIBSLP
168        "     --slp             - Enable OpenSLP support\n"
169#endif
170#ifdef ROAR_HAVE_LIBX11
171        "     --x11             - Enable X11 support\n"
172#endif
173        " --jumbo-mtu MTU       - Sets the MTU for Jumbo Packets\n"
174        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
175        "                         You need the permissions to change the GID\n"
176        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
177        "                         You need the permissions to change the UID (normaly only root has)\n"
178        " --no-listen           - Do not listen for new clients\n"
179        "                         (only usefull for relaing, impleys --terminate)\n"
180        " --client-fh           - Comunicate with a client over this handle\n"
181        "                         (only usefull for relaing)\n"
182        " --close-fh            - Closes the given fh\n"
183        " --standby             - Start in standby state\n"
184        " --auto-standby        - Automatical goes into standby if there are no streams\n",
185#ifdef ROAR_DEFAULT_SOCKGRP
186        ROAR_DEFAULT_SOCKGRP
187#else
188        "(none)"
189#endif
190       );
191// printf("\n Options:\n\n");
192 printf("\n");
193}
194
195static void list_proto (void) {
196 printf("  Protocol Flag Subsys - Description\n");
197 printf("------------------------------------------------------\n");
198 printf("  roar          WM LRX - RoarAudio native protocol\n");
199#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
200 printf("  esd           W      - EsounD emulation\n");
201#endif
202 printf("  simple        WM LRX - PulseAudio simple protocol\n");
203}
204
205#endif
206
207int restart_server (char * server, int terminate) {
208 struct roar_connection con;
209#ifdef ROAR_HAVE_KILL
210 char buf[80];
211 ssize_t l;
212 struct roar_vio_calls fh;
213 pid_t pid;
214 int ok;
215
216 if ( pidfile != NULL ) {
217  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
218   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
219  } else {
220   l = roar_vio_read(&fh, buf, 80);
221   roar_vio_close(&fh);
222   if ( l > 0 ) {
223    buf[l-1] = 0;
224    buf[79]  = 0;
225    pid = atoi(buf);
226    if ( terminate ) {
227     ok = kill(pid, SIGUSR1);
228    } else {
229     ok = kill(pid, SIGINT);
230    }
231    if ( ok == 0 ) {
232     return 0;
233    } else {
234     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
235    }
236   } else {
237    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
238   }
239  }
240 }
241#endif
242
243 if ( roar_connect(&con, server) == -1 ) {
244  return -1;
245 }
246
247 if ( roar_terminate(&con, terminate) == -1 ) {
248  return -1;
249 }
250
251 return roar_disconnect(&con);
252}
253
254#define R_SETUID 1
255#define R_SETGID 2
256
257int init_config (void) {
258 int i;
259
260 memset(g_config, 0, sizeof(struct roard_config));
261
262 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
263  g_config->streams[i].mixer_channels = 1;
264  g_config->streams[i].mixer.rpg_mul  = 1;
265  g_config->streams[i].mixer.rpg_div  = 1;
266  g_config->streams[i].mixer.scale    = 65535;
267  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
268 }
269
270 g_config->streams[ROAR_DIR_PLAY    ].flags = ROAR_FLAG_META;
271 g_config->streams[ROAR_DIR_OUTPUT  ].flags = ROAR_FLAG_PASSMIXER;
272 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
273 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
274 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
275
276 g_config->location = "***default***";
277
278 return 0;
279}
280
281#ifdef ROAR_SUPPORT_LISTEN
282int init_listening (void) {
283 int i;
284
285 memset(g_listen, 0, sizeof(g_listen));
286
287 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
288  g_listen[i].socket = -1;
289  g_listen[i].proto  = ROAR_PROTO_ROARAUDIO;
290  server[i]          = NULL;
291 }
292
293 return 0;
294}
295
296int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
297#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
298 struct group   * grp  = NULL;
299#endif
300#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
301 struct passwd  * pwd  = NULL;
302#endif
303#ifdef ROAR_HAVE_UNIX
304 char * env_roar_proxy_backup;
305#endif
306 int    sockid = -1;
307 int    sock;
308 int    i;
309
310 if ( *addr != 0 ) {
311  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
312   if ( g_listen[i].socket == -1 ) {
313    sockid = i;
314    break;
315   }
316  }
317
318  if ( sockid == -1 )
319   return -1;
320
321  g_listen[sockid].proto = proto;
322
323  ROAR_DBG("add_listen(*): proto=0x%.4x", proto);
324
325  if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) {
326#ifdef ROAR_HAVE_UNIX
327   if ( *addr == '/' ) {
328    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
329     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
330     unsetenv("ROAR_PROXY");
331    }
332    if ( (sock = roar_socket_connect(addr, port)) != -1 ) {
333     close(sock);
334     ROAR_ERR("Can not open listen socket: Socket allready in use");
335     return 1;
336    } else {
337     unlink(addr);
338     if ( (g_listen[sockid].socket = roar_socket_listen(sock_type, addr, port)) == -1 ) {
339      ROAR_ERR("Can not open listen socket: %s", strerror(errno));
340      return 1;
341     }
342    }
343    if ( env_roar_proxy_backup != NULL ) {
344     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
345     free(env_roar_proxy_backup);
346    }
347#else
348   if (0) { // noop
349#endif
350   } else {
351    ROAR_ERR("Can not open listen socket: %s", strerror(errno));
352    return 1;
353   }
354  }
355
356#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
357  if ( group != NULL ) {
358   if ( (grp = getgrnam(group)) == NULL ) {
359    ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno));
360   }
361  }
362#endif
363#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
364  if ( user ) {
365   if ( (pwd = getpwnam(user)) == NULL ) {
366    ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno));
367   }
368  }
369#endif
370
371#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
372  if ( *addr == '/' ) {
373   if ( grp || pwd ) {
374     if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 )
375      return 1;
376   }
377#ifdef ROAR_HAVE_GETUID
378   if ( grp ) {
379    if ( getuid() == 0 )
380     if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
381      return 1;
382   }
383#endif
384  }
385#endif
386 }
387
388 // in case we opened the listening socket correctly.
389 if ( dir == -1 )
390  dir = ROAR_DIR_PLAY;
391
392 g_listen[sockid].inst.stpl.dir = dir;
393 memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info));
394
395 switch (dir) {
396  case ROAR_DIR_PLAY:
397  case ROAR_DIR_RECORD:
398  case ROAR_DIR_MONITOR:
399  case ROAR_DIR_FILTER:
400  case ROAR_DIR_BIDIR:
401    if ( !g_listen[sockid].inst.stpl.info.rate )
402     g_listen[sockid].inst.stpl.info.rate = g_sa->rate;
403
404    if ( !g_listen[sockid].inst.stpl.info.bits )
405     g_listen[sockid].inst.stpl.info.bits = g_sa->bits;
406
407    if ( !g_listen[sockid].inst.stpl.info.channels )
408     g_listen[sockid].inst.stpl.info.channels = g_sa->channels;
409
410    if ( !g_listen[sockid].inst.stpl.info.codec )
411     g_listen[sockid].inst.stpl.info.codec = g_sa->codec;
412   break;
413 }
414
415 server[sockid] = addr;
416 return 0;
417}
418#endif
419
420int update_stream_flags (char * str) {
421 int    dir;
422 char * flags;
423 char * k;
424 int    op;
425 int    flag;
426
427 if ( (flags = strstr(str, "=")) == NULL )
428  return -1;
429
430 *flags = 0;
431  flags++;
432
433 if ( (dir = roar_str2dir(str)) == -1 )
434  return -1;
435
436 while (flags != NULL) {
437  k = flags;
438  flags = strstr(flags, ",");
439
440  if ( flags != NULL )
441   *(flags++) = 0;
442
443  switch (*k) {
444   case '+': k++; op = ROAR_SET_FLAG;   break;
445   case '-': k++; op = ROAR_RESET_FLAG; break;
446   default:
447     op = ROAR_SET_FLAG;
448  }
449
450  flag = 0;
451
452  if ( !strcmp(k, "sync") ) {
453   flag = ROAR_FLAG_SYNC;
454  } else if ( !strcmp(k, "meta") ) {
455   flag = ROAR_FLAG_META;
456  } else if ( !strcmp(k, "cleanmeta") ) {
457   flag = ROAR_FLAG_CLEANMETA;
458  } else if ( !strcmp(k, "pause") ) {
459   flag = ROAR_FLAG_PAUSE;
460  } else if ( !strcmp(k, "mute") ) {
461   flag = ROAR_FLAG_MUTE;
462  } else if ( !strcmp(k, "antiecho") ) {
463   flag = ROAR_FLAG_ANTIECHO;
464  } else if ( !strcmp(k, "passmixer") ) {
465   flag = ROAR_FLAG_PASSMIXER;
466  } else {
467   return -1;
468  }
469
470  g_config->streams[dir].flags |= flag;
471
472  if ( op == ROAR_RESET_FLAG )
473   g_config->streams[dir].flags -= flag;
474 }
475
476 return 0;
477}
478
479int add_output (char * drv, char * dev, char * opts, int prim, int count) {
480 int stream;
481 struct roar_stream * s;
482 struct roar_stream_server * ss;
483 char * k, * v;
484#ifdef ROAR_DRIVER_CODEC
485 char * to_free = NULL;
486#endif
487 int sync = 0, f_mmap = 0;
488 int32_t blocks = -1, blocksize = -1;
489 int dir = ROAR_DIR_OUTPUT;
490 int error = 0;
491 // DMX:
492 int32_t channel  = -1;
493 int32_t universe = -1;
494 uint16_t tu16;
495 float q = -32e6;
496
497 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
498
499 if ( drv == NULL && count == 0 ) {
500  drv  = ROAR_DRIVER_DEFAULT;
501  prim = 1;
502  sync = 1;
503
504#ifdef ROAR_DRIVER_CODEC
505  if ( opts == NULL ) {
506   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
507  }
508#endif
509 }
510
511 if ( opts == NULL && count == 0 ) {
512  sync = 1;
513  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
514 }
515
516 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
517
518 if ( (stream = streams_new()) == -1 ) {
519  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
520  if ( prim ) alive = 0;
521  return -1;
522 }
523
524 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
525
526 streams_get(stream, &ss);
527 s = ROAR_STREAM(ss);
528
529 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
530
531 memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1
532
533 s->pos_rel_id = -1;
534// s->info.codec = codec;
535
536 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
537
538 if ( opts == NULL ) {
539  k = NULL;
540 } else {
541  k = strtok(opts, ",");
542 }
543
544 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k);
545
546 while (k != NULL) {
547//  ROAR_WARN("add_output(*): opts: %s", k);
548
549  if ( (v = strstr(k, "=")) != NULL ) {
550   *v++ = 0;
551  }
552
553  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
554  if ( strcmp(k, "rate") == 0 ) {
555   s->info.rate = atoi(v);
556  } else if ( strcmp(k, "channels") == 0 ) {
557   s->info.channels = atoi(v);
558  } else if ( strcmp(k, "bits") == 0 ) {
559   s->info.bits = atoi(v);
560  } else if ( strcmp(k, "codec") == 0 ) {
561   if ( (s->info.codec = roar_str2codec(v)) == -1 ) {
562    ROAR_ERR("add_output(*): unknown codec '%s'", v);
563    error++;
564   }
565  } else if ( strcmp(k, "q") == 0 ) {
566   q = atof(v);
567  } else if ( strcmp(k, "blocks") == 0 ) {
568   blocks = atoi(v);
569  } else if ( strcmp(k, "blocksize") == 0 ) {
570   blocksize = atoi(v);
571  } else if ( strcmp(k, "mmap") == 0 ) {
572   f_mmap = 1;
573  } else if ( strcmp(k, "subsystem") == 0 ) {
574   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
575    dir = ROAR_DIR_OUTPUT;
576#ifndef ROAR_WITHOUT_DCOMP_MIDI
577   } else if ( !strcasecmp(v, "midi") ) {
578    dir = ROAR_DIR_MIDI_OUT;
579#endif
580#ifndef ROAR_WITHOUT_DCOMP_LIGHT
581   } else if ( !strcasecmp(v, "light") ) {
582    dir = ROAR_DIR_LIGHT_OUT;
583#endif
584#ifndef ROAR_WITHOUT_DCOMP_RAW
585   } else if ( !strcasecmp(v, "raw") ) {
586    dir = ROAR_DIR_RAW_OUT;
587#endif
588   } else if ( !strcasecmp(v, "complex") ) {
589    dir = ROAR_DIR_COMPLEX_OUT;
590   } else {
591    ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k);
592    error++;
593   }
594  // DMX:
595  } else if ( strcmp(k, "channel") == 0 ) {
596   channel  = atoi(v);
597   if ( channel < 0 || channel > 65535 ) {
598    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
599    channel = -1;
600    error++;
601   }
602  } else if ( strcmp(k, "universe") == 0 ) {
603   universe = atoi(v);
604   if ( universe < 0 || universe > 255 ) {
605    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
606    universe = -1;
607    error++;
608   }
609
610  } else if ( strcmp(k, "name") == 0 ) {
611   if ( streams_set_name(stream, v) == -1 ) {
612    ROAR_ERR("add_output(*): Can not set Stream name");
613    error++;
614   }
615
616  } else if ( strcmp(k, "meta") == 0 ) {
617   streams_set_flag(stream, ROAR_FLAG_META);
618  } else if ( strcmp(k, "sync") == 0 ) {
619   sync = 1;
620  } else if ( strcmp(k, "primary") == 0 ) {
621   prim = 1;
622
623  } else if ( strcmp(k, "cleanmeta") == 0 ) {
624   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
625  } else if ( strcmp(k, "autoconf") == 0 ) {
626   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
627  } else if ( strcmp(k, "recsource") == 0 ) {
628   streams_set_flag(stream, ROAR_FLAG_RECSOURCE);
629  } else if ( strcmp(k, "passmixer") == 0 ) {
630   streams_set_flag(stream, ROAR_FLAG_PASSMIXER);
631  } else {
632   ROAR_ERR("add_output(*): unknown option '%s'", k);
633   error++;
634  }
635
636  if ( error ) {
637   streams_delete(stream);
638   if ( prim ) alive = 0;
639#ifdef ROAR_DRIVER_CODEC
640   if ( to_free != NULL )
641    free(to_free);
642#endif
643   return -1;
644  }
645
646  k = strtok(NULL, ",");
647 }
648
649 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
650
651 // set audio info...
652 switch (dir) {
653  case ROAR_DIR_LIGHT_OUT:
654    switch (s->info.codec) {
655     case ROAR_CODEC_DMX512:
656     case -1:
657       if ( s->info.rate == -1 )
658        s->info.rate = ROAR_OUTPUT_CFREQ;
659
660       s->info.channels =   0;
661       s->info.bits     =   8;
662       s->info.codec    = ROAR_CODEC_DMX512; // in case codec == -1
663      break;
664    }
665   break;
666  case ROAR_DIR_MIDI_OUT:
667    switch (s->info.codec) {
668     case ROAR_CODEC_MIDI:
669     case -1:
670       if ( s->info.rate == -1 )
671        s->info.rate    = ROAR_MIDI_TICKS_PER_BEAT;
672
673       s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
674       s->info.bits     = ROAR_MIDI_BITS;
675       s->info.codec    = ROAR_CODEC_MIDI; // in case codec == -1
676      break;
677    }
678   break;
679  case ROAR_DIR_RAW_OUT:
680    if ( s->info.rate == -1 )
681     s->info.rate = 0;
682    if ( s->info.bits == -1 )
683     s->info.bits = 0;
684    if ( s->info.channels == -1 )
685     s->info.channels = 0;
686    if ( s->info.codec == -1 )
687     s->info.codec = 0;
688   break;
689 }
690
691 if ( s->info.rate == -1 )
692  s->info.rate = g_sa->rate;
693 if ( s->info.bits == -1 )
694  s->info.bits = g_sa->bits;
695 if ( s->info.channels == -1 )
696  s->info.channels = g_sa->channels;
697 if ( s->info.codec == -1 )
698  s->info.codec = g_sa->codec;
699
700 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
701
702 if ( streams_set_dir(stream, dir, 1) == -1 ) {
703  streams_delete(stream);
704  return -1;
705 }
706
707#ifdef ROAR_DRIVER_CODEC
708 if ( to_free != NULL )
709  free(to_free);
710#endif
711
712 if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW )
713  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
714
715 ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec;
716
717 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) {
718  ss->driver_id = -1; // don't close a driver not opened...
719  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
720  streams_delete(stream);
721  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
722  if ( prim ) alive = 0;
723  return -1;
724 }
725
726 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
727 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
728
729 if ( blocks != -1 )
730  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
731
732 if ( blocksize != -1 )
733  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
734
735 // TODO: we shoudld *really* check for errors here...
736 if ( channel != -1 ) {
737  tu16 = channel;
738  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
739 }
740 if ( universe != -1 ) {
741  tu16 = universe;
742  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
743 }
744
745 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
746
747 streams_set_fh(stream, -1); // update some internal structures
748
749 if ( q > -1e6 ) {
750  ROAR_DBG("add_output(*): setting q=%f", q);
751  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
752 }
753
754 client_stream_add(g_self_client, stream);
755
756 if ( prim ) {
757  streams_mark_primary(stream);
758  s->pos_rel_id = stream;
759 }
760
761 if ( sync ) {
762  streams_set_flag(stream, ROAR_FLAG_SYNC);
763 } else {
764  streams_reset_flag(stream, ROAR_FLAG_SYNC);
765 }
766
767 if ( f_mmap )
768  streams_set_flag(stream, ROAR_FLAG_MMAP);
769
770 ROAR_DBG("add_output(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec);
771 return 0;
772}
773
774// X11:
775#ifdef ROAR_HAVE_LIBX11
776int register_x11 (int unreg, char * sockname) {
777 struct roar_x11_connection * x11con = NULL;
778 int ret = 0;
779
780 if ( (x11con = roar_x11_connect(NULL)) == NULL )
781  return -1;
782
783 if ( unreg ) {
784  if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 )
785   ret = -1;
786 } else {
787  if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 )
788   ret = -1;
789 }
790
791 roar_x11_disconnect(x11con);
792
793 return ret;
794}
795#endif
796
797// SLP:
798void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
799 /* return the error code in the cookie */
800 *(SLPError*)cookie = errcode;
801}
802
803int register_slp (int unreg, char * sockname) {
804#ifdef ROAR_HAVE_LIBSLP
805 static int regged = 0;
806 static char * sn = NULL;
807 SLPError err;
808 SLPError callbackerr;
809 SLPHandle hslp;
810 char addr[1024];
811 char attr[1024] = "";
812 char * location;
813
814 if ( sockname != NULL )
815  sn = sockname;
816
817 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn);
818
819 err = SLPOpen("en", SLP_FALSE, &hslp);
820
821 if (err != SLP_OK) {
822  ROAR_ERR("Error opening slp handle: Error #%i", err);
823  return -1;
824 }
825
826 if (!unreg) {
827
828  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
829   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
830   SLPClose(hslp);
831   return -1;
832  }
833
834  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
835#ifndef ROAR_WITHOUT_DCOMP_LIGHT
836                               "(light-channels=%i),"
837#endif
838                               "(location=%s)",
839           g_sa->rate, g_sa->channels, g_sa->bits,
840#ifndef ROAR_WITHOUT_DCOMP_LIGHT
841           g_light_state.channels,
842#endif
843           location
844          );
845
846  /* Register a service with SLP */
847  err = SLPReg(hslp,
848               addr,
849               SLP_LIFETIME_MAXIMUM,
850               0,
851               attr,
852               SLP_TRUE,
853               register_slp_callback,
854               &callbackerr);
855  regged = 1;
856 } else if ( unreg && regged ) {
857  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
858  regged = 0;
859 } else {
860  SLPClose(hslp);
861  return -1;
862 }
863
864 /* err may contain an error code that occurred as the slp library    */
865 /* _prepared_ to make the call.                                     */
866 if ( err != SLP_OK ) {
867  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
868  return -1;
869 }
870
871 /* callbackerr may contain an error code (that was assigned through */
872 /* the callback cookie) that occurred as slp packets were sent on    */
873 /* the wire */
874 if (callbackerr != SLP_OK) {
875  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
876  return -1;
877 }
878
879 SLPClose(hslp);
880 return 0;
881#else
882 return -1;
883#endif
884}
885
886
887// MAIN:
888
889#ifdef ROAR_HAVE_MAIN_ARGS
890int main (int argc, char * argv[]) {
891#else
892int main (void) {
893#endif
894#ifdef ROAR_HAVE_MAIN_ARGS
895 int i;
896 char * k;
897#endif
898#if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID)
899 char user_sock[80]  = {0};
900#endif
901 struct roar_audio_info sa, max_sa;
902 struct roard_config config;
903#ifdef ROAR_HAVE_FORK
904 int    daemon       = 0;
905#endif
906 int    realtime     = 0;
907 int    sysclocksync = 0;
908 char * driver    = NULL;
909 char * device    = NULL;
910#ifdef ROAR_HAVE_MAIN_ARGS
911 char * opts      = NULL;
912#endif
913// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
914#ifdef ROAR_SUPPORT_LISTEN
915 int    port       = ROAR_DEFAULT_PORT;
916 char * sock_addr  = NULL;
917 int    sock_proto = ROAR_PROTO_ROARAUDIO;
918 int    sock_dir   = -1;
919 struct roar_audio_info sock_info = {0, 0, 0, 0};
920#endif
921 int               drvid;
922#ifndef ROAR_WITHOUT_DCOMP_SOURCES
923 char * s_drv     = "cf";
924 char * s_dev     = NULL;
925 char * s_con     = NULL;
926 char * s_opt     = NULL;
927 int    s_prim    = 0;
928#endif
929 char * o_drv     = getenv("ROAR_DRIVER");
930 char * o_dev     = getenv("ROAR_DEVICE");
931 char * o_opts    = NULL;
932 int    o_prim    = 0;
933 int    o_count   = 0;
934#ifndef ROAR_WITHOUT_DCOMP_LIGHT
935 int    light_channels = LIGHT_CHANNELS_DEFAULT;
936#endif
937#ifdef ROAR_DEFAULT_SOCKGRP
938 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
939#else
940 char * sock_grp  = NULL;
941#endif
942 char * sock_user = NULL;
943#ifdef ROAR_SUPPORT_LISTEN
944 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
945#endif
946#ifdef ROAR_HAVE_LIBSLP
947 int    reg_slp   = 0;
948#endif
949#ifdef ROAR_HAVE_LIBX11
950 int    reg_x11   = 0;
951#endif
952#ifdef ROAR_HAVE_CHROOT
953 char * chrootdir = NULL;
954#endif
955#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
956 struct group   * grp  = NULL;
957#endif
958#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
959 struct passwd  * pwd  = NULL;
960#endif
961#ifdef ROAR_HAVE_GETSERVBYNAME
962 struct servent * serv = NULL;
963#endif
964 DRIVER_USERDATA_T drvinst;
965 struct roar_client * self = NULL;
966#ifdef ROAR_HAVE_LIBDNET
967 char decnethost[80];
968#endif
969#ifdef SUPPORT_PIDFILE
970 struct roar_vio_calls pidfile_vio;
971#endif
972
973 ROAR_DBG("main(*): starting roard...");
974
975 g_standby       =  0;
976 g_autostandby   =  0;
977 alive           =  1;
978#ifdef ROAR_SUPPORT_LISTEN
979 g_no_listen     =  0;
980#else
981 g_terminate     =  1;
982#endif
983
984 g_verbose       = ROAR_DBG_INFO_NONE;
985
986 sa.bits     = ROAR_BITS_DEFAULT;
987 sa.channels = ROAR_CHANNELS_DEFAULT;
988 sa.rate     = ROAR_RATE_DEFAULT;
989 sa.codec    = ROAR_CODEC_DEFAULT;
990
991 g_sa        = &sa;
992 g_max_sa    = &max_sa;
993
994 memcpy(g_max_sa, g_sa, sizeof(max_sa));
995
996 g_config = &config;
997
998 if ( init_config() == -1 ) {
999  ROAR_ERR("Can not init default config!");
1000  return 1;
1001 }
1002
1003 // load config
1004 roar_libroar_get_config();
1005
1006#ifdef ROAR_SUPPORT_LISTEN
1007 if ( init_listening() == -1 ) {
1008  ROAR_ERR("Can not init listening sockets!");
1009  return 1;
1010 }
1011#endif
1012
1013#ifndef ROAR_WITHOUT_DCOMP_MIDI
1014 if ( midi_init_config() == -1 ) {
1015  ROAR_ERR("Can not init MIDI config!");
1016  return 1;
1017 }
1018#endif
1019
1020#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1021 if ( ssynth_init_config() == -1 ) {
1022  ROAR_ERR("Can not init ssynth config!");
1023  return 1;
1024 }
1025#endif
1026
1027#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1028 if ( rdtcs_init_config() == -1 ) {
1029  ROAR_ERR("Can not init RDTCS config!");
1030  return 1;
1031 }
1032#endif
1033
1034 if ( plugins_preinit() == -1 ) {
1035  ROAR_ERR("Can not pre-init plugins!");
1036  return 1;
1037 }
1038
1039#ifdef ROAR_SUPPORT_LISTEN
1040#ifndef ROAR_TARGET_WIN32
1041 sock_addr = ROAR_DEFAULT_SOCK_GLOBAL;
1042#else
1043 sock_addr = ROAR_DEFAULT_HOST;
1044#endif
1045
1046#ifdef ROAR_HAVE_GETUID
1047 if ( getuid() != 0 && getenv("HOME") != NULL ) {
1048  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
1049  sock_addr = user_sock;
1050 }
1051#endif
1052
1053 if ( getenv("ROAR_SERVER") != NULL )
1054  sock_addr = getenv("ROAR_SERVER");
1055#endif
1056
1057 if ( clients_init() == -1 ) {
1058  ROAR_ERR("Can not init clients!");
1059  return 1;
1060 }
1061
1062 if ( streams_init() == -1 ) {
1063  ROAR_ERR("Can not init streams!");
1064  return 1;
1065 }
1066
1067 if ( (g_self_client = clients_new()) == -1 ) {
1068  ROAR_ERR("Can not create self client!");
1069  return 1;
1070 }
1071
1072#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1073 if ( sources_init() == -1 ) {
1074  ROAR_ERR("Can not init sources!");
1075  return 1;
1076 }
1077
1078 if ( (sources_set_client(g_self_client)) == -1 ) {
1079  ROAR_ERR("Can not init set source client!");
1080  return 1;
1081 }
1082#endif
1083
1084#ifdef ROAR_HAVE_MAIN_ARGS
1085 for (i = 1; i < argc; i++) {
1086  k = argv[i];
1087
1088  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
1089   usage();
1090   return 0;
1091
1092  } else if ( strcmp(k, "--start") == 0 ) {
1093   // this is a no op
1094  } else if ( strcmp(k, "--restart") == 0 ) {
1095#ifdef ROAR_SUPPORT_LISTEN
1096   if ( restart_server(sock_addr, 1) == -1 ) {
1097    ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr);
1098   }
1099#else
1100   ROAR_ERR("--restart not supported");
1101#endif
1102  } else if ( strcmp(k, "--shutdown") == 0 ) {
1103#ifdef ROAR_SUPPORT_LISTEN
1104   if ( restart_server(sock_addr, 1) == -1 ) {
1105    ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr);
1106    return 1;
1107   }
1108   return 0;
1109#else
1110   ROAR_ERR("--shutdown not supported");
1111   return 1;
1112#endif
1113  } else if ( strcmp(k, "--stop") == 0 ) {
1114#ifdef ROAR_SUPPORT_LISTEN
1115   if ( restart_server(sock_addr, 0) == -1 ) {
1116    ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr);
1117    return 1;
1118   }
1119   return 0;
1120#else
1121   ROAR_ERR("--stop not supported");
1122   return 1;
1123#endif
1124
1125
1126  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
1127#ifdef ROAR_HAVE_FORK
1128   daemon = 1;
1129#else
1130   ROAR_ERR("--daemon not supported");
1131#endif
1132  } else if ( strcmp(k, "--verbose") == 0 ) {
1133   g_verbose++;
1134  } else if ( strcmp(k, "--terminate") == 0 ) {
1135   g_terminate = 1;
1136  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
1137   sysclocksync = 1000;
1138  } else if ( strcmp(k, "--realtime") == 0 ) {
1139   realtime++;
1140  } else if ( strcmp(k, "--chroot") == 0 ) {
1141#ifdef ROAR_HAVE_CHROOT
1142   chrootdir = argv[++i];
1143#else
1144   ROAR_ERR("--chroot not supported");
1145   i++;
1146#endif
1147  } else if ( strcmp(k, "--setgid") == 0 ) {
1148#ifdef ROAR_HAVE_SETGID
1149   setids |= R_SETGID;
1150#else
1151   ROAR_ERR("--setgid not supported");
1152#endif
1153  } else if ( strcmp(k, "--setuid") == 0 ) {
1154#ifdef ROAR_HAVE_SETUID
1155   setids |= R_SETUID;
1156#else
1157   ROAR_ERR("--setuid not supported");
1158#endif
1159  } else if ( strcmp(k, "--location") == 0 ) {
1160   g_config->location = argv[++i];
1161  } else if ( strcmp(k, "--pidfile") == 0 ) {
1162#ifdef SUPPORT_PIDFILE
1163   pidfile = argv[++i];
1164#else
1165   ROAR_ERR("--pidfile not supported");
1166   i++;
1167#endif
1168
1169  } else if ( strcmp(k, "--plugin-load") == 0 ) {
1170   if ( plugins_load(argv[++i]) == -1 ) {
1171    ROAR_ERR("Can not load plugin");
1172   }
1173
1174  } else if ( strcmp(k, "--list-cf") == 0 ) {
1175   print_codecfilterlist();
1176   return 0;
1177
1178  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
1179   sa.rate = atoi(argv[++i]);
1180  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
1181   sa.bits = atoi(argv[++i]);
1182  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
1183   sa.channels = atoi(argv[++i]);
1184
1185  } else if ( strcmp(k, "--stream-flags") == 0 ) {
1186   if ( update_stream_flags(argv[++i]) == -1 ) {
1187    ROAR_ERR("Can not set stream flags");
1188    return 1;
1189   }
1190
1191  } else if ( strcmp(k, "-d") == 0 || strcmp(k, "--driver") == 0 ) {
1192   driver = argv[++i];
1193   if ( strcmp(driver, "list") == 0 ) {
1194    ROAR_WARN("The option is obsolete, use --list-driver!");
1195    print_driverlist();
1196    return 0;
1197   }
1198  } else if ( strcmp(k, "-D") == 0 || strcmp(k, "--device") == 0 ) {
1199   device = argv[++i];
1200  } else if ( strcmp(k, "-dO") == 0 ) {
1201   opts = argv[++i];
1202  } else if ( strcmp(k, "--list-driver") == 0 ) {
1203   print_driverlist();
1204   return 0;
1205
1206  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
1207   o_drv  = argv[++i];
1208  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
1209   o_dev  = argv[++i];
1210  } else if ( strcmp(k, "-oO") == 0 ) {
1211   o_opts = argv[++i];
1212  } else if ( strcmp(k, "-oP") == 0 ) {
1213   o_prim = 1;
1214  } else if ( strcmp(k, "-oN") == 0 ) {
1215   if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
1216    o_count++;
1217
1218   o_drv  = o_dev = o_opts = NULL;
1219   o_prim = 0;
1220
1221  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
1222#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1223   s_drv = argv[++i];
1224#else
1225   ROAR_ERR("main(*): No support for sources compiled in");
1226#endif
1227  } else if ( strcmp(k, "-S") == 0 ) {
1228#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1229   s_dev = argv[++i];
1230#else
1231   ROAR_ERR("main(*): No support for sources compiled in");
1232#endif
1233  } else if ( strcmp(k, "-sO") == 0 ) {
1234#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1235   s_opt = argv[++i];
1236#else
1237   ROAR_ERR("main(*): No support for sources compiled in");
1238#endif
1239  } else if ( strcmp(k, "-sC") == 0 ) {
1240#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1241   s_con = argv[++i];
1242#else
1243   ROAR_ERR("main(*): No support for sources compiled in");
1244#endif
1245  } else if ( strcmp(k, "-sP") == 0 ) {
1246#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1247   s_prim = 1;
1248#else
1249   ROAR_ERR("main(*): No support for sources compiled in");
1250#endif
1251  } else if ( strcmp(k, "-sN") == 0 ) {
1252#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1253   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1254    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1255   }
1256   s_opt = s_dev = s_con = NULL;
1257   s_drv = "cf";
1258   s_prim = 0;
1259#else
1260   ROAR_ERR("main(*): No support for sources compiled in");
1261#endif
1262  } else if ( strcmp(k, "--list-sources") == 0 ) {
1263#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1264   print_sourcelist();
1265   return 0;
1266#else
1267   ROAR_ERR("main(*): No support for sources compiled in");
1268   return 1;
1269#endif
1270
1271  } else if ( strcmp(k, "--light-channels") == 0 ) {
1272#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1273   light_channels = atoi(argv[++i]);
1274#else
1275   ROAR_WARN("main(*): no light subsystem compiled in");
1276#endif
1277
1278  } else if ( strcmp(k, "--rds-pi") == 0 ) {
1279#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1280   g_rdtcs.rds.pi = atoi(argv[++i]);
1281#else
1282   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1283#endif
1284  } else if ( strcmp(k, "--rds-ps") == 0 ) {
1285#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1286   if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) {
1287    ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]);
1288    return 1;
1289   }
1290#else
1291   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1292#endif
1293  } else if ( strcmp(k, "--rds-pty") == 0 ) {
1294#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1295   if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) {
1296    ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]);
1297    return 1;
1298   }
1299#else
1300   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1301#endif
1302  } else if ( strcmp(k, "--rds-tp") == 0 ) {
1303#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1304   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) {
1305    ROAR_ERR("Can not set RDS TP flag");
1306    return 1;
1307   }
1308#else
1309   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1310#endif
1311  } else if ( strcmp(k, "--rds-ct") == 0 ) {
1312#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1313   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) {
1314    ROAR_ERR("Can not set RDS CT flag");
1315    return 1;
1316   }
1317#else
1318   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
1319#endif
1320
1321
1322  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
1323#ifndef ROAR_WITHOUT_DCOMP_CB
1324   midi_config.init_cb = 0;
1325#else
1326   // no warning here as this is the disable option
1327#endif
1328  } else if ( strcmp(k, "--midi-console-enable") == 0 ) {
1329#ifndef ROAR_WITHOUT_DCOMP_CB
1330   midi_config.init_cb = 1;
1331#else
1332   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
1333#endif
1334  } else if ( strcmp(k, "--midi-console") == 0 ) {
1335#ifndef ROAR_WITHOUT_DCOMP_CB
1336   midi_config.console_dev = argv[++i];
1337   midi_config.init_cb = 1;
1338#else
1339   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
1340#endif
1341
1342  } else if ( strcmp(k, "--ssynth-enable") == 0 ) {
1343#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1344   ssynth_conf.enable = 1;
1345#else
1346   ROAR_ERR("main(*): No support for ssynth compiled in");
1347#endif
1348  } else if ( strcmp(k, "--ssynth-disable") == 0 ) {
1349#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1350   ssynth_conf.enable = 0;
1351#else
1352   // we can safely ignore the disable
1353#endif
1354
1355  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
1356   // This is only usefull in INET not UNIX mode.
1357#ifdef ROAR_SUPPORT_LISTEN
1358   if ( *sock_addr == '/' )
1359    sock_addr = ROAR_DEFAULT_HOST;
1360
1361   errno = 0;
1362   if ( (port = atoi(argv[++i])) < 1 ) {
1363#ifdef ROAR_HAVE_GETSERVBYNAME
1364    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
1365     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
1366     return 1;
1367    }
1368    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
1369    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
1370            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
1371    port = ROAR_NET2HOST16(serv->s_port);
1372#else
1373    ROAR_ERR("invalite port number: %s", argv[i]);
1374    return 1;
1375#endif
1376   }
1377#endif
1378  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
1379#ifdef ROAR_SUPPORT_LISTEN
1380   sock_addr = argv[++i];
1381#endif
1382
1383  } else if ( strcmp(k, "--proto") == 0 ) {
1384#ifdef ROAR_SUPPORT_LISTEN
1385   if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) {
1386    ROAR_ERR("Unknown protocol: %s", argv[i]);
1387    return 1;
1388   }
1389#endif
1390  } else if ( strcmp(k, "--proto-dir") == 0 ) {
1391#ifdef ROAR_SUPPORT_LISTEN
1392   if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) {
1393    ROAR_ERR("Unknown stream direction: %s", argv[i]);
1394    return 1;
1395   }
1396#endif
1397  } else if ( strcmp(k, "--proto-rate") == 0 ) {
1398#ifdef ROAR_SUPPORT_LISTEN
1399   sock_info.rate = atoi(argv[++i]);
1400#endif
1401  } else if ( strcmp(k, "--proto-bits") == 0 ) {
1402#ifdef ROAR_SUPPORT_LISTEN
1403   sock_info.bits = atoi(argv[++i]);
1404#endif
1405  } else if ( strcmp(k, "--proto-chans") == 0 ) {
1406#ifdef ROAR_SUPPORT_LISTEN
1407   sock_info.channels = atoi(argv[++i]);
1408#endif
1409  } else if ( strcmp(k, "--proto-codec") == 0 ) {
1410#ifdef ROAR_SUPPORT_LISTEN
1411   if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) {
1412    ROAR_ERR("Unknown codec: %s", argv[i]);
1413    return 1;
1414   }
1415#endif
1416
1417
1418  } else if ( strcmp(k, "--list-proto") == 0 ) {
1419   list_proto();
1420   return 0;
1421
1422  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
1423#ifdef ROAR_SUPPORT_LISTEN
1424   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
1425    sock_type = ROAR_SOCKET_TYPE_TCP;
1426
1427   if ( *sock_addr == '/' )
1428    sock_addr = ROAR_DEFAULT_HOST;
1429#endif
1430
1431  } else if ( strcmp(k, "-4") == 0 ) {
1432#ifdef ROAR_SUPPORT_LISTEN
1433   sock_type = ROAR_SOCKET_TYPE_TCP;
1434   if ( *sock_addr == '/' )
1435    sock_addr = ROAR_DEFAULT_HOST;
1436#endif
1437  } else if ( strcmp(k, "-6") == 0 ) {
1438#ifdef ROAR_SUPPORT_LISTEN
1439#ifdef PF_INET6
1440   sock_type = ROAR_SOCKET_TYPE_TCP6;
1441   if ( *sock_addr == '/' )
1442    sock_addr = ROAR_DEFAULT_HOST;
1443#else
1444    ROAR_ERR("No IPv6 support compiled in!");
1445    return 1;
1446#endif
1447#endif
1448
1449  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
1450#ifdef ROAR_SUPPORT_LISTEN
1451   // ignore this case as it is the default behavor.
1452   sock_type = ROAR_SOCKET_TYPE_UNIX;
1453#endif
1454
1455  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
1456#ifdef ROAR_SUPPORT_LISTEN
1457#ifdef ROAR_HAVE_LIBDNET
1458    port   = ROAR_DEFAULT_NUM;
1459    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
1460    sock_addr = decnethost;
1461    sock_type = ROAR_SOCKET_TYPE_DECNET;
1462#else
1463    ROAR_ERR("No DECnet support compiled in!");
1464    return 1;
1465#endif
1466#endif
1467  } else if ( strcmp(k, "--new-sock") == 0 ) {
1468#ifdef ROAR_SUPPORT_LISTEN
1469   if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
1470    ROAR_ERR("Can not open listen socket!");
1471    return 1;
1472   }
1473#endif
1474
1475  } else if ( strcmp(k, "--slp") == 0 ) {
1476#ifdef ROAR_HAVE_LIBSLP
1477   reg_slp = 1;
1478#else
1479   ROAR_ERR("No OpenSLP support compiled in!");
1480   return 1;
1481#endif
1482
1483  } else if ( strcmp(k, "--x11") == 0 ) {
1484#ifdef ROAR_HAVE_LIBX11
1485   reg_x11 = 1;
1486#else
1487   ROAR_ERR("No X11 support compiled in!");
1488   return 1;
1489#endif
1490
1491
1492  } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
1493   g_config->jumbo_mtu = atoi(argv[++i]);
1494
1495  } else if ( strcmp(k, "-G") == 0 ) {
1496   sock_grp  = argv[++i];
1497  } else if ( strcmp(k, "-U") == 0 ) {
1498   sock_user = argv[++i];
1499
1500  } else if ( strcmp(k, "--no-listen") == 0 ) {
1501#ifdef ROAR_SUPPORT_LISTEN
1502   sock_addr   = "";
1503   g_terminate = 1;
1504   g_no_listen = 1;
1505#endif
1506  } else if ( strcmp(k, "--client-fh") == 0 ) {
1507   if ( clients_set_fh(clients_new(), atoi(argv[++i])) == -1 ) {
1508    ROAR_ERR("main(*): Can not set client's fh");
1509    return 1;
1510   }
1511  } else if ( strcmp(k, "--close-fh") == 0 ) {
1512#ifdef ROAR_HAVE_IO_POSIX
1513   close(atoi(argv[++i]));
1514#else
1515   i++;
1516   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
1517#endif
1518
1519  } else if ( strcmp(k, "--standby") == 0 ) {
1520   g_standby = 1;
1521  } else if ( strcmp(k, "--auto-standby") == 0 ) {
1522   g_autostandby = 1;
1523  } else {
1524   usage();
1525   return 1;
1526  }
1527
1528 }
1529#endif
1530
1531#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1532 if ( s_dev != NULL ) {
1533  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
1534   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
1535  }
1536 }
1537#endif
1538
1539 add_output(o_drv, o_dev, o_opts, o_prim, o_count);
1540
1541 ROAR_DBG("Server config: rate=%i, bits=%i, chans=%i", sa.rate, sa.bits, sa.channels);
1542
1543 if ( waveform_init() == -1 ) {
1544  ROAR_ERR("Can not initialize Waveform subsystem");
1545  return 1;
1546 }
1547
1548#ifndef ROAR_WITHOUT_DCOMP_MIDI
1549 if ( midi_init() == -1 ) {
1550  ROAR_ERR("Can not initialize MIDI subsystem");
1551 }
1552#endif
1553
1554#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1555 if ( ssynth_init() == -1 ) {
1556  ROAR_ERR("Can not initialize ssynth subsystem");
1557 }
1558#endif
1559
1560#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1561 if ( light_init(light_channels) == -1 ) {
1562  ROAR_ERR("Can not initialize light control subsystem");
1563 }
1564#endif
1565
1566#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1567 if ( rdtcs_init() == -1 ) {
1568  ROAR_ERR("Can not initialize RDTCS subsystem");
1569 }
1570#endif
1571
1572 if ( plugins_init() == -1 ) {
1573  ROAR_ERR("Can not initialize plugins");
1574 }
1575
1576#ifdef ROAR_SUPPORT_LISTEN
1577 if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
1578  ROAR_ERR("Can not open listen socket!");
1579  return 1;
1580 }
1581#endif
1582
1583 if ( output_buffer_init(&sa) == -1 ) {
1584  ROAR_ERR("Can not init output buffer!");
1585  return 1;
1586 }
1587
1588 if ( driver == NULL ) {
1589  driver = "null";
1590 } else {
1591  ROAR_WARN("Usage of old driver interface. use -o not -d!");
1592 }
1593
1594 if ( driver_open(&drvinst, &drvid, driver, device, &sa) == -1 ) {
1595  ROAR_ERR("Can not open output driver!");
1596  return 1;
1597 }
1598
1599 if ( samples_init() == -1 ) {
1600  ROAR_ERR("Can not init samples!");
1601  return 1;
1602 }
1603
1604
1605 // we should handle this on microcontrollers, too.
1606#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
1607 signal(SIGINT,  on_sig_int);
1608 signal(SIGTERM, on_sig_term);
1609 signal(SIGCHLD, on_sig_chld);
1610 signal(SIGUSR1, on_sig_usr1);
1611 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
1612#endif
1613
1614 if ( realtime ) {
1615#ifdef DEBUG
1616  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compiel without -DDEBUG");
1617#endif
1618
1619#ifdef ROAR_HAVE_NICE
1620  errno = 0;
1621  nice(-5*realtime); // -5 for each --realtime
1622  if ( errno ) {
1623   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1624  }
1625#else
1626  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
1627#endif
1628/*
1629#ifdef __linux__
1630  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
1631   ROAR_WARN("Can not set io priority: %s", strerror(errno));
1632#endif
1633*/
1634 }
1635
1636#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
1637 if ( setids & R_SETGID ) {
1638  if ( sock_grp == NULL ) {
1639   ROAR_ERR("Can not set GID if no groupname is supplied");
1640   return 1;
1641  }
1642  if ( (grp = getgrnam(sock_grp)) == NULL ) {
1643   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
1644   return 1;
1645  }
1646  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
1647   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
1648  }
1649  if ( !grp || setgid(grp->gr_gid) == -1 ) {
1650   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
1651  }
1652 }
1653#endif
1654
1655
1656 clients_set_pid(g_self_client, getpid());
1657#ifdef ROAR_HAVE_GETUID
1658 clients_set_uid(g_self_client, getuid());
1659#endif
1660#ifdef ROAR_HAVE_GETGID
1661 clients_set_gid(g_self_client, getgid());
1662#endif
1663 clients_get(g_self_client, &self);
1664
1665 if ( self == NULL ) {
1666  ROAR_ERR("Can not get self client!");
1667  return 1;
1668 }
1669
1670 strcpy(self->name, "RoarAudio daemon internal");
1671
1672 if ( roar_nnode_free(&(self->nnode)) == -1 )
1673  return 1;
1674
1675 // not fully correct but ok as workaorund
1676 // so tools assume that roard runs on the same machine as
1677 // they in case they use AF_UNIX:
1678 if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 )
1679  return 1;
1680
1681#ifdef ROAR_HAVE_FORK
1682 if ( daemon ) {
1683  close(ROAR_STDIN );
1684  close(ROAR_STDOUT);
1685  close(ROAR_STDERR);
1686
1687  if ( fork() )
1688   ROAR_U_EXIT(0);
1689
1690#ifdef ROAR_HAVE_SETSID
1691  setsid();
1692#endif
1693  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
1694 }
1695#endif
1696
1697#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1698 // early test for UID as we need this for the pidfile and the setuid()
1699 if ( sock_user != NULL ) {
1700  if ( (pwd = getpwnam(sock_user)) == NULL ) {
1701   ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
1702   return 1;
1703  }
1704 }
1705#endif
1706
1707#ifdef SUPPORT_PIDFILE
1708 if ( pidfile != NULL ) {
1709  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
1710   ROAR_ERR("Can not write pidfile: %s", pidfile);
1711  } else {
1712   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
1713   roar_vio_close(&pidfile_vio);
1714  }
1715#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1716  if ( pwd || grp ) {
1717   if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) {
1718    ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno));
1719   }
1720  }
1721  if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) {
1722   ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno));
1723  }
1724#endif
1725 }
1726#endif
1727
1728#ifdef ROAR_HAVE_CHROOT
1729 if (chrootdir) {
1730  if ( chroot(chrootdir) == -1 ) {
1731   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
1732   return 2;
1733  }
1734  if ( chdir("/") == -1 ) {
1735   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
1736   return 2;
1737  }
1738 }
1739#endif
1740
1741#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1742 if ( setids & R_SETUID ) {
1743  if ( sock_user == NULL ) {
1744   ROAR_ERR("Can not set UID if no username is supplied");
1745   return 1;
1746  }
1747  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
1748   ROAR_ERR("Can not set UserID: %s", strerror(errno));
1749   return 3;
1750  }
1751#ifdef ROAR_HAVE_GETUID
1752  clients_set_uid(g_self_client, getuid());
1753#endif
1754 }
1755#endif
1756
1757 // Register with OpenSLP:
1758#ifdef ROAR_HAVE_LIBSLP
1759 if ( reg_slp ) {
1760  register_slp(0, sock_addr);
1761 }
1762#endif
1763
1764#ifdef ROAR_HAVE_LIBX11
1765 if ( reg_x11 ) {
1766  register_x11(0, sock_addr);
1767 }
1768#endif
1769
1770 // start main loop...
1771 main_loop(drvid, drvinst, &sa, sysclocksync);
1772
1773 // clean up.
1774 clean_quit_prep();
1775 driver_close(drvinst, drvid);
1776 output_buffer_free();
1777
1778 return 0;
1779}
1780
1781void cleanup_listen_socket (int terminate) {
1782 int i;
1783
1784 // Deregister from SLP:
1785#ifdef ROAR_HAVE_LIBSLP
1786 register_slp(1, NULL);
1787#endif
1788
1789#ifdef ROAR_HAVE_LIBX11
1790 register_x11(1, NULL);
1791#endif
1792
1793#ifdef ROAR_SUPPORT_LISTEN
1794 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
1795  if ( g_listen[i].socket != -1 ) {
1796#ifdef ROAR_HAVE_IO_POSIX
1797   close(g_listen[i].socket);
1798#endif // #else is useless because we are in void context.
1799
1800   g_listen[i].socket = -1;
1801
1802#ifdef ROAR_HAVE_UNIX
1803   if ( server[i] != NULL )
1804    if ( *(server[i]) == '/' )
1805     unlink(server[i]);
1806#endif
1807  }
1808 }
1809
1810#endif
1811
1812 if ( terminate )
1813  g_terminate = 1;
1814}
1815
1816void clean_quit_prep (void) {
1817 cleanup_listen_socket(0);
1818
1819 plugins_free();
1820
1821#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1822 sources_free();
1823#endif
1824 streams_free();
1825 clients_free();
1826#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1827 ssynth_free();
1828#endif
1829#ifndef ROAR_WITHOUT_DCOMP_CB
1830 midi_cb_stop(); // stop console beep
1831#endif
1832#ifndef ROAR_WITHOUT_DCOMP_MIDI
1833 midi_free();
1834#endif
1835#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1836 light_free();
1837#endif
1838#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1839 rdtcs_free();
1840#endif
1841
1842 waveform_free();
1843
1844#ifdef SUPPORT_PIDFILE
1845 if ( pidfile != NULL )
1846  unlink(pidfile);
1847#endif
1848}
1849
1850void clean_quit (void) {
1851 clean_quit_prep();
1852// driver_close(drvinst, drvid);
1853// output_buffer_free();
1854 exit(0);
1855}
1856
1857//ll
Note: See TracBrowser for help on using the repository browser.