Line data Source code
1 : /*
2 : * http_static.c - skeleton vpp-api-test 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 : #include <vat/vat.h>
18 : #include <vlibapi/api.h>
19 : #include <vlibmemory/api.h>
20 : #include <vppinfra/error.h>
21 :
22 : uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
23 :
24 : /* Declare message IDs */
25 : #include <http_static/http_static.api_enum.h>
26 : #include <http_static/http_static.api_types.h>
27 :
28 : typedef struct
29 : {
30 : /* API message ID base */
31 : u16 msg_id_base;
32 : vat_main_t *vat_main;
33 : } http_static_test_main_t;
34 :
35 : http_static_test_main_t http_static_test_main;
36 :
37 : #define __plugin_msg_base http_static_test_main.msg_id_base
38 : #include <vlibapi/vat_helper_macros.h>
39 :
40 : static int
41 0 : api_http_static_enable (vat_main_t * vam)
42 : {
43 0 : unformat_input_t *line_input = vam->input;
44 : vl_api_http_static_enable_t *mp;
45 : u64 tmp;
46 0 : u8 *www_root = 0;
47 0 : u8 *uri = 0;
48 0 : u32 prealloc_fifos = 0;
49 0 : u32 private_segment_size = 0;
50 0 : u32 fifo_size = 8 << 10;
51 0 : u32 cache_size_limit = 1 << 20;
52 : int ret;
53 :
54 : /* Parse args required to build the message */
55 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
56 : {
57 0 : if (unformat (line_input, "www-root %s", &www_root))
58 : ;
59 0 : else if (unformat (line_input, "prealloc-fifos %d", &prealloc_fifos))
60 : ;
61 0 : else if (unformat (line_input, "private-segment-size %U",
62 : unformat_memory_size, &tmp))
63 : {
64 0 : if (tmp >= 0x100000000ULL)
65 : {
66 0 : errmsg ("private segment size %llu, too large", tmp);
67 0 : return -99;
68 : }
69 0 : private_segment_size = (u32) tmp;
70 : }
71 0 : else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
72 : &tmp))
73 : {
74 0 : if (tmp >= 0x100000000ULL)
75 : {
76 0 : errmsg ("fifo-size %llu, too large", tmp);
77 0 : return -99;
78 : }
79 0 : fifo_size = (u32) tmp;
80 : }
81 0 : else if (unformat (line_input, "cache-size %U", unformat_memory_size,
82 : &tmp))
83 : {
84 0 : if (tmp < (128ULL << 10))
85 : {
86 0 : errmsg ("cache-size must be at least 128kb");
87 0 : return -99;
88 : }
89 0 : cache_size_limit = (u32) tmp;
90 : }
91 :
92 0 : else if (unformat (line_input, "uri %s", &uri))
93 : ;
94 : else
95 : {
96 0 : errmsg ("unknown input `%U'", format_unformat_error, line_input);
97 0 : return -99;
98 : }
99 : }
100 :
101 0 : if (www_root == 0)
102 : {
103 0 : errmsg ("Must specify www-root");
104 0 : return -99;
105 : }
106 :
107 0 : if (uri == 0)
108 0 : uri = format (0, "tcp://0.0.0.0/80%c", 0);
109 :
110 :
111 :
112 : /* Construct the API message */
113 0 : M (HTTP_STATIC_ENABLE, mp);
114 0 : strncpy_s ((char *) mp->www_root, 256, (const char *) www_root, 256);
115 0 : strncpy_s ((char *) mp->uri, 256, (const char *) uri, 256);
116 0 : mp->fifo_size = ntohl (fifo_size);
117 0 : mp->cache_size_limit = ntohl (cache_size_limit);
118 0 : mp->prealloc_fifos = ntohl (prealloc_fifos);
119 0 : mp->private_segment_size = ntohl (private_segment_size);
120 :
121 : /* send it... */
122 0 : S (mp);
123 :
124 : /* Wait for a reply... */
125 0 : W (ret);
126 0 : return ret;
127 : }
128 :
129 : #include <http_static/http_static.api_test.c>
130 :
131 : /*
132 : * fd.io coding-style-patch-verification: ON
133 : *
134 : * Local Variables:
135 : * eval: (c-set-style "gnu")
136 : * End:
137 : */
|