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
ebbc84ee
Commit
ebbc84ee
authored
Jan 04, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added identity encode and decode, also fixed wb_append() and wb_printf
parent
7f59f107
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
4 deletions
+95
-4
test01.vtc
src/tests/test01.vtc
+15
-0
vmod_convert.c
src/vmod_convert.c
+66
-3
wb.c
src/wb.c
+13
-1
wb.h
src/wb.h
+1
-0
No files found.
src/tests/test01.vtc
View file @
ebbc84ee
...
...
@@ -15,6 +15,17 @@ varnish v1 -vcl+backend {
convert
.
transcode
(
IDENTITY
,
HEXLC
,
req
.
url
+
"Hel"
+
"lo "
+
""
+
"world"
+
req
.
url
);
set
resp
.
http
.
id
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
IDENTITY
,
"The quick brown fox jumps over the lazy dog"
));
set
resp
.
http
.
idlist
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
IDENTITY
,
""
+
req
.
url
+
"The quick "
+
"brown fox jumps over "
+
""
+
"the lazy dog"
+
""
+
req
.
url
+
""
));
set
resp
.
http
.
idempty
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
IDENTITY
,
""
));
set
resp
.
http
.
idemptylist
=
convert
.
encode
(
IDENTITY
,
convert
.
decode
(
IDENTITY
,
""
+
""
+
""
));
}
}
-
start
...
...
@@ -22,6 +33,10 @@ client c1 {
txreq
-
url
"/"
rxresp
expect
resp
.
http
.
hex
==
"2f48656c6c6f20776f726c642f"
expect
resp
.
http
.
id
==
"The quick brown fox jumps over the lazy dog"
expect
resp
.
http
.
idlist
==
"/The quick brown fox jumps over the lazy dog/"
expect
resp
.
http
.
idempty
==
""
expect
resp
.
http
.
idemptylist
==
""
}
client
c1
-
run
src/vmod_convert.c
View file @
ebbc84ee
...
...
@@ -79,6 +79,62 @@ event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e event)
return
(
0
);
}
static
VCL_BLOB
id_encode
(
struct
ws
*
ws
,
struct
vmod_priv
*
rblob
,
const
char
*
in
,
size_t
inlen
)
{
struct
wb_s
wb
;
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
AN
(
rblob
);
if
(
in
==
NULL
||
inlen
==
0
)
return
null_blob
;
if
(
!
wb_create
(
ws
,
&
wb
)
||
!
wb_append
(
&
wb
,
in
,
inlen
))
return
NULL
;
(
void
)
wb_finish_blob
(
&
wb
,
rblob
);
assert
(
rblob
->
len
>
0
);
return
rblob
;
}
static
VCL_BLOB
id_decode
(
struct
ws
*
ws
,
struct
vmod_priv
*
rblob
,
const
char
*
p
,
va_list
ap
)
{
const
char
*
next
;
struct
wb_s
wb
;
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
AN
(
rblob
);
if
(
p
==
vrt_magic_string_end
)
return
null_blob
;
do
{
next
=
va_arg
(
ap
,
const
char
*
);
}
while
(
*
next
==
'\0'
||
next
==
NULL
);
if
(
next
==
vrt_magic_string_end
&&
(
p
==
NULL
||
*
p
==
'\0'
))
return
null_blob
;
if
(
!
wb_create
(
ws
,
&
wb
)
||
!
wb_append
(
&
wb
,
p
,
-
1
))
return
NULL
;
while
(
next
!=
vrt_magic_string_end
)
{
if
(
!
wb_append
(
&
wb
,
next
,
-
1
))
{
wb_reset
(
&
wb
);
return
NULL
;
}
do
{
next
=
va_arg
(
ap
,
const
char
*
);
}
while
(
next
==
NULL
||
*
next
==
'\0'
);
}
(
void
)
wb_finish_blob
(
&
wb
,
rblob
);
if
(
rblob
->
len
==
0
)
return
null_blob
;
return
rblob
;
}
/*
* Base64-encode *in (size: inlen) into the blob supplied as rblob. If
* there is insufficient space, it will bail out and return
...
...
@@ -262,10 +318,17 @@ hex_encode(struct ws *ws, struct vmod_priv *rblob, const ssize_t len,
VCL_BLOB
vmod_decode
(
VRT_CTX
,
VCL_ENUM
decs
,
const
char
*
p
,
...)
{
enum
encoding
dec
=
parse_encoding
(
decs
);
va_list
ap
;
struct
vmod_priv
tmp
[
1
];
VCL_BLOB
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
assert
(
dec
!=
_INVALID
);
return
null_blob
;
assert
(
dec
==
IDENTITY
);
// XXX
va_start
(
ap
,
p
);
r
=
id_decode
(
ctx
->
ws
,
tmp
,
p
,
ap
);
va_end
(
ap
);
return
r
;
}
VCL_STRING
...
...
@@ -279,7 +342,7 @@ vmod_encode(VRT_CTX, VCL_ENUM encs, VCL_BLOB b) {
switch
(
enc
)
{
case
IDENTITY
:
// XXX
r
=
id_encode
(
ctx
->
ws
,
tmp
,
b
->
priv
,
b
->
len
);
break
;
case
BASE64
:
case
BASE64URL
:
...
...
src/wb.c
View file @
ebbc84ee
...
...
@@ -57,7 +57,7 @@ wb_reset(struct wb_s *wb)
}
bool
wb_
append
(
struct
wb_s
*
wb
,
const
char
*
format
,
...)
wb_
printf
(
struct
wb_s
*
wb
,
const
char
*
format
,
...)
{
int
len
;
va_list
ap
;
...
...
@@ -77,6 +77,18 @@ wb_append(struct wb_s *wb, const char *format, ...)
return
true
;
}
bool
wb_append
(
struct
wb_s
*
wb
,
const
char
*
p
,
int
len
)
{
if
(
len
==
-
1
)
len
=
strlen
(
p
);
if
(
len
>=
wb_space
(
wb
))
return
false
;
memcpy
(
wb
->
w
,
p
,
len
);
wb_advance
(
wb
,
len
);
return
true
;
}
/*
* release varnish workspace
*
...
...
src/wb.h
View file @
ebbc84ee
...
...
@@ -47,5 +47,6 @@ wb_advanceP(struct wb_s *wb, char *w) {
char
*
wb_create
(
struct
ws
*
ws
,
struct
wb_s
*
wb
);
void
wb_reset
(
struct
wb_s
*
wb
);
bool
wb_printf
(
struct
wb_s
*
wb
,
const
char
*
format
,
...);
bool
wb_append
(
struct
wb_s
*
wb
,
const
char
*
p
,
int
len
);
char
*
wb_finish
(
struct
wb_s
*
wb
,
ssize_t
*
l
);
struct
vmod_priv
*
wb_finish_blob
(
struct
wb_s
*
wb
,
struct
vmod_priv
*
blob
);
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