]> err.no Git - varnish/commitdiff
Add a 'vcl.show' command which displays the source code for a given VCL
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Jul 2007 12:21:50 +0000 (12:21 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Jul 2007 12:21:50 +0000 (12:21 +0000)
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
varnish-cache/bin/varnishd/mgt_cli.h
varnish-cache/bin/varnishd/mgt_vcc.c
varnish-cache/include/cli.h

index 08facca8ddce39a48422f79af896705a0d7de830..d0a5b4af95b798b070d32b1d24a16b1a84ef2e0a 100644 (file)
@@ -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 },
index 811450b31ca91e8ce0cd50055d08dd12b482e4ed..884a776f7b4fe13d2658860be02ca13c08b68bdf 100644 (file)
@@ -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;
index e91d70f2d4abeb24ece143fa4d8d1025e2cbb12b..abb77c576b0d5e7a479e9a99e2682495947d381e 100644 (file)
@@ -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);
+               }
+       }
+}
index 72b4a9e4f713322e1fa7fe3653544fdd0e19f6f7..11013ec8a2b21ed61da3eb8a250ca790c43fe9dd 100644 (file)
        "\tCompile and load the VCL file under the name provided.",     \
        2, 2
 
-#define CLI_VCL_INLINE                                         \
-       "vcl.inline",                                           \
-       "vcl.inline <configname> <quoted_VCLstring>",           \
+#define CLI_VCL_INLINE                                                 \
+       "vcl.inline",                                                   \
+       "vcl.inline <configname> <quoted_VCLstring>",                   \
        "\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 <configname>",                                     \
        "\tUnload the named configuration (when possible).",            \
        1, 1
        "\tList all loaded configuration.",                             \
        0, 0
 
+#define CLI_VCL_SHOW                                                   \
+       "vcl.show",                                                     \
+       "vcl.show <configname>",                                        \
+       "\tDisplay the source code for the specified configuration.",   \
+       1, 1
+
 #define CLI_VCL_USE                                                    \
        "vcl.use",                                                      \
-       "vcl.use <configname>",                                 \
+       "vcl.use <configname>",                                         \
        "\tSwitch to the named configuration immediately.",             \
        1, 1