operational.c \
cache.c entry.c \
backend.c database.c thread.c conn.c rww.c log.c \
+ operation.c sent.c \
dummy.c
OBJS = init.lo search.lo compare.lo abandon.lo modify.lo bind.lo \
operational.lo \
cache.lo entry.lo \
backend.lo database.lo thread.lo conn.lo rww.lo log.lo \
+ operation.lo sent.lo \
dummy.lo
LDAP_INCDIR= ../../../include
#define SLAPD_MONITOR_LOG_DN \
SLAPD_MONITOR_LOG_RDN "," SLAPD_MONITOR_DN
+#define SLAPD_MONITOR_OPS 10
+#define SLAPD_MONITOR_OPS_NAME "Operations"
+#define SLAPD_MONITOR_OPS_RDN \
+ "cn=" SLAPD_MONITOR_OPS_NAME
+#define SLAPD_MONITOR_OPS_DN \
+ SLAPD_MONITOR_OPS_RDN "," SLAPD_MONITOR_DN
+
+#define SLAPD_MONITOR_SENT 11
+#define SLAPD_MONITOR_SENT_NAME "Sent"
+#define SLAPD_MONITOR_SENT_RDN \
+ "cn=" SLAPD_MONITOR_SENT_NAME
+#define SLAPD_MONITOR_SENT_DN \
+ SLAPD_MONITOR_SENT_RDN "," SLAPD_MONITOR_DN
+
struct monitorsubsys {
int mss_type;
char *mss_name;
mp = ( struct monitorentrypriv * )e_backend->e_private;
mp->mp_children = e_tmp;
- monitor_cache_release( mi, e_backend);
+ monitor_cache_release( mi, e_backend );
return( 0 );
}
{
struct monitorinfo *mi;
- Entry *e;
- struct berval *bv[2], val;
+ Entry *e, *e_tmp, *e_conn;
+ struct monitorentrypriv *mp;
+ char buf[1024];
+ struct berval val, *bv[2] = { &val, NULL };
assert( be != NULL );
mi = ( struct monitorinfo * )be->be_private;
if ( monitor_cache_get( mi,
- monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e ) ) {
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_conn_init: "
return( -1 );
}
- bv[0] = &val;
- bv[1] = NULL;
+ e_tmp = NULL;
+
+ /*
+ * Total conns
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Total,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Total\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_conn_init: "
+ "unable to create entry 'cn=Total,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_conn_init: "
+ "unable to create entry 'cn=Total,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+ mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_conn_init: "
+ "unable to add entry 'cn=Total,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_conn_init: "
+ "unable to add entry 'cn=Total,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ /*
+ * Current conns
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Current,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Current\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_conn_init: "
+ "unable to create entry 'cn=Current,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_conn_init: "
+ "unable to create entry 'cn=Current,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+ mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_conn_init: "
+ "unable to add entry 'cn=Current,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_conn_init: "
+ "unable to add entry 'cn=Current,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ mp = ( struct monitorentrypriv * )e_conn->e_private;
+ mp->mp_children = e_tmp;
- monitor_cache_release( mi, e );
+ monitor_cache_release( mi, e_conn );
return( 0 );
}
Entry *e
)
{
- Connection *c;
- int connindex;
- int nconns, nwritewaiters, nreadwaiters;
+ long n = -1;
- Attribute *a;
- struct berval *bv[2], val, **b = NULL;
- char buf[1024];
-
- assert( mi != NULL );
- assert( e != NULL );
+ assert( mi );
+ assert( e );
- bv[0] = &val;
- bv[1] = NULL;
-
- nconns = nwritewaiters = nreadwaiters = 0;
- for ( c = connection_first( &connindex );
- c != NULL;
- c = connection_next( c, &connindex ), nconns++ ) {
- if ( c->c_writewaiter ) {
- nwritewaiters++;
- }
- if ( c->c_currentber != NULL ) {
- nreadwaiters++;
+ if ( strncasecmp( e->e_ndn, "CN=TOTAL",
+ sizeof("CN=TOTAL")-1 ) == 0 ) {
+ n = connections_nextid();
+
+ } else if ( strncasecmp( e->e_ndn, "CN=CURRENT",
+ sizeof("CN=CURRENT")-1 ) == 0 ) {
+ Connection *c;
+ int connindex;
+
+ for ( n = 0, c = connection_first( &connindex );
+ c != NULL;
+ n++, c = connection_next( c, &connindex ) ) {
+ /* No Op */ ;
}
+ connection_done(c);
}
- connection_done(c);
-
-#if 0
- snprintf( buf, sizeof( buf ), "readwaiters=%d", nreadwaiters );
-
- if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
- for ( b = a->a_vals; b[0] != NULL; b++ ) {
- if ( strncmp( b[0]->bv_val, "readwaiters=",
- sizeof( "readwaiters=" ) - 1 ) == 0 ) {
- free( b[0]->bv_val );
- b[0] = ber_bvstrdup( buf );
- break;
- }
+
+ if ( n != -1 ) {
+ Attribute *a;
+ char buf[16];
+
+ a = attr_find( e->e_attrs, monitor_ad_desc );
+ if ( a == NULL ) {
+ return( -1 );
}
+
+ snprintf( buf, sizeof( buf ), "%ld", n );
+ ber_bvfree( a->a_vals[ 0 ] );
+ a->a_vals[ 0 ] = ber_bvstrdup( buf );
}
-
- if ( b == NULL || b[0] == NULL ) {
- val.bv_val = buf;
- val.bv_len = strlen( buf );
- attr_merge( e, monitor_ad_desc, bv );
- }
-#endif
return( 0 );
}
char buf2[22];
char buf3[22];
- struct berval *bv[2], val;
+ struct berval val, *bv[2] = { &val, NULL };
Entry *e;
buf3
);
- bv[0] = &val;
- bv[1] = NULL;
-
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, monitor_ad_desc, bv );
c != NULL;
c = connection_next( c, &connindex )) {
if ( conn_create( c, &e ) || e == NULL ) {
- // error
+ connection_done(c);
+ return( -1 );
}
mp = ( struct monitorentrypriv * )e->e_private;
mp->mp_next = e_tmp;
c = connection_next( c, &connindex )) {
if ( c->c_connid == connid ) {
if ( conn_create( c, ep ) || *ep == NULL ) {
- // error
+ connection_done(c);
+ return( -1 );
}
}
}
int i;
struct monitorentrypriv *mp;
AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts;
- struct berval *bv[2], val;
+ struct berval val, *bv[2] = { &val, NULL };
assert( be != NULL );
assert( monitor_ad_desc != NULL );
return( -1 );
}
- bv[0] = &val;
- bv[1] = NULL;
e_tmp = NULL;
for ( i = nBackendDB; i--; ) {
char buf[1024];
NULL, /* update */
NULL, /* create */
monitor_subsys_log_modify
+ }, {
+ SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
+ NULL, NULL, NULL,
+ MONITOR_F_NONE,
+ monitor_subsys_ops_init,
+ monitor_subsys_ops_update,
+ NULL, /* create */
+ NULL, /* modify */
+ }, {
+ SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
+ NULL, NULL, NULL,
+ MONITOR_F_NONE,
+ monitor_subsys_sent_init,
+ monitor_subsys_sent_update,
+ NULL, /* create */
+ NULL, /* modify */
}, { -1, NULL }
};
--- /dev/null
+/* operation.c - deal with operation subsystem */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*
+ * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ *
+ * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
+ *
+ * This work has beed deveolped for the OpenLDAP Foundation
+ * in the hope that it may be useful to the Open Source community,
+ * but WITHOUT ANY WARRANTY.
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author and SysNet s.n.c. are not responsible for the consequences
+ * of use of this software, no matter how awful, even if they arise from
+ * flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the documentation.
+ * SysNet s.n.c. cannot be responsible for the consequences of the
+ * alterations.
+ *
+ * 4. This notice may not be removed or altered.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include "slap.h"
+#include "back-monitor.h"
+
+int
+monitor_subsys_ops_init(
+ BackendDB *be
+)
+{
+ struct monitorinfo *mi;
+
+ Entry *e, *e_tmp, *e_op;
+ struct monitorentrypriv *mp;
+ char buf[1024];
+ struct berval val, *bv[2] = { &val, NULL };
+
+ assert( be != NULL );
+
+ mi = ( struct monitorinfo * )be->be_private;
+
+ if ( monitor_cache_get( mi,
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_ops_init: "
+ "unable to get entry '%s'\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_ops_init: "
+ "unable to get entry '%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = NULL;
+
+ /*
+ * Initiated ops
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Initiated,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Initiated\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_ops_init: "
+ "unable to create entry 'cn=Initiated,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_ops_init: "
+ "unable to create entry 'cn=Initiated,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_ops_init: "
+ "unable to add entry 'cn=Initiated,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_ops_init: "
+ "unable to add entry 'cn=Initiated,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ /*
+ * Completed ops
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Completed,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Completed\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_ops_init: "
+ "unable to create entry 'cn=Completed,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_ops_init: "
+ "unable to create entry 'cn=Completed,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_ops_init: "
+ "unable to add entry 'cn=Completed,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_ops_init: "
+ "unable to add entry 'cn=Completed,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ mp = ( struct monitorentrypriv * )e_op->e_private;
+ mp->mp_children = e_tmp;
+
+ monitor_cache_release( mi, e_op );
+
+ return( 0 );
+}
+
+int
+monitor_subsys_ops_update(
+ struct monitorinfo *mi,
+ Entry *e
+)
+{
+ long n = -1;
+
+ assert( mi );
+ assert( e );
+
+ if ( strncasecmp( e->e_ndn, "CN=INITIATED",
+ sizeof("CN=INITIATED")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_ops_mutex);
+ n = num_ops_initiated;
+ ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
+
+ } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED",
+ sizeof("CN=COMPLETED")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_ops_mutex);
+ n = num_ops_completed;
+ ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
+ }
+
+ if ( n != -1 ) {
+ Attribute *a;
+ char buf[16];
+
+ a = attr_find( e->e_attrs, monitor_ad_desc );
+ if ( a == NULL ) {
+ return( -1 );
+ }
+
+ snprintf( buf, sizeof( buf ), "%ld", n );
+ ber_bvfree( a->a_vals[ 0 ] );
+ a->a_vals[ 0 ] = ber_bvstrdup( buf );
+ }
+
+ return( 0 );
+}
+
int monitor_subsys_log_init LDAP_P(( BackendDB *be ));
int monitor_subsys_log_modify LDAP_P(( struct monitorinfo *mi, Entry *e, Modifications *modlist ));
+/*
+ * operations
+ */
+int monitor_subsys_ops_init LDAP_P(( BackendDB *be ));
+int monitor_subsys_ops_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
+
+/*
+ * sent
+ */
+int monitor_subsys_sent_init LDAP_P(( BackendDB *be ));
+int monitor_subsys_sent_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
+
LDAP_END_DECL
#endif
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
for ( b = a->a_vals; b[0] != NULL; b++ ) {
if ( strncmp( b[0]->bv_val, str, strlen( str ) ) == 0 ) {
- free( b[0]->bv_val );
+ ber_bvfree( b[0] );
b[0] = ber_bvstrdup( buf );
break;
}
)
{
struct monitorinfo *mi = (struct monitorinfo *) be->be_private;
- Entry *e, *e_tmp;
+ Entry *e, *e_tmp, *e_ch;
struct monitorentrypriv *mp;
int nentries;
int rc;
mp = ( struct monitorentrypriv * )e_parent->e_private;
e = mp->mp_children;
- if ( e == NULL && MONITOR_HAS_VOLATILE_CH( mp ) ) {
- monitor_entry_create( mi, NULL, e_parent, &e );
- if ( e != NULL) {
- monitor_cache_lock( e );
- }
+ if ( MONITOR_HAS_VOLATILE_CH( mp ) ) {
+ monitor_entry_create( mi, NULL, e_parent, &e_ch );
}
monitor_cache_release( mi, e_parent );
+ /* no volatile entries? */
+ if ( e_ch == NULL ) {
+ /* no persistent entries? return */
+ if ( e == NULL ) {
+ return( 0 );
+ }
+
+ /* volatile entries */
+ } else {
+ /* if no persistent, return only volatile */
+ if ( e == NULL ) {
+ e = e_ch;
+ monitor_cache_lock( e_ch );
+
+ /* else append persistent to volatile */
+ } else {
+ e_tmp = e_ch;
+ do {
+ mp = ( struct monitorentrypriv * )e_tmp->e_private;
+ e_tmp = mp->mp_next;
+
+ if ( e_tmp == NULL ) {
+ mp->mp_next = e;
+ break;
+ }
+ } while ( e_tmp );
+ e = e_ch;
+ }
+ }
+
+ /* return entries */
for ( nentries = *nentriesp; e != NULL; ) {
mp = ( struct monitorentrypriv * )e->e_private;
--- /dev/null
+/* sent.c - deal with data sent subsystem */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*
+ * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ *
+ * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
+ *
+ * This work has beed deveolped for the OpenLDAP Foundation
+ * in the hope that it may be useful to the Open Source community,
+ * but WITHOUT ANY WARRANTY.
+ *
+ * Permission is granted to anyone to use this software for any purpose
+ * on any computer system, and to alter it and redistribute it, subject
+ * to the following restrictions:
+ *
+ * 1. The author and SysNet s.n.c. are not responsible for the consequences
+ * of use of this software, no matter how awful, even if they arise from
+ * flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits should appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits should appear in the documentation.
+ * SysNet s.n.c. cannot be responsible for the consequences of the
+ * alterations.
+ *
+ * 4. This notice may not be removed or altered.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include "slap.h"
+#include "back-monitor.h"
+
+int
+monitor_subsys_sent_init(
+ BackendDB *be
+)
+{
+ struct monitorinfo *mi;
+
+ Entry *e, *e_tmp, *e_sent;
+ struct monitorentrypriv *mp;
+ char buf[1024];
+ struct berval val, *bv[2] = { &val, NULL };
+
+ assert( be != NULL );
+
+ mi = ( struct monitorinfo * )be->be_private;
+
+ if ( monitor_cache_get( mi,
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to get entry '%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to get entry '%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = NULL;
+
+ /*
+ * Entries
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Entries,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Entries\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Entries,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Entries,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Entries,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Entries,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ /*
+ * Referrals
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Referrals,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Referrals\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Referrals,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Referrals,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Referrals,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Referrals,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ /*
+ * PDU
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=PDU,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: PDU\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=PDU,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=PDU,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=PDU,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=PDU,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ /*
+ * Bytes
+ */
+ snprintf( buf, sizeof( buf ),
+ "dn: cn=Bytes,%s\n"
+ "objectClass: top\n"
+ "objectClass: LDAPsubEntry\n"
+#ifdef SLAPD_MONITORSUBENTRY
+ "objectClass: monitorSubEntry\n"
+#else /* !SLAPD_MONITORSUBENTRY */
+ "objectClass: extensibleObject\n"
+#endif /* !SLAPD_MONITORSUBENTRY */
+ "cn: Bytes\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_dn );
+
+ e = str2entry( buf );
+ if ( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Bytes,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to create entry 'cn=Bytes,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ val.bv_val = "0";
+ val.bv_len = 1;
+ attr_merge( e, monitor_ad_desc, bv );
+
+ mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
+ e->e_private = ( void * )mp;
+ mp->mp_next = e_tmp;
+ mp->mp_children = NULL;
+ mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT];
+ mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \
+ | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
+
+ if ( monitor_cache_add( mi, e ) ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Bytes,%s'\n",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn ));
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "monitor_subsys_sent_init: "
+ "unable to add entry 'cn=Bytes,%s'\n%s%s",
+ monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn,
+ "", "" );
+#endif
+ return( -1 );
+ }
+
+ e_tmp = e;
+
+ mp = ( struct monitorentrypriv * )e_sent->e_private;
+ mp->mp_children = e_tmp;
+
+ monitor_cache_release( mi, e_sent );
+
+ return( 0 );
+}
+
+int
+monitor_subsys_sent_update(
+ struct monitorinfo *mi,
+ Entry *e
+)
+{
+ long n = -1;
+
+ assert( mi );
+ assert( e );
+
+ if ( strncasecmp( e->e_ndn, "CN=ENTRIES",
+ sizeof("CN=ENTRIES")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+ n = num_entries_sent;
+ ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+ } else if ( strncasecmp( e->e_ndn, "CN=REFERRALS",
+ sizeof("CN=REFERRALS")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+ n = num_refs_sent;
+ ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+ } else if ( strncasecmp( e->e_ndn, "CN=PDU",
+ sizeof("CN=PDU")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+ n = num_pdu_sent;
+ ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+
+ } else if ( strncasecmp( e->e_ndn, "CN=BYTES",
+ sizeof("CN=BYTES")-1 ) == 0 ) {
+ ldap_pvt_thread_mutex_lock(&num_sent_mutex);
+ n = num_bytes_sent;
+ ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
+ }
+
+ if ( n != -1 ) {
+ Attribute *a;
+ char buf[16];
+
+ a = attr_find( e->e_attrs, monitor_ad_desc );
+ if ( a == NULL ) {
+ return( -1 );
+ }
+
+ snprintf( buf, sizeof( buf ), "%ld", n );
+ ber_bvfree( a->a_vals[ 0 ] );
+ a->a_vals[ 0 ] = ber_bvstrdup( buf );
+ }
+
+ return( 0 );
+}
+
return NULL;
}
+unsigned long connections_nextid(void)
+{
+ return 0;
+}
+
void connection_done( Connection *c )
{
assert(0);