/*
- * $Id: pack.c,v 1.5 2009-05-04 09:09:43 franklahm Exp $
- *
* Copyright (C) Joerg Lenneis 2003
+ * Copyright (C) Frank Lahm 2010
* All Rights Reserved. See COPYING.
*/
#include <netatalk/endian.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
}
/* --------------- */
-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;
}
/* --------------- */
-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;
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(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);
+}
+
/* 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. */