2 * Copyright (c) 2017-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.
15 #ifndef __included_http_static_h__
16 #define __included_http_static_h__
18 #include <vnet/session/application_interface.h>
19 #include <vnet/session/session.h>
20 #include <http/http.h>
22 #include <vppinfra/hash.h>
23 #include <vppinfra/error.h>
24 #include <http_static/http_cache.h>
26 /** @file http_static.h
27 * Static http server definitions
30 /** \brief Application session
34 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
36 /** rx thread index */
38 /** vpp session index, handle */
39 u32 vpp_session_index;
40 session_handle_t vpp_session_handle;
41 /** Fully-resolved file path */
47 /** Current data send offset */
49 /** Need to free data in detach_cache_entry */
51 /** File cache pool index */
53 /** Content type, e.g. text, text/javascript, etc. */
54 http_content_type_t content_type;
57 typedef struct hss_session_handle_
68 } hss_session_handle_t;
70 STATIC_ASSERT_SIZEOF (hss_session_handle_t, sizeof (u64));
73 typedef struct hss_url_handler_args_
75 hss_session_handle_t sh;
83 http_req_method_t reqtype;
92 http_status_code_t sc;
95 } hss_url_handler_args_t;
97 typedef enum hss_url_handler_rc_
100 HSS_URL_HANDLER_ERROR,
101 HSS_URL_HANDLER_ASYNC,
102 } hss_url_handler_rc_t;
104 typedef hss_url_handler_rc_t (*hss_url_handler_fn) (hss_url_handler_args_t *);
105 typedef void (*hss_register_url_fn) (hss_url_handler_fn, char *, int);
106 typedef void (*hss_session_send_fn) (hss_url_handler_args_t *args);
108 /** \brief Main data structure
112 /** Per thread vector of session pools */
113 hss_session_t **sessions;
115 /** Hash tables for built-in GET and POST handlers */
116 uword *get_url_handlers;
117 uword *post_url_handlers;
121 /** root path to be served */
124 /** Application index */
127 /** Cert and key pair for tls */
130 /* API message ID base */
133 vlib_main_t *vlib_main;
139 /** Enable debug messages */
141 /** Number of preallocated fifos, usually 0 */
143 /** Private segment size, usually 0 */
144 u64 private_segment_size;
145 /** Size of the allocated rx, tx fifos, roughly 8K or so */
147 /** The bind URI, defaults to tcp://0.0.0.0/80 */
149 /** Threshold for switching to ptr data in http msgs */
151 /** Enable the use of builtinurls */
152 u8 enable_url_handlers;
153 /** Max cache size before LRU occurs */
156 /** hash table of file extensions to mime types string indices */
157 uword *mime_type_indices_by_file_extensions;
160 extern hss_main_t hss_main;
162 int hss_create (vlib_main_t *vm);
165 * Register a GET or POST URL handler
167 void hss_register_url_handler (hss_url_handler_fn fp, const char *url,
168 http_req_method_t type);
169 void hss_session_send_data (hss_url_handler_args_t *args);
170 void hss_builtinurl_json_handlers_init (void);
171 hss_session_t *hss_session_get (u32 thread_index, u32 hs_index);
173 #endif /* __included_http_static_h__ */
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")