aboutsummaryrefslogtreecommitdiff
path: root/lib/reqaddparm.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-01-22 23:59:22 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-01-23 00:03:33 +0200
commitb1824338b366e25756e4c64f04e535684529832d (patch)
tree2dcbf32e0b4fb06b1c4b0a992db882ba184bbd18 /lib/reqaddparm.c
parent2beaaadb282bd4667e3af1ed65e3944960d1bd3e (diff)
downloadeclat-b1824338b366e25756e4c64f04e535684529832d.tar.gz
eclat-b1824338b366e25756e4c64f04e535684529832d.tar.bz2
Namespace fixup: use "request" consistently
Diffstat (limited to 'lib/reqaddparm.c')
-rw-r--r--lib/reqaddparm.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/reqaddparm.c b/lib/reqaddparm.c
new file mode 100644
index 0000000..916bf92
--- /dev/null
+++ b/lib/reqaddparm.c
@@ -0,0 +1,93 @@
+/* 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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <string.h>
+#include "libeclat.h"
+#include "grecs.h"
+
+void
+eclat_request_add_param0(struct ec2_request *req, const char *name,
+ const char *value, int encoded)
+{
+ struct ec2_param *p, key;
+ int install = 1;
+
+ key.name = (char*) name;
+ p = grecs_symtab_lookup_or_install(req->params, &key, &install);
+ if (!install)
+ free(p->value);
+ p->value = value ? grecs_strdup(value) : NULL;
+ p->encoded = encoded;
+}
+
+void
+eclat_request_add_param(struct ec2_request *req, const char *name,
+ const char *value)
+{
+ eclat_request_add_param0(req, name, value, 0);
+}
+
+void
+eclat_request_add_param_encoded(struct ec2_request *req, const char *name,
+ const char *value)
+{
+ if (value) {
+ char *str;
+ urlencode(value, strlen(value), &str, NULL);
+ eclat_request_add_param0(req, name, str, 1);
+ free(str);
+ } else
+ eclat_request_add_param0(req, name, value, 1);
+}
+
+
+static void
+free_header(void *data)
+{
+ struct ec2_param *p = data;
+ free(p->name);
+ free(p->value);
+ free(p);
+}
+
+void
+eclat_request_add_header(struct ec2_request *req, const char *name,
+ const char *value)
+{
+ struct ec2_param *ent;
+
+ if (!req->headers) {
+ req->headers = grecs_list_create();
+ req->headers->free_entry = free_header;
+ }
+ ent = grecs_malloc(sizeof(*ent));
+ ent->name = grecs_strdup(name);
+ if (value) {
+ int len;
+
+ while (*value == ' ' || *value == '\t')
+ ++value;
+ len = strlen(value);
+ while (len && (value[len-1] == ' ' || value[len-1] == '\t'))
+ --len;
+ ent->value = grecs_malloc(len + 1);
+ memcpy(ent->value, value, len);
+ ent->value[len] = 0;
+ } else
+ ent->value = NULL;
+ grecs_list_append(req->headers, ent);
+}

Return to:

Send suggestions and report system problems to the System administrator.