2 * Copyright (c) 2022 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef SRC_PLUGINS_HTTP_HTTP_H_
17 #define SRC_PLUGINS_HTTP_HTTP_H_
19 #include <vnet/plugin/plugin.h>
20 #include <vpp/app/version.h>
22 #include <vppinfra/time_range.h>
24 #include <vnet/session/application_interface.h>
25 #include <vnet/session/application.h>
26 #include <http/http_buffer.h>
31 #define HTTP_DBG(_lvl, _fmt, _args...) \
32 if (_lvl <= HTTP_DEBUG) \
33 clib_warning (_fmt, ##_args)
35 #define HTTP_DBG(_lvl, _fmt, _args...)
38 typedef struct http_conn_id_
42 session_handle_t app_session_handle;
43 u32 parent_app_api_ctx;
45 session_handle_t tc_session_handle;
46 u32 parent_app_wrk_index;
49 STATIC_ASSERT (sizeof (http_conn_id_t) <= TRANSPORT_CONN_ID_LEN,
50 "ctx id must be less than TRANSPORT_CONN_ID_LEN");
52 typedef enum http_conn_state_
54 HTTP_CONN_STATE_LISTEN,
55 HTTP_CONN_STATE_CONNECTING,
56 HTTP_CONN_STATE_ESTABLISHED,
57 HTTP_CONN_STATE_TRANSPORT_CLOSED,
58 HTTP_CONN_STATE_APP_CLOSED,
59 HTTP_CONN_STATE_CLOSED
62 typedef enum http_state_
65 HTTP_STATE_WAIT_APP_METHOD,
66 HTTP_STATE_WAIT_CLIENT_METHOD,
67 HTTP_STATE_WAIT_SERVER_REPLY,
68 HTTP_STATE_WAIT_APP_REPLY,
69 HTTP_STATE_CLIENT_IO_MORE_DATA,
70 HTTP_STATE_APP_IO_MORE_DATA,
74 typedef enum http_req_method_
80 typedef enum http_msg_type_
86 #define foreach_http_content_type \
87 _ (APP_7Z, ".7z", "application / x - 7z - compressed") \
88 _ (APP_DOC, ".doc", "application / msword") \
89 _ (APP_DOCX, ".docx", \
90 "application / vnd.openxmlformats - " \
91 "officedocument.wordprocessingml.document") \
92 _ (APP_EPUB, ".epub", "application / epub + zip") \
93 _ (APP_FONT, ".eot", "application / vnd.ms - fontobject") \
94 _ (APP_JAR, ".jar", "application / java - archive") \
95 _ (APP_JSON, ".json", "application / json") \
96 _ (APP_JSON_LD, ".jsonld", "application / ld + json") \
97 _ (APP_MPKG, ".mpkg", "application / vnd.apple.installer + xml") \
98 _ (APP_ODP, ".odp", "application / vnd.oasis.opendocument.presentation") \
99 _ (APP_ODS, ".ods", "application / vnd.oasis.opendocument.spreadsheet") \
100 _ (APP_ODT, ".odt", "application / vnd.oasis.opendocument.text") \
101 _ (APP_OGX, ".ogx", "application / ogg") \
102 _ (APP_PDF, ".pdf", "application / pdf") \
103 _ (APP_PHP, ".php", "application / x - httpd - php") \
104 _ (APP_PPT, ".ppt", "application / vnd.ms - powerpoint") \
105 _ (APP_PPTX, ".pptx", "application / vnd.ms - powerpoint") \
106 _ (APP_RAR, ".rar", "application / vnd.rar") \
107 _ (APP_RTF, ".rtf", "application / rtf") \
108 _ (APP_SH, ".sh", "application / x - sh") \
109 _ (APP_TAR, ".tar", "application / x - tar") \
110 _ (APP_VSD, ".vsd", "application / vnd.visio") \
111 _ (APP_XHTML, ".xhtml", "application / xhtml + xml") \
112 _ (APP_XLS, ".xls", "application / vnd.ms - excel") \
113 _ (APP_XML, ".xml", "application / xml") \
114 _ (APP_XSLX, ".xlsx", \
115 "application / vnd.openxmlformats - officedocument.spreadsheetml.sheet") \
116 _ (APP_XUL, ".xul", "application / vnd.mozilla.xul + xml") \
117 _ (APP_ZIP, ".zip", "application / zip") \
118 _ (AUDIO_AAC, ".aac", "audio / aac") \
119 _ (AUDIO_CD, ".cda", "application / x - cdf") \
120 _ (AUDIO_WAV, ".wav", "audio / wav") \
121 _ (AUDIO_WEBA, ".weba", "audio / webm") \
122 _ (AUDO_MIDI, ".midi", "audio / midi") \
123 _ (AUDO_MID, ".mid", "audo / midi") \
124 _ (AUDO_MP3, ".mp3", "audio / mpeg") \
125 _ (AUDO_OGA, ".oga", "audio / ogg") \
126 _ (AUDO_OPUS, ".opus", "audio / opus") \
127 _ (APP_OCTET_STREAM, ".bin", "application / octet - stream") \
128 _ (BZIP2, ".bz2", "application / x - bzip2") \
129 _ (BZIP, ".bz", "application / x - bzip") \
130 _ (FONT_OTF, ".otf", "font / otf") \
131 _ (FONT_TTF, ".ttf", "font / ttf") \
132 _ (FONT_WOFF2, ".woff2", "font / woff2") \
133 _ (FONT_WOFF, ".woff", "font / woff") \
134 _ (GZIP, ".gz", "application / gzip") \
135 _ (IMAGE_AVIF, ".avif", "image / avif") \
136 _ (IMAGE_BMP, ".bmp", "image / bmp") \
137 _ (IMAGE_GIF, ".gif", "image / gif") \
138 _ (IMAGE_ICON, ".ico", "image / vnd.microsoft.icon") \
139 _ (IMAGE_JPEG, ".jpeg", "image / jpeg") \
140 _ (IMAGE_JPG, ".jpg", "image / jpeg") \
141 _ (IMAGE_PNG, ".png", "image / png") \
142 _ (IMAGE_SVG, ".svg", "image / svg + xml") \
143 _ (IMAGE_TIFF, ".tiff", "image / tiff") \
144 _ (IMAGE_TIF, ".tif", "image / tiff") \
145 _ (IMAGE_WEBP, ".webp", "image / webp") \
146 _ (SCRIPT_CSH, ".csh", "application / x - csh") \
147 _ (TEXT_ABIWORD, ".abw", "application / x - abiword") \
148 _ (TEXT_ARCHIVE, ".arc", "application / x - freearc") \
149 _ (TEXT_AZW, ".azw", "application / vnd.amazon.ebook") \
150 _ (TEXT_CALENDAR, ".ics", "text / calendar") \
151 _ (TEXT_CSS, ".css", "text / css") \
152 _ (TEXT_CSV, ".csv", "text / csv") \
153 _ (TEXT_HTM, ".htm", "text / html") \
154 _ (TEXT_HTML, ".html", "text / html") \
155 _ (TEXT_JS, ".js", "text / javascript") \
156 _ (TEXT_MJS, ".mjs", "text / javascript") \
157 _ (TEXT_PLAIN, ".txt", "text / plain") \
158 _ (VIDEO_3GP2, ".3g2", "video / 3gpp2") \
159 _ (VIDEO_3GP, ".3gp", "video / 3gpp") \
160 _ (VIDEO_AVI, ".avi", "video / x - msvideo") \
161 _ (VIDEO_MP4, ".mp4", "video / mp4") \
162 _ (VIDEO_MPEG, ".mpeg", "video / mpeg") \
163 _ (VIDEO_OGG, ".ogv", "video / ogg") \
164 _ (VIDEO_TS, ".ts", "video / mp2t") \
165 _ (VIDEO_WEBM, ".webm", "video / webm")
167 typedef enum http_content_type_
169 #define _(s, ext, str) HTTP_CONTENT_##s,
170 foreach_http_content_type
172 } http_content_type_t;
174 #define foreach_http_status_code \
175 _ (200, OK, "200 OK") \
176 _ (301, MOVED, "301 Moved Permanently") \
177 _ (400, BAD_REQUEST, "400 Bad Request") \
178 _ (404, NOT_FOUND, "404 Not Found") \
179 _ (405, METHOD_NOT_ALLOWED, "405 Method Not Allowed") \
180 _ (500, INTERNAL_ERROR, "500 Internal Server Error")
182 typedef enum http_status_code_
184 #define _(c, s, str) HTTP_STATUS_##s,
185 foreach_http_status_code
188 } http_status_code_t;
190 typedef enum http_msg_data_type_
192 HTTP_MSG_DATA_INLINE,
194 } http_msg_data_type_t;
196 typedef struct http_msg_data_
198 http_msg_data_type_t type;
203 typedef struct http_msg_
205 http_msg_type_t type;
208 http_req_method_t method_type;
209 http_status_code_t code;
211 http_content_type_t content_type;
212 http_msg_data_t data;
215 typedef struct http_tc_
219 transport_connection_t connection;
220 http_conn_id_t c_http_conn_id;
222 #define h_tc_session_handle c_http_conn_id.tc_session_handle
223 #define h_pa_wrk_index c_http_conn_id.parent_app_wrk_index
224 #define h_pa_session_handle c_http_conn_id.app_session_handle
225 #define h_pa_app_api_ctx c_http_conn_id.parent_app_api_ctx
226 #define h_hc_index connection.c_index
228 http_conn_state_t state;
235 http_state_t http_state;
236 http_req_method_t method;
239 http_buffer_t tx_buf;
244 typedef struct http_worker_
246 http_conn_t *conn_pool;
249 typedef struct http_main_
252 http_conn_t *listener_pool;
255 clib_timebase_t timebase;
271 http_state_is_tx_valid (http_conn_t *hc)
273 http_state_t state = hc->http_state;
274 return (state == HTTP_STATE_APP_IO_MORE_DATA ||
275 state == HTTP_STATE_CLIENT_IO_MORE_DATA ||
276 state == HTTP_STATE_WAIT_APP_REPLY ||
277 state == HTTP_STATE_WAIT_APP_METHOD);
280 #endif /* SRC_PLUGINS_HTTP_HTTP_H_ */
283 * fd.io coding-style-patch-verification: ON
286 * eval: (c-set-style "gnu")