122bc2c46SDave Barach/*
222bc2c46SDave Barach * http_static.c - skeleton vpp engine plug-in
322bc2c46SDave Barach *
422bc2c46SDave Barach * Copyright (c) <current-year> <your-organization>
522bc2c46SDave Barach * Licensed under the Apache License, Version 2.0 (the "License");
622bc2c46SDave Barach * you may not use this file except in compliance with the License.
722bc2c46SDave Barach * You may obtain a copy of the License at:
822bc2c46SDave Barach *
922bc2c46SDave Barach *     http://www.apache.org/licenses/LICENSE-2.0
1022bc2c46SDave Barach *
1122bc2c46SDave Barach * Unless required by applicable law or agreed to in writing, software
1222bc2c46SDave Barach * distributed under the License is distributed on an "AS IS" BASIS,
1322bc2c46SDave Barach * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1422bc2c46SDave Barach * See the License for the specific language governing permissions and
1522bc2c46SDave Barach * limitations under the License.
1622bc2c46SDave Barach */
1722bc2c46SDave Barach
1822bc2c46SDave Barach#include <vnet/vnet.h>
1922bc2c46SDave Barach#include <vnet/plugin/plugin.h>
2022bc2c46SDave Barach#include <http_static/http_static.h>
2122bc2c46SDave Barach
2222bc2c46SDave Barach#include <vlibapi/api.h>
2322bc2c46SDave Barach#include <vlibmemory/api.h>
2422bc2c46SDave Barach#include <vpp/app/version.h>
2522bc2c46SDave Barach
2622bc2c46SDave Barach/* define message IDs */
2783a49e12SOle Troan#include <http_static/http_static.api_enum.h>
2883a49e12SOle Troan#include <http_static/http_static.api_types.h>
2922bc2c46SDave Barach
3068b24e2cSPaul Vinciguerra#include <vpp/api/types.h>
3168b24e2cSPaul Vinciguerra
3222bc2c46SDave Barach#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
3322bc2c46SDave Barach
3422bc2c46SDave Barach#define REPLY_MSG_ID_BASE hmp->msg_id_base
3522bc2c46SDave Barach#include <vlibapi/api_helper_macros.h>
3622bc2c46SDave Barach
3722bc2c46SDave Barachhttp_static_main_t http_static_main;
3822bc2c46SDave Barach
3922bc2c46SDave Barach/* API message handler */
4022bc2c46SDave Barachstatic void vl_api_http_static_enable_t_handler
4122bc2c46SDave Barach  (vl_api_http_static_enable_t * mp)
4222bc2c46SDave Barach{
4322bc2c46SDave Barach  vl_api_http_static_enable_reply_t *rmp;
4422bc2c46SDave Barach  http_static_main_t *hmp = &http_static_main;
4522bc2c46SDave Barach  int rv;
4668b24e2cSPaul Vinciguerra
47e5ff5a36SOle Troan  mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
48e5ff5a36SOle Troan  mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
4922bc2c46SDave Barach
5022bc2c46SDave Barach  rv = http_static_server_enable_api
5168b24e2cSPaul Vinciguerra    (ntohl (mp->fifo_size),
5268b24e2cSPaul Vinciguerra     ntohl (mp->cache_size_limit),
5322bc2c46SDave Barach     ntohl (mp->prealloc_fifos),
54e5ff5a36SOle Troan     ntohl (mp->private_segment_size), mp->www_root, mp->uri);
5522bc2c46SDave Barach
5722bc2c46SDave Barach}
5822bc2c46SDave Barach
5983a49e12SOle Troan#include <http_static/http_static.api.c>
6022bc2c46SDave Barachstatic clib_error_t *
6122bc2c46SDave Barachhttp_static_init (vlib_main_t * vm)
6222bc2c46SDave Barach{
6322bc2c46SDave Barach  http_static_main_t *hmp = &http_static_main;
6422bc2c46SDave Barach
6522bc2c46SDave Barach  hmp->vlib_main = vm;
6622bc2c46SDave Barach  hmp->vnet_main = vnet_get_main ();
6722bc2c46SDave Barach
6822bc2c46SDave Barach  /* Ask for a correctly-sized block of API message decode slots */
6983a49e12SOle Troan  hmp->msg_id_base = setup_message_id_table ();
7022bc2c46SDave Barach
7183a49e12SOle Troan  return 0;
7222bc2c46SDave Barach}
7322bc2c46SDave Barach
7422bc2c46SDave BarachVLIB_INIT_FUNCTION (http_static_init);
7522bc2c46SDave Barach
7622bc2c46SDave Barach/* *INDENT-OFF* */
7722bc2c46SDave BarachVLIB_PLUGIN_REGISTER () =
7822bc2c46SDave Barach{
7922bc2c46SDave Barach  .version = VPP_BUILD_VER,
801d1985deSDave Wallace  .description = "HTTP Static Server"
8122bc2c46SDave Barach};
8222bc2c46SDave Barach/* *INDENT-ON* */
8322bc2c46SDave Barach
8422bc2c46SDave Barach/*
8522bc2c46SDave Barach * fd.io coding-style-patch-verification: ON
8622bc2c46SDave Barach *
8722bc2c46SDave Barach * Local Variables:
8822bc2c46SDave Barach * eval: (c-set-style "gnu")
8922bc2c46SDave Barach * End:
9022bc2c46SDave Barach */