r2982 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish
phk at projects.linpro.no
phk at projects.linpro.no
Tue Jul 22 09:37:33 CEST 2008
Author: phk
Date: 2008-07-22 09:37:32 +0200 (Tue, 22 Jul 2008)
New Revision: 2982
Modified:
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/include/cli_priv.h
trunk/varnish-cache/lib/libvarnish/cli_common.c
Log:
Add a cli_quote() function for quoting a string properly when reporting
it in the CLI.
Use it for cc_command and listen_address parameters
Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-22 07:19:40 UTC (rev 2981)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-22 07:37:32 UTC (rev 2982)
@@ -315,11 +315,7 @@
(void)par;
if (arg == NULL) {
- /* Quote the string if we have more than one socket */
- if (heritage.nsocks > 1)
- cli_out(cli, "\"%s\"", master.listen_address);
- else
- cli_out(cli, "%s", master.listen_address);
+ cli_quote(cli, master.listen_address);
return;
}
@@ -348,7 +344,8 @@
int j, n;
if (VSS_parse(av[i], &host, &port) != 0) {
- cli_out(cli, "Invalid listen address \"%s\"", av[i]);
+ cli_out(cli, "Invalid listen address ");
+ cli_quote(cli, av[i]);
cli_result(cli, CLIS_PARAM);
break;
}
@@ -356,7 +353,8 @@
free(host);
free(port);
if (n == 0) {
- cli_out(cli, "Invalid listen address \"%s\"", av[i]);
+ cli_out(cli, "Invalid listen address ");
+ cli_quote(cli, av[i]);
cli_result(cli, CLIS_PARAM);
break;
}
@@ -399,7 +397,7 @@
/* XXX should have tweak_generic_string */
(void)par;
if (arg == NULL) {
- cli_out(cli, "%s", mgt_cc_cmd);
+ cli_quote(cli, mgt_cc_cmd);
} else {
free(mgt_cc_cmd);
mgt_cc_cmd = strdup(arg);
Modified: trunk/varnish-cache/include/cli_priv.h
===================================================================
--- trunk/varnish-cache/include/cli_priv.h 2008-07-22 07:19:40 UTC (rev 2981)
+++ trunk/varnish-cache/include/cli_priv.h 2008-07-22 07:37:32 UTC (rev 2982)
@@ -54,6 +54,7 @@
/* The implementation must provide these functions */
void cli_out(struct cli *cli, const char *fmt, ...);
+void cli_quote(struct cli *cli, const char *str);
void cli_param(struct cli *cli);
void cli_result(struct cli *cli, unsigned r);
Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-22 07:19:40 UTC (rev 2981)
+++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-22 07:37:32 UTC (rev 2982)
@@ -69,6 +69,53 @@
}
void
+cli_quote(struct cli *cli, const char *s)
+{
+ const char *q;
+ int quote = 0;
+
+ for (q = s; *q != '\0'; q++) {
+ if (!isgraph(*q) || *q == '"') {
+ quote++;
+ break;
+ }
+ }
+ if (!quote) {
+ (void)vsb_cat(cli->sb, s);
+ return;
+ }
+ (void)vsb_putc(cli->sb, '"');
+ for (q = s; *q != '\0'; q++) {
+ switch (*q) {
+ case ' ':
+ (void)vsb_putc(cli->sb, *q);
+ break;
+ case '\\':
+ case '"':
+ (void)vsb_putc(cli->sb, '\\');
+ (void)vsb_putc(cli->sb, *q);
+ break;
+ case '\n':
+ (void)vsb_cat(cli->sb, "\\n");
+ break;
+ case '\r':
+ (void)vsb_cat(cli->sb, "\\r");
+ break;
+ case '\t':
+ (void)vsb_cat(cli->sb, "\\t");
+ break;
+ default:
+ if (isgraph(*q))
+ (void)vsb_putc(cli->sb, *q);
+ else
+ (void)vsb_printf(cli->sb, "\\%o", *q);
+ break;
+ }
+ }
+ (void)vsb_putc(cli->sb, '"');
+}
+
+void
cli_result(struct cli *cli, unsigned res)
{
@@ -78,7 +125,6 @@
printf("CLI result = %d\n", res);
}
-
void
cli_param(struct cli *cli)
{
More information about the varnish-commit
mailing list