vcl session: switch to generic cert key apis
[vpp.git] / src / plugins / http_static / http_static.h
1
2 /*
3  * http_static.h - skeleton vpp engine plug-in header file
4  *
5  * Copyright (c) <current-year> <your-organization>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_http_static_h__
19 #define __included_http_static_h__
20
21 #include <vnet/vnet.h>
22 #include <vnet/session/application.h>
23 #include <vnet/session/application_interface.h>
24 #include <vnet/session/session.h>
25 #include <vnet/ip/ip.h>
26 #include <vnet/ethernet/ethernet.h>
27
28 #include <vppinfra/hash.h>
29 #include <vppinfra/error.h>
30 #include <vppinfra/time_range.h>
31 #include <vppinfra/tw_timer_2t_1w_2048sl.h>
32 #include <vppinfra/bihash_vec8_8.h>
33
34 /** @file http_static.h
35  * Static http server definitions
36  */
37
38 typedef struct
39 {
40   /* API message ID base */
41   u16 msg_id_base;
42
43   /* convenience */
44   vlib_main_t *vlib_main;
45   vnet_main_t *vnet_main;
46 } http_static_main_t;
47
48 extern http_static_main_t http_static_main;
49
50 /** \brief Session States
51  */
52
53 typedef enum
54 {
55   /** Session is closed */
56   HTTP_STATE_CLOSED,
57   /** Session is established */
58   HTTP_STATE_ESTABLISHED,
59   /** Session has sent an OK response */
60   HTTP_STATE_OK_SENT,
61   /** Session has sent an HTML response */
62   HTTP_STATE_SEND_MORE_DATA,
63   /** Number of states */
64   HTTP_STATE_N_STATES,
65 } http_session_state_t;
66
67 typedef enum
68 {
69   CALLED_FROM_RX,
70   CALLED_FROM_TX,
71   CALLED_FROM_TIMER,
72 } http_state_machine_called_from_t;
73
74 typedef enum
75 {
76   HTTP_BUILTIN_METHOD_GET = 0,
77   HTTP_BUILTIN_METHOD_POST,
78 } http_builtin_method_type_t;
79
80
81 /** \brief Application session
82  */
83 typedef struct
84 {
85   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
86   /** Base class instance variables */
87 #define _(type, name) type name;
88   foreach_app_session_field
89 #undef _
90   /** rx thread index */
91   u32 thread_index;
92   /** rx buffer */
93   u8 *rx_buf;
94   /** vpp session index, handle */
95   u32 vpp_session_index;
96   u64 vpp_session_handle;
97   /** Timeout timer handle */
98   u32 timer_handle;
99   /** Fully-resolved file path */
100   u8 *path;
101   /** File data, a vector */
102   u8 *data;
103   /** Current data send offset */
104   u32 data_offset;
105   /** Need to free data in detach_cache_entry */
106   int free_data;
107
108   /** File cache pool index */
109   u32 cache_pool_index;
110   /** state machine called from... */
111   http_state_machine_called_from_t called_from;
112 } http_session_t;
113
114 /** \brief In-memory file data cache entry
115  */
116 typedef struct
117 {
118   /** Name of the file */
119   u8 *filename;
120   /** Contents of the file, as a u8 * vector */
121   u8 *data;
122   /** Last time the cache entry was used */
123   f64 last_used;
124   /** Cache LRU links */
125   u32 next_index;
126   u32 prev_index;
127   /** Reference count, so we don't recycle while referenced */
128   int inuse;
129 } file_data_cache_t;
130
131 /** \brief Main data structure
132  */
133
134 typedef struct
135 {
136   /** Per thread vector of session pools */
137   http_session_t **sessions;
138   /** Session pool reader writer lock */
139   clib_rwlock_t sessions_lock;
140   /** vpp session to http session index map */
141   u32 **session_to_http_session;
142
143   /** Enable debug messages */
144   int debug_level;
145
146   /** vpp message/event queue */
147   svm_msg_q_t **vpp_queue;
148
149   /** Unified file data cache pool */
150   file_data_cache_t *cache_pool;
151   /** Hash table which maps file name to file data */
152     BVT (clib_bihash) name_to_data;
153
154   /** Hash tables for built-in GET and POST handlers */
155   uword *get_url_handlers;
156   uword *post_url_handlers;
157
158   /** Current cache size */
159   u64 cache_size;
160   /** Max cache size in bytes */
161   u64 cache_limit;
162   /** Number of cache evictions */
163   u64 cache_evictions;
164
165   /** Cache LRU listheads */
166   u32 first_index;
167   u32 last_index;
168
169   /** root path to be served */
170   u8 *www_root;
171
172   /** Server's event queue */
173   svm_queue_t *vl_input_queue;
174
175   /** API client handle */
176   u32 my_client_index;
177
178   /** Application index */
179   u32 app_index;
180
181   /** Process node index for event scheduling */
182   u32 node_index;
183
184   /** Cert and key pair for tls */
185   u32 ckpair_index;
186
187   /** Session cleanup timer wheel */
188   tw_timer_wheel_2t_1w_2048sl_t tw;
189   clib_spinlock_t tw_lock;
190
191   /** Time base, so we can generate browser cache control http spew */
192   clib_timebase_t timebase;
193
194   /** Number of preallocated fifos, usually 0 */
195   u32 prealloc_fifos;
196   /** Private segment size, usually 0 */
197   u32 private_segment_size;
198   /** Size of the allocated rx, tx fifos, roughly 8K or so */
199   u32 fifo_size;
200   /** The bind URI, defaults to tcp://0.0.0.0/80 */
201   u8 *uri;
202   vlib_main_t *vlib_main;
203 } http_static_server_main_t;
204
205 extern http_static_server_main_t http_static_server_main;
206
207 int http_static_server_enable_api (u32 fifo_size, u32 cache_limit,
208                                    u32 prealloc_fifos,
209                                    u32 private_segment_size,
210                                    u8 * www_root, u8 * uri);
211
212 void http_static_server_register_builtin_handler
213   (void *fp, char *url, int type);
214
215 #endif /* __included_http_static_h__ */
216
217 /*
218  * fd.io coding-style-patch-verification: ON
219  *
220  * Local Variables:
221  * eval: (c-set-style "gnu")
222  * End:
223  */