From d2b291aff39e3906fa87184913590b85eb572bb8 Mon Sep 17 00:00:00 2001 From: des Date: Tue, 3 Jul 2007 12:21:50 +0000 Subject: [PATCH] Add a 'vcl.show' command which displays the source code for a given VCL script. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1626 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/mgt_cli.c | 1 + varnish-cache/bin/varnishd/mgt_cli.h | 1 + varnish-cache/bin/varnishd/mgt_vcc.c | 26 ++++++++++++++++++++++++++ varnish-cache/include/cli.h | 18 ++++++++++++------ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/varnish-cache/bin/varnishd/mgt_cli.c b/varnish-cache/bin/varnishd/mgt_cli.c index 08facca8..d0a5b4af 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.c +++ b/varnish-cache/bin/varnishd/mgt_cli.c @@ -148,6 +148,7 @@ static struct cli_proto mgt_cli_proto[] = { { CLI_VCL_USE, mcf_config_use, NULL }, { CLI_VCL_DISCARD, mcf_config_discard, NULL }, { CLI_VCL_LIST, mcf_config_list, NULL }, + { CLI_VCL_SHOW, mcf_config_show, NULL }, { CLI_PARAM_SHOW, mcf_param_show, NULL }, { CLI_PARAM_SET, mcf_param_set, NULL }, { CLI_HELP, cli_func_help, NULL }, diff --git a/varnish-cache/bin/varnishd/mgt_cli.h b/varnish-cache/bin/varnishd/mgt_cli.h index 811450b3..884a776f 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.h +++ b/varnish-cache/bin/varnishd/mgt_cli.h @@ -42,3 +42,4 @@ cli_func_t mcf_config_inline; cli_func_t mcf_config_use; cli_func_t mcf_config_discard; cli_func_t mcf_config_list; +cli_func_t mcf_config_show; diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index e91d70f2..abb77c57 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -573,3 +573,29 @@ mcf_config_list(struct cli *cli, char **av, void *priv) } } +void +mcf_config_show(struct cli *cli, char **av, void *priv) +{ + struct vclprog *vp; + void *dlh, *sym; + const char **src; + + (void)priv; + if ((vp = mcf_find_vcl(cli, av[2])) != NULL) { + if ((dlh = dlopen(vp->fname, RTLD_NOW | RTLD_LOCAL)) == NULL) { + cli_out(cli, "failed to load %s: %s\n", + vp->name, dlerror()); + cli_result(cli, CLIS_CANT); + } else if ((sym = dlsym(dlh, "srcbody")) == NULL) { + cli_out(cli, "failed to locate source for %s: %s\n", + vp->name, dlerror()); + cli_result(cli, CLIS_CANT); + dlclose(dlh); + } else { + src = sym; + cli_out(cli, src[0]); + /* cli_out(cli, src[1]); */ + dlclose(dlh); + } + } +} diff --git a/varnish-cache/include/cli.h b/varnish-cache/include/cli.h index 72b4a9e4..11013ec8 100644 --- a/varnish-cache/include/cli.h +++ b/varnish-cache/include/cli.h @@ -79,14 +79,14 @@ "\tCompile and load the VCL file under the name provided.", \ 2, 2 -#define CLI_VCL_INLINE \ - "vcl.inline", \ - "vcl.inline ", \ +#define CLI_VCL_INLINE \ + "vcl.inline", \ + "vcl.inline ", \ "\tCompile and load the VCL data under the name provided.", \ 2, 2 -#define CLI_VCL_DISCARD \ - "vcl.discard", \ +#define CLI_VCL_DISCARD \ + "vcl.discard", \ "vcl.discard ", \ "\tUnload the named configuration (when possible).", \ 1, 1 @@ -97,9 +97,15 @@ "\tList all loaded configuration.", \ 0, 0 +#define CLI_VCL_SHOW \ + "vcl.show", \ + "vcl.show ", \ + "\tDisplay the source code for the specified configuration.", \ + 1, 1 + #define CLI_VCL_USE \ "vcl.use", \ - "vcl.use ", \ + "vcl.use ", \ "\tSwitch to the named configuration immediately.", \ 1, 1 -- 2.39.5