| | | 1 | | #include "report_handler.h" |
| | | 2 | | #include "../../database/cJSON.h" |
| | | 3 | | #include <string.h> |
| | | 4 | | #include <stdlib.h> |
| | | 5 | | #include <stdio.h> |
| | | 6 | | |
| | 2 | 7 | | char *generate_maintenance_xml_report(void) { |
| | 2 | 8 | | char *xml = (char *)malloc(512); |
| | 2 | 9 | | strcpy(xml, "<?xml version=\"1.0\"?><report><maintenance><log>Maintenance Report - All equipment running normally</log |
| | 2 | 10 | | return xml; |
| | | 11 | | } |
| | | 12 | | |
| | 2 | 13 | | char *generate_inventory_xml_report(void) { |
| | 2 | 14 | | char *xml = (char *)malloc(512); |
| | 2 | 15 | | strcpy(xml, "<?xml version=\"1.0\"?><report><inventory><item>Inventory Report - Stock levels normal</item></inventory> |
| | 2 | 16 | | return xml; |
| | | 17 | | } |
| | | 18 | | |
| | 2 | 19 | | void handle_report_request(HttpRequest *req, HttpResponse *res) { |
| | | 20 | | char *xml; |
| | | 21 | | |
| | 2 | 22 | | if (strstr(req->path, "maintenance")) { |
| | 1 | 23 | | xml = generate_maintenance_xml_report(); |
| | | 24 | | } else { |
| | 1 | 25 | | xml = generate_inventory_xml_report(); |
| | | 26 | | } |
| | | 27 | | |
| | 2 | 28 | | res->status_code = 200; |
| | 2 | 29 | | strcpy(res->content_type, "application/xml"); |
| | 2 | 30 | | strncpy(res->body, xml, 8191); |
| | 2 | 31 | | res->body[8191] = '\0'; |
| | 2 | 32 | | free(xml); |
| | 2 | 33 | | } |