kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit ef814a677de41406c8be1ceb267de89e5c6bead1
parent 6dbcb30eb95925b124129c35cdd2200701a6e88e
Author: Joris Vink <joris@coders.se>
Date:   Wed,  7 Aug 2013 14:41:16 +0200

Add http_argument_multiple_lookup() and http_argument_multiple_free().

Prototypes:
	int	http_argument_multiple_lookup(struct http_req *req,
		    struct http_arg *args);
	void	http_argument_multiple_free(struct http_arg *args);

These functions can be used to lookup arguments in a single call.

args points to an array of struct http_arg elements. Each of them
have the argument name set and its value set to NULL.

The array must have its last element name field set to NULL.

Upon return http_argument_multiple_lookup() gives the caller the
number of arguments that were successfully found. It makes their values
available under the value field in the struct http_arg array passed.

Example:
	int			v;
	struct http_args	args[4];

	memset(args, 0, sizeof(args));
	args[0].name = "email";
	args[1].name = "password1";
	args[2].name = "password2";
	args[3].name = NULL;

	v = http_argument_multiple_lookup(req, args);
	if (v != 3) {
		kore_debug("argument %s was not present", args[v].name);
	} else {
		for (v = 0; args[v].name != NULL; v++)
			kore_debug("%s -> %s", args[v].name, args[v].value);
	}

	http_argument_multiple_free(args);

Diffstat:
includes/http.h | 3+++
includes/kore.h | 2++
src/http.c | 27+++++++++++++++++++++++++++
3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/includes/http.h b/includes/http.h @@ -79,8 +79,11 @@ int http_generic_404(struct http_request *); int http_header_recv(struct netbuf *); char *http_post_data_text(struct http_request *); int http_populate_arguments(struct http_request *); +void http_argument_multiple_free(struct http_arg *); int http_argument_lookup(struct http_request *, const char *, char **); +int http_argument_multiple_lookup(struct http_request *, + struct http_arg *); void kore_accesslog(struct http_request *); diff --git a/includes/kore.h b/includes/kore.h @@ -47,6 +47,8 @@ #define KORE_PIDFILE_DEFAULT "/var/run/kore.pid" #define KORE_DEFAULT_CIPHER_LIST "HIGH:!aNULL:!MD5;" +#define KORE_DEBUG 1 + #if defined(KORE_DEBUG) #define kore_debug(fmt, ...) \ if (kore_debug) \ diff --git a/src/http.c b/src/http.c @@ -485,6 +485,33 @@ http_argument_lookup(struct http_request *req, const char *name, char **out) return (KORE_RESULT_ERROR); } +int +http_argument_multiple_lookup(struct http_request *req, struct http_arg *args) +{ + int i; + + for (i = 0; args[i].name != NULL; i++) { + if (!http_argument_lookup(req, + args[i].name, &(args[i].value))) { + args[i].value = NULL; + return (i); + } + } + + return (i); +} + +void +http_argument_multiple_free(struct http_arg *args) +{ + int i; + + for (i = 0; args[i].name != NULL; i++) { + if (args[i].value != NULL) + kore_mem_free(args[i].value); + } +} + char * http_post_data_text(struct http_request *req) {