]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
comment cleanup
[openldap] / servers / slapd / back-bdb / operational.c
1 /* operational.c - bdb backend operational attributes function */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/string.h>
12 #include <ac/socket.h>
13
14 #include "slap.h"
15 #include "back-bdb.h"
16 #include "external.h"
17
18 /*
19  * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE
20  * if the entry has children or not.
21  */
22 int
23 bdb_hasSubordinates(
24         Operation       *op,
25         Entry           *e,
26         int             *hasSubordinates )
27 {
28         int             rc;
29         
30         assert( e );
31
32 retry:
33         rc = bdb_cache_children( op, NULL, e );
34         
35         switch( rc ) {
36         case DB_LOCK_DEADLOCK:
37         case DB_LOCK_NOTGRANTED:
38                 ldap_pvt_thread_yield();
39                 goto retry;
40
41         case 0:
42                 *hasSubordinates = LDAP_COMPARE_TRUE;
43                 break;
44
45         case DB_NOTFOUND:
46                 *hasSubordinates = LDAP_COMPARE_FALSE;
47                 rc = LDAP_SUCCESS;
48                 break;
49
50         default:
51 #ifdef NEW_LOGGING
52                 LDAP_LOG ( OPERATION, ERR, 
53                         "=> bdb_hasSubordinates: has_children failed: %s (%d)\n",
54                         db_strerror(rc), rc, 0 );
55 #else
56                 Debug(LDAP_DEBUG_ARGS, 
57                         "<=- bdb_hasSubordinates: has_children failed: %s (%d)\n", 
58                         db_strerror(rc), rc, 0 );
59 #endif
60                 rc = LDAP_OTHER;
61         }
62
63         return rc;
64 }
65
66 /*
67  * sets the supported operational attributes (if required)
68  */
69 int
70 bdb_operational(
71         Operation       *op,
72         SlapReply       *rs,
73         int             opattrs,
74         Attribute       **a )
75 {
76         Attribute       **aa = a;
77         
78         assert( rs->sr_entry );
79
80         if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, rs->sr_attrs ) ) {
81                 int     hasSubordinates;
82
83                 rs->sr_err = bdb_hasSubordinates( op, rs->sr_entry, &hasSubordinates );
84                 if ( rs->sr_err == LDAP_SUCCESS ) {
85                         *aa = slap_operational_hasSubordinate( hasSubordinates == LDAP_COMPARE_TRUE );
86                         if ( *aa != NULL ) {
87                                 aa = &(*aa)->a_next;
88                         }
89                 }
90         }
91
92         return rs->sr_err;
93 }
94