]> err.no Git - varnish/commitdiff
Move the body of cli_quote() to vsb_quote() and give it a, presently
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 18 Jan 2009 14:50:20 +0000 (14:50 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 18 Jan 2009 14:50:20 +0000 (14:50 +0000)
unused, "how" argument flag.

We currently have far too many "quote this string properly" implementations
in varnish, hopefully, this will replace most of them.

Once this stabilizes, vsb_quote() will be contributed back to FreeBSD.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3515 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/vsb.h
varnish-cache/lib/libvarnish/cli_common.c
varnish-cache/lib/libvarnish/vsb.c

index 4bc22db0268146296dd7c530e44f8e49d3e13a1d..d107f020d864d81ea880484e051aaeb4f91f8ade 100644 (file)
@@ -77,6 +77,7 @@ char          *vsb_data(struct vsb *);
 int             vsb_len(struct vsb *);
 int             vsb_done(const struct vsb *);
 void            vsb_delete(struct vsb *);
+void            vsb_quote(struct vsb *s, const char *p, int how);
 #ifdef __cplusplus
 };
 #endif
index e390d651da7045d40ed7e2187468e49ded9dec50..8b68418d49b30234a870812a268d47ec568a350e 100644 (file)
@@ -72,48 +72,8 @@ cli_out(struct cli *cli, const char *fmt, ...)
 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, '"');
+       vsb_quote(cli->sb, s, 0);
 }
 
 void
index af9f1701b5f4daf801b15a1e96ea6f2daf705048..691906ad4f9b6e7bc23b06a69777d57b42ccd79b 100644 (file)
@@ -476,3 +476,55 @@ vsb_done(const struct vsb *s)
 
        return(VSB_ISFINISHED(s));
 }
+
+/*
+ * Quote a string
+ */
+void
+vsb_quote(struct vsb *s, const char *p, int how)
+{
+       const char *q;
+       int quote = 0;
+
+       (void)how;      /* For future enhancements */
+
+       for (q = p; *q != '\0'; q++) {
+               if (!isgraph(*q) || *q == '"') {
+                       quote++;
+                       break;
+               }
+       }
+       if (!quote) {
+               (void)vsb_cat(s, p);
+               return;
+       }
+       (void)vsb_putc(s, '"');
+       for (q = p; *q != '\0'; q++) {
+               switch (*q) {
+               case ' ':
+                       (void)vsb_putc(s, *q);
+                       break;
+               case '\\':
+               case '"':
+                       (void)vsb_putc(s, '\\');
+                       (void)vsb_putc(s, *q);
+                       break;
+               case '\n':
+                       (void)vsb_cat(s, "\\n");
+                       break;
+               case '\r':
+                       (void)vsb_cat(s, "\\r");
+                       break;
+               case '\t':
+                       (void)vsb_cat(s, "\\t");
+                       break;
+               default:
+                       if (isgraph(*q))
+                               (void)vsb_putc(s, *q);
+                       else
+                               (void)vsb_printf(s, "\\%o", *q);
+                       break;
+               }
+       }
+       (void)vsb_putc(s, '"');
+}