diff options
| author | amelia squires <[email protected]> | 2024-08-26 12:41:30 -0500 |
|---|---|---|
| committer | amelia squires <[email protected]> | 2024-08-26 12:42:47 -0500 |
| commit | 90c4b7dcbc57d2f86a77c997069d96158d54ca55 (patch) | |
| tree | 408852199d1e7cd5cfc628319671622ab8f51558 /src/net/util.h | |
| parent | bf97d851115e5d5cae7ad80131e3726b3eef5b2d (diff) | |
sort networking code
Diffstat (limited to 'src/net/util.h')
| -rw-r--r-- | src/net/util.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/net/util.h b/src/net/util.h new file mode 100644 index 0000000..d723b6f --- /dev/null +++ b/src/net/util.h @@ -0,0 +1,47 @@ +#include "common.h" + +/** + * @brief calls recv into buffer until everything is read + * + * buffer is allocated in BUFFER_SIZE chunks + * + * @param {int} fd of the connection + * @param {char**} pointer to a unallocated buffer + * @param {int*} pointer to an int, will be where the header ends + * @return {int64_t} bytes read, -1 if the body was damaged, -2 if the header was +*/ +int64_t recv_full_buffer(int client_fd, char** _buffer, int* header_eof, int* state); + +/** + * @brief converts the request buffer into a parray_t + * + * @param {char*} request buffer + * @param {int} where the header ends + * @param {parray_t**} pointer to a unallocated parray_t + * @return {int} returns 0 or -1 on failure +*/ +int parse_header(char* buffer, int header_eof, parray_t** _table); + +/** + * @brief contructs an http request + * + * @param {str**} pointer to an unallocated destination string + * @param {int} response code + * @param {char*} string representation of the response code + * @param {char*} all other header values + * @param {char*} response content + * @param {size_t} content length +*/ +void http_build(str** _dest, int code, char* code_det, char* header_vs, char* content, size_t len); + +/** + * @brief gets a string representation of a http code + * + * @param {int} http response code + * @param {char*} allocated destination string +*/ +void http_code(int code, char* code_det); + +void client_fd_errors(int client_fd); + +int content_disposition(str* src, parray_t** _dest); |
