FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
http_static.c
Go to the documentation of this file.
1 /*
2  * http_static.c - skeleton vpp engine plug-in
3  *
4  * Copyright (c) <current-year> <your-organization>
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25 
26 /* define message IDs */
28 
29 #include <vpp/api/types.h>
30 
31 /* define message structures */
32 #define vl_typedefs
34 #undef vl_typedefs
35 
36 /* define generated endian-swappers */
37 #define vl_endianfun
39 #undef vl_endianfun
40 
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
43 #define vl_printfun
45 #undef vl_printfun
46 
47 /* Get the API version number */
48 #define vl_api_version(n,v) static u32 api_version=(v);
50 #undef vl_api_version
51 
52 #define REPLY_MSG_ID_BASE hmp->msg_id_base
54 
56 
57 /* List of message types that this plugin understands */
58 
59 #define foreach_http_static_plugin_api_msg \
60 _(HTTP_STATIC_ENABLE, http_static_enable)
61 
62 /* API message handler */
65 {
66  vl_api_http_static_enable_reply_t *rmp;
68  int rv;
69 
70  mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
71  mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
72 
74  (ntohl (mp->fifo_size),
75  ntohl (mp->cache_size_limit),
76  ntohl (mp->prealloc_fifos),
77  ntohl (mp->private_segment_size), mp->www_root, mp->uri);
78 
79  REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_REPLY);
80 }
81 
82 /* Set up the API message handling tables */
83 static clib_error_t *
85 {
87 #define _(N,n) \
88  vl_msg_api_set_handlers((VL_API_##N + hmp->msg_id_base), \
89  #n, \
90  vl_api_##n##_t_handler, \
91  vl_noop_handler, \
92  vl_api_##n##_t_endian, \
93  vl_api_##n##_t_print, \
94  sizeof(vl_api_##n##_t), 1);
96 #undef _
97 
98  return 0;
99 }
100 
101 #define vl_msg_name_crc_list
103 #undef vl_msg_name_crc_list
104 
105 static void
107 {
108 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + hmp->msg_id_base);
109  foreach_vl_msg_name_crc_http_static;
110 #undef _
111 }
112 
113 static clib_error_t *
115 {
117  clib_error_t *error = 0;
118  u8 *name;
119 
120  hmp->vlib_main = vm;
121  hmp->vnet_main = vnet_get_main ();
122 
123  name = format (0, "http_static_%08x%c", api_version, 0);
124 
125  /* Ask for a correctly-sized block of API message decode slots */
127  ((char *) name, VL_MSG_FIRST_AVAILABLE);
128 
129  error = http_static_plugin_api_hookup (vm);
130 
131  /* Add our API messages to the global name_crc hash table */
133 
134  vec_free (name);
135 
136  return error;
137 }
138 
140 
141 /* *INDENT-OFF* */
143 {
144  .version = VPP_BUILD_VER,
145  .description = "HTTP Static Server"
146 };
147 /* *INDENT-ON* */
148 
149 /*
150  * fd.io coding-style-patch-verification: ON
151  *
152  * Local Variables:
153  * eval: (c-set-style "gnu")
154  * End:
155  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define foreach_http_static_plugin_api_msg
Definition: http_static.c:59
static clib_error_t * http_static_init(vlib_main_t *vm)
Definition: http_static.c:114
unsigned char u8
Definition: types.h:56
vnet_main_t * vnet_main
Definition: http_static.h:44
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
vlib_main_t * vlib_main
Definition: http_static.h:43
Configure and enable the static http server.
Definition: http_static.api:18
static void setup_message_id_table(http_static_main_t *hmp, api_main_t *am)
Definition: http_static.c:106
#define REPLY_MACRO(t)
u8 name[64]
Definition: memclnt.api:152
int http_static_server_enable_api(u32 fifo_size, u32 cache_limit, u32 prealloc_fifos, u32 private_segment_size, u8 *www_root, u8 *uri)
API helper function for vl_api_http_static_enable_t messages.
http_static_main_t http_static_main
Definition: http_static.c:55
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void vl_api_http_static_enable_t_handler(vl_api_http_static_enable_t *mp)
Definition: http_static.c:64
#define ARRAY_LEN(x)
Definition: clib.h:63
VLIB_PLUGIN_REGISTER()
static clib_error_t * http_static_plugin_api_hookup(vlib_main_t *vm)
Definition: http_static.c:84
api_main_t api_main
Definition: api_shared.c:35
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:957