summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-09 01:17:29 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-09 01:17:29 +0200
commit98206c93194ced5dffe41e72939e337f851f3fb4 (patch)
tree5b0b5184878a9bd7fe102f87f38308af478b6c7d
parent083f4da2a8edc5757496306981a272ea9e4d73dc (diff)
journal: add matching support to gatewayd
-rw-r--r--src/journal/journal-gatewayd.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 0957dcbe5a..9599e891da 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -45,6 +45,8 @@ typedef struct RequestMeta {
FILE *tmp;
uint64_t delta, size;
+
+ int argument_parse_error;
} RequestMeta;
static const char* const mime_types[_OUTPUT_MODE_MAX] = {
@@ -337,6 +339,51 @@ static int request_parse_range(
return 0;
}
+static int request_parse_arguments_iterator(
+ void *cls,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *value) {
+
+ RequestMeta *m = cls;
+ _cleanup_free_ char *p = NULL;
+ int r;
+
+ assert(m);
+
+ if (isempty(key)) {
+ m->argument_parse_error = -EINVAL;
+ return MHD_NO;
+ }
+
+ p = strjoin(key, "=", strempty(value), NULL);
+ if (!p) {
+ m->argument_parse_error = log_oom();
+ return MHD_NO;
+ }
+
+ r = sd_journal_add_match(m->journal, p, 0);
+ if (r < 0) {
+ m->argument_parse_error = r;
+ return MHD_NO;
+ }
+
+ return MHD_YES;
+}
+
+static int request_parse_arguments(
+ RequestMeta *m,
+ struct MHD_Connection *connection) {
+
+ assert(m);
+ assert(connection);
+
+ m->argument_parse_error = 0;
+ MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, request_parse_arguments_iterator, m);
+
+ return m->argument_parse_error;
+}
+
static int request_handler_entries(
struct MHD_Connection *connection,
void **connection_cls) {
@@ -362,6 +409,9 @@ static int request_handler_entries(
if (request_parse_range(m, connection) < 0)
return respond_error(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse Range header.\n");
+ if (request_parse_arguments(m, connection) < 0)
+ return respond_error(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse URL arguments.\n");
+
/* log_info("cursor = %s", m->cursor); */
/* log_info("skip = %lli", m->n_skip); */
/* if (!m->n_entries_set) */