diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-03-15 13:29:52 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-03-15 14:12:23 +0200 |
commit | 58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2 (patch) | |
tree | 01fcd1416af582e2429f0ae8d120e2af39b8f9d9 /src | |
parent | 677473cdfc42b9fd83623902e80de946f108825c (diff) | |
download | eclat-58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2.tar.gz eclat-58a8936d30bbb18b8ad93fecfe3fe2210d1c18b2.tar.bz2 |
Upgrade grecs
* grecs: pull
* configure.ac: Enable json
* lib/Makefile.am (AM_CPPFLAGS): Use @GRECS_INCLUDES@
(libeclat_a_SOURCES): Remove json sources.
* src/Makefile.am (AM_CPPFLAGS): Use @GRECS_INCLUDES@
* tests/Makefile.am: Likewise.
* lib/json.h: Remove.
* lib/jsongrm.y: Remove.
* lib/jsonlex.l: Remove.
* tests/tjson.c: Remove.
* src/config.c (eclat_kw): Mark statically initialized memory locations
as such.
* src/mktags.c (process_tags): Use wordsplit to process quoted arguments.
* lib/bidimap.c (bidimap_config): Fill allocated memory with 0's
* lib/filemap.c (filemap_config): Likewise.
* lib/gdbmmap.c (gdbm_map_config): Likewise.
* lib/seqmap.c (seqmap_config): Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/config.c | 7 | ||||
-rw-r--r-- | src/eclat.h | 2 | ||||
-rw-r--r-- | src/ispeek.c | 26 | ||||
-rw-r--r-- | src/mktags.c | 32 | ||||
-rw-r--r-- | src/util.c | 43 |
7 files changed, 60 insertions, 57 deletions
diff --git a/src/.gitignore b/src/.gitignore index 38b001a..71b6685 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,5 +1,6 @@ cmdline.h *-cl.h eclat +ispeek comtab.man xref.man diff --git a/src/Makefile.am b/src/Makefile.am index f772c79..e78461c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ # This file is part of Eclat -# Copyright (C) 2012-2015 Sergey Poznyakoff +# Copyright (C) 2012-2018 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 @@ -79,7 +79,7 @@ ispeek_SOURCES = \ LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a $(CURL_LIBS) @MAPLIBS@ AM_CPPFLAGS = \ - -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib $(CURL_CFLAGS)\ + @GRECS_INCLUDES@ -I$(top_srcdir)/lib $(CURL_CFLAGS)\ -DSYSCONFDIR=\"$(sysconfdir)\"\ -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ @@ -134,7 +134,7 @@ EXTRA_DIST=\ SUFFIXES=.opt .c .h .opt.h: - $(AM_V_GEN)m4 -s $(top_srcdir)/grecs/build-aux/getopt.m4 eclatcl.m4 $< | sed '1d' > $@ + $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 eclatcl.m4 $< | sed '1d' > $@ comtab.man: eclat.c $(AM_V_GEN)if test -f eclat.c; then\ diff --git a/src/config.c b/src/config.c index 069ddd0..01379f3 100644 --- a/src/config.c +++ b/src/config.c @@ -380,13 +380,13 @@ static struct grecs_keyword instance_store_kw[] = { static struct grecs_keyword eclat_kw[] = { { "default-endpoint", "hostname", "Set default EC2 endpoint", - grecs_type_string, GRECS_DFLT, &endpoint }, + grecs_type_string, GRECS_CONST, &endpoint }, { "region", "<name: string> <endpoint: string>", "Define a region", grecs_type_string, GRECS_MULT, NULL, 0, cb_region }, { "signature-version", "version", "Signature version", - grecs_type_string, GRECS_DFLT, &signature_version }, + grecs_type_string, GRECS_CONST, &signature_version }, { "authentication-provider", "<type: file|instance-store> <arg: string>", "Define authentication provider.", grecs_type_string, GRECS_DFLT, NULL, 0, cb_authentication_provider }, @@ -468,7 +468,8 @@ config_init() DEFAULT_INCLUDE_DIR, NULL); grecs_preprocessor = DEFAULT_PREPROCESSOR; grecs_log_to_stderr = 1; - grecs_adjust_string_locations = 1; + grecs_parser_options = GRECS_OPTION_ADJUST_STRING_LOCATIONS + | GRECS_OPTION_QUOTED_STRING_CONCAT; grecs_print_diag_fun = grecs_print_diag; ec2_regtab = grecs_symtab_create_default(sizeof(struct ec2_param)); diff --git a/src/eclat.h b/src/eclat.h index 221347f..21e89e1 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -25,7 +25,7 @@ #include <curl/curl.h> #include <expat.h> #include "grecs.h" -#include "grecsopt.h" +#include "grecs/opt.h" #include "wordsplit.h" #include "libeclat.h" #include "forlan.h" diff --git a/src/ispeek.c b/src/ispeek.c index e602125..9e4f8e3 100644 --- a/src/ispeek.c +++ b/src/ispeek.c @@ -24,10 +24,10 @@ #include <string.h> #include <curl/curl.h> #include "grecs.h" -#include "grecsopt.h" +#include "grecs/opt.h" #include "wordsplit.h" #include "libeclat.h" -#include "json.h" +#include "grecs/json.h" const char *base_url = "http://169.254.169.254/latest"; @@ -128,29 +128,31 @@ print_file(const char *path, struct closure *cl) if (argv[0]) { char *key; - struct json_object *obj; + struct json_value *obj; static char typestr[] = { [json_null] = '0', [json_bool] = 'b', [json_number] = 'n', [json_string] = 's', [json_arr] = 'a', - [json_obj] = 'o' + [json_object] = 'o' }; obj = json_parse_string(text, strlen(text)); - if (!obj) - die(EX_DATAERR, - "%s: near %s", - json_err_diag, - json_err_ptr); + if (!obj) { + char *str = NULL; + size_t len = 0; + grecs_asprint_locus(&str, &len, &json_err_locus); + die(EX_DATAERR, "%s: %s", str, json_err_diag); + } + while (key = *argv++) { - struct json_object *p; + struct json_value *p; char *s; if (print_options & PRINT_NAME) printf("%s%s", key, delim); - p = json_object_lookup(obj, key); + p = json_value_lookup(obj, key); if (p) { if (print_options & PRINT_TYPE) printf("%c%s", typestr[p->type], delim); @@ -181,7 +183,7 @@ print_file(const char *path, struct closure *cl) case json_arr: printf("array"); break; - case json_obj: + case json_object: printf("object"); break; } diff --git a/src/mktags.c b/src/mktags.c index 6fb3b10..27ea327 100644 --- a/src/mktags.c +++ b/src/mktags.c @@ -1,5 +1,5 @@ /* This file is part of Eclat. - Copyright (C) 2012-2015 Sergey Poznyakoff. + Copyright (C) 2012-2018 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 @@ -52,6 +52,8 @@ process_tags(eclat_command_env_t *env, int argc, char **argv, int require_tags) size_t insize = 0; ssize_t rc; char *p; + struct wordsplit ws; + int wsflags; if (strcmp(from_file, "-") == 0) { from_file = "<stdin>"; @@ -63,32 +65,28 @@ process_tags(eclat_command_env_t *env, int argc, char **argv, int require_tags) from_file, strerror(errno)); } + wsflags = WRDSF_DEFFLAGS|WRDSF_NOSPLIT; while ((rc = grecs_getline(&inbuf, &insize, fp)) > 0) { - eclat_trimnl(inbuf); - if (inbuf[0] == '#' || inbuf[0] == 0) - continue; - p = strchr(inbuf, '='); + char *text; + if (wordsplit(inbuf, &ws, wsflags)) { + die(EX_SOFTWARE, "%s", wordsplit_strerror(&ws)); + } + wsflags |= WRDSF_REUSE; + text = ws.ws_wordv[0]; + p = strchr(text, '='); if (p) *p++ = 0; grecs_asprintf(&bufptr, &bufsize, "Tag.%d.Key", j); - eclat_request_add_param(q, bufptr, inbuf); + eclat_request_add_param(q, bufptr, text); if (p) { grecs_asprintf(&bufptr, &bufsize, "Tag.%d.Value", j); - if (*p == '"' && p[strlen(p)-1] == '"') { - size_t len = strlen(p); - char *copy = grecs_malloc(len); - - wordsplit_c_unquote_copy(copy, p + 1, - len - 2); - eclat_request_add_param(q, bufptr, - copy); - free(copy); - } else - eclat_request_add_param(q, bufptr, p); + eclat_request_add_param(q, bufptr, p); } ++j; } + if (wsflags & WRDSF_REUSE) + wordsplit_free(&ws); fclose(fp); free(inbuf); @@ -15,7 +15,7 @@ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ #include "eclat.h" -#include "json.h" +#include "grecs/json.h" #include <termios.h> #include <sys/ioctl.h> #include <sys/stat.h> @@ -501,7 +501,7 @@ char * eclat_get_instance_zone() { char *doc; - struct json_object *obj, *p; + struct json_value *obj, *p; char *retval = NULL; CURL *curl; char *url; @@ -522,17 +522,17 @@ eclat_get_instance_zone() if (!doc) return NULL; obj = json_parse_string(doc, strlen(doc)); - if (!obj) - die(EX_DATAERR, - "%s: near %s", - json_err_diag, - json_err_ptr); - - p = json_object_lookup(obj, "region"); + if (!obj) { + char *str = NULL; + size_t len = 0; + grecs_asprint_locus(&str, &len, &json_err_locus); + die(EX_DATAERR, "%s: %s", str, json_err_diag); + } + p = json_value_lookup(obj, "region"); if (p && p->type == json_string) retval = grecs_strdup(p->v.s); grecs_txtacc_free(acc); - json_object_free(obj); + json_value_free(obj); return retval; } @@ -544,7 +544,7 @@ eclat_get_instance_creds(char *id, char **access_key_ptr, char **secret_key_ptr, char *url = NULL; char *s; char *doc; - struct json_object *obj, *p; + struct json_value *obj, *p; int err = 0; struct grecs_txtacc *acc; @@ -579,32 +579,33 @@ eclat_get_instance_creds(char *id, char **access_key_ptr, char **secret_key_ptr, free(url); obj = json_parse_string(doc, strlen(doc)); - if (!obj) - die(EX_DATAERR, - "%s: near %s", - json_err_diag, - json_err_ptr); - - p = json_object_lookup(obj, "AccessKeyId"); + if (!obj) { + char *str = NULL; + size_t len = 0; + grecs_asprint_locus(&str, &len, &json_err_locus); + die(EX_DATAERR, "%s: %s", str, json_err_diag); + } + + p = json_value_lookup(obj, "AccessKeyId"); if (p && p->type == json_string) *access_key_ptr = grecs_strdup(p->v.s); else err = 1; - p = json_object_lookup(obj, "SecretAccessKey"); + p = json_value_lookup(obj, "SecretAccessKey"); if (p && p->type == json_string) *secret_key_ptr = grecs_strdup(p->v.s); else err = 1; - p = json_object_lookup(obj, "Token"); + p = json_value_lookup(obj, "Token"); if (p && p->type == json_string) *token_ptr = grecs_strdup(p->v.s); else err = 1; grecs_txtacc_free(acc); - json_object_free(obj); + json_value_free(obj); if (err) die(EX_DATAERR, "security credentials missing"); |