Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-blobcode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-blobcode
Commits
8859a614
Commit
8859a614
authored
Jul 08, 2015
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first bits working
parent
807eb5c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
5 deletions
+128
-5
test01.vtc
src/tests/test01.vtc
+7
-2
vmod_convert.c
src/vmod_convert.c
+121
-3
No files found.
src/tests/test01.vtc
View file @
8859a614
# looks like -*- perl -*-
varnishtest
"Test convert vmod"
server
s1
{
...
...
@@ -9,14 +11,17 @@ varnish v1 -vcl+backend {
import
convert
from
"${vmod_topbuild}/src/.libs/libvmod_convert.so"
;
sub
vcl_deliver
{
set resp.http.hello = convert.hello("World");
set
resp
.
http
.
hex
=
convert
.
transcode
(
IDENTITY
,
HEXLC
,
req
.
url
+
"Hel"
+
"lo "
+
""
+
"world"
+
req
.
url
);
}
}
-
start
client
c1
{
txreq
-
url
"/"
rxresp
expect resp.http.he
llo == "Hello, World
"
expect
resp
.
http
.
he
x
==
"2f48656c6c6f20776f726c642f
"
}
client
c1
-
run
src/vmod_convert.c
View file @
8859a614
...
...
@@ -23,6 +23,101 @@ static const struct vmod_priv const null_blob[1] =
}
};
static
inline
char
hexnibblelc
(
char
c
)
{
return
((
c
>
9
)
?
(
'a'
+
(
c
-
0xa
))
:
(
'0'
+
c
));
}
/*
* en/decoders need to work for the string_list vargs case (implicit length) as
* well as for the blob case (explicit length). Fortunately, the blob case is
* not varadic, so we can assume just one length argument _or_ varags
*
* rblob: alloc additional whitespace so any result can also be (safely)
* used as a string.
*/
static
VCL_BLOB
hex_encode_va
(
struct
ws
*
ws
,
struct
vmod_priv
*
rblob
,
const
ssize_t
len
,
const
char
*
in
,
va_list
va
)
{
char
*
p
=
ws
->
f
;
char
*
out
=
p
;
// should be const, but (struct vmod_priv).priv isnt
const
char
*
e
=
out
+
WS_Reserve
(
ws
,
0
);
ssize_t
insz
;
int
i
;
AN
(
rblob
);
if
(
in
==
vrt_magic_string_end
)
goto
nodata
;
if
(
len
!=
-
1
)
insz
=
len
;
else
if
(
in
==
NULL
)
insz
=
0
;
else
insz
=
strlen
(
in
);
fprintf
(
stderr
,
"magic_string_end %p
\n
"
,
vrt_magic_string_end
);
do
{
if
(
insz
==
0
)
goto
next
;
fprintf
(
stderr
,
"debug in %p %s
\n
"
,
in
,
in
);
// p + 2 includes terminating null byte
for
(
i
=
0
;
i
<
insz
&&
p
+
2
<
e
;
i
++
)
{
*
p
++
=
hexnibblelc
((
in
[
i
]
&
0xf0
)
>>
4
);
*
p
++
=
hexnibblelc
(
in
[
i
]
&
0x0f
);
}
if
(
i
!=
insz
)
goto
err
;
next:
in
=
va_arg
(
va
,
const
char
*
);
if
(
in
==
vrt_magic_string_end
)
break
;
insz
=
(
in
!=
NULL
)
?
strlen
(
in
)
:
0
;
}
while
(
1
);
if
(
p
==
out
)
goto
nodata
;
*
p
++
=
'\0'
;
assert
(
p
<
e
);
rblob
->
priv
=
out
;
rblob
->
len
=
p
-
out
-
1
;
rblob
->
free
=
NULL
;
WS_ReleaseP
(
ws
,
p
);
return
rblob
;
nodata:
WS_Release
(
ws
,
0
);
return
null_blob
;
err:
WS_Release
(
ws
,
0
);
return
NULL
;
}
static
VCL_BLOB
hex_encode
(
struct
ws
*
ws
,
struct
vmod_priv
*
rblob
,
const
ssize_t
len
,
const
char
*
in
,
...)
{
va_list
ap
;
VCL_BLOB
r
;
va_start
(
ap
,
in
);
r
=
hex_encode_va
(
ws
,
rblob
,
len
,
in
,
ap
);
va_end
(
ap
);
return
r
;
}
/* Functions */
VCL_BLOB
...
...
@@ -36,18 +131,41 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, const char *p, ...) {
VCL_STRING
vmod_encode
(
VRT_CTX
,
VCL_ENUM
encs
,
VCL_BLOB
b
)
{
enum
encoding
enc
=
parse_encoding
(
encs
);
struct
vmod_priv
tmp
[
1
];
const
struct
vmod_priv
*
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
assert
(
enc
!=
_INVALID
);
return
"XXX"
;
assert
(
enc
==
HEXLC
);
// XXX
r
=
hex_encode
(
ctx
->
ws
,
tmp
,
b
->
len
,
b
->
priv
,
vrt_magic_string_end
);
if
(
r
==
NULL
)
return
NULL
;
return
r
->
priv
;
}
VCL_STRING
VCL_STRING
__match_proto__
(
td_convert_transcode
)
vmod_transcode
(
VRT_CTX
,
VCL_ENUM
decs
,
VCL_ENUM
encs
,
const
char
*
p
,
...)
{
enum
encoding
dec
=
parse_encoding
(
decs
);
enum
encoding
enc
=
parse_encoding
(
encs
);
struct
vmod_priv
tmp
[
1
];
va_list
ap
;
VCL_BLOB
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
assert
(
dec
!=
_INVALID
);
assert
(
enc
!=
_INVALID
);
return
p
;
// XXX DO THE DECODE BIT
assert
(
enc
==
HEXLC
);
// XXX
va_start
(
ap
,
p
);
r
=
hex_encode_va
(
ctx
->
ws
,
tmp
,
-
1
,
p
,
ap
);
va_end
(
ap
);
if
(
r
==
NULL
)
return
NULL
;
return
r
->
priv
;
}
VCL_BLOB
vmod_transcode_blob
(
VRT_CTX
,
VCL_ENUM
decs
,
VCL_ENUM
encs
,
VCL_BLOB
b
)
{
...
...
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