From 4a72c67c34b1c5b348e61ab900fb0b64305b9f97 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 2 Feb 2015 14:53:19 +0200 Subject: New options: --check-permissions and --add-parameter * NEWS: Update. * doc/eclat-stop.1: Update. * doc/eclat.1man: Update. * etc/default.fln: Special handling for DryRunOperation and UnauthorizedOperation codes. * lib/paramlist.c: New file. * lib/Makefile.am (libeclat_a_SOURCES): Add paramlist.c * lib/forlan.c: New function dequote. * lib/libeclat.h (eclat_request_add_param0) (ec2_param_free, ec2_param_list_create) (ec2_param_list_append) (eclat_request_add_param_list): New protos. * lib/reqcreat.c (ec2_param_free): Remove static qualifier. * src/stop-cl.opt: New file. * src/Makefile.am (OPTFILES): Add stop-cl.opt * src/cmdline.opt: New options: --check-permissions and --add-parameter. * src/eclat.c (extra_param): New global. (find_format): print error message if no such format is found. * src/startstop.c (eclat_stop_instance): Use parse_stop_options --- lib/Makefile.am | 1 + lib/forlan.c | 17 +++++++++++++++++ lib/libeclat.h | 9 +++++++++ lib/paramlist.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/reqcreat.c | 2 +- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 lib/paramlist.c (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index 5cfa67a..711bc98 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -53,6 +53,7 @@ libeclat_a_SOURCES=\ hmac_sha256.c\ libeclat.h\ map.c\ + paramlist.c\ path.c\ req2url.c\ reqaddparm.c\ diff --git a/lib/forlan.c b/lib/forlan.c index 2275bc7..977271d 100644 --- a/lib/forlan.c +++ b/lib/forlan.c @@ -1048,6 +1048,22 @@ func_decode(forlan_eval_env_t env, struct grecs_list *list) grecs_txtacc_free(acc); } +static void +func_dequote(forlan_eval_env_t env, struct grecs_list *list) +{ + struct forlan_value *val = list->head->data; + char *s = val->v.string; + size_t l = strlen(s); + + if (l >= 2 && s[0] == '"' && s[l-1] == '"') { + s++; + l -= 2; + } + env->retval.v.string = grecs_malloc(l + 1); + memcpy(env->retval.v.string, s, l); + env->retval.v.string[l] = 0; +} + static void func_exit(forlan_eval_env_t env, struct grecs_list *list) { @@ -1127,6 +1143,7 @@ static struct forlan_function functab[] = { { "parent", forlan_value_node, "n", 1, 1, func_parent }, { "sort", forlan_value_void, "nss", 1, 3, func_sort }, { "decode", forlan_value_literal, "s", 1, 1, func_decode }, + { "dequote", forlan_value_literal, "s", 1, 1, func_dequote }, { "exit", forlan_value_void, "s", 1, 1, func_exit }, { "empty", forlan_value_boolean, "n", 1, 1, func_empty }, { "timestamp", forlan_value_literal, "s", 1, 1, func_timestamp }, diff --git a/lib/libeclat.h b/lib/libeclat.h index b33f0a2..770fb7d 100644 --- a/lib/libeclat.h +++ b/lib/libeclat.h @@ -105,6 +105,8 @@ struct ec2_request *eclat_request_create(int flags, const char *endpoint, const char *uri, char const *region, char const *access_key, char const *token); void eclat_request_free(struct ec2_request *); +void eclat_request_add_param0(struct ec2_request *req, const char *name, + const char *value, int encoded); void eclat_request_add_param(struct ec2_request *req, const char *name, const char *value); void eclat_request_add_param_encoded(struct ec2_request *req, const char *name, @@ -119,6 +121,13 @@ char *eclat_request_to_url(struct ec2_request *req); void eclat_request_encode(struct ec2_request *req); void eclat_request_finalize(struct ec2_request *req); +void ec2_param_free(void *ptr); + +struct grecs_list *ec2_param_list_create(void); +void ec2_param_list_append(struct grecs_list **lp, char const *name, + char const *val); +void eclat_request_add_param_list(struct ec2_request *req, + struct grecs_list *lp); typedef struct eclat_partial_tree *eclat_partial_tree_t; diff --git a/lib/paramlist.c b/lib/paramlist.c new file mode 100644 index 0000000..6d6c40a --- /dev/null +++ b/lib/paramlist.c @@ -0,0 +1,57 @@ +/* This file is part of Eclat. + Copyright (C) 2012-2015 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 . */ + +#include +#include +#include "libeclat.h" +#include "grecs.h" + +struct grecs_list * +ec2_param_list_create() +{ + struct grecs_list *lp = grecs_list_create(); + lp->free_entry = ec2_param_free; + return lp; +} + +void +ec2_param_list_append(struct grecs_list **lpp, char const *name, + char const *val) +{ + struct ec2_param *p; + if (!*lpp) + *lpp = ec2_param_list_create(); + p = grecs_zalloc(sizeof(*p)); + p->name = grecs_strdup(name); + p->value = grecs_strdup(val); + p->encoded = 0; + grecs_list_append(*lpp, p); +} + +void +eclat_request_add_param_list(struct ec2_request *req, struct grecs_list *lp) +{ + struct grecs_list_entry *ep; + + if (!lp) + return; + for (ep = lp->head; ep; ep = ep->next) { + struct ec2_param *param = ep->data; + eclat_request_add_param0(req, + param->name, param->value, + param->encoded); + } +} diff --git a/lib/reqcreat.c b/lib/reqcreat.c index 65f7880..58d7829 100644 --- a/lib/reqcreat.c +++ b/lib/reqcreat.c @@ -18,7 +18,7 @@ #include "libeclat.h" #include "grecs.h" -static void +void ec2_param_free(void *ptr) { struct ec2_param *p = ptr; -- cgit v1.2.1