Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-ece
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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-ece
Commits
aee01e64
Commit
aee01e64
authored
Sep 16, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate repetitive error-checking code.
parent
2270eafb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
59 deletions
+33
-59
vmod_ece.c
src/vmod_ece.c
+33
-59
No files found.
src/vmod_ece.c
View file @
aee01e64
...
...
@@ -74,6 +74,33 @@ VPFX(event)(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
NEEDLESS
(
return
(
0
));
}
#define CHECK_ID(ctx, id, len, ret) \
do { \
if ((id) == NULL) { \
VRT_fail((ctx), "key id is NULL"); \
return ret; \
} \
len = strlen(id); \
if ((len) > 255) { \
VRT_fail((ctx), "key id \"%.80s...\" too long " \
"(length %zu > 255)", (id), (len)); \
return ret; \
} \
} while(0)
#define CHECK_KEY(ctx, key) \
do { \
if ((key) == NULL || (key)->blob == NULL) { \
VRT_fail((ctx), "key contents are empty"); \
return; \
} \
if ((key)->len != 16) { \
VRT_fail((ctx), "illegal key length %zu (must be 16)", \
(key)->len); \
return; \
} \
} while(0)
VCL_VOID
vmod_add_key
(
VRT_CTX
,
VCL_STRING
id
,
VCL_BLOB
key
)
{
...
...
@@ -81,24 +108,8 @@ vmod_add_key(VRT_CTX, VCL_STRING id, VCL_BLOB key)
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
id
==
NULL
)
{
VRT_fail
(
ctx
,
"key id is NULL"
);
return
;
}
if
(
key
==
NULL
||
key
->
blob
==
NULL
)
{
VRT_fail
(
ctx
,
"key contents are empty"
);
return
;
}
if
(
key
->
len
!=
16
)
{
VRT_fail
(
ctx
,
"illegal key length %zu (must be 16)"
,
key
->
len
);
return
;
}
len
=
strlen
(
id
);
if
(
len
>
255
)
{
VRT_fail
(
ctx
,
"key id
\"
%.80s...
\"
too long (length %zu > 255)"
,
id
,
len
);
return
;
}
CHECK_ID
(
ctx
,
id
,
len
,);
CHECK_KEY
(
ctx
,
key
);
/* KEY_Add calls VRT_fail() on error. */
(
void
)
KEY_Add
(
ctx
,
(
uint8_t
*
)
id
,
(
uint8_t
)
len
,
key
->
blob
);
...
...
@@ -110,25 +121,8 @@ vmod_set_key(VRT_CTX, VCL_STRING id, VCL_BLOB key)
size_t
len
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
id
==
NULL
)
{
VRT_fail
(
ctx
,
"key id is NULL"
);
return
;
}
if
(
key
==
NULL
||
key
->
blob
==
NULL
)
{
VRT_fail
(
ctx
,
"key contents are empty"
);
return
;
}
if
(
key
->
len
!=
16
)
{
VRT_fail
(
ctx
,
"illegal key length %zu (must be 16)"
,
key
->
len
);
return
;
}
len
=
strlen
(
id
);
if
(
len
>
255
)
{
VRT_fail
(
ctx
,
"key id
\"
%.80s...
\"
too long (length %zu > 255)"
,
id
,
len
);
return
;
}
CHECK_ID
(
ctx
,
id
,
len
,);
CHECK_KEY
(
ctx
,
key
);
/* KEY_Set calls VRT_fail() on error. */
(
void
)
KEY_Set
(
ctx
,
(
uint8_t
*
)
id
,
(
uint8_t
)
len
,
key
->
blob
);
...
...
@@ -140,17 +134,7 @@ vmod_delete_key(VRT_CTX, VCL_STRING id)
size_t
len
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
id
==
NULL
)
{
VRT_fail
(
ctx
,
"key id is NULL"
);
return
;
}
len
=
strlen
(
id
);
if
(
len
>
255
)
{
VRT_fail
(
ctx
,
"key id
\"
%.80s...
\"
too long (length %zu > 255)"
,
id
,
len
);
return
;
}
CHECK_ID
(
ctx
,
id
,
len
,);
/* KEY_Delete calls VRT_fail() on error. */
(
void
)
KEY_Delete
(
ctx
,
(
uint8_t
*
)
id
,
(
uint8_t
)
len
);
...
...
@@ -162,17 +146,7 @@ vmod_key_exists(VRT_CTX, VCL_STRING id)
size_t
len
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
id
==
NULL
)
{
VRT_fail
(
ctx
,
"key id is NULL"
);
return
(
0
);
}
len
=
strlen
(
id
);
if
(
len
>
255
)
{
VRT_fail
(
ctx
,
"key id
\"
%.80s...
\"
too long (length %zu > 255)"
,
id
,
len
);
return
(
0
);
}
CHECK_ID
(
ctx
,
id
,
len
,
0
);
return
(
KEY_Exists
((
uint8_t
*
)
id
,
(
uint8_t
)
len
));
}
...
...
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