1 /* $Id: options.c,v 1.20 2008/10/06 13:22:02 nanard Exp $ */
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * (c) 2006 Thomas Bernard
6 * This software is subject to the conditions detailed
7 * in the LICENCE file provided within the distribution */
15 #include "upnppermissions.h"
16 #include "upnpglobalvars.h"
18 struct option
* ary_options
= NULL
;
22 enum upnpconfigoptions id
;
25 { UPNPEXT_IFNAME
, "ext_ifname" },
26 { UPNPEXT_IP
, "ext_ip" },
27 { UPNPLISTENING_IP
, "listening_ip" },
29 { UPNPBITRATE_UP
, "bitrate_up" },
30 { UPNPBITRATE_DOWN
, "bitrate_down" },
31 { UPNPPRESENTATIONURL
, "presentation_url" },
32 { UPNPNOTIFY_INTERVAL
, "notify_interval" },
33 { UPNPSYSTEM_UPTIME
, "system_uptime" },
34 { UPNPPACKET_LOG
, "packet_log" },
36 { UPNPSERIAL
, "serial"},
37 { UPNPMODEL_NUMBER
, "model_number"},
38 { UPNPCLEANTHRESHOLD
, "clean_ruleset_threshold"},
39 { UPNPCLEANINTERVAL
, "clean_ruleset_interval"},
41 { UPNPFORWARDCHAIN
, "upnp_forward_chain"},
42 { UPNPNATCHAIN
, "upnp_nat_chain"},
45 { UPNPENABLENATPMP
, "enable_natpmp"},
47 { UPNPENABLE
, "enable_upnp"},
49 { UPNPQUEUE
, "queue"},
52 #ifdef PF_ENABLE_FILTER_RULES
53 { UPNPQUICKRULES
, "quickrules" },
55 #ifdef ENABLE_LEASEFILE
56 { UPNPLEASEFILE
, "lease_file"},
58 { UPNPMINISSDPDSOCKET
, "minissdpdsocket"},
59 { UPNPSECUREMODE
, "secure_mode"}
63 readoptionsfile(const char * fname
)
73 enum upnpconfigoptions id
;
75 if(!fname
|| (strlen(fname
) == 0))
78 memset(buffer
, 0, sizeof(buffer
));
81 printf("Reading configuration from file %s\n", fname
);
84 if(!(hfile
= fopen(fname
, "r")))
87 if(ary_options
!= NULL
)
93 while(fgets(buffer
, sizeof(buffer
), hfile
))
96 t
= strchr(buffer
, '\n');
101 while((t
>= buffer
) && isspace(*t
))
108 /* skip leading whitespaces */
110 while(isspace(*name
))
113 /* check for comments or empty lines */
114 if(name
[0] == '#' || name
[0] == '\0') continue;
116 /* check for UPnP permissions rule */
117 if(0 == memcmp(name
, "allow", 5) || 0 == memcmp(name
, "deny", 4))
119 upnppermlist
= realloc(upnppermlist
,
120 sizeof(struct upnpperm
) * (num_upnpperm
+1));
122 if(read_permission_line(upnppermlist
+ num_upnpperm
, name
) >= 0)
128 fprintf(stderr
, "parsing error file %s line %d : %s\n",
129 fname
, linenum
, name
);
133 if(!(equals
= strchr(name
, '=')))
135 fprintf(stderr
, "parsing error file %s line %d : %s\n",
136 fname
, linenum
, name
);
140 /* remove ending whitespaces */
141 for(t
=equals
-1; t
>name
&& isspace(*t
); t
--)
147 /* skip leading whitespaces */
148 while(isspace(*value
))
152 for(i
=0; i
<sizeof(optionids
)/sizeof(optionids
[0]); i
++)
154 /*printf("%2d %2d %s %s\n", i, optionids[i].id, name,
155 optionids[i].name); */
157 if(0 == strcmp(name
, optionids
[i
].name
))
159 id
= optionids
[i
].id
;
164 if(id
== UPNP_INVALID
)
166 fprintf(stderr
, "parsing error file %s line %d : %s=%s\n",
167 fname
, linenum
, name
, value
);
172 ary_options
= (struct option
*) realloc(ary_options
, num_options
* sizeof(struct option
));
174 ary_options
[num_options
-1].id
= id
;
175 strncpy(ary_options
[num_options
-1].value
, value
, MAX_OPTION_VALUE_LEN
);