http_static: code cleanup
[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 <vppinfra/bihash_vec8_8.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   /** File data, a vector */
44   u8 *data;
45   /** Current data send offset */
46   u32 data_offset;
47   /** Need to free data in detach_cache_entry */
48   int free_data;
49   /** File cache pool index */
50   u32 cache_pool_index;
51 } hss_session_t;
52
53 /** \brief In-memory file data cache entry
54  */
55 typedef struct
56 {
57   /** Name of the file */
58   u8 *filename;
59   /** Contents of the file, as a u8 * vector */
60   u8 *data;
61   /** Last time the cache entry was used */
62   f64 last_used;
63   /** Cache LRU links */
64   u32 next_index;
65   u32 prev_index;
66   /** Reference count, so we don't recycle while referenced */
67   int inuse;
68 } hss_cache_entry_t;
69
70 /** \brief Main data structure
71  */
72
73 typedef struct
74 {
75   /** Per thread vector of session pools */
76   hss_session_t **sessions;
77   /** Session pool reader writer lock */
78   clib_spinlock_t cache_lock;
79
80   /** Unified file data cache pool */
81   hss_cache_entry_t *cache_pool;
82   /** Hash table which maps file name to file data */
83     BVT (clib_bihash) name_to_data;
84
85   /** Hash tables for built-in GET and POST handlers */
86   uword *get_url_handlers;
87   uword *post_url_handlers;
88
89   /** Current cache size */
90   u64 cache_size;
91   /** Max cache size in bytes */
92   u64 cache_limit;
93   /** Number of cache evictions */
94   u64 cache_evictions;
95
96   /** Cache LRU listheads */
97   u32 first_index;
98   u32 last_index;
99
100   /** root path to be served */
101   u8 *www_root;
102
103   /** Application index */
104   u32 app_index;
105
106   /** Cert and key pair for tls */
107   u32 ckpair_index;
108
109   /* API message ID base */
110   u16 msg_id_base;
111
112   vlib_main_t *vlib_main;
113
114   /*
115    * Config
116    */
117
118   /** Enable debug messages */
119   int debug_level;
120   /** Number of preallocated fifos, usually 0 */
121   u32 prealloc_fifos;
122   /** Private segment size, usually 0 */
123   u64 private_segment_size;
124   /** Size of the allocated rx, tx fifos, roughly 8K or so */
125   u32 fifo_size;
126   /** The bind URI, defaults to tcp://0.0.0.0/80 */
127   u8 *uri;
128   /** Threshold for switching to ptr data in http msgs */
129   u32 use_ptr_thresh;
130 } hss_main_t;
131
132 extern hss_main_t hss_main;
133
134 int hss_create (vlib_main_t *vm);
135
136 void http_static_server_register_builtin_handler (void *fp, char *url,
137                                                   http_req_method_t type);
138
139 #endif /* __included_http_static_h__ */
140
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "gnu")
146  * End:
147  */