Improved PKCS7 support
[gnutls.git] / src / serv-gaa.c
blobbcad4c839f9c2e5327d822bea7a490c8706073fd
1 /* File generated by GAA 1.6.0
2 */
3 #define GAA_NO_WIN32
4 #line 80 "serv.gaa"
6 #include <common.h>
7 #include <stdio.h>
8 #include <string.h>
10 #ifndef GAA_NO_WIN32
11 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
12 #define GAA_WIN32
13 #endif
14 #endif
16 void __gaa_helpsingle(char short_name, char *name,
17 char *arg_desc, char *opt_help)
19 int col1, col3, col4, tabsize = 3, curr;
20 int i;
22 col1 = 5; /* Default values */
23 col3 = 30;
24 col4 = 70;
26 curr = 0;
27 for(i = 0; i < col1; i++)
29 printf(" ");
30 curr++;
32 if(short_name)
34 if(name && *name)
36 printf("-%c, ", short_name);
37 curr += 4;
39 else
41 printf("-%c ", short_name);
42 curr += 3;
45 if(name && *name)
47 printf("--%s ", name);
48 curr += 3 + strlen(name);
50 if(arg_desc && *arg_desc)
52 printf("%s ", arg_desc);
53 curr += 1 + strlen(arg_desc);
55 if(curr >= col3)
57 printf("\n");
58 curr = 0;
60 if(opt_help) /* let's print the option's help body */
62 const char *str = opt_help;
63 while(*str)
65 while(curr < col3)
67 printf(" ");
68 curr++;
70 switch(*str)
72 case '\n':
73 printf("\n");
74 curr = 0;
75 break;
76 case '\t':
79 printf(" ");
80 curr++;
82 while((curr - col3) % tabsize != 0 && curr < col4);
83 case ' ':
84 if(*str == ' ')
86 curr++;
87 printf(" ");
89 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
90 && str[i] != '\t'; i++);
91 if(curr + i - 1 >= col4)
92 curr = col4;
93 break;
94 default:
95 printf("%c", *str);
96 curr++;
98 if(curr >= col4)
100 printf("\n");
101 curr = 0;
103 str++;
106 printf("\n");
109 void gaa_help(void)
111 printf("gnutls-serv help\nUsage: gnutls-serv [options]""\n");
112 __gaa_helpsingle('g', "generate", "", "Generate Diffie Hellman Parameters.");
113 __gaa_helpsingle('p', "port", """integer"" ", "The port to connect to.");
114 __gaa_helpsingle(0, "http", "", "Act as an HTTP Server.");
115 __gaa_helpsingle(0, "x509cafile", """FILE"" ", "Certificate file to use.");
116 __gaa_helpsingle(0, "pgpkeyring", """FILE"" ", "PGP Key ring file to use.");
117 __gaa_helpsingle(0, "pgptrustdb", """FILE"" ", "PGP trustdb file to use.");
118 __gaa_helpsingle(0, "pgpkeyfile", """FILE"" ", "PGP Key file to use.");
119 __gaa_helpsingle(0, "pgpcertfile", """FILE"" ", "PGP Public Key (certificate) file to use.");
120 __gaa_helpsingle(0, "x509keyfile", """FILE"" ", "X.509 key file to use.");
121 __gaa_helpsingle(0, "x509certfile", """FILE"" ", "X.509 Certificate file to use.");
122 __gaa_helpsingle(0, "pgpkeyserver", """FILE"" ", "PGP Keyserver to use.");
123 __gaa_helpsingle(0, "srppasswd", """FILE"" ", "SRP password file to use.");
124 __gaa_helpsingle(0, "srppasswdconf", """FILE"" ", "SRP password conf file to use.");
125 __gaa_helpsingle(0, "ciphers", """cipher1 cipher2..."" ", "Ciphers to enable.");
126 __gaa_helpsingle(0, "protocols", """protocol1 protocol2..."" ", "Protocols to enable.");
127 __gaa_helpsingle(0, "comp", """comp1 comp2..."" ", "Compression methods to enable.");
128 __gaa_helpsingle(0, "macs", """mac1 mac2..."" ", "MACs to enable.");
129 __gaa_helpsingle(0, "kx", """kx1 kx2..."" ", "Key exchange methods to enable.");
130 __gaa_helpsingle(0, "ctypes", """certType1 certType2..."" ", "Certificate types to enable.");
131 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
132 __gaa_helpsingle('h', "help", "", "prints this help");
134 #line 100 "gaa.skel"
136 /* Copy of C area */
138 #line 104 "gaa.skel"
139 /* GAA HEADER */
140 #ifndef GAA_HEADER_POKY
141 #define GAA_HEADER_POKY
143 typedef struct _gaainfo gaainfo;
145 struct _gaainfo
147 #line 64 "serv.gaa"
148 char **ctype;
149 #line 63 "serv.gaa"
150 int nctype;
151 #line 60 "serv.gaa"
152 char **kx;
153 #line 59 "serv.gaa"
154 int nkx;
155 #line 56 "serv.gaa"
156 char **macs;
157 #line 55 "serv.gaa"
158 int nmacs;
159 #line 52 "serv.gaa"
160 char **comp;
161 #line 51 "serv.gaa"
162 int ncomp;
163 #line 48 "serv.gaa"
164 char **proto;
165 #line 47 "serv.gaa"
166 int nproto;
167 #line 44 "serv.gaa"
168 char **ciphers;
169 #line 43 "serv.gaa"
170 int nciphers;
171 #line 39 "serv.gaa"
172 char *srp_passwd_conf;
173 #line 36 "serv.gaa"
174 char *srp_passwd;
175 #line 33 "serv.gaa"
176 char *pgp_keyserver;
177 #line 30 "serv.gaa"
178 char *x509_certfile;
179 #line 27 "serv.gaa"
180 char *x509_keyfile;
181 #line 24 "serv.gaa"
182 char *pgp_certfile;
183 #line 21 "serv.gaa"
184 char *pgp_keyfile;
185 #line 18 "serv.gaa"
186 char *pgp_trustdb;
187 #line 15 "serv.gaa"
188 char *pgp_keyring;
189 #line 12 "serv.gaa"
190 char *x509_cafile;
191 #line 9 "serv.gaa"
192 int http;
193 #line 6 "serv.gaa"
194 int port;
195 #line 3 "serv.gaa"
196 int generate;
198 #line 114 "gaa.skel"
201 #ifdef __cplusplus
202 extern "C"
204 #endif
206 int gaa(int argc, char *argv[], gaainfo *gaaval);
208 void gaa_help(void);
210 int gaa_file(char *name, gaainfo *gaaval);
212 #ifdef __cplusplus
214 #endif
217 #endif
219 #line 135 "gaa.skel"
221 /* C declarations */
223 #define GAAERROR(x) \
225 gaa_error = 1; \
226 return x; \
229 char *gaa_current_option;
230 int gaa_error = 0;
232 /* Generated by gaa */
234 #include <string.h>
235 #include <stdlib.h>
238 #define GAA_OK -1
240 #define GAA_ERROR_NOMATCH 0
241 #define GAA_ERROR_NOTENOUGH_ARGS 1
242 #define GAA_ERROR_INVALID_ARG 2
243 #define GAA_ERROR_UNKNOWN 3
245 #define GAA_NOT_AN_OPTION 0
246 #define GAA_WORD_OPTION 1
247 #define GAA_LETTER_OPTION 2
248 #define GAA_MULTIPLE_OPTION 3
250 #define GAA_REST 0
251 #define GAA_NB_OPTION 21
252 #define GAAOPTID_help 1
253 #define GAAOPTID_list 2
254 #define GAAOPTID_ctypes 3
255 #define GAAOPTID_kx 4
256 #define GAAOPTID_macs 5
257 #define GAAOPTID_comp 6
258 #define GAAOPTID_protocols 7
259 #define GAAOPTID_ciphers 8
260 #define GAAOPTID_srppasswdconf 9
261 #define GAAOPTID_srppasswd 10
262 #define GAAOPTID_pgpkeyserver 11
263 #define GAAOPTID_x509certfile 12
264 #define GAAOPTID_x509keyfile 13
265 #define GAAOPTID_pgpcertfile 14
266 #define GAAOPTID_pgpkeyfile 15
267 #define GAAOPTID_pgptrustdb 16
268 #define GAAOPTID_pgpkeyring 17
269 #define GAAOPTID_x509cafile 18
270 #define GAAOPTID_http 19
271 #define GAAOPTID_port 20
272 #define GAAOPTID_generate 21
274 #line 168 "gaa.skel"
276 #define GAA_CHECK1STR(a,b) \
277 if(a[0] == str[0]) \
279 gaa_current_option = a; \
280 return b; \
283 #define GAA_CHECKSTR(a,b) \
284 if(strcmp(a,str) == 0) \
286 gaa_current_option = a; \
287 return b; \
290 #define GAA_TESTMOREARGS \
291 if(!OK) \
293 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
294 gaa_index++; \
295 if(gaa_last_non_option == gaa_index) \
296 return GAA_ERROR_NOTENOUGH_ARGS; \
299 #define GAA_TESTMOREOPTIONALARGS \
300 if(!OK) \
302 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
303 gaa_index++; \
304 if(gaa_last_non_option == gaa_index) \
305 OK = 1; \
308 #define GAA_FILL_2ARGS(target, func) \
309 target = func(GAAargv[gaa_index]); \
310 gaa_arg_used[gaa_index] = 1; \
311 if(gaa_error == 1) \
313 gaa_error = 0; \
314 return GAA_ERROR_INVALID_ARG; \
319 #define GAA_FILL(target, func, num) \
320 if(!OK) \
322 target = func(GAAargv[gaa_index]); \
323 gaa_arg_used[gaa_index] = 1; \
324 if(gaa_error == 1) \
326 gaa_error = 0; \
327 return GAA_ERROR_INVALID_ARG; \
329 num = 1; \
331 else \
333 num = 0; \
336 #define GAA_LIST_FILL(target, func, type ,num) \
337 if(!OK) \
339 num = 0; \
340 target = NULL; \
341 if ( gaa_last_non_option - gaa_index > 0) \
342 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
343 for(; gaa_index < gaa_last_non_option; gaa_index++) \
345 if(gaa_arg_used[gaa_index] == 0) \
347 GAA_FILL_2ARGS(target[num], func); \
348 num++; \
351 if(num == 0) \
352 return GAA_ERROR_NOTENOUGH_ARGS; \
355 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
356 if(!OK) \
358 num = 0; \
359 target = NULL; \
360 if ( gaa_last_non_option - gaa_index > 0) \
361 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
362 for(; gaa_index < gaa_last_non_option; gaa_index++) \
364 if(gaa_arg_used[gaa_index] == 0) \
366 GAA_FILL_2ARGS(target[num], func); \
367 num++; \
372 #define GAA_OBLIGAT(str) \
373 k = 0; \
374 for(i = 0; i < strlen(str); i++) \
376 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
377 if(j == GAA_ERROR_NOMATCH) \
379 printf("Error: invalid 'obligat' set\n"); \
380 exit(-1); \
382 if(opt_list[j] == 1) \
383 k = 1; \
385 if(k == 0) \
387 if(strlen(str) == 1) \
388 printf("You must give the -%s option\n", str); \
389 else \
390 printf("You must give at least one option of '%s'\n", str); \
391 return 0; \
394 #define GAA_INCOMP(str) \
395 k = 0; \
396 for(i = 0; i < strlen(str); i++) \
398 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
399 if(j == GAA_ERROR_NOMATCH) \
401 printf("Error: invalid 'obligat' set\n"); \
402 exit(-1); \
404 if(opt_list[j] == 1) \
405 k++; \
407 if(k > 1) \
409 printf("The options '%s' are incompatible\n", str); \
410 return 0; \
414 char **GAAargv;
415 int GAAargc;
416 char *gaa_arg_used;
417 int gaa_processing_file = 0;
418 int inited = 0;
420 int gaa_getint(char *arg)
422 int tmp;
423 char a;
424 if(sscanf(arg, "%d%c", &tmp, &a) != 1)
426 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
427 GAAERROR(-1);
429 return tmp;
432 char gaa_getchar(char *arg)
434 if(strlen(arg) != 1)
436 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
437 GAAERROR(-1);
439 return arg[0];
442 char* gaa_getstr(char *arg)
444 return arg;
446 float gaa_getfloat(char *arg)
448 float tmp;
449 char a;
450 if(sscanf(arg, "%f%c", &tmp, &a) != 1)
452 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
453 GAAERROR(-1);
455 return tmp;
457 /* option structures */
459 struct GAAOPTION_ctypes
461 char** arg1;
462 int size1;
465 struct GAAOPTION_kx
467 char** arg1;
468 int size1;
471 struct GAAOPTION_macs
473 char** arg1;
474 int size1;
477 struct GAAOPTION_comp
479 char** arg1;
480 int size1;
483 struct GAAOPTION_protocols
485 char** arg1;
486 int size1;
489 struct GAAOPTION_ciphers
491 char** arg1;
492 int size1;
495 struct GAAOPTION_srppasswdconf
497 char* arg1;
498 int size1;
501 struct GAAOPTION_srppasswd
503 char* arg1;
504 int size1;
507 struct GAAOPTION_pgpkeyserver
509 char* arg1;
510 int size1;
513 struct GAAOPTION_x509certfile
515 char* arg1;
516 int size1;
519 struct GAAOPTION_x509keyfile
521 char* arg1;
522 int size1;
525 struct GAAOPTION_pgpcertfile
527 char* arg1;
528 int size1;
531 struct GAAOPTION_pgpkeyfile
533 char* arg1;
534 int size1;
537 struct GAAOPTION_pgptrustdb
539 char* arg1;
540 int size1;
543 struct GAAOPTION_pgpkeyring
545 char* arg1;
546 int size1;
549 struct GAAOPTION_x509cafile
551 char* arg1;
552 int size1;
555 struct GAAOPTION_port
557 int arg1;
558 int size1;
561 #line 349 "gaa.skel"
562 int gaa_is_an_argument(char *str)
564 #ifdef GAA_WIN32
565 if(str[0] == '/' && str[1] != 0)
566 return GAA_MULTIPLE_OPTION;
567 #endif
568 if(str[0] != '-')
569 return GAA_NOT_AN_OPTION;
570 if(str[1] == 0)
571 return GAA_NOT_AN_OPTION;
572 if(str[1] == '-')
574 if(str[2] != 0)
575 return GAA_WORD_OPTION;
576 else
577 return GAA_NOT_AN_OPTION;
579 if(str[2] == 0)
580 return GAA_LETTER_OPTION;
581 else
582 return GAA_MULTIPLE_OPTION;
585 int gaa_get_option_num(char *str, int status)
587 switch(status)
589 case GAA_LETTER_OPTION:
590 GAA_CHECK1STR("", GAAOPTID_ctypes);
591 GAA_CHECK1STR("", GAAOPTID_kx);
592 GAA_CHECK1STR("", GAAOPTID_macs);
593 GAA_CHECK1STR("", GAAOPTID_comp);
594 GAA_CHECK1STR("", GAAOPTID_protocols);
595 GAA_CHECK1STR("", GAAOPTID_ciphers);
596 GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
597 GAA_CHECK1STR("", GAAOPTID_srppasswd);
598 GAA_CHECK1STR("", GAAOPTID_pgpkeyserver);
599 GAA_CHECK1STR("", GAAOPTID_x509certfile);
600 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
601 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
602 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
603 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
604 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
605 GAA_CHECK1STR("", GAAOPTID_x509cafile);
606 GAA_CHECK1STR("p", GAAOPTID_port);
607 case GAA_MULTIPLE_OPTION:
608 #line 375 "gaa.skel"
609 GAA_CHECK1STR("h", GAAOPTID_help);
610 GAA_CHECK1STR("l", GAAOPTID_list);
611 GAA_CHECK1STR("", GAAOPTID_http);
612 GAA_CHECK1STR("g", GAAOPTID_generate);
614 #line 277 "gaa.skel"
615 break;
616 case GAA_WORD_OPTION:
617 GAA_CHECKSTR("help", GAAOPTID_help);
618 GAA_CHECKSTR("list", GAAOPTID_list);
619 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
620 GAA_CHECKSTR("kx", GAAOPTID_kx);
621 GAA_CHECKSTR("macs", GAAOPTID_macs);
622 GAA_CHECKSTR("comp", GAAOPTID_comp);
623 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
624 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
625 GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
626 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
627 GAA_CHECKSTR("pgpkeyserver", GAAOPTID_pgpkeyserver);
628 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
629 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
630 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
631 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
632 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
633 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
634 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
635 GAA_CHECKSTR("http", GAAOPTID_http);
636 GAA_CHECKSTR("port", GAAOPTID_port);
637 GAA_CHECKSTR("generate", GAAOPTID_generate);
639 #line 281 "gaa.skel"
640 break;
641 default: break;
643 return GAA_ERROR_NOMATCH;
646 int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
648 int OK = 0;
649 int gaa_last_non_option;
650 struct GAAOPTION_ctypes GAATMP_ctypes;
651 struct GAAOPTION_kx GAATMP_kx;
652 struct GAAOPTION_macs GAATMP_macs;
653 struct GAAOPTION_comp GAATMP_comp;
654 struct GAAOPTION_protocols GAATMP_protocols;
655 struct GAAOPTION_ciphers GAATMP_ciphers;
656 struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
657 struct GAAOPTION_srppasswd GAATMP_srppasswd;
658 struct GAAOPTION_pgpkeyserver GAATMP_pgpkeyserver;
659 struct GAAOPTION_x509certfile GAATMP_x509certfile;
660 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
661 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
662 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
663 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
664 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
665 struct GAAOPTION_x509cafile GAATMP_x509cafile;
666 struct GAAOPTION_port GAATMP_port;
668 #line 393 "gaa.skel"
669 #ifdef GAA_REST_EXISTS
670 struct GAAREST GAAREST_tmp;
671 #endif
673 opt_list[gaa_num] = 1;
675 for(gaa_last_non_option = gaa_index;
676 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
677 gaa_last_non_option++);
679 if(gaa_num == GAA_REST)
681 gaa_index = 1;
682 gaa_last_non_option = GAAargc;
685 switch(gaa_num)
687 case GAAOPTID_help:
688 OK = 0;
689 #line 69 "serv.gaa"
690 { gaa_help(); exit(0); ;};
692 return GAA_OK;
693 break;
694 case GAAOPTID_list:
695 OK = 0;
696 #line 68 "serv.gaa"
697 { print_list(); exit(0); ;};
699 return GAA_OK;
700 break;
701 case GAAOPTID_ctypes:
702 OK = 0;
703 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
704 #line 65 "serv.gaa"
705 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
707 return GAA_OK;
708 break;
709 case GAAOPTID_kx:
710 OK = 0;
711 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
712 #line 61 "serv.gaa"
713 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
715 return GAA_OK;
716 break;
717 case GAAOPTID_macs:
718 OK = 0;
719 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
720 #line 57 "serv.gaa"
721 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
723 return GAA_OK;
724 break;
725 case GAAOPTID_comp:
726 OK = 0;
727 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
728 #line 53 "serv.gaa"
729 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
731 return GAA_OK;
732 break;
733 case GAAOPTID_protocols:
734 OK = 0;
735 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
736 #line 49 "serv.gaa"
737 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
739 return GAA_OK;
740 break;
741 case GAAOPTID_ciphers:
742 OK = 0;
743 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
744 #line 45 "serv.gaa"
745 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
747 return GAA_OK;
748 break;
749 case GAAOPTID_srppasswdconf:
750 OK = 0;
751 GAA_TESTMOREARGS;
752 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
753 gaa_index++;
754 #line 40 "serv.gaa"
755 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
757 return GAA_OK;
758 break;
759 case GAAOPTID_srppasswd:
760 OK = 0;
761 GAA_TESTMOREARGS;
762 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
763 gaa_index++;
764 #line 37 "serv.gaa"
765 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
767 return GAA_OK;
768 break;
769 case GAAOPTID_pgpkeyserver:
770 OK = 0;
771 GAA_TESTMOREARGS;
772 GAA_FILL(GAATMP_pgpkeyserver.arg1, gaa_getstr, GAATMP_pgpkeyserver.size1);
773 gaa_index++;
774 #line 34 "serv.gaa"
775 { gaaval->pgp_keyserver = GAATMP_pgpkeyserver.arg1 ;};
777 return GAA_OK;
778 break;
779 case GAAOPTID_x509certfile:
780 OK = 0;
781 GAA_TESTMOREARGS;
782 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
783 gaa_index++;
784 #line 31 "serv.gaa"
785 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
787 return GAA_OK;
788 break;
789 case GAAOPTID_x509keyfile:
790 OK = 0;
791 GAA_TESTMOREARGS;
792 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
793 gaa_index++;
794 #line 28 "serv.gaa"
795 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
797 return GAA_OK;
798 break;
799 case GAAOPTID_pgpcertfile:
800 OK = 0;
801 GAA_TESTMOREARGS;
802 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
803 gaa_index++;
804 #line 25 "serv.gaa"
805 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
807 return GAA_OK;
808 break;
809 case GAAOPTID_pgpkeyfile:
810 OK = 0;
811 GAA_TESTMOREARGS;
812 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
813 gaa_index++;
814 #line 22 "serv.gaa"
815 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
817 return GAA_OK;
818 break;
819 case GAAOPTID_pgptrustdb:
820 OK = 0;
821 GAA_TESTMOREARGS;
822 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
823 gaa_index++;
824 #line 19 "serv.gaa"
825 { gaaval->pgp_keyring = GAATMP_pgptrustdb.arg1 ;};
827 return GAA_OK;
828 break;
829 case GAAOPTID_pgpkeyring:
830 OK = 0;
831 GAA_TESTMOREARGS;
832 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
833 gaa_index++;
834 #line 16 "serv.gaa"
835 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
837 return GAA_OK;
838 break;
839 case GAAOPTID_x509cafile:
840 OK = 0;
841 GAA_TESTMOREARGS;
842 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
843 gaa_index++;
844 #line 13 "serv.gaa"
845 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
847 return GAA_OK;
848 break;
849 case GAAOPTID_http:
850 OK = 0;
851 #line 10 "serv.gaa"
852 { gaaval->http = 1 ;};
854 return GAA_OK;
855 break;
856 case GAAOPTID_port:
857 OK = 0;
858 GAA_TESTMOREARGS;
859 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
860 gaa_index++;
861 #line 7 "serv.gaa"
862 { gaaval->port = GAATMP_port.arg1 ;};
864 return GAA_OK;
865 break;
866 case GAAOPTID_generate:
867 OK = 0;
868 #line 4 "serv.gaa"
869 { gaaval->generate = 1 ;};
871 return GAA_OK;
872 break;
874 #line 413 "gaa.skel"
875 default: break;
877 return GAA_ERROR_UNKNOWN;
880 int gaa(int argc, char **argv, gaainfo *gaaval)
882 int tmp1, tmp2;
883 int i, j;
884 char *opt_list;
886 GAAargv = argv;
887 GAAargc = argc;
889 opt_list = (char*) malloc(GAA_NB_OPTION + 1);
890 for(i = 0; i < GAA_NB_OPTION + 1; i++)
891 opt_list[i] = 0;
892 /* initialization */
893 if(inited == 0)
896 #line 71 "serv.gaa"
897 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
898 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
899 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0;
900 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
901 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->pgp_keyserver=NULL;
902 gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL;
903 gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL; ;};
906 inited = 1;
907 #line 438 "gaa.skel"
908 gaa_arg_used = NULL;
910 if (argc > 0)
911 gaa_arg_used = malloc(argc * sizeof(char));
912 for(i = 1; i < argc; i++)
913 gaa_arg_used[i] = 0;
914 for(i = 1; i < argc; i++)
916 if(gaa_arg_used[i] == 0)
918 j = 0;
919 tmp1 = gaa_is_an_argument(GAAargv[i]);
920 switch(tmp1)
922 case GAA_WORD_OPTION:
923 j++;
924 case GAA_LETTER_OPTION:
925 j++;
926 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
927 if(tmp2 == GAA_ERROR_NOMATCH)
929 printf("Invalid option '%s'\n", argv[i]+j);
930 return 0;
932 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
934 case GAA_ERROR_NOTENOUGH_ARGS:
935 printf("'%s': not enough arguments\n",gaa_current_option);
936 return 0;
937 case GAA_ERROR_INVALID_ARG:
938 printf("Invalid arguments\n");
939 return 0;
940 case GAA_OK:
941 break;
942 default:
943 printf("Unknown error\n");
945 gaa_arg_used[i] = 1;
946 break;
947 case GAA_MULTIPLE_OPTION:
948 for(j = 1; j < strlen(argv[i]); j++)
950 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
951 if(tmp2 == GAA_ERROR_NOMATCH)
953 printf("Invalid option '%c'\n", *(argv[i]+j));
954 return 0;
956 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
958 case GAA_ERROR_NOTENOUGH_ARGS:
959 printf("'%s': not enough arguments\n",gaa_current_option);
960 return 0;
961 case GAA_ERROR_INVALID_ARG:
962 printf("Invalid arguments\n");
963 return 0;
964 case GAA_OK:
965 break;
966 default:
967 printf("Unknown error\n");
970 gaa_arg_used[i] = 1;
971 break;
972 default: break;
976 if(gaa_processing_file == 0)
979 #line 507 "gaa.skel"
980 #ifdef GAA_REST_EXISTS
981 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
983 case GAA_ERROR_NOTENOUGH_ARGS:
984 printf("Rest: not enough arguments\n");
985 return 0;
986 case GAA_ERROR_INVALID_ARG:
987 printf("Invalid arguments\n");
988 return 0;
989 case GAA_OK:
990 break;
991 default:
992 printf("Unknown error\n");
994 #endif
996 for(i = 1; i < argc; i++)
998 if(gaa_arg_used[i] == 0)
1000 printf("Too many arguments\n");
1001 return 0;
1004 free(gaa_arg_used);
1005 free(opt_list);
1006 return -1;
1009 struct gaastrnode
1011 char *str;
1012 struct gaastrnode *next;
1015 typedef struct gaastrnode gaa_str_node;
1017 int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1019 int pos_ini;
1020 char a;
1021 int i = 0, len = 0, newline = 0;
1023 if(argc == 1)
1024 newline = 1;
1026 if(fscanf(file,"%c", &a) != 1) return 0;
1028 while(a == ' ' || a == 9 || a == '\n')
1030 if(a == '\n')
1032 newline=1;
1033 len = 2;
1035 if(fscanf(file,"%c", &a) != 1) return 0;
1038 pos_ini = ftell(file) - 1;
1040 while(a != ' ' && a != 9 && a != '\n')
1043 len++;
1044 if(fscanf(file,"%c", &a) != 1) a = ' ';
1047 tmp_str->str = malloc((len + 1) * sizeof(char));
1048 if(newline == 1)
1050 tmp_str->str[0] = '-';
1051 tmp_str->str[1] = '-';
1052 i = 2;
1054 else
1056 i = 0;
1059 fseek(file,pos_ini, SEEK_SET);
1062 if(fscanf(file, "%c", &a) != 1)
1064 i+=2;
1065 break;
1067 tmp_str->str[i] = a;
1068 i++;
1070 while(a != ' ' && a != 9 && a != '\n');
1072 tmp_str->str[i - 1] = 0;
1074 fseek(file,- 1, SEEK_CUR);
1075 /* printf("%d\n", ftell(file)); */
1077 return -1;
1080 int gaa_file(char *name, gaainfo *gaaval)
1082 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1083 int rval, i;
1084 char **argv;
1085 int argc = 0;
1086 FILE *file;
1088 gaa_processing_file = 1;
1090 if((file = fopen(name, "r")) == NULL)
1092 printf("Couldn't open '%s' configuration file for reading\n", name);
1093 return 0;
1096 tmp_str = &first_str;
1099 argc++;
1100 *tmp_str = malloc(sizeof(gaa_str_node));
1101 (*tmp_str)->str = NULL;
1102 (*tmp_str)->next = NULL;
1104 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1105 tmp_str = &((*tmp_str)->next);
1107 while(rval == -1);
1109 if(rval == 1)
1110 return 0;
1112 argv = malloc((1 + argc) * sizeof(char*));
1113 tmp_str2 = first_str;
1114 argv[0] = "cfg";
1115 for(i = 1; i < argc; i++)
1117 argv[i] = tmp_str2->str;
1118 tmp_str2 = tmp_str2->next;
1121 rval = gaa(argc, argv, gaaval);
1122 gaa_processing_file = 0;
1123 return rval;