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);
This commit is contained in:
Joris Vink 2013-08-07 14:41:16 +02:00
parent 6dbcb30eb9
commit ef814a677d
3 changed files with 32 additions and 0 deletions

View File

@ -79,8 +79,11 @@ int http_generic_404(struct http_request *);
int http_header_recv(struct netbuf *); int http_header_recv(struct netbuf *);
char *http_post_data_text(struct http_request *); char *http_post_data_text(struct http_request *);
int http_populate_arguments(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 *, int http_argument_lookup(struct http_request *,
const char *, char **); const char *, char **);
int http_argument_multiple_lookup(struct http_request *,
struct http_arg *);
void kore_accesslog(struct http_request *); void kore_accesslog(struct http_request *);

View File

@ -47,6 +47,8 @@
#define KORE_PIDFILE_DEFAULT "/var/run/kore.pid" #define KORE_PIDFILE_DEFAULT "/var/run/kore.pid"
#define KORE_DEFAULT_CIPHER_LIST "HIGH:!aNULL:!MD5;" #define KORE_DEFAULT_CIPHER_LIST "HIGH:!aNULL:!MD5;"
#define KORE_DEBUG 1
#if defined(KORE_DEBUG) #if defined(KORE_DEBUG)
#define kore_debug(fmt, ...) \ #define kore_debug(fmt, ...) \
if (kore_debug) \ if (kore_debug) \

View File

@ -485,6 +485,33 @@ http_argument_lookup(struct http_request *req, const char *name, char **out)
return (KORE_RESULT_ERROR); 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 * char *
http_post_data_text(struct http_request *req) http_post_data_text(struct http_request *req)
{ {