diff options
author | Jeremy Allison <jra@samba.org> | 2012-09-11 09:06:45 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2012-09-11 20:08:37 +0200 |
commit | 7c1fd74ba5261aa447c54872e49b374b543b1831 (patch) | |
tree | a4411de169e3b0ae5ca07eab885f5f610d7537cd /lib/ldb | |
parent | 33d9a22dcb3662e8a5e33d490d2739712151677c (diff) | |
download | samba-7c1fd74ba5261aa447c54872e49b374b543b1831.tar.gz samba-7c1fd74ba5261aa447c54872e49b374b543b1831.tar.bz2 samba-7c1fd74ba5261aa447c54872e49b374b543b1831.zip |
At Michael's suggestion, factor common code into a function. My bad :-).
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Sep 11 20:08:37 CEST 2012 on sn-devel-104
Diffstat (limited to 'lib/ldb')
-rw-r--r-- | lib/ldb/common/ldb_parse.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/ldb/common/ldb_parse.c b/lib/ldb/common/ldb_parse.c index f47ef43376..33e8444be7 100644 --- a/lib/ldb/common/ldb_parse.c +++ b/lib/ldb/common/ldb_parse.c @@ -111,6 +111,13 @@ struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str) return ret; } +static bool need_encode(unsigned char cval) +{ + if (cval < 0x20 || cval > 0x7E || strchr(" *()\\&|!\"", cval)) { + return true; + } + return false; +} /* encode a blob as a RFC2254 binary string, escaping any @@ -124,8 +131,7 @@ char *ldb_binary_encode(TALLOC_CTX *mem_ctx, struct ldb_val val) unsigned char *buf = val.data; for (i=0;i<val.length;i++) { - unsigned int cval = buf[i]; - if (cval < 0x20 || cval > 0x7E || strchr(" *()\\&|!\"", buf[i])) { + if (need_encode(buf[i])) { len += 2; } } @@ -134,8 +140,7 @@ char *ldb_binary_encode(TALLOC_CTX *mem_ctx, struct ldb_val val) len = 0; for (i=0;i<val.length;i++) { - unsigned int cval = buf[i]; - if (cval < 0x20 || cval > 0x7E || strchr(" *()\\&|!\"", buf[i])) { + if (need_encode(buf[i])) { snprintf(ret+len, 4, "\\%02X", buf[i]); len += 3; } else { |