Updated cli and server to read certificate and keys from command line
[gnutls.git] / src / serv-gaa.c
blobfadb538f447e4f995f3aceeefe418b5d785597df
1 /* File generated by GAA 1.6.0b3
2 */
3 #define GAA_NO_WIN32
4 #line 80 "serv.gaa"
6 #include <common.h>
7 #include <stdio.h>
9 #ifndef GAA_NO_WIN32
10 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
11 #define GAA_WIN32
12 #endif
13 #endif
15 void __gaa_helpsingle(char short_name, char *name,
16 char *arg_desc, char *opt_help)
18 int col1, col3, col4, tabsize = 3, curr;
19 int i;
21 col1 = 5; /* Default values */
22 col3 = 30;
23 col4 = 70;
25 curr = 0;
26 for(i = 0; i < col1; i++)
28 printf(" ");
29 curr++;
31 if(short_name)
33 if(name && *name)
35 printf("-%c, ", short_name);
36 curr += 4;
38 else
40 printf("-%c ", short_name);
41 curr += 3;
44 if(name && *name)
46 printf("--%s ", name);
47 curr += 3 + strlen(name);
49 if(arg_desc && *arg_desc)
51 printf("%s ", arg_desc);
52 curr += 1 + strlen(arg_desc);
54 if(curr >= col3)
56 printf("\n");
57 curr = 0;
59 if(opt_help) /* let's print the option's help body */
61 const char *str = opt_help;
62 while(*str)
64 while(curr < col3)
66 printf(" ");
67 curr++;
69 switch(*str)
71 case '\n':
72 printf("\n");
73 curr = 0;
74 break;
75 case '\t':
78 printf(" ");
79 curr++;
81 while((curr - col3) % tabsize != 0 && curr < col4);
82 case ' ':
83 if(*str == ' ')
85 curr++;
86 printf(" ");
88 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
89 && str[i] != '\t'; i++);
90 if(curr + i - 1 >= col4)
91 curr = col4;
92 break;
93 default:
94 printf("%c", *str);
95 curr++;
97 if(curr >= col4)
99 printf("\n");
100 curr = 0;
102 str++;
105 printf("\n");
108 void gaa_help(void)
110 printf("gnutls-serv help\nUsage: gnutls-serv [options]""\n");
111 __gaa_helpsingle('g', "generate", "", "Generate Diffie Hellman Parameters.");
112 __gaa_helpsingle('p', "port", """integer"" ", "The port to connect to.");
113 __gaa_helpsingle(0, "http", "", "Act as an HTTP Server.");
114 __gaa_helpsingle(0, "cafile", """FILE"" ", "Certificate file to use.");
115 __gaa_helpsingle(0, "pgpkeyring", """FILE"" ", "PGP Key ring file to use.");
116 __gaa_helpsingle(0, "pgptrustdb", """FILE"" ", "PGP trustdb file to use.");
117 __gaa_helpsingle(0, "pgpkeyfile", """FILE"" ", "PGP Key file to use.");
118 __gaa_helpsingle(0, "pgpcertfile", """FILE"" ", "PGP Public Key (certificate) file to use.");
119 __gaa_helpsingle(0, "x509keyfile", """FILE"" ", "X.509 key file to use.");
120 __gaa_helpsingle(0, "x509certfile", """FILE"" ", "X.509 Certificate file to use.");
121 __gaa_helpsingle(0, "pgpkeyserver", """FILE"" ", "PGP Keyserver to use.");
122 __gaa_helpsingle(0, "srppasswd", """FILE"" ", "SRP password file to use.");
123 __gaa_helpsingle(0, "srppasswdconf", """FILE"" ", "SRP password conf file to use.");
124 __gaa_helpsingle(0, "ciphers", """cipher1 cipher2..."" ", "Ciphers to enable.");
125 __gaa_helpsingle(0, "protocols", """protocol1 protocol2..."" ", "Protocols to enable.");
126 __gaa_helpsingle(0, "comp", """comp1 comp2..."" ", "Compression methods to enable.");
127 __gaa_helpsingle(0, "macs", """mac1 mac2..."" ", "MACs to enable.");
128 __gaa_helpsingle(0, "kx", """kx1 kx2..."" ", "Key exchange methods to enable.");
129 __gaa_helpsingle(0, "ctypes", """certType1 certType2..."" ", "Certificate types to enable.");
130 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
131 __gaa_helpsingle('h', "help", "", "prints this help");
133 #line 100 "gaa.skel"
135 /* Copy of C area */
137 #line 104 "gaa.skel"
138 /* GAA HEADER */
139 #ifndef GAA_HEADER_POKY
140 #define GAA_HEADER_POKY
142 typedef struct _gaainfo gaainfo;
144 struct _gaainfo
146 #line 64 "serv.gaa"
147 char **ctype;
148 #line 63 "serv.gaa"
149 int nctype;
150 #line 60 "serv.gaa"
151 char **kx;
152 #line 59 "serv.gaa"
153 int nkx;
154 #line 56 "serv.gaa"
155 char **macs;
156 #line 55 "serv.gaa"
157 int nmacs;
158 #line 52 "serv.gaa"
159 char **comp;
160 #line 51 "serv.gaa"
161 int ncomp;
162 #line 48 "serv.gaa"
163 char **proto;
164 #line 47 "serv.gaa"
165 int nproto;
166 #line 44 "serv.gaa"
167 char **ciphers;
168 #line 43 "serv.gaa"
169 int nciphers;
170 #line 39 "serv.gaa"
171 char *srp_passwd_conf;
172 #line 36 "serv.gaa"
173 char *srp_passwd;
174 #line 33 "serv.gaa"
175 char *pgp_keyserver;
176 #line 30 "serv.gaa"
177 char *x509_certfile;
178 #line 27 "serv.gaa"
179 char *x509_keyfile;
180 #line 24 "serv.gaa"
181 char *pgp_certfile;
182 #line 21 "serv.gaa"
183 char *pgp_keyfile;
184 #line 18 "serv.gaa"
185 char *pgp_trustdb;
186 #line 15 "serv.gaa"
187 char *pgp_keyring;
188 #line 12 "serv.gaa"
189 char *x509_cafile;
190 #line 9 "serv.gaa"
191 int http;
192 #line 6 "serv.gaa"
193 int port;
194 #line 3 "serv.gaa"
195 int generate;
197 #line 114 "gaa.skel"
200 #ifdef __cplusplus
201 extern "C"
203 #endif
205 int gaa(int argc, char *argv[], gaainfo *gaaval);
207 void gaa_help(void);
209 int gaa_file(char *name, gaainfo *gaaval);
211 #ifdef __cplusplus
213 #endif
216 #endif
218 #line 135 "gaa.skel"
220 /* C declarations */
222 #define GAAERROR(x) \
224 gaa_error = 1; \
225 return x; \
228 char *gaa_current_option;
229 int gaa_error = 0;
231 /* Generated by gaa */
233 #include <string.h>
234 #include <stdlib.h>
237 #define GAA_OK -1
239 #define GAA_ERROR_NOMATCH 0
240 #define GAA_ERROR_NOTENOUGH_ARGS 1
241 #define GAA_ERROR_INVALID_ARG 2
242 #define GAA_ERROR_UNKNOWN 3
244 #define GAA_NOT_AN_OPTION 0
245 #define GAA_WORD_OPTION 1
246 #define GAA_LETTER_OPTION 2
247 #define GAA_MULTIPLE_OPTION 3
249 #define GAA_REST 0
250 #define GAA_NB_OPTION 21
251 #define GAAOPTID_help 1
252 #define GAAOPTID_list 2
253 #define GAAOPTID_ctypes 3
254 #define GAAOPTID_kx 4
255 #define GAAOPTID_macs 5
256 #define GAAOPTID_comp 6
257 #define GAAOPTID_protocols 7
258 #define GAAOPTID_ciphers 8
259 #define GAAOPTID_srppasswdconf 9
260 #define GAAOPTID_srppasswd 10
261 #define GAAOPTID_pgpkeyserver 11
262 #define GAAOPTID_x509certfile 12
263 #define GAAOPTID_x509keyfile 13
264 #define GAAOPTID_pgpcertfile 14
265 #define GAAOPTID_pgpkeyfile 15
266 #define GAAOPTID_pgptrustdb 16
267 #define GAAOPTID_pgpkeyring 17
268 #define GAAOPTID_cafile 18
269 #define GAAOPTID_http 19
270 #define GAAOPTID_port 20
271 #define GAAOPTID_generate 21
273 #line 168 "gaa.skel"
275 #define GAA_CHECK1STR(a,b) \
276 if(a[0] == str[0]) \
278 gaa_current_option = a; \
279 return b; \
282 #define GAA_CHECKSTR(a,b) \
283 if(strcmp(a,str) == 0) \
285 gaa_current_option = a; \
286 return b; \
289 #define GAA_TESTMOREARGS \
290 if(!OK) \
292 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
293 gaa_index++; \
294 if(gaa_last_non_option == gaa_index) \
295 return GAA_ERROR_NOTENOUGH_ARGS; \
298 #define GAA_TESTMOREOPTIONALARGS \
299 if(!OK) \
301 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
302 gaa_index++; \
303 if(gaa_last_non_option == gaa_index) \
304 OK = 1; \
307 #define GAA_FILL_2ARGS(target, func) \
308 target = func(GAAargv[gaa_index]); \
309 gaa_arg_used[gaa_index] = 1; \
310 if(gaa_error == 1) \
312 gaa_error = 0; \
313 return GAA_ERROR_INVALID_ARG; \
318 #define GAA_FILL(target, func, num) \
319 if(!OK) \
321 target = func(GAAargv[gaa_index]); \
322 gaa_arg_used[gaa_index] = 1; \
323 if(gaa_error == 1) \
325 gaa_error = 0; \
326 return GAA_ERROR_INVALID_ARG; \
328 num = 1; \
330 else \
332 num = 0; \
335 #define GAA_LIST_FILL(target, func, type ,num) \
336 if(!OK) \
338 num = 0; \
339 target = NULL; \
340 if ( gaa_last_non_option - gaa_index > 0) \
341 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
342 for(; gaa_index < gaa_last_non_option; gaa_index++) \
344 if(gaa_arg_used[gaa_index] == 0) \
346 GAA_FILL_2ARGS(target[num], func); \
347 num++; \
350 if(num == 0) \
351 return GAA_ERROR_NOTENOUGH_ARGS; \
354 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
355 if(!OK) \
357 num = 0; \
358 target = NULL; \
359 if ( gaa_last_non_option - gaa_index > 0) \
360 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
361 for(; gaa_index < gaa_last_non_option; gaa_index++) \
363 if(gaa_arg_used[gaa_index] == 0) \
365 GAA_FILL_2ARGS(target[num], func); \
366 num++; \
371 #define GAA_OBLIGAT(str) \
372 k = 0; \
373 for(i = 0; i < strlen(str); i++) \
375 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
376 if(j == GAA_ERROR_NOMATCH) \
378 printf("Error: invalid 'obligat' set\n"); \
379 exit(-1); \
381 if(opt_list[j] == 1) \
382 k = 1; \
384 if(k == 0) \
386 if(strlen(str) == 1) \
387 printf("You must give the -%s option\n", str); \
388 else \
389 printf("You must give at least one option of '%s'\n", str); \
390 return 0; \
393 #define GAA_INCOMP(str) \
394 k = 0; \
395 for(i = 0; i < strlen(str); i++) \
397 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
398 if(j == GAA_ERROR_NOMATCH) \
400 printf("Error: invalid 'obligat' set\n"); \
401 exit(-1); \
403 if(opt_list[j] == 1) \
404 k++; \
406 if(k > 1) \
408 printf("The options '%s' are incompatible\n", str); \
409 return 0; \
413 char **GAAargv;
414 int GAAargc;
415 char *gaa_arg_used;
416 int gaa_processing_file = 0;
417 int inited = 0;
419 int gaa_getint(char *arg)
421 int tmp;
422 char a;
423 if(sscanf(arg, "%d%c", &tmp, &a) != 1)
425 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
426 GAAERROR(-1);
428 return tmp;
431 char gaa_getchar(char *arg)
433 if(strlen(arg) != 1)
435 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
436 GAAERROR(-1);
438 return arg[0];
441 char* gaa_getstr(char *arg)
443 return arg;
445 float gaa_getfloat(char *arg)
447 float tmp;
448 char a;
449 if(sscanf(arg, "%f%c", &tmp, &a) != 1)
451 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
452 GAAERROR(-1);
454 return tmp;
456 /* option structures */
458 struct GAAOPTION_ctypes
460 char** arg1;
461 int size1;
464 struct GAAOPTION_kx
466 char** arg1;
467 int size1;
470 struct GAAOPTION_macs
472 char** arg1;
473 int size1;
476 struct GAAOPTION_comp
478 char** arg1;
479 int size1;
482 struct GAAOPTION_protocols
484 char** arg1;
485 int size1;
488 struct GAAOPTION_ciphers
490 char** arg1;
491 int size1;
494 struct GAAOPTION_srppasswdconf
496 char* arg1;
497 int size1;
500 struct GAAOPTION_srppasswd
502 char* arg1;
503 int size1;
506 struct GAAOPTION_pgpkeyserver
508 char* arg1;
509 int size1;
512 struct GAAOPTION_x509certfile
514 char* arg1;
515 int size1;
518 struct GAAOPTION_x509keyfile
520 char* arg1;
521 int size1;
524 struct GAAOPTION_pgpcertfile
526 char* arg1;
527 int size1;
530 struct GAAOPTION_pgpkeyfile
532 char* arg1;
533 int size1;
536 struct GAAOPTION_pgptrustdb
538 char* arg1;
539 int size1;
542 struct GAAOPTION_pgpkeyring
544 char* arg1;
545 int size1;
548 struct GAAOPTION_cafile
550 char* arg1;
551 int size1;
554 struct GAAOPTION_port
556 int arg1;
557 int size1;
560 #line 349 "gaa.skel"
561 int gaa_is_an_argument(char *str)
563 #ifdef GAA_WIN32
564 if(str[0] == '/' && str[1] != 0)
565 return GAA_MULTIPLE_OPTION;
566 #endif
567 if(str[0] != '-')
568 return GAA_NOT_AN_OPTION;
569 if(str[1] == 0)
570 return GAA_NOT_AN_OPTION;
571 if(str[1] == '-')
573 if(str[2] != 0)
574 return GAA_WORD_OPTION;
575 else
576 return GAA_NOT_AN_OPTION;
578 if(str[2] == 0)
579 return GAA_LETTER_OPTION;
580 else
581 return GAA_MULTIPLE_OPTION;
584 int gaa_get_option_num(char *str, int status)
586 switch(status)
588 case GAA_LETTER_OPTION:
589 GAA_CHECK1STR("", GAAOPTID_ctypes);
590 GAA_CHECK1STR("", GAAOPTID_kx);
591 GAA_CHECK1STR("", GAAOPTID_macs);
592 GAA_CHECK1STR("", GAAOPTID_comp);
593 GAA_CHECK1STR("", GAAOPTID_protocols);
594 GAA_CHECK1STR("", GAAOPTID_ciphers);
595 GAA_CHECK1STR("", GAAOPTID_srppasswdconf);
596 GAA_CHECK1STR("", GAAOPTID_srppasswd);
597 GAA_CHECK1STR("", GAAOPTID_pgpkeyserver);
598 GAA_CHECK1STR("", GAAOPTID_x509certfile);
599 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
600 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
601 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
602 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
603 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
604 GAA_CHECK1STR("", GAAOPTID_cafile);
605 GAA_CHECK1STR("p", GAAOPTID_port);
606 case GAA_MULTIPLE_OPTION:
607 #line 375 "gaa.skel"
608 GAA_CHECK1STR("h", GAAOPTID_help);
609 GAA_CHECK1STR("l", GAAOPTID_list);
610 GAA_CHECK1STR("", GAAOPTID_http);
611 GAA_CHECK1STR("g", GAAOPTID_generate);
613 #line 277 "gaa.skel"
614 break;
615 case GAA_WORD_OPTION:
616 GAA_CHECKSTR("help", GAAOPTID_help);
617 GAA_CHECKSTR("list", GAAOPTID_list);
618 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
619 GAA_CHECKSTR("kx", GAAOPTID_kx);
620 GAA_CHECKSTR("macs", GAAOPTID_macs);
621 GAA_CHECKSTR("comp", GAAOPTID_comp);
622 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
623 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
624 GAA_CHECKSTR("srppasswdconf", GAAOPTID_srppasswdconf);
625 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
626 GAA_CHECKSTR("pgpkeyserver", GAAOPTID_pgpkeyserver);
627 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
628 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
629 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
630 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
631 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
632 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
633 GAA_CHECKSTR("cafile", GAAOPTID_cafile);
634 GAA_CHECKSTR("http", GAAOPTID_http);
635 GAA_CHECKSTR("port", GAAOPTID_port);
636 GAA_CHECKSTR("generate", GAAOPTID_generate);
638 #line 281 "gaa.skel"
639 break;
640 default: break;
642 return GAA_ERROR_NOMATCH;
645 int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
647 int OK = 0;
648 int gaa_last_non_option;
649 struct GAAOPTION_ctypes GAATMP_ctypes;
650 struct GAAOPTION_kx GAATMP_kx;
651 struct GAAOPTION_macs GAATMP_macs;
652 struct GAAOPTION_comp GAATMP_comp;
653 struct GAAOPTION_protocols GAATMP_protocols;
654 struct GAAOPTION_ciphers GAATMP_ciphers;
655 struct GAAOPTION_srppasswdconf GAATMP_srppasswdconf;
656 struct GAAOPTION_srppasswd GAATMP_srppasswd;
657 struct GAAOPTION_pgpkeyserver GAATMP_pgpkeyserver;
658 struct GAAOPTION_x509certfile GAATMP_x509certfile;
659 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
660 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
661 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
662 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
663 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
664 struct GAAOPTION_cafile GAATMP_cafile;
665 struct GAAOPTION_port GAATMP_port;
667 #line 393 "gaa.skel"
668 #ifdef GAA_REST_EXISTS
669 struct GAAREST GAAREST_tmp;
670 #endif
672 opt_list[gaa_num] = 1;
674 for(gaa_last_non_option = gaa_index;
675 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
676 gaa_last_non_option++);
678 if(gaa_num == GAA_REST)
680 gaa_index = 1;
681 gaa_last_non_option = GAAargc;
684 switch(gaa_num)
686 case GAAOPTID_help:
687 OK = 0;
688 #line 69 "serv.gaa"
689 { gaa_help(); exit(0); ;};
691 return GAA_OK;
692 break;
693 case GAAOPTID_list:
694 OK = 0;
695 #line 68 "serv.gaa"
696 { print_list(); exit(0); ;};
698 return GAA_OK;
699 break;
700 case GAAOPTID_ctypes:
701 OK = 0;
702 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
703 #line 65 "serv.gaa"
704 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
706 return GAA_OK;
707 break;
708 case GAAOPTID_kx:
709 OK = 0;
710 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
711 #line 61 "serv.gaa"
712 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
714 return GAA_OK;
715 break;
716 case GAAOPTID_macs:
717 OK = 0;
718 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
719 #line 57 "serv.gaa"
720 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
722 return GAA_OK;
723 break;
724 case GAAOPTID_comp:
725 OK = 0;
726 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
727 #line 53 "serv.gaa"
728 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
730 return GAA_OK;
731 break;
732 case GAAOPTID_protocols:
733 OK = 0;
734 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
735 #line 49 "serv.gaa"
736 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
738 return GAA_OK;
739 break;
740 case GAAOPTID_ciphers:
741 OK = 0;
742 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
743 #line 45 "serv.gaa"
744 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
746 return GAA_OK;
747 break;
748 case GAAOPTID_srppasswdconf:
749 OK = 0;
750 GAA_TESTMOREARGS;
751 GAA_FILL(GAATMP_srppasswdconf.arg1, gaa_getstr, GAATMP_srppasswdconf.size1);
752 gaa_index++;
753 #line 40 "serv.gaa"
754 { gaaval->srp_passwd_conf = GAATMP_srppasswdconf.arg1 ;};
756 return GAA_OK;
757 break;
758 case GAAOPTID_srppasswd:
759 OK = 0;
760 GAA_TESTMOREARGS;
761 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
762 gaa_index++;
763 #line 37 "serv.gaa"
764 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
766 return GAA_OK;
767 break;
768 case GAAOPTID_pgpkeyserver:
769 OK = 0;
770 GAA_TESTMOREARGS;
771 GAA_FILL(GAATMP_pgpkeyserver.arg1, gaa_getstr, GAATMP_pgpkeyserver.size1);
772 gaa_index++;
773 #line 34 "serv.gaa"
774 { gaaval->pgp_keyserver = GAATMP_pgpkeyserver.arg1 ;};
776 return GAA_OK;
777 break;
778 case GAAOPTID_x509certfile:
779 OK = 0;
780 GAA_TESTMOREARGS;
781 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
782 gaa_index++;
783 #line 31 "serv.gaa"
784 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
786 return GAA_OK;
787 break;
788 case GAAOPTID_x509keyfile:
789 OK = 0;
790 GAA_TESTMOREARGS;
791 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
792 gaa_index++;
793 #line 28 "serv.gaa"
794 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
796 return GAA_OK;
797 break;
798 case GAAOPTID_pgpcertfile:
799 OK = 0;
800 GAA_TESTMOREARGS;
801 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
802 gaa_index++;
803 #line 25 "serv.gaa"
804 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
806 return GAA_OK;
807 break;
808 case GAAOPTID_pgpkeyfile:
809 OK = 0;
810 GAA_TESTMOREARGS;
811 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
812 gaa_index++;
813 #line 22 "serv.gaa"
814 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
816 return GAA_OK;
817 break;
818 case GAAOPTID_pgptrustdb:
819 OK = 0;
820 GAA_TESTMOREARGS;
821 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
822 gaa_index++;
823 #line 19 "serv.gaa"
824 { gaaval->pgp_keyring = GAATMP_pgptrustdb.arg1 ;};
826 return GAA_OK;
827 break;
828 case GAAOPTID_pgpkeyring:
829 OK = 0;
830 GAA_TESTMOREARGS;
831 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
832 gaa_index++;
833 #line 16 "serv.gaa"
834 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
836 return GAA_OK;
837 break;
838 case GAAOPTID_cafile:
839 OK = 0;
840 GAA_TESTMOREARGS;
841 GAA_FILL(GAATMP_cafile.arg1, gaa_getstr, GAATMP_cafile.size1);
842 gaa_index++;
843 #line 13 "serv.gaa"
844 { gaaval->x509_cafile = GAATMP_cafile.arg1 ;};
846 return GAA_OK;
847 break;
848 case GAAOPTID_http:
849 OK = 0;
850 #line 10 "serv.gaa"
851 { gaaval->http = 1 ;};
853 return GAA_OK;
854 break;
855 case GAAOPTID_port:
856 OK = 0;
857 GAA_TESTMOREARGS;
858 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
859 gaa_index++;
860 #line 7 "serv.gaa"
861 { gaaval->port = GAATMP_port.arg1 ;};
863 return GAA_OK;
864 break;
865 case GAAOPTID_generate:
866 OK = 0;
867 #line 4 "serv.gaa"
868 { gaaval->generate = 1 ;};
870 return GAA_OK;
871 break;
873 #line 413 "gaa.skel"
874 default: break;
876 return GAA_ERROR_UNKNOWN;
879 int gaa(int argc, char **argv, gaainfo *gaaval)
881 int tmp1, tmp2;
882 int i, j;
883 char *opt_list;
885 GAAargv = argv;
886 GAAargc = argc;
888 opt_list = (char*) malloc(GAA_NB_OPTION + 1);
889 for(i = 0; i < GAA_NB_OPTION + 1; i++)
890 opt_list[i] = 0;
891 /* initialization */
892 if(inited == 0)
895 #line 71 "serv.gaa"
896 { gaaval->generate=0; gaaval->port=5556; gaaval->http=0; gaaval->ciphers=NULL;
897 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
898 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0;
899 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
900 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->pgp_keyserver=NULL;
901 gaaval->srp_passwd=NULL; gaaval->srp_passwd_conf=NULL;
902 gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL; ;};
905 inited = 1;
906 #line 438 "gaa.skel"
907 gaa_arg_used = NULL;
909 if (argc > 0)
910 gaa_arg_used = malloc(argc * sizeof(char));
911 for(i = 1; i < argc; i++)
912 gaa_arg_used[i] = 0;
913 for(i = 1; i < argc; i++)
915 if(gaa_arg_used[i] == 0)
917 j = 0;
918 tmp1 = gaa_is_an_argument(GAAargv[i]);
919 switch(tmp1)
921 case GAA_WORD_OPTION:
922 j++;
923 case GAA_LETTER_OPTION:
924 j++;
925 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
926 if(tmp2 == GAA_ERROR_NOMATCH)
928 printf("Invalid option '%s'\n", argv[i]+j);
929 return 0;
931 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
933 case GAA_ERROR_NOTENOUGH_ARGS:
934 printf("'%s': not enough arguments\n",gaa_current_option);
935 return 0;
936 case GAA_ERROR_INVALID_ARG:
937 printf("Invalid arguments\n");
938 return 0;
939 case GAA_OK:
940 break;
941 default:
942 printf("Unknown error\n");
944 gaa_arg_used[i] = 1;
945 break;
946 case GAA_MULTIPLE_OPTION:
947 for(j = 1; j < strlen(argv[i]); j++)
949 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
950 if(tmp2 == GAA_ERROR_NOMATCH)
952 printf("Invalid option '%c'\n", *(argv[i]+j));
953 return 0;
955 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
957 case GAA_ERROR_NOTENOUGH_ARGS:
958 printf("'%s': not enough arguments\n",gaa_current_option);
959 return 0;
960 case GAA_ERROR_INVALID_ARG:
961 printf("Invalid arguments\n");
962 return 0;
963 case GAA_OK:
964 break;
965 default:
966 printf("Unknown error\n");
969 gaa_arg_used[i] = 1;
970 break;
971 default: break;
975 if(gaa_processing_file == 0)
978 #line 507 "gaa.skel"
979 #ifdef GAA_REST_EXISTS
980 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
982 case GAA_ERROR_NOTENOUGH_ARGS:
983 printf("Rest: not enough arguments\n");
984 return 0;
985 case GAA_ERROR_INVALID_ARG:
986 printf("Invalid arguments\n");
987 return 0;
988 case GAA_OK:
989 break;
990 default:
991 printf("Unknown error\n");
993 #endif
995 for(i = 1; i < argc; i++)
997 if(gaa_arg_used[i] == 0)
999 printf("Too many arguments\n");
1000 return 0;
1003 free(gaa_arg_used);
1004 free(opt_list);
1005 return -1;
1008 struct gaastrnode
1010 char *str;
1011 struct gaastrnode *next;
1014 typedef struct gaastrnode gaa_str_node;
1016 int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1018 int pos_ini;
1019 char a;
1020 int i = 0, len = 0, newline = 0;
1022 if(argc == 1)
1023 newline = 1;
1025 if(fscanf(file,"%c", &a) != 1) return 0;
1027 while(a == ' ' || a == 9 || a == '\n')
1029 if(a == '\n')
1031 newline=1;
1032 len = 2;
1034 if(fscanf(file,"%c", &a) != 1) return 0;
1037 pos_ini = ftell(file) - 1;
1039 while(a != ' ' && a != 9 && a != '\n')
1042 len++;
1043 if(fscanf(file,"%c", &a) != 1) a = ' ';
1046 tmp_str->str = malloc((len + 1) * sizeof(char));
1047 if(newline == 1)
1049 tmp_str->str[0] = '-';
1050 tmp_str->str[1] = '-';
1051 i = 2;
1053 else
1055 i = 0;
1058 fseek(file,pos_ini, SEEK_SET);
1061 if(fscanf(file, "%c", &a) != 1)
1063 i+=2;
1064 break;
1066 tmp_str->str[i] = a;
1067 i++;
1069 while(a != ' ' && a != 9 && a != '\n');
1071 tmp_str->str[i - 1] = 0;
1073 fseek(file,- 1, SEEK_CUR);
1074 /* printf("%d\n", ftell(file)); */
1076 return -1;
1079 int gaa_file(char *name, gaainfo *gaaval)
1081 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1082 int rval, i;
1083 char **argv;
1084 int argc = 0;
1085 FILE *file;
1087 gaa_processing_file = 1;
1089 if((file = fopen(name, "r")) == NULL)
1091 printf("Couldn't open '%s' configuration file for reading\n", name);
1092 return 0;
1095 tmp_str = &first_str;
1098 argc++;
1099 *tmp_str = malloc(sizeof(gaa_str_node));
1100 (*tmp_str)->str = NULL;
1101 (*tmp_str)->next = NULL;
1103 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1104 tmp_str = &((*tmp_str)->next);
1106 while(rval == -1);
1108 if(rval == 1)
1109 return 0;
1111 argv = malloc((1 + argc) * sizeof(char*));
1112 tmp_str2 = first_str;
1113 argv[0] = "cfg";
1114 for(i = 1; i < argc; i++)
1116 argv[i] = tmp_str2->str;
1117 tmp_str2 = tmp_str2->next;
1120 rval = gaa(argc, argv, gaaval);
1121 gaa_processing_file = 0;
1122 return rval;