* UPD: afpd: new option "searchdb" which enables fast catalog searches
using the CNID db.
+* FIX: Case-insensitive fast search with the CNID db
Changes in 2.2alpha4
====================
#include <atalk/cnid_dbd_private.h>
#include <atalk/util.h>
#include <atalk/bstradd.h>
+#include <atalk/unicode.h>
#include "desktop.h"
#include "directory.h"
int result = AFP_OK;
struct path path;
char *rrbuf = rbuf;
+ char buffer[MAXPATHLEN +2];
+ uint16_t flags = CONV_TOLOWER;
LOG(log_debug, logtype_afpd, "catsearch_db(req pos: %u): {pos: %u, name: %s}",
*pos, cur_pos, uname);
}
if (cur_pos == 0 || *pos == 0) {
+ if (convert_charset(vol->v_volcharset,
+ vol->v_volcharset,
+ vol->v_maccharset,
+ uname,
+ strlen(uname),
+ buffer,
+ MAXPATHLEN,
+ &flags) == (size_t)-1) {
+ LOG(log_error, logtype_cnid, "catsearch_db: conversion error");
+ result = AFPERR_MISC;
+ goto catsearch_end;
+ }
+
+ LOG(log_debug, logtype_afpd, "catsearch_db: %s", buffer);
+
if ((num_matches = cnid_find(vol->v_cdb,
- uname,
+ buffer,
strlen(uname),
resbuf,
sizeof(resbuf))) == -1) {
}
#endif
- volume->v_cdb = cnid_open(volume->v_dbpath ? volume->v_dbpath : volume->v_path,
+ volume->v_cdb = cnid_open(volume->v_path,
volume->v_umask,
volume->v_cnidscheme,
flags,
#include <netatalk/endian.h>
#include <atalk/cnid_dbd_private.h>
#include <atalk/logger.h>
+#include <atalk/volinfo.h>
#include "db_param.h"
#include "dbif.h"
*/
#define DBOPTIONS (DB_CREATE | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER)
-static DBD *dbd;
+/* Global */
+struct volinfo volinfo;
+static DBD *dbd;
static int exit_sig = 0;
static void sig_exit(int signo)
logconfig = strdup(argv[4]);
setuplog(logconfig);
+ /* Load .volinfo file */
+ if (loadvolinfo(dir, &volinfo) == -1) {
+ LOG(log_error, logtype_cnid, "Cant load volinfo for \"%s\"", dir);
+ exit(EXIT_FAILURE);
+ }
+ dir = volinfo.v_dbpath;
+ if (vol_load_charsets(&volinfo) == -1) {
+ LOG(log_error, logtype_cnid, "Error loading charsets!");
+ exit(EXIT_FAILURE);
+ }
+ LOG(log_note, logtype_cnid, "db dir: \"%s\"", dir);
+
switch_to_user(dir);
/* Before we do anything else, check if there is an instance of cnid_dbd
running already and silently exit if yes. */
lockfd = get_lock();
- LOG(log_info, logtype_cnid, "Startup, DB dir %s", dir);
-
set_signal();
/* SIGINT and SIGTERM are always off, unless we are in pselect */
#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 */
+extern struct volinfo volinfo;
+
/* --------------- */
/*
* This implementation is portable, but could probably be faster by using htonl
/* --------------- */
int idxname(DB *dbp _U_, const DBT *pkey _U_, const DBT *pdata, DBT *skey)
{
+ 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);
}