From bbb018471f7a90aa63fec627bb070dbe286cfe8a Mon Sep 17 00:00:00 2001 From: Micah Moore Date: Mon, 5 Dec 2022 18:37:33 -0500 Subject: [PATCH] added val_api_url and updated handle_api --- src/http.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/http.c b/src/http.c index 2c08fae..ce76933 100644 --- a/src/http.c +++ b/src/http.c @@ -326,10 +326,48 @@ out: return success; } + +static int val_api_url(struct http_transaction *ta) { + char *req_path = bufio_offset2ptr(ta->client->bufio, ta->req_path); + if (!strcmp(req_path, "/api/login")) { + return 0; + } + if (!strcmp(req_path, "/api/video")) { + return 1; + } + return -1; + +} static bool handle_api(struct http_transaction *ta) { - return send_error(ta, HTTP_NOT_FOUND, "API not implemented"); + int val = val_api_url(ta); + + if (val == -1){ + return send_not_found(ta); + } + + http_add_header(&ta->resp_headers, "Accept-Ranges", "bytes"); + if (val == 0) { + if (ta->req_method == HTTP_POST) { + // Handle login post + } + + else if (ta->req_method == HTTP_GET){ + // Handle login get + } + + else{ + return send_error(ta, HTTP_METHOD_NOT_ALLOWED, "Unknown method.\n"); + } + + } + else { + // Handle video api + } + + return false; + } /* Set up an http client, associating it with a bufio buffer. */