diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2009-04-17 16:11:33 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2009-04-17 16:11:33 +0000 |
commit | 9b91b81870d4b792c9e826349c34d98b7a835e20 (patch) | |
tree | 44283bfd7b9167bccd3e02dbff1cf192b7b3df58 /src/pluto/defs.c | |
parent | c04e75487ffab245d35461b1d84eddd1e1408ba8 (diff) | |
download | strongswan-9b91b81870d4b792c9e826349c34d98b7a835e20.tar.bz2 strongswan-9b91b81870d4b792c9e826349c34d98b7a835e20.tar.xz |
ported most of the libstrongswan chunk_t macros to pluto
Diffstat (limited to 'src/pluto/defs.c')
-rw-r--r-- | src/pluto/defs.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/pluto/defs.c b/src/pluto/defs.c index e2f65e8c4..c6dde5a62 100644 --- a/src/pluto/defs.c +++ b/src/pluto/defs.c @@ -29,8 +29,27 @@ #include "log.h" #include "whack.h" /* for RC_LOG_SERIOUS */ +/** + * Empty chunk. + */ const chunk_t chunk_empty = { NULL, 0 }; +/** + * Create a clone of a chunk pointing to "ptr" + */ +chunk_t chunk_create_clone(u_char *ptr, chunk_t chunk) +{ + chunk_t clone = chunk_empty; + + if (chunk.ptr && chunk.len > 0) + { + clone.ptr = ptr; + clone.len = chunk.len; + memcpy(clone.ptr, chunk.ptr, chunk.len); + } + return clone; +} + bool all_zero(const unsigned char *m, size_t len) { @@ -86,17 +105,17 @@ concatenate_paths(const char *a, const char *b) /* compare two chunks, returns zero if a equals b * negative/positive if a is earlier/later in the alphabet than b */ -int -cmp_chunk(chunk_t a, chunk_t b) +int chunk_compare(chunk_t a, chunk_t b) { - int cmp_len, len, cmp_value; - - cmp_len = a.len - b.len; - len = (cmp_len < 0)? a.len : b.len; - cmp_value = memcmp(a.ptr, b.ptr, len); + int compare_len = a.len - b.len; + int len = (compare_len < 0)? a.len : b.len; - return (cmp_value == 0)? cmp_len : cmp_value; -}; + if (compare_len != 0 || len == 0) + { + return compare_len; + } + return memcmp(a.ptr, b.ptr, len); +} /* moves a chunk to a memory position, chunk is freed afterwards * position pointer is advanced after the insertion point @@ -107,7 +126,7 @@ mv_chunk(u_char **pos, chunk_t content) if (content.len > 0) { chunkcpy(*pos, content); - freeanychunk(content); + free(content.ptr); } } |