Updated cli and server to read certificate and keys from command line
[gnutls.git] / src / cli-gaa.c
blob7ac724b379bbbde3a75bd6d64246e03dc43d5fb9
1 /* File generated by GAA 1.6.0b3
2 */
3 #define GAA_NO_WIN32
4 #line 85 "cli.gaa"
6 /* C declarations */
8 #include <common.h>
9 #include <stdio.h>
11 #ifndef GAA_NO_WIN32
12 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
13 #define GAA_WIN32
14 #endif
15 #endif
17 void __gaa_helpsingle(char short_name, char *name,
18 char *arg_desc, char *opt_help)
20 int col1, col3, col4, tabsize = 3, curr;
21 int i;
23 col1 = 5; /* Default values */
24 col3 = 30;
25 col4 = 70;
27 curr = 0;
28 for(i = 0; i < col1; i++)
30 printf(" ");
31 curr++;
33 if(short_name)
35 if(name && *name)
37 printf("-%c, ", short_name);
38 curr += 4;
40 else
42 printf("-%c ", short_name);
43 curr += 3;
46 if(name && *name)
48 printf("--%s ", name);
49 curr += 3 + strlen(name);
51 if(arg_desc && *arg_desc)
53 printf("%s ", arg_desc);
54 curr += 1 + strlen(arg_desc);
56 if(curr >= col3)
58 printf("\n");
59 curr = 0;
61 if(opt_help) /* let's print the option's help body */
63 const char *str = opt_help;
64 while(*str)
66 while(curr < col3)
68 printf(" ");
69 curr++;
71 switch(*str)
73 case '\n':
74 printf("\n");
75 curr = 0;
76 break;
77 case '\t':
80 printf(" ");
81 curr++;
83 while((curr - col3) % tabsize != 0 && curr < col4);
84 case ' ':
85 if(*str == ' ')
87 curr++;
88 printf(" ");
90 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
91 && str[i] != '\t'; i++);
92 if(curr + i - 1 >= col4)
93 curr = col4;
94 break;
95 default:
96 printf("%c", *str);
97 curr++;
99 if(curr >= col4)
101 printf("\n");
102 curr = 0;
104 str++;
107 printf("\n");
110 void gaa_help(void)
112 printf("gnutls-cli help\nUsage: gnutls-cli [options] hostname""\n");
113 __gaa_helpsingle('r', "resume", "", "Connect, establish a session. Connect again and resume this session.");
114 __gaa_helpsingle('f', "fingerprint", "", "Send the openpgp fingerprint, instead of the key.");
115 __gaa_helpsingle('p', "port", """integer"" ", "The port to connect to.");
116 __gaa_helpsingle(0, "recordsize", """integer"" ", "The maximum record size to advertize.");
117 __gaa_helpsingle(0, "ciphers", """cipher1 cipher2..."" ", "Ciphers to enable.");
118 __gaa_helpsingle(0, "protocols", """protocol1 protocol2..."" ", "Protocols to enable.");
119 __gaa_helpsingle(0, "comp", """comp1 comp2..."" ", "Compression methods to enable.");
120 __gaa_helpsingle(0, "macs", """mac1 mac2..."" ", "MACs to enable.");
121 __gaa_helpsingle(0, "kx", """kx1 kx2..."" ", "Key exchange methods to enable.");
122 __gaa_helpsingle(0, "ctypes", """certType1 certType2..."" ", "Certificate types to enable.");
123 __gaa_helpsingle(0, "cafile", """FILE"" ", "Certificate file to use.");
124 __gaa_helpsingle(0, "pgpkeyfile", """FILE"" ", "PGP Key file to use.");
125 __gaa_helpsingle(0, "pgpkeyring", """FILE"" ", "PGP Key ring file to use.");
126 __gaa_helpsingle(0, "pgptrustdb", """FILE"" ", "PGP trustdb file to use.");
127 __gaa_helpsingle(0, "pgpcertfile", """FILE"" ", "PGP Public Key (certificate) file to use.");
128 __gaa_helpsingle(0, "x509keyfile", """FILE"" ", "X.509 key file to use.");
129 __gaa_helpsingle(0, "x509certfile", """FILE"" ", "X.509 Certificate file to use.");
130 __gaa_helpsingle(0, "srpusername", """NAME"" ", "SRP username to use.");
131 __gaa_helpsingle(0, "srppasswd", """PASSWD"" ", "SRP password to use.");
132 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
133 __gaa_helpsingle('h', "help", "", "prints this help");
135 #line 100 "gaa.skel"
137 /* Copy of C area */
139 #line 104 "gaa.skel"
140 /* GAA HEADER */
141 #ifndef GAA_HEADER_POKY
142 #define GAA_HEADER_POKY
144 typedef struct _gaainfo gaainfo;
146 struct _gaainfo
148 #line 72 "cli.gaa"
149 char **rest_args;
150 #line 71 "cli.gaa"
151 int nrest_args;
152 #line 64 "cli.gaa"
153 char *srp_passwd;
154 #line 61 "cli.gaa"
155 char *srp_username;
156 #line 58 "cli.gaa"
157 char *x509_certfile;
158 #line 55 "cli.gaa"
159 char *x509_keyfile;
160 #line 52 "cli.gaa"
161 char *pgp_certfile;
162 #line 49 "cli.gaa"
163 char *pgp_trustdb;
164 #line 46 "cli.gaa"
165 char *pgp_keyring;
166 #line 43 "cli.gaa"
167 char *pgp_keyfile;
168 #line 40 "cli.gaa"
169 char *x509_cafile;
170 #line 37 "cli.gaa"
171 char **ctype;
172 #line 36 "cli.gaa"
173 int nctype;
174 #line 33 "cli.gaa"
175 char **kx;
176 #line 32 "cli.gaa"
177 int nkx;
178 #line 29 "cli.gaa"
179 char **macs;
180 #line 28 "cli.gaa"
181 int nmacs;
182 #line 25 "cli.gaa"
183 char **comp;
184 #line 24 "cli.gaa"
185 int ncomp;
186 #line 21 "cli.gaa"
187 char **proto;
188 #line 20 "cli.gaa"
189 int nproto;
190 #line 17 "cli.gaa"
191 char **ciphers;
192 #line 16 "cli.gaa"
193 int nciphers;
194 #line 12 "cli.gaa"
195 int record_size;
196 #line 9 "cli.gaa"
197 int port;
198 #line 6 "cli.gaa"
199 int fingerprint;
200 #line 3 "cli.gaa"
201 int resume;
203 #line 114 "gaa.skel"
206 #ifdef __cplusplus
207 extern "C"
209 #endif
211 int gaa(int argc, char *argv[], gaainfo *gaaval);
213 void gaa_help(void);
215 int gaa_file(char *name, gaainfo *gaaval);
217 #ifdef __cplusplus
219 #endif
222 #endif
224 #line 135 "gaa.skel"
226 /* C declarations */
228 #define GAAERROR(x) \
230 gaa_error = 1; \
231 return x; \
234 char *gaa_current_option;
235 int gaa_error = 0;
237 /* Generated by gaa */
239 #include <string.h>
240 #include <stdlib.h>
243 #define GAA_OK -1
245 #define GAA_ERROR_NOMATCH 0
246 #define GAA_ERROR_NOTENOUGH_ARGS 1
247 #define GAA_ERROR_INVALID_ARG 2
248 #define GAA_ERROR_UNKNOWN 3
250 #define GAA_NOT_AN_OPTION 0
251 #define GAA_WORD_OPTION 1
252 #define GAA_LETTER_OPTION 2
253 #define GAA_MULTIPLE_OPTION 3
255 #define GAA_REST 0
256 #define GAA_NB_OPTION 21
257 #define GAAOPTID_help 1
258 #define GAAOPTID_list 2
259 #define GAAOPTID_srppasswd 3
260 #define GAAOPTID_srpusername 4
261 #define GAAOPTID_x509certfile 5
262 #define GAAOPTID_x509keyfile 6
263 #define GAAOPTID_pgpcertfile 7
264 #define GAAOPTID_pgptrustdb 8
265 #define GAAOPTID_pgpkeyring 9
266 #define GAAOPTID_pgpkeyfile 10
267 #define GAAOPTID_cafile 11
268 #define GAAOPTID_ctypes 12
269 #define GAAOPTID_kx 13
270 #define GAAOPTID_macs 14
271 #define GAAOPTID_comp 15
272 #define GAAOPTID_protocols 16
273 #define GAAOPTID_ciphers 17
274 #define GAAOPTID_recordsize 18
275 #define GAAOPTID_port 19
276 #define GAAOPTID_fingerprint 20
277 #define GAAOPTID_resume 21
279 #line 168 "gaa.skel"
281 #define GAA_CHECK1STR(a,b) \
282 if(a[0] == str[0]) \
284 gaa_current_option = a; \
285 return b; \
288 #define GAA_CHECKSTR(a,b) \
289 if(strcmp(a,str) == 0) \
291 gaa_current_option = a; \
292 return b; \
295 #define GAA_TESTMOREARGS \
296 if(!OK) \
298 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
299 gaa_index++; \
300 if(gaa_last_non_option == gaa_index) \
301 return GAA_ERROR_NOTENOUGH_ARGS; \
304 #define GAA_TESTMOREOPTIONALARGS \
305 if(!OK) \
307 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
308 gaa_index++; \
309 if(gaa_last_non_option == gaa_index) \
310 OK = 1; \
313 #define GAA_FILL_2ARGS(target, func) \
314 target = func(GAAargv[gaa_index]); \
315 gaa_arg_used[gaa_index] = 1; \
316 if(gaa_error == 1) \
318 gaa_error = 0; \
319 return GAA_ERROR_INVALID_ARG; \
324 #define GAA_FILL(target, func, num) \
325 if(!OK) \
327 target = func(GAAargv[gaa_index]); \
328 gaa_arg_used[gaa_index] = 1; \
329 if(gaa_error == 1) \
331 gaa_error = 0; \
332 return GAA_ERROR_INVALID_ARG; \
334 num = 1; \
336 else \
338 num = 0; \
341 #define GAA_LIST_FILL(target, func, type ,num) \
342 if(!OK) \
344 num = 0; \
345 target = NULL; \
346 if ( gaa_last_non_option - gaa_index > 0) \
347 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
348 for(; gaa_index < gaa_last_non_option; gaa_index++) \
350 if(gaa_arg_used[gaa_index] == 0) \
352 GAA_FILL_2ARGS(target[num], func); \
353 num++; \
356 if(num == 0) \
357 return GAA_ERROR_NOTENOUGH_ARGS; \
360 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
361 if(!OK) \
363 num = 0; \
364 target = NULL; \
365 if ( gaa_last_non_option - gaa_index > 0) \
366 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
367 for(; gaa_index < gaa_last_non_option; gaa_index++) \
369 if(gaa_arg_used[gaa_index] == 0) \
371 GAA_FILL_2ARGS(target[num], func); \
372 num++; \
377 #define GAA_OBLIGAT(str) \
378 k = 0; \
379 for(i = 0; i < strlen(str); i++) \
381 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
382 if(j == GAA_ERROR_NOMATCH) \
384 printf("Error: invalid 'obligat' set\n"); \
385 exit(-1); \
387 if(opt_list[j] == 1) \
388 k = 1; \
390 if(k == 0) \
392 if(strlen(str) == 1) \
393 printf("You must give the -%s option\n", str); \
394 else \
395 printf("You must give at least one option of '%s'\n", str); \
396 return 0; \
399 #define GAA_INCOMP(str) \
400 k = 0; \
401 for(i = 0; i < strlen(str); i++) \
403 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
404 if(j == GAA_ERROR_NOMATCH) \
406 printf("Error: invalid 'obligat' set\n"); \
407 exit(-1); \
409 if(opt_list[j] == 1) \
410 k++; \
412 if(k > 1) \
414 printf("The options '%s' are incompatible\n", str); \
415 return 0; \
419 char **GAAargv;
420 int GAAargc;
421 char *gaa_arg_used;
422 int gaa_processing_file = 0;
423 int inited = 0;
425 int gaa_getint(char *arg)
427 int tmp;
428 char a;
429 if(sscanf(arg, "%d%c", &tmp, &a) != 1)
431 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
432 GAAERROR(-1);
434 return tmp;
437 char gaa_getchar(char *arg)
439 if(strlen(arg) != 1)
441 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
442 GAAERROR(-1);
444 return arg[0];
447 char* gaa_getstr(char *arg)
449 return arg;
451 float gaa_getfloat(char *arg)
453 float tmp;
454 char a;
455 if(sscanf(arg, "%f%c", &tmp, &a) != 1)
457 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
458 GAAERROR(-1);
460 return tmp;
462 /* option structures */
464 struct GAAOPTION_srppasswd
466 char* arg1;
467 int size1;
470 struct GAAOPTION_srpusername
472 char* arg1;
473 int size1;
476 struct GAAOPTION_x509certfile
478 char* arg1;
479 int size1;
482 struct GAAOPTION_x509keyfile
484 char* arg1;
485 int size1;
488 struct GAAOPTION_pgpcertfile
490 char* arg1;
491 int size1;
494 struct GAAOPTION_pgptrustdb
496 char* arg1;
497 int size1;
500 struct GAAOPTION_pgpkeyring
502 char* arg1;
503 int size1;
506 struct GAAOPTION_pgpkeyfile
508 char* arg1;
509 int size1;
512 struct GAAOPTION_cafile
514 char* arg1;
515 int size1;
518 struct GAAOPTION_ctypes
520 char** arg1;
521 int size1;
524 struct GAAOPTION_kx
526 char** arg1;
527 int size1;
530 struct GAAOPTION_macs
532 char** arg1;
533 int size1;
536 struct GAAOPTION_comp
538 char** arg1;
539 int size1;
542 struct GAAOPTION_protocols
544 char** arg1;
545 int size1;
548 struct GAAOPTION_ciphers
550 char** arg1;
551 int size1;
554 struct GAAOPTION_recordsize
556 int arg1;
557 int size1;
560 struct GAAOPTION_port
562 int arg1;
563 int size1;
565 #define GAA_REST_EXISTS
567 struct GAAREST
569 char** arg1;
570 int size1;
573 #line 349 "gaa.skel"
574 int gaa_is_an_argument(char *str)
576 #ifdef GAA_WIN32
577 if(str[0] == '/' && str[1] != 0)
578 return GAA_MULTIPLE_OPTION;
579 #endif
580 if(str[0] != '-')
581 return GAA_NOT_AN_OPTION;
582 if(str[1] == 0)
583 return GAA_NOT_AN_OPTION;
584 if(str[1] == '-')
586 if(str[2] != 0)
587 return GAA_WORD_OPTION;
588 else
589 return GAA_NOT_AN_OPTION;
591 if(str[2] == 0)
592 return GAA_LETTER_OPTION;
593 else
594 return GAA_MULTIPLE_OPTION;
597 int gaa_get_option_num(char *str, int status)
599 switch(status)
601 case GAA_LETTER_OPTION:
602 GAA_CHECK1STR("", GAAOPTID_srppasswd);
603 GAA_CHECK1STR("", GAAOPTID_srpusername);
604 GAA_CHECK1STR("", GAAOPTID_x509certfile);
605 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
606 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
607 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
608 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
609 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
610 GAA_CHECK1STR("", GAAOPTID_cafile);
611 GAA_CHECK1STR("", GAAOPTID_ctypes);
612 GAA_CHECK1STR("", GAAOPTID_kx);
613 GAA_CHECK1STR("", GAAOPTID_macs);
614 GAA_CHECK1STR("", GAAOPTID_comp);
615 GAA_CHECK1STR("", GAAOPTID_protocols);
616 GAA_CHECK1STR("", GAAOPTID_ciphers);
617 GAA_CHECK1STR("", GAAOPTID_recordsize);
618 GAA_CHECK1STR("p", GAAOPTID_port);
619 case GAA_MULTIPLE_OPTION:
620 #line 375 "gaa.skel"
621 GAA_CHECK1STR("h", GAAOPTID_help);
622 GAA_CHECK1STR("l", GAAOPTID_list);
623 GAA_CHECK1STR("f", GAAOPTID_fingerprint);
624 GAA_CHECK1STR("r", GAAOPTID_resume);
626 #line 277 "gaa.skel"
627 break;
628 case GAA_WORD_OPTION:
629 GAA_CHECKSTR("help", GAAOPTID_help);
630 GAA_CHECKSTR("list", GAAOPTID_list);
631 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
632 GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
633 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
634 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
635 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
636 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
637 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
638 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
639 GAA_CHECKSTR("cafile", GAAOPTID_cafile);
640 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
641 GAA_CHECKSTR("kx", GAAOPTID_kx);
642 GAA_CHECKSTR("macs", GAAOPTID_macs);
643 GAA_CHECKSTR("comp", GAAOPTID_comp);
644 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
645 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
646 GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
647 GAA_CHECKSTR("port", GAAOPTID_port);
648 GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
649 GAA_CHECKSTR("resume", GAAOPTID_resume);
651 #line 281 "gaa.skel"
652 break;
653 default: break;
655 return GAA_ERROR_NOMATCH;
658 int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
660 int OK = 0;
661 int gaa_last_non_option;
662 struct GAAOPTION_srppasswd GAATMP_srppasswd;
663 struct GAAOPTION_srpusername GAATMP_srpusername;
664 struct GAAOPTION_x509certfile GAATMP_x509certfile;
665 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
666 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
667 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
668 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
669 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
670 struct GAAOPTION_cafile GAATMP_cafile;
671 struct GAAOPTION_ctypes GAATMP_ctypes;
672 struct GAAOPTION_kx GAATMP_kx;
673 struct GAAOPTION_macs GAATMP_macs;
674 struct GAAOPTION_comp GAATMP_comp;
675 struct GAAOPTION_protocols GAATMP_protocols;
676 struct GAAOPTION_ciphers GAATMP_ciphers;
677 struct GAAOPTION_recordsize GAATMP_recordsize;
678 struct GAAOPTION_port GAATMP_port;
680 #line 393 "gaa.skel"
681 #ifdef GAA_REST_EXISTS
682 struct GAAREST GAAREST_tmp;
683 #endif
685 opt_list[gaa_num] = 1;
687 for(gaa_last_non_option = gaa_index;
688 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
689 gaa_last_non_option++);
691 if(gaa_num == GAA_REST)
693 gaa_index = 1;
694 gaa_last_non_option = GAAargc;
697 switch(gaa_num)
699 case GAAOPTID_help:
700 OK = 0;
701 #line 69 "cli.gaa"
702 { gaa_help(); exit(0); ;};
704 return GAA_OK;
705 break;
706 case GAAOPTID_list:
707 OK = 0;
708 #line 68 "cli.gaa"
709 { print_list(); exit(0); ;};
711 return GAA_OK;
712 break;
713 case GAAOPTID_srppasswd:
714 OK = 0;
715 GAA_TESTMOREARGS;
716 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
717 gaa_index++;
718 #line 65 "cli.gaa"
719 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
721 return GAA_OK;
722 break;
723 case GAAOPTID_srpusername:
724 OK = 0;
725 GAA_TESTMOREARGS;
726 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
727 gaa_index++;
728 #line 62 "cli.gaa"
729 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
731 return GAA_OK;
732 break;
733 case GAAOPTID_x509certfile:
734 OK = 0;
735 GAA_TESTMOREARGS;
736 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
737 gaa_index++;
738 #line 59 "cli.gaa"
739 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
741 return GAA_OK;
742 break;
743 case GAAOPTID_x509keyfile:
744 OK = 0;
745 GAA_TESTMOREARGS;
746 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
747 gaa_index++;
748 #line 56 "cli.gaa"
749 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
751 return GAA_OK;
752 break;
753 case GAAOPTID_pgpcertfile:
754 OK = 0;
755 GAA_TESTMOREARGS;
756 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
757 gaa_index++;
758 #line 53 "cli.gaa"
759 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
761 return GAA_OK;
762 break;
763 case GAAOPTID_pgptrustdb:
764 OK = 0;
765 GAA_TESTMOREARGS;
766 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
767 gaa_index++;
768 #line 50 "cli.gaa"
769 { gaaval->pgp_keyring = GAATMP_pgptrustdb.arg1 ;};
771 return GAA_OK;
772 break;
773 case GAAOPTID_pgpkeyring:
774 OK = 0;
775 GAA_TESTMOREARGS;
776 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
777 gaa_index++;
778 #line 47 "cli.gaa"
779 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
781 return GAA_OK;
782 break;
783 case GAAOPTID_pgpkeyfile:
784 OK = 0;
785 GAA_TESTMOREARGS;
786 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
787 gaa_index++;
788 #line 44 "cli.gaa"
789 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
791 return GAA_OK;
792 break;
793 case GAAOPTID_cafile:
794 OK = 0;
795 GAA_TESTMOREARGS;
796 GAA_FILL(GAATMP_cafile.arg1, gaa_getstr, GAATMP_cafile.size1);
797 gaa_index++;
798 #line 41 "cli.gaa"
799 { gaaval->x509_cafile = GAATMP_cafile.arg1 ;};
801 return GAA_OK;
802 break;
803 case GAAOPTID_ctypes:
804 OK = 0;
805 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
806 #line 38 "cli.gaa"
807 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
809 return GAA_OK;
810 break;
811 case GAAOPTID_kx:
812 OK = 0;
813 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
814 #line 34 "cli.gaa"
815 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
817 return GAA_OK;
818 break;
819 case GAAOPTID_macs:
820 OK = 0;
821 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
822 #line 30 "cli.gaa"
823 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
825 return GAA_OK;
826 break;
827 case GAAOPTID_comp:
828 OK = 0;
829 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
830 #line 26 "cli.gaa"
831 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
833 return GAA_OK;
834 break;
835 case GAAOPTID_protocols:
836 OK = 0;
837 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
838 #line 22 "cli.gaa"
839 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
841 return GAA_OK;
842 break;
843 case GAAOPTID_ciphers:
844 OK = 0;
845 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
846 #line 18 "cli.gaa"
847 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
849 return GAA_OK;
850 break;
851 case GAAOPTID_recordsize:
852 OK = 0;
853 GAA_TESTMOREARGS;
854 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
855 gaa_index++;
856 #line 13 "cli.gaa"
857 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
859 return GAA_OK;
860 break;
861 case GAAOPTID_port:
862 OK = 0;
863 GAA_TESTMOREARGS;
864 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
865 gaa_index++;
866 #line 10 "cli.gaa"
867 { gaaval->port = GAATMP_port.arg1 ;};
869 return GAA_OK;
870 break;
871 case GAAOPTID_fingerprint:
872 OK = 0;
873 #line 7 "cli.gaa"
874 { gaaval->fingerprint = 1 ;};
876 return GAA_OK;
877 break;
878 case GAAOPTID_resume:
879 OK = 0;
880 #line 4 "cli.gaa"
881 { gaaval->resume = 1 ;};
883 return GAA_OK;
884 break;
885 case GAA_REST:
886 GAA_LIST_FILL(GAAREST_tmp.arg1, gaa_getstr, char*, GAAREST_tmp.size1);
887 #line 73 "cli.gaa"
888 { gaaval->rest_args = GAAREST_tmp.arg1; gaaval->nrest_args = GAAREST_tmp.size1 ;};
890 return GAA_OK;
891 break;
893 #line 413 "gaa.skel"
894 default: break;
896 return GAA_ERROR_UNKNOWN;
899 int gaa(int argc, char **argv, gaainfo *gaaval)
901 int tmp1, tmp2;
902 int i, j;
903 char *opt_list;
905 GAAargv = argv;
906 GAAargc = argc;
908 opt_list = (char*) malloc(GAA_NB_OPTION + 1);
909 for(i = 0; i < GAA_NB_OPTION + 1; i++)
910 opt_list[i] = 0;
911 /* initialization */
912 if(inited == 0)
915 #line 75 "cli.gaa"
916 { gaaval->resume=0; gaaval->port=443; gaaval->rest_args=NULL; gaaval->nrest_args=0; gaaval->ciphers=NULL;
917 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
918 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->record_size=0;
919 gaaval->fingerprint=0; gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL;
920 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
921 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL;
922 gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; ;};
925 inited = 1;
926 #line 438 "gaa.skel"
927 gaa_arg_used = NULL;
929 if (argc > 0)
930 gaa_arg_used = malloc(argc * sizeof(char));
931 for(i = 1; i < argc; i++)
932 gaa_arg_used[i] = 0;
933 for(i = 1; i < argc; i++)
935 if(gaa_arg_used[i] == 0)
937 j = 0;
938 tmp1 = gaa_is_an_argument(GAAargv[i]);
939 switch(tmp1)
941 case GAA_WORD_OPTION:
942 j++;
943 case GAA_LETTER_OPTION:
944 j++;
945 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
946 if(tmp2 == GAA_ERROR_NOMATCH)
948 printf("Invalid option '%s'\n", argv[i]+j);
949 return 0;
951 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
953 case GAA_ERROR_NOTENOUGH_ARGS:
954 printf("'%s': not enough arguments\n",gaa_current_option);
955 return 0;
956 case GAA_ERROR_INVALID_ARG:
957 printf("Invalid arguments\n");
958 return 0;
959 case GAA_OK:
960 break;
961 default:
962 printf("Unknown error\n");
964 gaa_arg_used[i] = 1;
965 break;
966 case GAA_MULTIPLE_OPTION:
967 for(j = 1; j < strlen(argv[i]); j++)
969 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
970 if(tmp2 == GAA_ERROR_NOMATCH)
972 printf("Invalid option '%c'\n", *(argv[i]+j));
973 return 0;
975 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
977 case GAA_ERROR_NOTENOUGH_ARGS:
978 printf("'%s': not enough arguments\n",gaa_current_option);
979 return 0;
980 case GAA_ERROR_INVALID_ARG:
981 printf("Invalid arguments\n");
982 return 0;
983 case GAA_OK:
984 break;
985 default:
986 printf("Unknown error\n");
989 gaa_arg_used[i] = 1;
990 break;
991 default: break;
995 if(gaa_processing_file == 0)
998 #line 507 "gaa.skel"
999 #ifdef GAA_REST_EXISTS
1000 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1002 case GAA_ERROR_NOTENOUGH_ARGS:
1003 printf("Rest: not enough arguments\n");
1004 return 0;
1005 case GAA_ERROR_INVALID_ARG:
1006 printf("Invalid arguments\n");
1007 return 0;
1008 case GAA_OK:
1009 break;
1010 default:
1011 printf("Unknown error\n");
1013 #endif
1015 for(i = 1; i < argc; i++)
1017 if(gaa_arg_used[i] == 0)
1019 printf("Too many arguments\n");
1020 return 0;
1023 free(gaa_arg_used);
1024 free(opt_list);
1025 return -1;
1028 struct gaastrnode
1030 char *str;
1031 struct gaastrnode *next;
1034 typedef struct gaastrnode gaa_str_node;
1036 int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1038 int pos_ini;
1039 char a;
1040 int i = 0, len = 0, newline = 0;
1042 if(argc == 1)
1043 newline = 1;
1045 if(fscanf(file,"%c", &a) != 1) return 0;
1047 while(a == ' ' || a == 9 || a == '\n')
1049 if(a == '\n')
1051 newline=1;
1052 len = 2;
1054 if(fscanf(file,"%c", &a) != 1) return 0;
1057 pos_ini = ftell(file) - 1;
1059 while(a != ' ' && a != 9 && a != '\n')
1062 len++;
1063 if(fscanf(file,"%c", &a) != 1) a = ' ';
1066 tmp_str->str = malloc((len + 1) * sizeof(char));
1067 if(newline == 1)
1069 tmp_str->str[0] = '-';
1070 tmp_str->str[1] = '-';
1071 i = 2;
1073 else
1075 i = 0;
1078 fseek(file,pos_ini, SEEK_SET);
1081 if(fscanf(file, "%c", &a) != 1)
1083 i+=2;
1084 break;
1086 tmp_str->str[i] = a;
1087 i++;
1089 while(a != ' ' && a != 9 && a != '\n');
1091 tmp_str->str[i - 1] = 0;
1093 fseek(file,- 1, SEEK_CUR);
1094 /* printf("%d\n", ftell(file)); */
1096 return -1;
1099 int gaa_file(char *name, gaainfo *gaaval)
1101 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1102 int rval, i;
1103 char **argv;
1104 int argc = 0;
1105 FILE *file;
1107 gaa_processing_file = 1;
1109 if((file = fopen(name, "r")) == NULL)
1111 printf("Couldn't open '%s' configuration file for reading\n", name);
1112 return 0;
1115 tmp_str = &first_str;
1118 argc++;
1119 *tmp_str = malloc(sizeof(gaa_str_node));
1120 (*tmp_str)->str = NULL;
1121 (*tmp_str)->next = NULL;
1123 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1124 tmp_str = &((*tmp_str)->next);
1126 while(rval == -1);
1128 if(rval == 1)
1129 return 0;
1131 argv = malloc((1 + argc) * sizeof(char*));
1132 tmp_str2 = first_str;
1133 argv[0] = "cfg";
1134 for(i = 1; i < argc; i++)
1136 argv[i] = tmp_str2->str;
1137 tmp_str2 = tmp_str2->next;
1140 rval = gaa(argc, argv, gaaval);
1141 gaa_processing_file = 0;
1142 return rval;