-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.c
82 lines (67 loc) · 1.75 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// ui.c
// urchin
//
// Created by Daniel Finneran on 26/04/2018.
// Copyright © 2018 Daniel Finneran. All rights reserved.
//
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "httpd.h"
#include "log.h"
#include "httpui.h"
#include "mem.h"
#include "utils.h"
#include "fork.h"
char *handleGetData(httpRequest *request)
{
char *updateText = NULL;
if (request->URI == NULL) {
updateText = "NULL";
}
char *parse = strdup(request->URI);
char *URI = strtok(parse, "?");
strtok(NULL, "=");
char *query = strtok(NULL, "q");
logInfof("GET request for %s\n", request->URI);
if (stringMatch("/oom", URI)) {
updateText = getMemoryConfiguration();
}
if (stringMatch("/poop", URI)) {
updateText ="poop";
}
if (stringMatch("/mem", URI))
{
if (query) {
char *eptr;
long result = strtol(query, &eptr, 10);
setMem(result);
allocateMemory();
logInfof("Allocating %s bytes of memory\n", query);
updateText = query;
}
}
if (stringMatch("/hostname", URI)) {
updateText = readFile("/etc/hostname");
}
//Process GETs
if (stringMatch("/child", URI)) {
forkSelf(1);
updateText = "BRAAAAAAAAINZ";
}
if (stringMatch("/becomeparent", URI)) {
becomeParent();
}
if (updateText == NULL) {
updateText = "¯\\_(ツ)_/¯";
}
unsigned long newBufferSize = strlen(updateText) + strlen((char *)htmlfiles_index_html);
char buffer[newBufferSize];
sprintf(buffer, (char *)htmlfiles_index_html, updateText );
return strdup(buffer);
}
//char *getResponse(char *uri, char *query)
//{
//
//}