forked from mirrors/kore
q->value should be set to NULL if a query parameter is present but no value was set for it.
introduce kore_buf_appendv() (much like readv()). introduce kore_buf_appendf() (printf into buffers).
This commit is contained in:
parent
61b937ac1b
commit
45adae62f7
|
@ -108,6 +108,11 @@ struct kore_buf {
|
|||
u_int32_t offset;
|
||||
};
|
||||
|
||||
struct buf_vec {
|
||||
u_int8_t *data;
|
||||
u_int32_t length;
|
||||
};
|
||||
|
||||
extern int server_port;
|
||||
extern char *server_ip;
|
||||
|
||||
|
@ -151,6 +156,8 @@ void net_send_queue(struct connection *, u_int8_t *, size_t, int,
|
|||
struct kore_buf *kore_buf_create(u_int32_t);
|
||||
void kore_buf_append(struct kore_buf *, u_int8_t *, u_int32_t);
|
||||
u_int8_t *kore_buf_release(struct kore_buf *, u_int32_t *);
|
||||
void kore_buf_appendf(struct kore_buf *, const char *, ...);
|
||||
void kore_buf_appendv(struct kore_buf *, struct buf_vec *, u_int16_t);
|
||||
|
||||
struct spdy_header_block *spdy_header_block_create(int);
|
||||
struct spdy_stream *spdy_stream_lookup(struct connection *, u_int32_t);
|
||||
|
|
26
src/buf.c
26
src/buf.c
|
@ -62,6 +62,32 @@ kore_buf_append(struct kore_buf *buf, u_int8_t *d, u_int32_t len)
|
|||
buf->offset += len;
|
||||
}
|
||||
|
||||
void
|
||||
kore_buf_appendv(struct kore_buf *buf, struct buf_vec *v, u_int16_t count)
|
||||
{
|
||||
u_int16_t i;
|
||||
struct buf_vec *p;
|
||||
|
||||
p = v;
|
||||
for (i = 0; i < count; i++) {
|
||||
kore_buf_append(buf, p->data, p->length);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
kore_buf_appendf(struct kore_buf *buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char b[2048];
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(b, sizeof(b), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
kore_buf_append(buf, (u_int8_t *)b, strlen(b));
|
||||
}
|
||||
|
||||
u_int8_t *
|
||||
kore_buf_release(struct kore_buf *buf, u_int32_t *len)
|
||||
{
|
||||
|
|
12
src/http.c
12
src/http.c
|
@ -130,7 +130,8 @@ http_request_free(struct http_request *req)
|
|||
|
||||
TAILQ_REMOVE(&(req->arguments), q, list);
|
||||
free(q->name);
|
||||
free(q->value);
|
||||
if (q->value != NULL)
|
||||
free(q->value);
|
||||
free(q);
|
||||
}
|
||||
|
||||
|
@ -417,14 +418,17 @@ http_populate_arguments(struct http_request *req)
|
|||
v = kore_split_string(query, "&", args, HTTP_MAX_QUERY_ARGS);
|
||||
for (i = 0; i < v; i++) {
|
||||
c = kore_split_string(args[i], "=", val, 3);
|
||||
if (c != 2) {
|
||||
if (c != 1 && c != 2) {
|
||||
kore_log("malformed query argument");
|
||||
continue;
|
||||
}
|
||||
|
||||
q = (struct http_arg *)kore_malloc(sizeof(*q));
|
||||
q->name = kore_strdup(val[0]);
|
||||
q->value = kore_strdup(val[1]);
|
||||
if (c == 2)
|
||||
q->value = kore_strdup(val[1]);
|
||||
else
|
||||
q->value = NULL;
|
||||
TAILQ_INSERT_TAIL(&(req->arguments), q, list);
|
||||
count++;
|
||||
}
|
||||
|
@ -440,6 +444,8 @@ http_argument_lookup(struct http_request *req, const char *name, char **out)
|
|||
|
||||
TAILQ_FOREACH(q, &(req->arguments), list) {
|
||||
if (!strcmp(q->name, name)) {
|
||||
if (q->value == NULL)
|
||||
return (KORE_RESULT_ERROR);
|
||||
*out = kore_strdup(q->value);
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue