Mailing List Archive

r1626 - in trunk/varnish-cache: bin/varnishd include
Author: des
Date: 2007-07-03 14:21:50 +0200 (Tue, 03 Jul 2007)
New Revision: 1626

Modified:
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/bin/varnishd/mgt_cli.h
trunk/varnish-cache/bin/varnishd/mgt_vcc.c
trunk/varnish-cache/include/cli.h
Log:
Add a 'vcl.show' command which displays the source code for a given VCL
script.


Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-03 11:34:16 UTC (rev 1625)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-03 12:21:50 UTC (rev 1626)
@@ -148,6 +148,7 @@
{ 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 },

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-03 11:34:16 UTC (rev 1625)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-03 12:21:50 UTC (rev 1626)
@@ -42,3 +42,4 @@
cli_func_t mcf_config_use;
cli_func_t mcf_config_discard;
cli_func_t mcf_config_list;
+cli_func_t mcf_config_show;

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-03 11:34:16 UTC (rev 1625)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-03 12:21:50 UTC (rev 1626)
@@ -573,3 +573,29 @@
}
}

+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);
+ }
+ }
+}

Modified: trunk/varnish-cache/include/cli.h
===================================================================
--- trunk/varnish-cache/include/cli.h 2007-07-03 11:34:16 UTC (rev 1625)
+++ trunk/varnish-cache/include/cli.h 2007-07-03 12:21:50 UTC (rev 1626)
@@ -79,14 +79,14 @@
"\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
@@ -97,9 +97,15 @@
"\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