Line data Source code
1 : /* 2 : * builtinurl.c - skeleton vpp engine plug-in 3 : * 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: 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 <builtinurl/builtinurl.h> 21 : 22 : #include <vlibapi/api.h> 23 : #include <vlibmemory/api.h> 24 : #include <vpp/app/version.h> 25 : #include <stdbool.h> 26 : 27 : /* define message IDs */ 28 : #include <builtinurl/builtinurl.api_enum.h> 29 : #include <builtinurl/builtinurl.api_types.h> 30 : 31 : #define REPLY_MSG_ID_BASE bmp->msg_id_base 32 : #include <vlibapi/api_helper_macros.h> 33 : 34 : builtinurl_main_t builtinurl_main; 35 : 36 : /* Action function shared between message handler and debug CLI */ 37 : 38 : int 39 0 : builtinurl_enable (builtinurl_main_t * bmp) 40 : { 41 : void (*fp) (void *, char *, int); 42 : 43 0 : if (bmp->initialized) 44 0 : return 0; 45 : 46 : /* Look up the builtin URL registration handler */ 47 0 : fp = vlib_get_plugin_symbol 48 : ("http_static_plugin.so", "http_static_server_register_builtin_handler"); 49 : 50 : /* Most likely, the http_static plugin isn't loaded. Done. */ 51 0 : if (fp == 0) 52 0 : return VNET_API_ERROR_NO_SUCH_TABLE; 53 : 54 0 : bmp->register_handler = fp; 55 0 : builtinurl_handler_init (bmp); 56 0 : bmp->initialized = 1; 57 : 58 0 : return 0; 59 : } 60 : 61 : static clib_error_t * 62 0 : builtinurl_enable_command_fn (vlib_main_t * vm, 63 : unformat_input_t * input, 64 : vlib_cli_command_t * cmd) 65 : { 66 0 : builtinurl_main_t *bmp = &builtinurl_main; 67 : 68 : int rv; 69 : 70 0 : rv = builtinurl_enable (bmp); 71 : 72 0 : switch (rv) 73 : { 74 0 : case 0: 75 0 : break; 76 : 77 0 : case VNET_API_ERROR_NO_SUCH_TABLE: 78 0 : return clib_error_return 79 : (0, "http_static_server_register_builtin_handler undefined"); 80 : break; 81 : 82 0 : default: 83 0 : return clib_error_return (0, "builtinurl_enable returned %d", rv); 84 : } 85 0 : return 0; 86 : } 87 : 88 : /* *INDENT-OFF* */ 89 253287 : VLIB_CLI_COMMAND (builtinurl_enable_command, static) = 90 : { 91 : .path = "builtinurl enable", 92 : .short_help = "Turn on builtin http/https GET and POST urls", 93 : .function = builtinurl_enable_command_fn, 94 : }; 95 : /* *INDENT-ON* */ 96 : 97 : /* API message handler */ 98 0 : static void vl_api_builtinurl_enable_t_handler 99 : (vl_api_builtinurl_enable_t * mp) 100 : { 101 : vl_api_builtinurl_enable_reply_t *rmp; 102 0 : builtinurl_main_t *bmp = &builtinurl_main; 103 : int rv; 104 : 105 0 : rv = builtinurl_enable (bmp); 106 : 107 0 : REPLY_MACRO (VL_API_BUILTINURL_ENABLE_REPLY); 108 : } 109 : 110 : #include <builtinurl/builtinurl.api.c> 111 : static clib_error_t * 112 559 : builtinurl_init (vlib_main_t * vm) 113 : { 114 559 : builtinurl_main_t *bmp = &builtinurl_main; 115 : 116 559 : bmp->vlib_main = vm; 117 559 : bmp->vnet_main = vnet_get_main (); 118 : 119 : /* Ask for a correctly-sized block of API message decode slots */ 120 559 : bmp->msg_id_base = setup_message_id_table (); 121 : 122 559 : return 0; 123 : } 124 : 125 1119 : VLIB_INIT_FUNCTION (builtinurl_init); 126 : 127 : /* *INDENT-OFF* */ 128 : VLIB_PLUGIN_REGISTER () = 129 : { 130 : .version = VPP_BUILD_VER, 131 : .description = "vpp built-in URL support", 132 : }; 133 : /* *INDENT-ON* */ 134 : 135 : /* 136 : * fd.io coding-style-patch-verification: ON 137 : * 138 : * Local Variables: 139 : * eval: (c-set-style "gnu") 140 : * End: 141 : */