Seregon/zftpd

Zero-copy FTP/HTTP Daemon compatible with all POSIX systems

C/11.0 KB/No license
include/http_parser.h
zftpd / include / http_parser.h
1/*
2MIT License
3 
4Copyright (c) 2026 Seregon
5 
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12 
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15 
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
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 
36typedef enum {
37 HTTP_METHOD_GET,
38 HTTP_METHOD_POST,
39 HTTP_METHOD_HEAD,
40 HTTP_METHOD_UNKNOWN,
41} http_method_t;
42 
43typedef struct {
44 char *name;
45 char *value;
46} http_header_t;
47 
48typedef 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 
59int http_parse_request(char *buffer, size_t length, http_request_t *request);
60const char* http_get_header(const http_request_t *request, const char *name);
61 
62#endif /* HTTP_PARSER_H */
63