Version 1.8.0.1
[socat.git] / xioparam.c
blobb2b14067f96ea7763a90d5ab35cfa75a151c2ebc
1 /* source: xioparam.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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 xioparms_t xioparms = {
14 false, /* strictopts */
15 "!!", /* pipesep */
16 ":", /* paramsep */
17 ",", /* optionsep */
18 ':', /* ip4portsep */
19 ':', /* ip6portsep */
20 '\0', /* logopt */
21 NULL, /* syslogfac */
22 WITH_DEFAULT_IPV, /* default_ip */
23 WITH_DEFAULT_IPV, /* preferred_ip */
24 false, /* experimental */
25 NULL, /* sniffleft_name */
26 NULL, /* sniffright_name */
27 8192 /* bufsiz */
28 } ;
31 /* allow application to set xioopen options */
32 int xiosetopt(char what, const char *arg) {
33 switch (what) {
34 case 's': xioparms.strictopts = true; break;
35 case 'p': if ((xioparms.pipesep = strdup(arg)) == NULL) {
36 Error1("strdup("F_Zu"): out of memory", strlen(arg)+1);
37 return -1;
39 break;
40 case 'o': xioparms.ip4portsep = arg[0];
41 if (arg[1] != '\0') {
42 Error2("xiosetopt('%c', \"%s\"): port separator must be single character",
43 what, arg);
44 return -1;
46 break;
47 case 'l': xioparms.logopt = *arg; break;
48 case 'y': xioparms.syslogfac = arg; break;
49 case 'r': xioparms.sniffleft_name = arg; break;
50 case 'R': xioparms.sniffright_name = arg; break;
51 default:
52 Error2("xiosetopt('%c', \"%s\"): unknown option",
53 what, arg?arg:"NULL");
54 return -1;
56 return 0;
60 int xioinqopt(char what, char *arg, size_t n) {
61 switch (what) {
62 case 's': return xioparms.strictopts;
63 case 'p':
64 arg[0] = '\0'; strncat(arg, xioparms.pipesep, n-1);
65 return 0;
66 case 'o': return xioparms.ip4portsep;
67 case 'l': return xioparms.logopt;
68 case 'r':
69 if (xioparms.sniffleft_name == NULL) {
70 return 1;
72 if (n < strlen(xioparms.sniffleft_name)+1) {
73 return -1;
75 arg[0] = '\0';
76 strncat(arg, xioparms.sniffleft_name, n-1);
77 return 0;
78 case 'R':
79 if (xioparms.sniffright_name == NULL) {
80 return 1;
82 if (n < strlen(xioparms.sniffright_name)+1) {
83 return -1;
85 arg[0] = '\0';
86 strncat(arg, xioparms.sniffright_name, n-1);
87 return 0;
88 default:
89 Error3("xioinqopt('%c', \"%s\", "F_Zu"): unknown option",
90 what, arg, n);
91 return -1;
93 return 0;