Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_dynamic_multipart.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Pharos-owned multipart form-data parsing for in-process dynamic handling.
4 *
5 * Provides boundary extraction, part lookup, filename extraction, and
6 * file-part extraction so that the dynamic runtime can process multipart
7 * uploads without delegating to a child process or relying on app-owned
8 * shell logic.
9 */
10
11#ifndef PHAROS_NATIVE_DYNAMIC_MULTIPART_H
12#define PHAROS_NATIVE_DYNAMIC_MULTIPART_H
13
14#include <stddef.h>
15
16/** @name Boundary extraction
17 * @{
18 */
19
20/**
21 * @brief Extracts the MIME boundary string from a Content-Type header.
22 *
23 * @param content_type The full Content-Type header value.
24 * @return Newly allocated boundary string (without the leading @c -- ),
25 * or NULL when the boundary cannot be determined.
26 * Caller must free.
27 */
28char *native_dynamic_multipart_boundary(const char *content_type);
29
30/** @} */
31
32/** @name Part lookup
33 * @{
34 */
35
36/**
37 * @brief Finds a named part in a multipart request body.
38 *
39 * Searches @p body for a part whose Content-Disposition name matches
40 * @p field_name. When found, optionally returns the text content,
41 * the uploaded filename, and/or the raw content range within @p body.
42 *
43 * @param body Raw multipart body bytes.
44 * @param body_len Byte length of @p body.
45 * @param content_type The full Content-Type header (must contain the boundary).
46 * @param field_name The form field name to locate.
47 * @param out_text Receives a NUL-terminated copy of the part content
48 * (may be NULL to skip).
49 * @param out_filename Receives the uploaded filename (may be NULL to skip).
50 * @param out_content_start Receives a pointer into @p body at the content start
51 * (may be NULL to skip).
52 * @param out_content_len Receives the content byte length (may be NULL to skip).
53 * @return 1 when a matching part was found, 0 otherwise.
54 */
56 const unsigned char *body,
57 size_t body_len,
58 const char *content_type,
59 const char *field_name,
60 char **out_text,
61 char **out_filename,
62 const unsigned char **out_content_start,
63 size_t *out_content_len
64);
65
66/** @} */
67
68/** @name Filename extraction
69 * @{
70 */
71
72/**
73 * @brief Extracts the uploaded filename for a named multipart file part.
74 *
75 * @param body Raw multipart body bytes.
76 * @param body_len Byte length of @p body.
77 * @param content_type The full Content-Type header.
78 * @param field_name The form field name of the file input.
79 * @return Newly allocated filename string, or NULL when not found.
80 * Caller must free.
81 */
83 const unsigned char *body,
84 size_t body_len,
85 const char *content_type,
86 const char *field_name
87);
88
89/** @} */
90
91/** @name Text extraction
92 * @{
93 */
94
95/**
96 * @brief Extracts a text value from a multipart form field.
97 *
98 * @param body Raw multipart body bytes.
99 * @param body_len Byte length of @p body.
100 * @param content_type The full Content-Type header.
101 * @param field_name The form field name to extract.
102 * @return Newly allocated text value, or NULL when not found.
103 * Caller must free.
104 */
106 const unsigned char *body,
107 size_t body_len,
108 const char *content_type,
109 const char *field_name
110);
111
112/** @} */
113
114/** @name File extraction
115 * @{
116 */
117
118/**
119 * @brief Extracts file content from a multipart file part and writes it to disk.
120 *
121 * @param body Raw multipart body bytes.
122 * @param body_len Byte length of @p body.
123 * @param content_type The full Content-Type header.
124 * @param field_name The form field name of the file input.
125 * @param output_path Destination file path on disk.
126 * @return 0 on success, non-zero on failure.
127 */
129 const unsigned char *body,
130 size_t body_len,
131 const char *content_type,
132 const char *field_name,
133 const char *output_path
134);
135
136/** @} */
137
138#endif
int native_dynamic_multipart_extract_file(const unsigned char *body, size_t body_len, const char *content_type, const char *field_name, const char *output_path)
Extracts file content from a multipart file part and writes it to disk.
char * native_dynamic_multipart_extract_text(const unsigned char *body, size_t body_len, const char *content_type, const char *field_name)
Extracts a text value from a multipart form field.
int native_dynamic_multipart_find_part(const unsigned char *body, size_t body_len, const char *content_type, const char *field_name, char **out_text, char **out_filename, const unsigned char **out_content_start, size_t *out_content_len)
Finds a named part in a multipart request body.
char * native_dynamic_multipart_boundary(const char *content_type)
Extracts the MIME boundary string from a Content-Type header.
char * native_dynamic_multipart_filename(const unsigned char *body, size_t body_len, const char *content_type, const char *field_name)
Extracts the uploaded filename for a named multipart file part.