Fix the mess with ldb includes.
[metze/samba/wip.git] / source4 / lib / ldb / common / ldb_utf8.c
index 743e976e84e000696db21ec2e8ef30f00c74b6e2..0a8a89ac1d14e2d48a1248f613c8a7e1c4f2f20e 100644 (file)
@@ -10,7 +10,7 @@
    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.
+   version 3 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
@@ -18,8 +18,7 @@
    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
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
@@ -32,8 +31,8 @@
  *  Author: Andrew Tridgell
  */
 
-#include "includes.h"
-#include "ldb/include/includes.h"
+#include "ldb_private.h"
+#include "system/locale.h"
 
 
 /*
   function to handle utf8 caseless comparisons
  */
 void ldb_set_utf8_fns(struct ldb_context *ldb,
-                       void *context,
-                       int (*cmp)(void *, const char *, const char *),
-                       char *(*casefold)(void *, void *, const char *))
+                     void *context,
+                     char *(*casefold)(void *, void *, const char *, size_t))
 {
        if (context)
                ldb->utf8_fns.context = context;
-       if (cmp)
-               ldb->utf8_fns.caseless_cmp = cmp;
        if (casefold)
                ldb->utf8_fns.casefold = casefold;
 }
@@ -57,10 +53,10 @@ void ldb_set_utf8_fns(struct ldb_context *ldb,
   a simple case folding function
   NOTE: does not handle UTF8
 */
-char *ldb_casefold_default(void *context, void *mem_ctx, const char *s)
+char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n)
 {
        int i;
-       char *ret = talloc_strdup(mem_ctx, s);
+       char *ret = talloc_strndup(mem_ctx, s, n);
        if (!s) {
                errno = ENOMEM;
                return NULL;
@@ -71,29 +67,14 @@ char *ldb_casefold_default(void *context, void *mem_ctx, const char *s)
        return ret;
 }
 
-/*
-  a caseless compare, optimised for 7 bit
-  NOTE: doesn't handle UTF8
-*/
-
-int ldb_caseless_cmp_default(void *context, const char *s1, const char *s2)
-{
-       return strcasecmp(s1,s2);
-}
-
 void ldb_set_utf8_default(struct ldb_context *ldb)
 {
-       ldb_set_utf8_fns(ldb, NULL, ldb_caseless_cmp_default, ldb_casefold_default);
-}
-
-char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s)
-{
-       return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s);
+       ldb_set_utf8_fns(ldb, NULL, ldb_casefold_default);
 }
 
-int ldb_caseless_cmp(struct ldb_context *ldb, const char *s1, const char *s2)
+char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s, size_t n)
 {
-       return ldb->utf8_fns.caseless_cmp(ldb->utf8_fns.context, s1, s2);
+       return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s, n);
 }
 
 /*
@@ -128,22 +109,11 @@ int ldb_valid_attr_name(const char *s)
        return 1;
 }
 
-/*
-  compare two attribute names
-  attribute names are restricted by rfc2251 so using
-  strcasecmp and toupper here is ok.
-  return 0 for match
-*/
-int ldb_attr_cmp(const char *attr1, const char *attr2)
-{
-       return strcasecmp(attr1, attr2);
-}
-
 char *ldb_attr_casefold(void *mem_ctx, const char *s)
 {
        int i;
        char *ret = talloc_strdup(mem_ctx, s);
-       if (!s) {
+       if (!ret) {
                errno = ENOMEM;
                return NULL;
        }