]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/pack.c
New MySQL CNID backend
[netatalk.git] / etc / cnid_dbd / pack.c
index 02a73075f953d295f763b629d43f99794566f060..dc61ddedede532df09531bf054d7f153c1c66251 100644 (file)
@@ -1,7 +1,6 @@
 /*
- * $Id: pack.c,v 1.4 2009-04-28 13:01:24 franklahm Exp $
- *
  * Copyright (C) Joerg Lenneis 2003
+ * Copyright (C) Frank Lahm 2010
  * All Rights Reserved.  See COPYING.
  */
 
@@ -9,25 +8,20 @@
 #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"
 
-#ifdef DEBUG
-/*
- *  Auxiliary stuff for stringify_devino. See comments below.
- */
-static char hexchars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-#endif
+static const struct vol *volume;
 
 /* --------------- */
 /*
@@ -56,10 +50,7 @@ static void pack_devino(unsigned char *buf, dev_t dev, ino_t ino)
 }
 
 /* --------------- */
-int didname(dbp, pkey, pdata, skey)
-DB *dbp _U_;
-const DBT *pkey _U_, *pdata;
-DBT *skey;
+int didname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey)
 {
 int len;
  
@@ -74,10 +65,7 @@ int len;
 }
  
 /* --------------- */
-int devino(dbp, pkey, pdata, skey)
-DB *dbp _U_;
-const DBT *pkey _U_, *pdata;
-DBT *skey;
+int devino(DB *dbp _U_, const DBT *pkey _U_,  const DBT *pdata, DBT *skey)
 {
     memset(skey, 0, sizeof(DBT));
     skey->data = (char *)pdata->data + CNID_DEVINO_OFS;
@@ -85,6 +73,34 @@ 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. */
@@ -111,43 +127,3 @@ unsigned char *pack_cnid_data(struct cnid_dbd_rqst *rqst)
     return start;
 }
 
-#ifdef DEBUG
-
-/*
- *  Whack 4 or 8 byte dev/ino numbers into something printable for DEBUG
- *  logging. This function must not be used more that once per printf() style
- *  invocation. This (or something improved) should probably migrate to
- *  libatalk logging. Checking for printf() %ll support would be an alternative.
- */
-
-char *stringify_devino(dev_t dev, ino_t ino)
-{
-    static char rbuf[CNID_DEV_LEN * 2 + 1 + CNID_INO_LEN * 2 + 1] = {0};
-    char buf[CNID_DEV_LEN + CNID_INO_LEN];
-    char *c1;
-    char *c2;
-    char *middle;
-    char *end;
-    int   ci;
-
-    pack_devino((unsigned char *)buf, dev, ino);
-    
-    middle = buf + CNID_DEV_LEN;
-    end = buf + CNID_DEV_LEN + CNID_INO_LEN;
-    c1  = buf;
-    c2  = rbuf;  
-    
-    while (c1 < end) {
-       if (c1 == middle) {
-           *c2 = '/';
-           c2++;
-       }    
-       ci = *c1;
-       c2[0] = hexchars[(ci & 0xf0) >> 4];
-       c2[1] = hexchars[ci & 0x0f];
-       c1++;
-       c2 += 2;
-    }
-    return rbuf;
-}
-#endif