hs-test: more debug output in http3 test
[vpp.git] / src / plugins / http_static / http_static.h
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 #ifndef __included_http_static_h__
16 #define __included_http_static_h__
17
18 #include <vnet/session/application_interface.h>
19 #include <vnet/session/session.h>
20 #include <http/http.h>
21
22 #include <vppinfra/hash.h>
23 #include <vppinfra/error.h>
24 #include <http_static/http_cache.h>
25
26 /** @file http_static.h
27  * Static http server definitions
28  */
29
30 /** \brief Application session
31  */
32 typedef struct
33 {
34   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
35   u32 session_index;
36   /** rx thread index */
37   u32 thread_index;
38   /** vpp session index, handle */
39   u32 vpp_session_index;
40   session_handle_t vpp_session_handle;
41   /** Fully-resolved file path */
42   u8 *path;
43   /** Data to send */
44   u8 *data;
45   /** Data length */
46   u64 data_len;
47   /** Current data send offset */
48   u32 data_offset;
49   /** Need to free data in detach_cache_entry */
50   int free_data;
51   /** File cache pool index */
52   u32 cache_pool_index;
53   /** Content type, e.g. text, text/javascript, etc. */
54   http_content_type_t content_type;
55 } hss_session_t;
56
57 typedef struct hss_session_handle_
58 {
59   union
60   {
61     struct
62     {
63       u32 session_index;
64       u32 thread_index;
65     };
66     u64 as_u64;
67   };
68 } hss_session_handle_t;
69
70 STATIC_ASSERT_SIZEOF (hss_session_handle_t, sizeof (u64));
71
72
73 typedef struct hss_url_handler_args_
74 {
75   hss_session_handle_t sh;
76
77   union
78   {
79     /* Request args */
80     struct
81     {
82       u8 *request;
83       http_req_method_t reqtype;
84     };
85
86     /* Reply args */
87     struct
88     {
89       u8 *data;
90       uword data_len;
91       u8 free_vec_data;
92       http_status_code_t sc;
93     };
94   };
95 } hss_url_handler_args_t;
96
97 typedef enum hss_url_handler_rc_
98 {
99   HSS_URL_HANDLER_OK,
100   HSS_URL_HANDLER_ERROR,
101   HSS_URL_HANDLER_ASYNC,
102 } hss_url_handler_rc_t;
103
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);
107
108 /** \brief Main data structure
109  */
110 typedef struct
111 {
112   /** Per thread vector of session pools */
113   hss_session_t **sessions;
114
115   /** Hash tables for built-in GET and POST handlers */
116   uword *get_url_handlers;
117   uword *post_url_handlers;
118
119   hss_cache_t cache;
120
121   /** root path to be served */
122   u8 *www_root;
123
124   /** Application index */
125   u32 app_index;
126
127   /** Cert and key pair for tls */
128   u32 ckpair_index;
129
130   /* API message ID base */
131   u16 msg_id_base;
132
133   vlib_main_t *vlib_main;
134
135   /*
136    * Config
137    */
138
139   /** Enable debug messages */
140   int debug_level;
141   /** Number of preallocated fifos, usually 0 */
142   u32 prealloc_fifos;
143   /** Private segment size, usually 0 */
144   u64 private_segment_size;
145   /** Size of the allocated rx, tx fifos, roughly 8K or so */
146   u32 fifo_size;
147   /** The bind URI, defaults to tcp://0.0.0.0/80 */
148   u8 *uri;
149   /** Threshold for switching to ptr data in http msgs */
150   u64 use_ptr_thresh;
151   /** Enable the use of builtinurls */
152   u8 enable_url_handlers;
153   /** Max cache size before LRU occurs */
154   u64 cache_size;
155
156   /** hash table of file extensions to mime types string indices */
157   uword *mime_type_indices_by_file_extensions;
158 } hss_main_t;
159
160 extern hss_main_t hss_main;
161
162 int hss_create (vlib_main_t *vm);
163
164 /**
165  * Register a GET or POST URL handler
166  */
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);
172
173 #endif /* __included_http_static_h__ */
174
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */