]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/pack.c
Merge master
[netatalk.git] / etc / cnid_dbd / pack.c
index eb90d85809b5f45af70e5736e7990e8d1beb26eb..69f5fa627e7125c157a273448bf948a374679566 100644 (file)
@@ -8,19 +8,22 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-#include <netatalk/endian.h>
+#include <arpa/inet.h>
 
 #include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
+#include <inttypes.h>
 #include <sys/param.h>
-#include <sys/cdefs.h>
 #include <db.h>
 
+#include <atalk/unicode.h>
+#include <atalk/volinfo.h>
+#include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 #include "pack.h"
 
+/* in main.c for `cnid_dbd` or cmd_dbd.c for `dbd` */
+extern struct volinfo volinfo;
+
 /* --------------- */
 /*
  *  This implementation is portable, but could probably be faster by using htonl
@@ -74,9 +77,23 @@ int devino(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
 /* --------------- */
 int idxname(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
 {
+    static char buffer[MAXPATHLEN +2];
+    uint16_t flags = CONV_TOLOWER;
     memset(skey, 0, sizeof(DBT));
-    skey->data = (char *)pdata->data + CNID_NAME_OFS;
-    skey->size = strlen((char *)skey->data) + 1;
+
+    if (convert_charset(volinfo.v_volcharset,
+                        volinfo.v_volcharset,
+                        volinfo.v_maccharset,
+                        (char *)pdata->data + CNID_NAME_OFS,
+                        strlen((char *)pdata->data + CNID_NAME_OFS),
+                        buffer,
+                        MAXPATHLEN,
+                        &flags) == (size_t)-1) {
+        LOG(log_error, logtype_cnid, "idxname: conversion error");
+    }
+
+    skey->data = buffer;
+    skey->size = strlen(skey->data);
     return (0);
 }