- int len = sprintf(response, "Content-type: text/plain\n\nYou requested %s using GET\n", request);
- write(sfd, response, len);
+ char response[BUFSIZ];
+ int len = 0;
+ // TODO: Magical low level interfacing stuff!
+ if (strcmp("/sensor", request) == 0) // dummy test
+ {
+ len = sprintf(response, "SENSOR OFFLINE\n");
+ }
+ else
+ {
+ FILE * f = fopen(request+1, "r");
+ if (f == NULL)
+ {
+ log_print(LOGWARN, "Get", "File \"%s\" doesn't exist", request+1);
+ len = sprintf(response, "You requested \"%s\" using GET\n", request);
+ }
+ else
+ {
+ while (fgets(response, sizeof(response), f) != NULL)
+ {
+ write(sfd, response, strlen(response));
+ }
+ }
+ }
+ if (len > 0)
+ write(sfd, response, len);