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