http_static: refactor to use http transport
[vpp.git] / src / plugins / http_static / http_static.c
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>
20 #include <http_static/http_static.h>
21
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25
26 /* define message IDs */
27 #include <http_static/http_static.api_enum.h>
28 #include <http_static/http_static.api_types.h>
29
30 #include <vpp/api/types.h>
31
32 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
33
34 #define REPLY_MSG_ID_BASE hmp->msg_id_base
35 #include <vlibapi/api_helper_macros.h>
36
37 http_static_main_t http_static_main;
38
39 /* API message handler */
40 static void vl_api_http_static_enable_t_handler
41   (vl_api_http_static_enable_t * mp)
42 {
43   vl_api_http_static_enable_reply_t *rmp;
44   http_static_main_t *hmp = &http_static_main;
45   int rv;
46
47   mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
48   mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
49
50   rv =
51     hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
52                     ntohl (mp->prealloc_fifos),
53                     ntohl (mp->private_segment_size), mp->www_root, mp->uri);
54
55   REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_REPLY);
56 }
57
58 #include <http_static/http_static.api.c>
59 static clib_error_t *
60 http_static_init (vlib_main_t * vm)
61 {
62   http_static_main_t *hmp = &http_static_main;
63
64   hmp->vlib_main = vm;
65   hmp->vnet_main = vnet_get_main ();
66
67   /* Ask for a correctly-sized block of API message decode slots */
68   hmp->msg_id_base = setup_message_id_table ();
69
70   return 0;
71 }
72
73 VLIB_INIT_FUNCTION (http_static_init);
74
75 /* *INDENT-OFF* */
76 VLIB_PLUGIN_REGISTER () =
77 {
78   .version = VPP_BUILD_VER,
79   .description = "HTTP Static Server"
80 };
81 /* *INDENT-ON* */
82
83 /*
84  * fd.io coding-style-patch-verification: ON
85  *
86  * Local Variables:
87  * eval: (c-set-style "gnu")
88  * End:
89  */