source: roaraudio/roard/roard.c @ 4811:8d0d713ca0c1

Last change on this file since 4811:8d0d713ca0c1 was 4811:8d0d713ca0c1, checked in by phi, 13 years ago

Removed old -d and friends from roard (Closes: #122)

File size: 81.7 KB
Line 
1//roard.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28enum action {
29 START,
30 STOP,
31 RESTART,
32 RESTART_RETRY,
33 SHUTDOWN
34};
35
36enum af_mode {
37 AF_MODE_NONE,
38 AF_MODE_LOAD,
39 AF_MODE_GEN
40};
41
42#ifdef ROAR_SUPPORT_LISTEN
43char * server[ROAR_MAX_LISTEN_SOCKETS];
44#endif
45
46#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX)
47#define SUPPORT_PIDFILE
48char * pidfile = NULL;
49#endif
50
51#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
52int    setids    = 0;
53#endif
54
55#ifdef ROAR_HAVE_LIBX11
56char * x11display = NULL;
57#endif
58
59int add_output (char * drv, char * dev, char * opts, int prim, int count);
60
61void dbg_notify_cb(struct roar_notify_core * core, struct roar_event * event, void * userdata) {
62 char buf[1024] = "";
63 char estr[1024] = "/* ROAR_??? */";
64 char ttstr[1024] = "/* ROAR_OT_??? */";
65 const char * ttname;
66 uint32_t ev = ROAR_EVENT_GET_TYPE(event);
67 int i;
68
69 ttname = roar_ot2str(event->target_type);
70 if ( ttname != NULL ) {
71  snprintf(ttstr, sizeof(ttstr)-1, "/* ROAR_OT_%s */", ttname);
72  buf[sizeof(ttstr)-1] = 0;
73  for (i = 0; ttstr[i] != 0; i++)
74   if ( islower(ttstr[i]) )
75    ttstr[i] = toupper(ttstr[i]);
76 }
77
78 if ( ev == ROAR_NOTIFY_SPECIAL ) {
79  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_SPECIAL */");
80 } else if ( ROAR_NOTIFY_IS_CMD(ev) ) {
81  if ( command_get_name(ROAR_NOTIFY_EVENT2CMD(ev), &ttname) == -1 ) {
82   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(%i) */", ROAR_NOTIFY_EVENT2CMD(ev));
83  } else {
84   snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_CMD2EVENT(ROAR_CMD_%s) */", ttname);
85   for (i = 0; estr[i] != 0; i++)
86    if ( islower(estr[i]) )
87     estr[i] = toupper(estr[i]);
88  }
89 } else if ( ROAR_NOTIFY_IS_EGRP(ev) ) {
90  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_EGRP2EVENT(%i) */", ROAR_NOTIFY_EVENT2EGRP(ev));
91 } else if ( ROAR_NOTIFY_IS_OE(ev) ) {
92  switch (ev) {
93   // OE basics:
94   case ROAR_OE_BASICS_CHANGE_STATE:
95     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_STATE */");
96    break;
97   case ROAR_OE_BASICS_CHANGE_FLAGS:
98     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_CHANGE_FLAGS */");
99    break;
100   case ROAR_OE_BASICS_NEW:
101     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_NEW */");
102    break;
103   case ROAR_OE_BASICS_DELETE:
104     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_BASICS_DELETE */");
105    break;
106   // OE Streams:
107   case ROAR_OE_STREAM_CHANGE_VOLUME:
108     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_CHANGE_VOLUME */");
109    break;
110   case ROAR_OE_STREAM_XRUN:
111     snprintf(estr, sizeof(estr)-1, "/* ROAR_OE_STREAM_XRUN */");
112    break;
113   // OE Default:
114   default:
115     snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_OE2EVENT(%i) */", ROAR_NOTIFY_EVENT2OE(ev));
116    break;
117  }
118 } else if ( ROAR_NOTIFY_IS_USER(ev) ) {
119  snprintf(estr, sizeof(estr)-1, "/* ROAR_NOTIFY_USER2EVENT(%i) */", ROAR_NOTIFY_EVENT2USER(ev));
120 }
121
122 buf[sizeof(estr)-1] = 0;
123
124 if ( event->flags & ROAR_EVENT_FLAG_PROXYEVENT ) {
125  snprintf(buf, sizeof(buf)-1, ".event_proxy=0x%.8x%s, ", (int)event->event_proxy, estr);
126  buf[sizeof(buf)-1] = 0;
127 }
128
129 ROAR_INFO("dbg_notify_cb(core=%p, event=%p{.flags=0x%.8x, event=0x%.8x%s, %s.emitter=%i, .target=%i, .target_type=%i%s, .arg0=%i, .arg1=%i, .arg2=%p}, userdata=%p) = (void)",
130           0 /* always print: minlevel = 0 */,
131           core, event,
132           (int)event->flags,
133           (int)event->event,
134           (event->flags & ROAR_EVENT_FLAG_PROXYEVENT ? "" : estr),
135           buf,
136           event->emitter,
137           event->target,
138           event->target_type,
139           ttstr,
140           event->arg0,
141           event->arg1,
142           event->arg2,
143           userdata);
144}
145
146void dbg_notify_cb_register (void) {
147 struct roar_event event;
148
149 memset(&event, 0, sizeof(event));
150
151 event.event = ROAR_EGRP_ANY_EVENT;
152
153 event.emitter = -1;
154 event.target = -1;
155 event.target_type = -1;
156
157 roar_notify_core_subscribe(NULL, &event, dbg_notify_cb, NULL);
158}
159
160#ifdef ROAR_HAVE_MAIN_ARGS
161void usage (void) {
162 printf("Usage: roard [OPTIONS]...\n\n");
163
164 printf("Misc Options:\n\n");
165 printf(
166        " --daemon              - Bring the server into background after init\n"
167        " --verbose             - Be more verbose, can be used multiple times\n"
168        " --terminate           - Terminate after last client quited\n"
169        " --start               - No op parameter (starting roard is default operation)\n"
170        " --restart             - Trys to stop an old instance and start a new with new settings\n"
171        " --stop                - Stops a running roard (provide --pidfile!)\n"
172        " --shutdown            - Terminates a running roard (provide --pidfile!)\n"
173        " --realtime            - Trys to get realtime priority,\n"
174        "                         give multible times for being more realtime\n"
175        " --memlock LEVEL       - Set default memory locking level to LEVEL\n"
176        " --chroot DIR          - chroots to the given dir\n"
177        " --setgid              - GroupID to the audio group as specified via -G\n"
178        " --setuid              - UserID to the audio user as specified via -U\n"
179        " --sysclocksync        - calculate exact sample rate using the system clock\n"
180        " --location  LOC       - Set lion readable location of server\n"
181        " --description  DESC   - Set lion readable description of server\n"
182#ifdef SUPPORT_PIDFILE
183        " --pidfile PIDFILE     - Write a pidfile at PIDFILE\n"
184#endif
185#ifdef ROAR_HAVE_SYSLOG
186        " --log-syslog          - Log Warnings, Errors, ... to syslog\n"
187#endif
188       );
189
190 printf("\nAuth Options:\n\n");
191 printf(
192        " --guest-acclev ACCLEV - Sets the access level for guest access to ACCLEV\n"
193        " --trust-acclev ACCLEV - Sets the access level for trust-authed\n"
194        "                         connections to ACCLEV\n"
195        " --trust-root          - Trust root user\n"
196        " --no-trust-root       - Don't trust root user\n"
197        " --authfile-gen FILE   - Generate an new authfile\n"
198        " --authfile-load FILE  - Load an authfile\n"
199        " --authfile-type TYPE  - Type of authfile\n"
200        " --authfile-acclev ACCLEV\n"
201        "                       - Sets the access level for authfile\n"
202        " --new-authfile        - Parameters for new authfile follow\n"
203       );
204
205 printf("\nPlugin Options:\n\n");
206 printf(
207        " --plugin-load FILE    - Load plugin FILE\n"
208       );
209
210 printf("\nAudio Options:\n\n");
211 printf(
212        " -R  --rate   RATE     - Set server rate\n"
213        " -B  --bits   BITS     - Set server bits\n"
214        " -C  --chans  CHANNELS - Set server channels\n"
215        " --aiprofile  PROFILE  - Use the given audio profile\n"
216       );
217
218 printf("\nStream Options:\n\n");
219 printf(
220        " --stream-flags D=F    - Set default flags for stream directions\n"
221        "                         D is the stream direction and F is a comma separated\n"
222        "                         list of flags in form +flag or -flag to set or unset\n"
223        "                         a flag as default or remove it from the default\n"
224       );
225
226 printf("\nOutput Options:\n\n");
227 printf(" -o  --odriver DRV     - Set the driver, use '--list-driver' to get a list\n");
228 printf(" -O  --odevice DEV     - Set the device\n");
229 printf(" -oO OPTS              - Set output options\n");
230 printf(" -oN                   - Adds another output\n");
231 printf(" -oP                   - Mark output as primary\n");
232#ifdef ROAR_DRIVER_DEFAULT
233 printf(" --list-driver         - List all drivers (default driver: %s)\n", ROAR_DRIVER_DEFAULT);
234#else
235 printf(" --list-driver         - List all drivers (default driver: (autodetect))\n");
236#endif
237
238#ifndef ROAR_WITHOUT_DCOMP_SOURCES
239 printf("\nSource Options:\n\n");
240 printf(" -s  --source DRV      - Use DRV as input driver\n"
241        " -S           DEV      - Use DEV as input device\n"
242        " -sO          OPTS     - Use OPTS as input options\n"
243        " -sN                   - Adds another source\n"
244        " -sP                   - Make souce as primary\n"
245       );
246 printf(" --list-sources        - List all sources\n");
247#endif
248
249#ifndef ROAR_WITHOUT_DCOMP_MIXER
250 printf("\nHardware Mixer Options:\n\n");
251 printf(" -m  --mixer  DRV      - Use DRV as mixer driver\n"
252        " -M           DEV      - Use DEV as mixer device\n"
253        " -mO          OPTS     - Use OPTS as mixer options\n"
254        " -mN                   - Adds another mixer\n"
255        " -mP                   - Make mixer as primary\n"
256       );
257 printf(" --list-mixers         - List all mixers\n");
258#endif
259
260 printf("\nCodec Filter Options:\n\n");
261 printf(" --list-cf             - List all codec filter\n"
262       );
263
264#ifndef ROAR_WITHOUT_DCOMP_MIDI
265 printf("\nMIDI Options:\n\n");
266 printf(" --midi-no-console     - Disable console based MIDI synth\n"
267        " --midi-console-enable - Enables the console based MIDI synth\n"
268        " --midi-console DEV    - Set device for MIDI console\n"
269#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
270        " --ssynth-enable       - Enable simple software synth\n"
271        " --ssynth-disable      - Disable simple software synth\n"
272#endif
273       );
274#endif
275
276#ifndef ROAR_WITHOUT_DCOMP_LIGHT
277 printf("\nLight Control Options:\n\n");
278 printf(" --light-channels NUM  - Sets the number of channels for Light control (default: %i)\n",
279                                  LIGHT_CHANNELS_DEFAULT
280       );
281#endif
282
283#ifndef ROAR_WITHOUT_DCOMP_RDTCS
284 printf("\nRadio Data and Transmitter Control System Options:\n\n");
285 printf(" --rds-pi   PI         - Sets the RDS Programme Identification (PI)\n"
286        " --rds-ps   PS         - Sets the RDS Programme Service Name (PS)\n"
287        " --rds-pty  PTY        - Sets the RDS Programme Type (PTY)\n"
288        " --rds-tp              - Sets the RDS Traffic Programme (TP) flag\n"
289        " --rds-ct              - Enables sending of RDS Clock Time (CT)\n"
290       );
291#endif
292
293#ifdef ROAR_HAVE_LIBX11
294 printf("\nX11 Options:\n\n");
295 printf(
296        " --x11-display DISPLAY - Set display for X11\n"
297        " --display DISPLAY     - Set display for X11\n"
298       );
299#endif
300
301 printf("\nServer Options:\n\n");
302 printf(" -t  --tcp             - Use TCP listen socket\n"
303#ifdef ROAR_HAVE_UNIX
304        " -u  --unix            - Use UNIX Domain listen socket (default)\n"
305#endif
306#ifdef ROAR_HAVE_LIBDNET
307        " -n  --decnet          - use DECnet listen socket\n"
308#endif
309        " -4                    - Use IPv4 connections (implies -t)\n"
310#ifdef AF_INET6
311        " -6                    - Use IPv6 connections (implies -t)\n"
312#endif
313#ifdef IPV6_ADDRFORM
314        " -64                   - Try to downgrade sockets from IPv6 into IPv4,\n"
315        "                         this is normaly not useful.\n"
316#endif
317        " -p  --port            - TCP Port to bind to\n"
318        " -b  --bind            - IP/Hostname to bind to\n"
319        "     --sock            - Filename for UNIX Domain Socket\n"
320        "     --proto PROTO     - Use PROTO as protocol on Socket\n"
321        "     --proto-dir DIR   - Set direction parameter for protocol\n"
322        "     --proto-rate RATE - Set sample rate parameter for protocol\n"
323        "     --proto-bits BITS - Set bits per sample parameter for protocol\n"
324        "     --proto-codec E   - Set codec parameter for protocol\n"
325        "     --proto-chans C   - Set number of channels parameter for protocol\n"
326        "     --proto-aiprofile PROFILE\n"
327        "                       - Sets the audio profile for socket\n"
328        "     --proto-profile P - Set profile for listen socket\n"
329        "     --list-proto      - List supported protocols\n"
330        "     --list-profiles   - List supported profiles for --proto-profile\n"
331        "     --new-sock        - Parameters for new socket follow\n"
332#ifdef ROAR_HAVE_LIBSLP
333        "     --slp             - Enable OpenSLP support\n"
334#endif
335#ifdef ROAR_HAVE_LIBX11
336        "     --x11             - Enable X11 support\n"
337#endif
338        " --jumbo-mtu MTU       - Sets the MTU for Jumbo Packets\n"
339        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: %s)\n"
340        "                         You need the permissions to change the GID\n"
341        " -U  USER              - Sets the user for the UNIX Domain Socket, (default: do not set)\n"
342        "                         You need the permissions to change the UID (normaly only root has)\n"
343        " --no-listen           - Do not listen for new clients\n"
344        "                         (only useful for relaing, impleys --terminate)\n"
345        " --client-fh           - Comunicate with a client over this handle\n"
346        "                         (only useful for relaing)\n"
347        " --close-fh            - Closes the given fh\n"
348        " --standby             - Start in standby state\n"
349        " --auto-standby        - Automatical goes into standby if there are no streams\n",
350#ifdef ROAR_DEFAULT_SOCKGRP
351        ROAR_DEFAULT_SOCKGRP
352#else
353        "(none)"
354#endif
355       );
356// printf("\n Options:\n\n");
357 printf("\n");
358}
359
360static void list_proto (void) {
361 printf("  Protocol Flag Subsys - Description\n");
362 printf("------------------------------------------------------\n");
363 printf("  roar          WM LRX - RoarAudio native protocol\n");
364#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
365 printf("  esd           W      - EsounD emulation\n");
366#endif
367#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE
368 printf("  simple        WM LRX - PulseAudio simple protocol\n");
369#endif
370#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND
371 printf("  rsound        W      - RSound emulation\n");
372#endif
373#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
374 printf("  rplay         W      - RPlay emulation\n");
375#endif
376#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER
377 printf("  gopher               - The Internet Gopher Protocol\n");
378#endif
379}
380
381#endif
382
383#define _pmsg(format, args...) roar_debug_msg(type, __LINE__, __FILE__, ROAR_DBG_PREFIX, format, ## args)
384#define _pmsgc(group, counter, name) _pmsg("  Counter %-10s: %llu", (name), (long long unsigned int)counters_get(group, counter))
385void counters_print(int type, int force) {
386 if ( type != ROAR_DEBUG_TYPE_INFO || force || (ROAR_DBG_INFOVAR) >= ROAR_DBG_INFO_INFO ) {
387  _pmsg("--- Counter Listing ---");
388  _pmsg(" Current:");
389  _pmsgc(cur, clients, "Clients");
390  _pmsgc(cur, streams, "Streams");
391  _pmsg(" Total:");
392  _pmsgc(sum, clients, "Clients");
393  _pmsgc(sum, streams, "Streams");
394  _pmsg("--- End of Counter Listing ---");
395 }
396}
397#undef _pmsgc
398#undef _pmsg
399
400int restart_server (char * server, int terminate) {
401 struct roar_connection con;
402#ifdef ROAR_HAVE_KILL
403 char buf[80];
404 ssize_t l;
405 struct roar_vio_calls fh;
406 pid_t pid;
407 int ok;
408
409 ROAR_INFO("restart_server(server='%s', terminate=%i): trying to restart server", ROAR_DBG_INFO_INFO, server, terminate);
410
411 if ( pidfile != NULL ) {
412  if ( roar_vio_open_file(&fh, pidfile, O_RDONLY, 0644) == -1 ) {
413   ROAR_WARN("restart_server(*): Can not read pidfile: %s", pidfile);
414  } else {
415   l = roar_vio_read(&fh, buf, 80);
416   roar_vio_close(&fh);
417   if ( l > 0 ) {
418    buf[l-1] = 0;
419    buf[79]  = 0;
420    pid = atoi(buf);
421    if ( terminate ) {
422     ok = kill(pid, SIGUSR1);
423    } else {
424     ok = kill(pid, SIGINT);
425    }
426    if ( ok == 0 ) {
427     return 0;
428    } else {
429     ROAR_WARN("restart_server(*): Can not kill roard by pidfile");
430    }
431   } else {
432    ROAR_WARN("restart_server(*): Can not find a PID in the pidfile");
433   }
434  }
435 }
436#endif
437
438 if ( roar_simple_connect(&con, server, "roard") == -1 ) {
439  return -1;
440 }
441
442 if ( roar_terminate(&con, terminate) == -1 ) {
443  return -1;
444 }
445
446 return roar_disconnect(&con);
447}
448
449#define R_SETUID 1
450#define R_SETGID 2
451
452int init_config (void) {
453 int i;
454
455 memset(g_config, 0, sizeof(struct roard_config));
456
457 for (i = 0; i < ROAR_DIR_DIRIDS; i++) {
458  g_config->streams[i].mixer_channels = 1;
459  g_config->streams[i].mixer.rpg_mul  = 1;
460  g_config->streams[i].mixer.rpg_div  = 1;
461  g_config->streams[i].mixer.scale    = 65535;
462  g_config->streams[i].mixer.mixer[0] = g_config->streams[i].mixer.scale;
463 }
464
465 g_config->streams[ROAR_DIR_PLAY    ].flags = ROAR_FLAG_META;
466 g_config->streams[ROAR_DIR_OUTPUT  ].flags = ROAR_FLAG_PASSMIXER;
467 g_config->streams[ROAR_DIR_FILTER  ].flags = ROAR_FLAG_SYNC;
468 g_config->streams[ROAR_DIR_MIDI_OUT].flags = ROAR_FLAG_SYNC;
469 g_config->streams[ROAR_DIR_BIDIR   ].flags = ROAR_FLAG_ANTIECHO;
470
471 g_config->location    = CONF_DEF_STRING;
472 g_config->description = CONF_DEF_STRING;
473
474 g_config->memlock_level = -1;
475
476 return 0;
477}
478
479#ifdef ROAR_SUPPORT_LISTEN
480int init_listening (void) {
481 int i;
482
483 memset(g_listen, 0, sizeof(g_listen));
484
485 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
486  g_listen[i].proto  = ROAR_PROTO_ROARAUDIO;
487  server[i]          = NULL;
488 }
489
490 return 0;
491}
492
493int get_listen(struct roard_listen ** sock, char *** sockname) {
494 int i;
495
496 if ( sock == NULL )
497  return -1;
498
499 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
500  if ( ! g_listen[i].used ) {
501   server[i] = NULL;
502   *sock = &(g_listen[i]);
503
504   if ( sockname != NULL )
505    *sockname = &(server[i]);
506
507   return 0;
508  }
509 }
510
511 return -1;
512}
513
514#ifdef ROAR_SUPPORT_LISTEN
515static struct _listen_profile {
516 const char * name;
517 int          type;
518 int          port;
519 const char * sockaddr;
520 int          proto;
521 int          dir;
522 const char * aiprofile;
523 const char * desc;
524} _g_listen_profiles[] = {
525 // RoarAudio:
526#ifdef ROAR_HAVE_UNIX
527 {"roar-usock",     ROAR_SOCKET_TYPE_UNIX,   0,                 "~/" ROAR_DEFAULT_SOCK_USER,
528                    ROAR_PROTO_ROARAUDIO, -1, NULL,
529                    "RoarAudio default user profile"},
530 {"roar-gsock",     ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_SOCK_GLOBAL,
531                    ROAR_PROTO_ROARAUDIO, -1, NULL,
532                    "RoarAudio default global profile"},
533#endif
534#ifdef ROAR_HAVE_IPV4
535 {"roar-tcp",       ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PORT, ROAR_DEFAULT_INET4_HOST,
536                    ROAR_PROTO_ROARAUDIO, -1, NULL,
537                    "RoarAudio local TCP profile"},
538 {"roar-tcp-pub",   ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PORT, ROAR_NET_INET4_ANYHOST,
539                    ROAR_PROTO_ROARAUDIO, -1, NULL,
540                    "RoarAudio network TCP profile"},
541#endif
542#ifdef ROAR_HAVE_IPV6
543 {"roar-tcp6",      ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_PORT, ROAR_DEFAULT_INET4_HOST,
544                    ROAR_PROTO_ROARAUDIO, -1, NULL,
545                    "RoarAudio local TCP profile"},
546 {"roar-tcp-pub6",  ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_PORT, ROAR_NET_INET4_ANYHOST,
547                    ROAR_PROTO_ROARAUDIO, -1, NULL,
548                    "RoarAudio network TCP profile"},
549#endif
550#ifdef ROAR_HAVE_LIBDNET
551 {"roar-dnet",      ROAR_SOCKET_TYPE_DECNET, 0,                 ROAR_DEFAULT_LISTEN_OBJECT,
552                    ROAR_PROTO_ROARAUDIO, -1, NULL,
553                    "RoarAudio default DECnet"},
554#endif
555#ifdef ROAR_HAVE_UNIX
556 {"roar-abstract",  ROAR_SOCKET_TYPE_UNKNOWN,   0,              "+abstract",        ROAR_PROTO_ROARAUDIO, -1, NULL,
557                    "RoarAudio abstract namespace profile"},
558#endif
559
560 // EsounD:
561#if !defined(ROAR_WITHOUT_DCOMP_EMUL_ESD) && defined(ROAR_HAVE_H_ESD)
562#ifdef ROAR_HAVE_UNIX
563 {"esd-unix",       ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_ESD_GSOCK,
564                    ROAR_PROTO_ESOUND,    -1, NULL,
565                    "EsounD default local profile"},
566#endif
567#ifdef ROAR_HAVE_IPV4
568 {"esd-tcp",        ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET4_LOCALHOST,
569                    ROAR_PROTO_ESOUND,    -1, NULL,
570                    "EsounD local TCP profile"},
571 {"esd-tcp-pub",    ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET4_ANYHOST,
572                    ROAR_PROTO_ESOUND,    -1, NULL,
573                    "EsounD network TCP profile"},
574#endif
575#ifdef ROAR_HAVE_IPV6
576 {"esd-tcp6",       ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET6_LOCALHOST,
577                    ROAR_PROTO_ESOUND,    -1, NULL,
578                    "EsounD local TCP profile"},
579 {"esd-tcp-pub6",   ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_ESD_PORT, ROAR_NET_INET6_ANYHOST,
580                    ROAR_PROTO_ESOUND,    -1, NULL,
581                    "EsounD network TCP profile"},
582#endif
583#endif
584
585 // RSound:
586#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND
587#ifdef ROAR_HAVE_UNIX
588 {"rsound-unix",    ROAR_SOCKET_TYPE_UNIX,   0,                 ROAR_DEFAULT_RSOUND_GSOCK,
589                    ROAR_PROTO_RSOUND,    -1, NULL,
590                    "RSound default local profile"},
591#endif
592#ifdef ROAR_HAVE_IPV4
593 {"rsound-tcp",     ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET4_LOCALHOST,
594                    ROAR_PROTO_RSOUND,    -1, NULL,
595                    "RSound local TCP profile"},
596 {"rsound-tcp-pub", ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET4_ANYHOST,
597                    ROAR_PROTO_RSOUND,    -1, NULL,
598                    "RSound network TCP profile"},
599#endif
600#ifdef ROAR_HAVE_IPV6
601 {"rsound-tcp6",    ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET6_LOCALHOST,
602                    ROAR_PROTO_RSOUND,    -1, NULL,
603                    "RSound local TCP profile"},
604 {"rsound-tcp-pub6", ROAR_SOCKET_TYPE_TCP6,  ROAR_DEFAULT_RSOUND_PORT, ROAR_NET_INET6_ANYHOST,
605                    ROAR_PROTO_RSOUND,    -1, NULL,
606                    "RSound network TCP profile"},
607#endif
608#ifdef ROAR_HAVE_LIBDNET
609 {"rsound-dnet",    ROAR_SOCKET_TYPE_DECNET, 0,                 ROAR_DEFAULT_RSOUND_OBJECT,
610                    ROAR_PROTO_RSOUND,    -1, NULL,
611                    "RSound DECnet profile"},
612#endif
613#endif
614
615 // PulseAudio Simple:
616#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE
617#ifdef ROAR_HAVE_IPV4
618 {"pas-play-tcp",   ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PA_PORT, ROAR_NET_INET4_ANYHOST,
619                    ROAR_PROTO_SIMPLE, ROAR_DIR_PLAY, "default",
620                    "PulseAudio Simple TCP play profile"},
621 {"pas-mon-tcp",    ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_PA_PORT, ROAR_NET_INET4_ANYHOST,
622                    ROAR_PROTO_SIMPLE, ROAR_DIR_MONITOR, "default",
623                    "PulseAudio Simple TCP monitor profile"},
624#endif
625#ifdef ROAR_HAVE_IPV6
626 {"pas-play-tcp6",  ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_PA_PORT, ROAR_NET_INET6_ANYHOST,
627                    ROAR_PROTO_SIMPLE, ROAR_DIR_PLAY, "default",
628                    "PulseAudio Simple TCP play profile"},
629 {"pas-mon-tcp6",   ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_PA_PORT, ROAR_NET_INET6_ANYHOST,
630                    ROAR_PROTO_SIMPLE, ROAR_DIR_MONITOR, "default",
631                    "PulseAudio Simple TCP monitor profile"},
632#endif
633#endif
634
635 // RPlay:
636#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
637#ifdef ROAR_HAVE_IPV4
638 {"rplay-tcp",      ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET4_LOCALHOST,
639                    ROAR_PROTO_RPLAY,     -1, NULL,
640                    "RPlay local TCP profile"},
641 {"rplay-tcp-pub",  ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET4_ANYHOST,
642                    ROAR_PROTO_RPLAY,     -1, NULL,
643                    "RPlay network TCP profile"},
644#endif
645#ifdef ROAR_HAVE_IPV6
646 {"rplay-tcp6",     ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET6_LOCALHOST,
647                    ROAR_PROTO_RPLAY,     -1, NULL,
648                    "RPlay local TCP profile"},
649 {"rplay-tcp-pub6", ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_RPLAY_PORT, ROAR_NET_INET6_ANYHOST,
650                    ROAR_PROTO_RPLAY,     -1, NULL,
651                    "RPlay network TCP profile"},
652#endif
653#endif
654
655// Gopher:
656#ifndef ROAR_WITHOUT_DCOMP_EMUL_GOPHER
657#ifdef ROAR_HAVE_IPV4
658 {"gopher-tcp",     ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET4_LOCALHOST,
659                    ROAR_PROTO_GOPHER,    -1, NULL,
660                    "Gopher local TCP profile"},
661 {"gopher-tcp-pub", ROAR_SOCKET_TYPE_TCP,    ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET4_ANYHOST,
662                    ROAR_PROTO_GOPHER,    -1, NULL,
663                    "Gopher network TCP profile"},
664#endif
665#ifdef ROAR_HAVE_IPV6
666 {"gopher-tcp6",    ROAR_SOCKET_TYPE_TCP6,   ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET6_LOCALHOST,
667                    ROAR_PROTO_GOPHER,    -1, NULL,
668                    "Gopher local TCP profile"},
669 {"gopher-tcp-pub6", ROAR_SOCKET_TYPE_TCP6,  ROAR_DEFAULT_GOPHER_PORT, ROAR_NET_INET6_ANYHOST,
670                    ROAR_PROTO_GOPHER,    -1, NULL,
671                    "Gopher network TCP profile"},
672#endif
673#endif
674
675 // End of List:
676 {NULL, -1, -1, NULL, -1, -1, NULL, NULL}
677};
678
679void listen_listen_profiles (void) {
680 struct _listen_profile * p;
681 char * type;
682 int i;
683 char port[8];
684
685 printf("Name            Type    Address          Port    Protocol  Dir        Audio Profile - Description\n");
686 printf("-------------------------------------------------------------------------------------------------\n");
687      //roar-tcp-pub 0.0.0.0       16002   RoarAudio unknown    (null) - (null)
688
689 for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) {
690  switch (p->type) {
691   case ROAR_SOCKET_TYPE_UNIX:   type = "UNIX";   break;
692   case ROAR_SOCKET_TYPE_TCP:    type = "TCP";    break;
693   case ROAR_SOCKET_TYPE_DECNET: type = "DECnet"; break;
694   case ROAR_SOCKET_TYPE_TCP6:   type = "TCP6";   break;
695   default:
696     type = "unknown";
697    break;
698  }
699
700  if ( p->port ) {
701   snprintf(port, sizeof(port)-1, "%i", p->port);
702   port[sizeof(port)-1] = 0;
703  } else {
704   strcpy(port, "(none)");
705  }
706
707  printf("%-15s %-7s %-16s %-7s %-9s %-10s %-13s - %s\n",
708           p->name,
709           type,
710           p->sockaddr, port,
711           roar_proto2str(p->proto),
712           p->dir == -1 ? "(none)" : roar_dir2str(p->dir), p->aiprofile == NULL ? "(none)" : p->aiprofile,
713           p->desc == NULL ? "" : p->desc);
714 }
715}
716
717int get_listen_profile (const char * name,
718                        int * port, char ** sockaddr, int * type,
719                        int * proto,
720                        int * dir, struct roar_audio_info * info) {
721 static char buf[1024];
722 struct _listen_profile * p;
723 int i;
724
725 for (i = 0; (p = &(_g_listen_profiles[i]))->name != NULL; i++) {
726  if ( !strcasecmp(p->name, name) ) {
727   *port     = p->port;
728
729   if ( p->type == ROAR_SOCKET_TYPE_UNIX && p->sockaddr[0] != '+' ) {
730    roar_env_render_path_r(buf, sizeof(buf), p->sockaddr);
731   } else {
732    strncpy(buf, p->sockaddr, sizeof(buf));
733   }
734   *sockaddr = buf;
735   *type     = p->type;
736
737   *proto    = p->proto;
738   *dir      = p->dir;
739
740   if ( p->aiprofile != NULL ) {
741    if ( roar_profile2info(info, p->aiprofile) == -1 ) {
742     ROAR_ERR("Unknown audio profile: %s", p->aiprofile);
743     return -1;
744    }
745   }
746   return 0;
747  }
748 }
749
750 return -1;
751}
752#endif
753
754int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
755#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
756 struct group   * grp  = NULL;
757#endif
758#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
759 struct passwd  * pwd  = NULL;
760#endif
761#ifdef ROAR_HAVE_UNIX
762 char * env_roar_proxy_backup;
763#endif
764 int    sockid = -1;
765#ifdef ROAR_HAVE_UNIX
766 int    sock;
767#endif
768 int    i;
769
770 ROAR_INFO("add_listen(addr='%s', port=%i, sock_type=%i, user='%s', group='%s', proto=%s(%i), dir=%s(%i), info={.rate=%u, .bits=%u, .channels=%u, .codec=%s(%u)}): trying to add listen socket",
771            ROAR_DBG_INFO_INFO,
772            addr, port, sock_type, user, group, roar_proto2str(proto), proto, roar_dir2str(dir), dir,
773            info->rate, info->bits, info->channels, roar_codec2str(info->codec), info->codec);
774
775 if ( *addr != 0 ) {
776  for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
777   if ( ! g_listen[i].used ) {
778    sockid = i;
779    break;
780   }
781  }
782
783  if ( sockid == -1 )
784   return -1;
785
786  g_listen[sockid].proto = proto;
787
788  ROAR_DBG("add_listen(*): proto=0x%.4x", proto);
789
790  if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) {
791#ifdef ROAR_HAVE_UNIX
792   if ( *addr == '/' ) {
793    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
794     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
795     unsetenv("ROAR_PROXY");
796    }
797    if ( (sock = roar_socket_connect(addr, port)) != -1 ) {
798     close(sock);
799     ROAR_ERR("Can not open listen socket: Socket allready in use");
800     return -1;
801    } else {
802     unlink(addr);
803     if ( roar_vio_open_socket_listen(&(g_listen[sockid].sock), sock_type, addr, port) == -1 ) {
804      ROAR_ERR("Can not open listen socket: %s", strerror(errno));
805      return -1;
806     }
807    }
808    if ( env_roar_proxy_backup != NULL ) {
809     setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
810     free(env_roar_proxy_backup);
811    }
812#else
813   if (0) { // noop
814#endif
815   } else {
816    ROAR_ERR("Can not open listen socket: %s", strerror(errno));
817    return -1;
818   }
819  }
820
821  ROAR_DBG("add_listen(*) = ?");
822
823#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
824  if ( group != NULL ) {
825   if ( (grp = getgrnam(group)) == NULL ) {
826    ROAR_ERR("Can not get GID for group %s: %s", group, strerror(errno));
827   }
828  }
829#endif
830
831  ROAR_DBG("add_listen(*) = ?");
832
833#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
834  if ( user ) {
835   if ( (pwd = getpwnam(user)) == NULL ) {
836    ROAR_ERR("Can not get UID for user %s: %s", user, strerror(errno));
837   }
838  }
839#endif
840
841  ROAR_DBG("add_listen(*) = ?");
842
843#if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_UNIX)
844  if ( *addr == '/' ) {
845   if ( grp || pwd ) {
846     if ( chown(addr, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 )
847      return -1;
848   }
849#ifdef ROAR_HAVE_GETUID
850   if ( grp ) {
851    if ( getuid() == 0 )
852     if ( chmod(addr, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 )
853      return -1;
854   }
855#endif
856  }
857#endif
858 }
859
860 ROAR_DBG("add_listen(*) = ?");
861
862 // in case we opened the listening socket correctly.
863 if ( dir == -1 )
864  dir = ROAR_DIR_PLAY;
865
866 g_listen[sockid].inst.stpl.dir = dir;
867 memcpy(&(g_listen[sockid].inst.stpl.info), info, sizeof(struct roar_audio_info));
868
869 switch (dir) {
870  case ROAR_DIR_PLAY:
871  case ROAR_DIR_RECORD:
872  case ROAR_DIR_MONITOR:
873  case ROAR_DIR_FILTER:
874  case ROAR_DIR_BIDIR:
875    if ( !g_listen[sockid].inst.stpl.info.rate )
876     g_listen[sockid].inst.stpl.info.rate = g_sa->rate;
877
878    if ( !g_listen[sockid].inst.stpl.info.bits )
879     g_listen[sockid].inst.stpl.info.bits = g_sa->bits;
880
881    if ( !g_listen[sockid].inst.stpl.info.channels )
882     g_listen[sockid].inst.stpl.info.channels = g_sa->channels;
883
884    if ( !g_listen[sockid].inst.stpl.info.codec )
885     g_listen[sockid].inst.stpl.info.codec = g_sa->codec;
886   break;
887 }
888
889 g_listen[sockid].used = 1;
890 server[sockid]        = addr;
891
892 return 0;
893}
894#endif
895
896int update_stream_flags (char * str) {
897 int    dir;
898 char * flags;
899 char * k;
900 int    op;
901 int    flag;
902
903 if ( (flags = strstr(str, "=")) == NULL )
904  return -1;
905
906 *flags = 0;
907  flags++;
908
909 if ( (dir = roar_str2dir(str)) == -1 )
910  return -1;
911
912 while (flags != NULL) {
913  k = flags;
914  flags = strstr(flags, ",");
915
916  if ( flags != NULL )
917   *(flags++) = 0;
918
919  switch (*k) {
920   case '+': k++; op = ROAR_SET_FLAG;   break;
921   case '-': k++; op = ROAR_RESET_FLAG; break;
922   default:
923     op = ROAR_SET_FLAG;
924  }
925
926  flag = 0;
927
928  if ( !strcmp(k, "sync") ) {
929   flag = ROAR_FLAG_SYNC;
930  } else if ( !strcmp(k, "meta") ) {
931   flag = ROAR_FLAG_META;
932  } else if ( !strcmp(k, "cleanmeta") ) {
933   flag = ROAR_FLAG_CLEANMETA;
934  } else if ( !strcmp(k, "pause") ) {
935   flag = ROAR_FLAG_PAUSE;
936  } else if ( !strcmp(k, "mute") ) {
937   flag = ROAR_FLAG_MUTE;
938  } else if ( !strcmp(k, "antiecho") ) {
939   flag = ROAR_FLAG_ANTIECHO;
940  } else if ( !strcmp(k, "passmixer") ) {
941   flag = ROAR_FLAG_PASSMIXER;
942  } else {
943   return -1;
944  }
945
946  g_config->streams[dir].flags |= flag;
947
948  if ( op == ROAR_RESET_FLAG )
949   g_config->streams[dir].flags -= flag;
950 }
951
952 return 0;
953}
954
955#ifdef ROAR_DRIVER_DEFAULT
956#define add_default_output add_output
957#else
958int add_default_output (char * drv, char * dev, char * opts, int prim, int count) {
959 char * drvs[] = {
960  // operating system depended things:
961#ifdef __OpenBSD__
962  /* OpenBSD use sndio natively, this check is discusses with upstream (See ML archive August 2010) */
963  "sndio",
964#endif
965  // native and pseudo-native interfaces:
966  "oss", "alsa", "sndio", "wmm",
967  // sound libs:
968  "ao", "portaudio",
969  // other sound systems:
970  "esd", "rsound", "pulsesimple", "roar",
971  // specal buildins:
972  "sysclock", "null",
973  // terminator:
974  NULL
975 };
976 int i;
977 int ret;
978 int _alive;
979
980 if ( drv != NULL )
981  return add_output(drv, dev, opts, prim, count);
982
983 if ( dev != NULL ) {
984  ROAR_WARN("add_default_output(drv=(none), dev='%s', opts='%s', prim=%i, count=%i): It's not recommended to use device name without driver name.", dev, opts, prim, count);
985 }
986
987 for (i = 0; drvs[i] != NULL; i++) {
988  ROAR_INFO("add_default_output(*): trying driver %s", ROAR_DBG_INFO_INFO, drvs[i]);
989  _alive = alive; // save global alive setting
990
991  ret = add_output(drvs[i], dev, opts, prim, count);
992  if ( ret != -1 )
993   return ret;
994
995  alive = _alive; // restore global alive setting
996  ROAR_INFO("add_default_output(*): Driver %s faild to load", ROAR_DBG_INFO_VERBOSE, drvs[i]);
997 }
998
999 return -1;
1000}
1001#endif
1002
1003int add_output (char * drv, char * dev, char * opts, int prim, int count) {
1004 int stream;
1005 struct roar_stream * s;
1006 struct roar_stream_server * ss;
1007 char * k, * v;
1008#ifdef ROAR_DRIVER_CODEC
1009 char * to_free = NULL;
1010#endif
1011 int sync = 0, f_mmap = 0;
1012 int32_t blocks = -1, blocksize = -1;
1013 int dir = ROAR_DIR_OUTPUT;
1014 int error = 0;
1015 // DMX:
1016 int32_t channel  = -1;
1017 int32_t universe = -1;
1018 uint16_t tu16;
1019 float q = -32e6;
1020
1021 ROAR_INFO("add_output(drv='%s', dev='%s', opts='%s', prim=%i, count=%i): trying to add output driver", ROAR_DBG_INFO_INFO, drv, dev, opts, prim, count);
1022
1023 if ( drv == NULL && count == 0 ) {
1024#ifdef ROAR_DRIVER_DEFAULT
1025  drv  = ROAR_DRIVER_DEFAULT;
1026  prim = 1;
1027  sync = 1;
1028
1029#ifdef ROAR_DRIVER_CODEC
1030  if ( opts == NULL ) {
1031   opts = to_free = strdup("codec=" ROAR_DRIVER_CODEC);
1032  }
1033#endif
1034#else
1035  ROAR_ERR("add_output(*): Can not find default driver");
1036  return -1;
1037#endif
1038 }
1039
1040 if ( opts == NULL && count == 0 ) {
1041  sync = 1;
1042  prim = 1; // if ( prim == 0 ) prim = 1; -> prim allways = 1
1043 }
1044
1045 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1046
1047 if ( (stream = streams_new()) == -1 ) {
1048  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
1049  if ( prim ) alive = 0;
1050  return -1;
1051 }
1052
1053 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1054
1055 streams_get(stream, &ss);
1056 s = ROAR_STREAM(ss);
1057
1058 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1059
1060 memset(&(s->info), 0xFF, sizeof(struct roar_audio_info)); // set everything to -1
1061
1062 s->pos_rel_id = -1;
1063// s->info.codec = codec;
1064
1065 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1066
1067 if ( opts == NULL ) {
1068  k = NULL;
1069 } else {
1070  k = strtok(opts, ",");
1071 }
1072
1073 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s'): initial k='%s'(%p)", drv, dev, opts, k, k);
1074
1075 while (k != NULL) {
1076//  ROAR_WARN("add_output(*): opts: %s", k);
1077
1078  if ( (v = strstr(k, "=")) != NULL ) {
1079   *v++ = 0;
1080  }
1081
1082  ROAR_DBG("add_output(*): opts: k='%s', v='%s'", k, v);
1083  if ( strcmp(k, "rate") == 0 ) {
1084   s->info.rate = atoi(v);
1085  } else if ( strcmp(k, "channels") == 0 ) {
1086   s->info.channels = atoi(v);
1087  } else if ( strcmp(k, "bits") == 0 ) {
1088   s->info.bits = atoi(v);
1089  } else if ( strcmp(k, "codec") == 0 ) {
1090   if ( (s->info.codec = roar_str2codec(v)) == -1 ) {
1091    ROAR_ERR("add_output(*): unknown codec '%s'", v);
1092    error++;
1093   }
1094  } else if ( strcmp(k, "q") == 0 ) {
1095   q = atof(v);
1096  } else if ( strcmp(k, "blocks") == 0 ) {
1097   blocks = atoi(v);
1098  } else if ( strcmp(k, "blocksize") == 0 ) {
1099   blocksize = atoi(v);
1100  } else if ( strcmp(k, "mmap") == 0 ) {
1101   f_mmap = 1;
1102  } else if ( strcmp(k, "subsystem") == 0 ) {
1103   if ( !strcasecmp(v, "wave") || !strcasecmp(v, "waveform") ) {
1104    dir = ROAR_DIR_OUTPUT;
1105#ifndef ROAR_WITHOUT_DCOMP_MIDI
1106   } else if ( !strcasecmp(v, "midi") ) {
1107    dir = ROAR_DIR_MIDI_OUT;
1108#endif
1109#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1110   } else if ( !strcasecmp(v, "light") ) {
1111    dir = ROAR_DIR_LIGHT_OUT;
1112#endif
1113#ifndef ROAR_WITHOUT_DCOMP_RAW
1114   } else if ( !strcasecmp(v, "raw") ) {
1115    dir = ROAR_DIR_RAW_OUT;
1116#endif
1117   } else if ( !strcasecmp(v, "complex") ) {
1118    dir = ROAR_DIR_COMPLEX_OUT;
1119   } else {
1120    ROAR_ERR("add_output(*): unknown/unsupported subsystem '%s'", k);
1121    error++;
1122   }
1123  // DMX:
1124  } else if ( strcmp(k, "channel") == 0 ) {
1125   channel  = atoi(v);
1126   if ( channel < 0 || channel > 65535 ) {
1127    ROAR_ERR("add_output(*): Invalide channel (not within 0..65535): %i", channel);
1128    channel = -1;
1129    error++;
1130   }
1131  } else if ( strcmp(k, "universe") == 0 ) {
1132   universe = atoi(v);
1133   if ( universe < 0 || universe > 255 ) {
1134    ROAR_ERR("add_output(*): Invalide universe (not within 0..255): %i", universe);
1135    universe = -1;
1136    error++;
1137   }
1138
1139  } else if ( strcmp(k, "name") == 0 ) {
1140   if ( streams_set_name(stream, v) == -1 ) {
1141    ROAR_ERR("add_output(*): Can not set Stream name");
1142    error++;
1143   }
1144
1145  } else if ( strcmp(k, "meta") == 0 ) {
1146   streams_set_flag(stream, ROAR_FLAG_META);
1147  } else if ( strcmp(k, "sync") == 0 ) {
1148   sync = 1;
1149  } else if ( strcmp(k, "primary") == 0 ) {
1150   prim = 1;
1151
1152  } else if ( strcmp(k, "cleanmeta") == 0 ) {
1153   streams_set_flag(stream, ROAR_FLAG_CLEANMETA);
1154  } else if ( strcmp(k, "autoconf") == 0 ) {
1155   streams_set_flag(stream, ROAR_FLAG_AUTOCONF);
1156  } else if ( strcmp(k, "recsource") == 0 ) {
1157   streams_set_flag(stream, ROAR_FLAG_RECSOURCE);
1158  } else if ( strcmp(k, "passmixer") == 0 ) {
1159   streams_set_flag(stream, ROAR_FLAG_PASSMIXER);
1160  } else {
1161   ROAR_ERR("add_output(*): unknown option '%s'", k);
1162   error++;
1163  }
1164
1165  if ( error ) {
1166   streams_delete(stream);
1167   if ( prim ) alive = 0;
1168#ifdef ROAR_DRIVER_CODEC
1169   if ( to_free != NULL )
1170    free(to_free);
1171#endif
1172   return -1;
1173  }
1174
1175  k = strtok(NULL, ",");
1176 }
1177
1178 ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = ?", drv, dev, opts);
1179
1180 // set audio info...
1181 switch (dir) {
1182  case ROAR_DIR_LIGHT_OUT:
1183    switch (s->info.codec) {
1184     case ROAR_CODEC_DMX512:
1185     case -1:
1186       if ( s->info.rate == -1 )
1187        s->info.rate = ROAR_OUTPUT_CFREQ;
1188
1189       s->info.channels =   0;
1190       s->info.bits     =   8;
1191       s->info.codec    = ROAR_CODEC_DMX512; // in case codec == -1
1192      break;
1193    }
1194   break;
1195  case ROAR_DIR_MIDI_OUT:
1196    switch (s->info.codec) {
1197     case ROAR_CODEC_MIDI:
1198     case -1:
1199       if ( s->info.rate == -1 )
1200        s->info.rate    = ROAR_MIDI_TICKS_PER_BEAT;
1201
1202       s->info.channels = ROAR_MIDI_CHANNELS_DEFAULT;
1203       s->info.bits     = ROAR_MIDI_BITS;
1204       s->info.codec    = ROAR_CODEC_MIDI; // in case codec == -1
1205      break;
1206    }
1207   break;
1208  case ROAR_DIR_RAW_OUT:
1209    if ( s->info.rate == -1 )
1210     s->info.rate = 0;
1211    if ( s->info.bits == -1 )
1212     s->info.bits = 0;
1213    if ( s->info.channels == -1 )
1214     s->info.channels = 0;
1215    if ( s->info.codec == -1 )
1216     s->info.codec = 0;
1217   break;
1218 }
1219
1220 if ( s->info.rate == -1 )
1221  s->info.rate = g_sa->rate;
1222 if ( s->info.bits == -1 )
1223  s->info.bits = g_sa->bits;
1224 if ( s->info.channels == -1 )
1225  s->info.channels = g_sa->channels;
1226 if ( s->info.codec == -1 )
1227  s->info.codec = g_sa->codec;
1228
1229 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);
1230
1231 if ( streams_set_dir(stream, dir, 1) == -1 ) {
1232  streams_delete(stream);
1233  return -1;
1234 }
1235
1236#ifdef ROAR_DRIVER_CODEC
1237 if ( to_free != NULL )
1238  free(to_free);
1239#endif
1240
1241 if ( s->info.codec == ROAR_CODEC_ALAW || s->info.codec == ROAR_CODEC_MULAW )
1242  s->info.bits = 8; // needed to open OSS driver, will be overriden by codecfilter
1243
1244 ROAR_STREAM_SERVER(s)->codec_orgi = s->info.codec;
1245
1246 if ( driver_openvio(&(ss->vio), &(ss->driver_id), drv, dev, &(s->info), -1, ss) == -1 ) {
1247  ss->driver_id = -1; // don't close a driver not opened...
1248  memset(&(ss->vio), 0, sizeof(struct roar_vio_calls));
1249  streams_delete(stream);
1250  if ( prim ) alive = 0;
1251  ROAR_ERR("add_output(drv='%s', dev='%s', opts='%s'): can not open output driver.", drv, dev, opts);
1252  ROAR_DBG("add_output(drv='%s', dev='%s', opts='%s') = -1", drv, dev, opts);
1253  return -1;
1254 }
1255
1256 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAMID, &stream); // ignore errors here
1257 roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_SSTREAM,   s); // ignore errors here
1258
1259 if ( blocks != -1 )
1260  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLOCKS, &blocks);
1261
1262 if ( blocksize != -1 )
1263  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DBLKSIZE, &blocksize);
1264
1265 // TODO: we shoudld *really* check for errors here...
1266 if ( channel != -1 ) {
1267  tu16 = channel;
1268  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXSCHAN, &tu16);
1269 }
1270 if ( universe != -1 ) {
1271  tu16 = universe;
1272  roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_DMXUNIV, &tu16);
1273 }
1274
1275 ROAR_DBG("add_output(*): ss->driver_id=%i", ss->driver_id);
1276
1277 streams_set_fh(stream, -1); // update some internal structures
1278
1279 if ( q > -1e6 ) {
1280  ROAR_DBG("add_output(*): setting q=%f", q);
1281  streams_ctl(stream, ROAR_CODECFILTER_CTL_SET_Q|ROAR_STREAM_CTL_TYPE_FLOAT, &q);
1282 }
1283
1284 client_stream_add(g_self_client, stream);
1285
1286 if ( prim ) {
1287  streams_mark_primary(stream);
1288  s->pos_rel_id = stream;
1289 }
1290
1291 if ( sync ) {
1292  streams_set_flag(stream, ROAR_FLAG_SYNC);
1293 } else {
1294  streams_reset_flag(stream, ROAR_FLAG_SYNC);
1295 }
1296
1297 if ( f_mmap )
1298  streams_set_flag(stream, ROAR_FLAG_MMAP);
1299
1300 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);
1301 return 0;
1302}
1303
1304#ifndef ROAR_WITHOUT_DCOMP_MIXER
1305int add_hwmixer (char * drv, char * dev, char * opts, int prim, int count) {
1306 char * basename = NULL;
1307 char * subnames = NULL;
1308 char * k, * v;
1309 int basestream = streams_new();
1310 int ret;
1311 int error = 0;
1312//int hwmixer_open(int basestream, char * drv, char * dev, int fh, char * basename, char * subnames) {
1313
1314 if ( basestream == -1 )
1315  return -1;
1316
1317 client_stream_add(g_self_client, basestream);
1318
1319 if ( opts == NULL ) {
1320  k = NULL;
1321 } else {
1322  k = strtok(opts, ",");
1323 }
1324
1325 while (k != NULL) {
1326//  ROAR_WARN("add_output(*): opts: %s", k);
1327
1328  if ( (v = strstr(k, "=")) != NULL ) {
1329   *v++ = 0;
1330  }
1331
1332  if ( strcmp(k, "primary") == 0 ) {
1333   prim = 1;
1334
1335  } else if ( strcmp(k, "name") == 0 ) {
1336   basename = v;
1337  } else if ( strcmp(k, "subs") == 0 ) {
1338   subnames = v;
1339
1340  } else if ( strcmp(k, "autoconf") == 0 ) {
1341   streams_set_flag(basestream, ROAR_FLAG_AUTOCONF);
1342  } else if ( strcmp(k, "passmixer") == 0 ) {
1343   streams_set_flag(basestream, ROAR_FLAG_PASSMIXER);
1344  } else {
1345   ROAR_ERR("add_hwmixer(*): unknown option '%s'", k);
1346   error++;
1347  }
1348
1349  if ( error ) {
1350   streams_delete(basestream);
1351   if ( prim ) alive = 0;
1352   return -1;
1353  }
1354
1355  k = strtok(NULL, ",");
1356 }
1357
1358 if ( prim ) {
1359  streams_mark_primary(basestream);
1360 }
1361
1362 ret = hwmixer_open(basestream, drv, dev, -1, basename, subnames);
1363
1364 if ( ret == -1 ) {
1365  streams_delete(basestream);
1366 }
1367
1368 return ret == -1 ? -1 : 0;
1369}
1370#endif
1371
1372int add_authfile (const char * file, const char * type, enum af_mode mode, enum roard_client_acclev acclev) {
1373 struct roar_authfile * authfile = NULL;
1374 struct roar_authfile_key *  key = NULL;
1375 int af_type = ROAR_AUTHFILE_TYPE_AUTO;
1376 void * keydata;
1377 int i;
1378
1379 if ( type == NULL ) {
1380  // noop.
1381 } else if ( !strcasecmp(type, "roar") ) {
1382  af_type = ROAR_AUTHFILE_TYPE_ROAR;
1383 } else if ( !strcasecmp(type, "roar") ) {
1384  af_type = ROAR_AUTHFILE_TYPE_ROAR;
1385 } else if ( !strcasecmp(type, "esd") ) {
1386  af_type = ROAR_AUTHFILE_TYPE_ESD;
1387 } else if ( !strcasecmp(type, "pulse") ) {
1388  af_type = ROAR_AUTHFILE_TYPE_PULSE;
1389 } else if ( !strcasecmp(type, "htpasswd") ) {
1390  af_type = ROAR_AUTHFILE_TYPE_HTPASSWD;
1391 } else if ( !strcasecmp(type, "xauth") ) {
1392  af_type = ROAR_AUTHFILE_TYPE_XAUTH;
1393 } else {
1394  ROAR_ERR("add_authfile(*): unknown authfile type '%s'.", type);
1395  return -1;
1396 }
1397
1398 if ( mode == AF_MODE_GEN && af_type == ROAR_AUTHFILE_TYPE_AUTO )
1399  af_type = ROAR_AUTHFILE_TYPE_ESD;
1400
1401 switch (mode) {
1402  case AF_MODE_NONE:
1403    return 0;
1404   break;
1405  case AF_MODE_GEN:
1406    switch (af_type) {
1407     case ROAR_AUTHFILE_TYPE_ESD:
1408       key = roar_authfile_key_new_random(ROAR_AUTH_T_COOKIE, 16, NULL);
1409      break;
1410     case ROAR_AUTHFILE_TYPE_PULSE:
1411       key = roar_authfile_key_new_random(ROAR_AUTH_T_COOKIE, 256, NULL);
1412      break;
1413     default:
1414       return -1;
1415      break;
1416    }
1417
1418    if ( key == NULL ) {
1419     ROAR_ERR("add_authfile(*): Can not generate key.");
1420     return -1;
1421    }
1422
1423    if ( (authfile = roar_authfile_open(af_type, file, 1, ROAR_AUTHFILE_VERSION_AUTO)) == NULL ) {
1424     roar_authfile_key_unref(key);
1425     return -1;
1426    }
1427
1428    if ( roar_authfile_add_key(authfile, key) == -1 ) {
1429     ROAR_WARN("add_authfile(*): Can not add key to authfile.");
1430    }
1431
1432    keydata = roar_mm_memdup(key->data, key->len);
1433
1434    if ( keydata == NULL ) {
1435     ROAR_WARN("add_authfile(*): Can not allocate memory for key.");
1436    } else if ( auth_addkey_cookie(acclev, keydata, key->len) == -1 ) {
1437     ROAR_WARN("add_authfile(*): Can not add key to internal key storage.");
1438    }
1439
1440    roar_authfile_key_unref(key);
1441    if ( roar_authfile_close(authfile) != 0 )
1442     return -1;
1443    return 0;
1444   break;
1445  case AF_MODE_LOAD:
1446    if ( (authfile = roar_authfile_open(af_type, file, 0, ROAR_AUTHFILE_VERSION_AUTO)) == NULL ) {
1447     return -1;
1448    }
1449
1450    for (i = 0; ; i++) {
1451     key = roar_authfile_lookup_key(authfile, ROAR_AUTH_T_AUTO, i, NULL);
1452     if ( key == NULL )
1453      break;
1454
1455     if ( key->type == ROAR_AUTH_T_COOKIE ) {
1456      keydata = roar_mm_memdup(key->data, key->len);
1457
1458      if ( keydata == NULL ) {
1459       ROAR_WARN("add_authfile(*): Can not allocate memory for key.");
1460      } else if ( auth_addkey_cookie(acclev, keydata, key->len) == -1 ) {
1461       ROAR_WARN("add_authfile(*): Can not add key to internal key storage.");
1462      }
1463     } else {
1464      ROAR_WARN("add_authfile(*): Unknown key type: %i", key->type);
1465     }
1466
1467     roar_authfile_key_unref(key);
1468    }
1469
1470    if ( roar_authfile_close(authfile) != 0 )
1471     return -1;
1472    return 0;
1473   break;
1474 }
1475
1476 return -1;
1477}
1478
1479// X11:
1480#ifdef ROAR_HAVE_LIBX11
1481int register_x11 (int unreg, char * sockname) {
1482 struct roar_x11_connection * x11con = NULL;
1483 int ret = 0;
1484
1485 if ( (x11con = roar_x11_connect(x11display)) == NULL ) {
1486  ROAR_ERR("Can not connect to X11 server for %sregistering", unreg ? "un" : "");
1487  return -1;
1488 }
1489
1490 if ( unreg ) {
1491  if ( roar_x11_delete_prop(x11con, "ROAR_SERVER") == -1 ) {
1492   ret = -1;
1493   ROAR_ERR("Error while unregistereing from X11", ROAR_DBG_INFO_INFO);
1494  } else {
1495   ROAR_INFO("Successfully unregistered from X11", ROAR_DBG_INFO_INFO);
1496  }
1497 } else {
1498  if ( roar_x11_set_prop(x11con, "ROAR_SERVER", sockname) == -1 ) {
1499   ret = -1;
1500   ROAR_ERR("Error while registereing to X11", ROAR_DBG_INFO_INFO);
1501  } else {
1502   ROAR_INFO("Successfully registered to X11", ROAR_DBG_INFO_INFO);
1503  }
1504 }
1505
1506 roar_x11_disconnect(x11con);
1507
1508 return ret;
1509}
1510#endif
1511
1512// SLP:
1513void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) {
1514 /* return the error code in the cookie */
1515 *(SLPError*)cookie = errcode;
1516}
1517
1518int register_slp (int unreg, char * sockname) {
1519#ifdef ROAR_HAVE_LIBSLP
1520 static int regged = 0;
1521 static char * sn = NULL;
1522 SLPError err;
1523 SLPError callbackerr;
1524 SLPHandle hslp;
1525 char addr[1024];
1526 char attr[1024] = "";
1527 char * location;
1528 char * description;
1529 char * standards;
1530
1531 if ( sockname != NULL )
1532  sn = sockname;
1533
1534 snprintf(addr, sizeof(addr), ROAR_SLP_URL_TYPE_ROAR "://%s", sn);
1535
1536 err = SLPOpen("en", SLP_FALSE, &hslp);
1537
1538 if (err != SLP_OK) {
1539  ROAR_ERR("Error opening slp handle: Error #%i", err);
1540  return -1;
1541 }
1542
1543 if (!unreg) {
1544
1545  if ( SLPEscape(g_config->location, &location, SLP_FALSE) != SLP_OK ) {
1546   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
1547   SLPClose(hslp);
1548   return -1;
1549  }
1550
1551  if ( SLPEscape(g_config->description, &description, SLP_FALSE) != SLP_OK ) {
1552   ROAR_ERR("Error using SLPEscape() on server location, really bad!");
1553   SLPClose(hslp);
1554   return -1;
1555  }
1556
1557  standards = stds_string();
1558
1559  if ( standards == NULL ) {
1560   if ( (standards = roar_mm_malloc(1)) == NULL ) {
1561    SLPClose(hslp);
1562    return -1;
1563   }
1564   standards[0] = 0;
1565  }
1566
1567  snprintf(attr, sizeof(attr), "(wave-rate=%i),(wave-channels=%i),(wave-bits=%i),"
1568#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1569                               "(light-channels=%i),"
1570#endif
1571                               "(standards=%s),"
1572                               "(location=%s),(description=%s)",
1573           g_sa->rate, g_sa->channels, g_sa->bits,
1574#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1575           g_light_state.channels,
1576#endif
1577           standards,
1578           location, description
1579          );
1580
1581  roar_mm_free(standards);
1582
1583  /* Register a service with SLP */
1584  err = SLPReg(hslp,
1585               addr,
1586               SLP_LIFETIME_MAXIMUM,
1587               0,
1588               attr,
1589               SLP_TRUE,
1590               register_slp_callback,
1591               &callbackerr);
1592  regged = 1;
1593 } else if ( unreg && regged ) {
1594  err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr);
1595  regged = 0;
1596 } else {
1597  SLPClose(hslp);
1598  return -1;
1599 }
1600
1601 /* err may contain an error code that occurred as the slp library    */
1602 /* _prepared_ to make the call.                                     */
1603 if ( err != SLP_OK ) {
1604  ROAR_ERR("Error (de)registering service with slp: Error #%i", err);
1605  return -1;
1606 }
1607
1608 /* callbackerr may contain an error code (that was assigned through */
1609 /* the callback cookie) that occurred as slp packets were sent on    */
1610 /* the wire */
1611 if (callbackerr != SLP_OK) {
1612  ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr);
1613  return -1;
1614 }
1615
1616 SLPClose(hslp);
1617 return 0;
1618#else
1619 return -1;
1620#endif
1621}
1622
1623static int auth_setup (enum roard_client_acclev none_acclev,
1624                       enum roard_client_acclev trust_acclev, int trust_root, uid_t trust_uid, gid_t trust_gid) {
1625 union auth_typeunion * key;
1626 size_t i;
1627
1628 // Info:
1629 // if a authlevel is <= ACCLEV_IDENTED we do not need to add this to the keyring
1630 // as ACCLEV_IDENTED is already gained if IDENTIFY call was done correctly.
1631
1632 if ( !(none_acclev <= ACCLEV_IDENTED) ) {
1633  if ( auth_addkey_anonymous(none_acclev) == -1 )
1634   return -1;
1635 }
1636
1637 if ( !(trust_acclev <= ACCLEV_IDENTED) ) {
1638  if ( (key = auth_regkey_simple(ROAR_AUTH_T_TRUST, trust_acclev)) == NULL )
1639   return -1;
1640
1641  // zerosize all counters.
1642  memset(key, 0, sizeof(union auth_typeunion));
1643
1644  i = 0;
1645
1646  if ( trust_uid != -1 )
1647   key->trust.uids[i++] = trust_uid;
1648
1649#ifdef ROAR_ROOT_UID
1650  if ( trust_root )
1651   key->trust.uids[i++] = ROAR_ROOT_UID;
1652#endif
1653
1654  key->trust.uids_len = i;
1655
1656  i = 0;
1657
1658  if ( trust_gid != -1 )
1659   key->trust.gids[i++] = trust_gid;
1660
1661  key->trust.gids_len = i;
1662 }
1663
1664 return 0;
1665}
1666
1667
1668// MAIN:
1669
1670#define _CKHAVEARGS(x) if ( (i + (x)) >= argc ) { \
1671                        ROAR_ERR("Option %s requires more arguments. See --help for more details.", k); \
1672                        return 70; \
1673                       }
1674
1675#ifdef ROAR_HAVE_MAIN_ARGS
1676int main (int argc, char * argv[]) {
1677#else
1678int main (void) {
1679#endif
1680#ifdef ROAR_HAVE_MAIN_ARGS
1681 enum action action = START;
1682 int i;
1683 char * k;
1684#endif
1685#if defined(ROAR_SUPPORT_LISTEN) && defined(ROAR_HAVE_GETUID)
1686 char user_sock[80]  = {0};
1687#endif
1688 struct roar_audio_info sa, max_sa;
1689 struct roard_config config;
1690#ifdef ROAR_HAVE_FORK
1691 int    daemon       = 0;
1692#endif
1693 int    realtime     = 0;
1694 int    sysclocksync = 0;
1695// char * server = ROAR_DEFAULT_SOCK_GLOBAL;
1696#ifdef ROAR_SUPPORT_LISTEN
1697 int    port       = ROAR_DEFAULT_PORT;
1698 char * sock_addr  = NULL;
1699 int    sock_proto = ROAR_PROTO_ROARAUDIO;
1700 int    sock_dir   = -1;
1701 struct roar_audio_info sock_info = {0, 0, 0, 0};
1702#endif
1703#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1704 char * s_drv     = "cf";
1705 char * s_dev     = NULL;
1706 char * s_con     = NULL;
1707 char * s_opt     = NULL;
1708 int    s_prim    = 0;
1709#endif
1710 char * o_drv     = getenv("ROAR_DRIVER");
1711 char * o_dev     = getenv("ROAR_DEVICE");
1712 char * o_opts    = NULL;
1713 int    o_prim    = 0;
1714 int    o_count   = 0;
1715#ifndef ROAR_WITHOUT_DCOMP_MIXER
1716 char * m_drv     = NULL;
1717 char * m_dev     = NULL;
1718 char * m_opts    = NULL;
1719 int    m_prim    = 0;
1720 int    m_count   = 0;
1721#endif
1722 enum roard_client_acclev none_acclev  = ACCLEV_ALL;
1723 enum roard_client_acclev trust_acclev = ACCLEV_ALL;
1724 int                      trust_root   = 1;
1725 char * af_file                        = NULL;
1726 char * af_type                        = NULL;
1727 enum af_mode af_mode                  = AF_MODE_NONE;
1728 enum roard_client_acclev af_acclev    = ACCLEV_ALL;
1729#ifndef ROAR_WITHOUT_DCOMP_LIGHT
1730 int    light_channels = LIGHT_CHANNELS_DEFAULT;
1731#endif
1732#ifdef ROAR_DEFAULT_SOCKGRP
1733 char * sock_grp  = ROAR_DEFAULT_SOCKGRP;
1734#else
1735 char * sock_grp  = NULL;
1736#endif
1737 char * sock_user = NULL;
1738#ifdef ROAR_SUPPORT_LISTEN
1739 int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
1740#endif
1741#ifdef ROAR_HAVE_LIBSLP
1742 int    reg_slp   = 0;
1743#endif
1744#ifdef ROAR_HAVE_LIBX11
1745 int    reg_x11   = 0;
1746#endif
1747#ifdef ROAR_HAVE_CHROOT
1748 char * chrootdir = NULL;
1749#endif
1750#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
1751 struct group   * grp  = NULL;
1752#endif
1753#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
1754 struct passwd  * pwd  = NULL;
1755#endif
1756#ifdef ROAR_HAVE_GETSERVBYNAME
1757 struct servent * serv = NULL;
1758#endif
1759 struct roar_client * self = NULL;
1760#ifdef ROAR_HAVE_LIBDNET
1761 char decnethost[80];
1762#endif
1763#ifdef SUPPORT_PIDFILE
1764 struct roar_vio_calls pidfile_vio;
1765#endif
1766
1767 ROAR_DBG("main(*): starting roard...");
1768
1769 g_standby       =  0;
1770 g_autostandby   =  0;
1771 alive           =  1;
1772#ifdef ROAR_SUPPORT_LISTEN
1773 g_no_listen     =  0;
1774#else
1775 g_terminate     =  1;
1776#endif
1777
1778 g_verbose       = ROAR_DBG_INFO_NONE;
1779
1780 sa.bits     = ROAR_BITS_DEFAULT;
1781 sa.channels = ROAR_CHANNELS_DEFAULT;
1782 sa.rate     = ROAR_RATE_DEFAULT;
1783 sa.codec    = ROAR_CODEC_DEFAULT;
1784
1785 g_sa        = &sa;
1786 g_max_sa    = &max_sa;
1787
1788 memcpy(g_max_sa, g_sa, sizeof(max_sa));
1789
1790 counters_init();
1791
1792 g_config = &config;
1793
1794 if ( init_config() == -1 ) {
1795  ROAR_ERR("Can not init default config!");
1796  return 1;
1797 }
1798
1799 // load config
1800 roar_libroar_get_config();
1801
1802 // init notify core:
1803 // TODO: reconsider number of lists.
1804 if ( roar_notify_core_new_global(-1) == -1 ) {
1805  ROAR_ERR("Can not init notify core!");
1806  return 1;
1807 }
1808
1809 if ( roar_notify_core_register_proxy(NULL, roar_notify_proxy_std, NULL) == -1 ) {
1810  ROAR_ERR("Can not init notify core!");
1811  return 1;
1812 }
1813
1814#ifdef DEBUG
1815 // enable early in case we have DEBUG set.
1816 dbg_notify_cb_register();
1817#endif
1818
1819 if ( auth_init() == -1 ) {
1820  ROAR_ERR("Can not init auth subsystem!");
1821  return 1;
1822 }
1823
1824#ifdef ROAR_SUPPORT_LISTEN
1825 if ( init_listening() == -1 ) {
1826  ROAR_ERR("Can not init listening sockets!");
1827  return 1;
1828 }
1829#endif
1830
1831#ifndef ROAR_WITHOUT_DCOMP_MIDI
1832 if ( midi_init_config() == -1 ) {
1833  ROAR_ERR("Can not init MIDI config!");
1834  return 1;
1835 }
1836#endif
1837
1838#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
1839 if ( ssynth_init_config() == -1 ) {
1840  ROAR_ERR("Can not init ssynth config!");
1841  return 1;
1842 }
1843#endif
1844
1845#ifndef ROAR_WITHOUT_DCOMP_RDTCS
1846 if ( rdtcs_init_config() == -1 ) {
1847  ROAR_ERR("Can not init RDTCS config!");
1848  return 1;
1849 }
1850#endif
1851
1852 if ( plugins_preinit() == -1 ) {
1853  ROAR_ERR("Can not pre-init plugins!");
1854  return 1;
1855 }
1856
1857#ifdef ROAR_SUPPORT_LISTEN
1858#ifndef ROAR_TARGET_WIN32
1859 sock_addr = ROAR_DEFAULT_SOCK_GLOBAL;
1860#else
1861 sock_addr = ROAR_DEFAULT_HOST;
1862#endif
1863
1864#ifdef ROAR_HAVE_GETUID
1865 if ( getuid() != 0 && getenv("HOME") != NULL ) {
1866/*
1867  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
1868*/
1869  roar_env_render_path_r(user_sock, sizeof(user_sock), "~/" ROAR_DEFAULT_SOCK_USER);
1870  sock_addr = user_sock;
1871  ROAR_DBG("main(*): setting sock_addr='%s'", sock_addr);
1872 }
1873#endif
1874
1875 if ( getenv("ROAR_SERVER") != NULL )
1876  sock_addr = getenv("ROAR_SERVER");
1877#endif
1878
1879 if ( clients_init() == -1 ) {
1880  ROAR_ERR("Can not init clients!");
1881  return 1;
1882 }
1883
1884 if ( streams_init() == -1 ) {
1885  ROAR_ERR("Can not init streams!");
1886  return 1;
1887 }
1888
1889 if ( (g_self_client = clients_new()) == -1 ) {
1890  ROAR_ERR("Can not create self client!");
1891  return 1;
1892 }
1893
1894#ifndef ROAR_WITHOUT_DCOMP_SOURCES
1895 if ( sources_init() == -1 ) {
1896  ROAR_ERR("Can not init sources!");
1897  return 1;
1898 }
1899
1900 if ( (sources_set_client(g_self_client)) == -1 ) {
1901  ROAR_ERR("Can not init set source client!");
1902  return 1;
1903 }
1904#endif
1905
1906#ifdef ROAR_HAVE_MAIN_ARGS
1907 for (i = 1; i < argc; i++) {
1908  k = argv[i];
1909
1910  if ( strcmp(k, "-h") == 0 || strcmp(k, "--help") == 0 ) {
1911   usage();
1912   return 0;
1913
1914  } else if ( strcmp(k, "--start") == 0 ) {
1915   // this is a no op
1916   action = START;
1917  } else if ( strcmp(k, "--restart") == 0 ) {
1918   action = RESTART;
1919#ifdef ROAR_SUPPORT_LISTEN
1920   if ( restart_server(sock_addr, 1) == -1 ) {
1921    ROAR_WARN("Can not terminate old server (not running at %s?), will retry later.", sock_addr);
1922    action = RESTART_RETRY;
1923   }
1924#else
1925   ROAR_ERR("--restart not supported");
1926#endif
1927  } else if ( strcmp(k, "--shutdown") == 0 ) {
1928   action = SHUTDOWN;
1929  } else if ( strcmp(k, "--stop") == 0 ) {
1930   action = STOP;
1931
1932
1933  } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
1934#ifdef ROAR_HAVE_FORK
1935   daemon = 1;
1936#else
1937   ROAR_ERR("--daemon not supported");
1938#endif
1939  } else if ( strcmp(k, "--verbose") == 0 ) {
1940   g_verbose++;
1941  } else if ( strcmp(k, "--terminate") == 0 ) {
1942   g_terminate = 1;
1943  } else if ( strcmp(k, "--sysclocksync") == 0 ) {
1944   sysclocksync = 1000;
1945  } else if ( strcmp(k, "--realtime") == 0 ) {
1946   realtime++;
1947  } else if ( strcmp(k, "--memlock") == 0 ) {
1948   _CKHAVEARGS(1);
1949   g_config->memlock_level = memlock_str2level(argv[++i]);
1950  } else if ( strcmp(k, "--chroot") == 0 ) {
1951   _CKHAVEARGS(1);
1952#ifdef ROAR_HAVE_CHROOT
1953   chrootdir = argv[++i];
1954#else
1955   ROAR_ERR("--chroot not supported");
1956   i++;
1957#endif
1958  } else if ( strcmp(k, "--setgid") == 0 ) {
1959#ifdef ROAR_HAVE_SETGID
1960   setids |= R_SETGID;
1961#else
1962   ROAR_ERR("--setgid not supported");
1963#endif
1964  } else if ( strcmp(k, "--setuid") == 0 ) {
1965#ifdef ROAR_HAVE_SETUID
1966   setids |= R_SETUID;
1967#else
1968   ROAR_ERR("--setuid not supported");
1969#endif
1970  } else if ( strcmp(k, "--location") == 0 ) {
1971   _CKHAVEARGS(1);
1972   g_config->location = argv[++i];
1973  } else if ( strcmp(k, "--description") == 0 ) {
1974   _CKHAVEARGS(1);
1975   g_config->description = argv[++i];
1976  } else if ( strcmp(k, "--pidfile") == 0 ) {
1977   _CKHAVEARGS(1);
1978#ifdef SUPPORT_PIDFILE
1979   pidfile = argv[++i];
1980#else
1981   ROAR_ERR("--pidfile not supported");
1982   i++;
1983#endif
1984  } else if ( strcmp(k, "--log-syslog") == 0 ) {
1985#ifdef ROAR_HAVE_SYSLOG
1986   roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
1987#else
1988   ROAR_ERR("--log-syslog not supported");
1989#endif
1990
1991
1992  } else if ( strcmp(k, "--plugin-load") == 0 ) {
1993   _CKHAVEARGS(1);
1994   if ( plugins_load(argv[++i]) == -1 ) {
1995    ROAR_ERR("Can not load plugin");
1996   }
1997
1998  } else if ( strcmp(k, "--guest-acclev") == 0 ) {
1999   _CKHAVEARGS(1);
2000   none_acclev = clients_str2acclev(argv[++i]);
2001  } else if ( strcmp(k, "--trust-acclev") == 0 ) {
2002   _CKHAVEARGS(1);
2003   trust_acclev = clients_str2acclev(argv[++i]);
2004  } else if ( strcmp(k, "--trust-root") == 0 ) {
2005   trust_root = 1;
2006  } else if ( strcmp(k, "--no-trust-root") == 0 ) {
2007   trust_root = 0;
2008
2009  } else if ( strcmp(k, "--authfile-gen") == 0 ) {
2010   _CKHAVEARGS(1);
2011   af_file = argv[++i];
2012   af_mode = AF_MODE_GEN;
2013  } else if ( strcmp(k, "--authfile-load") == 0 ) {
2014   _CKHAVEARGS(1);
2015   af_file = argv[++i];
2016   af_mode = AF_MODE_LOAD;
2017  } else if ( strcmp(k, "--authfile-type") == 0 ) {
2018   _CKHAVEARGS(1);
2019   af_type = argv[++i];
2020  } else if ( strcmp(k, "--authfile-acclev") == 0 ) {
2021   _CKHAVEARGS(1);
2022   af_acclev = clients_str2acclev(argv[++i]);
2023  } else if ( strcmp(k, "--new-authfile") == 0 ) {
2024   if ( af_mode != AF_MODE_NONE ) {
2025    if ( add_authfile(af_file, af_type, af_mode, af_acclev) == -1 ) {
2026     ROAR_ERR("main(*): adding authfile '%s' failed!", af_file);
2027    }
2028   }
2029   af_file   = NULL;
2030   af_type   = NULL;
2031   af_mode   = AF_MODE_NONE;
2032   af_acclev = ACCLEV_ALL;
2033
2034  } else if ( strcmp(k, "--list-cf") == 0 ) {
2035   print_codecfilterlist();
2036   return 0;
2037
2038  } else if ( strcmp(k, "-R") == 0 || strcmp(k, "--rate") == 0 ) {
2039   _CKHAVEARGS(1);
2040   sa.rate = atoi(argv[++i]);
2041  } else if ( strcmp(k, "-B") == 0 || strcmp(k, "--bits") == 0 ) {
2042   _CKHAVEARGS(1);
2043   sa.bits = atoi(argv[++i]);
2044  } else if ( strcmp(k, "-C") == 0 || strcmp(k, "--chans") == 0 ) {
2045   _CKHAVEARGS(1);
2046   sa.channels = atoi(argv[++i]);
2047
2048  } else if ( strcmp(k, "--aiprofile") == 0 ) {
2049   _CKHAVEARGS(1);
2050   if ( roar_profile2info(&sa, argv[++i]) == -1 ) {
2051    ROAR_ERR("Unknown audio profile: %s", argv[i]);
2052    return 1;
2053   }
2054   sa.codec    = ROAR_CODEC_DEFAULT;
2055
2056  } else if ( strcmp(k, "--stream-flags") == 0 ) {
2057   _CKHAVEARGS(1);
2058   if ( update_stream_flags(argv[++i]) == -1 ) {
2059    ROAR_ERR("Can not set stream flags");
2060    return 1;
2061   }
2062
2063  } else if ( strcmp(k, "--list-driver") == 0 ) {
2064   print_driverlist();
2065   return 0;
2066
2067  } else if ( strcmp(k, "-o") == 0 || strcmp(k, "--odriver") == 0 ) {
2068   _CKHAVEARGS(1);
2069   o_drv  = argv[++i];
2070  } else if ( strcmp(k, "-O") == 0 || strcmp(k, "--odevice") == 0 ) {
2071   _CKHAVEARGS(1);
2072   o_dev  = argv[++i];
2073  } else if ( strcmp(k, "-oO") == 0 ) {
2074   _CKHAVEARGS(1);
2075   o_opts = argv[++i];
2076  } else if ( strcmp(k, "-oP") == 0 ) {
2077   o_prim = 1;
2078  } else if ( strcmp(k, "-oN") == 0 ) {
2079   if ( action == START || action == RESTART ) {
2080    if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 )
2081     o_count++;
2082
2083    o_drv  = o_dev = o_opts = NULL;
2084    o_prim = 0;
2085   }
2086
2087  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) {
2088   _CKHAVEARGS(1);
2089#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2090   s_drv = argv[++i];
2091#else
2092   ROAR_ERR("main(*): No support for sources compiled in");
2093   i++;
2094#endif
2095  } else if ( strcmp(k, "-S") == 0 ) {
2096   _CKHAVEARGS(1);
2097#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2098   s_dev = argv[++i];
2099#else
2100   ROAR_ERR("main(*): No support for sources compiled in");
2101   i++;
2102#endif
2103  } else if ( strcmp(k, "-sO") == 0 ) {
2104   _CKHAVEARGS(1);
2105#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2106   s_opt = argv[++i];
2107#else
2108   ROAR_ERR("main(*): No support for sources compiled in");
2109   i++;
2110#endif
2111  } else if ( strcmp(k, "-sC") == 0 ) {
2112   _CKHAVEARGS(1);
2113#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2114   s_con = argv[++i];
2115#else
2116   ROAR_ERR("main(*): No support for sources compiled in");
2117   i++;
2118#endif
2119  } else if ( strcmp(k, "-sP") == 0 ) {
2120#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2121   s_prim = 1;
2122#else
2123   ROAR_ERR("main(*): No support for sources compiled in");
2124#endif
2125  } else if ( strcmp(k, "-sN") == 0 ) {
2126#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2127   if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
2128    ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
2129   }
2130   s_opt = s_dev = s_con = NULL;
2131   s_drv = "cf";
2132   s_prim = 0;
2133#else
2134   ROAR_ERR("main(*): No support for sources compiled in");
2135#endif
2136  } else if ( strcmp(k, "--list-sources") == 0 ) {
2137#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2138   print_sourcelist();
2139   return 0;
2140#else
2141   ROAR_ERR("main(*): No support for sources compiled in");
2142   return 1;
2143#endif
2144
2145  } else if ( strcmp(k, "-m") == 0 || strcmp(k, "--mixer") == 0 ) {
2146   _CKHAVEARGS(1);
2147#ifndef ROAR_WITHOUT_DCOMP_MIXER
2148   m_drv  = argv[++i];
2149#else
2150   ROAR_ERR("main(*): No support for mixer compiled in");
2151   return 1;
2152#endif
2153  } else if ( strcmp(k, "-M") == 0 ) {
2154   _CKHAVEARGS(1);
2155#ifndef ROAR_WITHOUT_DCOMP_MIXER
2156   m_dev  = argv[++i];
2157#else
2158   ROAR_ERR("main(*): No support for mixer compiled in");
2159   return 1;
2160#endif
2161  } else if ( strcmp(k, "-mO") == 0 ) {
2162   _CKHAVEARGS(1);
2163#ifndef ROAR_WITHOUT_DCOMP_MIXER
2164   m_opts = argv[++i];
2165#else
2166   ROAR_ERR("main(*): No support for mixer compiled in");
2167   return 1;
2168#endif
2169  } else if ( strcmp(k, "-mP") == 0 ) {
2170#ifndef ROAR_WITHOUT_DCOMP_MIXER
2171   m_prim = 1;
2172#else
2173   ROAR_ERR("main(*): No support for mixer compiled in");
2174   return 1;
2175#endif
2176  } else if ( strcmp(k, "-mN") == 0 ) {
2177#ifndef ROAR_WITHOUT_DCOMP_MIXER
2178   if ( add_hwmixer(m_drv, m_dev, m_opts, m_prim, m_count) != -1 )
2179    m_count++;
2180
2181   m_drv  = o_dev = o_opts = NULL;
2182   m_prim = 0;
2183#else
2184   ROAR_ERR("main(*): No support for mixer compiled in");
2185   return 1;
2186#endif
2187  } else if ( strcmp(k, "--list-mixers") == 0 ) {
2188#ifndef ROAR_WITHOUT_DCOMP_MIXER
2189   print_hwmixerlist();
2190   return 0;
2191#else
2192   ROAR_ERR("main(*): No support for mixer compiled in");
2193   return 1;
2194#endif
2195
2196  } else if ( strcmp(k, "--light-channels") == 0 ) {
2197   _CKHAVEARGS(1);
2198#ifndef ROAR_WITHOUT_DCOMP_LIGHT
2199   light_channels = atoi(argv[++i]);
2200#else
2201   ROAR_WARN("main(*): no light subsystem compiled in");
2202   i++;
2203#endif
2204
2205  } else if ( strcmp(k, "--rds-pi") == 0 ) {
2206   _CKHAVEARGS(1);
2207#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2208   g_rdtcs.rds.pi = atoi(argv[++i]);
2209#else
2210   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2211   i++;
2212#endif
2213  } else if ( strcmp(k, "--rds-ps") == 0 ) {
2214   _CKHAVEARGS(1);
2215#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2216   if ( rdtcs_rds_set_ps(argv[++i]) == -1 ) {
2217    ROAR_ERR("Can not set RDS PS to '%s' (longer than 8 chars?)", argv[i]);
2218    return 1;
2219   }
2220#else
2221   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2222   i++;
2223#endif
2224  } else if ( strcmp(k, "--rds-pty") == 0 ) {
2225   _CKHAVEARGS(1);
2226#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2227   if ( rdtcs_rds_set_pty(argv[++i]) == -1 ) {
2228    ROAR_ERR("Can not set RDS PTY to '%s'", argv[i]);
2229    return 1;
2230   }
2231#else
2232   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2233   i++;
2234#endif
2235  } else if ( strcmp(k, "--rds-tp") == 0 ) {
2236#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2237   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_TP, 0) == -1 ) {
2238    ROAR_ERR("Can not set RDS TP flag");
2239    return 1;
2240   }
2241#else
2242   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2243#endif
2244  } else if ( strcmp(k, "--rds-ct") == 0 ) {
2245#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2246   if ( rdtcs_rds_set_flag(RDTCS_RDS_FLAG_CT, 0) == -1 ) {
2247    ROAR_ERR("Can not set RDS CT flag");
2248    return 1;
2249   }
2250#else
2251   ROAR_WARN("main(*): no RDTCS subsystem compiled in");
2252#endif
2253
2254
2255  } else if ( strcmp(k, "--midi-no-console") == 0 ) {
2256#ifndef ROAR_WITHOUT_DCOMP_CB
2257   midi_config.init_cb = 0;
2258#else
2259   // no warning here as this is the disable option
2260#endif
2261  } else if ( strcmp(k, "--midi-console-enable") == 0 ) {
2262#ifndef ROAR_WITHOUT_DCOMP_CB
2263   midi_config.init_cb = 1;
2264#else
2265   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
2266#endif
2267  } else if ( strcmp(k, "--midi-console") == 0 ) {
2268   _CKHAVEARGS(1);
2269#ifndef ROAR_WITHOUT_DCOMP_CB
2270   midi_config.console_dev = argv[++i];
2271   midi_config.init_cb = 1;
2272#else
2273   ROAR_ERR("main(*): No support for MIDI subsystem part CB compiled in");
2274   i++;
2275#endif
2276
2277  } else if ( strcmp(k, "--ssynth-enable") == 0 ) {
2278#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
2279   ssynth_conf.enable = 1;
2280#else
2281   ROAR_ERR("main(*): No support for ssynth compiled in");
2282#endif
2283  } else if ( strcmp(k, "--ssynth-disable") == 0 ) {
2284#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
2285   ssynth_conf.enable = 0;
2286#else
2287   // we can safely ignore the disable
2288#endif
2289
2290  } else if ( strcmp(k, "--x11-display") == 0 || strcmp(k, "--display") == 0 ) {
2291   _CKHAVEARGS(1);
2292#ifdef ROAR_HAVE_LIBX11
2293   x11display = argv[++i];
2294#else
2295   ROAR_ERR("No X11 support compiled in!");
2296   return 1;
2297#endif
2298
2299
2300  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--port") == 0 ) {
2301   _CKHAVEARGS(1);
2302   // This is only useful in INET not UNIX mode.
2303#ifdef ROAR_SUPPORT_LISTEN
2304   if ( *sock_addr == '/' )
2305    sock_addr = ROAR_DEFAULT_HOST;
2306
2307   errno = 0;
2308   if ( (port = atoi(argv[++i])) < 1 ) {
2309#ifdef ROAR_HAVE_GETSERVBYNAME
2310    if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
2311     ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
2312     return 1;
2313    }
2314    // NOTE: we need to use ROAR_NET2HOST16() here even if s_port is of type int!
2315    ROAR_DBG("main(*): serv = {s_name='%s', s_aliases={...}, s_port=%i, s_proto='%s'}",
2316            serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
2317    port = ROAR_NET2HOST16(serv->s_port);
2318#else
2319    ROAR_ERR("invalite port number: %s", argv[i]);
2320    return 1;
2321#endif
2322   }
2323#endif
2324  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
2325   _CKHAVEARGS(1);
2326#ifdef ROAR_SUPPORT_LISTEN
2327   sock_addr = argv[++i];
2328#else
2329   i++;
2330#endif
2331
2332  } else if ( strcmp(k, "--proto") == 0 ) {
2333#ifdef ROAR_SUPPORT_LISTEN
2334   if ( (sock_proto = roar_str2proto(argv[++i])) == -1 ) {
2335    ROAR_ERR("Unknown protocol: %s", argv[i]);
2336    return 1;
2337   }
2338#endif
2339  } else if ( strcmp(k, "--proto-dir") == 0 ) {
2340   _CKHAVEARGS(1);
2341#ifdef ROAR_SUPPORT_LISTEN
2342   if ( (sock_dir = roar_str2dir(argv[++i])) == -1 ) {
2343    ROAR_ERR("Unknown stream direction: %s", argv[i]);
2344    return 1;
2345   }
2346#else
2347   i++;
2348#endif
2349  } else if ( strcmp(k, "--proto-rate") == 0 ) {
2350   _CKHAVEARGS(1);
2351#ifdef ROAR_SUPPORT_LISTEN
2352   sock_info.rate = atoi(argv[++i]);
2353#else
2354   i++;
2355#endif
2356  } else if ( strcmp(k, "--proto-bits") == 0 ) {
2357   _CKHAVEARGS(1);
2358#ifdef ROAR_SUPPORT_LISTEN
2359   sock_info.bits = atoi(argv[++i]);
2360#else
2361   i++;
2362#endif
2363  } else if ( strcmp(k, "--proto-chans") == 0 ) {
2364   _CKHAVEARGS(1);
2365#ifdef ROAR_SUPPORT_LISTEN
2366   sock_info.channels = atoi(argv[++i]);
2367#else
2368   i++;
2369#endif
2370  } else if ( strcmp(k, "--proto-codec") == 0 ) {
2371   _CKHAVEARGS(1);
2372#ifdef ROAR_SUPPORT_LISTEN
2373   if ( (sock_info.codec = roar_str2codec(argv[++i])) == -1 ) {
2374    ROAR_ERR("Unknown codec: %s", argv[i]);
2375    return 1;
2376   }
2377#else
2378   i++;
2379#endif
2380  } else if ( strcmp(k, "--proto-aiprofile") == 0 ) {
2381   _CKHAVEARGS(1);
2382#ifdef ROAR_SUPPORT_LISTEN
2383   if ( roar_profile2info(&sock_info, argv[++i]) == -1 ) {
2384    ROAR_ERR("Unknown audio profile: %s", argv[i]);
2385    return 1;
2386   }
2387#else
2388   i++;
2389#endif
2390  } else if ( strcmp(k, "--list-profiles") == 0 ) {
2391#ifdef ROAR_SUPPORT_LISTEN
2392   listen_listen_profiles();
2393   return 0;
2394#endif
2395  } else if ( strcmp(k, "--proto-profile") == 0 ) {
2396   _CKHAVEARGS(1);
2397#ifdef ROAR_SUPPORT_LISTEN
2398   if ( get_listen_profile(argv[++i], &port, &sock_addr, &sock_type, &sock_proto, &sock_dir, &sock_info) == -1 ) {
2399    ROAR_ERR("Unknown listen profile: %s", argv[i]);
2400    return 1;
2401   }
2402#else
2403   i++;
2404#endif
2405
2406
2407  } else if ( strcmp(k, "--list-proto") == 0 ) {
2408   list_proto();
2409   return 0;
2410
2411  } else if ( strcmp(k, "-t") == 0 || strcmp(k, "--tcp") == 0 ) {
2412#ifdef ROAR_SUPPORT_LISTEN
2413   if ( sock_type != ROAR_SOCKET_TYPE_TCP && sock_type != ROAR_SOCKET_TYPE_TCP6 )
2414    sock_type = ROAR_SOCKET_TYPE_TCP;
2415
2416   if ( *sock_addr == '/' )
2417    sock_addr = ROAR_DEFAULT_HOST;
2418#endif
2419
2420  } else if ( strcmp(k, "-4") == 0 ) {
2421#ifdef ROAR_SUPPORT_LISTEN
2422   sock_type = ROAR_SOCKET_TYPE_TCP;
2423   if ( *sock_addr == '/' )
2424    sock_addr = ROAR_DEFAULT_HOST;
2425#endif
2426  } else if ( strcmp(k, "-6") == 0 ) {
2427#ifdef ROAR_SUPPORT_LISTEN
2428#ifdef AF_INET6
2429   sock_type = ROAR_SOCKET_TYPE_TCP6;
2430   if ( *sock_addr == '/' )
2431    sock_addr = ROAR_DEFAULT_HOST;
2432#else
2433    ROAR_ERR("No IPv6 support compiled in!");
2434    return 1;
2435#endif
2436#endif
2437
2438  } else if ( strcmp(k, "-u") == 0 || strcmp(k, "--unix") == 0 ) {
2439#ifdef ROAR_SUPPORT_LISTEN
2440   // ignore this case as it is the default behavor.
2441   sock_type = ROAR_SOCKET_TYPE_UNIX;
2442#endif
2443
2444  } else if ( strcmp(k, "-n") == 0 || strcmp(k, "--decnet") == 0 ) {
2445#ifdef ROAR_SUPPORT_LISTEN
2446#ifdef ROAR_HAVE_LIBDNET
2447    port   = ROAR_DEFAULT_NUM;
2448    strcpy(decnethost, ROAR_DEFAULT_LISTEN_OBJECT);
2449    sock_addr = decnethost;
2450    sock_type = ROAR_SOCKET_TYPE_DECNET;
2451#else
2452    ROAR_ERR("No DECnet support compiled in!");
2453    return 1;
2454#endif
2455#endif
2456  } else if ( strcmp(k, "--new-sock") == 0 ) {
2457#ifdef ROAR_SUPPORT_LISTEN
2458   if ( action == START || action == RESTART ) {
2459    if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
2460     ROAR_ERR("Can not open listen socket!");
2461     return 1;
2462    }
2463   }
2464#endif
2465
2466  } else if ( strcmp(k, "--slp") == 0 ) {
2467#ifdef ROAR_HAVE_LIBSLP
2468   reg_slp = 1;
2469#else
2470   ROAR_ERR("No OpenSLP support compiled in!");
2471   return 1;
2472#endif
2473
2474  } else if ( strcmp(k, "--x11") == 0 ) {
2475#ifdef ROAR_HAVE_LIBX11
2476   reg_x11 = 1;
2477#else
2478   ROAR_ERR("No X11 support compiled in!");
2479   return 1;
2480#endif
2481
2482
2483  } else if ( strcmp(k, "--jumbo-mtu") == 0 ) {
2484   _CKHAVEARGS(1);
2485   g_config->jumbo_mtu = atoi(argv[++i]);
2486
2487  } else if ( strcmp(k, "-G") == 0 ) {
2488   _CKHAVEARGS(1);
2489   sock_grp  = argv[++i];
2490  } else if ( strcmp(k, "-U") == 0 ) {
2491   _CKHAVEARGS(1);
2492   sock_user = argv[++i];
2493
2494  } else if ( strcmp(k, "--no-listen") == 0 ) {
2495#ifdef ROAR_SUPPORT_LISTEN
2496   sock_addr   = "";
2497   g_terminate = 1;
2498   g_no_listen = 1;
2499#endif
2500  } else if ( strcmp(k, "--client-fh") == 0 ) {
2501   _CKHAVEARGS(1);
2502   if ( clients_new_from_fh(atoi(argv[++i]), ROAR_PROTO_ROARAUDIO, ROAR_BYTEORDER_NETWORK, 1) == -1 ) {
2503    ROAR_ERR("main(*): Can not set client's fh");
2504    return 1;
2505   }
2506  } else if ( strcmp(k, "--close-fh") == 0 ) {
2507   _CKHAVEARGS(1);
2508#ifdef ROAR_HAVE_IO_POSIX
2509   close(atoi(argv[++i]));
2510#else
2511   i++;
2512   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
2513#endif
2514
2515  } else if ( strcmp(k, "--standby") == 0 ) {
2516   g_standby = 1;
2517  } else if ( strcmp(k, "--auto-standby") == 0 ) {
2518   g_autostandby = 1;
2519  } else {
2520   usage();
2521   return 1;
2522  }
2523
2524 }
2525#endif
2526
2527#ifdef ROAR_HAVE_MAIN_ARGS
2528 switch (action) {
2529  case START:
2530    // NO-OP.
2531   break;
2532  case RESTART:
2533    // NO-OP, done before.
2534   break;
2535  case STOP:
2536#ifdef ROAR_SUPPORT_LISTEN
2537    if ( restart_server(sock_addr, 0) == -1 ) {
2538     ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr);
2539     return 1;
2540    }
2541    return 0;
2542#else
2543    ROAR_ERR("--stop not supported");
2544    return 1;
2545#endif
2546   break;
2547  case SHUTDOWN:
2548#ifdef ROAR_SUPPORT_LISTEN
2549    if ( restart_server(sock_addr, 1) == -1 ) {
2550     ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr);
2551     return 1;
2552    }
2553    return 0;
2554#else
2555    ROAR_ERR("--shutdown not supported");
2556    return 1;
2557#endif
2558   break;
2559  case RESTART_RETRY:
2560#ifdef ROAR_SUPPORT_LISTEN
2561    if ( restart_server(sock_addr, 1) == -1 ) {
2562     ROAR_WARN("Can not terminate old server (again) (not running at %s?), tring to continue anyway", sock_addr);
2563     action = RESTART;
2564    }
2565#endif
2566   break;
2567 }
2568#endif
2569
2570#ifndef DEBUG
2571 // notify dbg if requested, if in DEBUG mode
2572 // do not able because it got enabled early.
2573 if ( g_verbose >= 4 )
2574  dbg_notify_cb_register();
2575#endif
2576
2577 if ( af_mode != AF_MODE_NONE ) {
2578  if ( add_authfile(af_file, af_type, af_mode, af_acclev) == -1 ) {
2579   ROAR_ERR("main(*): adding authfile '%s' failed!", af_file);
2580  }
2581 }
2582
2583#ifndef ROAR_WITHOUT_DCOMP_MIXER
2584 if ( m_drv != NULL ) {
2585  if ( add_hwmixer(m_drv, m_dev, m_opts, m_prim, m_count) == -1 ) {
2586   ROAR_ERR("main(*): adding mixer '%s' via '%s' failed!", m_dev, m_drv);
2587  }
2588 }
2589#endif
2590
2591#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2592 if ( s_dev != NULL ) {
2593  if ( sources_add(s_drv, s_dev, s_con, s_opt, s_prim) == -1 ) {
2594   ROAR_ERR("main(*): adding source '%s' via '%s' failed!", s_dev, s_drv);
2595  }
2596 }
2597#endif
2598
2599 add_default_output(o_drv, o_dev, o_opts, o_prim, o_count);
2600
2601 ROAR_INFO("Server config: rate=%i, bits=%i, chans=%i", ROAR_DBG_INFO_NOTICE, sa.rate, sa.bits, sa.channels);
2602
2603 if ( waveform_init() == -1 ) {
2604  ROAR_ERR("Can not initialize Waveform subsystem");
2605  return 1;
2606 }
2607
2608#ifndef ROAR_WITHOUT_DCOMP_MIDI
2609 if ( midi_init() == -1 ) {
2610  ROAR_ERR("Can not initialize MIDI subsystem");
2611 }
2612#endif
2613
2614#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
2615 if ( ssynth_init() == -1 ) {
2616  ROAR_ERR("Can not initialize ssynth subsystem");
2617 }
2618#endif
2619
2620#ifndef ROAR_WITHOUT_DCOMP_LIGHT
2621 if ( light_init(light_channels) == -1 ) {
2622  ROAR_ERR("Can not initialize light control subsystem");
2623 }
2624#endif
2625
2626#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2627 if ( rdtcs_init() == -1 ) {
2628  ROAR_ERR("Can not initialize RDTCS subsystem");
2629 }
2630#endif
2631
2632 if ( plugins_init() == -1 ) {
2633  ROAR_ERR("Can not initialize plugins");
2634 }
2635
2636#ifdef ROAR_SUPPORT_LISTEN
2637 if ( !g_no_listen ) {
2638  if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) {
2639   ROAR_ERR("Can not open listen socket!");
2640   return 1;
2641  }
2642 }
2643#endif
2644
2645 if ( output_buffer_init(&sa) == -1 ) {
2646  ROAR_ERR("Can not init output buffer!");
2647  return 1;
2648 }
2649
2650 if ( samples_init() == -1 ) {
2651  ROAR_ERR("Can not init samples!");
2652  return 1;
2653 }
2654
2655
2656 // we should handle this on microcontrollers, too.
2657#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_TARGET_WIN32)
2658 signal(SIGINT,  on_sig_int);
2659 signal(SIGTERM, on_sig_term);
2660 signal(SIGCHLD, on_sig_chld);
2661 signal(SIGUSR1, on_sig_usr1);
2662 signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
2663#endif
2664
2665 if ( g_config->memlock_level == -1 ) {
2666  g_config->memlock_level = MEMLOCK_DEFAULT;
2667 }
2668
2669 if ( memlock_set_level(g_config->memlock_level) == -1 ) {
2670  ROAR_WARN("Can not set memory locking level to target level.");
2671 }
2672
2673 if ( realtime ) {
2674#ifdef DEBUG
2675  ROAR_WARN("compiled with -DDEBUG but realtime is enabled: for real realtime support compile without -DDEBUG");
2676#endif
2677
2678#ifdef ROAR_HAVE_NICE
2679  // this stupid error check is because type of returned data of nice() changed
2680  // too often. On some systems it may return 0/-1, on some new nice value or
2681  // mixed forms of both.
2682  errno = 0;
2683  (void)nice(-5*realtime); // -5 for each --realtime
2684  if ( errno ) {
2685   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
2686  }
2687#else
2688  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
2689#endif
2690/*
2691#ifdef __linux__
2692  if ( ioprio_set(IOPRIO_WHO_PROCESS, getpid(), IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0)) == -1 )
2693   ROAR_WARN("Can not set io priority: %s", strerror(errno));
2694#endif
2695*/
2696 }
2697
2698#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
2699 if ( setids & R_SETGID ) {
2700  if ( sock_grp == NULL ) {
2701   ROAR_ERR("Can not set GID if no groupname is supplied");
2702   return 1;
2703  }
2704  if ( (grp = getgrnam(sock_grp)) == NULL ) {
2705   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
2706   return 1;
2707  }
2708  if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
2709   ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno));
2710  }
2711  if ( !grp || setgid(grp->gr_gid) == -1 ) {
2712   ROAR_ERR("Can not set GroupID: %s", strerror(errno));
2713  }
2714 }
2715#endif
2716
2717
2718 clients_set_pid(g_self_client, getpid());
2719#ifdef ROAR_HAVE_GETUID
2720 clients_set_uid(g_self_client, getuid());
2721#endif
2722#ifdef ROAR_HAVE_GETGID
2723 clients_set_gid(g_self_client, getgid());
2724#endif
2725 clients_get(g_self_client, &self);
2726
2727 if ( self == NULL ) {
2728  ROAR_ERR("Can not get self client!");
2729  return 1;
2730 }
2731
2732 strcpy(self->name, "RoarAudio daemon internal");
2733
2734 if ( roar_nnode_free(&(self->nnode)) == -1 )
2735  return 1;
2736
2737 // not fully correct but ok as workaorund
2738 // so tools assume that roard runs on the same machine as
2739 // they in case they use AF_UNIX:
2740 if ( roar_nnode_new(&(self->nnode), ROAR_SOCKET_TYPE_UNIX) == -1 )
2741  return 1;
2742
2743#ifdef ROAR_HAVE_FORK
2744 if ( daemon ) {
2745#ifdef ROAR_HAVE_SYSLOG
2746  roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG);
2747#else
2748  roar_debug_set_stderr_fh(-1);
2749#endif
2750
2751  close(ROAR_STDIN );
2752  close(ROAR_STDOUT);
2753  close(ROAR_STDERR);
2754
2755  if ( fork() )
2756   ROAR_U_EXIT(0);
2757
2758#ifdef ROAR_HAVE_SETSID
2759  setsid();
2760#endif
2761  clients_set_pid(g_self_client, getpid()); // reset pid as it changed
2762 }
2763#endif
2764
2765#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
2766 // early test for UID as we need this for the pidfile and the setuid()
2767 if ( sock_user != NULL ) {
2768  if ( (pwd = getpwnam(sock_user)) == NULL ) {
2769   ROAR_ERR("Can not get UID for user %s: %s", sock_user, strerror(errno));
2770   return 1;
2771  }
2772 }
2773#endif
2774
2775 ROAR_INFO("Process ID: %i", ROAR_DBG_INFO_INFO, (int)getpid());
2776
2777#ifdef SUPPORT_PIDFILE
2778 if ( pidfile != NULL ) {
2779  if ( roar_vio_open_file(&pidfile_vio, pidfile, O_WRONLY|O_CREAT, 0644) == -1 ) {
2780   ROAR_ERR("Can not write pidfile: %s", pidfile);
2781  } else {
2782   roar_vio_printf(&pidfile_vio, "%i\n", getpid());
2783   roar_vio_close(&pidfile_vio);
2784  }
2785#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
2786  if ( pwd || grp ) {
2787   if ( chown(pidfile, pwd ? pwd->pw_uid : -1, grp ? grp->gr_gid : -1) == -1 ) {
2788    ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno));
2789   }
2790  }
2791  if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) {
2792   ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno));
2793  }
2794#endif
2795 }
2796#endif
2797
2798#ifdef ROAR_HAVE_CHROOT
2799 if (chrootdir) {
2800  if ( chroot(chrootdir) == -1 ) {
2801   ROAR_ERR("Can not chroot to %s: %s", chrootdir, strerror(errno));
2802   return 2;
2803  }
2804  if ( chdir("/") == -1 ) {
2805   ROAR_ERR("Can not chdir to /: %s", strerror(errno));
2806   return 2;
2807  }
2808 }
2809#endif
2810
2811#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
2812 if ( setids & R_SETUID ) {
2813  if ( sock_user == NULL ) {
2814   ROAR_ERR("Can not set UID if no username is supplied");
2815   return 1;
2816  }
2817  if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
2818   ROAR_ERR("Can not set UserID: %s", strerror(errno));
2819   return 3;
2820  }
2821#ifdef ROAR_HAVE_GETUID
2822  clients_set_uid(g_self_client, getuid());
2823#endif
2824 }
2825#endif
2826
2827 // setup auth:
2828#if defined(ROAR_HAVE_GETUID) && defined(ROAR_HAVE_GETGID)
2829 if ( auth_setup(none_acclev, trust_acclev, trust_root, getuid(), getgid()) == -1 ) {
2830#else
2831 if ( auth_setup(none_acclev, trust_acclev, trust_root, -1, -1) == -1 ) {
2832#endif
2833  ROAR_ERR("Can not set up auth. Bad.");
2834  alive = 0;
2835 }
2836
2837 // Register with OpenSLP:
2838#ifdef ROAR_HAVE_LIBSLP
2839 if ( reg_slp ) {
2840  register_slp(0, sock_addr);
2841 }
2842#endif
2843
2844#ifdef ROAR_HAVE_LIBX11
2845 if ( reg_x11 ) {
2846  register_x11(0, sock_addr);
2847 }
2848#endif
2849
2850 ROAR_INFO("Startup complet", ROAR_DBG_INFO_INFO);
2851
2852 // start main loop...
2853 ROAR_INFO("Entering main loop", ROAR_DBG_INFO_INFO);
2854 main_loop(&sa, sysclocksync);
2855 ROAR_INFO("Left main loop", ROAR_DBG_INFO_INFO);
2856
2857 // clean up.
2858 clean_quit_prep();
2859 output_buffer_free();
2860
2861 roar_notify_core_free(NULL);
2862
2863 ROAR_INFO("Exiting, no error", ROAR_DBG_INFO_INFO);
2864 return 0;
2865}
2866
2867void cleanup_listen_socket (int terminate) {
2868 int i;
2869
2870 ROAR_DBG("cleanup_listen_socket(terminate=%i) = (void)?", terminate);
2871
2872 ROAR_INFO("Cleaning up listen sockets", ROAR_DBG_INFO_INFO);
2873
2874 // Deregister from SLP:
2875#ifdef ROAR_HAVE_LIBSLP
2876 register_slp(1, NULL);
2877#endif
2878
2879#ifdef ROAR_HAVE_LIBX11
2880 register_x11(1, NULL);
2881#endif
2882
2883#ifdef ROAR_SUPPORT_LISTEN
2884 for (i = 0; i < ROAR_MAX_LISTEN_SOCKETS; i++) {
2885  if ( g_listen[i].used  ) {
2886   roar_vio_close(&(g_listen[i].sock));
2887
2888   g_listen[i].used = 0;
2889
2890#ifdef ROAR_HAVE_UNIX
2891   if ( server[i] != NULL )
2892    if ( *(server[i]) == '/' )
2893     unlink(server[i]);
2894#endif
2895  }
2896 }
2897
2898#endif
2899
2900 if ( terminate )
2901  g_terminate = 1;
2902}
2903
2904void clean_quit_prep (void) {
2905 cleanup_listen_socket(0);
2906
2907 plugins_free();
2908
2909#ifndef ROAR_WITHOUT_DCOMP_SOURCES
2910 sources_free();
2911#endif
2912 streams_free();
2913 clients_free();
2914#ifndef ROAR_WITHOUT_DCOMP_SSYNTH
2915 ssynth_free();
2916#endif
2917#ifndef ROAR_WITHOUT_DCOMP_CB
2918 midi_cb_stop(); // stop console beep
2919#endif
2920#ifndef ROAR_WITHOUT_DCOMP_MIDI
2921 midi_free();
2922#endif
2923#ifndef ROAR_WITHOUT_DCOMP_LIGHT
2924 light_free();
2925#endif
2926#ifndef ROAR_WITHOUT_DCOMP_RDTCS
2927 rdtcs_free();
2928#endif
2929
2930 waveform_free();
2931
2932#ifdef SUPPORT_PIDFILE
2933 if ( pidfile != NULL )
2934  unlink(pidfile);
2935#endif
2936
2937 auth_free();
2938}
2939
2940void clean_quit (void) {
2941 ROAR_INFO("Shuting down", ROAR_DBG_INFO_INFO);
2942
2943 counters_print(ROAR_DEBUG_TYPE_INFO, 0);
2944
2945 clean_quit_prep();
2946// output_buffer_free();
2947
2948 roar_notify_core_free(NULL);
2949
2950 ROAR_INFO("Exiting, no error", ROAR_DBG_INFO_INFO);
2951 exit(0);
2952}
2953
2954//ll
Note: See TracBrowser for help on using the repository browser.