summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb_utf8.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-01 09:45:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:38 -0500
commit0dad5a34273bf5cadcfd4a36d69bdffbf69eb073 (patch)
tree78ddbe4e053287a0e7a0300e945627ce4b24bc29 /source4/lib/ldb/common/ldb_utf8.c
parenta2b6d47390a07f0d2a737d17144f825a9733d5bf (diff)
downloadsamba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.tar.gz
samba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.tar.bz2
samba-0dad5a34273bf5cadcfd4a36d69bdffbf69eb073.zip
r435: a major upgrade for ldb
- added the ability to mark record attributes as being CASE_INSENSITIVE, WILDCARD or INTEGER. - added the ability to support objectclass subclasses, and to search by a parent class - added internal support for case insensitive versus case sensitive indexing (not UTF8 compliant yet) - cleaned up a number of const warnings - added a number of helper functions for fetching integers, strings and doubles - added a in-memory cache for important database properties, supported by a database sequence number - changed some variable names to avoid conflicts with C++ (This used to be commit f2bf06f25c2e6c744817711c7bedbd1d3b52f994)
Diffstat (limited to 'source4/lib/ldb/common/ldb_utf8.c')
-rw-r--r--source4/lib/ldb/common/ldb_utf8.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c
new file mode 100644
index 0000000000..7767b0955e
--- /dev/null
+++ b/source4/lib/ldb/common/ldb_utf8.c
@@ -0,0 +1,87 @@
+/*
+ ldb database library
+
+ Copyright (C) Andrew Tridgell 2004
+
+ ** NOTE! The following LGPL license applies to the ldb
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ * Name: ldb
+ *
+ * Component: ldb utf8 handling
+ *
+ * Description: case folding and case comparison for UTF8 strings
+ *
+ * Author: Andrew Tridgell
+ */
+
+#include "includes.h"
+
+/*
+ TODO:
+ a simple case folding function - will be replaced by a UTF8 aware function later
+*/
+char *ldb_casefold(const char *s)
+{
+ int i;
+ char *ret = strdup(s);
+ if (!s) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ for (i=0;ret[i];i++) {
+ ret[i] = toupper(ret[i]);
+ }
+ return ret;
+}
+
+/*
+ a caseless compare, optimised for 7 bit
+ TODO: doesn't yet handle UTF8
+*/
+static int ldb_caseless_cmp(const char *s1, const char *s2)
+{
+ int i;
+ for (i=0;s1[i] != 0;i++) {
+ int c1 = toupper(s1[i]), c2 = toupper(s2[i]);
+ if (c1 != c2) {
+ return c1 - c2;
+ }
+ }
+ return s2[i];
+}
+
+/*
+ compare two basedn fields
+ return 0 for match
+*/
+int ldb_dn_cmp(const char *dn1, const char *dn2)
+{
+ return ldb_caseless_cmp(dn1, dn2);
+}
+
+/*
+ compare two attributes
+ return 0 for match
+*/
+int ldb_attr_cmp(const char *dn1, const char *dn2)
+{
+ return ldb_caseless_cmp(dn1, dn2);
+}