Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
b0d1a40f
Commit
b0d1a40f
authored
Feb 12, 2020
by
Guillaume Quintard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add VSB_QUOTE_GLOB
parent
898e7803
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
5 deletions
+86
-5
vsb.h
include/vsb.h
+1
-0
Makefile.am
lib/libvarnish/Makefile.am
+4
-1
vsb.c
lib/libvarnish/vsb.c
+32
-4
vsb_test.c
lib/libvarnish/vsb_test.c
+49
-0
No files found.
include/vsb.h
View file @
b0d1a40f
...
...
@@ -84,6 +84,7 @@ void VSB_destroy(struct vsb **);
#define VSB_QUOTE_CSTR 8
#define VSB_QUOTE_UNSAFE 16
#define VSB_QUOTE_ESCHEX 32
#define VSB_QUOTE_GLOB 64
void
VSB_quote_pfx
(
struct
vsb
*
,
const
char
*
,
const
void
*
,
int
len
,
int
how
);
void
VSB_quote
(
struct
vsb
*
,
const
void
*
,
int
len
,
int
how
);
...
...
lib/libvarnish/Makefile.am
View file @
b0d1a40f
...
...
@@ -43,7 +43,7 @@ libvarnish_a_SOURCES = \
vtim.c
\
vus.c
TESTS
=
vjsn_test vnum_c_test binheap
TESTS
=
vjsn_test vnum_c_test binheap
vsb_test
noinst_PROGRAMS
=
${
TESTS
}
...
...
@@ -57,3 +57,6 @@ vnum_c_test_LDADD = ${LIBM} libvarnish.a @SAN_LDFLAGS@
vjsn_test_SOURCES
=
vjsn.c
vjsn_test_CFLAGS
=
-DVJSN_TEST
@SAN_CFLAGS@
vjsn_test_LDADD
=
libvarnish.a @SAN_LDFLAGS@
vsb_test_SOURCES
=
vsb_test.c vsb.c vas.c
vsb_test_LDADD
=
libvarnish.a
lib/libvarnish/vsb.c
View file @
b0d1a40f
...
...
@@ -563,7 +563,7 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
nl
=
0
;
switch
(
*
q
)
{
case
'?'
:
if
(
how
&
VSB_QUOTE_CSTR
)
if
(
how
&
(
VSB_QUOTE_CSTR
|
VSB_QUOTE_GLOB
)
)
(
void
)
VSB_putc
(
s
,
'\\'
);
(
void
)
VSB_putc
(
s
,
*
q
);
break
;
...
...
@@ -571,6 +571,10 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
(
void
)
VSB_putc
(
s
,
*
q
);
break
;
case
'\\'
:
if
(
!
(
how
&
(
VSB_QUOTE_UNSAFE
)))
(
void
)
VSB_putc
(
s
,
'\\'
);
(
void
)
VSB_putc
(
s
,
*
q
);
break
;
case
'"'
:
if
(
!
(
how
&
VSB_QUOTE_UNSAFE
))
(
void
)
VSB_putc
(
s
,
'\\'
);
...
...
@@ -582,18 +586,42 @@ VSB_quote_pfx(struct vsb *s, const char *pfx, const void *v, int len, int how)
}
else
if
(
how
&
(
VSB_QUOTE_NONL
|
VSB_QUOTE_UNSAFE
))
{
(
void
)
VSB_printf
(
s
,
"
\n
"
);
nl
=
1
;
}
else
if
(
how
&
VSB_QUOTE_GLOB
)
{
(
void
)
VSB_printf
(
s
,
"
\\\\
n"
);
}
else
{
(
void
)
VSB_printf
(
s
,
"
\\
n"
);
}
break
;
case
'\r'
:
(
void
)
VSB_cat
(
s
,
"
\\
r"
);
if
(
how
&
VSB_QUOTE_GLOB
)
(
void
)
VSB_cat
(
s
,
"
\\\\
r"
);
else
(
void
)
VSB_cat
(
s
,
"
\\
r"
);
break
;
case
'\t'
:
(
void
)
VSB_cat
(
s
,
"
\\
t"
);
if
(
how
&
VSB_QUOTE_GLOB
)
(
void
)
VSB_cat
(
s
,
"
\\\\
t"
);
else
(
void
)
VSB_cat
(
s
,
"
\\
t"
);
break
;
case
'\v'
:
(
void
)
VSB_cat
(
s
,
"
\\
v"
);
if
(
how
&
VSB_QUOTE_GLOB
)
(
void
)
VSB_cat
(
s
,
"
\\\\
v"
);
else
(
void
)
VSB_cat
(
s
,
"
\\
v"
);
break
;
case
'['
:
/* FALLTHROUGH */
case
']'
:
/* FALLTHROUGH */
case
'{'
:
/* FALLTHROUGH */
case
'}'
:
/* FALLTHROUGH */
case
'*'
:
if
(
how
&
VSB_QUOTE_GLOB
)
(
void
)
VSB_putc
(
s
,
'\\'
);
(
void
)
VSB_putc
(
s
,
*
q
);
break
;
default:
/* XXX: Implement VSB_QUOTE_JSON */
...
...
lib/libvarnish/vsb_test.c
0 → 100644
View file @
b0d1a40f
#include <stdio.h>
#include <string.h>
#include "vdef.h"
#include "vas.h"
#include "vsb.h"
struct
tc
{
int
how
;
const
char
*
in
;
const
char
*
out
;
};
struct
tc
tcs
[]
=
{
{
VSB_QUOTE_GLOB
,
"abcdefghijklmnopqrstvwxyz"
,
"abcdefghijklmnopqrstvwxyz"
},
{
VSB_QUOTE_GLOB
,
"ABCDEFGHIJKLMNOPQRSTVWXYZ"
,
"ABCDEFGHIJKLMNOPQRSTVWXYZ"
},
{
VSB_QUOTE_GLOB
,
"01234567789"
,
"01234567789"
},
{
VSB_QUOTE_GLOB
,
"abcde[f-g]{h,i,j}
\\
l?*xyz"
,
"abcde
\\
[f-g
\\
]
\\
{h,i,j
\\
}
\\\\
l
\\
?
\\
*xyz"
},
{
VSB_QUOTE_GLOB
,
"0123
\t
\"\r\v\n
'"
,
"0123
\\\\
t
\\\"\\\\
r
\\\\
v
\\\\
n'"
},
{
0
,
NULL
,
NULL
}
};
int
main
(
int
argc
,
char
*
argv
[])
{
int
err
=
0
;
struct
tc
*
tc
;
struct
vsb
*
vsb
;
(
void
)
argc
;
(
void
)
argv
;
vsb
=
VSB_new_auto
();
AN
(
vsb
);
for
(
tc
=
tcs
;
tc
->
in
;
tc
++
)
{
VSB_quote
(
vsb
,
tc
->
in
,
-
1
,
tc
->
how
);
VSB_finish
(
vsb
);
printf
(
"%s -> %s"
,
tc
->
in
,
VSB_data
(
vsb
));
if
(
strcmp
(
VSB_data
(
vsb
),
tc
->
out
))
{
printf
(
", but should have been %s"
,
tc
->
out
);
err
=
1
;
}
printf
(
"
\n
"
);
VSB_clear
(
vsb
);
}
VSB_delete
(
vsb
);
printf
(
"error is %i
\n
"
,
err
);
return
(
err
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment