kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 0e2f478c7509d9a72d58636eeffd5e9fd9ac6e57
parent a2897f790cc8d8060f35c06eda334e6d751ad663
Author: Joris Vink <joris@coders.se>
Date:   Sun,  3 Aug 2014 15:20:20 +0200

Fix http_argument_get_*() integer functions.

Diffstat:
includes/http.h | 35+++++++++++++++++++++--------------
src/http.c | 5+++--
2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/includes/http.h b/includes/http.h @@ -55,11 +55,11 @@ struct http_arg { TAILQ_ENTRY(http_arg) list; }; -#define COPY_ARG_TYPE(v, l, t, o) \ +#define COPY_ARG_TYPE(v, l, t) \ do { \ if (l != NULL) \ *l = sizeof(t); \ - *(t **)o = *(t **)v; \ + *(t *)nout = v; \ } while (0); #define COPY_ARG_INT64(type, sign) \ @@ -69,7 +69,7 @@ struct http_arg { nval = (type)kore_strtonum64(q->s_value, sign, &err); \ if (err != KORE_RESULT_OK) \ return (KORE_RESULT_ERROR); \ - COPY_ARG_TYPE(&nval, len, type, out); \ + COPY_ARG_TYPE(nval, len, type); \ } while (0); #define COPY_ARG_INT(min, max, type) \ @@ -79,7 +79,7 @@ struct http_arg { nval = kore_strtonum(q->s_value, 10, min, max, &err); \ if (err != KORE_RESULT_OK) \ return (KORE_RESULT_ERROR); \ - COPY_ARG_TYPE(&nval, len, type, out); \ + COPY_ARG_TYPE(nval, len, type); \ } while (0); #define CACHE_STRING() \ @@ -93,39 +93,46 @@ struct http_arg { #define COPY_AS_INTTYPE_64(type, sign) \ do { \ + if (nout == NULL) \ + return (KORE_RESULT_ERROR); \ CACHE_STRING(); \ COPY_ARG_INT64(type, sign); \ } while (0); #define COPY_AS_INTTYPE(min, max, type) \ do { \ + if (nout == NULL) \ + return (KORE_RESULT_ERROR); \ CACHE_STRING(); \ COPY_ARG_INT(min, max, type); \ } while (0); -#define http_argument_type(r, n, o, l, t) \ - http_argument_get(r, n, (void **)o, l, t) +#define http_argument_type(r, n, so, no, l, t) \ + http_argument_get(r, n, so, no, l, t) #define http_argument_get_string(n, o, l) \ - http_argument_type(req, n, o, l, HTTP_ARG_TYPE_STRING) + http_argument_type(req, n, o, NULL, l, HTTP_ARG_TYPE_STRING) + +#define http_argument_get_byte(n, o) \ + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_BYTE) #define http_argument_get_uint16(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_UINT16) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_UINT16) #define http_argument_get_int16(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_INT16) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_INT16) #define http_argument_get_uint32(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_UINT32) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_UINT32) #define http_argument_get_int32(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_INT32) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_INT32) #define http_argument_get_uint64(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_UINT64) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_UINT64) #define http_argument_get_int64(n, o) \ - http_argument_type(req, n, o, NULL, HTTP_ARG_TYPE_INT64) + http_argument_type(req, n, NULL, o, NULL, HTTP_ARG_TYPE_INT64) struct http_file { @@ -203,7 +210,7 @@ int http_generic_404(struct http_request *); int http_populate_arguments(struct http_request *); int http_populate_multipart_form(struct http_request *, int *); int http_argument_get(struct http_request *, - const char *, void **, u_int32_t *, int); + const char *, void **, void *, u_int32_t *, int); int http_file_lookup(struct http_request *, char *, char **, u_int8_t **, u_int32_t *); diff --git a/src/http.c b/src/http.c @@ -611,7 +611,7 @@ http_populate_arguments(struct http_request *req) int http_argument_get(struct http_request *req, const char *name, - void **out, u_int32_t *len, int type) + void **out, void *nout, u_int32_t *len, int type) { struct http_arg *q; @@ -627,7 +627,8 @@ http_argument_get(struct http_request *req, const char *name, *out = q->value; return (KORE_RESULT_OK); case HTTP_ARG_TYPE_BYTE: - COPY_ARG_TYPE(q->value, len, u_int8_t, out); + COPY_ARG_TYPE(*(u_int8_t *)q->value, + len, u_int8_t); return (KORE_RESULT_OK); case HTTP_ARG_TYPE_INT16: COPY_AS_INTTYPE(SHRT_MIN, SHRT_MAX, int16_t);