aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/hs_apps/http_cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/hs_apps/http_cli.c')
-rw-r--r--src/plugins/hs_apps/http_cli.c87
1 files changed, 50 insertions, 37 deletions
diff --git a/src/plugins/hs_apps/http_cli.c b/src/plugins/hs_apps/http_cli.c
index 18b57f6c29d..dfa90f9eced 100644
--- a/src/plugins/hs_apps/http_cli.c
+++ b/src/plugins/hs_apps/http_cli.c
@@ -74,6 +74,10 @@ typedef struct
/* pool of uri maps */
hcs_uri_map_t *uri_map_pool;
+
+ /* for appns */
+ u8 *appns_id;
+ u64 appns_secret;
} hcs_main_t;
static hcs_main_t hcs_main;
@@ -402,7 +406,7 @@ hcs_ts_rx_callback (session_t *ts)
}
if (is_encoded)
{
- u8 *decoded = http_percent_decode (args.buf);
+ u8 *decoded = http_percent_decode (args.buf, vec_len (args.buf));
vec_free (args.buf);
args.buf = decoded;
}
@@ -597,6 +601,11 @@ hcs_attach ()
hcm->fifo_size ? hcm->fifo_size : 32 << 10;
a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = hcm->prealloc_fifos;
+ if (hcm->appns_id)
+ {
+ a->namespace_id = hcm->appns_id;
+ a->options[APP_OPTIONS_NAMESPACE_SECRET] = hcm->appns_secret;
+ }
if (vnet_application_attach (a))
{
@@ -651,9 +660,10 @@ hcs_listen ()
if (need_crypto)
{
- session_endpoint_alloc_ext_cfg (&a->sep_ext,
- TRANSPORT_ENDPT_EXT_CFG_CRYPTO);
- a->sep_ext.ext_cfg->crypto.ckpair_index = hcm->ckpair_index;
+ transport_endpt_ext_cfg_t *ext_cfg = session_endpoint_add_ext_cfg (
+ &a->sep_ext, TRANSPORT_ENDPT_EXT_CFG_CRYPTO,
+ sizeof (transport_endpt_crypto_cfg_t));
+ ext_cfg->crypto.ckpair_index = hcm->ckpair_index;
}
rv = vnet_listen (a);
@@ -667,15 +677,25 @@ hcs_listen ()
}
if (need_crypto)
- clib_mem_free (a->sep_ext.ext_cfg);
+ session_endpoint_free_ext_cfgs (&a->sep_ext);
return rv;
}
+static void
+hcs_detach ()
+{
+ vnet_app_detach_args_t _a, *a = &_a;
+ hcs_main_t *hcm = &hcs_main;
+ a->app_index = hcm->app_index;
+ a->api_client_index = APP_INVALID_INDEX;
+ hcm->app_index = ~0;
+ vnet_application_detach (a);
+}
+
static int
hcs_unlisten ()
{
- session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
hcs_main_t *hcm = &hcs_main;
vnet_unlisten_args_t _a, *a = &_a;
char *uri;
@@ -688,9 +708,6 @@ hcs_unlisten ()
uri = (char *) hcm->uri;
ASSERT (uri);
- if (parse_uri (uri, &sep))
- return -1;
-
value = hash_get_mem (hcm->index_by_uri, uri);
if (value)
{
@@ -700,8 +717,11 @@ hcs_unlisten ()
rv = vnet_unlisten (a);
if (rv == 0)
{
+ hash_unset_mem (hcm->index_by_uri, uri);
vec_free (map->uri);
pool_put (hcm->uri_map_pool, map);
+ if (pool_elts (hcm->uri_map_pool) == 0)
+ hcs_detach ();
}
}
else
@@ -710,17 +730,6 @@ hcs_unlisten ()
return rv;
}
-static void
-hcs_detach ()
-{
- vnet_app_detach_args_t _a, *a = &_a;
- hcs_main_t *hcm = &hcs_main;
- a->app_index = hcm->app_index;
- a->api_client_index = APP_INVALID_INDEX;
- hcm->app_index = ~0;
- vnet_application_detach (a);
-}
-
static int
hcs_create (vlib_main_t *vm)
{
@@ -776,6 +785,10 @@ hcs_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
hcm->fifo_size <<= 10;
else if (unformat (line_input, "uri %_%v%_", &hcm->uri))
;
+ else if (unformat (line_input, "appns %_%v%_", &hcm->appns_id))
+ ;
+ else if (unformat (line_input, "secret %lu", &hcm->appns_secret))
+ ;
else if (unformat (line_input, "listener"))
{
if (unformat (line_input, "add"))
@@ -804,31 +817,30 @@ hcs_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
start_server:
if (hcm->uri == 0)
- hcm->uri = format (0, "tcp://0.0.0.0/80%c", 0);
+ hcm->uri = format (0, "tcp://0.0.0.0/80");
if (hcm->app_index != (u32) ~0)
{
+ if (hcm->appns_id && (listener_add != ~0))
+ {
+ error = clib_error_return (
+ 0, "appns must not be specified for listener add/del");
+ goto done;
+ }
if (listener_add == 1)
{
if (hcs_listen ())
- {
- error = clib_error_return (0, "failed to start listening %v",
- hcm->uri);
- goto done;
- }
- else
- goto done;
+ error =
+ clib_error_return (0, "failed to start listening %v", hcm->uri);
+ goto done;
}
else if (listener_add == 0)
{
- if (hcs_unlisten () != 0)
- {
- error =
- clib_error_return (0, "failed to stop listening %v", hcm->uri);
- goto done;
- }
- else
- goto done;
+ rv = hcs_unlisten ();
+ if (rv != 0)
+ error = clib_error_return (
+ 0, "failed to stop listening %v, rv = %d", hcm->uri, rv);
+ goto done;
}
else
{
@@ -855,6 +867,7 @@ start_server:
}
done:
+ vec_free (hcm->appns_id);
vec_free (hcm->uri);
return error;
}
@@ -863,7 +876,7 @@ VLIB_CLI_COMMAND (hcs_create_command, static) = {
.path = "http cli server",
.short_help = "http cli server [uri <uri>] [fifo-size <nbytes>] "
"[private-segment-size <nMG>] [prealloc-fifos <n>] "
- "[listener <add|del>]",
+ "[listener <add|del>] [appns <app-ns> secret <appns-secret>]",
.function = hcs_create_command_fn,
};