blob: be47cc1a0de89399c0554097533c0f4a9a9d092c [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
jjakoa7cd2492003-04-11 09:40:12 +00002 File autogenerated by gengetopt version 2.8
jjako52c24142002-12-16 13:33:51 +00003 generated with the following command:
jjakoa7cd2492003-04-11 09:40:12 +00004 gengetopt --conf-parser
jjako52c24142002-12-16 13:33:51 +00005
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
9*/
10
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15/* If we use autoconf. */
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19/* Check for configure's getopt check result. */
20#ifndef HAVE_GETOPT_LONG
21#include "getopt.h"
22#else
23#include <getopt.h>
24#endif
25
26#ifndef HAVE_STRDUP
27#define strdup gengetopt_strdup
28#endif /* HAVE_STRDUP */
29
30#include "cmdline.h"
31
32
33void
34cmdline_parser_print_version (void)
35{
36 printf ("%s %s\n", PACKAGE, VERSION);
37}
38
39void
40cmdline_parser_print_help (void)
41{
42 cmdline_parser_print_version ();
43 printf("\n"
44 "Usage: %s [OPTIONS]...\n", PACKAGE);
45 printf(" -h --help Print help and exit\n");
46 printf(" -V --version Print version and exit\n");
jjako52c24142002-12-16 13:33:51 +000047 printf(" -d --debug Run in debug mode (default=off)\n");
48 printf(" -cSTRING --conf=STRING Read configuration file\n");
49 printf(" --pidfile=STRING Filename of process id file (default='./sgsnemu.pid')\n");
50 printf(" --statedir=STRING Directory of nonvolatile data (default='./')\n");
51 printf(" --dns=STRING DNS Server to use\n");
52 printf(" -lSTRING --listen=STRING Local interface\n");
53 printf(" -rSTRING --remote=STRING Remote host\n");
jjako52c24142002-12-16 13:33:51 +000054 printf(" --contexts=INT Number of contexts (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000055 printf(" --timelimit=INT Exit after timelimit seconds (default='0')\n");
jjako193e8b12003-11-10 12:31:41 +000056 printf(" --gtpversion=INT GTP version to use (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000057 printf(" -aSTRING --apn=STRING Access point name (default='internet')\n");
58 printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n");
jjako193e8b12003-11-10 12:31:41 +000059 printf(" --nsapi=INT NSAPI (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000060 printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n");
61 printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n");
62 printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n");
63 printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n");
jjako5da68452003-01-28 16:08:47 +000064 printf(" --createif Create local network interface (default=off)\n");
jjako193e8b12003-11-10 12:31:41 +000065 printf(" -nSTRING --net=STRING Network address for local interface\n");
jjakoa7cd2492003-04-11 09:40:12 +000066 printf(" --defaultroute Create default route (default=off)\n");
jjako5da68452003-01-28 16:08:47 +000067 printf(" --ipup=STRING Script to run after link-up\n");
68 printf(" --ipdown=STRING Script to run after link-down\n");
jjako5da68452003-01-28 16:08:47 +000069 printf(" --pinghost=STRING Ping remote host\n");
70 printf(" --pingrate=INT Number of ping req per second (default='1')\n");
71 printf(" --pingsize=INT Number of ping data bytes (default='56')\n");
72 printf(" --pingcount=INT Number of ping req to send (default='0')\n");
73 printf(" --pingquiet Do not print ping packet info (default=off)\n");
jjako52c24142002-12-16 13:33:51 +000074}
75
76
77#ifndef HAVE_STRDUP
78/* gengetopt_strdup(): automatically generated from strdup.c. */
79/* strdup.c replacement of strdup, which is not standard */
80static char *
81gengetopt_strdup (const char *s)
82{
83 char *result = (char*)malloc(strlen(s) + 1);
84 if (result == (char*)0)
85 return (char*)0;
86 strcpy(result, s);
87 return result;
88}
89#endif /* HAVE_STRDUP */
90
91int
92cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
93{
94 int c; /* Character of the parsed option. */
95 int missing_required_options = 0;
96
97 args_info->help_given = 0 ;
98 args_info->version_given = 0 ;
jjako52c24142002-12-16 13:33:51 +000099 args_info->debug_given = 0 ;
100 args_info->conf_given = 0 ;
101 args_info->pidfile_given = 0 ;
102 args_info->statedir_given = 0 ;
103 args_info->dns_given = 0 ;
104 args_info->listen_given = 0 ;
105 args_info->remote_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000106 args_info->contexts_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000107 args_info->timelimit_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000108 args_info->gtpversion_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000109 args_info->apn_given = 0 ;
110 args_info->imsi_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000111 args_info->nsapi_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000112 args_info->msisdn_given = 0 ;
113 args_info->qos_given = 0 ;
114 args_info->uid_given = 0 ;
115 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000116 args_info->createif_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000117 args_info->net_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +0000118 args_info->defaultroute_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000119 args_info->ipup_given = 0 ;
120 args_info->ipdown_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000121 args_info->pinghost_given = 0 ;
122 args_info->pingrate_given = 0 ;
123 args_info->pingsize_given = 0 ;
124 args_info->pingcount_given = 0 ;
125 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000126#define clear_args() { \
jjako52c24142002-12-16 13:33:51 +0000127 args_info->debug_flag = 0;\
128 args_info->conf_arg = NULL; \
129 args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
130 args_info->statedir_arg = strdup("./") ;\
131 args_info->dns_arg = NULL; \
132 args_info->listen_arg = NULL; \
133 args_info->remote_arg = NULL; \
jjako52c24142002-12-16 13:33:51 +0000134 args_info->contexts_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000135 args_info->timelimit_arg = 0 ;\
jjako193e8b12003-11-10 12:31:41 +0000136 args_info->gtpversion_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000137 args_info->apn_arg = strdup("internet") ;\
138 args_info->imsi_arg = strdup("240010123456789") ;\
jjako193e8b12003-11-10 12:31:41 +0000139 args_info->nsapi_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000140 args_info->msisdn_arg = strdup("46702123456") ;\
141 args_info->qos_arg = 0x0b921f ;\
142 args_info->uid_arg = strdup("mig") ;\
143 args_info->pwd_arg = strdup("hemmelig") ;\
jjako5da68452003-01-28 16:08:47 +0000144 args_info->createif_flag = 0;\
jjako193e8b12003-11-10 12:31:41 +0000145 args_info->net_arg = NULL; \
jjakoa7cd2492003-04-11 09:40:12 +0000146 args_info->defaultroute_flag = 0;\
jjako5da68452003-01-28 16:08:47 +0000147 args_info->ipup_arg = NULL; \
148 args_info->ipdown_arg = NULL; \
jjako5da68452003-01-28 16:08:47 +0000149 args_info->pinghost_arg = NULL; \
150 args_info->pingrate_arg = 1 ;\
151 args_info->pingsize_arg = 56 ;\
152 args_info->pingcount_arg = 0 ;\
153 args_info->pingquiet_flag = 0;\
jjako52c24142002-12-16 13:33:51 +0000154}
155
156 clear_args();
157
158 optarg = 0;
159 optind = 1;
160 opterr = 1;
161 optopt = '?';
162
163 while (1)
164 {
165 int option_index = 0;
166 char *stop_char;
167 static struct option long_options[] = {
168 { "help", 0, NULL, 'h' },
169 { "version", 0, NULL, 'V' },
jjako52c24142002-12-16 13:33:51 +0000170 { "debug", 0, NULL, 'd' },
171 { "conf", 1, NULL, 'c' },
172 { "pidfile", 1, NULL, 0 },
173 { "statedir", 1, NULL, 0 },
174 { "dns", 1, NULL, 0 },
175 { "listen", 1, NULL, 'l' },
176 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000177 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000178 { "timelimit", 1, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000179 { "gtpversion", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000180 { "apn", 1, NULL, 'a' },
181 { "imsi", 1, NULL, 'i' },
jjako193e8b12003-11-10 12:31:41 +0000182 { "nsapi", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000183 { "msisdn", 1, NULL, 'm' },
184 { "qos", 1, NULL, 'q' },
185 { "uid", 1, NULL, 'u' },
186 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000187 { "createif", 0, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000188 { "net", 1, NULL, 'n' },
jjakoa7cd2492003-04-11 09:40:12 +0000189 { "defaultroute", 0, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000190 { "ipup", 1, NULL, 0 },
191 { "ipdown", 1, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000192 { "pinghost", 1, NULL, 0 },
193 { "pingrate", 1, NULL, 0 },
194 { "pingsize", 1, NULL, 0 },
195 { "pingcount", 1, NULL, 0 },
196 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000197 { NULL, 0, NULL, 0 }
198 };
199
jjako193e8b12003-11-10 12:31:41 +0000200 c = getopt_long (argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:", long_options, &option_index);
jjako52c24142002-12-16 13:33:51 +0000201
202 if (c == -1) break; /* Exit from `while (1)' loop. */
203
204 switch (c)
205 {
206 case 'h': /* Print help and exit. */
207 clear_args ();
208 cmdline_parser_print_help ();
209 exit (EXIT_SUCCESS);
210
211 case 'V': /* Print version and exit. */
212 clear_args ();
213 cmdline_parser_print_version ();
214 exit (EXIT_SUCCESS);
215
jjako52c24142002-12-16 13:33:51 +0000216 case 'd': /* Run in debug mode. */
217 if (args_info->debug_given)
218 {
219 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
220 clear_args ();
221 exit (EXIT_FAILURE);
222 }
223 args_info->debug_given = 1;
224 args_info->debug_flag = !(args_info->debug_flag);
225 break;
226
227 case 'c': /* Read configuration file. */
228 if (args_info->conf_given)
229 {
230 fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
231 clear_args ();
232 exit (EXIT_FAILURE);
233 }
234 args_info->conf_given = 1;
235 args_info->conf_arg = strdup (optarg);
236 break;
237
238 case 'l': /* Local interface. */
239 if (args_info->listen_given)
240 {
241 fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
242 clear_args ();
243 exit (EXIT_FAILURE);
244 }
245 args_info->listen_given = 1;
246 args_info->listen_arg = strdup (optarg);
247 break;
248
249 case 'r': /* Remote host. */
250 if (args_info->remote_given)
251 {
252 fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
253 clear_args ();
254 exit (EXIT_FAILURE);
255 }
256 args_info->remote_given = 1;
257 args_info->remote_arg = strdup (optarg);
258 break;
259
jjako52c24142002-12-16 13:33:51 +0000260 case 'a': /* Access point name. */
261 if (args_info->apn_given)
262 {
263 fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
264 clear_args ();
265 exit (EXIT_FAILURE);
266 }
267 args_info->apn_given = 1;
268 args_info->apn_arg = strdup (optarg);
269 break;
270
271 case 'i': /* IMSI. */
272 if (args_info->imsi_given)
273 {
274 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
275 clear_args ();
276 exit (EXIT_FAILURE);
277 }
278 args_info->imsi_given = 1;
279 args_info->imsi_arg = strdup (optarg);
280 break;
281
282 case 'm': /* Mobile Station ISDN number. */
283 if (args_info->msisdn_given)
284 {
285 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
286 clear_args ();
287 exit (EXIT_FAILURE);
288 }
289 args_info->msisdn_given = 1;
290 args_info->msisdn_arg = strdup (optarg);
291 break;
292
293 case 'q': /* Requested quality of service. */
294 if (args_info->qos_given)
295 {
296 fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
297 clear_args ();
298 exit (EXIT_FAILURE);
299 }
300 args_info->qos_given = 1;
301 args_info->qos_arg = strtol (optarg,&stop_char,0);
302 break;
303
304 case 'u': /* Login user ID. */
305 if (args_info->uid_given)
306 {
307 fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
308 clear_args ();
309 exit (EXIT_FAILURE);
310 }
311 args_info->uid_given = 1;
312 args_info->uid_arg = strdup (optarg);
313 break;
314
315 case 'p': /* Login password. */
316 if (args_info->pwd_given)
317 {
318 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
319 clear_args ();
320 exit (EXIT_FAILURE);
321 }
322 args_info->pwd_given = 1;
323 args_info->pwd_arg = strdup (optarg);
324 break;
325
jjako193e8b12003-11-10 12:31:41 +0000326 case 'n': /* Network address for local interface. */
327 if (args_info->net_given)
328 {
329 fprintf (stderr, "%s: `--net' (`-n') option given more than once\n", PACKAGE);
330 clear_args ();
331 exit (EXIT_FAILURE);
332 }
333 args_info->net_given = 1;
334 args_info->net_arg = strdup (optarg);
335 break;
336
jjako52c24142002-12-16 13:33:51 +0000337
338 case 0: /* Long option with no short option */
339 /* Filename of process id file. */
340 if (strcmp (long_options[option_index].name, "pidfile") == 0)
341 {
342 if (args_info->pidfile_given)
343 {
344 fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
345 clear_args ();
346 exit (EXIT_FAILURE);
347 }
348 args_info->pidfile_given = 1;
349 args_info->pidfile_arg = strdup (optarg);
350 break;
351 }
352 /* Directory of nonvolatile data. */
353 else if (strcmp (long_options[option_index].name, "statedir") == 0)
354 {
355 if (args_info->statedir_given)
356 {
357 fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
358 clear_args ();
359 exit (EXIT_FAILURE);
360 }
361 args_info->statedir_given = 1;
362 args_info->statedir_arg = strdup (optarg);
363 break;
364 }
365 /* DNS Server to use. */
366 else if (strcmp (long_options[option_index].name, "dns") == 0)
367 {
368 if (args_info->dns_given)
369 {
370 fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
371 clear_args ();
372 exit (EXIT_FAILURE);
373 }
374 args_info->dns_given = 1;
375 args_info->dns_arg = strdup (optarg);
376 break;
377 }
jjako52c24142002-12-16 13:33:51 +0000378 /* Number of contexts. */
379 else if (strcmp (long_options[option_index].name, "contexts") == 0)
380 {
381 if (args_info->contexts_given)
382 {
383 fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
384 clear_args ();
385 exit (EXIT_FAILURE);
386 }
387 args_info->contexts_given = 1;
388 args_info->contexts_arg = strtol (optarg,&stop_char,0);
389 break;
390 }
jjako52c24142002-12-16 13:33:51 +0000391 /* Exit after timelimit seconds. */
392 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
393 {
394 if (args_info->timelimit_given)
395 {
396 fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
397 clear_args ();
398 exit (EXIT_FAILURE);
399 }
400 args_info->timelimit_given = 1;
401 args_info->timelimit_arg = strtol (optarg,&stop_char,0);
402 break;
403 }
jjako193e8b12003-11-10 12:31:41 +0000404 /* GTP version to use. */
405 else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
406 {
407 if (args_info->gtpversion_given)
408 {
409 fprintf (stderr, "%s: `--gtpversion' option given more than once\n", PACKAGE);
410 clear_args ();
411 exit (EXIT_FAILURE);
412 }
413 args_info->gtpversion_given = 1;
414 args_info->gtpversion_arg = strtol (optarg,&stop_char,0);
415 break;
416 }
417 /* NSAPI. */
418 else if (strcmp (long_options[option_index].name, "nsapi") == 0)
419 {
420 if (args_info->nsapi_given)
421 {
422 fprintf (stderr, "%s: `--nsapi' option given more than once\n", PACKAGE);
423 clear_args ();
424 exit (EXIT_FAILURE);
425 }
426 args_info->nsapi_given = 1;
427 args_info->nsapi_arg = strtol (optarg,&stop_char,0);
428 break;
429 }
jjako5da68452003-01-28 16:08:47 +0000430 /* Create local network interface. */
431 else if (strcmp (long_options[option_index].name, "createif") == 0)
432 {
433 if (args_info->createif_given)
434 {
435 fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
436 clear_args ();
437 exit (EXIT_FAILURE);
438 }
439 args_info->createif_given = 1;
440 args_info->createif_flag = !(args_info->createif_flag);
441 break;
442 }
jjakoa7cd2492003-04-11 09:40:12 +0000443 /* Create default route. */
444 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
445 {
446 if (args_info->defaultroute_given)
447 {
448 fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
449 clear_args ();
450 exit (EXIT_FAILURE);
451 }
452 args_info->defaultroute_given = 1;
453 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
454 break;
455 }
jjako5da68452003-01-28 16:08:47 +0000456 /* Script to run after link-up. */
457 else if (strcmp (long_options[option_index].name, "ipup") == 0)
458 {
459 if (args_info->ipup_given)
460 {
461 fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
462 clear_args ();
463 exit (EXIT_FAILURE);
464 }
465 args_info->ipup_given = 1;
466 args_info->ipup_arg = strdup (optarg);
467 break;
468 }
469 /* Script to run after link-down. */
470 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
471 {
472 if (args_info->ipdown_given)
473 {
474 fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
475 clear_args ();
476 exit (EXIT_FAILURE);
477 }
478 args_info->ipdown_given = 1;
479 args_info->ipdown_arg = strdup (optarg);
480 break;
481 }
jjako5da68452003-01-28 16:08:47 +0000482 /* Ping remote host. */
483 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
484 {
485 if (args_info->pinghost_given)
486 {
487 fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
488 clear_args ();
489 exit (EXIT_FAILURE);
490 }
491 args_info->pinghost_given = 1;
492 args_info->pinghost_arg = strdup (optarg);
493 break;
494 }
495 /* Number of ping req per second. */
496 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
497 {
498 if (args_info->pingrate_given)
499 {
500 fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
501 clear_args ();
502 exit (EXIT_FAILURE);
503 }
504 args_info->pingrate_given = 1;
505 args_info->pingrate_arg = strtol (optarg,&stop_char,0);
506 break;
507 }
508 /* Number of ping data bytes. */
509 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
510 {
511 if (args_info->pingsize_given)
512 {
513 fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
514 clear_args ();
515 exit (EXIT_FAILURE);
516 }
517 args_info->pingsize_given = 1;
518 args_info->pingsize_arg = strtol (optarg,&stop_char,0);
519 break;
520 }
521 /* Number of ping req to send. */
522 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
523 {
524 if (args_info->pingcount_given)
525 {
526 fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
527 clear_args ();
528 exit (EXIT_FAILURE);
529 }
530 args_info->pingcount_given = 1;
531 args_info->pingcount_arg = strtol (optarg,&stop_char,0);
532 break;
533 }
534 /* Do not print ping packet info. */
535 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
536 {
537 if (args_info->pingquiet_given)
538 {
539 fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
540 clear_args ();
541 exit (EXIT_FAILURE);
542 }
543 args_info->pingquiet_given = 1;
544 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
545 break;
546 }
jjako52c24142002-12-16 13:33:51 +0000547
548 case '?': /* Invalid option. */
549 /* `getopt_long' already printed an error message. */
550 exit (EXIT_FAILURE);
551
552 default: /* bug: option not considered. */
553 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
554 abort ();
555 } /* switch */
556 } /* while */
557
558
559 if ( missing_required_options )
560 exit (EXIT_FAILURE);
561
562 return 0;
563}
564
565#define CONFIGPARSERBUFSIZE 1024
566
567int
568cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
569{
570 FILE* file;
571 char linebuf[CONFIGPARSERBUFSIZE];
572 int line_num = 0;
573 int len;
574 int fnum;
575 char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
576 char *stop_char;
577
578 if ((file = fopen(filename, "r")) == NULL)
579 {
580 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
581 PACKAGE, filename);
582 exit (EXIT_FAILURE);
583 }
584
585 while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
586 {
587 ++line_num;
588 len = strlen(linebuf);
589 if (len == CONFIGPARSERBUFSIZE-1)
590 {
591 fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
592 PACKAGE, CONFIGPARSERBUFSIZE, filename);
593 exit (EXIT_FAILURE);
594 }
595
596 if (linebuf[0] == '#')
597 continue; /* Line was a comment */
598
599 /* Get the option */
600 if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
601 {
602 if (!strcmp(fopt, "help"))
603 {
604 if (override || !args_info->help_given)
605 {
606 args_info->help_given = 1;
607
608 }
609 continue;
610 }
611 if (!strcmp(fopt, "version"))
612 {
613 if (override || !args_info->version_given)
614 {
615 args_info->version_given = 1;
616
617 }
618 continue;
619 }
jjako52c24142002-12-16 13:33:51 +0000620 if (!strcmp(fopt, "debug"))
621 {
622 if (override || !args_info->debug_given)
623 {
624 args_info->debug_given = 1;
625 args_info->debug_flag = !(args_info->debug_flag);
626 }
627 continue;
628 }
629 if (!strcmp(fopt, "conf"))
630 {
631 if (override || !args_info->conf_given)
632 {
633 args_info->conf_given = 1;
634 if (fnum == 2)
635 args_info->conf_arg = strdup (farg);
636 else
637 {
638 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
639 filename, line_num);
640 exit (EXIT_FAILURE);
641 }
642 }
643 continue;
644 }
645 if (!strcmp(fopt, "pidfile"))
646 {
647 if (override || !args_info->pidfile_given)
648 {
649 args_info->pidfile_given = 1;
650 if (fnum == 2)
651 args_info->pidfile_arg = strdup (farg);
652 else
653 {
654 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
655 filename, line_num);
656 exit (EXIT_FAILURE);
657 }
658 }
659 continue;
660 }
661 if (!strcmp(fopt, "statedir"))
662 {
663 if (override || !args_info->statedir_given)
664 {
665 args_info->statedir_given = 1;
666 if (fnum == 2)
667 args_info->statedir_arg = strdup (farg);
668 else
669 {
670 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
671 filename, line_num);
672 exit (EXIT_FAILURE);
673 }
674 }
675 continue;
676 }
677 if (!strcmp(fopt, "dns"))
678 {
679 if (override || !args_info->dns_given)
680 {
681 args_info->dns_given = 1;
682 if (fnum == 2)
683 args_info->dns_arg = strdup (farg);
684 else
685 {
686 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
687 filename, line_num);
688 exit (EXIT_FAILURE);
689 }
690 }
691 continue;
692 }
693 if (!strcmp(fopt, "listen"))
694 {
695 if (override || !args_info->listen_given)
696 {
697 args_info->listen_given = 1;
698 if (fnum == 2)
699 args_info->listen_arg = strdup (farg);
700 else
701 {
702 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
703 filename, line_num);
704 exit (EXIT_FAILURE);
705 }
706 }
707 continue;
708 }
709 if (!strcmp(fopt, "remote"))
710 {
711 if (override || !args_info->remote_given)
712 {
713 args_info->remote_given = 1;
714 if (fnum == 2)
715 args_info->remote_arg = strdup (farg);
716 else
717 {
718 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
719 filename, line_num);
720 exit (EXIT_FAILURE);
721 }
722 }
723 continue;
724 }
jjako52c24142002-12-16 13:33:51 +0000725 if (!strcmp(fopt, "contexts"))
726 {
727 if (override || !args_info->contexts_given)
728 {
729 args_info->contexts_given = 1;
730 if (fnum == 2)
731 args_info->contexts_arg = strtol (farg,&stop_char,0);
732 else
733 {
734 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
735 filename, line_num);
736 exit (EXIT_FAILURE);
737 }
738 }
739 continue;
740 }
jjako52c24142002-12-16 13:33:51 +0000741 if (!strcmp(fopt, "timelimit"))
742 {
743 if (override || !args_info->timelimit_given)
744 {
745 args_info->timelimit_given = 1;
746 if (fnum == 2)
747 args_info->timelimit_arg = strtol (farg,&stop_char,0);
748 else
749 {
750 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
751 filename, line_num);
752 exit (EXIT_FAILURE);
753 }
754 }
755 continue;
756 }
jjako193e8b12003-11-10 12:31:41 +0000757 if (!strcmp(fopt, "gtpversion"))
758 {
759 if (override || !args_info->gtpversion_given)
760 {
761 args_info->gtpversion_given = 1;
762 if (fnum == 2)
763 args_info->gtpversion_arg = strtol (farg,&stop_char,0);
764 else
765 {
766 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
767 filename, line_num);
768 exit (EXIT_FAILURE);
769 }
770 }
771 continue;
772 }
jjako52c24142002-12-16 13:33:51 +0000773 if (!strcmp(fopt, "apn"))
774 {
775 if (override || !args_info->apn_given)
776 {
777 args_info->apn_given = 1;
778 if (fnum == 2)
779 args_info->apn_arg = strdup (farg);
780 else
781 {
782 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
783 filename, line_num);
784 exit (EXIT_FAILURE);
785 }
786 }
787 continue;
788 }
789 if (!strcmp(fopt, "imsi"))
790 {
791 if (override || !args_info->imsi_given)
792 {
793 args_info->imsi_given = 1;
794 if (fnum == 2)
795 args_info->imsi_arg = strdup (farg);
796 else
797 {
798 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
799 filename, line_num);
800 exit (EXIT_FAILURE);
801 }
802 }
803 continue;
804 }
jjako193e8b12003-11-10 12:31:41 +0000805 if (!strcmp(fopt, "nsapi"))
806 {
807 if (override || !args_info->nsapi_given)
808 {
809 args_info->nsapi_given = 1;
810 if (fnum == 2)
811 args_info->nsapi_arg = strtol (farg,&stop_char,0);
812 else
813 {
814 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
815 filename, line_num);
816 exit (EXIT_FAILURE);
817 }
818 }
819 continue;
820 }
jjako52c24142002-12-16 13:33:51 +0000821 if (!strcmp(fopt, "msisdn"))
822 {
823 if (override || !args_info->msisdn_given)
824 {
825 args_info->msisdn_given = 1;
826 if (fnum == 2)
827 args_info->msisdn_arg = strdup (farg);
828 else
829 {
830 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
831 filename, line_num);
832 exit (EXIT_FAILURE);
833 }
834 }
835 continue;
836 }
837 if (!strcmp(fopt, "qos"))
838 {
839 if (override || !args_info->qos_given)
840 {
841 args_info->qos_given = 1;
842 if (fnum == 2)
843 args_info->qos_arg = strtol (farg,&stop_char,0);
844 else
845 {
846 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
847 filename, line_num);
848 exit (EXIT_FAILURE);
849 }
850 }
851 continue;
852 }
853 if (!strcmp(fopt, "uid"))
854 {
855 if (override || !args_info->uid_given)
856 {
857 args_info->uid_given = 1;
858 if (fnum == 2)
859 args_info->uid_arg = strdup (farg);
860 else
861 {
862 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
863 filename, line_num);
864 exit (EXIT_FAILURE);
865 }
866 }
867 continue;
868 }
869 if (!strcmp(fopt, "pwd"))
870 {
871 if (override || !args_info->pwd_given)
872 {
873 args_info->pwd_given = 1;
874 if (fnum == 2)
875 args_info->pwd_arg = strdup (farg);
876 else
877 {
878 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
879 filename, line_num);
880 exit (EXIT_FAILURE);
881 }
882 }
883 continue;
884 }
jjako5da68452003-01-28 16:08:47 +0000885 if (!strcmp(fopt, "createif"))
886 {
887 if (override || !args_info->createif_given)
888 {
889 args_info->createif_given = 1;
890 args_info->createif_flag = !(args_info->createif_flag);
891 }
892 continue;
893 }
jjako193e8b12003-11-10 12:31:41 +0000894 if (!strcmp(fopt, "net"))
895 {
896 if (override || !args_info->net_given)
897 {
898 args_info->net_given = 1;
899 if (fnum == 2)
900 args_info->net_arg = strdup (farg);
901 else
902 {
903 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
904 filename, line_num);
905 exit (EXIT_FAILURE);
906 }
907 }
908 continue;
909 }
jjakoa7cd2492003-04-11 09:40:12 +0000910 if (!strcmp(fopt, "defaultroute"))
911 {
912 if (override || !args_info->defaultroute_given)
913 {
914 args_info->defaultroute_given = 1;
915 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
916 }
917 continue;
918 }
jjako5da68452003-01-28 16:08:47 +0000919 if (!strcmp(fopt, "ipup"))
920 {
921 if (override || !args_info->ipup_given)
922 {
923 args_info->ipup_given = 1;
924 if (fnum == 2)
925 args_info->ipup_arg = strdup (farg);
926 else
927 {
928 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
929 filename, line_num);
930 exit (EXIT_FAILURE);
931 }
932 }
933 continue;
934 }
935 if (!strcmp(fopt, "ipdown"))
936 {
937 if (override || !args_info->ipdown_given)
938 {
939 args_info->ipdown_given = 1;
940 if (fnum == 2)
941 args_info->ipdown_arg = strdup (farg);
942 else
943 {
944 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
945 filename, line_num);
946 exit (EXIT_FAILURE);
947 }
948 }
949 continue;
950 }
jjako5da68452003-01-28 16:08:47 +0000951 if (!strcmp(fopt, "pinghost"))
952 {
953 if (override || !args_info->pinghost_given)
954 {
955 args_info->pinghost_given = 1;
956 if (fnum == 2)
957 args_info->pinghost_arg = strdup (farg);
958 else
959 {
960 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
961 filename, line_num);
962 exit (EXIT_FAILURE);
963 }
964 }
965 continue;
966 }
967 if (!strcmp(fopt, "pingrate"))
968 {
969 if (override || !args_info->pingrate_given)
970 {
971 args_info->pingrate_given = 1;
972 if (fnum == 2)
973 args_info->pingrate_arg = strtol (farg,&stop_char,0);
974 else
975 {
976 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
977 filename, line_num);
978 exit (EXIT_FAILURE);
979 }
980 }
981 continue;
982 }
983 if (!strcmp(fopt, "pingsize"))
984 {
985 if (override || !args_info->pingsize_given)
986 {
987 args_info->pingsize_given = 1;
988 if (fnum == 2)
989 args_info->pingsize_arg = strtol (farg,&stop_char,0);
990 else
991 {
992 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
993 filename, line_num);
994 exit (EXIT_FAILURE);
995 }
996 }
997 continue;
998 }
999 if (!strcmp(fopt, "pingcount"))
1000 {
1001 if (override || !args_info->pingcount_given)
1002 {
1003 args_info->pingcount_given = 1;
1004 if (fnum == 2)
1005 args_info->pingcount_arg = strtol (farg,&stop_char,0);
1006 else
1007 {
1008 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
1009 filename, line_num);
1010 exit (EXIT_FAILURE);
1011 }
1012 }
1013 continue;
1014 }
1015 if (!strcmp(fopt, "pingquiet"))
1016 {
1017 if (override || !args_info->pingquiet_given)
1018 {
1019 args_info->pingquiet_given = 1;
1020 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
1021 }
1022 continue;
1023 }
jjako52c24142002-12-16 13:33:51 +00001024
1025
1026 /* Tried all known options. This one is unknown! */
1027 fprintf (stderr, "%s: Unknown option '%s' found in %s\n",
1028 PACKAGE, fopt, filename);
1029 exit (EXIT_FAILURE);
1030 }
1031 } /* while */
1032 fclose(file); /* No error checking on close */
1033
1034 return 0;
1035}