version 1.7.3.0
[socat.git] / xioparam.c
blobd13cb2772a6d19a52c100c525a1ef9f8fb899d7a
1 /* source: xioparam.c */
2 /* Copyright Gerhard Rieger */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for xio options handling */
7 #include "xiosysincludes.h"
8 #include "xioopen.h"
10 /*#include "xioparam.h" are all in xio.h */
12 /* options that can be applied to this module */
13 xioopts_t xioopts = {
14 false, /* strictopts */
15 "!!", /* pipesep */
16 ":", /* paramsep */
17 ",", /* optionsep */
18 ':', /* ip4portsep */
19 ':', /* ip6portsep */
20 '\0', /* logopt */
21 NULL, /* syslogfac */
22 '4', /* default_ip */
23 '4' /* preferred_ip */
24 } ;
27 /* allow application to set xioopen options */
28 int xiosetopt(char what, const char *arg) {
29 switch (what) {
30 case 's': xioopts.strictopts = true; break;
31 case 'p': if ((xioopts.pipesep = strdup(arg)) == NULL) {
32 Error1("strdup("F_Zu"): out of memory", strlen(arg)+1);
33 return -1;
35 break;
36 case 'o': xioopts.ip4portsep = arg[0];
37 if (arg[1] != '\0') {
38 Error2("xiosetopt('%c', \"%s\"): port separator must be single character",
39 what, arg);
40 return -1;
42 break;
43 case 'l': xioopts.logopt = *arg; break;
44 case 'y': xioopts.syslogfac = arg; break;
45 default:
46 Error2("xiosetopt('%c', \"%s\"): unknown option",
47 what, arg?arg:"NULL");
48 return -1;
50 return 0;
54 int xioinqopt(char what, char *arg, size_t n) {
55 switch (what) {
56 case 's': return xioopts.strictopts;
57 case 'p':
58 arg[0] = '\0'; strncat(arg, xioopts.pipesep, n-1);
59 return 0;
60 case 'o': return xioopts.ip4portsep;
61 case 'l': return xioopts.logopt;
62 default:
63 Error3("xioinqopt('%c', \"%s\", "F_Zu"): unknown option",
64 what, arg, n);
65 return -1;
67 return 0;