aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-01-23 12:45:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-01-23 13:08:19 +0200
commit0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2 (patch)
tree2b617611ddeb6f97d9f316750496ac13c5ce59ad /src
parentb1824338b366e25756e4c64f04e535684529832d (diff)
downloadeclat-0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2.tar.gz
eclat-0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2.tar.bz2
Implement HTTP POST
* NEWS: Update. * doc/eclat.conf.5: Document http-method. Reorganize description of endpoints and regions. * lib/libeclat.h (ec2_request) <postdata>: New member (eclat_request_finalize): New proto. * lib/req2url.c (eclat_request_to_url): Remove second argument. All uses changed. (eclat_request_finalize): New function. * lib/reqfree.c: Free postdata. * lib/reqsign.c (requestsign4): Implement post. * src/config.c: New configuration statement http-method. * src/eclat.c (use_post): New variable. * src/eclat.h (use_post): New extern. * src/util.c (eclat_send_request): Implement post.
Diffstat (limited to 'src')
-rw-r--r--src/config.c33
-rw-r--r--src/eclat.c14
-rw-r--r--src/eclat.h1
-rw-r--r--src/util.c12
4 files changed, 53 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c
index 548b11a..49b47f9 100644
--- a/src/config.c
+++ b/src/config.c
@@ -296,8 +296,8 @@ cb_authentication_provider(enum grecs_callback_command cmd,
}
if (strcmp(type, "file") == 0) {
- if (arg) {
- grecs_error(locus, 0, "requered argument missing");
+ if (!arg) {
+ grecs_error(locus, 0, "required argument missing");
return 1;
}
authentication_provider = authp_file;
@@ -337,6 +337,29 @@ cb_access_file(enum grecs_callback_command cmd,
*(char**)varptr = grecs_strdup(value->v.string);
return 0;
}
+
+static int
+cb_http_method(enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr,
+ grecs_value_t *value,
+ void *cb_data)
+{
+ if (cmd != grecs_callback_set_value) {
+ grecs_error(locus, 0, "Unexpected block statement");
+ return 1;
+ }
+ if (!value || value->type != GRECS_TYPE_STRING) {
+ grecs_error(locus, 0, "expected string value");
+ return 1;
+ }
+ if (strcasecmp(value->v.string, "post") == 0)
+ use_post = 1;
+ else if (strcasecmp(value->v.string, "get"))
+ grecs_error(&value->locus, 0, "invalid http method");
+ return 0;
+}
+
static struct grecs_keyword instance_store_kw[] = {
{ "base-url", "URL",
@@ -387,6 +410,9 @@ static struct grecs_keyword eclat_kw[] = {
grecs_type_section, GRECS_DFLT,
NULL, 0,
cb_ssl, NULL, ssl_kw },
+ { "http-method", "arg: post|get",
+ "Define HTTP method to use",
+ grecs_type_string, GRECS_DFLT, NULL, 0, cb_http_method },
{ "format", "<command: string> <format: string>",
"Set default format for <command>",
grecs_type_string, GRECS_MULT, NULL, 0, cb_format },
@@ -465,6 +491,9 @@ config_finish(struct grecs_node *tree)
exit(EX_CONFIG);
if (grecs_error_count || run_config_finish_hooks())
exit(EX_CONFIG);
+
+ if (use_post)
+ signature_version = "4";
}
diff --git a/src/eclat.c b/src/eclat.c
index beaa934..2e46930 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -31,6 +31,7 @@ char *secret_key;
char *security_token;
char *region_name;
int use_ssl;
+int use_post;
int ssl_verify_peer = 1;
char *ssl_ca_file;
char *ssl_ca_path;
@@ -646,10 +647,15 @@ eclat_do_command(eclat_command_env_t *env, struct eclat_command *command,
int rc;
if (!(command->flags & CMD_NOQRY)) {
- env->request = eclat_request_create(use_ssl ? EC2_RF_HTTPS : 0,
- endpoint, "/",
- region_name, access_key,
- security_token);
+ int flags = 0;
+ if (use_ssl)
+ flags |= EC2_RF_HTTPS;
+ if (use_post)
+ flags |= EC2_RF_POST;
+ env->request = eclat_request_create(flags,
+ endpoint, "/",
+ region_name, access_key,
+ security_token);
}
if (command->tag)
diff --git a/src/eclat.h b/src/eclat.h
index a8ac2a0..604ffdc 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -49,6 +49,7 @@ enum authentication_provider {
extern char *endpoint;
extern char *signature_version;
extern int use_ssl;
+extern int use_post;
extern int ssl_verify_peer;
extern char *ssl_ca_file;
extern char *ssl_ca_path;
diff --git a/src/util.c b/src/util.c
index 92532f0..79a78ff 100644
--- a/src/util.c
+++ b/src/util.c
@@ -227,8 +227,15 @@ eclat_send_request(CURL *curl, struct ec2_request *req)
struct curl_slist *headers = NULL;
/* Prepare the request */
+ if (req->flags & EC2_RF_POST) {
+ eclat_request_finalize(req);
+ curl_easy_setopt(curl, CURLOPT_POST, 1);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req->postdata);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
+ strlen(req->postdata));
+ }
eclat_request_sign(req, secret_key, signature_version);
- url = eclat_request_to_url(req, NULL);
+ url = eclat_request_to_url(req);
curl_easy_setopt(curl, CURLOPT_URL, url);
debug(ECLAT_DEBCAT_MAIN, 1, ("using URL: %s", url));
free(url);
@@ -263,6 +270,9 @@ eclat_send_request(CURL *curl, struct ec2_request *req)
curl_easy_strerror(rc));
}
+ if (req->flags & EC2_RF_POST)
+ debug(ECLAT_DEBCAT_MAIN, 1, ("DATA: %s", req->postdata));
+
if (dry_run_mode)
debug(ECLAT_DEBCAT_MAIN, 1, ("not sending request"));
else {

Return to:

Send suggestions and report system problems to the System administrator.