mirror of https://git.kore.io/kore.git
Fix http_argument_get_*() integer functions.
This commit is contained in:
parent
a2897f790c
commit
0e2f478c75
|
@ -55,11 +55,11 @@ struct http_arg {
|
||||||
TAILQ_ENTRY(http_arg) list;
|
TAILQ_ENTRY(http_arg) list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define COPY_ARG_TYPE(v, l, t, o) \
|
#define COPY_ARG_TYPE(v, l, t) \
|
||||||
do { \
|
do { \
|
||||||
if (l != NULL) \
|
if (l != NULL) \
|
||||||
*l = sizeof(t); \
|
*l = sizeof(t); \
|
||||||
*(t **)o = *(t **)v; \
|
*(t *)nout = v; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define COPY_ARG_INT64(type, sign) \
|
#define COPY_ARG_INT64(type, sign) \
|
||||||
|
@ -69,7 +69,7 @@ struct http_arg {
|
||||||
nval = (type)kore_strtonum64(q->s_value, sign, &err); \
|
nval = (type)kore_strtonum64(q->s_value, sign, &err); \
|
||||||
if (err != KORE_RESULT_OK) \
|
if (err != KORE_RESULT_OK) \
|
||||||
return (KORE_RESULT_ERROR); \
|
return (KORE_RESULT_ERROR); \
|
||||||
COPY_ARG_TYPE(&nval, len, type, out); \
|
COPY_ARG_TYPE(nval, len, type); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define COPY_ARG_INT(min, max, type) \
|
#define COPY_ARG_INT(min, max, type) \
|
||||||
|
@ -79,7 +79,7 @@ struct http_arg {
|
||||||
nval = kore_strtonum(q->s_value, 10, min, max, &err); \
|
nval = kore_strtonum(q->s_value, 10, min, max, &err); \
|
||||||
if (err != KORE_RESULT_OK) \
|
if (err != KORE_RESULT_OK) \
|
||||||
return (KORE_RESULT_ERROR); \
|
return (KORE_RESULT_ERROR); \
|
||||||
COPY_ARG_TYPE(&nval, len, type, out); \
|
COPY_ARG_TYPE(nval, len, type); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define CACHE_STRING() \
|
#define CACHE_STRING() \
|
||||||
|
@ -93,39 +93,46 @@ struct http_arg {
|
||||||
|
|
||||||
#define COPY_AS_INTTYPE_64(type, sign) \
|
#define COPY_AS_INTTYPE_64(type, sign) \
|
||||||
do { \
|
do { \
|
||||||
|
if (nout == NULL) \
|
||||||
|
return (KORE_RESULT_ERROR); \
|
||||||
CACHE_STRING(); \
|
CACHE_STRING(); \
|
||||||
COPY_ARG_INT64(type, sign); \
|
COPY_ARG_INT64(type, sign); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define COPY_AS_INTTYPE(min, max, type) \
|
#define COPY_AS_INTTYPE(min, max, type) \
|
||||||
do { \
|
do { \
|
||||||
|
if (nout == NULL) \
|
||||||
|
return (KORE_RESULT_ERROR); \
|
||||||
CACHE_STRING(); \
|
CACHE_STRING(); \
|
||||||
COPY_ARG_INT(min, max, type); \
|
COPY_ARG_INT(min, max, type); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define http_argument_type(r, n, o, l, t) \
|
#define http_argument_type(r, n, so, no, l, t) \
|
||||||
http_argument_get(r, n, (void **)o, l, t)
|
http_argument_get(r, n, so, no, l, t)
|
||||||
|
|
||||||
#define http_argument_get_string(n, o, l) \
|
#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) \
|
#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) \
|
#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) \
|
#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) \
|
#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) \
|
#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) \
|
#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 {
|
struct http_file {
|
||||||
|
@ -203,7 +210,7 @@ int http_generic_404(struct http_request *);
|
||||||
int http_populate_arguments(struct http_request *);
|
int http_populate_arguments(struct http_request *);
|
||||||
int http_populate_multipart_form(struct http_request *, int *);
|
int http_populate_multipart_form(struct http_request *, int *);
|
||||||
int http_argument_get(struct http_request *,
|
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 **,
|
int http_file_lookup(struct http_request *, char *, char **,
|
||||||
u_int8_t **, u_int32_t *);
|
u_int8_t **, u_int32_t *);
|
||||||
|
|
||||||
|
|
|
@ -611,7 +611,7 @@ http_populate_arguments(struct http_request *req)
|
||||||
|
|
||||||
int
|
int
|
||||||
http_argument_get(struct http_request *req, const char *name,
|
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;
|
struct http_arg *q;
|
||||||
|
|
||||||
|
@ -627,7 +627,8 @@ http_argument_get(struct http_request *req, const char *name,
|
||||||
*out = q->value;
|
*out = q->value;
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
case HTTP_ARG_TYPE_BYTE:
|
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);
|
return (KORE_RESULT_OK);
|
||||||
case HTTP_ARG_TYPE_INT16:
|
case HTTP_ARG_TYPE_INT16:
|
||||||
COPY_AS_INTTYPE(SHRT_MIN, SHRT_MAX, int16_t);
|
COPY_AS_INTTYPE(SHRT_MIN, SHRT_MAX, int16_t);
|
||||||
|
|
Loading…
Reference in New Issue