X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-gatewayd.c;h=33dda266b6a31f049a1e286889fc64db5e427126;hb=c6511e859c35b12de4e6fb5f58d7258d9de3b8f2;hp=274ef5ffeb08a99d3e9798ef7aa4ddfd82261d46;hpb=77ad3b93de65c27cc82dbccc7d336c3aff768c77;p=elogind.git diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c index 274ef5ffe..33dda266b 100644 --- a/src/journal/journal-gatewayd.c +++ b/src/journal/journal-gatewayd.c @@ -49,6 +49,7 @@ typedef struct RequestMeta { int argument_parse_error; bool follow; + bool discrete; } RequestMeta; static const char* const mime_types[_OUTPUT_MODE_MAX] = { @@ -205,6 +206,19 @@ static ssize_t request_reader_entries( return MHD_CONTENT_READER_END_OF_STREAM; } + if (m->discrete) { + assert(m->cursor); + + r = sd_journal_test_cursor(m->journal, m->cursor); + if (r < 0) { + log_error("Failed to test cursor: %s", strerror(-r)); + return MHD_CONTENT_READER_END_WITH_ERROR; + } + + if (r == 0) + return MHD_CONTENT_READER_END_OF_STREAM; + } + pos -= m->size; m->delta += m->size; @@ -380,6 +394,22 @@ static int request_parse_arguments_iterator( return MHD_YES; } + if (streq(key, "discrete")) { + if (isempty(value)) { + m->discrete = true; + return MHD_YES; + } + + r = parse_boolean(value); + if (r < 0) { + m->argument_parse_error = r; + return MHD_NO; + } + + m->discrete = r; + return MHD_YES; + } + p = strjoin(key, "=", strempty(value), NULL); if (!p) { m->argument_parse_error = log_oom(); @@ -436,6 +466,14 @@ static int request_handler_entries( if (request_parse_arguments(m, connection) < 0) return respond_error(connection, MHD_HTTP_BAD_REQUEST, "Failed to parse URL arguments.\n"); + if (m->discrete) { + if (!m->cursor) + return respond_error(connection, MHD_HTTP_BAD_REQUEST, "Discrete seeks require a cursor specification.\n"); + + m->n_entries = 1; + m->n_entries_set = true; + } + if (m->cursor) r = sd_journal_seek_cursor(m->journal, m->cursor); else if (m->n_skip >= 0)