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
f16546e7
Commit
f16546e7
authored
Jan 11, 2016
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encapsulate en-/decode into static functions in the main source
parent
253e7c8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
60 deletions
+50
-60
vmod_convert.c
src/vmod_convert.c
+50
-60
No files found.
src/vmod_convert.c
View file @
f16546e7
...
...
@@ -42,18 +42,6 @@ static const struct vmod_priv const null_blob[1] =
}
};
int
__match_proto__
(
vmod_event_f
)
event
(
VRT_CTX
,
struct
vmod_priv
*
priv
,
enum
vcl_event_e
event
)
{
(
void
)
priv
;
if
(
event
!=
VCL_EVENT_LOAD
)
return
0
;
base64_init
();
return
(
0
);
}
static
inline
VCL_STRING
concat_va
(
struct
ws
*
ws
,
const
char
*
p
,
va_list
ap
)
{
...
...
@@ -121,9 +109,53 @@ decode_l_va(enum encoding dec, const char * const p, va_list ap)
}
}
static
inline
ssize_t
__match_proto__
(
decode_f
)
decode
(
const
enum
encoding
dec
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
const
char
*
restrict
const
p
,
va_list
ap
)
{
switch
(
dec
)
{
case
IDENTITY
:
return
id_decode
(
dec
,
buf
,
maxlen
,
p
,
ap
);
default:
WRONG
(
"Illegal decoding"
);
}
}
static
inline
ssize_t
__match_proto__
(
encode_f
)
encode
(
const
enum
encoding
enc
,
char
*
restrict
const
buf
,
const
size_t
maxlen
,
const
char
*
restrict
const
in
,
const
size_t
inlen
)
{
switch
(
enc
)
{
case
IDENTITY
:
return
id_encode
(
enc
,
buf
,
maxlen
,
in
,
inlen
);
case
BASE64
:
case
BASE64URL
:
case
BASE64URLNOPAD
:
return
base64_encode
(
enc
,
buf
,
maxlen
,
in
,
inlen
);
case
HEX
:
case
HEXLC
:
return
hex_encode
(
enc
,
buf
,
maxlen
,
in
,
inlen
);
default:
WRONG
(
"Illegal encoding"
);
}
}
/* init / event handler */
int
__match_proto__
(
vmod_event_f
)
event
(
VRT_CTX
,
struct
vmod_priv
*
priv
,
enum
vcl_event_e
event
)
{
(
void
)
priv
;
if
(
event
!=
VCL_EVENT_LOAD
)
return
0
;
base64_init
();
return
(
0
);
}
/* Functions */
VCL_BLOB
VCL_BLOB
__match_proto__
(
td_convert_decode
)
vmod_decode
(
VRT_CTX
,
VCL_ENUM
decs
,
const
char
*
p
,
...)
{
enum
encoding
dec
=
parse_encoding
(
decs
);
va_list
ap
;
...
...
@@ -133,8 +165,6 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, const char *p, ...) {
ssize_t
len
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
assert
(
dec
!=
_INVALID
);
assert
(
dec
==
IDENTITY
);
// XXX
snap
=
WS_Snapshot
(
ctx
->
ws
);
if
((
b
=
WS_Alloc
(
ctx
->
ws
,
sizeof
(
struct
vmod_priv
)))
==
NULL
)
...
...
@@ -146,7 +176,7 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, const char *p, ...) {
buf
=
wb_buf
(
&
wb
);
va_start
(
ap
,
p
);
len
=
id_
decode
(
dec
,
buf
,
wb_space
(
&
wb
),
p
,
ap
);
len
=
decode
(
dec
,
buf
,
wb_space
(
&
wb
),
p
,
ap
);
va_end
(
ap
);
if
(
len
==
-
1
)
{
...
...
@@ -167,7 +197,7 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, const char *p, ...) {
return
b
;
}
VCL_STRING
VCL_STRING
__match_proto__
(
td_convert_encode
)
vmod_encode
(
VRT_CTX
,
VCL_ENUM
encs
,
VCL_BLOB
b
)
{
enum
encoding
enc
=
parse_encoding
(
encs
);
struct
wb_s
wb
;
...
...
@@ -179,25 +209,7 @@ vmod_encode(VRT_CTX, VCL_ENUM encs, VCL_BLOB b) {
if
(
wb_create
(
ctx
->
ws
,
&
wb
)
==
NULL
)
return
NULL
;
switch
(
enc
)
{
case
IDENTITY
:
len
=
id_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
b
->
priv
,
b
->
len
);
break
;
case
BASE64
:
case
BASE64URL
:
case
BASE64URLNOPAD
:
len
=
base64_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
b
->
priv
,
b
->
len
);
break
;
case
HEX
:
case
HEXLC
:
len
=
hex_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
b
->
priv
,
b
->
len
);
break
;
default:
WRONG
(
"Illegal encoding"
);
}
len
=
encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
b
->
priv
,
b
->
len
);
if
(
len
==
-
1
)
{
wb_reset
(
&
wb
);
...
...
@@ -243,13 +255,7 @@ vmod_transcode(VRT_CTX, VCL_ENUM decs, VCL_ENUM encs, const char *p, ...) {
char
buf
[
l
];
va_start
(
ap
,
p
);
switch
(
dec
)
{
case
IDENTITY
:
len
=
id_decode
(
dec
,
buf
,
l
,
p
,
ap
);
break
;
default:
WRONG
(
"Illegal decoding"
);
}
len
=
decode
(
dec
,
buf
,
l
,
p
,
ap
);
va_end
(
ap
);
if
(
len
==
-
1
)
...
...
@@ -258,23 +264,7 @@ vmod_transcode(VRT_CTX, VCL_ENUM decs, VCL_ENUM encs, const char *p, ...) {
if
(
wb_create
(
ctx
->
ws
,
&
wb
)
==
NULL
)
return
NULL
;
switch
(
enc
)
{
case
IDENTITY
:
len
=
id_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
buf
,
len
);
break
;
case
HEX
:
case
HEXLC
:
len
=
hex_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
buf
,
len
);
break
;
case
BASE64
:
case
BASE64URL
:
case
BASE64URLNOPAD
:
len
=
base64_encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
buf
,
len
);
break
;
default:
WRONG
(
"Illegal encoding"
);
}
len
=
encode
(
enc
,
wb_buf
(
&
wb
),
wb_space
(
&
wb
),
buf
,
len
);
if
(
len
==
-
1
)
{
wb_reset
(
&
wb
);
return
NULL
;
...
...
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