2 * builtinurl.c - skeleton vpp engine plug-in
4 * Copyright (c) 2019 Cisco and/or its affiliates.
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <builtinurl/builtinurl.h>
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
27 /* define message IDs */
28 #include <builtinurl/builtinurl.api_enum.h>
29 #include <builtinurl/builtinurl.api_types.h>
31 #define REPLY_MSG_ID_BASE bmp->msg_id_base
32 #include <vlibapi/api_helper_macros.h>
34 builtinurl_main_t builtinurl_main;
36 /* Action function shared between message handler and debug CLI */
39 builtinurl_enable (builtinurl_main_t * bmp)
41 void (*fp) (void *, char *, int);
46 /* Look up the builtin URL registration handler */
47 fp = vlib_get_plugin_symbol
48 ("http_static_plugin.so", "http_static_server_register_builtin_handler");
50 /* Most likely, the http_static plugin isn't loaded. Done. */
52 return VNET_API_ERROR_NO_SUCH_TABLE;
54 bmp->register_handler = fp;
55 builtinurl_handler_init (bmp);
62 builtinurl_enable_command_fn (vlib_main_t * vm,
63 unformat_input_t * input,
64 vlib_cli_command_t * cmd)
66 builtinurl_main_t *bmp = &builtinurl_main;
70 rv = builtinurl_enable (bmp);
77 case VNET_API_ERROR_NO_SUCH_TABLE:
78 return clib_error_return
79 (0, "http_static_server_register_builtin_handler undefined");
83 return clib_error_return (0, "builtinurl_enable returned %d", rv);
89 VLIB_CLI_COMMAND (builtinurl_enable_command, static) =
91 .path = "builtinurl enable",
92 .short_help = "Turn on builtin http/https GET and POST urls",
93 .function = builtinurl_enable_command_fn,
97 /* API message handler */
98 static void vl_api_builtinurl_enable_t_handler
99 (vl_api_builtinurl_enable_t * mp)
101 vl_api_builtinurl_enable_reply_t *rmp;
102 builtinurl_main_t *bmp = &builtinurl_main;
105 rv = builtinurl_enable (bmp);
107 REPLY_MACRO (VL_API_BUILTINURL_ENABLE_REPLY);
110 #include <builtinurl/builtinurl.api.c>
111 static clib_error_t *
112 builtinurl_init (vlib_main_t * vm)
114 builtinurl_main_t *bmp = &builtinurl_main;
117 bmp->vnet_main = vnet_get_main ();
119 /* Ask for a correctly-sized block of API message decode slots */
120 bmp->msg_id_base = setup_message_id_table ();
125 VLIB_INIT_FUNCTION (builtinurl_init);
128 VLIB_PLUGIN_REGISTER () =
130 .version = VPP_BUILD_VER,
131 .description = "vpp built-in URL support",
136 * fd.io coding-style-patch-verification: ON
139 * eval: (c-set-style "gnu")