]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/pack.c
New MySQL CNID backend
[netatalk.git] / etc / cnid_dbd / pack.c
index 1b4a15be588646fff8814ff9f2557abc08d02f7e..dc61ddedede532df09531bf054d7f153c1c66251 100644 (file)
@@ -1,7 +1,6 @@
 /*
- * $Id: pack.c,v 1.6 2009-10-13 22:55:37 didg Exp $
- *
  * Copyright (C) Joerg Lenneis 2003
+ * Copyright (C) Frank Lahm 2010
  * All Rights Reserved.  See COPYING.
  */
 
@@ -9,19 +8,21 @@
 #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/cnid_dbd_private.h>
+#include <atalk/unicode.h>
+#include <atalk/logger.h>
+#include <atalk/cnid_bdb_private.h>
+#include <atalk/volume.h>
 #include "pack.h"
 
+static const struct vol *volume;
+
 /* --------------- */
 /*
  *  This implementation is portable, but could probably be faster by using htonl
@@ -72,6 +73,34 @@ int devino(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
     return (0);
 }
 
+/* --------------- */
+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));
+
+    if (convert_charset(volume->v_volcharset,
+                        volume->v_volcharset,
+                        volume->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);
+}
+
+void pack_setvol(const struct vol *vol)
+{
+    volume = vol;
+}
+
 /* The equivalent to make_cnid_data in the cnid library. Non re-entrant. We
    differ from make_cnid_data in that we never return NULL, rqst->name cannot
    ever cause start[] to overflow because name length is checked in libatalk. */