]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/cnid/cnid_resolve.c
apply parts of the netbsd build patch by Patrick Welche <prlw1@newn.cam.ac.uk>, mostl...
[netatalk.git] / libatalk / cnid / cnid_resolve.c
index b36e7ab6fa0e35e6ee36fc6acaebf4387f83ca90..86bc4789792bc7ae60e5645a1d753907847c58bb 100644 (file)
@@ -1,16 +1,17 @@
 /*
- * $Id: cnid_resolve.c,v 1.2 2001-06-29 14:14:46 rufustfirefly Exp $
+ * $Id: cnid_resolve.c,v 1.13 2002-08-30 03:12:52 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#ifdef CNID_DB
 #include <stdio.h>
 #include <string.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <syslog.h>
+#include <atalk/logger.h>
 #include <errno.h>
 
 #include <db.h>
 
 #include "cnid_private.h"
 
-/* return the did/name pair corresponding to a CNID. */
-char *cnid_resolve(void *CNID, cnid_t *id)
-{
-  CNID_private *db;
-  DBT key, data;
-
-  if (!(db = CNID) || !id || !(*id))
-    return NULL;
-
-  memset(&key, 0, sizeof(key));
-  memset(&data, 0, sizeof(data));
-
-  key.data = id;
-  key.size = sizeof(*id);
-  while (errno = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0)) {
-    if (errno == EAGAIN)
-      continue;
-
-    if (errno != DB_NOTFOUND) 
-      syslog(LOG_ERR, "cnid_resolve: can't get did/name");
-
-    *id = 0;
-    return NULL;
-  }
-  
-  memcpy(id, data.data + CNID_DEVINO_LEN, sizeof(*id));
-  return data.data + CNID_HEADER_LEN;
+/* Return the did/name pair corresponding to a CNID. */
+char *cnid_resolve(void *CNID, cnid_t *id, void *buffer, u_int32_t len) {
+    CNID_private *db;
+    DBT key, data;
+    int rc;
+
+    if (!(db = CNID) || !id || !(*id)) {
+        return NULL;
+    }
+
+    memset(&key, 0, sizeof(key));
+    memset(&data, 0, sizeof(data));
+
+    data.data = buffer;
+    data.ulen = len;
+    data.flags = DB_DBT_USERMEM;
+
+    key.data = id;
+    key.size = sizeof(cnid_t);
+    while ((rc = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
+#ifndef CNID_DB_CDB
+        if (rc == DB_LOCK_DEADLOCK) {
+            continue;
+        }
+#endif /* CNID_DB_CDB */
+
+        if (rc != DB_NOTFOUND) {
+            LOG(log_error, logtype_default, "cnid_resolve: Unable to get did/name: %s",
+                db_strerror(rc));
+        }
+
+        *id = 0;
+        return NULL;
+    }
+
+    memcpy(id, (char *)data.data + CNID_DEVINO_LEN, sizeof(cnid_t));
+#ifdef DEBUG
+    LOG(log_info, logtype_default, "cnid_resolve: Returning id = %u, did/name = %s",
+        ntohl(*id), (char *)data.data + CNID_HEADER_LEN);
+#endif
+    return (char *)data.data + CNID_HEADER_LEN;
 }
+#endif /* CNID_DB */