• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/netatalk-2.2.0/etc/cnid_dbd/
1/*
2 * $Id: dbd_delete.c,v 1.5 2009-07-12 09:21:34 franklahm Exp $
3 *
4 * Copyright (C) Joerg Lenneis 2003
5 * All Rights Reserved.  See COPYING.
6 */
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif /* HAVE_CONFIG_H */
11
12#include <string.h>
13#include <errno.h>
14#include <netatalk/endian.h>
15#include <atalk/logger.h>
16#include <atalk/cnid_dbd_private.h>
17
18#include "dbif.h"
19#include "dbd.h"
20#include "pack.h"
21
22int dbd_delete(DBD *dbd, struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply, int idx)
23{
24    DBT key;
25    int rc;
26    unsigned char *buf;
27
28    memset(&key, 0, sizeof(key));
29    rply->namelen = 0;
30
31    switch (idx) {
32    case DBIF_IDX_DEVINO:
33        buf = pack_cnid_data(rqst);
34        key.data = buf + CNID_DEVINO_OFS;
35        key.size = CNID_DEVINO_LEN;
36        if ((rc = dbif_del(dbd, DBIF_IDX_DEVINO, &key, 0)) < 0) {
37            LOG(log_error, logtype_cnid, "dbd_delete: Unable to delete entry for dev/ino: 0x%llx/0x%llx",
38                (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
39            rply->result = CNID_DBD_RES_ERR_DB;
40            return -1;
41        }
42        if (rc) {
43            LOG(log_debug, logtype_cnid, "cnid_delete: deleted dev/ino: 0x%llx/0x%llx",
44                (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
45            rply->result = CNID_DBD_RES_OK;
46        } else {
47            LOG(log_debug, logtype_cnid, "cnid_delete: dev/ino: 0x%llx/0x%llx not in database",
48                (unsigned long long)rqst->dev, (unsigned long long)rqst->ino);
49            rply->result = CNID_DBD_RES_NOTFOUND;
50        }
51        break;
52    case DBIF_IDX_DIDNAME:
53        buf = pack_cnid_data(rqst);
54        key.data = buf + CNID_DID_OFS;
55        key.size = CNID_DID_LEN + rqst->namelen + 1;
56        if ((rc = dbif_del(dbd, DBIF_IDX_DIDNAME, &key, 0)) < 0) {
57            LOG(log_error, logtype_cnid, "dbd_delete: Unable to delete entry for DID: %lu, name: %s",
58                ntohl(rqst->did), rqst->name);
59            rply->result = CNID_DBD_RES_ERR_DB;
60            return -1;
61        }
62        if (rc) {
63            LOG(log_debug, logtype_cnid, "cnid_delete: deleted DID: %lu, name: %s",
64                ntohl(rqst->did), rqst->name);
65            rply->result = CNID_DBD_RES_OK;
66        } else {
67            LOG(log_debug, logtype_cnid, "cnid_delete: DID: %lu, name: %s not in database",
68                ntohl(rqst->did), rqst->name);
69            rply->result = CNID_DBD_RES_NOTFOUND;
70        }
71        break;
72    default:
73        key.data = (void *) &rqst->cnid;
74        key.size = sizeof(rqst->cnid);
75
76        if ((rc = dbif_del(dbd, DBIF_CNID, &key, 0)) < 0) {
77            LOG(log_error, logtype_cnid, "dbd_delete: Unable to delete entry for CNID %u", ntohl(rqst->cnid));
78            rply->result = CNID_DBD_RES_ERR_DB;
79            return -1;
80        }
81        if (rc) {
82            LOG(log_debug, logtype_cnid, "cnid_delete: CNID %u deleted", ntohl(rqst->cnid));
83            rply->result = CNID_DBD_RES_OK;
84        } else {
85            LOG(log_debug, logtype_cnid, "cnid_delete: CNID %u not in database", ntohl(rqst->cnid));
86            rply->result = CNID_DBD_RES_NOTFOUND;
87        }
88    }
89
90    return 1;
91}
92