Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | /* |
| 2 | MIT License |
| 3 | |
| 4 | Copyright (c) 2026 Seregon |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | of this software and associated documentation files (the "Software"), to deal |
| 8 | in the Software without restriction, including without limitation the rights |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | copies of the Software, and to permit persons to whom the Software is |
| 11 | furnished to do so, subject to the following conditions: |
| 12 | |
| 13 | The above copyright notice and this permission notice shall be included in all |
| 14 | copies or substantial portions of the Software. |
| 15 | |
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * @file http_parser.h |
| 27 | * @brief Minimal HTTP/1.1 parser |
| 28 | */ |
| 29 | |
| 30 | #ifndef HTTP_PARSER_H |
| 31 | #define HTTP_PARSER_H |
| 32 | |
| 33 | #include "http_config.h" |
| 34 | #include <stddef.h> |
| 35 | |
| 36 | typedef enum { |
| 37 | HTTP_METHOD_GET, |
| 38 | HTTP_METHOD_POST, |
| 39 | HTTP_METHOD_HEAD, |
| 40 | HTTP_METHOD_UNKNOWN, |
| 41 | } http_method_t; |
| 42 | |
| 43 | typedef struct { |
| 44 | char *name; |
| 45 | char *value; |
| 46 | } http_header_t; |
| 47 | |
| 48 | typedef struct { |
| 49 | http_method_t method; |
| 50 | char uri[HTTP_URI_MAX_LENGTH]; |
| 51 | int version_major; |
| 52 | int version_minor; |
| 53 | http_header_t headers[HTTP_HEADER_MAX_COUNT]; |
| 54 | size_t num_headers; |
| 55 | char *body; |
| 56 | size_t body_length; |
| 57 | } http_request_t; |
| 58 | |
| 59 | int http_parse_request(char *buffer, size_t length, http_request_t *request); |
| 60 | const char* http_get_header(const http_request_t *request, const char *name); |
| 61 | |
| 62 | #endif /* HTTP_PARSER_H */ |
| 63 |