Tizen 2.0 Release
[external/libgnutls26.git] / src / cli-gaa.c
1 /* File generated by GAA 1.6.6
2  */
3 #define GAA_NO_WIN32
4 #line 1 "cli.gaa"
5
6
7 /* C declarations */
8
9 #include <config.h>
10 #include <common.h>
11
12 void cli_version(void);
13
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
17
18 #ifndef GAA_NO_WIN32
19 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(WINDOWS)
20 #define GAA_WIN32
21 #endif
22 #endif
23
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);
30         }
31         return ret;
32 }
33
34 static void __gaa_helpsingle(char short_name, char *name, 
35         char *arg_desc, char *opt_help)
36 {
37      int col1, col3, col4, tabsize = 3, curr;
38      int i;
39
40      col1 = 5; /* Default values */
41      col3 = 30;
42      col4 = 70;
43
44      curr = 0;
45      for(i = 0; i < col1; i++)
46         {
47         printf(" ");
48         curr++;
49         }
50      if(short_name)
51         {
52         if(name && *name)
53           {
54             printf("-%c, ", short_name);
55             curr += 4;
56           }
57         else
58           {
59             printf("-%c ", short_name);
60             curr += 3;
61           }
62         }
63      if(name && *name)
64         {
65           printf("--%s ", name);
66           curr += 3 + strlen(name);
67         }
68      if(arg_desc && *arg_desc)
69         {
70           printf("%s ", arg_desc);
71           curr += 1 + strlen(arg_desc);
72         }
73      if(curr >= col3)
74         {
75           printf("\n");
76           curr = 0;
77         }
78      if(opt_help) /* let's print the option's help body */
79         {
80         const char *str = opt_help;
81         while(*str)
82           {
83              while(curr < col3)
84                {
85                  printf(" ");
86                  curr++;
87                }
88              switch(*str)
89                {
90                  case '\n':
91                      printf("\n");
92                      curr = 0;
93                      break;
94                  case '\t':
95                      do
96                         {
97                         printf(" ");
98                         curr++;
99                         }
100                      while((curr - col3) % tabsize != 0 && curr < col4);
101                  case ' ':
102                      if(*str == ' ')
103                         {
104                         curr++;
105                         printf(" ");
106                         }
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++;
115                }
116              if(curr >= col4)
117                {
118                  printf("\n");
119                  curr = 0;
120                }
121              str++;
122           }
123         }
124      printf("\n");
125 }
126
127 void gaa_help(void)
128 {
129         printf("GnuTLS 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, "priority", "PRIORITY STRING ", "Priorities string.");
143         __gaa_helpsingle(0, "x509cafile", "FILE ", "Certificate file or PKCS #11 URL to use.");
144         __gaa_helpsingle(0, "x509crlfile", "FILE ", "CRL file to use.");
145         __gaa_helpsingle(0, "pgpkeyfile", "FILE ", "PGP Key file to use.");
146         __gaa_helpsingle(0, "pgpkeyring", "FILE ", "PGP Key ring file to use.");
147         __gaa_helpsingle(0, "pgpcertfile", "FILE ", "PGP Public Key (certificate) file to use.");
148         __gaa_helpsingle(0, "pgpsubkey", "HEX|auto ", "PGP subkey to use.");
149         __gaa_helpsingle(0, "x509keyfile", "FILE ", "X.509 key file or PKCS #11 URL to use.");
150         __gaa_helpsingle(0, "x509certfile", "FILE ", "X.509 Certificate file or PKCS #11 URL to use.");
151         __gaa_helpsingle(0, "srpusername", "NAME ", "SRP username to use.");
152         __gaa_helpsingle(0, "srppasswd", "PASSWD ", "SRP password to use.");
153         __gaa_helpsingle(0, "pskusername", "NAME ", "PSK username to use.");
154         __gaa_helpsingle(0, "pskkey", "KEY ", "PSK key (in hex) to use.");
155         __gaa_helpsingle(0, "opaque-prf-input", "DATA ", "Use Opaque PRF Input DATA.");
156         __gaa_helpsingle('p', "port", "PORT ", "The port to connect to.");
157         __gaa_helpsingle(0, "insecure", "", "Don't abort program if server certificate can't be validated.");
158         __gaa_helpsingle('l', "list", "", "Print a list of the supported algorithms and modes.");
159         __gaa_helpsingle('h', "help", "", "prints this help");
160         __gaa_helpsingle('v', "version", "", "prints the program's version number");
161
162 #line 100 "gaa.skel"
163 }
164 /* Copy of C area */
165
166 #line 104 "gaa.skel"
167 /* GAA HEADER */
168 #ifndef GAA_HEADER_POKY
169 #define GAA_HEADER_POKY
170
171 typedef struct _gaainfo gaainfo;
172
173 struct _gaainfo
174 {
175 #line 103 "cli.gaa"
176         char *rest_args;
177 #line 95 "cli.gaa"
178         int insecure;
179 #line 92 "cli.gaa"
180         char *port;
181 #line 89 "cli.gaa"
182         char *opaque_prf_input;
183 #line 86 "cli.gaa"
184         char *psk_key;
185 #line 83 "cli.gaa"
186         char *psk_username;
187 #line 80 "cli.gaa"
188         char *srp_passwd;
189 #line 77 "cli.gaa"
190         char *srp_username;
191 #line 74 "cli.gaa"
192         char *x509_certfile;
193 #line 71 "cli.gaa"
194         char *x509_keyfile;
195 #line 68 "cli.gaa"
196         char *pgp_subkey;
197 #line 65 "cli.gaa"
198         char *pgp_certfile;
199 #line 62 "cli.gaa"
200         char *pgp_keyring;
201 #line 59 "cli.gaa"
202         char *pgp_keyfile;
203 #line 56 "cli.gaa"
204         char *x509_crlfile;
205 #line 53 "cli.gaa"
206         char *x509_cafile;
207 #line 50 "cli.gaa"
208         char *priorities;
209 #line 47 "cli.gaa"
210         int verbose;
211 #line 44 "cli.gaa"
212         int record_size;
213 #line 41 "cli.gaa"
214         int print_cert;
215 #line 38 "cli.gaa"
216         int disable_extensions;
217 #line 35 "cli.gaa"
218         int fingerprint;
219 #line 32 "cli.gaa"
220         int fmtder;
221 #line 29 "cli.gaa"
222         int crlf;
223 #line 26 "cli.gaa"
224         int starttls;
225 #line 23 "cli.gaa"
226         int noticket;
227 #line 20 "cli.gaa"
228         int rehandshake;
229 #line 17 "cli.gaa"
230         int resume;
231 #line 14 "cli.gaa"
232         int debug;
233
234 #line 114 "gaa.skel"
235 };
236
237 #ifdef __cplusplus
238 extern "C"
239 {
240 #endif
241
242     int gaa(int argc, char *argv[], gaainfo *gaaval);
243
244     void gaa_help(void);
245     
246     int gaa_file(const char *name, gaainfo *gaaval);
247     
248 #ifdef __cplusplus
249 }
250 #endif
251
252
253 #endif
254
255 #line 135 "gaa.skel"
256
257 /* C declarations */
258
259 #define GAAERROR(x)    \
260 {                   \
261 gaa_error = 1;      \
262 return x;        \
263 }
264
265 static char *gaa_current_option;
266 static int gaa_error = 0;
267
268 /* Generated by gaa */
269
270 #include <string.h>
271 #include <stdlib.h>
272
273
274 #define GAA_OK                       -1
275
276 #define GAA_ERROR_NOMATCH            0
277 #define GAA_ERROR_NOTENOUGH_ARGS     1
278 #define GAA_ERROR_INVALID_ARG        2
279 #define GAA_ERROR_UNKNOWN            3
280
281 #define GAA_NOT_AN_OPTION       0
282 #define GAA_WORD_OPTION         1
283 #define GAA_LETTER_OPTION       2
284 #define GAA_MULTIPLE_OPTION     3
285
286 #define GAA_REST                0
287 #define GAA_NB_OPTION           31
288 #define GAAOPTID_version        1
289 #define GAAOPTID_help   2
290 #define GAAOPTID_list   3
291 #define GAAOPTID_insecure       4
292 #define GAAOPTID_port   5
293 #define GAAOPTID_opaque_prf_input       6
294 #define GAAOPTID_pskkey 7
295 #define GAAOPTID_pskusername    8
296 #define GAAOPTID_srppasswd      9
297 #define GAAOPTID_srpusername    10
298 #define GAAOPTID_x509certfile   11
299 #define GAAOPTID_x509keyfile    12
300 #define GAAOPTID_pgpsubkey      13
301 #define GAAOPTID_pgpcertfile    14
302 #define GAAOPTID_pgpkeyring     15
303 #define GAAOPTID_pgpkeyfile     16
304 #define GAAOPTID_x509crlfile    17
305 #define GAAOPTID_x509cafile     18
306 #define GAAOPTID_priority       19
307 #define GAAOPTID_verbose        20
308 #define GAAOPTID_recordsize     21
309 #define GAAOPTID_print_cert     22
310 #define GAAOPTID_disable_extensions     23
311 #define GAAOPTID_fingerprint    24
312 #define GAAOPTID_x509fmtder     25
313 #define GAAOPTID_crlf   26
314 #define GAAOPTID_starttls       27
315 #define GAAOPTID_noticket       28
316 #define GAAOPTID_rehandshake    29
317 #define GAAOPTID_resume 30
318 #define GAAOPTID_debug  31
319
320 #line 168 "gaa.skel"
321
322 #define GAA_CHECK1STR(a,b)      \
323 if(a[0] == str[0])              \
324 {                               \
325     gaa_current_option = a;     \
326     return b;                   \
327 }
328
329 #define GAA_CHECKSTR(a,b)                \
330 if(strcmp(a,str) == 0)                   \
331 {                                        \
332     gaa_current_option = a;              \
333     return b;                            \
334 }
335
336 #define GAA_TESTMOREARGS                                                  \
337 if(!OK)                                                                     \
338 {                                  \
339 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
340     gaa_index++;                                                            \
341 if(gaa_last_non_option == gaa_index)                                        \
342     return GAA_ERROR_NOTENOUGH_ARGS; \
343 }
344
345 #define GAA_TESTMOREOPTIONALARGS                                                  \
346 if(!OK) \
347 { \
348 while((gaa_last_non_option != gaa_index) && (gaa_arg_used[gaa_index] == 1)) \
349     gaa_index++;                                                            \
350 if(gaa_last_non_option == gaa_index)                                        \
351     OK = 1; \
352 }
353
354 #define GAA_FILL_2ARGS(target, func)           \
355 target = func(GAAargv[gaa_index]);       \
356 gaa_arg_used[gaa_index] = 1;             \
357 if(gaa_error == 1)                       \
358 {                                        \
359     gaa_error = 0;                       \
360     return GAA_ERROR_INVALID_ARG;        \
361
362
363
364
365 #define GAA_FILL(target, func, num)           \
366 if(!OK) \
367 { \
368 target = func(GAAargv[gaa_index]);       \
369 gaa_arg_used[gaa_index] = 1;             \
370 if(gaa_error == 1)                       \
371 {                                        \
372     gaa_error = 0;                       \
373     return GAA_ERROR_INVALID_ARG;        \
374 } \
375 num = 1;  \
376 } \
377 else \
378 { \
379 num = 0; \
380 }
381
382 #define GAA_LIST_FILL(target, func, type ,num)                      \
383 if(!OK) \
384 { \
385 num = 0;                                                            \
386 target = NULL;                                                      \
387 if ( gaa_last_non_option - gaa_index > 0)                           \
388   target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
389 for(; gaa_index < gaa_last_non_option; gaa_index++)                 \
390 {                                                                   \
391     if(gaa_arg_used[gaa_index] == 0)                                \
392     {                                                               \
393         GAA_FILL_2ARGS(target[num], func);                          \
394         num++;                                                      \
395     }                                                               \
396 }                                                                   \
397 if(num == 0)                                                        \
398     return GAA_ERROR_NOTENOUGH_ARGS; \
399 }
400
401 #define GAA_OPTIONALLIST_FILL(target, func, type ,num)                      \
402 if(!OK) \
403 { \
404 num = 0;                                                            \
405 target = NULL;                                                      \
406 if ( gaa_last_non_option - gaa_index > 0)                           \
407   target = gaa_malloc((gaa_last_non_option - gaa_index) * sizeof(type));\
408 for(; gaa_index < gaa_last_non_option; gaa_index++)                 \
409 {                                                                   \
410     if(gaa_arg_used[gaa_index] == 0)                                \
411     {                                                               \
412         GAA_FILL_2ARGS(target[num], func);                                \
413         num++;                                                      \
414     }                                                               \
415 } \
416 }
417
418 #define GAA_OBLIGAT(str)                                            \
419 k = 0;                                                              \
420 for(i = 0; i < strlen(str); i++)                                    \
421 {                                                                   \
422     j = gaa_get_option_num(str + i, GAA_LETTER_OPTION);           \
423     if(j == GAA_ERROR_NOMATCH)                                       \
424     {                                                               \
425         printf("Error: invalid 'obligat' set\n");                  \
426         exit(-1);                                                   \
427     }                                                               \
428     if(opt_list[j] == 1)                                            \
429         k = 1;                                                      \
430 }                                                                    \
431 if(k == 0)                                                            \
432 {                                                                      \
433     if(strlen(str) == 1)                                                \
434         printf("You must give the -%s option\n", str);                     \
435     else                                                                  \
436         printf("You must give at least one option of '%s'\n", str);          \
437     return 0;         \
438 }
439         
440 #define GAA_INCOMP(str)                                                \
441 k = 0;                                                              \
442 for(i = 0; i < strlen(str); i++)                                    \
443 {                                                                   \
444     j = gaa_get_option_num(str + i, GAA_LETTER_OPTION);           \
445     if(j == GAA_ERROR_NOMATCH)                                      \
446     {                                                               \
447         printf("Error: invalid 'obligat' set\n");                  \
448         exit(-1);                                                   \
449     }                                                               \
450     if(opt_list[j] == 1)                                            \
451         k++;                                                      \
452 }                   \
453 if(k > 1)                                                            \
454 {                                                                      \
455     printf("The options '%s' are incompatible\n", str);              \
456     return 0;                                                          \
457 }
458         
459
460 static char **GAAargv;
461 static int GAAargc;
462 static char *gaa_arg_used;
463 static int gaa_processing_file = 0;
464 static int inited = 0;
465
466 static int gaa_getint(char *arg)
467 {
468     int tmp;
469     char a;
470     if(sscanf(arg, "%d%c", &tmp, &a) < 1)
471     {
472         printf("Option %s: '%s' isn't an integer\n", gaa_current_option, arg);
473         GAAERROR(-1);
474     }
475     return tmp;
476 }
477
478 static char gaa_getchar(char *arg)
479 {
480     if(strlen(arg) != 1)
481     {
482         printf("Option %s: '%s' isn't an character\n", gaa_current_option, arg);
483         GAAERROR(-1);
484     }
485     return arg[0];
486 }
487
488 static char* gaa_getstr(char *arg)
489 {
490     return arg;
491 }
492 static float gaa_getfloat(char *arg)
493 {
494     float tmp;
495     char a;
496     if(sscanf(arg, "%f%c", &tmp, &a) < 1)
497     {
498         printf("Option %s: '%s' isn't a float number\n", gaa_current_option, arg);
499         GAAERROR(-1);
500     }
501     return tmp;
502 }
503 /* option structures */
504
505 struct GAAOPTION_port 
506 {
507         char* arg1;
508         int size1;
509 };
510
511 struct GAAOPTION_opaque_prf_input 
512 {
513         char* arg1;
514         int size1;
515 };
516
517 struct GAAOPTION_pskkey 
518 {
519         char* arg1;
520         int size1;
521 };
522
523 struct GAAOPTION_pskusername 
524 {
525         char* arg1;
526         int size1;
527 };
528
529 struct GAAOPTION_srppasswd 
530 {
531         char* arg1;
532         int size1;
533 };
534
535 struct GAAOPTION_srpusername 
536 {
537         char* arg1;
538         int size1;
539 };
540
541 struct GAAOPTION_x509certfile 
542 {
543         char* arg1;
544         int size1;
545 };
546
547 struct GAAOPTION_x509keyfile 
548 {
549         char* arg1;
550         int size1;
551 };
552
553 struct GAAOPTION_pgpsubkey 
554 {
555         char* arg1;
556         int size1;
557 };
558
559 struct GAAOPTION_pgpcertfile 
560 {
561         char* arg1;
562         int size1;
563 };
564
565 struct GAAOPTION_pgpkeyring 
566 {
567         char* arg1;
568         int size1;
569 };
570
571 struct GAAOPTION_pgpkeyfile 
572 {
573         char* arg1;
574         int size1;
575 };
576
577 struct GAAOPTION_x509crlfile 
578 {
579         char* arg1;
580         int size1;
581 };
582
583 struct GAAOPTION_x509cafile 
584 {
585         char* arg1;
586         int size1;
587 };
588
589 struct GAAOPTION_priority 
590 {
591         char* arg1;
592         int size1;
593 };
594
595 struct GAAOPTION_recordsize 
596 {
597         int arg1;
598         int size1;
599 };
600
601 struct GAAOPTION_debug 
602 {
603         int arg1;
604         int size1;
605 };
606 #define GAA_REST_EXISTS
607
608 struct GAAREST
609 {
610         char* arg1;
611         int size1;
612 };
613          
614 #line 349 "gaa.skel"
615 static int gaa_is_an_argument(char *str)
616 {
617 #ifdef GAA_WIN32
618     if(str[0] == '/' && str[1] != 0)
619         return GAA_MULTIPLE_OPTION;
620 #endif
621     if(str[0] != '-')
622         return GAA_NOT_AN_OPTION;
623     if(str[1] == 0)
624         return GAA_NOT_AN_OPTION;
625     if(str[1] == '-')
626     {
627         if(str[2] != 0)
628             return GAA_WORD_OPTION;
629         else
630             return GAA_NOT_AN_OPTION;
631     }
632     if(str[2] == 0)
633         return GAA_LETTER_OPTION;
634     else
635         return GAA_MULTIPLE_OPTION;
636 }
637
638 static int gaa_get_option_num(char *str, int status)
639 {
640     switch(status)
641         {
642         case GAA_LETTER_OPTION:
643                         GAA_CHECK1STR("p", GAAOPTID_port);
644                         GAA_CHECK1STR("", GAAOPTID_opaque_prf_input);
645                         GAA_CHECK1STR("", GAAOPTID_pskkey);
646                         GAA_CHECK1STR("", GAAOPTID_pskusername);
647                         GAA_CHECK1STR("", GAAOPTID_srppasswd);
648                         GAA_CHECK1STR("", GAAOPTID_srpusername);
649                         GAA_CHECK1STR("", GAAOPTID_x509certfile);
650                         GAA_CHECK1STR("", GAAOPTID_x509keyfile);
651                         GAA_CHECK1STR("", GAAOPTID_pgpsubkey);
652                         GAA_CHECK1STR("", GAAOPTID_pgpcertfile);
653                         GAA_CHECK1STR("", GAAOPTID_pgpkeyring);
654                         GAA_CHECK1STR("", GAAOPTID_pgpkeyfile);
655                         GAA_CHECK1STR("", GAAOPTID_x509crlfile);
656                         GAA_CHECK1STR("", GAAOPTID_x509cafile);
657                         GAA_CHECK1STR("", GAAOPTID_priority);
658                         GAA_CHECK1STR("", GAAOPTID_recordsize);
659                         GAA_CHECK1STR("d", GAAOPTID_debug);
660         case GAA_MULTIPLE_OPTION:
661 #line 375 "gaa.skel"
662                         GAA_CHECK1STR("v", GAAOPTID_version);
663                         GAA_CHECK1STR("h", GAAOPTID_help);
664                         GAA_CHECK1STR("l", GAAOPTID_list);
665                         GAA_CHECK1STR("", GAAOPTID_insecure);
666                         GAA_CHECK1STR("V", GAAOPTID_verbose);
667                         GAA_CHECK1STR("", GAAOPTID_print_cert);
668                         GAA_CHECK1STR("", GAAOPTID_disable_extensions);
669                         GAA_CHECK1STR("f", GAAOPTID_fingerprint);
670                         GAA_CHECK1STR("", GAAOPTID_x509fmtder);
671                         GAA_CHECK1STR("", GAAOPTID_crlf);
672                         GAA_CHECK1STR("s", GAAOPTID_starttls);
673                         GAA_CHECK1STR("", GAAOPTID_noticket);
674                         GAA_CHECK1STR("e", GAAOPTID_rehandshake);
675                         GAA_CHECK1STR("r", GAAOPTID_resume);
676
677 #line 277 "gaa.skel"
678         break;
679         case GAA_WORD_OPTION:
680                         GAA_CHECKSTR("version", GAAOPTID_version);
681                         GAA_CHECKSTR("help", GAAOPTID_help);
682                         GAA_CHECKSTR("list", GAAOPTID_list);
683                         GAA_CHECKSTR("insecure", GAAOPTID_insecure);
684                         GAA_CHECKSTR("port", GAAOPTID_port);
685                         GAA_CHECKSTR("opaque-prf-input", GAAOPTID_opaque_prf_input);
686                         GAA_CHECKSTR("pskkey", GAAOPTID_pskkey);
687                         GAA_CHECKSTR("pskusername", GAAOPTID_pskusername);
688                         GAA_CHECKSTR("srppasswd", GAAOPTID_srppasswd);
689                         GAA_CHECKSTR("srpusername", GAAOPTID_srpusername);
690                         GAA_CHECKSTR("x509certfile", GAAOPTID_x509certfile);
691                         GAA_CHECKSTR("x509keyfile", GAAOPTID_x509keyfile);
692                         GAA_CHECKSTR("pgpsubkey", GAAOPTID_pgpsubkey);
693                         GAA_CHECKSTR("pgpcertfile", GAAOPTID_pgpcertfile);
694                         GAA_CHECKSTR("pgpkeyring", GAAOPTID_pgpkeyring);
695                         GAA_CHECKSTR("pgpkeyfile", GAAOPTID_pgpkeyfile);
696                         GAA_CHECKSTR("x509crlfile", GAAOPTID_x509crlfile);
697                         GAA_CHECKSTR("x509cafile", GAAOPTID_x509cafile);
698                         GAA_CHECKSTR("priority", GAAOPTID_priority);
699                         GAA_CHECKSTR("verbose", GAAOPTID_verbose);
700                         GAA_CHECKSTR("recordsize", GAAOPTID_recordsize);
701                         GAA_CHECKSTR("print-cert", GAAOPTID_print_cert);
702                         GAA_CHECKSTR("disable-extensions", GAAOPTID_disable_extensions);
703                         GAA_CHECKSTR("fingerprint", GAAOPTID_fingerprint);
704                         GAA_CHECKSTR("x509fmtder", GAAOPTID_x509fmtder);
705                         GAA_CHECKSTR("crlf", GAAOPTID_crlf);
706                         GAA_CHECKSTR("starttls", GAAOPTID_starttls);
707                         GAA_CHECKSTR("noticket", GAAOPTID_noticket);
708                         GAA_CHECKSTR("rehandshake", GAAOPTID_rehandshake);
709                         GAA_CHECKSTR("resume", GAAOPTID_resume);
710                         GAA_CHECKSTR("debug", GAAOPTID_debug);
711
712 #line 281 "gaa.skel"
713         break;
714         default: break;
715         }
716     return GAA_ERROR_NOMATCH;
717 }
718
719 static int gaa_try(int gaa_num, int gaa_index, gaainfo *gaaval, char *opt_list)
720 {
721     int OK = 0;
722     int gaa_last_non_option;
723         struct GAAOPTION_port GAATMP_port;
724         struct GAAOPTION_opaque_prf_input GAATMP_opaque_prf_input;
725         struct GAAOPTION_pskkey GAATMP_pskkey;
726         struct GAAOPTION_pskusername GAATMP_pskusername;
727         struct GAAOPTION_srppasswd GAATMP_srppasswd;
728         struct GAAOPTION_srpusername GAATMP_srpusername;
729         struct GAAOPTION_x509certfile GAATMP_x509certfile;
730         struct GAAOPTION_x509keyfile GAATMP_x509keyfile;
731         struct GAAOPTION_pgpsubkey GAATMP_pgpsubkey;
732         struct GAAOPTION_pgpcertfile GAATMP_pgpcertfile;
733         struct GAAOPTION_pgpkeyring GAATMP_pgpkeyring;
734         struct GAAOPTION_pgpkeyfile GAATMP_pgpkeyfile;
735         struct GAAOPTION_x509crlfile GAATMP_x509crlfile;
736         struct GAAOPTION_x509cafile GAATMP_x509cafile;
737         struct GAAOPTION_priority GAATMP_priority;
738         struct GAAOPTION_recordsize GAATMP_recordsize;
739         struct GAAOPTION_debug GAATMP_debug;
740
741 #line 393 "gaa.skel"
742 #ifdef GAA_REST_EXISTS
743     struct GAAREST GAAREST_tmp;
744 #endif
745
746     opt_list[gaa_num] = 1;
747     
748     for(gaa_last_non_option = gaa_index;
749         (gaa_last_non_option != GAAargc) && (gaa_is_an_argument(GAAargv[gaa_last_non_option]) == GAA_NOT_AN_OPTION);
750         gaa_last_non_option++);
751
752     if(gaa_num == GAA_REST)
753     {
754         gaa_index = 1;
755         gaa_last_non_option = GAAargc;
756     }
757     
758     switch(gaa_num)
759     {
760         case GAAOPTID_version:
761         OK = 0;
762 #line 101 "cli.gaa"
763 { cli_version(); exit(0); ;};
764
765                 return GAA_OK;
766                 break;
767         case GAAOPTID_help:
768         OK = 0;
769 #line 99 "cli.gaa"
770 { gaa_help(); exit(0); ;};
771
772                 return GAA_OK;
773                 break;
774         case GAAOPTID_list:
775         OK = 0;
776 #line 98 "cli.gaa"
777 { print_list(gaaval->verbose); exit(0); ;};
778
779                 return GAA_OK;
780                 break;
781         case GAAOPTID_insecure:
782         OK = 0;
783 #line 96 "cli.gaa"
784 { gaaval->insecure = 1 ;};
785
786                 return GAA_OK;
787                 break;
788         case GAAOPTID_port:
789         OK = 0;
790                 GAA_TESTMOREARGS;
791                 GAA_FILL(GAATMP_port.arg1, gaa_getstr, GAATMP_port.size1);
792                 gaa_index++;
793 #line 93 "cli.gaa"
794 { gaaval->port = GAATMP_port.arg1 ;};
795
796                 return GAA_OK;
797                 break;
798         case GAAOPTID_opaque_prf_input:
799         OK = 0;
800                 GAA_TESTMOREARGS;
801                 GAA_FILL(GAATMP_opaque_prf_input.arg1, gaa_getstr, GAATMP_opaque_prf_input.size1);
802                 gaa_index++;
803 #line 90 "cli.gaa"
804 { gaaval->opaque_prf_input = GAATMP_opaque_prf_input.arg1 ;};
805
806                 return GAA_OK;
807                 break;
808         case GAAOPTID_pskkey:
809         OK = 0;
810                 GAA_TESTMOREARGS;
811                 GAA_FILL(GAATMP_pskkey.arg1, gaa_getstr, GAATMP_pskkey.size1);
812                 gaa_index++;
813 #line 87 "cli.gaa"
814 { gaaval->psk_key = GAATMP_pskkey.arg1 ;};
815
816                 return GAA_OK;
817                 break;
818         case GAAOPTID_pskusername:
819         OK = 0;
820                 GAA_TESTMOREARGS;
821                 GAA_FILL(GAATMP_pskusername.arg1, gaa_getstr, GAATMP_pskusername.size1);
822                 gaa_index++;
823 #line 84 "cli.gaa"
824 { gaaval->psk_username = GAATMP_pskusername.arg1 ;};
825
826                 return GAA_OK;
827                 break;
828         case GAAOPTID_srppasswd:
829         OK = 0;
830                 GAA_TESTMOREARGS;
831                 GAA_FILL(GAATMP_srppasswd.arg1, gaa_getstr, GAATMP_srppasswd.size1);
832                 gaa_index++;
833 #line 81 "cli.gaa"
834 { gaaval->srp_passwd = GAATMP_srppasswd.arg1 ;};
835
836                 return GAA_OK;
837                 break;
838         case GAAOPTID_srpusername:
839         OK = 0;
840                 GAA_TESTMOREARGS;
841                 GAA_FILL(GAATMP_srpusername.arg1, gaa_getstr, GAATMP_srpusername.size1);
842                 gaa_index++;
843 #line 78 "cli.gaa"
844 { gaaval->srp_username = GAATMP_srpusername.arg1 ;};
845
846                 return GAA_OK;
847                 break;
848         case GAAOPTID_x509certfile:
849         OK = 0;
850                 GAA_TESTMOREARGS;
851                 GAA_FILL(GAATMP_x509certfile.arg1, gaa_getstr, GAATMP_x509certfile.size1);
852                 gaa_index++;
853 #line 75 "cli.gaa"
854 { gaaval->x509_certfile = GAATMP_x509certfile.arg1 ;};
855
856                 return GAA_OK;
857                 break;
858         case GAAOPTID_x509keyfile:
859         OK = 0;
860                 GAA_TESTMOREARGS;
861                 GAA_FILL(GAATMP_x509keyfile.arg1, gaa_getstr, GAATMP_x509keyfile.size1);
862                 gaa_index++;
863 #line 72 "cli.gaa"
864 { gaaval->x509_keyfile = GAATMP_x509keyfile.arg1 ;};
865
866                 return GAA_OK;
867                 break;
868         case GAAOPTID_pgpsubkey:
869         OK = 0;
870                 GAA_TESTMOREARGS;
871                 GAA_FILL(GAATMP_pgpsubkey.arg1, gaa_getstr, GAATMP_pgpsubkey.size1);
872                 gaa_index++;
873 #line 69 "cli.gaa"
874 { gaaval->pgp_subkey = GAATMP_pgpsubkey.arg1 ;};
875
876                 return GAA_OK;
877                 break;
878         case GAAOPTID_pgpcertfile:
879         OK = 0;
880                 GAA_TESTMOREARGS;
881                 GAA_FILL(GAATMP_pgpcertfile.arg1, gaa_getstr, GAATMP_pgpcertfile.size1);
882                 gaa_index++;
883 #line 66 "cli.gaa"
884 { gaaval->pgp_certfile = GAATMP_pgpcertfile.arg1 ;};
885
886                 return GAA_OK;
887                 break;
888         case GAAOPTID_pgpkeyring:
889         OK = 0;
890                 GAA_TESTMOREARGS;
891                 GAA_FILL(GAATMP_pgpkeyring.arg1, gaa_getstr, GAATMP_pgpkeyring.size1);
892                 gaa_index++;
893 #line 63 "cli.gaa"
894 { gaaval->pgp_keyring = GAATMP_pgpkeyring.arg1 ;};
895
896                 return GAA_OK;
897                 break;
898         case GAAOPTID_pgpkeyfile:
899         OK = 0;
900                 GAA_TESTMOREARGS;
901                 GAA_FILL(GAATMP_pgpkeyfile.arg1, gaa_getstr, GAATMP_pgpkeyfile.size1);
902                 gaa_index++;
903 #line 60 "cli.gaa"
904 { gaaval->pgp_keyfile = GAATMP_pgpkeyfile.arg1 ;};
905
906                 return GAA_OK;
907                 break;
908         case GAAOPTID_x509crlfile:
909         OK = 0;
910                 GAA_TESTMOREARGS;
911                 GAA_FILL(GAATMP_x509crlfile.arg1, gaa_getstr, GAATMP_x509crlfile.size1);
912                 gaa_index++;
913 #line 57 "cli.gaa"
914 { gaaval->x509_crlfile = GAATMP_x509crlfile.arg1 ;};
915
916                 return GAA_OK;
917                 break;
918         case GAAOPTID_x509cafile:
919         OK = 0;
920                 GAA_TESTMOREARGS;
921                 GAA_FILL(GAATMP_x509cafile.arg1, gaa_getstr, GAATMP_x509cafile.size1);
922                 gaa_index++;
923 #line 54 "cli.gaa"
924 { gaaval->x509_cafile = GAATMP_x509cafile.arg1 ;};
925
926                 return GAA_OK;
927                 break;
928         case GAAOPTID_priority:
929         OK = 0;
930                 GAA_TESTMOREARGS;
931                 GAA_FILL(GAATMP_priority.arg1, gaa_getstr, GAATMP_priority.size1);
932                 gaa_index++;
933 #line 51 "cli.gaa"
934 { gaaval->priorities = GAATMP_priority.arg1 ;};
935
936                 return GAA_OK;
937                 break;
938         case GAAOPTID_verbose:
939         OK = 0;
940 #line 48 "cli.gaa"
941 { gaaval->verbose = 1 ;};
942
943                 return GAA_OK;
944                 break;
945         case GAAOPTID_recordsize:
946         OK = 0;
947                 GAA_TESTMOREARGS;
948                 GAA_FILL(GAATMP_recordsize.arg1, gaa_getint, GAATMP_recordsize.size1);
949                 gaa_index++;
950 #line 45 "cli.gaa"
951 { gaaval->record_size = GAATMP_recordsize.arg1 ;};
952
953                 return GAA_OK;
954                 break;
955         case GAAOPTID_print_cert:
956         OK = 0;
957 #line 42 "cli.gaa"
958 { gaaval->print_cert = 1 ;};
959
960                 return GAA_OK;
961                 break;
962         case GAAOPTID_disable_extensions:
963         OK = 0;
964 #line 39 "cli.gaa"
965 { gaaval->disable_extensions = 1 ;};
966
967                 return GAA_OK;
968                 break;
969         case GAAOPTID_fingerprint:
970         OK = 0;
971 #line 36 "cli.gaa"
972 { gaaval->fingerprint = 1 ;};
973
974                 return GAA_OK;
975                 break;
976         case GAAOPTID_x509fmtder:
977         OK = 0;
978 #line 33 "cli.gaa"
979 { gaaval->fmtder = 1 ;};
980
981                 return GAA_OK;
982                 break;
983         case GAAOPTID_crlf:
984         OK = 0;
985 #line 30 "cli.gaa"
986 { gaaval->crlf = 1 ;};
987
988                 return GAA_OK;
989                 break;
990         case GAAOPTID_starttls:
991         OK = 0;
992 #line 27 "cli.gaa"
993 { gaaval->starttls = 1 ;};
994
995                 return GAA_OK;
996                 break;
997         case GAAOPTID_noticket:
998         OK = 0;
999 #line 24 "cli.gaa"
1000 { gaaval->noticket = 1 ;};
1001
1002                 return GAA_OK;
1003                 break;
1004         case GAAOPTID_rehandshake:
1005         OK = 0;
1006 #line 21 "cli.gaa"
1007 { gaaval->rehandshake = 1 ;};
1008
1009                 return GAA_OK;
1010                 break;
1011         case GAAOPTID_resume:
1012         OK = 0;
1013 #line 18 "cli.gaa"
1014 { gaaval->resume = 1 ;};
1015
1016                 return GAA_OK;
1017                 break;
1018         case GAAOPTID_debug:
1019         OK = 0;
1020                 GAA_TESTMOREARGS;
1021                 GAA_FILL(GAATMP_debug.arg1, gaa_getint, GAATMP_debug.size1);
1022                 gaa_index++;
1023 #line 15 "cli.gaa"
1024 { gaaval->debug = GAATMP_debug.arg1 ;};
1025
1026                 return GAA_OK;
1027                 break;
1028         case GAA_REST:
1029                 GAA_TESTMOREARGS;
1030                 GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
1031                 gaa_index++;
1032 #line 104 "cli.gaa"
1033 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
1034
1035                 return GAA_OK;
1036                 break;
1037
1038 #line 413 "gaa.skel"
1039     default: break;
1040     }
1041     return GAA_ERROR_UNKNOWN;
1042 }
1043
1044 int gaa(int argc, char **argv, gaainfo *gaaval)
1045 {
1046     int tmp1, tmp2;
1047     int i, j;
1048     char *opt_list;
1049
1050     GAAargv = argv;
1051     GAAargc = argc;
1052
1053     opt_list = (char*) gaa_malloc(GAA_NB_OPTION + 1);
1054
1055     for(i = 0; i < GAA_NB_OPTION + 1; i++)
1056         opt_list[i] = 0;
1057     /* initialization */
1058     if(inited == 0)
1059     {
1060
1061 #line 106 "cli.gaa"
1062 { gaaval->resume=0; gaaval->noticket=0; gaaval->port="443"; gaaval->rest_args=NULL; 
1063         gaaval->record_size=0; 
1064         gaaval->fingerprint=0; gaaval->pgp_keyring=NULL; gaaval->x509_crlfile = NULL;
1065         gaaval->x509_cafile = NULL; gaaval->pgp_keyfile=NULL; gaaval->pgp_certfile=NULL; gaaval->disable_extensions = 0;
1066         gaaval->x509_keyfile=NULL; gaaval->x509_certfile=NULL; gaaval->crlf = 0; 
1067         gaaval->srp_username=NULL; gaaval->srp_passwd=NULL; gaaval->fmtder = 0; gaaval->starttls =0; 
1068         gaaval->debug = 0; gaaval->print_cert = 0; gaaval->verbose = 0; gaaval->psk_key = NULL; 
1069         gaaval->psk_username = NULL; gaaval->priorities = NULL;
1070         gaaval->opaque_prf_input = NULL; gaaval->pgp_subkey = NULL; gaaval->rehandshake = 0; ;};
1071
1072     }
1073     inited = 1;
1074 #line 438 "gaa.skel"
1075     gaa_arg_used = NULL;
1076
1077     if (argc > 0) {
1078       gaa_arg_used = gaa_malloc(argc * sizeof(char));
1079     }
1080
1081     for(i = 1; i < argc; i++)
1082         gaa_arg_used[i] = 0;
1083     for(i = 1; i < argc; i++)
1084     {
1085         if(gaa_arg_used[i] == 0)
1086         {
1087             j = 0;
1088             tmp1 = gaa_is_an_argument(GAAargv[i]);
1089             switch(tmp1)
1090             {
1091             case GAA_WORD_OPTION:
1092                 j++;
1093             case GAA_LETTER_OPTION:
1094                 j++;
1095                 tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1096                 if(tmp2 == GAA_ERROR_NOMATCH)
1097                 {
1098                     printf("Invalid option '%s'\n", argv[i]+j);
1099                     return 0;
1100                 }
1101                 switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1102                 {
1103                 case GAA_ERROR_NOTENOUGH_ARGS:
1104                     printf("'%s': not enough arguments\n",gaa_current_option);
1105                     return 0;
1106                 case GAA_ERROR_INVALID_ARG:
1107                     printf("Invalid arguments\n");
1108                     return 0;
1109                 case GAA_OK:
1110                     break;
1111                 default:
1112                     printf("Unknown error\n");
1113                 }
1114                 gaa_arg_used[i] = 1;
1115                 break;
1116             case GAA_MULTIPLE_OPTION:
1117                 for(j = 1; j < strlen(argv[i]); j++)
1118                 {
1119                     tmp2 = gaa_get_option_num(argv[i]+j, tmp1);
1120                     if(tmp2 == GAA_ERROR_NOMATCH)
1121                     {
1122                         printf("Invalid option '%c'\n", *(argv[i]+j));
1123                         return 0;
1124                     }
1125                     switch(gaa_try(tmp2, i+1, gaaval, opt_list))
1126                     {
1127                     case GAA_ERROR_NOTENOUGH_ARGS:
1128                         printf("'%s': not enough arguments\n",gaa_current_option);
1129                         return 0;
1130                     case GAA_ERROR_INVALID_ARG:
1131                         printf("Invalid arguments\n");
1132                         return 0;
1133                     case GAA_OK:
1134                         break;
1135                     default:
1136                         printf("Unknown error\n");
1137                     }
1138                 }
1139                 gaa_arg_used[i] = 1;
1140                 break;
1141             default: break;
1142             }
1143         }
1144     }
1145 if(gaa_processing_file == 0)
1146 {
1147
1148 #line 507 "gaa.skel"
1149 #ifdef GAA_REST_EXISTS
1150     switch(gaa_try(GAA_REST, 1, gaaval, opt_list))
1151     {
1152     case GAA_ERROR_NOTENOUGH_ARGS:
1153         printf("Rest: not enough arguments\n");
1154         return 0;
1155     case GAA_ERROR_INVALID_ARG:
1156         printf("Invalid arguments\n");
1157         return 0;
1158     case GAA_OK:
1159         break;
1160     default:
1161         printf("Unknown error\n");
1162     }
1163 #endif
1164 }
1165     for(i = 1; i < argc; i++)
1166     {
1167         if(gaa_arg_used[i] == 0)
1168         {
1169             printf("Too many arguments\n");
1170             return 0;
1171         }
1172     }
1173     free(gaa_arg_used);
1174     free(opt_list);
1175     return -1;
1176 }
1177
1178 struct gaastrnode
1179 {
1180     char *str;
1181     struct gaastrnode *next;
1182 };
1183
1184 typedef struct gaastrnode gaa_str_node;
1185
1186 static int gaa_internal_get_next_str(FILE *file, gaa_str_node *tmp_str, int argc)
1187 {
1188     int pos_ini;
1189     int a;
1190     int i = 0, len = 0, newline = 0;
1191
1192     if(argc == 1) {
1193         newline = 1;
1194         len = 2;
1195     }
1196     
1197     a = fgetc( file);
1198     if (a == EOF) return 0;
1199
1200     while(a == ' ' || a == 9 || a == '\n')
1201     {
1202         if(a == '\n')
1203         {
1204             newline=1;
1205             len = 2;
1206         }
1207         a = fgetc( file);
1208         if (a == EOF) return 0;
1209     }
1210
1211     pos_ini = ftell(file) - 1;
1212
1213     while(a != ' ' && a != 9 && a != '\n')
1214     {
1215
1216         len++;
1217         a = fgetc( file);
1218         if(a==EOF) return 0; //a = ' ';
1219     }
1220
1221     len += 1;
1222     tmp_str->str = gaa_malloc((len) * sizeof(char));
1223
1224     if(newline == 1)
1225     {
1226         tmp_str->str[0] = '-';
1227         tmp_str->str[1] = '-';
1228         i = 2;
1229     }
1230     else
1231     {
1232         i = 0;
1233     }
1234
1235     fseek(file,pos_ini, SEEK_SET);
1236     do
1237     {
1238         a = fgetc( file);
1239
1240         if (a == EOF) {
1241             i+=2;
1242             break;
1243         }
1244         tmp_str->str[i] = a;
1245         i++;
1246     }
1247     while(a != ' ' && a != 9 && a != '\n' && i < len);
1248
1249     tmp_str->str[i - 1] = 0;
1250
1251     fseek(file,- 1, SEEK_CUR);
1252 /*    printf("%d\n", ftell(file)); */
1253     
1254     return -1;
1255 }
1256
1257 int gaa_file(const char *name, gaainfo *gaaval)
1258 {
1259     gaa_str_node *first_str, **tmp_str, *tmp_str2;
1260     int rval, i;
1261     char **argv;
1262     int argc = 0;
1263     FILE *file;
1264
1265     gaa_processing_file = 1;
1266     
1267     if((file = fopen(name, "r")) == NULL)
1268     {
1269         printf("Couldn't open '%s' configuration file for reading\n", name);
1270         return 1;
1271     }
1272     
1273     tmp_str = &first_str;
1274     do
1275     {
1276         argc++;
1277         *tmp_str = gaa_malloc(sizeof(gaa_str_node));
1278
1279         (*tmp_str)->str = NULL;
1280         (*tmp_str)->next = NULL;
1281
1282         rval = gaa_internal_get_next_str(file, *tmp_str, argc);
1283         tmp_str = &((*tmp_str)->next);
1284     }
1285     while(rval == -1);
1286     
1287     if(rval == 1)
1288         return 0;
1289     
1290     argv = gaa_malloc((1 + argc) * sizeof(char*));
1291
1292     tmp_str2 = first_str;
1293     argv[0] = "cfg";
1294     for(i = 1; i < argc; i++)
1295     {
1296         argv[i] = tmp_str2->str;
1297         tmp_str2 = tmp_str2->next;
1298     }
1299
1300     rval = gaa(argc, argv, gaaval);
1301     gaa_processing_file = 0;
1302     return rval;
1303 }