Optimized memory handling in the record protocol.
[gnutls.git] / src / cli-gaa.c
blob8e913699463cec12fb5eb0ec66f6cc3326506a8e
1 /* File generated by GAA 1.6.0
2 */
3 #define GAA_NO_WIN32
4 #line 91 "cli.gaa"
6 /* C declarations */
8 #include <common.h>
9 #include <stdio.h>
10 #include <string.h>
12 #ifndef GAA_NO_WIN32
13 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
14 #define GAA_WIN32
15 #endif
16 #endif
18 void __gaa_helpsingle(char short_name, char *name,
19 char *arg_desc, char *opt_help)
21 int col1, col3, col4, tabsize = 3, curr;
22 int i;
24 col1 = 5; /* Default values */
25 col3 = 30;
26 col4 = 70;
28 curr = 0;
29 for(i = 0; i < col1; i++)
31 printf(" ");
32 curr++;
34 if(short_name)
36 if(name && *name)
38 printf("-%c, ", short_name);
39 curr += 4;
41 else
43 printf("-%c ", short_name);
44 curr += 3;
47 if(name && *name)
49 printf("--%s ", name);
50 curr += 3 + strlen(name);
52 if(arg_desc && *arg_desc)
54 printf("%s ", arg_desc);
55 curr += 1 + strlen(arg_desc);
57 if(curr >= col3)
59 printf("\n");
60 curr = 0;
62 if(opt_help) /* let's print the option's help body */
64 const char *str = opt_help;
65 while(*str)
67 while(curr < col3)
69 printf(" ");
70 curr++;
72 switch(*str)
74 case '\n':
75 printf("\n");
76 curr = 0;
77 break;
78 case '\t':
81 printf(" ");
82 curr++;
84 while((curr - col3) % tabsize != 0 && curr < col4);
85 case ' ':
86 if(*str == ' ')
88 curr++;
89 printf(" ");
91 for(i = 1; str[i] && str[i] != ' ' && str[i] != '\n'
92 && str[i] != '\t'; i++);
93 if(curr + i - 1 >= col4)
94 curr = col4;
95 break;
96 default:
97 printf("%c", *str);
98 curr++;
100 if(curr >= col4)
102 printf("\n");
103 curr = 0;
105 str++;
108 printf("\n");
111 void gaa_help(void)
113 printf("gnutls-cli help\nUsage: gnutls-cli [options] hostname""\n");
114 __gaa_helpsingle('r', "resume", "", "Connect, establish a session. Connect again and resume this session.");
115 __gaa_helpsingle(0, "crlf", "", "Send CR LF instead of LF.");
116 __gaa_helpsingle(0, "x509fmtder", "", "Use DER format for certificates");
117 __gaa_helpsingle('f', "fingerprint", "", "Send the openpgp fingerprint, instead of the key.");
118 __gaa_helpsingle('p', "port", """integer"" ", "The port to connect to.");
119 __gaa_helpsingle(0, "recordsize", """integer"" ", "The maximum record size to advertize.");
120 __gaa_helpsingle(0, "ciphers", """cipher1 cipher2..."" ", "Ciphers to enable.");
121 __gaa_helpsingle(0, "protocols", """protocol1 protocol2..."" ", "Protocols to enable.");
122 __gaa_helpsingle(0, "comp", """comp1 comp2..."" ", "Compression methods to enable.");
123 __gaa_helpsingle(0, "macs", """mac1 mac2..."" ", "MACs to enable.");
124 __gaa_helpsingle(0, "kx", """kx1 kx2..."" ", "Key exchange methods to enable.");
125 __gaa_helpsingle(0, "ctypes", """certType1 certType2..."" ", "Certificate types to enable.");
126 __gaa_helpsingle(0, "x509cafile", """FILE"" ", "Certificate file to use.");
127 __gaa_helpsingle(0, "pgpkeyfile", """FILE"" ", "PGP Key file to use.");
128 __gaa_helpsingle(0, "pgpkeyring", """FILE"" ", "PGP Key ring file to use.");
129 __gaa_helpsingle(0, "pgptrustdb", """FILE"" ", "PGP trustdb file to use.");
130 __gaa_helpsingle(0, "pgpcertfile", """FILE"" ", "PGP Public Key (certificate) file to use.");
131 __gaa_helpsingle(0, "x509keyfile", """FILE"" ", "X.509 key file to use.");
132 __gaa_helpsingle(0, "x509certfile", """FILE"" ", "X.509 Certificate file to use.");
133 __gaa_helpsingle(0, "srpusername", """NAME"" ", "SRP username to use.");
134 __gaa_helpsingle(0, "srppasswd", """PASSWD"" ", "SRP password to use.");
135 __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
136 __gaa_helpsingle('h', "help", "", "prints this help");
138 #line 100 "gaa.skel"
140 /* Copy of C area */
142 #line 104 "gaa.skel"
143 /* GAA HEADER */
144 #ifndef GAA_HEADER_POKY
145 #define GAA_HEADER_POKY
147 typedef struct _gaainfo gaainfo;
149 struct _gaainfo
151 #line 78 "cli.gaa"
152 char **rest_args;
153 #line 77 "cli.gaa"
154 int nrest_args;
155 #line 70 "cli.gaa"
156 char *srp_passwd;
157 #line 67 "cli.gaa"
158 char *srp_username;
159 #line 64 "cli.gaa"
160 char *x509_certfile;
161 #line 61 "cli.gaa"
162 char *x509_keyfile;
163 #line 58 "cli.gaa"
164 char *pgp_certfile;
165 #line 55 "cli.gaa"
166 char *pgp_trustdb;
167 #line 52 "cli.gaa"
168 char *pgp_keyring;
169 #line 49 "cli.gaa"
170 char *pgp_keyfile;
171 #line 46 "cli.gaa"
172 char *x509_cafile;
173 #line 43 "cli.gaa"
174 char **ctype;
175 #line 42 "cli.gaa"
176 int nctype;
177 #line 39 "cli.gaa"
178 char **kx;
179 #line 38 "cli.gaa"
180 int nkx;
181 #line 35 "cli.gaa"
182 char **macs;
183 #line 34 "cli.gaa"
184 int nmacs;
185 #line 31 "cli.gaa"
186 char **comp;
187 #line 30 "cli.gaa"
188 int ncomp;
189 #line 27 "cli.gaa"
190 char **proto;
191 #line 26 "cli.gaa"
192 int nproto;
193 #line 23 "cli.gaa"
194 char **ciphers;
195 #line 22 "cli.gaa"
196 int nciphers;
197 #line 18 "cli.gaa"
198 int record_size;
199 #line 15 "cli.gaa"
200 int port;
201 #line 12 "cli.gaa"
202 int fingerprint;
203 #line 9 "cli.gaa"
204 int fmtder;
205 #line 6 "cli.gaa"
206 int crlf;
207 #line 3 "cli.gaa"
208 int resume;
210 #line 114 "gaa.skel"
213 #ifdef __cplusplus
214 extern "C"
216 #endif
218 int gaa(int argc, char *argv[], gaainfo *gaaval);
220 void gaa_help(void);
222 int gaa_file(char *name, gaainfo *gaaval);
224 #ifdef __cplusplus
226 #endif
229 #endif
231 #line 135 "gaa.skel"
233 /* C declarations */
235 #define GAAERROR(x) \
237 gaa_error = 1; \
238 return x; \
241 char *gaa_current_option;
242 int gaa_error = 0;
244 /* Generated by gaa */
246 #include <string.h>
247 #include <stdlib.h>
250 #define GAA_OK -1
252 #define GAA_ERROR_NOMATCH 0
253 #define GAA_ERROR_NOTENOUGH_ARGS 1
254 #define GAA_ERROR_INVALID_ARG 2
255 #define GAA_ERROR_UNKNOWN 3
257 #define GAA_NOT_AN_OPTION 0
258 #define GAA_WORD_OPTION 1
259 #define GAA_LETTER_OPTION 2
260 #define GAA_MULTIPLE_OPTION 3
262 #define GAA_REST 0
263 #define GAA_NB_OPTION 23
264 #define GAAOPTID_help 1
265 #define GAAOPTID_list 2
266 #define GAAOPTID_srppasswd 3
267 #define GAAOPTID_srpusername 4
268 #define GAAOPTID_x509certfile 5
269 #define GAAOPTID_x509keyfile 6
270 #define GAAOPTID_pgpcertfile 7
271 #define GAAOPTID_pgptrustdb 8
272 #define GAAOPTID_pgpkeyring 9
273 #define GAAOPTID_pgpkeyfile 10
274 #define GAAOPTID_x509cafile 11
275 #define GAAOPTID_ctypes 12
276 #define GAAOPTID_kx 13
277 #define GAAOPTID_macs 14
278 #define GAAOPTID_comp 15
279 #define GAAOPTID_protocols 16
280 #define GAAOPTID_ciphers 17
281 #define GAAOPTID_recordsize 18
282 #define GAAOPTID_port 19
283 #define GAAOPTID_fingerprint 20
284 #define GAAOPTID_x509fmtder 21
285 #define GAAOPTID_crlf 22
286 #define GAAOPTID_resume 23
288 #line 168 "gaa.skel"
290 #define GAA_CHECK1STR(a,b) \
291 if(a[0] == str[0]) \
293 gaa_current_option = a; \
294 return b; \
297 #define GAA_CHECKSTR(a,b) \
298 if(strcmp(a,str) == 0) \
300 gaa_current_option = a; \
301 return b; \
304 #define GAA_TESTMOREARGS \
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 return GAA_ERROR_NOTENOUGH_ARGS; \
313 #define GAA_TESTMOREOPTIONALARGS \
314 if(!OK) \
316 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
317 gaa_index++; \
318 if(gaa_last_non_option == gaa_index) \
319 OK = 1; \
322 #define GAA_FILL_2ARGS(target, func) \
323 target = func(GAAargv[gaa_index]); \
324 gaa_arg_used[gaa_index] = 1; \
325 if(gaa_error == 1) \
327 gaa_error = 0; \
328 return GAA_ERROR_INVALID_ARG; \
333 #define GAA_FILL(target, func, num) \
334 if(!OK) \
336 target = func(GAAargv[gaa_index]); \
337 gaa_arg_used[gaa_index] = 1; \
338 if(gaa_error == 1) \
340 gaa_error = 0; \
341 return GAA_ERROR_INVALID_ARG; \
343 num = 1; \
345 else \
347 num = 0; \
350 #define GAA_LIST_FILL(target, func, type ,num) \
351 if(!OK) \
353 num = 0; \
354 target = NULL; \
355 if ( gaa_last_non_option - gaa_index > 0) \
356 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
357 for(; gaa_index < gaa_last_non_option; gaa_index++) \
359 if(gaa_arg_used[gaa_index] == 0) \
361 GAA_FILL_2ARGS(target[num], func); \
362 num++; \
365 if(num == 0) \
366 return GAA_ERROR_NOTENOUGH_ARGS; \
369 #define GAA_OPTIONALLIST_FILL(target, func, type ,num) \
370 if(!OK) \
372 num = 0; \
373 target = NULL; \
374 if ( gaa_last_non_option - gaa_index > 0) \
375 target = malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
376 for(; gaa_index < gaa_last_non_option; gaa_index++) \
378 if(gaa_arg_used[gaa_index] == 0) \
380 GAA_FILL_2ARGS(target[num], func); \
381 num++; \
386 #define GAA_OBLIGAT(str) \
387 k = 0; \
388 for(i = 0; i < strlen(str); i++) \
390 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
391 if(j == GAA_ERROR_NOMATCH) \
393 printf("Error: invalid 'obligat' set\n"); \
394 exit(-1); \
396 if(opt_list[j] == 1) \
397 k = 1; \
399 if(k == 0) \
401 if(strlen(str) == 1) \
402 printf("You must give the -%s option\n", str); \
403 else \
404 printf("You must give at least one option of '%s'\n", str); \
405 return 0; \
408 #define GAA_INCOMP(str) \
409 k = 0; \
410 for(i = 0; i < strlen(str); i++) \
412 j = gaa_get_option_num(str + i, GAA_LETTER_OPTION); \
413 if(j == GAA_ERROR_NOMATCH) \
415 printf("Error: invalid 'obligat' set\n"); \
416 exit(-1); \
418 if(opt_list[j] == 1) \
419 k++; \
421 if(k > 1) \
423 printf("The options '%s' are incompatible\n", str); \
424 return 0; \
428 char **GAAargv;
429 int GAAargc;
430 char *gaa_arg_used;
431 int gaa_processing_file = 0;
432 int inited = 0;
434 int gaa_getint(char *arg)
436 int tmp;
437 char a;
438 if(sscanf(arg, "%d%c", &tmp, &a) != 1)
440 printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
441 GAAERROR(-1);
443 return tmp;
446 char gaa_getchar(char *arg)
448 if(strlen(arg) != 1)
450 printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
451 GAAERROR(-1);
453 return arg[0];
456 char* gaa_getstr(char *arg)
458 return arg;
460 float gaa_getfloat(char *arg)
462 float tmp;
463 char a;
464 if(sscanf(arg, "%f%c", &tmp, &a) != 1)
466 printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
467 GAAERROR(-1);
469 return tmp;
471 /* option structures */
473 struct GAAOPTION_srppasswd
475 char* arg1;
476 int size1;
479 struct GAAOPTION_srpusername
481 char* arg1;
482 int size1;
485 struct GAAOPTION_x509certfile
487 char* arg1;
488 int size1;
491 struct GAAOPTION_x509keyfile
493 char* arg1;
494 int size1;
497 struct GAAOPTION_pgpcertfile
499 char* arg1;
500 int size1;
503 struct GAAOPTION_pgptrustdb
505 char* arg1;
506 int size1;
509 struct GAAOPTION_pgpkeyring
511 char* arg1;
512 int size1;
515 struct GAAOPTION_pgpkeyfile
517 char* arg1;
518 int size1;
521 struct GAAOPTION_x509cafile
523 char* arg1;
524 int size1;
527 struct GAAOPTION_ctypes
529 char** arg1;
530 int size1;
533 struct GAAOPTION_kx
535 char** arg1;
536 int size1;
539 struct GAAOPTION_macs
541 char** arg1;
542 int size1;
545 struct GAAOPTION_comp
547 char** arg1;
548 int size1;
551 struct GAAOPTION_protocols
553 char** arg1;
554 int size1;
557 struct GAAOPTION_ciphers
559 char** arg1;
560 int size1;
563 struct GAAOPTION_recordsize
565 int arg1;
566 int size1;
569 struct GAAOPTION_port
571 int arg1;
572 int size1;
574 #define GAA_REST_EXISTS
576 struct GAAREST
578 char** arg1;
579 int size1;
582 #line 349 "gaa.skel"
583 int gaa_is_an_argument(char *str)
585 #ifdef GAA_WIN32
586 if(str[0] == '/' && str[1] != 0)
587 return GAA_MULTIPLE_OPTION;
588 #endif
589 if(str[0] != '-')
590 return GAA_NOT_AN_OPTION;
591 if(str[1] == 0)
592 return GAA_NOT_AN_OPTION;
593 if(str[1] == '-')
595 if(str[2] != 0)
596 return GAA_WORD_OPTION;
597 else
598 return GAA_NOT_AN_OPTION;
600 if(str[2] == 0)
601 return GAA_LETTER_OPTION;
602 else
603 return GAA_MULTIPLE_OPTION;
606 int gaa_get_option_num(char *str, int status)
608 switch(status)
610 case GAA_LETTER_OPTION:
611 GAA_CHECK1STR("", GAAOPTID_srppasswd);
612 GAA_CHECK1STR("", GAAOPTID_srpusername);
613 GAA_CHECK1STR("", GAAOPTID_x509certfile);
614 GAA_CHECK1STR("", GAAOPTID_x509keyfile);
615 GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
616 GAA_CHECK1STR("", GAAOPTID_pgptrustdb);
617 GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
618 GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
619 GAA_CHECK1STR("", GAAOPTID_x509cafile);
620 GAA_CHECK1STR("", GAAOPTID_ctypes);
621 GAA_CHECK1STR("", GAAOPTID_kx);
622 GAA_CHECK1STR("", GAAOPTID_macs);
623 GAA_CHECK1STR("", GAAOPTID_comp);
624 GAA_CHECK1STR("", GAAOPTID_protocols);
625 GAA_CHECK1STR("", GAAOPTID_ciphers);
626 GAA_CHECK1STR("", GAAOPTID_recordsize);
627 GAA_CHECK1STR("p", GAAOPTID_port);
628 case GAA_MULTIPLE_OPTION:
629 #line 375 "gaa.skel"
630 GAA_CHECK1STR("h", GAAOPTID_help);
631 GAA_CHECK1STR("l", GAAOPTID_list);
632 GAA_CHECK1STR("f", GAAOPTID_fingerprint);
633 GAA_CHECK1STR("", GAAOPTID_x509fmtder);
634 GAA_CHECK1STR("", GAAOPTID_crlf);
635 GAA_CHECK1STR("r", GAAOPTID_resume);
637 #line 277 "gaa.skel"
638 break;
639 case GAA_WORD_OPTION:
640 GAA_CHECKSTR("help", GAAOPTID_help);
641 GAA_CHECKSTR("list", GAAOPTID_list);
642 GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
643 GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
644 GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
645 GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
646 GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
647 GAA_CHECKSTR("pgptrustdb", GAAOPTID_pgptrustdb);
648 GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
649 GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
650 GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
651 GAA_CHECKSTR("ctypes", GAAOPTID_ctypes);
652 GAA_CHECKSTR("kx", GAAOPTID_kx);
653 GAA_CHECKSTR("macs", GAAOPTID_macs);
654 GAA_CHECKSTR("comp", GAAOPTID_comp);
655 GAA_CHECKSTR("protocols", GAAOPTID_protocols);
656 GAA_CHECKSTR("ciphers", GAAOPTID_ciphers);
657 GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
658 GAA_CHECKSTR("port", GAAOPTID_port);
659 GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
660 GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
661 GAA_CHECKSTR("crlf", GAAOPTID_crlf);
662 GAA_CHECKSTR("resume", GAAOPTID_resume);
664 #line 281 "gaa.skel"
665 break;
666 default: break;
668 return GAA_ERROR_NOMATCH;
671 int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
673 int OK = 0;
674 int gaa_last_non_option;
675 struct GAAOPTION_srppasswd GAATMP_srppasswd;
676 struct GAAOPTION_srpusername GAATMP_srpusername;
677 struct GAAOPTION_x509certfile GAATMP_x509certfile;
678 struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
679 struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
680 struct GAAOPTION_pgptrustdb GAATMP_pgptrustdb;
681 struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
682 struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
683 struct GAAOPTION_x509cafile GAATMP_x509cafile;
684 struct GAAOPTION_ctypes GAATMP_ctypes;
685 struct GAAOPTION_kx GAATMP_kx;
686 struct GAAOPTION_macs GAATMP_macs;
687 struct GAAOPTION_comp GAATMP_comp;
688 struct GAAOPTION_protocols GAATMP_protocols;
689 struct GAAOPTION_ciphers GAATMP_ciphers;
690 struct GAAOPTION_recordsize GAATMP_recordsize;
691 struct GAAOPTION_port GAATMP_port;
693 #line 393 "gaa.skel"
694 #ifdef GAA_REST_EXISTS
695 struct GAAREST GAAREST_tmp;
696 #endif
698 opt_list[gaa_num] = 1;
700 for(gaa_last_non_option = gaa_index;
701 (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
702 gaa_last_non_option++);
704 if(gaa_num == GAA_REST)
706 gaa_index = 1;
707 gaa_last_non_option = GAAargc;
710 switch(gaa_num)
712 case GAAOPTID_help:
713 OK = 0;
714 #line 75 "cli.gaa"
715 { gaa_help(); exit(0); ;};
717 return GAA_OK;
718 break;
719 case GAAOPTID_list:
720 OK = 0;
721 #line 74 "cli.gaa"
722 { print_list(); exit(0); ;};
724 return GAA_OK;
725 break;
726 case GAAOPTID_srppasswd:
727 OK = 0;
728 GAA_TESTMOREARGS;
729 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
730 gaa_index++;
731 #line 71 "cli.gaa"
732 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
734 return GAA_OK;
735 break;
736 case GAAOPTID_srpusername:
737 OK = 0;
738 GAA_TESTMOREARGS;
739 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
740 gaa_index++;
741 #line 68 "cli.gaa"
742 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
744 return GAA_OK;
745 break;
746 case GAAOPTID_x509certfile:
747 OK = 0;
748 GAA_TESTMOREARGS;
749 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
750 gaa_index++;
751 #line 65 "cli.gaa"
752 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
754 return GAA_OK;
755 break;
756 case GAAOPTID_x509keyfile:
757 OK = 0;
758 GAA_TESTMOREARGS;
759 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
760 gaa_index++;
761 #line 62 "cli.gaa"
762 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
764 return GAA_OK;
765 break;
766 case GAAOPTID_pgpcertfile:
767 OK = 0;
768 GAA_TESTMOREARGS;
769 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
770 gaa_index++;
771 #line 59 "cli.gaa"
772 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
774 return GAA_OK;
775 break;
776 case GAAOPTID_pgptrustdb:
777 OK = 0;
778 GAA_TESTMOREARGS;
779 GAA_FILL(GAATMP_pgptrustdb.arg1, gaa_getstr, GAATMP_pgptrustdb.size1);
780 gaa_index++;
781 #line 56 "cli.gaa"
782 { gaaval->pgp_keyring = GAATMP_pgptrustdb.arg1 ;};
784 return GAA_OK;
785 break;
786 case GAAOPTID_pgpkeyring:
787 OK = 0;
788 GAA_TESTMOREARGS;
789 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
790 gaa_index++;
791 #line 53 "cli.gaa"
792 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
794 return GAA_OK;
795 break;
796 case GAAOPTID_pgpkeyfile:
797 OK = 0;
798 GAA_TESTMOREARGS;
799 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
800 gaa_index++;
801 #line 50 "cli.gaa"
802 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
804 return GAA_OK;
805 break;
806 case GAAOPTID_x509cafile:
807 OK = 0;
808 GAA_TESTMOREARGS;
809 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
810 gaa_index++;
811 #line 47 "cli.gaa"
812 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
814 return GAA_OK;
815 break;
816 case GAAOPTID_ctypes:
817 OK = 0;
818 GAA_LIST_FILL(GAATMP_ctypes.arg1, gaa_getstr, char*, GAATMP_ctypes.size1);
819 #line 44 "cli.gaa"
820 { gaaval->ctype = GAATMP_ctypes.arg1; gaaval->nctype = GAATMP_ctypes.size1 ;};
822 return GAA_OK;
823 break;
824 case GAAOPTID_kx:
825 OK = 0;
826 GAA_LIST_FILL(GAATMP_kx.arg1, gaa_getstr, char*, GAATMP_kx.size1);
827 #line 40 "cli.gaa"
828 { gaaval->kx = GAATMP_kx.arg1; gaaval->nkx = GAATMP_kx.size1 ;};
830 return GAA_OK;
831 break;
832 case GAAOPTID_macs:
833 OK = 0;
834 GAA_LIST_FILL(GAATMP_macs.arg1, gaa_getstr, char*, GAATMP_macs.size1);
835 #line 36 "cli.gaa"
836 { gaaval->macs = GAATMP_macs.arg1; gaaval->nmacs = GAATMP_macs.size1 ;};
838 return GAA_OK;
839 break;
840 case GAAOPTID_comp:
841 OK = 0;
842 GAA_LIST_FILL(GAATMP_comp.arg1, gaa_getstr, char*, GAATMP_comp.size1);
843 #line 32 "cli.gaa"
844 { gaaval->comp = GAATMP_comp.arg1; gaaval->ncomp = GAATMP_comp.size1 ;};
846 return GAA_OK;
847 break;
848 case GAAOPTID_protocols:
849 OK = 0;
850 GAA_LIST_FILL(GAATMP_protocols.arg1, gaa_getstr, char*, GAATMP_protocols.size1);
851 #line 28 "cli.gaa"
852 { gaaval->proto = GAATMP_protocols.arg1; gaaval->nproto = GAATMP_protocols.size1 ;};
854 return GAA_OK;
855 break;
856 case GAAOPTID_ciphers:
857 OK = 0;
858 GAA_LIST_FILL(GAATMP_ciphers.arg1, gaa_getstr, char*, GAATMP_ciphers.size1);
859 #line 24 "cli.gaa"
860 { gaaval->ciphers = GAATMP_ciphers.arg1; gaaval->nciphers = GAATMP_ciphers.size1 ;};
862 return GAA_OK;
863 break;
864 case GAAOPTID_recordsize:
865 OK = 0;
866 GAA_TESTMOREARGS;
867 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
868 gaa_index++;
869 #line 19 "cli.gaa"
870 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
872 return GAA_OK;
873 break;
874 case GAAOPTID_port:
875 OK = 0;
876 GAA_TESTMOREARGS;
877 GAA_FILL(GAATMP_port.arg1, gaa_getint, GAATMP_port.size1);
878 gaa_index++;
879 #line 16 "cli.gaa"
880 { gaaval->port = GAATMP_port.arg1 ;};
882 return GAA_OK;
883 break;
884 case GAAOPTID_fingerprint:
885 OK = 0;
886 #line 13 "cli.gaa"
887 { gaaval->fingerprint = 1 ;};
889 return GAA_OK;
890 break;
891 case GAAOPTID_x509fmtder:
892 OK = 0;
893 #line 10 "cli.gaa"
894 { gaaval->fmtder = 1 ;};
896 return GAA_OK;
897 break;
898 case GAAOPTID_crlf:
899 OK = 0;
900 #line 7 "cli.gaa"
901 { gaaval->crlf = 1 ;};
903 return GAA_OK;
904 break;
905 case GAAOPTID_resume:
906 OK = 0;
907 #line 4 "cli.gaa"
908 { gaaval->resume = 1 ;};
910 return GAA_OK;
911 break;
912 case GAA_REST:
913 GAA_LIST_FILL(GAAREST_tmp.arg1, gaa_getstr, char*, GAAREST_tmp.size1);
914 #line 79 "cli.gaa"
915 { gaaval->rest_args = GAAREST_tmp.arg1; gaaval->nrest_args = GAAREST_tmp.size1 ;};
917 return GAA_OK;
918 break;
920 #line 413 "gaa.skel"
921 default: break;
923 return GAA_ERROR_UNKNOWN;
926 int gaa(int argc, char **argv, gaainfo *gaaval)
928 int tmp1, tmp2;
929 int i, j;
930 char *opt_list;
932 GAAargv = argv;
933 GAAargc = argc;
935 opt_list = (char*) malloc(GAA_NB_OPTION + 1);
936 for(i = 0; i < GAA_NB_OPTION + 1; i++)
937 opt_list[i] = 0;
938 /* initialization */
939 if(inited == 0)
942 #line 81 "cli.gaa"
943 { gaaval->resume=0; gaaval->port=443; gaaval->rest_args=NULL; gaaval->nrest_args=0; gaaval->ciphers=NULL;
944 gaaval->kx=NULL; gaaval->comp=NULL; gaaval->macs=NULL; gaaval->ctype=NULL; gaaval->nciphers=0;
945 gaaval->nkx=0; gaaval->ncomp=0; gaaval->nmacs=0; gaaval->nctype = 0; gaaval->record_size=0;
946 gaaval->fingerprint=0; gaaval->pgp_trustdb=NULL; gaaval->pgp_keyring=NULL;
947 gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL;
948 gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->crlf = 0;
949 gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; gaaval->fmtder = 0; ;};
952 inited = 1;
953 #line 438 "gaa.skel"
954 gaa_arg_used = NULL;
956 if (argc > 0)
957 gaa_arg_used = malloc(argc * sizeof(char));
958 for(i = 1; i < argc; i++)
959 gaa_arg_used[i] = 0;
960 for(i = 1; i < argc; i++)
962 if(gaa_arg_used[i] == 0)
964 j = 0;
965 tmp1 = gaa_is_an_argument(GAAargv[i]);
966 switch(tmp1)
968 case GAA_WORD_OPTION:
969 j++;
970 case GAA_LETTER_OPTION:
971 j++;
972 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
973 if(tmp2 == GAA_ERROR_NOMATCH)
975 printf("Invalid option '%s'\n", argv[i]+j);
976 return 0;
978 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
980 case GAA_ERROR_NOTENOUGH_ARGS:
981 printf("'%s': not enough arguments\n",gaa_current_option);
982 return 0;
983 case GAA_ERROR_INVALID_ARG:
984 printf("Invalid arguments\n");
985 return 0;
986 case GAA_OK:
987 break;
988 default:
989 printf("Unknown error\n");
991 gaa_arg_used[i] = 1;
992 break;
993 case GAA_MULTIPLE_OPTION:
994 for(j = 1; j < strlen(argv[i]); j++)
996 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
997 if(tmp2 == GAA_ERROR_NOMATCH)
999 printf("Invalid option '%c'\n", *(argv[i]+j));
1000 return 0;
1002 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1004 case GAA_ERROR_NOTENOUGH_ARGS:
1005 printf("'%s': not enough arguments\n",gaa_current_option);
1006 return 0;
1007 case GAA_ERROR_INVALID_ARG:
1008 printf("Invalid arguments\n");
1009 return 0;
1010 case GAA_OK:
1011 break;
1012 default:
1013 printf("Unknown error\n");
1016 gaa_arg_used[i] = 1;
1017 break;
1018 default: break;
1022 if(gaa_processing_file == 0)
1025 #line 507 "gaa.skel"
1026 #ifdef GAA_REST_EXISTS
1027 switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1029 case GAA_ERROR_NOTENOUGH_ARGS:
1030 printf("Rest: not enough arguments\n");
1031 return 0;
1032 case GAA_ERROR_INVALID_ARG:
1033 printf("Invalid arguments\n");
1034 return 0;
1035 case GAA_OK:
1036 break;
1037 default:
1038 printf("Unknown error\n");
1040 #endif
1042 for(i = 1; i < argc; i++)
1044 if(gaa_arg_used[i] == 0)
1046 printf("Too many arguments\n");
1047 return 0;
1050 free(gaa_arg_used);
1051 free(opt_list);
1052 return -1;
1055 struct gaastrnode
1057 char *str;
1058 struct gaastrnode *next;
1061 typedef struct gaastrnode gaa_str_node;
1063 int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1065 int pos_ini;
1066 char a;
1067 int i = 0, len = 0, newline = 0;
1069 if(argc == 1)
1070 newline = 1;
1072 if(fscanf(file,"%c", &a) != 1) return 0;
1074 while(a == ' ' || a == 9 || a == '\n')
1076 if(a == '\n')
1078 newline=1;
1079 len = 2;
1081 if(fscanf(file,"%c", &a) != 1) return 0;
1084 pos_ini = ftell(file) - 1;
1086 while(a != ' ' && a != 9 && a != '\n')
1089 len++;
1090 if(fscanf(file,"%c", &a) != 1) a = ' ';
1093 tmp_str->str = malloc((len + 1) * sizeof(char));
1094 if(newline == 1)
1096 tmp_str->str[0] = '-';
1097 tmp_str->str[1] = '-';
1098 i = 2;
1100 else
1102 i = 0;
1105 fseek(file,pos_ini, SEEK_SET);
1108 if(fscanf(file, "%c", &a) != 1)
1110 i+=2;
1111 break;
1113 tmp_str->str[i] = a;
1114 i++;
1116 while(a != ' ' && a != 9 && a != '\n');
1118 tmp_str->str[i - 1] = 0;
1120 fseek(file,- 1, SEEK_CUR);
1121 /* printf("%d\n", ftell(file)); */
1123 return -1;
1126 int gaa_file(char *name, gaainfo *gaaval)
1128 gaa_str_node *first_str, **tmp_str, *tmp_str2;
1129 int rval, i;
1130 char **argv;
1131 int argc = 0;
1132 FILE *file;
1134 gaa_processing_file = 1;
1136 if((file = fopen(name, "r")) == NULL)
1138 printf("Couldn't open '%s' configuration file for reading\n", name);
1139 return 0;
1142 tmp_str = &first_str;
1145 argc++;
1146 *tmp_str = malloc(sizeof(gaa_str_node));
1147 (*tmp_str)->str = NULL;
1148 (*tmp_str)->next = NULL;
1150 rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1151 tmp_str = &((*tmp_str)->next);
1153 while(rval == -1);
1155 if(rval == 1)
1156 return 0;
1158 argv = malloc((1 + argc) * sizeof(char*));
1159 tmp_str2 = first_str;
1160 argv[0] = "cfg";
1161 for(i = 1; i < argc; i++)
1163 argv[i] = tmp_str2->str;
1164 tmp_str2 = tmp_str2->next;
1167 rval = gaa(argc, argv, gaaval);
1168 gaa_processing_file = 0;
1169 return rval;