aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-01-19 11:26:48 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-01-19 11:35:21 +0200
commit4d1258de786a83888d123f4e8f791f1ad6ecf605 (patch)
treee172edcda699af4b7db72f42e30f4399866b339b /tests
parent0766417065bfec9747bf0f41f9b68c27e378f817 (diff)
downloadeclat-4d1258de786a83888d123f4e8f791f1ad6ecf605.tar.gz
eclat-4d1258de786a83888d123f4e8f791f1ad6ecf605.tar.bz2
Initial support for IAM
* NEWS: Update. * doc/eclat.1man: Update. * lib/.gitignore: Update. * lib/Makefile.am (libeclat_a_SOURCES): Add new files. * lib/json.h: New file. * lib/jsongrm.y: New file. * lib/jsonlex.l: New file. * lib/yytrans: New file. * lib/libeclat.h (ec2_query) <token>: New member (eclat_query_create): Change signature. * lib/qcreat.c (eclat_query_create): Take security token as 5th argument. * lib/reqsign.c (querysign2): Add security token. * src/cmdline.opt: Update copyright years * src/ec2map.c (ec2_map_get): Pass security token to eclat_query_create. * src/eclat.c (security_token): New variable. (eclat_do_command): Pass security token to eclat_query_create. (main): Get authentication credentials from the instance store, if not found in the access file. * src/eclat.h (security_token): New extern. (eclat_get_instance_creds): New proto. * src/util.c (eclat_get_instance_zone): Use json parser. (eclat_get_instance_creds): New function. * tests/Makefile.am (noinst_PROGRAMS): add tjson * tests/tjson.c: New file.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/tjson.c116
3 files changed, 118 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 0f9880b..08adbd4 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,6 +6,7 @@ testsuite
testsuite.dir
testsuite.log
tforlan
+tjson
thmac
trws
turlenc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 30e501b..63bca9d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -117,6 +117,7 @@ endif
noinst_PROGRAMS = \
$(GDBMLOAD)\
tforlan\
+ tjson\
thmac\
trws\
turlenc\
diff --git a/tests/tjson.c b/tests/tjson.c
new file mode 100644
index 0000000..32e182e
--- /dev/null
+++ b/tests/tjson.c
@@ -0,0 +1,116 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012-2014 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#ifdef HAVE_GETOPT_H
+# include <getopt.h>
+#endif
+#include <errno.h>
+#include <sysexits.h>
+#include <libeclat.h>
+#include <json.h>
+
+void
+usage()
+{
+ printf("usage: %s [OPTIONS] FILE [INPUT]\n", program_name);
+}
+
+static char *
+readfile(FILE *fp)
+{
+ char inbuf[4096];
+ char *buf;
+ size_t bufsize = 0;
+ size_t bufmax;
+ size_t n;
+
+ bufmax = sizeof(inbuf);
+ buf = grecs_malloc(bufmax);
+
+ while (n = fread(inbuf, 1, sizeof(inbuf), fp)) {
+ if (bufsize + n >= bufmax) {
+ bufmax *= 2;
+ buf = grecs_realloc(buf, bufmax);
+ }
+ memcpy(buf + bufsize, inbuf, n);
+ bufsize += n;
+ }
+ if (ferror(fp))
+ die(EX_NOINPUT, "read error");
+ if (bufsize + 1 >= bufmax) {
+ bufmax++;
+ buf = grecs_realloc(buf, bufmax);
+ }
+ buf[bufsize] = 0;
+ return buf;
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+ char *file = "-";
+ FILE *fp;
+ int rc;
+ char *input;
+ struct json_object *obj;
+
+ set_program_name(argv[0]);
+ while ((rc = getopt(argc, argv, "f:h")) != EOF) {
+ switch (rc) {
+ case 'f':
+ file = optarg;
+ break;
+ case 'h':
+ usage();
+ return 0;
+ default:
+ exit(EX_USAGE);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ //FIXME: process args
+
+ if (strcmp(file, "-") == 0)
+ fp = stdin;
+ else {
+ fp = fopen(file, "r");
+ if (!fp)
+ die(EX_NOINPUT, "cannot open input file \"%s\": %s",
+ file, strerror(errno));
+ }
+
+ input = readfile(fp);
+ obj = json_parse_string(input, strlen(input));
+ if (!obj)
+ die(EX_DATAERR,
+ "%s: near %s",
+ json_err_diag,
+ json_err_ptr);
+
+ json_object_free(obj);
+ return 0;
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.