Fix dangling/unused bindings in `(gnutls)'.
[gnutls.git] / src / cli-gaa.c
blob98276be25cd15ca7cdf57e65ff227b8d6cd5ba96
1 /* File generated by GAA 1.6.6
2 */
3 #define GAA_NO_WIN32
4 #line 1 "cli.gaa"
7 /* C declarations */
9 #include <common.h>
11 void print_license(void);
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('s', "starttls", "", "Connect, establish a plain session and start TLS when EOF or a SIGALRM is received.");
133 __gaa_helpsingle(0, "crlf", "", "Send CR LF instead of LF.");
134 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates to read from.");
135 __gaa_helpsingle('f', "fingerprint", "", "Send the openpgp fingerprint, instead of the key.");
136 __gaa_helpsingle(0, "disable-extensions", "", "Disable all the TLS extensions.");
137 __gaa_helpsingle(0, "print-cert", "", "Print the certificate in PEM format.");
138 __gaa_helpsingle(0, "recordsize", "integer ", "The maximum record size to advertize.");
139 __gaa_helpsingle('V', "verbose", "", "More verbose output.");
140 __gaa_helpsingle(0, "ciphers", "cipher1 cipher2... ", "Ciphers to enable.");
141 __gaa_helpsingle(0, "protocols", "protocol1 protocol2... ", "Protocols to enable.");
142 __gaa_helpsingle(0, "comp", "comp1 comp2... ", "Compression methods to enable.");
143 __gaa_helpsingle(0, "macs", "mac1 mac2... ", "MACs to enable.");
144 __gaa_helpsingle(0, "kx", "kx1 kx2... ", "Key exchange methods to enable.");
145 __gaa_helpsingle(0, "ctypes", "certType1 certType2... ", "Certificate types to enable.");
146 __gaa_helpsingle(0, "priority", "PRIORITY STRING ", "Priorities string.");
147 __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file to use.");
148 __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
149 __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
150 __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
151 __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
152 __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file to use.");
153 __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file to use.");
154 __gaa_helpsingle(0, "srpusername", "NAME ", "SRP username to use.");
155 __gaa_helpsingle(0, "srppasswd", "PASSWD ", "SRP password to use.");
156 __gaa_helpsingle(0, "pskusername", "NAME ", "PSK username to use.");
157 __gaa_helpsingle(0, "pskkey", "KEY ", "PSK key (in hex) to use.");
158 __gaa_helpsingle(0, "opaque-prf-input", "DATA ", "Use Opaque PRF Input DATA.");
159 __gaa_helpsingle('p', "port", "PORT ", "The port to connect to.");
160 __gaa_helpsingle(0, "insecure", "", "Don't abort program if server certificate can't be validated.");
161 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
162 __gaa_helpsingle('h', "help", "", "prints this help");
163 __gaa_helpsingle('v', "version", "", "prints the program's version number");
164 __gaa_helpsingle(0, "copyright", "", "prints the program's license");
166 #line 100 "gaa.skel"
168 /* Copy of C area */
170 #line 104 "gaa.skel"
171 /* GAA HEADER */
172 #ifndef GAA_HEADER_POKY
173 #define GAA_HEADER_POKY
175 typedef struct _gaainfo gaainfo;
177 struct _gaainfo
179 #line 119 "cli.gaa"
180 char *rest_args;
181 #line 110 "cli.gaa"
182 int insecure;
183 #line 107 "cli.gaa"
184 char *port;
185 #line 104 "cli.gaa"
186 char *opaque_prf_input;
187 #line 101 "cli.gaa"
188 char *psk_key;
189 #line 98 "cli.gaa"
190 char *psk_username;
191 #line 95 "cli.gaa"
192 char *srp_passwd;
193 #line 92 "cli.gaa"
194 char *srp_username;
195 #line 89 "cli.gaa"
196 char *x509_certfile;
197 #line 86 "cli.gaa"
198 char *x509_keyfile;
199 #line 83 "cli.gaa"
200 char *pgp_certfile;
201 #line 80 "cli.gaa"
202 char *pgp_keyring;
203 #line 77 "cli.gaa"
204 char *pgp_keyfile;
205 #line 74 "cli.gaa"
206 char *x509_crlfile;
207 #line 71 "cli.gaa"
208 char *x509_cafile;
209 #line 68 "cli.gaa"
210 char *priorities;
211 #line 65 "cli.gaa"
212 char **ctype;
213 #line 64 "cli.gaa"
214 int nctype;
215 #line 61 "cli.gaa"
216 char **kx;
217 #line 60 "cli.gaa"
218 int nkx;
219 #line 57 "cli.gaa"
220 char **macs;
221 #line 56 "cli.gaa"
222 int nmacs;
223 #line 53 "cli.gaa"
224 char **comp;
225 #line 52 "cli.gaa"
226 int ncomp;
227 #line 49 "cli.gaa"
228 char **proto;
229 #line 48 "cli.gaa"
230 int nproto;
231 #line 45 "cli.gaa"
232 char **ciphers;
233 #line 44 "cli.gaa"
234 int nciphers;
235 #line 41 "cli.gaa"
236 int verbose;
237 #line 38 "cli.gaa"
238 int record_size;
239 #line 35 "cli.gaa"
240 int print_cert;
241 #line 32 "cli.gaa"
242 int disable_extensions;
243 #line 29 "cli.gaa"
244 int fingerprint;
245 #line 26 "cli.gaa"
246 int fmtder;
247 #line 23 "cli.gaa"
248 int crlf;
249 #line 20 "cli.gaa"
250 int starttls;
251 #line 17 "cli.gaa"
252 int resume;
253 #line 14 "cli.gaa"
254 int debug;
256 #line 114 "gaa.skel"
259 #ifdef __cplusplus
260 extern "C"
262 #endif
264 int gaa(int argc, char *argv[], gaainfo *gaaval);
266 void gaa_help(void);
268 int gaa_file(const char *name, gaainfo *gaaval);
270 #ifdef __cplusplus
272 #endif
275 #endif
277 #line 135 "gaa.skel"
279 /* C declarations */
281 #define GAAERROR(x) \
283 gaa_error = 1; \
284 return x; \
287 static char *gaa_current_option;
288 static int gaa_error = 0;
290 /* Generated by gaa */
292 #include <string.h>
293 #include <stdlib.h>
296 #define GAA_OK -1
298 #define GAA_ERROR_NOMATCH 0
299 #define GAA_ERROR_NOTENOUGH_ARGS 1
300 #define GAA_ERROR_INVALID_ARG 2
301 #define GAA_ERROR_UNKNOWN 3
303 #define GAA_NOT_AN_OPTION 0
304 #define GAA_WORD_OPTION 1
305 #define GAA_LETTER_OPTION 2
306 #define GAA_MULTIPLE_OPTION 3
308 #define GAA_REST 0
309 #define GAA_NB_OPTION 35
310 #define GAAOPTID_copyright 1
311 #define GAAOPTID_version 2
312 #define GAAOPTID_help 3
313 #define GAAOPTID_list 4
314 #define GAAOPTID_insecure 5
315 #define GAAOPTID_port 6
316 #define GAAOPTID_opaque_prf_input 7
317 #define GAAOPTID_pskkey 8
318 #define GAAOPTID_pskusername 9
319 #define GAAOPTID_srppasswd 10
320 #define GAAOPTID_srpusername 11
321 #define GAAOPTID_x509certfile 12
322 #define GAAOPTID_x509keyfile 13
323 #define GAAOPTID_pgpcertfile 14
324 #define GAAOPTID_pgpkeyring 15
325 #define GAAOPTID_pgpkeyfile 16
326 #define GAAOPTID_x509crlfile 17
327 #define GAAOPTID_x509cafile 18
328 #define GAAOPTID_priority 19
329 #define GAAOPTID_ctypes 20
330 #define GAAOPTID_kx 21
331 #define GAAOPTID_macs 22
332 #define GAAOPTID_comp 23
333 #define GAAOPTID_protocols 24
334 #define GAAOPTID_ciphers 25
335 #define GAAOPTID_verbose 26
336 #define GAAOPTID_recordsize 27
337 #define GAAOPTID_print_cert 28
338 #define GAAOPTID_disable_extensions 29
339 #define GAAOPTID_fingerprint 30
340 #define GAAOPTID_x509fmtder 31
341 #define GAAOPTID_crlf 32
342 #define GAAOPTID_starttls 33
343 #define GAAOPTID_resume 34
344 #define GAAOPTID_debug 35
346 #line 168 "gaa.skel"
348 #define GAA_CHECK1STR(a,b) \
349 if(a[0] == str[0]) \
351 gaa_current_option = a; \
352 return b; \
355 #define GAA_CHECKSTR(a,b) \
356 if(strcmp(a,str) == 0) \
358 gaa_current_option = a; \
359 return b; \
362 #define GAA_TESTMOREARGS \
363 if(!OK) \
365 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
366 gaa_index++; \
367 if(gaa_last_non_option == gaa_index) \
368 return GAA_ERROR_NOTENOUGH_ARGS; \
371 #define GAA_TESTMOREOPTIONALARGS \
372 if(!OK) \
374 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
375 gaa_index++; \
376 if(gaa_last_non_option == gaa_index) \
377 OK = 1; \
380 #define GAA_FILL_2ARGS(target, func) \
381 target = func(GAAargv[gaa_index]); \
382 gaa_arg_used[gaa_index] = 1; \
383 if(gaa_error == 1) \
385 gaa_error = 0; \
386 return GAA_ERROR_INVALID_ARG; \
391 #define GAA_FILL(target, func, num) \
392 if(!OK) \
394 target = func(GAAargv[gaa_index]); \
395 gaa_arg_used[gaa_index] = 1; \
396 if(gaa_error == 1) \
398 gaa_error = 0; \
399 return GAA_ERROR_INVALID_ARG; \
401 num = 1; \
403 else \
405 num = 0; \
408 #define GAA_LIST_FILL(target, func, type ,num) \
409 if(!OK) \
411 num = 0; \
412 target = NULL; \
413 if ( gaa_last_non_option - gaa_index > 0) \
414 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
415 for(; gaa_index < gaa_last_non_option; gaa_index++) \
417 if(gaa_arg_used[gaa_index] == 0) \
419 GAA_FILL_2ARGS(target[num], func); \
420 num++; \
423 if(num == 0) \
424 return GAA_ERROR_NOTENOUGH_ARGS; \
427 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
428 if(!OK) \
430 num = 0; \
431 target = NULL; \
432 if ( gaa_last_non_option - gaa_index > 0) \
433 target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
434 for(; gaa_index < gaa_last_non_option; gaa_index++) \
436 if(gaa_arg_used[gaa_index] == 0) \
438 GAA_FILL_2ARGS(target[num], func); \
439 num++; \
444 #define GAA_OBLIGAT(str) \
445 k = 0; \
446 for(i = 0; i < strlen(str); i++) \
448 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
449 if(j == GAA_ERROR_NOMATCH) \
451 printf("Error: invalid 'obligat' set\n"); \
452 exit(-1); \
454 if(opt_list[j] == 1) \
455 k = 1; \
457 if(k == 0) \
459 if(strlen(str) == 1) \
460 printf("You must give the -%s option\n", str); \
461 else \
462 printf("You must give at least one option of '%s'\n", str); \
463 return 0; \
466 #define GAA_INCOMP(str) \
467 k = 0; \
468 for(i = 0; i < strlen(str); i++) \
470 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
471 if(j == GAA_ERROR_NOMATCH) \
473 printf("Error: invalid 'obligat' set\n"); \
474 exit(-1); \
476 if(opt_list[j] == 1) \
477 k++; \
479 if(k > 1) \
481 printf("The options '%s' are incompatible\n", str); \
482 return 0; \
486 static char **GAAargv;
487 static int GAAargc;
488 static char *gaa_arg_used;
489 static int gaa_processing_file = 0;
490 static int inited = 0;
492 static int gaa_getint(char *arg)
494 int tmp;
495 char a;
496 if(sscanf(arg, "%d%c", &tmp, &a) < 1)
498 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
499 GAAERROR(-1);
501 return tmp;
504 static char gaa_getchar(char *arg)
506 if(strlen(arg) != 1)
508 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
509 GAAERROR(-1);
511 return arg[0];
514 static char* gaa_getstr(char *arg)
516 return arg;
518 static float gaa_getfloat(char *arg)
520 float tmp;
521 char a;
522 if(sscanf(arg, "%f%c", &tmp, &a) < 1)
524 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
525 GAAERROR(-1);
527 return tmp;
529 /* option structures */
531 struct GAAOPTION_port
533 char* arg1;
534 int size1;
537 struct GAAOPTION_opaque_prf_input
539 char* arg1;
540 int size1;
543 struct GAAOPTION_pskkey
545 char* arg1;
546 int size1;
549 struct GAAOPTION_pskusername
551 char* arg1;
552 int size1;
555 struct GAAOPTION_srppasswd
557 char* arg1;
558 int size1;
561 struct GAAOPTION_srpusername
563 char* arg1;
564 int size1;
567 struct GAAOPTION_x509certfile
569 char* arg1;
570 int size1;
573 struct GAAOPTION_x509keyfile
575 char* arg1;
576 int size1;
579 struct GAAOPTION_pgpcertfile
581 char* arg1;
582 int size1;
585 struct GAAOPTION_pgpkeyring
587 char* arg1;
588 int size1;
591 struct GAAOPTION_pgpkeyfile
593 char* arg1;
594 int size1;
597 struct GAAOPTION_x509crlfile
599 char* arg1;
600 int size1;
603 struct GAAOPTION_x509cafile
605 char* arg1;
606 int size1;
609 struct GAAOPTION_priority
611 char* arg1;
612 int size1;
615 struct GAAOPTION_ctypes
617 char** arg1;
618 int size1;
621 struct GAAOPTION_kx
623 char** arg1;
624 int size1;
627 struct GAAOPTION_macs
629 char** arg1;
630 int size1;
633 struct GAAOPTION_comp
635 char** arg1;
636 int size1;
639 struct GAAOPTION_protocols
641 char** arg1;
642 int size1;
645 struct GAAOPTION_ciphers
647 char** arg1;
648 int size1;
651 struct GAAOPTION_recordsize
653 int arg1;
654 int size1;
657 struct GAAOPTION_debug
659 int arg1;
660 int size1;
662 #define GAA_REST_EXISTS
664 struct GAAREST
666 char* arg1;
667 int size1;
670 #line 349 "gaa.skel"
671 static int gaa_is_an_argument(char *str)
673 #ifdef GAA_WIN32
674 if(str[0] == '/' && str[1] != 0)
675 return GAA_MULTIPLE_OPTION;
676 #endif
677 if(str[0] != '-')
678 return GAA_NOT_AN_OPTION;
679 if(str[1] == 0)
680 return GAA_NOT_AN_OPTION;
681 if(str[1] == '-')
683 if(str[2] != 0)
684 return GAA_WORD_OPTION;
685 else
686 return GAA_NOT_AN_OPTION;
688 if(str[2] == 0)
689 return GAA_LETTER_OPTION;
690 else
691 return GAA_MULTIPLE_OPTION;
694 static int gaa_get_option_num(char *str, int status)
696 switch(status)
698 case GAA_LETTER_OPTION:
699 GAA_CHECK1STR("p", GAAOPTID_port);
700 GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
701 GAA_CHECK1STR("", GAAOPTID_pskkey);
702 GAA_CHECK1STR("", GAAOPTID_pskusername);
703 GAA_CHECK1STR("", GAAOPTID_srppasswd);
704 GAA_CHECK1STR("", GAAOPTID_srpusername);
705 GAA_CHECK1STR("", GAAOPTID_x509certfile);
706 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
707 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
708 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
709 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
710 GAA_CHECK1STR("", GAAOPTID_x509crlfile);
711 GAA_CHECK1STR("", GAAOPTID_x509cafile);
712 GAA_CHECK1STR("", GAAOPTID_priority);
713 GAA_CHECK1STR("", GAAOPTID_ctypes);
714 GAA_CHECK1STR("", GAAOPTID_kx);
715 GAA_CHECK1STR("", GAAOPTID_macs);
716 GAA_CHECK1STR("", GAAOPTID_comp);
717 GAA_CHECK1STR("", GAAOPTID_protocols);
718 GAA_CHECK1STR("", GAAOPTID_ciphers);
719 GAA_CHECK1STR("", GAAOPTID_recordsize);
720 GAA_CHECK1STR("d", GAAOPTID_debug);
721 case GAA_MULTIPLE_OPTION:
722 #line 375 "gaa.skel"
723 GAA_CHECK1STR("", GAAOPTID_copyright);
724 GAA_CHECK1STR("v", GAAOPTID_version);
725 GAA_CHECK1STR("h", GAAOPTID_help);
726 GAA_CHECK1STR("l", GAAOPTID_list);
727 GAA_CHECK1STR("", GAAOPTID_insecure);
728 GAA_CHECK1STR("V", GAAOPTID_verbose);
729 GAA_CHECK1STR("", GAAOPTID_print_cert);
730 GAA_CHECK1STR("", GAAOPTID_disable_extensions);
731 GAA_CHECK1STR("f", GAAOPTID_fingerprint);
732 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
733 GAA_CHECK1STR("", GAAOPTID_crlf);
734 GAA_CHECK1STR("s", GAAOPTID_starttls);
735 GAA_CHECK1STR("r", GAAOPTID_resume);
737 #line 277 "gaa.skel"
738 break;
739 case GAA_WORD_OPTION:
740 GAA_CHECKSTR("copyright", GAAOPTID_copyright);
741 GAA_CHECKSTR("version", GAAOPTID_version);
742 GAA_CHECKSTR("help", GAAOPTID_help);
743 GAA_CHECKSTR("list", GAAOPTID_list);
744 GAA_CHECKSTR("insecure", GAAOPTID_insecure);
745 GAA_CHECKSTR("port", GAAOPTID_port);
746 GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
747 GAA_CHECKSTR("pskkey", GAAOPTID_pskkey);
748 GAA_CHECKSTR("pskusername", GAAOPTID_pskusername);
749 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
750 GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
751 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
752 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
753 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
754 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
755 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
756 GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
757 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
758 GAA_CHECKSTR("priority", GAAOPTID_priority);
759 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
760 GAA_CHECKSTR("kx", GAAOPTID_kx);
761 GAA_CHECKSTR("macs", GAAOPTID_macs);
762 GAA_CHECKSTR("comp", GAAOPTID_comp);
763 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
764 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
765 GAA_CHECKSTR("verbose", GAAOPTID_verbose);
766 GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
767 GAA_CHECKSTR("print-cert", GAAOPTID_print_cert);
768 GAA_CHECKSTR("disable-extensions", GAAOPTID_disable_extensions);
769 GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
770 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
771 GAA_CHECKSTR("crlf", GAAOPTID_crlf);
772 GAA_CHECKSTR("starttls", GAAOPTID_starttls);
773 GAA_CHECKSTR("resume", GAAOPTID_resume);
774 GAA_CHECKSTR("debug", GAAOPTID_debug);
776 #line 281 "gaa.skel"
777 break;
778 default: break;
780 return GAA_ERROR_NOMATCH;
783 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
785 int OK = 0;
786 int gaa_last_non_option;
787 struct GAAOPTION_port GAATMP_port;
788 struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
789 struct GAAOPTION_pskkey GAATMP_pskkey;
790 struct GAAOPTION_pskusername GAATMP_pskusername;
791 struct GAAOPTION_srppasswd GAATMP_srppasswd;
792 struct GAAOPTION_srpusername GAATMP_srpusername;
793 struct GAAOPTION_x509certfile GAATMP_x509certfile;
794 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
795 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
796 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
797 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
798 struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
799 struct GAAOPTION_x509cafile GAATMP_x509cafile;
800 struct GAAOPTION_priority GAATMP_priority;
801 struct GAAOPTION_ctypes GAATMP_ctypes;
802 struct GAAOPTION_kx GAATMP_kx;
803 struct GAAOPTION_macs GAATMP_macs;
804 struct GAAOPTION_comp GAATMP_comp;
805 struct GAAOPTION_protocols GAATMP_protocols;
806 struct GAAOPTION_ciphers GAATMP_ciphers;
807 struct GAAOPTION_recordsize GAATMP_recordsize;
808 struct GAAOPTION_debug GAATMP_debug;
810 #line 393 "gaa.skel"
811 #ifdef GAA_REST_EXISTS
812 struct GAAREST GAAREST_tmp;
813 #endif
815 opt_list[gaa_num] = 1;
817 for(gaa_last_non_option = gaa_index;
818 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
819 gaa_last_non_option++);
821 if(gaa_num == GAA_REST)
823 gaa_index = 1;
824 gaa_last_non_option = GAAargc;
827 switch(gaa_num)
829 case GAAOPTID_copyright:
830 OK = 0;
831 #line 117 "cli.gaa"
832 { print_license(); exit(0); ;};
834 return GAA_OK;
835 break;
836 case GAAOPTID_version:
837 OK = 0;
838 #line 116 "cli.gaa"
839 { cli_version(); exit(0); ;};
841 return GAA_OK;
842 break;
843 case GAAOPTID_help:
844 OK = 0;
845 #line 114 "cli.gaa"
846 { gaa_help(); exit(0); ;};
848 return GAA_OK;
849 break;
850 case GAAOPTID_list:
851 OK = 0;
852 #line 113 "cli.gaa"
853 { print_list(gaaval->verbose); exit(0); ;};
855 return GAA_OK;
856 break;
857 case GAAOPTID_insecure:
858 OK = 0;
859 #line 111 "cli.gaa"
860 { gaaval->insecure = 1 ;};
862 return GAA_OK;
863 break;
864 case GAAOPTID_port:
865 OK = 0;
866 GAA_TESTMOREARGS;
867 GAA_FILL(GAATMP_port.arg1, gaa_getstr, GAATMP_port.size1);
868 gaa_index++;
869 #line 108 "cli.gaa"
870 { gaaval->port = GAATMP_port.arg1 ;};
872 return GAA_OK;
873 break;
874 case GAAOPTID_opaque_prf_input:
875 OK = 0;
876 GAA_TESTMOREARGS;
877 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
878 gaa_index++;
879 #line 105 "cli.gaa"
880 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
882 return GAA_OK;
883 break;
884 case GAAOPTID_pskkey:
885 OK = 0;
886 GAA_TESTMOREARGS;
887 GAA_FILL(GAATMP_pskkey.arg1, gaa_getstr, GAATMP_pskkey.size1);
888 gaa_index++;
889 #line 102 "cli.gaa"
890 { gaaval->psk_key = GAATMP_pskkey.arg1 ;};
892 return GAA_OK;
893 break;
894 case GAAOPTID_pskusername:
895 OK = 0;
896 GAA_TESTMOREARGS;
897 GAA_FILL(GAATMP_pskusername.arg1, gaa_getstr, GAATMP_pskusername.size1);
898 gaa_index++;
899 #line 99 "cli.gaa"
900 { gaaval->psk_username = GAATMP_pskusername.arg1 ;};
902 return GAA_OK;
903 break;
904 case GAAOPTID_srppasswd:
905 OK = 0;
906 GAA_TESTMOREARGS;
907 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
908 gaa_index++;
909 #line 96 "cli.gaa"
910 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
912 return GAA_OK;
913 break;
914 case GAAOPTID_srpusername:
915 OK = 0;
916 GAA_TESTMOREARGS;
917 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
918 gaa_index++;
919 #line 93 "cli.gaa"
920 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
922 return GAA_OK;
923 break;
924 case GAAOPTID_x509certfile:
925 OK = 0;
926 GAA_TESTMOREARGS;
927 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
928 gaa_index++;
929 #line 90 "cli.gaa"
930 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
932 return GAA_OK;
933 break;
934 case GAAOPTID_x509keyfile:
935 OK = 0;
936 GAA_TESTMOREARGS;
937 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
938 gaa_index++;
939 #line 87 "cli.gaa"
940 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
942 return GAA_OK;
943 break;
944 case GAAOPTID_pgpcertfile:
945 OK = 0;
946 GAA_TESTMOREARGS;
947 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
948 gaa_index++;
949 #line 84 "cli.gaa"
950 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
952 return GAA_OK;
953 break;
954 case GAAOPTID_pgpkeyring:
955 OK = 0;
956 GAA_TESTMOREARGS;
957 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
958 gaa_index++;
959 #line 81 "cli.gaa"
960 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
962 return GAA_OK;
963 break;
964 case GAAOPTID_pgpkeyfile:
965 OK = 0;
966 GAA_TESTMOREARGS;
967 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
968 gaa_index++;
969 #line 78 "cli.gaa"
970 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
972 return GAA_OK;
973 break;
974 case GAAOPTID_x509crlfile:
975 OK = 0;
976 GAA_TESTMOREARGS;
977 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
978 gaa_index++;
979 #line 75 "cli.gaa"
980 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
982 return GAA_OK;
983 break;
984 case GAAOPTID_x509cafile:
985 OK = 0;
986 GAA_TESTMOREARGS;
987 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
988 gaa_index++;
989 #line 72 "cli.gaa"
990 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
992 return GAA_OK;
993 break;
994 case GAAOPTID_priority:
995 OK = 0;
996 GAA_TESTMOREARGS;
997 GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1);
998 gaa_index++;
999 #line 69 "cli.gaa"
1000 { gaaval->priorities = GAATMP_priority.arg1 ;};
1002 return GAA_OK;
1003 break;
1004 case GAAOPTID_ctypes:
1005 OK = 0;
1006 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
1007 #line 66 "cli.gaa"
1008 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
1010 return GAA_OK;
1011 break;
1012 case GAAOPTID_kx:
1013 OK = 0;
1014 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
1015 #line 62 "cli.gaa"
1016 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
1018 return GAA_OK;
1019 break;
1020 case GAAOPTID_macs:
1021 OK = 0;
1022 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
1023 #line 58 "cli.gaa"
1024 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
1026 return GAA_OK;
1027 break;
1028 case GAAOPTID_comp:
1029 OK = 0;
1030 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
1031 #line 54 "cli.gaa"
1032 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
1034 return GAA_OK;
1035 break;
1036 case GAAOPTID_protocols:
1037 OK = 0;
1038 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
1039 #line 50 "cli.gaa"
1040 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
1042 return GAA_OK;
1043 break;
1044 case GAAOPTID_ciphers:
1045 OK = 0;
1046 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
1047 #line 46 "cli.gaa"
1048 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
1050 return GAA_OK;
1051 break;
1052 case GAAOPTID_verbose:
1053 OK = 0;
1054 #line 42 "cli.gaa"
1055 { gaaval->verbose = 1 ;};
1057 return GAA_OK;
1058 break;
1059 case GAAOPTID_recordsize:
1060 OK = 0;
1061 GAA_TESTMOREARGS;
1062 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
1063 gaa_index++;
1064 #line 39 "cli.gaa"
1065 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
1067 return GAA_OK;
1068 break;
1069 case GAAOPTID_print_cert:
1070 OK = 0;
1071 #line 36 "cli.gaa"
1072 { gaaval->print_cert = 1 ;};
1074 return GAA_OK;
1075 break;
1076 case GAAOPTID_disable_extensions:
1077 OK = 0;
1078 #line 33 "cli.gaa"
1079 { gaaval->disable_extensions = 1 ;};
1081 return GAA_OK;
1082 break;
1083 case GAAOPTID_fingerprint:
1084 OK = 0;
1085 #line 30 "cli.gaa"
1086 { gaaval->fingerprint = 1 ;};
1088 return GAA_OK;
1089 break;
1090 case GAAOPTID_x509fmtder:
1091 OK = 0;
1092 #line 27 "cli.gaa"
1093 { gaaval->fmtder = 1 ;};
1095 return GAA_OK;
1096 break;
1097 case GAAOPTID_crlf:
1098 OK = 0;
1099 #line 24 "cli.gaa"
1100 { gaaval->crlf = 1 ;};
1102 return GAA_OK;
1103 break;
1104 case GAAOPTID_starttls:
1105 OK = 0;
1106 #line 21 "cli.gaa"
1107 { gaaval->starttls = 1 ;};
1109 return GAA_OK;
1110 break;
1111 case GAAOPTID_resume:
1112 OK = 0;
1113 #line 18 "cli.gaa"
1114 { gaaval->resume = 1 ;};
1116 return GAA_OK;
1117 break;
1118 case GAAOPTID_debug:
1119 OK = 0;
1120 GAA_TESTMOREARGS;
1121 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1122 gaa_index++;
1123 #line 15 "cli.gaa"
1124 { gaaval->debug = GAATMP_debug.arg1 ;};
1126 return GAA_OK;
1127 break;
1128 case GAA_REST:
1129 GAA_TESTMOREARGS;
1130 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
1131 gaa_index++;
1132 #line 120 "cli.gaa"
1133 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
1135 return GAA_OK;
1136 break;
1138 #line 413 "gaa.skel"
1139 default: break;
1141 return GAA_ERROR_UNKNOWN;
1144 int gaa(int argc, char **argv, gaainfo *gaaval)
1146 int tmp1, tmp2;
1147 int i, j;
1148 char *opt_list;
1150 GAAargv = argv;
1151 GAAargc = argc;
1153 opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1155 for(i = 0; i < GAA_NB_OPTION + 1; i++)
1156 opt_list[i] = 0;
1157 /* initialization */
1158 if(inited == 0)
1161 #line 122 "cli.gaa"
1162 { gaaval->resume=0; gaaval->port="443"; gaaval->rest_args=NULL; gaaval->ciphers=NULL;
1163 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
1164 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->record_size=0;
1165 gaaval->fingerprint=0; gaaval->pgp_keyring=NULL; gaaval->x509_crlfile = NULL;
1166 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL; gaaval->disable_extensions = 0;
1167 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->crlf = 0;
1168 gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; gaaval->fmtder = 0; gaaval->starttls =0;
1169 gaaval->debug = 0; gaaval->print_cert = 0; gaaval->verbose = 0; gaaval->psk_key = NULL;
1170 gaaval->psk_username = NULL; gaaval->priorities = NULL;
1171 gaaval->opaque_prf_input = NULL; ;};
1174 inited = 1;
1175 #line 438 "gaa.skel"
1176 gaa_arg_used = NULL;
1178 if (argc > 0) {
1179 gaa_arg_used = gaa_malloc(argc * sizeof(char));
1182 for(i = 1; i < argc; i++)
1183 gaa_arg_used[i] = 0;
1184 for(i = 1; i < argc; i++)
1186 if(gaa_arg_used[i] == 0)
1188 j = 0;
1189 tmp1 = gaa_is_an_argument(GAAargv[i]);
1190 switch(tmp1)
1192 case GAA_WORD_OPTION:
1193 j++;
1194 case GAA_LETTER_OPTION:
1195 j++;
1196 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1197 if(tmp2 == GAA_ERROR_NOMATCH)
1199 printf("Invalid option '%s'\n", argv[i]+j);
1200 return 0;
1202 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1204 case GAA_ERROR_NOTENOUGH_ARGS:
1205 printf("'%s': not enough arguments\n",gaa_current_option);
1206 return 0;
1207 case GAA_ERROR_INVALID_ARG:
1208 printf("Invalid arguments\n");
1209 return 0;
1210 case GAA_OK:
1211 break;
1212 default:
1213 printf("Unknown error\n");
1215 gaa_arg_used[i] = 1;
1216 break;
1217 case GAA_MULTIPLE_OPTION:
1218 for(j = 1; j < strlen(argv[i]); j++)
1220 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1221 if(tmp2 == GAA_ERROR_NOMATCH)
1223 printf("Invalid option '%c'\n", *(argv[i]+j));
1224 return 0;
1226 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1228 case GAA_ERROR_NOTENOUGH_ARGS:
1229 printf("'%s': not enough arguments\n",gaa_current_option);
1230 return 0;
1231 case GAA_ERROR_INVALID_ARG:
1232 printf("Invalid arguments\n");
1233 return 0;
1234 case GAA_OK:
1235 break;
1236 default:
1237 printf("Unknown error\n");
1240 gaa_arg_used[i] = 1;
1241 break;
1242 default: break;
1246 if(gaa_processing_file == 0)
1249 #line 507 "gaa.skel"
1250 #ifdef GAA_REST_EXISTS
1251 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1253 case GAA_ERROR_NOTENOUGH_ARGS:
1254 printf("Rest: not enough arguments\n");
1255 return 0;
1256 case GAA_ERROR_INVALID_ARG:
1257 printf("Invalid arguments\n");
1258 return 0;
1259 case GAA_OK:
1260 break;
1261 default:
1262 printf("Unknown error\n");
1264 #endif
1266 for(i = 1; i < argc; i++)
1268 if(gaa_arg_used[i] == 0)
1270 printf("Too many arguments\n");
1271 return 0;
1274 free(gaa_arg_used);
1275 free(opt_list);
1276 return -1;
1279 struct gaastrnode
1281 char *str;
1282 struct gaastrnode *next;
1285 typedef struct gaastrnode gaa_str_node;
1287 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1289 int pos_ini;
1290 int a;
1291 int i = 0, len = 0, newline = 0;
1293 if(argc == 1) {
1294 newline = 1;
1295 len = 2;
1298 a = fgetc( file);
1299 if (a == EOF) return 0;
1301 while(a == ' ' || a == 9 || a == '\n')
1303 if(a == '\n')
1305 newline=1;
1306 len = 2;
1308 a = fgetc( file);
1309 if (a == EOF) return 0;
1312 pos_ini = ftell(file) - 1;
1314 while(a != ' ' && a != 9 && a != '\n')
1317 len++;
1318 a = fgetc( file);
1319 if(a==EOF) return 0; //a = ' ';
1322 len += 1;
1323 tmp_str->str = gaa_malloc((len) * sizeof(char));
1325 if(newline == 1)
1327 tmp_str->str[0] = '-';
1328 tmp_str->str[1] = '-';
1329 i = 2;
1331 else
1333 i = 0;
1336 fseek(file,pos_ini, SEEK_SET);
1339 a = fgetc( file);
1341 if (a == EOF) {
1342 i+=2;
1343 break;
1345 tmp_str->str[i] = a;
1346 i++;
1348 while(a != ' ' && a != 9 && a != '\n' && i < len);
1350 tmp_str->str[i - 1] = 0;
1352 fseek(file,- 1, SEEK_CUR);
1353 /* printf("%d\n", ftell(file)); */
1355 return -1;
1358 int gaa_file(const char *name, gaainfo *gaaval)
1360 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1361 int rval, i;
1362 char **argv;
1363 int argc = 0;
1364 FILE *file;
1366 gaa_processing_file = 1;
1368 if((file = fopen(name, "r")) == NULL)
1370 printf("Couldn't open '%s' configuration file for reading\n", name);
1371 return 1;
1374 tmp_str = &first_str;
1377 argc++;
1378 *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1380 (*tmp_str)->str = NULL;
1381 (*tmp_str)->next = NULL;
1383 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1384 tmp_str = &((*tmp_str)->next);
1386 while(rval == -1);
1388 if(rval == 1)
1389 return 0;
1391 argv = gaa_malloc((1 + argc) * sizeof(char*));
1393 tmp_str2 = first_str;
1394 argv[0] = "cfg";
1395 for(i = 1; i < argc; i++)
1397 argv[i] = tmp_str2->str;
1398 tmp_str2 = tmp_str2->next;
1401 rval = gaa(argc, argv, gaaval);
1402 gaa_processing_file = 0;
1403 return rval;