diff --git a/src/ServerController.c b/src/ServerController.c index 8eb62f3..0d010bf 100644 --- a/src/ServerController.c +++ b/src/ServerController.c @@ -114,7 +114,7 @@ void updateUtilization(){ } enum MHD_Result sendPage(struct MHD_Connection *connection, char* page, char *mimetype){ - struct MHD_Response *response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_PERSISTENT); + struct MHD_Response *response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_MUST_COPY); MHD_add_response_header(response, "Content-Type", mimetype); MHD_add_response_header(response, "Access-Control-Allow-Origin", "*"); enum MHD_Result result = MHD_queue_response(connection, MHD_HTTP_OK, response); @@ -123,27 +123,24 @@ enum MHD_Result sendPage(struct MHD_Connection *connection, char* page, char *mi } int answerConnection(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadDataSize, void **con_ls){ - if (strcmp(url, "/server") == 0){ - cJSON *response = cJSON_CreateObject(); - cJSON_AddStringToObject(response, "uptime", uptime); - cJSON_AddNumberToObject(response, "cpuCount", coreCount); - for (short int i = 0; i < coreCount + 1; i++){ - char *buf = malloc(32); - sprintf(buf, "cpu%i", i); - cJSON_AddNumberToObject(response, buf, (int) (cpuUtilization[i] + 0.5)); - free(buf); - } - cJSON_AddNumberToObject(response, "totalRam", maxRam); - cJSON_AddNumberToObject(response, "usedRam", usedRam); - cJSON_AddNumberToObject(response, "totalSwap", maxSwap); - cJSON_AddNumberToObject(response, "usedSwap", usedSwap); - - enum MHD_Result result = sendPage(connection, cJSON_Print(response), "application/json"); - - cJSON_Delete(response); - return result; + cJSON *response = cJSON_CreateObject(); + cJSON_AddStringToObject(response, "uptime", uptime); + cJSON_AddNumberToObject(response, "cpuCount", coreCount); + for (short int i = 0; i < coreCount + 1; i++){ + char *buf = malloc(32); + sprintf(buf, "cpu%i", i); + cJSON_AddNumberToObject(response, buf, (int) (cpuUtilization[i] + 0.5)); + free(buf); } - return MHD_NO; + cJSON_AddNumberToObject(response, "totalRam", maxRam); + cJSON_AddNumberToObject(response, "usedRam", usedRam); + cJSON_AddNumberToObject(response, "totalSwap", maxSwap); + cJSON_AddNumberToObject(response, "usedSwap", usedSwap); + + enum MHD_Result result = sendPage(connection, cJSON_Print(response), "application/json"); + + cJSON_Delete(response); + return result; } void readConfig(){