/* SPDX-License-Identifier: GPL-3.0-or-later */ /* Copyright 2022 Ivan Polyakov */ #include "request.h" #include #include void rpd_req_init(rpd_req *dest) { dest->method = GET; rpd_keyval_init(&dest->headers, 0); rpd_keyval_init(&dest->query, 0); rpd_keyval_init(&dest->params, 0); dest->path.parts_len = 0; dest->path.parts = NULL; dest->body = NULL; } enum rpd_req_methods rpd_req_smethod(const char *method) { if (!strcmp(method, "GET")) return GET; else if (!strcmp(method, "HEAD")) return HEAD; else if (!strcmp(method, "POST")) return POST; else if (!strcmp(method, "PUT")) return PUT; else if (!strcmp(method, "PATCH")) return PATCH; else if (!strcmp(method, "DELETE")) return DELETE; else if (!strcmp(method, "CONNECT")) return CONNECT; else if (!strcmp(method, "OPTIONS")) return OPTIONS; else if (!strcmp(method, "TRACE")) return TRACE; return UNKNOWN; } void rpd_req_cleanup(rpd_req *req) { if (req->body) { free(req->body); req->body = NULL; } rpd_url_cleanup(&req->path); rpd_keyval_cleanup(&req->headers); rpd_keyval_cleanup(&req->query); rpd_keyval_cleanup(&req->params); } void rpd_req_free(rpd_req *req) { rpd_req_cleanup(req); rpd_keyval_free(&req->headers); rpd_keyval_free(&req->query); rpd_keyval_free(&req->params); }