More enum docs.
[gnutls.git] / src / cli-gaa.c
blob715b43b69192adcecff40d42e31cecff2ef1cf97
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "cli.gaa"
7 /* C declarations */
9 #include <config.h>
10 #include <common.h>
12 void cli_version(void);
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #ifndef GAA_NO_WIN32
19 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
20 #define GAA_WIN32
21 #endif
22 #endif
24 static void* gaa_malloc( size_t size) {
25 void* ret;
26 ret = malloc(size);
27 if (ret==NULL) {
28 fprintf(stderr, "gaa: could not allocate memory");
29 exit(1);
31 return ret;
34 static void __gaa_helpsingle(char short_name, char *name,
35 char *arg_desc, char *opt_help)
37 int col1, col3, col4, tabsize = 3, curr;
38 int i;
40 col1 = 5; /* Default values */
41 col3 = 30;
42 col4 = 70;
44 curr = 0;
45 for(i = 0; i < col1; i++)
47 printf(" ");
48 curr++;
50 if(short_name)
52 if(name && *name)
54 printf("-%c, ", short_name);
55 curr += 4;
57 else
59 printf("-%c ", short_name);
60 curr += 3;
63 if(name && *name)
65 printf("--%s ", name);
66 curr += 3 + strlen(name);
68 if(arg_desc && *arg_desc)
70 printf("%s ", arg_desc);
71 curr += 1 + strlen(arg_desc);
73 if(curr >= col3)
75 printf("\n");
76 curr = 0;
78 if(opt_help) /* let's print the option's help body */
80 const char *str = opt_help;
81 while(*str)
83 while(curr < col3)
85 printf(" ");
86 curr++;
88 switch(*str)
90 case '\n':
91 printf("\n");
92 curr = 0;
93 break;
94 case '\t':
97 printf(" ");
98 curr++;
100 while((curr - col3) % tabsize != 0 && curr < col4);
101 case ' ':
102 if(*str == ' ')
104 curr++;
105 printf(" ");
107 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
108 && str[i] != '\t'; i++);
109 if(curr + i - 1 >= col4)
110 curr = col4;
111 break;
112 default:
113 printf("%c", *str);
114 curr++;
116 if(curr >= col4)
118 printf("\n");
119 curr = 0;
121 str++;
124 printf("\n");
127 void gaa_help(void)
129 printf("GNU TLS test client\nUsage: gnutls-cli [options] hostname\n\n\n");
130 __gaa_helpsingle('d', "debug", "integer ", "Enable debugging");
131 __gaa_helpsingle('r', "resume", "", "Connect, establish a session. Connect again and resume this session.");
132 __gaa_helpsingle('e', "rehandshake", "", "Connect, establish a session and rehandshake immediately.");
133 __gaa_helpsingle(0, "noticket", "", "Doen't accept session tickets.");
134 __gaa_helpsingle('s', "starttls", "", "Connect, establish a plain session and start TLS when EOF or a SIGALRM is received.");
135 __gaa_helpsingle(0, "crlf", "", "Send CR LF instead of LF.");
136 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates to read from.");
137 __gaa_helpsingle('f', "fingerprint", "", "Send the openpgp fingerprint, instead of the key.");
138 __gaa_helpsingle(0, "disable-extensions", "", "Disable all the TLS extensions.");
139 __gaa_helpsingle(0, "print-cert", "", "Print the certificate in PEM format.");
140 __gaa_helpsingle(0, "recordsize", "integer ", "The maximum record size to advertize.");
141 __gaa_helpsingle('V', "verbose", "", "More verbose output.");
142 __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
143 __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
144 __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
145 __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
146 __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
147 __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
148 __gaa_helpsingle(0, "priority", "PRIORITY STRING ", "Priorities string.");
149 __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
150 __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
151 __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
152 __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
153 __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
154 __gaa_helpsingle(0, "pgpsubkey", "HEX|auto ", "PGP subkey to use.");
155 __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file to use.");
156 __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
157 __gaa_helpsingle(0, "srpusername", "NAME ", "SRP username to use.");
158 __gaa_helpsingle(0, "srppasswd", "PASSWD ", "SRP password to use.");
159 __gaa_helpsingle(0, "pskusername", "NAME ", "PSK username to use.");
160 __gaa_helpsingle(0, "pskkey", "KEY ", "PSK key (in hex) to use.");
161 __gaa_helpsingle(0, "opaque-prf-input", "DATA ", "Use Opaque PRF Input DATA.");
162 __gaa_helpsingle('p', "port", "PORT ", "The port to connect to.");
163 __gaa_helpsingle(0, "insecure", "", "Don't abort program if server certificate can't be validated.");
164 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
165 __gaa_helpsingle('h', "help", "", "prints this help");
166 __gaa_helpsingle('v', "version", "", "prints the program's version number");
168 #line 100 "gaa.skel"
170 /* Copy of C area */
172 #line 104 "gaa.skel"
173 /* GAA HEADER */
174 #ifndef GAA_HEADER_POKY
175 #define GAA_HEADER_POKY
177 typedef struct _gaainfo gaainfo;
179 struct _gaainfo
181 #line 127 "cli.gaa"
182 char *rest_args;
183 #line 119 "cli.gaa"
184 int insecure;
185 #line 116 "cli.gaa"
186 char *port;
187 #line 113 "cli.gaa"
188 char *opaque_prf_input;
189 #line 110 "cli.gaa"
190 char *psk_key;
191 #line 107 "cli.gaa"
192 char *psk_username;
193 #line 104 "cli.gaa"
194 char *srp_passwd;
195 #line 101 "cli.gaa"
196 char *srp_username;
197 #line 98 "cli.gaa"
198 char *x509_certfile;
199 #line 95 "cli.gaa"
200 char *x509_keyfile;
201 #line 92 "cli.gaa"
202 char *pgp_subkey;
203 #line 89 "cli.gaa"
204 char *pgp_certfile;
205 #line 86 "cli.gaa"
206 char *pgp_keyring;
207 #line 83 "cli.gaa"
208 char *pgp_keyfile;
209 #line 80 "cli.gaa"
210 char *x509_crlfile;
211 #line 77 "cli.gaa"
212 char *x509_cafile;
213 #line 74 "cli.gaa"
214 char *priorities;
215 #line 71 "cli.gaa"
216 char **ctype;
217 #line 70 "cli.gaa"
218 int nctype;
219 #line 67 "cli.gaa"
220 char **kx;
221 #line 66 "cli.gaa"
222 int nkx;
223 #line 63 "cli.gaa"
224 char **macs;
225 #line 62 "cli.gaa"
226 int nmacs;
227 #line 59 "cli.gaa"
228 char **comp;
229 #line 58 "cli.gaa"
230 int ncomp;
231 #line 55 "cli.gaa"
232 char **proto;
233 #line 54 "cli.gaa"
234 int nproto;
235 #line 51 "cli.gaa"
236 char **ciphers;
237 #line 50 "cli.gaa"
238 int nciphers;
239 #line 47 "cli.gaa"
240 int verbose;
241 #line 44 "cli.gaa"
242 int record_size;
243 #line 41 "cli.gaa"
244 int print_cert;
245 #line 38 "cli.gaa"
246 int disable_extensions;
247 #line 35 "cli.gaa"
248 int fingerprint;
249 #line 32 "cli.gaa"
250 int fmtder;
251 #line 29 "cli.gaa"
252 int crlf;
253 #line 26 "cli.gaa"
254 int starttls;
255 #line 23 "cli.gaa"
256 int noticket;
257 #line 20 "cli.gaa"
258 int rehandshake;
259 #line 17 "cli.gaa"
260 int resume;
261 #line 14 "cli.gaa"
262 int debug;
264 #line 114 "gaa.skel"
267 #ifdef __cplusplus
268 extern "C"
270 #endif
272 int gaa(int argc, char *argv[], gaainfo *gaaval);
274 void gaa_help(void);
276 int gaa_file(const char *name, gaainfo *gaaval);
278 #ifdef __cplusplus
280 #endif
283 #endif
285 #line 135 "gaa.skel"
287 /* C declarations */
289 #define GAAERROR(x) \
291 gaa_error = 1; \
292 return x; \
295 static char *gaa_current_option;
296 static int gaa_error = 0;
298 /* Generated by gaa */
300 #include <string.h>
301 #include <stdlib.h>
304 #define GAA_OK -1
306 #define GAA_ERROR_NOMATCH 0
307 #define GAA_ERROR_NOTENOUGH_ARGS 1
308 #define GAA_ERROR_INVALID_ARG 2
309 #define GAA_ERROR_UNKNOWN 3
311 #define GAA_NOT_AN_OPTION 0
312 #define GAA_WORD_OPTION 1
313 #define GAA_LETTER_OPTION 2
314 #define GAA_MULTIPLE_OPTION 3
316 #define GAA_REST 0
317 #define GAA_NB_OPTION 37
318 #define GAAOPTID_version 1
319 #define GAAOPTID_help 2
320 #define GAAOPTID_list 3
321 #define GAAOPTID_insecure 4
322 #define GAAOPTID_port 5
323 #define GAAOPTID_opaque_prf_input 6
324 #define GAAOPTID_pskkey 7
325 #define GAAOPTID_pskusername 8
326 #define GAAOPTID_srppasswd 9
327 #define GAAOPTID_srpusername 10
328 #define GAAOPTID_x509certfile 11
329 #define GAAOPTID_x509keyfile 12
330 #define GAAOPTID_pgpsubkey 13
331 #define GAAOPTID_pgpcertfile 14
332 #define GAAOPTID_pgpkeyring 15
333 #define GAAOPTID_pgpkeyfile 16
334 #define GAAOPTID_x509crlfile 17
335 #define GAAOPTID_x509cafile 18
336 #define GAAOPTID_priority 19
337 #define GAAOPTID_ctypes 20
338 #define GAAOPTID_kx 21
339 #define GAAOPTID_macs 22
340 #define GAAOPTID_comp 23
341 #define GAAOPTID_protocols 24
342 #define GAAOPTID_ciphers 25
343 #define GAAOPTID_verbose 26
344 #define GAAOPTID_recordsize 27
345 #define GAAOPTID_print_cert 28
346 #define GAAOPTID_disable_extensions 29
347 #define GAAOPTID_fingerprint 30
348 #define GAAOPTID_x509fmtder 31
349 #define GAAOPTID_crlf 32
350 #define GAAOPTID_starttls 33
351 #define GAAOPTID_noticket 34
352 #define GAAOPTID_rehandshake 35
353 #define GAAOPTID_resume 36
354 #define GAAOPTID_debug 37
356 #line 168 "gaa.skel"
358 #define GAA_CHECK1STR(a,b) \
359 if(a[0] == str[0]) \
361 gaa_current_option = a; \
362 return b; \
365 #define GAA_CHECKSTR(a,b) \
366 if(strcmp(a,str) == 0) \
368 gaa_current_option = a; \
369 return b; \
372 #define GAA_TESTMOREARGS \
373 if(!OK) \
375 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
376 gaa_index++; \
377 if(gaa_last_non_option == gaa_index) \
378 return GAA_ERROR_NOTENOUGH_ARGS; \
381 #define GAA_TESTMOREOPTIONALARGS \
382 if(!OK) \
384 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
385 gaa_index++; \
386 if(gaa_last_non_option == gaa_index) \
387 OK = 1; \
390 #define GAA_FILL_2ARGS(target, func) \
391 target = func(GAAargv[gaa_index]); \
392 gaa_arg_used[gaa_index] = 1; \
393 if(gaa_error == 1) \
395 gaa_error = 0; \
396 return GAA_ERROR_INVALID_ARG; \
401 #define GAA_FILL(target, func, num) \
402 if(!OK) \
404 target = func(GAAargv[gaa_index]); \
405 gaa_arg_used[gaa_index] = 1; \
406 if(gaa_error == 1) \
408 gaa_error = 0; \
409 return GAA_ERROR_INVALID_ARG; \
411 num = 1; \
413 else \
415 num = 0; \
418 #define GAA_LIST_FILL(target, func, type ,num) \
419 if(!OK) \
421 num = 0; \
422 target = NULL; \
423 if ( gaa_last_non_option - gaa_index > 0) \
424 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
425 for(; gaa_index < gaa_last_non_option; gaa_index++) \
427 if(gaa_arg_used[gaa_index] == 0) \
429 GAA_FILL_2ARGS(target[num], func); \
430 num++; \
433 if(num == 0) \
434 return GAA_ERROR_NOTENOUGH_ARGS; \
437 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
438 if(!OK) \
440 num = 0; \
441 target = NULL; \
442 if ( gaa_last_non_option - gaa_index > 0) \
443 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
444 for(; gaa_index < gaa_last_non_option; gaa_index++) \
446 if(gaa_arg_used[gaa_index] == 0) \
448 GAA_FILL_2ARGS(target[num], func); \
449 num++; \
454 #define GAA_OBLIGAT(str) \
455 k = 0; \
456 for(i = 0; i < strlen(str); i++) \
458 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
459 if(j == GAA_ERROR_NOMATCH) \
461 printf("Error: invalid 'obligat' set\n"); \
462 exit(-1); \
464 if(opt_list[j] == 1) \
465 k = 1; \
467 if(k == 0) \
469 if(strlen(str) == 1) \
470 printf("You must give the -%s option\n", str); \
471 else \
472 printf("You must give at least one option of '%s'\n", str); \
473 return 0; \
476 #define GAA_INCOMP(str) \
477 k = 0; \
478 for(i = 0; i < strlen(str); i++) \
480 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
481 if(j == GAA_ERROR_NOMATCH) \
483 printf("Error: invalid 'obligat' set\n"); \
484 exit(-1); \
486 if(opt_list[j] == 1) \
487 k++; \
489 if(k > 1) \
491 printf("The options '%s' are incompatible\n", str); \
492 return 0; \
496 static char **GAAargv;
497 static int GAAargc;
498 static char *gaa_arg_used;
499 static int gaa_processing_file = 0;
500 static int inited = 0;
502 static int gaa_getint(char *arg)
504 int tmp;
505 char a;
506 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
508 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
509 GAAERROR(-1);
511 return tmp;
514 static char gaa_getchar(char *arg)
516 if(strlen(arg) != 1)
518 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
519 GAAERROR(-1);
521 return arg[0];
524 static char* gaa_getstr(char *arg)
526 return arg;
528 static float gaa_getfloat(char *arg)
530 float tmp;
531 char a;
532 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
534 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
535 GAAERROR(-1);
537 return tmp;
539 /* option structures */
541 struct GAAOPTION_port
543 char* arg1;
544 int size1;
547 struct GAAOPTION_opaque_prf_input
549 char* arg1;
550 int size1;
553 struct GAAOPTION_pskkey
555 char* arg1;
556 int size1;
559 struct GAAOPTION_pskusername
561 char* arg1;
562 int size1;
565 struct GAAOPTION_srppasswd
567 char* arg1;
568 int size1;
571 struct GAAOPTION_srpusername
573 char* arg1;
574 int size1;
577 struct GAAOPTION_x509certfile
579 char* arg1;
580 int size1;
583 struct GAAOPTION_x509keyfile
585 char* arg1;
586 int size1;
589 struct GAAOPTION_pgpsubkey
591 char* arg1;
592 int size1;
595 struct GAAOPTION_pgpcertfile
597 char* arg1;
598 int size1;
601 struct GAAOPTION_pgpkeyring
603 char* arg1;
604 int size1;
607 struct GAAOPTION_pgpkeyfile
609 char* arg1;
610 int size1;
613 struct GAAOPTION_x509crlfile
615 char* arg1;
616 int size1;
619 struct GAAOPTION_x509cafile
621 char* arg1;
622 int size1;
625 struct GAAOPTION_priority
627 char* arg1;
628 int size1;
631 struct GAAOPTION_ctypes
633 char** arg1;
634 int size1;
637 struct GAAOPTION_kx
639 char** arg1;
640 int size1;
643 struct GAAOPTION_macs
645 char** arg1;
646 int size1;
649 struct GAAOPTION_comp
651 char** arg1;
652 int size1;
655 struct GAAOPTION_protocols
657 char** arg1;
658 int size1;
661 struct GAAOPTION_ciphers
663 char** arg1;
664 int size1;
667 struct GAAOPTION_recordsize
669 int arg1;
670 int size1;
673 struct GAAOPTION_debug
675 int arg1;
676 int size1;
678 #define GAA_REST_EXISTS
680 struct GAAREST
682 char* arg1;
683 int size1;
686 #line 349 "gaa.skel"
687 static int gaa_is_an_argument(char *str)
689 #ifdef GAA_WIN32
690 if(str[0] == '/' && str[1] != 0)
691 return GAA_MULTIPLE_OPTION;
692 #endif
693 if(str[0] != '-')
694 return GAA_NOT_AN_OPTION;
695 if(str[1] == 0)
696 return GAA_NOT_AN_OPTION;
697 if(str[1] == '-')
699 if(str[2] != 0)
700 return GAA_WORD_OPTION;
701 else
702 return GAA_NOT_AN_OPTION;
704 if(str[2] == 0)
705 return GAA_LETTER_OPTION;
706 else
707 return GAA_MULTIPLE_OPTION;
710 static int gaa_get_option_num(char *str, int status)
712 switch(status)
714 case GAA_LETTER_OPTION:
715 GAA_CHECK1STR("p", GAAOPTID_port);
716 GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
717 GAA_CHECK1STR("", GAAOPTID_pskkey);
718 GAA_CHECK1STR("", GAAOPTID_pskusername);
719 GAA_CHECK1STR("", GAAOPTID_srppasswd);
720 GAA_CHECK1STR("", GAAOPTID_srpusername);
721 GAA_CHECK1STR("", GAAOPTID_x509certfile);
722 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
723 GAA_CHECK1STR("", GAAOPTID_pgpsubkey);
724 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
725 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
726 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
727 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
728 GAA_CHECK1STR("", GAAOPTID_x509cafile);
729 GAA_CHECK1STR("", GAAOPTID_priority);
730 GAA_CHECK1STR("", GAAOPTID_ctypes);
731 GAA_CHECK1STR("", GAAOPTID_kx);
732 GAA_CHECK1STR("", GAAOPTID_macs);
733 GAA_CHECK1STR("", GAAOPTID_comp);
734 GAA_CHECK1STR("", GAAOPTID_protocols);
735 GAA_CHECK1STR("", GAAOPTID_ciphers);
736 GAA_CHECK1STR("", GAAOPTID_recordsize);
737 GAA_CHECK1STR("d", GAAOPTID_debug);
738 case GAA_MULTIPLE_OPTION:
739 #line 375 "gaa.skel"
740 GAA_CHECK1STR("v", GAAOPTID_version);
741 GAA_CHECK1STR("h", GAAOPTID_help);
742 GAA_CHECK1STR("l", GAAOPTID_list);
743 GAA_CHECK1STR("", GAAOPTID_insecure);
744 GAA_CHECK1STR("V", GAAOPTID_verbose);
745 GAA_CHECK1STR("", GAAOPTID_print_cert);
746 GAA_CHECK1STR("", GAAOPTID_disable_extensions);
747 GAA_CHECK1STR("f", GAAOPTID_fingerprint);
748 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
749 GAA_CHECK1STR("", GAAOPTID_crlf);
750 GAA_CHECK1STR("s", GAAOPTID_starttls);
751 GAA_CHECK1STR("", GAAOPTID_noticket);
752 GAA_CHECK1STR("e", GAAOPTID_rehandshake);
753 GAA_CHECK1STR("r", GAAOPTID_resume);
755 #line 277 "gaa.skel"
756 break;
757 case GAA_WORD_OPTION:
758 GAA_CHECKSTR("version", GAAOPTID_version);
759 GAA_CHECKSTR("help", GAAOPTID_help);
760 GAA_CHECKSTR("list", GAAOPTID_list);
761 GAA_CHECKSTR("insecure", GAAOPTID_insecure);
762 GAA_CHECKSTR("port", GAAOPTID_port);
763 GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
764 GAA_CHECKSTR("pskkey", GAAOPTID_pskkey);
765 GAA_CHECKSTR("pskusername", GAAOPTID_pskusername);
766 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
767 GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
768 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
769 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
770 GAA_CHECKSTR("pgpsubkey", GAAOPTID_pgpsubkey);
771 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
772 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
773 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
774 GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
775 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
776 GAA_CHECKSTR("priority", GAAOPTID_priority);
777 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
778 GAA_CHECKSTR("kx", GAAOPTID_kx);
779 GAA_CHECKSTR("macs", GAAOPTID_macs);
780 GAA_CHECKSTR("comp", GAAOPTID_comp);
781 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
782 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
783 GAA_CHECKSTR("verbose", GAAOPTID_verbose);
784 GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
785 GAA_CHECKSTR("print-cert", GAAOPTID_print_cert);
786 GAA_CHECKSTR("disable-extensions", GAAOPTID_disable_extensions);
787 GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
788 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
789 GAA_CHECKSTR("crlf", GAAOPTID_crlf);
790 GAA_CHECKSTR("starttls", GAAOPTID_starttls);
791 GAA_CHECKSTR("noticket", GAAOPTID_noticket);
792 GAA_CHECKSTR("rehandshake", GAAOPTID_rehandshake);
793 GAA_CHECKSTR("resume", GAAOPTID_resume);
794 GAA_CHECKSTR("debug", GAAOPTID_debug);
796 #line 281 "gaa.skel"
797 break;
798 default: break;
800 return GAA_ERROR_NOMATCH;
803 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
805 int OK = 0;
806 int gaa_last_non_option;
807 struct GAAOPTION_port GAATMP_port;
808 struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
809 struct GAAOPTION_pskkey GAATMP_pskkey;
810 struct GAAOPTION_pskusername GAATMP_pskusername;
811 struct GAAOPTION_srppasswd GAATMP_srppasswd;
812 struct GAAOPTION_srpusername GAATMP_srpusername;
813 struct GAAOPTION_x509certfile GAATMP_x509certfile;
814 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
815 struct GAAOPTION_pgpsubkey GAATMP_pgpsubkey;
816 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
817 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
818 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
819 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
820 struct GAAOPTION_x509cafile GAATMP_x509cafile;
821 struct GAAOPTION_priority GAATMP_priority;
822 struct GAAOPTION_ctypes GAATMP_ctypes;
823 struct GAAOPTION_kx GAATMP_kx;
824 struct GAAOPTION_macs GAATMP_macs;
825 struct GAAOPTION_comp GAATMP_comp;
826 struct GAAOPTION_protocols GAATMP_protocols;
827 struct GAAOPTION_ciphers GAATMP_ciphers;
828 struct GAAOPTION_recordsize GAATMP_recordsize;
829 struct GAAOPTION_debug GAATMP_debug;
831 #line 393 "gaa.skel"
832 #ifdef GAA_REST_EXISTS
833 struct GAAREST GAAREST_tmp;
834 #endif
836 opt_list[gaa_num] = 1;
838 for(gaa_last_non_option = gaa_index;
839 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
840 gaa_last_non_option++);
842 if(gaa_num == GAA_REST)
844 gaa_index = 1;
845 gaa_last_non_option = GAAargc;
848 switch(gaa_num)
850 case GAAOPTID_version:
851 OK = 0;
852 #line 125 "cli.gaa"
853 { cli_version(); exit(0); ;};
855 return GAA_OK;
856 break;
857 case GAAOPTID_help:
858 OK = 0;
859 #line 123 "cli.gaa"
860 { gaa_help(); exit(0); ;};
862 return GAA_OK;
863 break;
864 case GAAOPTID_list:
865 OK = 0;
866 #line 122 "cli.gaa"
867 { print_list(gaaval->verbose); exit(0); ;};
869 return GAA_OK;
870 break;
871 case GAAOPTID_insecure:
872 OK = 0;
873 #line 120 "cli.gaa"
874 { gaaval->insecure = 1 ;};
876 return GAA_OK;
877 break;
878 case GAAOPTID_port:
879 OK = 0;
880 GAA_TESTMOREARGS;
881 GAA_FILL(GAATMP_port.arg1, gaa_getstr, GAATMP_port.size1);
882 gaa_index++;
883 #line 117 "cli.gaa"
884 { gaaval->port = GAATMP_port.arg1 ;};
886 return GAA_OK;
887 break;
888 case GAAOPTID_opaque_prf_input:
889 OK = 0;
890 GAA_TESTMOREARGS;
891 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
892 gaa_index++;
893 #line 114 "cli.gaa"
894 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
896 return GAA_OK;
897 break;
898 case GAAOPTID_pskkey:
899 OK = 0;
900 GAA_TESTMOREARGS;
901 GAA_FILL(GAATMP_pskkey.arg1, gaa_getstr, GAATMP_pskkey.size1);
902 gaa_index++;
903 #line 111 "cli.gaa"
904 { gaaval->psk_key = GAATMP_pskkey.arg1 ;};
906 return GAA_OK;
907 break;
908 case GAAOPTID_pskusername:
909 OK = 0;
910 GAA_TESTMOREARGS;
911 GAA_FILL(GAATMP_pskusername.arg1, gaa_getstr, GAATMP_pskusername.size1);
912 gaa_index++;
913 #line 108 "cli.gaa"
914 { gaaval->psk_username = GAATMP_pskusername.arg1 ;};
916 return GAA_OK;
917 break;
918 case GAAOPTID_srppasswd:
919 OK = 0;
920 GAA_TESTMOREARGS;
921 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
922 gaa_index++;
923 #line 105 "cli.gaa"
924 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
926 return GAA_OK;
927 break;
928 case GAAOPTID_srpusername:
929 OK = 0;
930 GAA_TESTMOREARGS;
931 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
932 gaa_index++;
933 #line 102 "cli.gaa"
934 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
936 return GAA_OK;
937 break;
938 case GAAOPTID_x509certfile:
939 OK = 0;
940 GAA_TESTMOREARGS;
941 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
942 gaa_index++;
943 #line 99 "cli.gaa"
944 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
946 return GAA_OK;
947 break;
948 case GAAOPTID_x509keyfile:
949 OK = 0;
950 GAA_TESTMOREARGS;
951 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
952 gaa_index++;
953 #line 96 "cli.gaa"
954 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
956 return GAA_OK;
957 break;
958 case GAAOPTID_pgpsubkey:
959 OK = 0;
960 GAA_TESTMOREARGS;
961 GAA_FILL(GAATMP_pgpsubkey.arg1, gaa_getstr, GAATMP_pgpsubkey.size1);
962 gaa_index++;
963 #line 93 "cli.gaa"
964 { gaaval->pgp_subkey = GAATMP_pgpsubkey.arg1 ;};
966 return GAA_OK;
967 break;
968 case GAAOPTID_pgpcertfile:
969 OK = 0;
970 GAA_TESTMOREARGS;
971 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
972 gaa_index++;
973 #line 90 "cli.gaa"
974 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
976 return GAA_OK;
977 break;
978 case GAAOPTID_pgpkeyring:
979 OK = 0;
980 GAA_TESTMOREARGS;
981 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
982 gaa_index++;
983 #line 87 "cli.gaa"
984 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
986 return GAA_OK;
987 break;
988 case GAAOPTID_pgpkeyfile:
989 OK = 0;
990 GAA_TESTMOREARGS;
991 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
992 gaa_index++;
993 #line 84 "cli.gaa"
994 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
996 return GAA_OK;
997 break;
998 case GAAOPTID_x509crlfile:
999 OK = 0;
1000 GAA_TESTMOREARGS;
1001 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
1002 gaa_index++;
1003 #line 81 "cli.gaa"
1004 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
1006 return GAA_OK;
1007 break;
1008 case GAAOPTID_x509cafile:
1009 OK = 0;
1010 GAA_TESTMOREARGS;
1011 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
1012 gaa_index++;
1013 #line 78 "cli.gaa"
1014 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
1016 return GAA_OK;
1017 break;
1018 case GAAOPTID_priority:
1019 OK = 0;
1020 GAA_TESTMOREARGS;
1021 GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1);
1022 gaa_index++;
1023 #line 75 "cli.gaa"
1024 { gaaval->priorities = GAATMP_priority.arg1 ;};
1026 return GAA_OK;
1027 break;
1028 case GAAOPTID_ctypes:
1029 OK = 0;
1030 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
1031 #line 72 "cli.gaa"
1032 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
1034 return GAA_OK;
1035 break;
1036 case GAAOPTID_kx:
1037 OK = 0;
1038 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
1039 #line 68 "cli.gaa"
1040 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
1042 return GAA_OK;
1043 break;
1044 case GAAOPTID_macs:
1045 OK = 0;
1046 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
1047 #line 64 "cli.gaa"
1048 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
1050 return GAA_OK;
1051 break;
1052 case GAAOPTID_comp:
1053 OK = 0;
1054 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
1055 #line 60 "cli.gaa"
1056 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
1058 return GAA_OK;
1059 break;
1060 case GAAOPTID_protocols:
1061 OK = 0;
1062 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
1063 #line 56 "cli.gaa"
1064 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
1066 return GAA_OK;
1067 break;
1068 case GAAOPTID_ciphers:
1069 OK = 0;
1070 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
1071 #line 52 "cli.gaa"
1072 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
1074 return GAA_OK;
1075 break;
1076 case GAAOPTID_verbose:
1077 OK = 0;
1078 #line 48 "cli.gaa"
1079 { gaaval->verbose = 1 ;};
1081 return GAA_OK;
1082 break;
1083 case GAAOPTID_recordsize:
1084 OK = 0;
1085 GAA_TESTMOREARGS;
1086 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
1087 gaa_index++;
1088 #line 45 "cli.gaa"
1089 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
1091 return GAA_OK;
1092 break;
1093 case GAAOPTID_print_cert:
1094 OK = 0;
1095 #line 42 "cli.gaa"
1096 { gaaval->print_cert = 1 ;};
1098 return GAA_OK;
1099 break;
1100 case GAAOPTID_disable_extensions:
1101 OK = 0;
1102 #line 39 "cli.gaa"
1103 { gaaval->disable_extensions = 1 ;};
1105 return GAA_OK;
1106 break;
1107 case GAAOPTID_fingerprint:
1108 OK = 0;
1109 #line 36 "cli.gaa"
1110 { gaaval->fingerprint = 1 ;};
1112 return GAA_OK;
1113 break;
1114 case GAAOPTID_x509fmtder:
1115 OK = 0;
1116 #line 33 "cli.gaa"
1117 { gaaval->fmtder = 1 ;};
1119 return GAA_OK;
1120 break;
1121 case GAAOPTID_crlf:
1122 OK = 0;
1123 #line 30 "cli.gaa"
1124 { gaaval->crlf = 1 ;};
1126 return GAA_OK;
1127 break;
1128 case GAAOPTID_starttls:
1129 OK = 0;
1130 #line 27 "cli.gaa"
1131 { gaaval->starttls = 1 ;};
1133 return GAA_OK;
1134 break;
1135 case GAAOPTID_noticket:
1136 OK = 0;
1137 #line 24 "cli.gaa"
1138 { gaaval->noticket = 1 ;};
1140 return GAA_OK;
1141 break;
1142 case GAAOPTID_rehandshake:
1143 OK = 0;
1144 #line 21 "cli.gaa"
1145 { gaaval->rehandshake = 1 ;};
1147 return GAA_OK;
1148 break;
1149 case GAAOPTID_resume:
1150 OK = 0;
1151 #line 18 "cli.gaa"
1152 { gaaval->resume = 1 ;};
1154 return GAA_OK;
1155 break;
1156 case GAAOPTID_debug:
1157 OK = 0;
1158 GAA_TESTMOREARGS;
1159 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1160 gaa_index++;
1161 #line 15 "cli.gaa"
1162 { gaaval->debug = GAATMP_debug.arg1 ;};
1164 return GAA_OK;
1165 break;
1166 case GAA_REST:
1167 GAA_TESTMOREARGS;
1168 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
1169 gaa_index++;
1170 #line 128 "cli.gaa"
1171 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
1173 return GAA_OK;
1174 break;
1176 #line 413 "gaa.skel"
1177 default: break;
1179 return GAA_ERROR_UNKNOWN;
1182 int gaa(int argc, char **argv, gaainfo *gaaval)
1184 int tmp1, tmp2;
1185 int i, j;
1186 char *opt_list;
1188 GAAargv = argv;
1189 GAAargc = argc;
1191 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1193 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1194 opt_list[i] = 0;
1195 /* initialization */
1196 if(inited == 0)
1199 #line 130 "cli.gaa"
1200 { gaaval->resume=0; gaaval->noticket=0; gaaval->port="443"; gaaval->rest_args=NULL; gaaval->ciphers=NULL;
1201 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1202 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->record_size=0;
1203 gaaval->fingerprint=0; gaaval->pgp_keyring=NULL; gaaval->x509_crlfile = NULL;
1204 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL; gaaval->disable_extensions = 0;
1205 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->crlf = 0;
1206 gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; gaaval->fmtder = 0; gaaval->starttls =0;
1207 gaaval->debug = 0; gaaval->print_cert = 0; gaaval->verbose = 0; gaaval->psk_key = NULL;
1208 gaaval->psk_username = NULL; gaaval->priorities = NULL;
1209 gaaval->opaque_prf_input = NULL; gaaval->pgp_subkey = NULL; gaaval->rehandshake = 0; ;};
1212 inited = 1;
1213 #line 438 "gaa.skel"
1214 gaa_arg_used = NULL;
1216 if (argc > 0) {
1217 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1220 for(i = 1; i < argc; i++)
1221 gaa_arg_used[i] = 0;
1222 for(i = 1; i < argc; i++)
1224 if(gaa_arg_used[i] == 0)
1226 j = 0;
1227 tmp1 = gaa_is_an_argument(GAAargv[i]);
1228 switch(tmp1)
1230 case GAA_WORD_OPTION:
1231 j++;
1232 case GAA_LETTER_OPTION:
1233 j++;
1234 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1235 if(tmp2 == GAA_ERROR_NOMATCH)
1237 printf("Invalid option '%s'\n", argv[i]+j);
1238 return 0;
1240 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1242 case GAA_ERROR_NOTENOUGH_ARGS:
1243 printf("'%s': not enough arguments\n",gaa_current_option);
1244 return 0;
1245 case GAA_ERROR_INVALID_ARG:
1246 printf("Invalid arguments\n");
1247 return 0;
1248 case GAA_OK:
1249 break;
1250 default:
1251 printf("Unknown error\n");
1253 gaa_arg_used[i] = 1;
1254 break;
1255 case GAA_MULTIPLE_OPTION:
1256 for(j = 1; j < strlen(argv[i]); j++)
1258 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1259 if(tmp2 == GAA_ERROR_NOMATCH)
1261 printf("Invalid option '%c'\n", *(argv[i]+j));
1262 return 0;
1264 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1266 case GAA_ERROR_NOTENOUGH_ARGS:
1267 printf("'%s': not enough arguments\n",gaa_current_option);
1268 return 0;
1269 case GAA_ERROR_INVALID_ARG:
1270 printf("Invalid arguments\n");
1271 return 0;
1272 case GAA_OK:
1273 break;
1274 default:
1275 printf("Unknown error\n");
1278 gaa_arg_used[i] = 1;
1279 break;
1280 default: break;
1284 if(gaa_processing_file == 0)
1287 #line 507 "gaa.skel"
1288 #ifdef GAA_REST_EXISTS
1289 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1291 case GAA_ERROR_NOTENOUGH_ARGS:
1292 printf("Rest: not enough arguments\n");
1293 return 0;
1294 case GAA_ERROR_INVALID_ARG:
1295 printf("Invalid arguments\n");
1296 return 0;
1297 case GAA_OK:
1298 break;
1299 default:
1300 printf("Unknown error\n");
1302 #endif
1304 for(i = 1; i < argc; i++)
1306 if(gaa_arg_used[i] == 0)
1308 printf("Too many arguments\n");
1309 return 0;
1312 free(gaa_arg_used);
1313 free(opt_list);
1314 return -1;
1317 struct gaastrnode
1319 char *str;
1320 struct gaastrnode *next;
1323 typedef struct gaastrnode gaa_str_node;
1325 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1327 int pos_ini;
1328 int a;
1329 int i = 0, len = 0, newline = 0;
1331 if(argc == 1) {
1332 newline = 1;
1333 len = 2;
1336 a = fgetc( file);
1337 if (a == EOF) return 0;
1339 while(a == ' ' || a == 9 || a == '\n')
1341 if(a == '\n')
1343 newline=1;
1344 len = 2;
1346 a = fgetc( file);
1347 if (a == EOF) return 0;
1350 pos_ini = ftell(file) - 1;
1352 while(a != ' ' && a != 9 && a != '\n')
1355 len++;
1356 a = fgetc( file);
1357 if(a==EOF) return 0; //a = ' ';
1360 len += 1;
1361 tmp_str->str = gaa_malloc((len) * sizeof(char));
1363 if(newline == 1)
1365 tmp_str->str[0] = '-';
1366 tmp_str->str[1] = '-';
1367 i = 2;
1369 else
1371 i = 0;
1374 fseek(file,pos_ini, SEEK_SET);
1377 a = fgetc( file);
1379 if (a == EOF) {
1380 i+=2;
1381 break;
1383 tmp_str->str[i] = a;
1384 i++;
1386 while(a != ' ' && a != 9 && a != '\n' && i < len);
1388 tmp_str->str[i - 1] = 0;
1390 fseek(file,- 1, SEEK_CUR);
1391 /* printf("%d\n", ftell(file)); */
1393 return -1;
1396 int gaa_file(const char *name, gaainfo *gaaval)
1398 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1399 int rval, i;
1400 char **argv;
1401 int argc = 0;
1402 FILE *file;
1404 gaa_processing_file = 1;
1406 if((file = fopen(name, "r")) == NULL)
1408 printf("Couldn't open '%s' configuration file for reading\n", name);
1409 return 1;
1412 tmp_str = &first_str;
1415 argc++;
1416 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1418 (*tmp_str)->str = NULL;
1419 (*tmp_str)->next = NULL;
1421 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1422 tmp_str = &((*tmp_str)->next);
1424 while(rval == -1);
1426 if(rval == 1)
1427 return 0;
1429 argv = gaa_malloc((1 + argc) * sizeof(char*));
1431 tmp_str2 = first_str;
1432 argv[0] = "cfg";
1433 for(i = 1; i < argc; i++)
1435 argv[i] = tmp_str2->str;
1436 tmp_str2 = tmp_str2->next;
1439 rval = gaa(argc, argv, gaaval);
1440 gaa_processing_file = 0;
1441 return rval;