]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/nextid.c
Delete incorrect comments
[openldap] / servers / slapd / back-bdb / nextid.c
1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21
22 #include "back-bdb.h"
23
24 int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *out )
25 {
26         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
27
28         ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
29         *out = ++bdb->bi_lastid;
30         ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
31
32         return 0;
33 }
34
35 int bdb_last_id( BackendDB *be, DB_TXN *tid )
36 {
37         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
38         int rc;
39         ID id = 0;
40         DBT key, data;
41         DBC *cursor;
42
43         DBTzero( &key );
44         key.flags = DB_DBT_USERMEM;
45         key.data = (char *) &id;
46         key.ulen = sizeof( id );
47
48         DBTzero( &data );
49         data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
50
51         /* Get a read cursor */
52         rc = bdb->bi_id2entry->bdi_db->cursor( bdb->bi_id2entry->bdi_db,
53                 tid, &cursor, 0 );
54
55         if (rc == 0) {
56                 rc = cursor->c_get(cursor, &key, &data, DB_LAST);
57                 cursor->c_close(cursor);
58         }
59
60         switch(rc) {
61         case DB_NOTFOUND:
62                 id = 0;
63                 rc = 0;
64                 /* FALLTHROUGH */
65         case 0:
66                 break;
67
68         default:
69                 Debug( LDAP_DEBUG_ANY,
70                         "=> bdb_last_id: get failed: %s (%d)\n",
71                         db_strerror(rc), rc, 0 );
72                 goto done;
73         }
74
75         bdb->bi_lastid = id;
76
77 done:
78         return rc;
79 }