From 2ab8489e1b0550bb5c8db8b2e212b62a4e2682fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 21 Jul 2013 08:26:25 +0200 Subject: [PATCH] archive: added report.c --- htdocs/archive/report.c | 95 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 htdocs/archive/report.c diff --git a/htdocs/archive/report.c b/htdocs/archive/report.c new file mode 100644 index 000000000..5a6a63fbd --- /dev/null +++ b/htdocs/archive/report.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include + +#include "webarchive.h" + +#define MAX_RECORDS 1000 + +void listAll(char **data) +{ + puts("Content-type: text/html\r\n\r\n"); + puts(""); + puts(""); + puts(""); + puts(""); + puts(""); + puts(""); + puts("
"); + for (int i = 0; i < MAX_RECORDS && data[i]; i++) { + const char *name = getname(data[i]); + int version = getversion(data[i]); + if (version < 0) + version = time(0); + if (i > 0) + printf(""); + printf("", name); + printf("", name, version); + printf("\n"); + } + puts("
%s", name, version); + printf("", name, version); + printf(" 
"); + puts(""); +} + +void listOne(char **data, const char name[]) +{ + int index = -1; + for (int i = 0; i < MAX_RECORDS && data[i]; i++) { + if (strcmp(getname(data[i]), name)==0) { + index = i; + break; + } + } + + puts("Content-type: text/plain\r\n\r\n"); + puts((index == -1) ? "Not found" : data[index]); +} + +int main() +{ + char *data[MAX_RECORDS] = {0}; + + // read + if (!readdata(data, MAX_RECORDS)) { + puts("Content-type: text/html\r\n\r\n"); + puts("Internal error: failed to load data"); + return 0; + } + + // sort + sortdata(data,MAX_RECORDS); + + const char *query_string = getenv("QUERY_STRING"); + if (query_string == NULL || *query_string == '\0') { + listAll(data); + } else if (strncmp(query_string, "name=", 5) == 0 && getname(query_string) != NULL) { + char name[32] = {0}; + strcpy(name, getname(query_string)); + listOne(data,name); + } else { + puts("Content-type: text/plain\r\n\r\n"); + puts("Invalid query"); + } + + return 0; +}