Added the --disable-client-cert option, to prevent the server asking the client for...
[gnutls:gnutls.git] / src / serv-gaa.c
1 /* File generated by GAA 1.6.6
2  */
3 #define GAA_NO_WIN32
4 #line 1 "serv.gaa"
5
6
7 #include <common.h>
8
9 void print_serv_license(void);
10 void serv_version(void);
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15
16 #ifndef GAA_NO_WIN32
17 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
18 #define GAA_WIN32
19 #endif
20 #endif
21
22 static void* gaa_malloc( size_t size) {
23 void* ret;
24         ret = malloc(size);
25         if (ret==NULL) {
26                 fprintf(stderr, "gaa: could not allocate memory");
27                 exit(1);
28         }
29         return ret;
30 }
31
32 static void __gaa_helpsingle(char short_name, char *name, 
33         char *arg_desc, char *opt_help)
34 {
35      int col1, col3, col4, tabsize = 3, curr;
36      int i;
37
38      col1 = 5; /* Default values */
39      col3 = 30;
40      col4 = 70;
41
42      curr = 0;
43      for(i = 0; i < col1; i++)
44         {
45         printf(" ");
46         curr++;
47         }
48      if(short_name)
49         {
50         if(name && *name)
51           {
52             printf("-%c, ", short_name);
53             curr += 4;
54           }
55         else
56           {
57             printf("-%c ", short_name);
58             curr += 3;
59           }
60         }
61      if(name && *name)
62         {
63           printf("--%s ", name);
64           curr += 3 + strlen(name);
65         }
66      if(arg_desc && *arg_desc)
67         {
68           printf("%s ", arg_desc);
69           curr += 1 + strlen(arg_desc);
70         }
71      if(curr >= col3)
72         {
73           printf("\n");
74           curr = 0;
75         }
76      if(opt_help) /* let's print the option's help body */
77         {
78         const char *str = opt_help;
79         while(*str)
80           {
81              while(curr < col3)
82                {
83                  printf(" ");
84                  curr++;
85                }
86              switch(*str)
87                {
88                  case '\n':
89                      printf("\n");
90                      curr = 0;
91                      break;
92                  case '\t':
93                      do
94                         {
95                         printf(" ");
96                         curr++;
97                         }
98                      while((curr - col3) % tabsize != 0 && curr < col4);
99                  case ' ':
100                      if(*str == ' ')
101                         {
102                         curr++;
103                         printf(" ");
104                         }
105                      for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
106                         && str[i] != '\t'; i++);
107                      if(curr + i - 1 >= col4)
108                         curr = col4;
109                      break;
110                 default:
111                      printf("%c", *str);
112                      curr++;
113                }
114              if(curr >= col4)
115                {
116                  printf("\n");
117                  curr = 0;
118                }
119              str++;
120           }
121         }
122      printf("\n");
123 }
124
125 void gaa_help(void)
126 {
127         printf("GNU TLS test server\nUsage: gnutls-serv [options]\n\n\n");
128         __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
129         __gaa_helpsingle('g', "generate", "", "Generate Diffie Hellman Parameters.");
130         __gaa_helpsingle('p', "port", "integer ", "The port to connect to.");
131         __gaa_helpsingle('q', "quiet", "", "Suppress some messages.");
132         __gaa_helpsingle(0, "nodb", "", "Does not use the resume database.");
133         __gaa_helpsingle(0, "http", "", "Act as an HTTP Server.");
134         __gaa_helpsingle(0, "echo", "", "Act as an Echo Server.");
135         __gaa_helpsingle(0, "dhparams", "FILE ", "DH params file to use.");
136         __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates");
137         __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
138         __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
139         __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
140         __gaa_helpsingle(0, "pgptrustdb", "FILE ", "PGP trustdb file to use.");
141         __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
142         __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
143         __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file to use.");
144         __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
145         __gaa_helpsingle(0, "x509dsakeyfile", "FILE ", "Alternative X.509 key file to use.");
146         __gaa_helpsingle(0, "x509dsacertfile", "FILE ", "Alternative X.509 certificate file to use.");
147         __gaa_helpsingle('r', "require-cert", "", "Require a valid certificate.");
148         __gaa_helpsingle('a', "disable-client-cert", "", "Disable request for a client certificate.");
149         __gaa_helpsingle(0, "pskpasswd", "FILE ", "PSK password file to use.");
150         __gaa_helpsingle(0, "srppasswd", "FILE ", "SRP password file to use.");
151         __gaa_helpsingle(0, "srppasswdconf", "FILE ", "SRP password conf file to use.");
152         __gaa_helpsingle(0, "authz-x509-attr-cert", "FILE ", "Use X.509 Attribute Certificate in FILE as authorization data.");
153         __gaa_helpsingle(0, "authz-saml-assertion", "FILE ", "Use SAML Assertion in FILE as authorization data.");
154         __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
155         __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
156         __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
157         __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
158         __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
159         __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
160         __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms  and modes.");
161         __gaa_helpsingle('h', "help", "", "prints this help");
162         __gaa_helpsingle('v', "version", "", "prints the program's version number");
163         __gaa_helpsingle(0, "copyright", "", "prints the program's license");
164
165 #line 100 "gaa.skel"
166 }
167 /* Copy of C area */
168
169 #line 104 "gaa.skel"
170 /* GAA HEADER */
171 #ifndef GAA_HEADER_POKY
172 #define GAA_HEADER_POKY
173
174 typedef struct _gaainfo gaainfo;
175
176 struct _gaainfo
177 {
178 #line 109 "serv.gaa"
179         char **ctype;
180 #line 108 "serv.gaa"
181         int nctype;
182 #line 105 "serv.gaa"
183         char **kx;
184 #line 104 "serv.gaa"
185         int nkx;
186 #line 101 "serv.gaa"
187         char **macs;
188 #line 100 "serv.gaa"
189         int nmacs;
190 #line 97 "serv.gaa"
191         char **comp;
192 #line 96 "serv.gaa"
193         int ncomp;
194 #line 93 "serv.gaa"
195         char **proto;
196 #line 92 "serv.gaa"
197         int nproto;
198 #line 89 "serv.gaa"
199         char **ciphers;
200 #line 88 "serv.gaa"
201         int nciphers;
202 #line 85 "serv.gaa"
203         char *authz_saml_assertion;
204 #line 82 "serv.gaa"
205         char *authz_x509_attr_cert;
206 #line 79 "serv.gaa"
207         char *srp_passwd_conf;
208 #line 76 "serv.gaa"
209         char *srp_passwd;
210 #line 73 "serv.gaa"
211         char *psk_passwd;
212 #line 70 "serv.gaa"
213         int disable_client_cert;
214 #line 67 "serv.gaa"
215         int require_cert;
216 #line 64 "serv.gaa"
217         char *x509_dsacertfile;
218 #line 61 "serv.gaa"
219         char *x509_dsakeyfile;
220 #line 58 "serv.gaa"
221         char *x509_certfile;
222 #line 55 "serv.gaa"
223         char *x509_keyfile;
224 #line 52 "serv.gaa"
225         char *pgp_certfile;
226 #line 49 "serv.gaa"
227         char *pgp_keyfile;
228 #line 46 "serv.gaa"
229         char *pgp_trustdb;
230 #line 43 "serv.gaa"
231         char *pgp_keyring;
232 #line 40 "serv.gaa"
233         char *x509_crlfile;
234 #line 37 "serv.gaa"
235         char *x509_cafile;
236 #line 34 "serv.gaa"
237         int fmtder;
238 #line 31 "serv.gaa"
239         char *dh_params_file;
240 #line 27 "serv.gaa"
241         int http;
242 #line 24 "serv.gaa"
243         int nodb;
244 #line 21 "serv.gaa"
245         int quiet;
246 #line 18 "serv.gaa"
247         int port;
248 #line 15 "serv.gaa"
249         int generate;
250 #line 12 "serv.gaa"
251         int debug;
252
253 #line 114 "gaa.skel"
254 };
255
256 #ifdef __cplusplus
257 extern "C"
258 {
259 #endif
260
261     int gaa(int argc, char *argv[], gaainfo *gaaval);
262
263     void gaa_help(void);
264     
265     int gaa_file(const char *name, gaainfo *gaaval);
266     
267 #ifdef __cplusplus
268 }
269 #endif
270
271
272 #endif
273
274 #line 135 "gaa.skel"
275
276 /* C declarations */
277
278 #define GAAERROR(x)    \
279 {                   \
280 gaa_error = 1;      \
281 return x;        \
282 }
283
284 static char *gaa_current_option;
285 static int gaa_error = 0;
286
287 /* Generated by gaa */
288
289 #include <string.h>
290 #include <stdlib.h>
291
292
293 #define GAA_OK                       -1
294
295 #define GAA_ERROR_NOMATCH            0
296 #define GAA_ERROR_NOTENOUGH_ARGS     1
297 #define GAA_ERROR_INVALID_ARG        2
298 #define GAA_ERROR_UNKNOWN            3
299
300 #define GAA_NOT_AN_OPTION       0
301 #define GAA_WORD_OPTION         1
302 #define GAA_LETTER_OPTION       2
303 #define GAA_MULTIPLE_OPTION     3
304
305 #define GAA_REST                0
306 #define GAA_NB_OPTION           36
307 #define GAAOPTID_copyright      1
308 #define GAAOPTID_version        2
309 #define GAAOPTID_help   3
310 #define GAAOPTID_list   4
311 #define GAAOPTID_ctypes 5
312 #define GAAOPTID_kx     6
313 #define GAAOPTID_macs   7
314 #define GAAOPTID_comp   8
315 #define GAAOPTID_protocols      9
316 #define GAAOPTID_ciphers        10
317 #define GAAOPTID_authz_saml_assertion   11
318 #define GAAOPTID_authz_x509_attr_cert   12
319 #define GAAOPTID_srppasswdconf  13
320 #define GAAOPTID_srppasswd      14
321 #define GAAOPTID_pskpasswd      15
322 #define GAAOPTID_disable_client_cert    16
323 #define GAAOPTID_require_cert   17
324 #define GAAOPTID_x509dsacertfile        18
325 #define GAAOPTID_x509dsakeyfile 19
326 #define GAAOPTID_x509certfile   20
327 #define GAAOPTID_x509keyfile    21
328 #define GAAOPTID_pgpcertfile    22
329 #define GAAOPTID_pgpkeyfile     23
330 #define GAAOPTID_pgptrustdb     24
331 #define GAAOPTID_pgpkeyring     25
332 #define GAAOPTID_x509crlfile    26
333 #define GAAOPTID_x509cafile     27
334 #define GAAOPTID_x509fmtder     28
335 #define GAAOPTID_dhparams       29
336 #define GAAOPTID_echo   30
337 #define GAAOPTID_http   31
338 #define GAAOPTID_nodb   32
339 #define GAAOPTID_quiet  33
340 #define GAAOPTID_port   34
341 #define GAAOPTID_generate       35
342 #define GAAOPTID_debug  36
343
344 #line 168 "gaa.skel"
345
346 #define GAA_CHECK1STR(a,b)      \
347 if(a[0] == str[0])              \
348 {                               \
349     gaa_current_option = a;     \
350     return b;                   \
351 }
352
353 #define GAA_CHECKSTR(a,b)                \
354 if(strcmp(a,str) == 0)                   \
355 {                                        \
356     gaa_current_option = a;              \
357     return b;                            \
358 }
359
360 #define GAA_TESTMOREARGS                                                  \
361 if(!OK)                                                                     \
362 {                                  \
363 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
364     gaa_index++;                                                            \
365 if(gaa_last_non_option == gaa_index)                                        \
366     return GAA_ERROR_NOTENOUGH_ARGS; \
367 }
368
369 #define GAA_TESTMOREOPTIONALARGS                                                  \
370 if(!OK) \
371 { \
372 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
373     gaa_index++;                                                            \
374 if(gaa_last_non_option == gaa_index)                                        \
375     OK = 1; \
376 }
377
378 #define GAA_FILL_2ARGS(target, func)           \
379 target = func(GAAargv[gaa_index]);       \
380 gaa_arg_used[gaa_index] = 1;             \
381 if(gaa_error == 1)                       \
382 {                                        \
383     gaa_error = 0;                       \
384     return GAA_ERROR_INVALID_ARG;        \
385
386
387
388
389 #define GAA_FILL(target, func, num)           \
390 if(!OK) \
391 { \
392 target = func(GAAargv[gaa_index]);       \
393 gaa_arg_used[gaa_index] = 1;             \
394 if(gaa_error == 1)                       \
395 {                                        \
396     gaa_error = 0;                       \
397     return GAA_ERROR_INVALID_ARG;        \
398 } \
399 num = 1;  \
400 } \
401 else \
402 { \
403 num = 0; \
404 }
405
406 #define GAA_LIST_FILL(target, func, type ,num)                      \
407 if(!OK) \
408 { \
409 num = 0;                                                            \
410 target = NULL;                                                      \
411 if ( gaa_last_non_option - gaa_index > 0)                           \
412   target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
413 for(; gaa_index < gaa_last_non_option; gaa_index++)                 \
414 {                                                                   \
415     if(gaa_arg_used[gaa_index] == 0)                                \
416     {                                                               \
417         GAA_FILL_2ARGS(target[num], func);                          \
418         num++;                                                      \
419     }                                                               \
420 }                                                                   \
421 if(num == 0)                                                        \
422     return GAA_ERROR_NOTENOUGH_ARGS; \
423 }
424
425 #define GAA_OPTIONALLIST_FILL(target, func, type ,num)                      \
426 if(!OK) \
427 { \
428 num = 0;                                                            \
429 target = NULL;                                                      \
430 if ( gaa_last_non_option - gaa_index > 0)                           \
431   target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
432 for(; gaa_index < gaa_last_non_option; gaa_index++)                 \
433 {                                                                   \
434     if(gaa_arg_used[gaa_index] == 0)                                \
435     {                                                               \
436         GAA_FILL_2ARGS(target[num], func);                                \
437         num++;                                                      \
438     }                                                               \
439 } \
440 }
441
442 #define GAA_OBLIGAT(str)                                            \
443 k = 0;                                                              \
444 for(i = 0; i < strlen(str); i++)                                    \
445 {                                                                   \
446     j = gaa_get_option_num(str + i, GAA_LETTER_OPTION);           \
447     if(j == GAA_ERROR_NOMATCH)                                       \
448     {                                                               \
449         printf("Error: invalid 'obligat' set\n");                  \
450         exit(-1);                                                   \
451     }                                                               \
452     if(opt_list[j] == 1)                                            \
453         k = 1;                                                      \
454 }                                                                    \
455 if(k == 0)                                                            \
456 {                                                                      \
457     if(strlen(str) == 1)                                                \
458         printf("You must give the -%s option\n", str);                     \
459     else                                                                  \
460         printf("You must give at least one option of '%s'\n", str);          \
461     return 0;         \
462 }
463         
464 #define GAA_INCOMP(str)                                                \
465 k = 0;                                                              \
466 for(i = 0; i < strlen(str); i++)                                    \
467 {                                                                   \
468     j = gaa_get_option_num(str + i, GAA_LETTER_OPTION);           \
469     if(j == GAA_ERROR_NOMATCH)                                      \
470     {                                                               \
471         printf("Error: invalid 'obligat' set\n");                  \
472         exit(-1);                                                   \
473     }                                                               \
474     if(opt_list[j] == 1)                                            \
475         k++;                                                      \
476 }                   \
477 if(k > 1)                                                            \
478 {                                                                      \
479     printf("The options '%s' are incompatible\n", str);              \
480     return 0;                                                          \
481 }
482         
483
484 static char **GAAargv;
485 static int GAAargc;
486 static char *gaa_arg_used;
487 static int gaa_processing_file = 0;
488 static int inited = 0;
489
490 static int gaa_getint(char *arg)
491 {
492     int tmp;
493     char a;
494     if(sscanf(arg, "%d%c", &tmp, &a) < 1)
495     {
496         printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
497         GAAERROR(-1);
498     }
499     return tmp;
500 }
501
502 static char gaa_getchar(char *arg)
503 {
504     if(strlen(arg) != 1)
505     {
506         printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
507         GAAERROR(-1);
508     }
509     return arg[0];
510 }
511
512 static char* gaa_getstr(char *arg)
513 {
514     return arg;
515 }
516 static float gaa_getfloat(char *arg)
517 {
518     float tmp;
519     char a;
520     if(sscanf(arg, "%f%c", &tmp, &a) < 1)
521     {
522         printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
523         GAAERROR(-1);
524     }
525     return tmp;
526 }
527 /* option structures */
528
529 struct GAAOPTION_ctypes 
530 {
531         char** arg1;
532         int size1;
533 };
534
535 struct GAAOPTION_kx 
536 {
537         char** arg1;
538         int size1;
539 };
540
541 struct GAAOPTION_macs 
542 {
543         char** arg1;
544         int size1;
545 };
546
547 struct GAAOPTION_comp 
548 {
549         char** arg1;
550         int size1;
551 };
552
553 struct GAAOPTION_protocols 
554 {
555         char** arg1;
556         int size1;
557 };
558
559 struct GAAOPTION_ciphers 
560 {
561         char** arg1;
562         int size1;
563 };
564
565 struct GAAOPTION_authz_saml_assertion 
566 {
567         char* arg1;
568         int size1;
569 };
570
571 struct GAAOPTION_authz_x509_attr_cert 
572 {
573         char* arg1;
574         int size1;
575 };
576
577 struct GAAOPTION_srppasswdconf 
578 {
579         char* arg1;
580         int size1;
581 };
582
583 struct GAAOPTION_srppasswd 
584 {
585         char* arg1;
586         int size1;
587 };
588
589 struct GAAOPTION_pskpasswd 
590 {
591         char* arg1;
592         int size1;
593 };
594
595 struct GAAOPTION_x509dsacertfile 
596 {
597         char* arg1;
598         int size1;
599 };
600
601 struct GAAOPTION_x509dsakeyfile 
602 {
603         char* arg1;
604         int size1;
605 };
606
607 struct GAAOPTION_x509certfile 
608 {
609         char* arg1;
610         int size1;
611 };
612
613 struct GAAOPTION_x509keyfile 
614 {
615         char* arg1;
616         int size1;
617 };
618
619 struct GAAOPTION_pgpcertfile 
620 {
621         char* arg1;
622         int size1;
623 };
624
625 struct GAAOPTION_pgpkeyfile 
626 {
627         char* arg1;
628         int size1;
629 };
630
631 struct GAAOPTION_pgptrustdb 
632 {
633         char* arg1;
634         int size1;
635 };
636
637 struct GAAOPTION_pgpkeyring 
638 {
639         char* arg1;
640         int size1;
641 };
642
643 struct GAAOPTION_x509crlfile 
644 {
645         char* arg1;
646         int size1;
647 };
648
649 struct GAAOPTION_x509cafile 
650 {
651         char* arg1;
652         int size1;
653 };
654
655 struct GAAOPTION_dhparams 
656 {
657         char* arg1;
658         int size1;
659 };
660
661 struct GAAOPTION_port 
662 {
663         int arg1;
664         int size1;
665 };
666
667 struct GAAOPTION_debug 
668 {
669         int arg1;
670         int size1;
671 };
672          
673 #line 349 "gaa.skel"
674 static int gaa_is_an_argument(char *str)
675 {
676 #ifdef GAA_WIN32
677     if(str[0] == '/' && str[1] != 0)
678         return GAA_MULTIPLE_OPTION;
679 #endif
680     if(str[0] != '-')
681         return GAA_NOT_AN_OPTION;
682     if(str[1] == 0)
683         return GAA_NOT_AN_OPTION;
684     if(str[1] == '-')
685     {
686         if(str[2] != 0)
687             return GAA_WORD_OPTION;
688         else
689             return GAA_NOT_AN_OPTION;
690     }
691     if(str[2] == 0)
692         return GAA_LETTER_OPTION;
693     else
694         return GAA_MULTIPLE_OPTION;
695 }
696
697 static int gaa_get_option_num(char *str, int status)
698 {
699     switch(status)
700         {
701         case GAA_LETTER_OPTION:
702                         GAA_CHECK1STR("", GAAOPTID_ctypes);
703                         GAA_CHECK1STR("", GAAOPTID_kx);
704                         GAA_CHECK1STR("", GAAOPTID_macs);
705                         GAA_CHECK1STR("", GAAOPTID_comp);
706                         GAA_CHECK1STR("", GAAOPTID_protocols);
707                         GAA_CHECK1STR("", GAAOPTID_ciphers);
708                         GAA_CHECK1STR("", GAAOPTID_authz_saml_assertion);
709                         GAA_CHECK1STR("", GAAOPTID_authz_x509_attr_cert);
710                         GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
711                         GAA_CHECK1STR("", GAAOPTID_srppasswd);
712                         GAA_CHECK1STR("", GAAOPTID_pskpasswd);
713                         GAA_CHECK1STR("", GAAOPTID_x509dsacertfile);
714                         GAA_CHECK1STR("", GAAOPTID_x509dsakeyfile);
715                         GAA_CHECK1STR("", GAAOPTID_x509certfile);
716                         GAA_CHECK1STR("", GAAOPTID_x509keyfile);
717                         GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
718                         GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
719                         GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
720                         GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
721                         GAA_CHECK1STR("", GAAOPTID_x509crlfile);
722                         GAA_CHECK1STR("", GAAOPTID_x509cafile);
723                         GAA_CHECK1STR("", GAAOPTID_dhparams);
724                         GAA_CHECK1STR("p", GAAOPTID_port);
725                         GAA_CHECK1STR("d", GAAOPTID_debug);
726         case GAA_MULTIPLE_OPTION:
727 #line 375 "gaa.skel"
728                         GAA_CHECK1STR("", GAAOPTID_copyright);
729                         GAA_CHECK1STR("v", GAAOPTID_version);
730                         GAA_CHECK1STR("h", GAAOPTID_help);
731                         GAA_CHECK1STR("l", GAAOPTID_list);
732                         GAA_CHECK1STR("a", GAAOPTID_disable_client_cert);
733                         GAA_CHECK1STR("r", GAAOPTID_require_cert);
734                         GAA_CHECK1STR("", GAAOPTID_x509fmtder);
735                         GAA_CHECK1STR("", GAAOPTID_echo);
736                         GAA_CHECK1STR("", GAAOPTID_http);
737                         GAA_CHECK1STR("", GAAOPTID_nodb);
738                         GAA_CHECK1STR("q", GAAOPTID_quiet);
739                         GAA_CHECK1STR("g", GAAOPTID_generate);
740
741 #line 277 "gaa.skel"
742         break;
743         case GAA_WORD_OPTION:
744                         GAA_CHECKSTR("copyright", GAAOPTID_copyright);
745                         GAA_CHECKSTR("version", GAAOPTID_version);
746                         GAA_CHECKSTR("help", GAAOPTID_help);
747                         GAA_CHECKSTR("list", GAAOPTID_list);
748                         GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
749                         GAA_CHECKSTR("kx", GAAOPTID_kx);
750                         GAA_CHECKSTR("macs", GAAOPTID_macs);
751                         GAA_CHECKSTR("comp", GAAOPTID_comp);
752                         GAA_CHECKSTR("protocols", GAAOPTID_protocols);
753                         GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
754                         GAA_CHECKSTR("authz-saml-assertion", GAAOPTID_authz_saml_assertion);
755                         GAA_CHECKSTR("authz-x509-attr-cert", GAAOPTID_authz_x509_attr_cert);
756                         GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
757                         GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
758                         GAA_CHECKSTR("pskpasswd", GAAOPTID_pskpasswd);
759                         GAA_CHECKSTR("disable-client-cert", GAAOPTID_disable_client_cert);
760                         GAA_CHECKSTR("require-cert", GAAOPTID_require_cert);
761                         GAA_CHECKSTR("x509dsacertfile", GAAOPTID_x509dsacertfile);
762                         GAA_CHECKSTR("x509dsakeyfile", GAAOPTID_x509dsakeyfile);
763                         GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
764                         GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
765                         GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
766                         GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
767                         GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
768                         GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
769                         GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
770                         GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
771                         GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
772                         GAA_CHECKSTR("dhparams", GAAOPTID_dhparams);
773                         GAA_CHECKSTR("echo", GAAOPTID_echo);
774                         GAA_CHECKSTR("http", GAAOPTID_http);
775                         GAA_CHECKSTR("nodb", GAAOPTID_nodb);
776                         GAA_CHECKSTR("quiet", GAAOPTID_quiet);
777                         GAA_CHECKSTR("port", GAAOPTID_port);
778                         GAA_CHECKSTR("generate", GAAOPTID_generate);
779                         GAA_CHECKSTR("debug", GAAOPTID_debug);
780
781 #line 281 "gaa.skel"
782         break;
783         default: break;
784         }
785     return GAA_ERROR_NOMATCH;
786 }
787
788 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
789 {
790     int OK = 0;
791     int gaa_last_non_option;
792         struct GAAOPTION_ctypes GAATMP_ctypes;
793         struct GAAOPTION_kx GAATMP_kx;
794         struct GAAOPTION_macs GAATMP_macs;
795         struct GAAOPTION_comp GAATMP_comp;
796         struct GAAOPTION_protocols GAATMP_protocols;
797         struct GAAOPTION_ciphers GAATMP_ciphers;
798         struct GAAOPTION_authz_saml_assertion GAATMP_authz_saml_assertion;
799         struct GAAOPTION_authz_x509_attr_cert GAATMP_authz_x509_attr_cert;
800         struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
801         struct GAAOPTION_srppasswd GAATMP_srppasswd;
802         struct GAAOPTION_pskpasswd GAATMP_pskpasswd;
803         struct GAAOPTION_x509dsacertfile GAATMP_x509dsacertfile;
804         struct GAAOPTION_x509dsakeyfile GAATMP_x509dsakeyfile;
805         struct GAAOPTION_x509certfile GAATMP_x509certfile;
806         struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
807         struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
808         struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
809         struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
810         struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
811         struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
812         struct GAAOPTION_x509cafile GAATMP_x509cafile;
813         struct GAAOPTION_dhparams GAATMP_dhparams;
814         struct GAAOPTION_port GAATMP_port;
815         struct GAAOPTION_debug GAATMP_debug;
816
817 #line 393 "gaa.skel"
818 #ifdef GAA_REST_EXISTS
819     struct GAAREST GAAREST_tmp;
820 #endif
821
822     opt_list[gaa_num] = 1;
823     
824     for(gaa_last_non_option = gaa_index;
825         (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
826         gaa_last_non_option++);
827
828     if(gaa_num == GAA_REST)
829     {
830         gaa_index = 1;
831         gaa_last_non_option = GAAargc;
832     }
833     
834     switch(gaa_num)
835     {
836         case GAAOPTID_copyright:
837         OK = 0;
838 #line 116 "serv.gaa"
839 { print_serv_license(); exit(0); ;};
840
841                 return GAA_OK;
842                 break;
843         case GAAOPTID_version:
844         OK = 0;
845 #line 115 "serv.gaa"
846 { serv_version(); exit(0); ;};
847
848                 return GAA_OK;
849                 break;
850         case GAAOPTID_help:
851         OK = 0;
852 #line 113 "serv.gaa"
853 { gaa_help(); exit(0); ;};
854
855                 return GAA_OK;
856                 break;
857         case GAAOPTID_list:
858         OK = 0;
859 #line 112 "serv.gaa"
860 { print_list(0); exit(0); ;};
861
862                 return GAA_OK;
863                 break;
864         case GAAOPTID_ctypes:
865         OK = 0;
866                 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
867 #line 110 "serv.gaa"
868 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
869
870                 return GAA_OK;
871                 break;
872         case GAAOPTID_kx:
873         OK = 0;
874                 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
875 #line 106 "serv.gaa"
876 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
877
878                 return GAA_OK;
879                 break;
880         case GAAOPTID_macs:
881         OK = 0;
882                 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
883 #line 102 "serv.gaa"
884 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
885
886                 return GAA_OK;
887                 break;
888         case GAAOPTID_comp:
889         OK = 0;
890                 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
891 #line 98 "serv.gaa"
892 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
893
894                 return GAA_OK;
895                 break;
896         case GAAOPTID_protocols:
897         OK = 0;
898                 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
899 #line 94 "serv.gaa"
900 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
901
902                 return GAA_OK;
903                 break;
904         case GAAOPTID_ciphers:
905         OK = 0;
906                 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
907 #line 90 "serv.gaa"
908 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
909
910                 return GAA_OK;
911                 break;
912         case GAAOPTID_authz_saml_assertion:
913         OK = 0;
914                 GAA_TESTMOREARGS;
915                 GAA_FILL(GAATMP_authz_saml_assertion.arg1, gaa_getstr, GAATMP_authz_saml_assertion.size1);
916                 gaa_index++;
917 #line 86 "serv.gaa"
918 { gaaval->authz_saml_assertion = GAATMP_authz_saml_assertion.arg1 ;};
919
920                 return GAA_OK;
921                 break;
922         case GAAOPTID_authz_x509_attr_cert:
923         OK = 0;
924                 GAA_TESTMOREARGS;
925                 GAA_FILL(GAATMP_authz_x509_attr_cert.arg1, gaa_getstr, GAATMP_authz_x509_attr_cert.size1);
926                 gaa_index++;
927 #line 83 "serv.gaa"
928 { gaaval->authz_x509_attr_cert = GAATMP_authz_x509_attr_cert.arg1 ;};
929
930                 return GAA_OK;
931                 break;
932         case GAAOPTID_srppasswdconf:
933         OK = 0;
934                 GAA_TESTMOREARGS;
935                 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
936                 gaa_index++;
937 #line 80 "serv.gaa"
938 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
939
940                 return GAA_OK;
941                 break;
942         case GAAOPTID_srppasswd:
943         OK = 0;
944                 GAA_TESTMOREARGS;
945                 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
946                 gaa_index++;
947 #line 77 "serv.gaa"
948 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
949
950                 return GAA_OK;
951                 break;
952         case GAAOPTID_pskpasswd:
953         OK = 0;
954                 GAA_TESTMOREARGS;
955                 GAA_FILL(GAATMP_pskpasswd.arg1, gaa_getstr, GAATMP_pskpasswd.size1);
956                 gaa_index++;
957 #line 74 "serv.gaa"
958 { gaaval->psk_passwd = GAATMP_pskpasswd.arg1 ;};
959
960                 return GAA_OK;
961                 break;
962         case GAAOPTID_disable_client_cert:
963         OK = 0;
964 #line 71 "serv.gaa"
965 { gaaval->disable_client_cert = 1 ;};
966
967                 return GAA_OK;
968                 break;
969         case GAAOPTID_require_cert:
970         OK = 0;
971 #line 68 "serv.gaa"
972 { gaaval->require_cert = 1 ;};
973
974                 return GAA_OK;
975                 break;
976         case GAAOPTID_x509dsacertfile:
977         OK = 0;
978                 GAA_TESTMOREARGS;
979                 GAA_FILL(GAATMP_x509dsacertfile.arg1, gaa_getstr, GAATMP_x509dsacertfile.size1);
980                 gaa_index++;
981 #line 65 "serv.gaa"
982 { gaaval->x509_dsacertfile = GAATMP_x509dsacertfile.arg1 ;};
983
984                 return GAA_OK;
985                 break;
986         case GAAOPTID_x509dsakeyfile:
987         OK = 0;
988                 GAA_TESTMOREARGS;
989                 GAA_FILL(GAATMP_x509dsakeyfile.arg1, gaa_getstr, GAATMP_x509dsakeyfile.size1);
990                 gaa_index++;
991 #line 62 "serv.gaa"
992 { gaaval->x509_dsakeyfile = GAATMP_x509dsakeyfile.arg1 ;};
993
994                 return GAA_OK;
995                 break;
996         case GAAOPTID_x509certfile:
997         OK = 0;
998                 GAA_TESTMOREARGS;
999                 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
1000                 gaa_index++;
1001 #line 59 "serv.gaa"
1002 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
1003
1004                 return GAA_OK;
1005                 break;
1006         case GAAOPTID_x509keyfile:
1007         OK = 0;
1008                 GAA_TESTMOREARGS;
1009                 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
1010                 gaa_index++;
1011 #line 56 "serv.gaa"
1012 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
1013
1014                 return GAA_OK;
1015                 break;
1016         case GAAOPTID_pgpcertfile:
1017         OK = 0;
1018                 GAA_TESTMOREARGS;
1019                 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
1020                 gaa_index++;
1021 #line 53 "serv.gaa"
1022 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
1023
1024                 return GAA_OK;
1025                 break;
1026         case GAAOPTID_pgpkeyfile:
1027         OK = 0;
1028                 GAA_TESTMOREARGS;
1029                 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
1030                 gaa_index++;
1031 #line 50 "serv.gaa"
1032 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
1033
1034                 return GAA_OK;
1035                 break;
1036         case GAAOPTID_pgptrustdb:
1037         OK = 0;
1038                 GAA_TESTMOREARGS;
1039                 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
1040                 gaa_index++;
1041 #line 47 "serv.gaa"
1042 { gaaval->pgp_trustdb = GAATMP_pgptrustdb.arg1 ;};
1043
1044                 return GAA_OK;
1045                 break;
1046         case GAAOPTID_pgpkeyring:
1047         OK = 0;
1048                 GAA_TESTMOREARGS;
1049                 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
1050                 gaa_index++;
1051 #line 44 "serv.gaa"
1052 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
1053
1054                 return GAA_OK;
1055                 break;
1056         case GAAOPTID_x509crlfile:
1057         OK = 0;
1058                 GAA_TESTMOREARGS;
1059                 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1060                 gaa_index++;
1061 #line 41 "serv.gaa"
1062 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1063
1064                 return GAA_OK;
1065                 break;
1066         case GAAOPTID_x509cafile:
1067         OK = 0;
1068                 GAA_TESTMOREARGS;
1069                 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1070                 gaa_index++;
1071 #line 38 "serv.gaa"
1072 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1073
1074                 return GAA_OK;
1075                 break;
1076         case GAAOPTID_x509fmtder:
1077         OK = 0;
1078 #line 35 "serv.gaa"
1079 { gaaval->fmtder = 1 ;};
1080
1081                 return GAA_OK;
1082                 break;
1083         case GAAOPTID_dhparams:
1084         OK = 0;
1085                 GAA_TESTMOREARGS;
1086                 GAA_FILL(GAATMP_dhparams.arg1, gaa_getstr, GAATMP_dhparams.size1);
1087                 gaa_index++;
1088 #line 32 "serv.gaa"
1089 { gaaval->dh_params_file = GAATMP_dhparams.arg1 ;};
1090
1091                 return GAA_OK;
1092                 break;
1093         case GAAOPTID_echo:
1094         OK = 0;
1095 #line 29 "serv.gaa"
1096 { gaaval->http = 0 ;};
1097
1098                 return GAA_OK;
1099                 break;
1100         case GAAOPTID_http:
1101         OK = 0;
1102 #line 28 "serv.gaa"
1103 { gaaval->http = 1 ;};
1104
1105                 return GAA_OK;
1106                 break;
1107         case GAAOPTID_nodb:
1108         OK = 0;
1109 #line 25 "serv.gaa"
1110 { gaaval->nodb = 1 ;};
1111
1112                 return GAA_OK;
1113                 break;
1114         case GAAOPTID_quiet:
1115         OK = 0;
1116 #line 22 "serv.gaa"
1117 { gaaval->quiet = 1 ;};
1118
1119                 return GAA_OK;
1120                 break;
1121         case GAAOPTID_port:
1122         OK = 0;
1123                 GAA_TESTMOREARGS;
1124                 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
1125                 gaa_index++;
1126 #line 19 "serv.gaa"
1127 { gaaval->port = GAATMP_port.arg1 ;};
1128
1129                 return GAA_OK;
1130                 break;
1131         case GAAOPTID_generate:
1132         OK = 0;
1133 #line 16 "serv.gaa"
1134 { gaaval->generate = 1 ;};
1135
1136                 return GAA_OK;
1137                 break;
1138         case GAAOPTID_debug:
1139         OK = 0;
1140                 GAA_TESTMOREARGS;
1141                 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1142                 gaa_index++;
1143 #line 13 "serv.gaa"
1144 { gaaval->debug = GAATMP_debug.arg1 ;};
1145
1146                 return GAA_OK;
1147                 break;
1148
1149 #line 413 "gaa.skel"
1150     default: break;
1151     }
1152     return GAA_ERROR_UNKNOWN;
1153 }
1154
1155 int gaa(int argc, char **argv, gaainfo *gaaval)
1156 {
1157     int tmp1, tmp2;
1158     int i, j, k;
1159     char *opt_list;
1160
1161     GAAargv = argv;
1162     GAAargc = argc;
1163
1164     opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1165
1166     for(i = 0; i < GAA_NB_OPTION + 1; i++)
1167         opt_list[i] = 0;
1168     /* initialization */
1169     if(inited == 0)
1170     {
1171
1172 #line 120 "serv.gaa"
1173 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
1174         gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1175         gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->nodb = 0;
1176         gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
1177         gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->x509_crlfile = NULL;
1178         gaaval->x509_dsakeyfile=NULL; gaaval->x509_dsacertfile=NULL; 
1179         gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL; gaaval->quiet = 0;
1180         gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL; gaaval->fmtder = 0; gaaval->disable_client_cert = 0;
1181         gaaval->dh_params_file=NULL; gaaval->debug=0; gaaval->require_cert = 0; gaaval->psk_passwd = 0; ;};
1182
1183     }
1184     inited = 1;
1185 #line 438 "gaa.skel"
1186     gaa_arg_used = NULL;
1187
1188     if (argc > 0) {
1189       gaa_arg_used = gaa_malloc(argc * sizeof(char));
1190     }
1191
1192     for(i = 1; i < argc; i++)
1193         gaa_arg_used[i] = 0;
1194     for(i = 1; i < argc; i++)
1195     {
1196         if(gaa_arg_used[i] == 0)
1197         {
1198             j = 0;
1199             tmp1 = gaa_is_an_argument(GAAargv[i]);
1200             switch(tmp1)
1201             {
1202             case GAA_WORD_OPTION:
1203                 j++;
1204             case GAA_LETTER_OPTION:
1205                 j++;
1206                 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1207                 if(tmp2 == GAA_ERROR_NOMATCH)
1208                 {
1209                     printf("Invalid option '%s'\n", argv[i]+j);
1210                     return 0;
1211                 }
1212                 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1213                 {
1214                 case GAA_ERROR_NOTENOUGH_ARGS:
1215                     printf("'%s': not enough arguments\n",gaa_current_option);
1216                     return 0;
1217                 case GAA_ERROR_INVALID_ARG:
1218                     printf("Invalid arguments\n");
1219                     return 0;
1220                 case GAA_OK:
1221                     break;
1222                 default:
1223                     printf("Unknown error\n");
1224                 }
1225                 gaa_arg_used[i] = 1;
1226                 break;
1227             case GAA_MULTIPLE_OPTION:
1228                 for(j = 1; j < strlen(argv[i]); j++)
1229                 {
1230                     tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1231                     if(tmp2 == GAA_ERROR_NOMATCH)
1232                     {
1233                         printf("Invalid option '%c'\n", *(argv[i]+j));
1234                         return 0;
1235                     }
1236                     switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1237                     {
1238                     case GAA_ERROR_NOTENOUGH_ARGS:
1239                         printf("'%s': not enough arguments\n",gaa_current_option);
1240                         return 0;
1241                     case GAA_ERROR_INVALID_ARG:
1242                         printf("Invalid arguments\n");
1243                         return 0;
1244                     case GAA_OK:
1245                         break;
1246                     default:
1247                         printf("Unknown error\n");
1248                     }
1249                 }
1250                 gaa_arg_used[i] = 1;
1251                 break;
1252             default: break;
1253             }
1254         }
1255     }
1256 if(gaa_processing_file == 0)
1257 {
1258         GAA_INCOMP("ra");
1259
1260 #line 507 "gaa.skel"
1261 #ifdef GAA_REST_EXISTS
1262     switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1263     {
1264     case GAA_ERROR_NOTENOUGH_ARGS:
1265         printf("Rest: not enough arguments\n");
1266         return 0;
1267     case GAA_ERROR_INVALID_ARG:
1268         printf("Invalid arguments\n");
1269         return 0;
1270     case GAA_OK:
1271         break;
1272     default:
1273         printf("Unknown error\n");
1274     }
1275 #endif
1276 }
1277     for(i = 1; i < argc; i++)
1278     {
1279         if(gaa_arg_used[i] == 0)
1280         {
1281             printf("Too many arguments\n");
1282             return 0;
1283         }
1284     }
1285     free(gaa_arg_used);
1286     free(opt_list);
1287     return -1;
1288 }
1289
1290 struct gaastrnode
1291 {
1292     char *str;
1293     struct gaastrnode *next;
1294 };
1295
1296 typedef struct gaastrnode gaa_str_node;
1297
1298 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1299 {
1300     int pos_ini;
1301     int a;
1302     int i = 0, len = 0, newline = 0;
1303
1304     if(argc == 1) {
1305         newline = 1;
1306         len = 2;
1307     }
1308     
1309     a = fgetc( file);
1310     if (a == EOF) return 0;
1311
1312     while(a == ' ' || a == 9 || a == '\n')
1313     {
1314         if(a == '\n')
1315         {
1316             newline=1;
1317             len = 2;
1318         }
1319         a = fgetc( file);
1320         if (a == EOF) return 0;
1321     }
1322
1323     pos_ini = ftell(file) - 1;
1324
1325     while(a != ' ' && a != 9 && a != '\n')
1326     {
1327
1328         len++;
1329         a = fgetc( file);
1330         if(a==EOF) return 0; //a = ' ';
1331     }
1332
1333     len += 1;
1334     tmp_str->str = gaa_malloc((len) * sizeof(char));
1335
1336     if(newline == 1)
1337     {
1338         tmp_str->str[0] = '-';
1339         tmp_str->str[1] = '-';
1340         i = 2;
1341     }
1342     else
1343     {
1344         i = 0;
1345     }
1346
1347     fseek(file,pos_ini, SEEK_SET);
1348     do
1349     {
1350         a = fgetc( file);
1351
1352         if (a == EOF) {
1353             i+=2;
1354             break;
1355         }
1356         tmp_str->str[i] = a;
1357         i++;
1358     }
1359     while(a != ' ' && a != 9 && a != '\n' && i < len);
1360
1361     tmp_str->str[i - 1] = 0;
1362
1363     fseek(file,- 1, SEEK_CUR);
1364 /*    printf("%d\n", ftell(file)); */
1365     
1366     return -1;
1367 }
1368
1369 int gaa_file(const char *name, gaainfo *gaaval)
1370 {
1371     gaa_str_node *first_str, **tmp_str, *tmp_str2;
1372     int rval, i;
1373     char **argv;
1374     int argc = 0;
1375     FILE *file;
1376
1377     gaa_processing_file = 1;
1378     
1379     if((file = fopen(name, "r")) == NULL)
1380     {
1381         printf("Couldn't open '%s' configuration file for reading\n", name);
1382         return 1;
1383     }
1384     
1385     tmp_str = &first_str;
1386     do
1387     {
1388         argc++;
1389         *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1390
1391         (*tmp_str)->str = NULL;
1392         (*tmp_str)->next = NULL;
1393
1394         rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1395         tmp_str = &((*tmp_str)->next);
1396     }
1397     while(rval == -1);
1398     
1399     if(rval == 1)
1400         return 0;
1401     
1402     argv = gaa_malloc((1 + argc) * sizeof(char*));
1403
1404     tmp_str2 = first_str;
1405     argv[0] = "cfg";
1406     for(i = 1; i < argc; i++)
1407     {
1408         argv[i] = tmp_str2->str;
1409         tmp_str2 = tmp_str2->next;
1410     }
1411
1412     rval = gaa(argc, argv, gaaval);
1413     gaa_processing_file = 0;
1414     return rval;
1415 }