mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-24 08:39:37 -05:00
Moved proxy caching to overlay
This commit is contained in:
parent
1762b5b71d
commit
066a80bbbb
13 changed files with 2 additions and 3943 deletions
|
|
@ -14,13 +14,9 @@
|
|||
## <http://www.OpenLDAP.org/license.html>.
|
||||
|
||||
SRCS = init.c config.c search.c bind.c unbind.c add.c compare.c \
|
||||
cache-query.c cache-search.c cache-config.c cache-merge.c \
|
||||
cache-template.c cache-substring.c cache-remove.c \
|
||||
delete.c modify.c modrdn.c \
|
||||
conn.c candidates.c dncache.c
|
||||
OBJS = init.lo config.lo search.lo bind.lo unbind.lo add.lo compare.lo \
|
||||
cache-query.lo cache-search.lo cache-config.lo cache-merge.lo \
|
||||
cache-template.lo cache-substring.lo cache-remove.lo \
|
||||
delete.lo modify.lo modrdn.lo \
|
||||
conn.lo candidates.lo dncache.lo
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@
|
|||
|
||||
/* String rewrite library */
|
||||
#include "rewrite.h"
|
||||
#include "cache.h"
|
||||
LDAP_BEGIN_DECL
|
||||
|
||||
struct slap_conn;
|
||||
|
|
@ -168,7 +167,6 @@ struct metainfo {
|
|||
struct metatarget **targets;
|
||||
|
||||
struct rewrite_info *rwinfo;
|
||||
cache_manager *cm;
|
||||
Backend *glue_be;
|
||||
|
||||
struct metadncache cache;
|
||||
|
|
|
|||
|
|
@ -1,333 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/string.h>
|
||||
#include <ac/socket.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
|
||||
#define MAX_ATTR_SETS 500
|
||||
static void find_supersets( struct attr_set* attr_sets, int numsets );
|
||||
static int compare_sets( struct attr_set* setA, int, int );
|
||||
|
||||
int
|
||||
meta_back_cache_config(
|
||||
BackendDB *be,
|
||||
const char *fname,
|
||||
int lineno,
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
{
|
||||
struct metainfo *li = ( struct metainfo * )be->be_private;
|
||||
|
||||
cache_manager* cm = li->cm;
|
||||
query_manager* qm = cm->qm;
|
||||
QueryTemplate* temp;
|
||||
AttributeName* attr_name;
|
||||
AttributeName* attrs;
|
||||
AttributeName* attrarray;
|
||||
const char* text=NULL;
|
||||
|
||||
int index, i;
|
||||
int num;
|
||||
|
||||
if ( li == NULL ) {
|
||||
fprintf( stderr, "%s: line %d: meta backend info is null!\n",
|
||||
fname, lineno );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( strcasecmp( argv[0], "cacheparams" ) == 0 ) {
|
||||
struct berval cache_suffix;
|
||||
|
||||
if ( argc < 6 ) {
|
||||
fprintf( stderr, "%s: line %d: missing arguments in \"cacheparams"
|
||||
" <thresh_lo> <thresh_hi> <numattrsets> <entry limit> "
|
||||
"<cycle_time>\" \n", fname, lineno );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
cm->caching = 1;
|
||||
cm->thresh_lo = atoi( argv[1] );
|
||||
cm->thresh_hi = atoi( argv[2] );
|
||||
if ( cm->thresh_hi <= cm->thresh_lo ) {
|
||||
fprintf( stderr, "%s: line %d: <thresh_lo> must be < <thresh_hi> "
|
||||
"in \"cacheparams <thresh_lo> <thresh_hi> <numattrsets> "
|
||||
"<entry limit> <cycle_time>\" \n", fname, lineno );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
cm->numattrsets = atoi( argv[3] );
|
||||
if ( cm->numattrsets > MAX_ATTR_SETS ) {
|
||||
fprintf( stderr, "%s: line %d: <numattrsets> must be <= %d in "
|
||||
"\"cacheparams <thresh_lo> <thresh_hi> <numattrsets> "
|
||||
"<entry limit> <cycle_time>\" \n",
|
||||
fname, lineno, MAX_ATTR_SETS );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
cm->num_entries_limit = atoi( argv[4] );
|
||||
cm->cc_period = atoi( argv[5] );
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"Total # of attribute sets to be cached = %d\n",
|
||||
cm->numattrsets, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Total # of attribute sets to be cached = %d\n",
|
||||
cm->numattrsets, 0, 0 );
|
||||
#endif
|
||||
qm->attr_sets = ( struct attr_set * )malloc( cm->numattrsets *
|
||||
sizeof( struct attr_set ));
|
||||
for ( i = 0; i < cm->numattrsets; i++ ) {
|
||||
qm->attr_sets[i].attrs = NULL;
|
||||
}
|
||||
rewrite_session( li->rwinfo, "cacheBase", be->be_nsuffix[0].bv_val,
|
||||
0, &cache_suffix.bv_val );
|
||||
if ( cache_suffix.bv_val != NULL ) {
|
||||
cache_suffix.bv_len = strlen( cache_suffix.bv_val );
|
||||
} else {
|
||||
cache_suffix = be->be_nsuffix[0];
|
||||
}
|
||||
li->glue_be = select_backend( &cache_suffix, 0, 1 );
|
||||
li->glue_be->be_flags |= SLAP_BFLAG_NO_SCHEMA_CHECK;
|
||||
if ( cache_suffix.bv_val != be->be_nsuffix[0].bv_val ) {
|
||||
ch_free( cache_suffix.bv_val );
|
||||
}
|
||||
|
||||
} else if ( strcasecmp( argv[0], "attrset" ) == 0 ) {
|
||||
if ( argc < 3 ) {
|
||||
fprintf( stderr, "%s: line %d: missing arguments in \"attr-set "
|
||||
"<index> <attributes>\" line\n", fname, lineno );
|
||||
return( 1 );
|
||||
}
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Attribute Set # %d\n",
|
||||
atoi( argv[1] ), 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Attribute Set # %d\n",
|
||||
atoi( argv[1] ), 0, 0 );
|
||||
#endif
|
||||
if (atoi(argv[1]) >= cm->numattrsets) {
|
||||
fprintf( stderr, "%s; line %d index out of bounds \n",
|
||||
fname, lineno );
|
||||
return 1;
|
||||
}
|
||||
index = atoi( argv[1] );
|
||||
if ( argv[2] && ( strcmp( argv[2], "*" ) != 0 )) {
|
||||
for ( i = 2; argv[i] != NULL; i++ ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "\t %s\n",
|
||||
argv[i], 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "\t %s\n",
|
||||
argv[i], 0, 0 );
|
||||
#endif
|
||||
attrs = qm->attr_sets[index].attrs;
|
||||
qm->attr_sets[index].attrs = (AttributeName*)realloc(
|
||||
attrs, i * sizeof( AttributeName ));
|
||||
attr_name = qm->attr_sets[index].attrs + ( i - 2 );
|
||||
ber_str2bv( argv[i], strlen(argv[i]), 1,
|
||||
&attr_name->an_name);
|
||||
attr_name->an_desc = NULL;
|
||||
slap_bv2ad( &attr_name->an_name,
|
||||
&attr_name->an_desc, &text );
|
||||
attr_name++;
|
||||
attr_name->an_name.bv_val = NULL;
|
||||
attr_name->an_name.bv_len = 0;
|
||||
}
|
||||
qm->attr_sets[index].count = i - 2;
|
||||
}
|
||||
} else if ( strcasecmp( argv[0], "addtemplate" ) == 0 ) {
|
||||
if ( argc != 4 ) {
|
||||
fprintf( stderr, "%s: line %d: missing argument(s) in "
|
||||
"\"addtemplate <filter> <proj attr set> <TTL>\" line\n",
|
||||
fname, lineno );
|
||||
return( 1 );
|
||||
}
|
||||
if (( i = atoi( argv[2] )) >= cm->numattrsets ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"%s: line %d, template index invalid\n",
|
||||
fname, lineno, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"%s: line %d, template index invalid\n",
|
||||
fname, lineno, 0 );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
num = cm->numtemplates;
|
||||
if ( num == 0 )
|
||||
find_supersets( qm->attr_sets, cm->numattrsets );
|
||||
qm->templates = ( QueryTemplate* )realloc( qm->templates,
|
||||
( num + 2 ) * sizeof( QueryTemplate ));
|
||||
temp = qm->templates + num;
|
||||
ldap_pvt_thread_rdwr_init( &temp->t_rwlock );
|
||||
temp->query = temp->query_last = NULL;
|
||||
temp->ttl = atoi( argv[3] );
|
||||
temp->no_of_queries = 0;
|
||||
if ( argv[1] == NULL ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"Templates string not specified "
|
||||
"for template %d\n", num, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Templates string not specified "
|
||||
"for template %d\n", num, 0, 0 );
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
temp->querystr = ch_strdup( argv[1] );
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Template:\n", 0, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Template:\n", 0, 0, 0 );
|
||||
#endif
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, " query template: %s\n",
|
||||
temp->querystr, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, " query template: %s\n",
|
||||
temp->querystr, 0, 0 );
|
||||
#endif
|
||||
temp->attr_set_index = i;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, " attributes: \n", 0, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, " attributes: \n", 0, 0, 0 );
|
||||
#endif
|
||||
if ( ( attrarray = qm->attr_sets[i].attrs ) != NULL ) {
|
||||
for ( i=0; attrarray[i].an_name.bv_val; i++ )
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "\t%s\n",
|
||||
attrarray[i].an_name.bv_val, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "\t%s\n",
|
||||
attrarray[i].an_name.bv_val, 0, 0 );
|
||||
#endif
|
||||
}
|
||||
temp++;
|
||||
temp->querystr = NULL;
|
||||
cm->numtemplates++;
|
||||
}
|
||||
/* anything else */
|
||||
else {
|
||||
fprintf( stderr, "%s: line %d: unknown directive \"%s\" in meta "
|
||||
"database definition (ignored)\n",
|
||||
fname, lineno, argv[0] );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
find_supersets ( struct attr_set* attr_sets, int numsets )
|
||||
{
|
||||
int num[MAX_ATTR_SETS];
|
||||
int i, j, res;
|
||||
int* id_array;
|
||||
for ( i = 0; i < MAX_ATTR_SETS; i++ )
|
||||
num[i] = 0;
|
||||
|
||||
for ( i = 0; i < numsets; i++ ) {
|
||||
attr_sets[i].ID_array = (int*) malloc( sizeof( int ) );
|
||||
attr_sets[i].ID_array[0] = -1;
|
||||
}
|
||||
|
||||
for ( i = 0; i < numsets; i++ ) {
|
||||
for ( j=i+1; j < numsets; j++ ) {
|
||||
res = compare_sets( attr_sets, i, j );
|
||||
switch ( res ) {
|
||||
case 0:
|
||||
break;
|
||||
case 3:
|
||||
case 1:
|
||||
id_array = attr_sets[i].ID_array;
|
||||
attr_sets[i].ID_array = (int *) realloc( id_array,
|
||||
( num[i] + 2 ) * sizeof( int ));
|
||||
attr_sets[i].ID_array[num[i]] = j;
|
||||
attr_sets[i].ID_array[num[i]+1] = -1;
|
||||
num[i]++;
|
||||
if (res == 1)
|
||||
break;
|
||||
case 2:
|
||||
id_array = attr_sets[j].ID_array;
|
||||
attr_sets[j].ID_array = (int *) realloc( id_array,
|
||||
( num[j] + 2 ) * sizeof( int ));
|
||||
attr_sets[j].ID_array[num[j]] = i;
|
||||
attr_sets[j].ID_array[num[j]+1] = -1;
|
||||
num[j]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* compares two sets of attributes (indices i and j)
|
||||
* returns 0: if neither set is contained in the other set
|
||||
* 1: if set i is contained in set j
|
||||
* 2: if set j is contained in set i
|
||||
* 3: the sets are equivalent
|
||||
*/
|
||||
|
||||
int
|
||||
compare_sets(struct attr_set* set, int i, int j)
|
||||
{
|
||||
int k,l,numI,numJ;
|
||||
int common=0;
|
||||
int result=0;
|
||||
|
||||
if (( set[i].attrs == NULL ) && ( set[j].attrs == NULL ))
|
||||
return 3;
|
||||
|
||||
if ( set[i].attrs == NULL )
|
||||
return 2;
|
||||
|
||||
if ( set[j].attrs == NULL )
|
||||
return 1;
|
||||
|
||||
numI = set[i].count;
|
||||
numJ = set[j].count;
|
||||
|
||||
for ( l=0; l < numI; l++ ) {
|
||||
for ( k = 0; k < numJ; k++ ) {
|
||||
if ( strcmp( set[i].attrs[l].an_name.bv_val,
|
||||
set[j].attrs[k].an_name.bv_val ) == 0 )
|
||||
common++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( common == numI )
|
||||
result = 1;
|
||||
|
||||
if ( common == numJ )
|
||||
result += 2;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,294 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/socket.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/time.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "ldif.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
#include "ldap_pvt.h"
|
||||
#undef ldap_debug /* silence a warning in ldap-int.h */
|
||||
#include "ldap_log.h"
|
||||
#include "../../../libraries/libldap/ldap-int.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
static struct berval bv_queryid_any = BER_BVC( "(queryid=*)" );
|
||||
|
||||
static Attribute*
|
||||
add_attribute(AttributeDescription *ad,
|
||||
Entry* e,
|
||||
BerVarray value_array
|
||||
);
|
||||
|
||||
static int
|
||||
null_response (
|
||||
Operation *op,
|
||||
SlapReply *rs
|
||||
);
|
||||
|
||||
static int
|
||||
normalize_values( Attribute* attr );
|
||||
|
||||
struct entry_info {
|
||||
int size_init;
|
||||
int size_final;
|
||||
int added;
|
||||
Entry* entry;
|
||||
struct berval* uuid;
|
||||
struct timeval tv; /* time */
|
||||
enum type_of_result err;
|
||||
Backend* glue_be;
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
get_entry_size(
|
||||
Entry* e,
|
||||
int size_init,
|
||||
struct exception* result )
|
||||
{
|
||||
Attribute *a;
|
||||
struct berval bv;
|
||||
int i;
|
||||
int tmplen;
|
||||
int size=0;
|
||||
|
||||
if ( result )
|
||||
result->type = SUCCESS;
|
||||
|
||||
if ( e->e_dn != NULL ) {
|
||||
tmplen = strlen( e->e_dn );
|
||||
size = LDIF_SIZE_NEEDED( 2, tmplen );
|
||||
}
|
||||
|
||||
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
|
||||
for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
|
||||
bv = a->a_vals[i];
|
||||
tmplen = a->a_desc->ad_cname.bv_len;
|
||||
size += LDIF_SIZE_NEEDED( tmplen, bv.bv_len);
|
||||
}
|
||||
}
|
||||
if ((size < size_init) && result) {
|
||||
result->type = SIZE_ERR;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
int
|
||||
merge_entry(
|
||||
Operation *op,
|
||||
SlapReply *rs,
|
||||
struct berval* query_uuid,
|
||||
struct exception* result )
|
||||
{
|
||||
struct entry_info info;
|
||||
int rc;
|
||||
Modifications* modlist = NULL;
|
||||
const char* text = NULL;
|
||||
BerVarray value_array;
|
||||
Attribute *uuid_attr, *attr;
|
||||
Entry *e;
|
||||
char textbuf[SLAP_TEXT_BUFLEN];
|
||||
size_t textlen = sizeof(textbuf);
|
||||
|
||||
SlapReply sreply = {REP_RESULT};
|
||||
|
||||
Operation op_tmp = *op;
|
||||
slap_callback cb;
|
||||
|
||||
sreply.sr_entry = NULL;
|
||||
sreply.sr_nentries = 0;
|
||||
|
||||
e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
|
||||
|
||||
dnPrettyNormal(0, &rs->sr_entry->e_name, &op_tmp.o_req_dn, &op_tmp.o_req_ndn, op->o_tmpmemctx);
|
||||
ber_dupbv( &e->e_name, &op_tmp.o_req_dn );
|
||||
ber_dupbv( &e->e_nname, &op_tmp.o_req_ndn );
|
||||
sl_free( op_tmp.o_req_ndn.bv_val, op->o_tmpmemctx );
|
||||
sl_free( op_tmp.o_req_dn.bv_val, op->o_tmpmemctx );
|
||||
op_tmp.o_req_dn = e->e_name;
|
||||
op_tmp.o_req_ndn = e->e_nname;
|
||||
|
||||
e->e_private = NULL;
|
||||
e->e_attrs = NULL;
|
||||
e->e_bv.bv_val = NULL;
|
||||
|
||||
/* add queryid attribute */
|
||||
value_array = (struct berval *)malloc(2 * sizeof( struct berval) );
|
||||
ber_dupbv(value_array, query_uuid);
|
||||
value_array[1].bv_val = NULL;
|
||||
value_array[1].bv_len = 0;
|
||||
|
||||
uuid_attr = add_attribute(slap_schema.si_ad_queryid, e, value_array);
|
||||
|
||||
/* append the attribute list from the fetched entry */
|
||||
uuid_attr->a_next = rs->sr_entry->e_attrs;
|
||||
rs->sr_entry->e_attrs = NULL;
|
||||
|
||||
for ( attr = e->e_attrs; attr; attr = attr->a_next ) {
|
||||
if ( normalize_values( attr ) ) {
|
||||
info.err = MERGE_ERR;
|
||||
result->rc = info.err;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
info.entry = e;
|
||||
info.uuid = query_uuid;
|
||||
info.size_init = get_entry_size( rs->sr_entry, 0, 0 );
|
||||
info.size_final = 0;
|
||||
info.added = 0;
|
||||
info.glue_be = op->o_bd;
|
||||
info.err = SUCCESS;
|
||||
cb.sc_private = &info;
|
||||
cb.sc_response = null_response;
|
||||
|
||||
op_tmp.o_tag = LDAP_REQ_ADD;
|
||||
op_tmp.o_protocol = LDAP_VERSION3;
|
||||
op_tmp.o_callback = &cb;
|
||||
op_tmp.o_time = slap_get_time();
|
||||
op_tmp.o_do_not_cache = 1;
|
||||
|
||||
op_tmp.ora_e = e;
|
||||
rc = op->o_bd->be_add( &op_tmp, &sreply );
|
||||
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
if ( rc == LDAP_ALREADY_EXISTS ) {
|
||||
slap_entry2mods( e, &modlist, &text, textbuf, textlen );
|
||||
op_tmp.o_tag = LDAP_REQ_MODIFY;
|
||||
op_tmp.orm_modlist = modlist;
|
||||
op_tmp.o_req_dn = e->e_name;
|
||||
op_tmp.o_req_ndn = e->e_nname;
|
||||
rc = op->o_bd->be_modify( &op_tmp, &sreply );
|
||||
result->rc = info.added;
|
||||
} else if ( rc == LDAP_REFERRAL ||
|
||||
rc == LDAP_NO_SUCH_OBJECT ) {
|
||||
syncrepl_add_glue( &op_tmp, e );
|
||||
result->rc = info.added;
|
||||
} else {
|
||||
result->rc = 0;
|
||||
}
|
||||
if ( modlist != NULL ) slap_mods_free( modlist );
|
||||
} else {
|
||||
info.size_init = 0;
|
||||
result->rc = info.added;
|
||||
be_entry_release_w( &op_tmp, e );
|
||||
}
|
||||
|
||||
if ( result->rc )
|
||||
info.size_final = get_entry_size( e, info.size_init, result );
|
||||
else
|
||||
info.size_final = info.size_init;
|
||||
|
||||
return ( info.size_final - info.size_init );
|
||||
}
|
||||
|
||||
static Attribute*
|
||||
add_attribute(AttributeDescription *ad,
|
||||
Entry* e,
|
||||
BerVarray value_array)
|
||||
{
|
||||
Attribute* new_attr, *last_attr;
|
||||
const char* text;
|
||||
|
||||
if (e->e_attrs == NULL)
|
||||
last_attr = NULL;
|
||||
else
|
||||
for (last_attr = e->e_attrs; last_attr->a_next;
|
||||
last_attr = last_attr->a_next)
|
||||
;
|
||||
|
||||
new_attr = (Attribute*)malloc(sizeof(Attribute));
|
||||
if (last_attr)
|
||||
last_attr->a_next = new_attr;
|
||||
else
|
||||
e->e_attrs = new_attr;
|
||||
|
||||
new_attr->a_next = NULL;
|
||||
new_attr->a_desc = NULL;
|
||||
new_attr->a_vals = value_array;
|
||||
new_attr->a_desc = ad;
|
||||
|
||||
return new_attr;
|
||||
}
|
||||
|
||||
static int
|
||||
null_response (
|
||||
Operation *op,
|
||||
SlapReply *rs )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
normalize_values( Attribute* attr )
|
||||
{
|
||||
int nvals, rc, i;
|
||||
|
||||
if (attr->a_vals == NULL) {
|
||||
attr->a_nvals = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for ( nvals = 0; attr->a_vals[nvals].bv_val; nvals++ )
|
||||
;
|
||||
|
||||
attr->a_nvals = (struct berval*)ch_malloc((nvals+1)*sizeof(struct berval));
|
||||
|
||||
if ( attr->a_desc->ad_type->sat_equality &&
|
||||
attr->a_desc->ad_type->sat_equality->smr_normalize )
|
||||
{
|
||||
for ( i = 0; i < nvals; i++ ) {
|
||||
rc = attr->a_desc->ad_type->sat_equality->smr_normalize(
|
||||
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
|
||||
attr->a_desc->ad_type->sat_syntax,
|
||||
attr->a_desc->ad_type->sat_equality,
|
||||
&attr->a_vals[i], &attr->a_nvals[i], NULL );
|
||||
if ( rc ) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( OPERATION, DETAIL1,
|
||||
"Error in normalizing attribute %s value %d (%d)\n",
|
||||
attr->a_desc->ad_cname.bv_val, i, rc );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Error in normalizing attribute %s value %d (%d)\n",
|
||||
attr->a_desc->ad_cname.bv_val, i, rc );
|
||||
#endif
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for ( i = 0; i < nvals; i++ ) {
|
||||
ber_dupbv( &attr->a_nvals[i], &attr->a_vals[i] );
|
||||
}
|
||||
}
|
||||
|
||||
attr->a_nvals[i].bv_val = NULL;
|
||||
attr->a_nvals[i].bv_len = 0;
|
||||
|
||||
return LDAP_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,468 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/string.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
|
||||
static void add_query_on_top (query_manager*, CachedQuery*);
|
||||
static int base_scope_compare(struct berval* dn_stored,
|
||||
struct berval* dn_incoming, int scope_stored,
|
||||
int scope_incoming);
|
||||
|
||||
/* check whether query is contained in any of
|
||||
* the cached queries in template template_index
|
||||
*/
|
||||
int
|
||||
query_containment(query_manager* qm,
|
||||
Query* query,
|
||||
int template_index)
|
||||
{
|
||||
QueryTemplate* templa= qm->templates;
|
||||
CachedQuery* qc;
|
||||
Query* q;
|
||||
Query* prev_q;
|
||||
Filter* inputf = query->filter;
|
||||
struct berval* base = &(query->base);
|
||||
int scope = query->scope;
|
||||
int i,res=0;
|
||||
Filter* fs;
|
||||
Filter* fi;
|
||||
int ret, rc;
|
||||
const char* text;
|
||||
|
||||
MatchingRule* mrule = NULL;
|
||||
if (inputf != NULL) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Lock QC index = %d\n",
|
||||
template_index, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Lock QC index = %d\n",
|
||||
template_index, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_rlock(&(templa[template_index].t_rwlock));
|
||||
for(qc=templa[template_index].query; qc != NULL; qc= qc->next) {
|
||||
q = (Query*)qc;
|
||||
if(base_scope_compare(&(q->base), base, q->scope, scope)) {
|
||||
fi = inputf;
|
||||
fs = q->filter;
|
||||
do {
|
||||
res=0;
|
||||
switch (fs->f_choice) {
|
||||
case LDAP_FILTER_EQUALITY:
|
||||
if (fi->f_choice == LDAP_FILTER_EQUALITY)
|
||||
mrule = fs->f_ava->aa_desc->ad_type->sat_equality;
|
||||
else
|
||||
ret = 1;
|
||||
break;
|
||||
case LDAP_FILTER_GE:
|
||||
case LDAP_FILTER_LE:
|
||||
mrule = fs->f_ava->aa_desc->ad_type->sat_ordering;
|
||||
break;
|
||||
default:
|
||||
mrule = NULL;
|
||||
}
|
||||
if (mrule) {
|
||||
rc = value_match(&ret, fs->f_ava->aa_desc, mrule,
|
||||
SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
|
||||
&(fi->f_ava->aa_value),
|
||||
&(fs->f_ava->aa_value), &text);
|
||||
if (rc != LDAP_SUCCESS) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"Unlock: Exiting QC index=%d\n",
|
||||
template_index, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Unlock: Exiting QC index=%d\n",
|
||||
template_index, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_runlock(&(templa[template_index].t_rwlock));
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"query_containment: Required "
|
||||
"matching rule not defined for "
|
||||
"a filter attribute",
|
||||
0, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"query_containment: Required "
|
||||
"matching rule not defined for "
|
||||
"a filter attribute",
|
||||
0, 0, 0 );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
switch (fs->f_choice) {
|
||||
case LDAP_FILTER_OR:
|
||||
case LDAP_FILTER_AND:
|
||||
fs = fs->f_and;
|
||||
fi = fi->f_and;
|
||||
res=1;
|
||||
break;
|
||||
case LDAP_FILTER_SUBSTRINGS:
|
||||
/* check if the equality query can be
|
||||
* answered with cached substring query */
|
||||
if ((fi->f_choice == LDAP_FILTER_EQUALITY)
|
||||
&& substr_containment_equality(
|
||||
fs, fi))
|
||||
res=1;
|
||||
/* check if the substring query can be
|
||||
* answered with cached substring query */
|
||||
if ((fi->f_choice ==LDAP_FILTER_SUBSTRINGS
|
||||
) && substr_containment_substr(
|
||||
fs, fi))
|
||||
res= 1;
|
||||
fs=fs->f_next;
|
||||
fi=fi->f_next;
|
||||
break;
|
||||
case LDAP_FILTER_PRESENT:
|
||||
res=1;
|
||||
fs=fs->f_next;
|
||||
fi=fi->f_next;
|
||||
break;
|
||||
case LDAP_FILTER_EQUALITY:
|
||||
if (ret == 0)
|
||||
res = 1;
|
||||
fs=fs->f_next;
|
||||
fi=fi->f_next;
|
||||
break;
|
||||
case LDAP_FILTER_GE:
|
||||
if (ret >= 0)
|
||||
res = 1;
|
||||
fs=fs->f_next;
|
||||
fi=fi->f_next;
|
||||
break;
|
||||
case LDAP_FILTER_LE:
|
||||
if (ret <= 0)
|
||||
res = 1;
|
||||
fs=fs->f_next;
|
||||
fi=fi->f_next;
|
||||
break;
|
||||
case LDAP_FILTER_NOT:
|
||||
res=0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while((res) && (fi != NULL) && (fs != NULL));
|
||||
|
||||
if(res) {
|
||||
ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
|
||||
if (qm->lru_top != qc) {
|
||||
remove_query(qm, qc);
|
||||
add_query_on_top(qm, qc);
|
||||
}
|
||||
ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"Not answerable: Unlock QC index=%d\n",
|
||||
template_index, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"Not answerable: Unlock QC index=%d\n",
|
||||
template_index, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_runlock(&(templa[template_index].t_rwlock));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove_query from LRU list */
|
||||
|
||||
void
|
||||
remove_query (query_manager* qm, CachedQuery* qc)
|
||||
{
|
||||
CachedQuery* up;
|
||||
CachedQuery* down;
|
||||
|
||||
if (!qc)
|
||||
return;
|
||||
|
||||
up = qc->lru_up;
|
||||
down = qc->lru_down;
|
||||
|
||||
if (!up)
|
||||
qm->lru_top = down;
|
||||
|
||||
if (!down)
|
||||
qm->lru_bottom = up;
|
||||
|
||||
if (down)
|
||||
down->lru_up = up;
|
||||
|
||||
if (up)
|
||||
up->lru_down = down;
|
||||
|
||||
qc->lru_up = qc->lru_down = NULL;
|
||||
}
|
||||
|
||||
/* add query on top of LRU list */
|
||||
void
|
||||
add_query_on_top (query_manager* qm, CachedQuery* qc)
|
||||
{
|
||||
CachedQuery* top = qm->lru_top;
|
||||
Query* q = (Query*)qc;
|
||||
|
||||
qm->lru_top = qc;
|
||||
|
||||
if (top)
|
||||
top->lru_up = qc;
|
||||
else
|
||||
qm->lru_bottom = qc;
|
||||
|
||||
qc->lru_down = top;
|
||||
qc->lru_up = NULL;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Base of added query = %s\n",
|
||||
q->base.bv_val, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Base of added query = %s\n",
|
||||
q->base.bv_val, 0, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
free_query (CachedQuery* qc)
|
||||
{
|
||||
Query* q = (Query*)qc;
|
||||
free(qc->q_uuid);
|
||||
filter_free(q->filter);
|
||||
free (q->base.bv_val);
|
||||
|
||||
free(q->attrs);
|
||||
free(qc);
|
||||
}
|
||||
|
||||
/* compare base and scope of incoming and cached queries */
|
||||
int base_scope_compare(
|
||||
struct berval* dn_stored,
|
||||
struct berval* dn_incoming,
|
||||
int scope_stored,
|
||||
int scope_incoming )
|
||||
{
|
||||
struct berval ndn_incoming = { 0L, NULL };
|
||||
struct berval pdn_incoming = { 0L, NULL };
|
||||
struct berval ndn_stored = { 0L, NULL };
|
||||
|
||||
int i;
|
||||
|
||||
if (scope_stored < scope_incoming)
|
||||
return 0;
|
||||
|
||||
dnNormalize(0, NULL, NULL, dn_incoming, &ndn_incoming, NULL);
|
||||
dnNormalize(0, NULL, NULL, dn_stored, &ndn_stored, NULL);
|
||||
|
||||
i = dnIsSuffix(&ndn_incoming, &ndn_stored);
|
||||
|
||||
if ( i == 0 )
|
||||
return 0;
|
||||
|
||||
switch(scope_stored) {
|
||||
case LDAP_SCOPE_BASE:
|
||||
if (strlen(ndn_incoming.bv_val) == strlen(ndn_stored.bv_val))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case LDAP_SCOPE_ONELEVEL:
|
||||
switch(scope_incoming){
|
||||
case LDAP_SCOPE_BASE:
|
||||
dnParent(&ndn_incoming, &pdn_incoming);
|
||||
if(strcmp(pdn_incoming.bv_val, ndn_stored.bv_val) == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
case LDAP_SCOPE_ONELEVEL:
|
||||
if (ndn_incoming.bv_len == ndn_stored.bv_len)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
case LDAP_SCOPE_SUBTREE:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add query to query cache */
|
||||
void add_query(
|
||||
query_manager* qm,
|
||||
Query* query,
|
||||
int template_index,
|
||||
char* uuid,
|
||||
struct exception* result)
|
||||
{
|
||||
CachedQuery* new_cached_query = (CachedQuery*) malloc(sizeof(CachedQuery));
|
||||
QueryTemplate* templ = (qm->templates)+template_index;
|
||||
Query* new_query;
|
||||
new_cached_query->template_id = template_index;
|
||||
new_cached_query->q_uuid = uuid;
|
||||
new_cached_query->lru_up = NULL;
|
||||
new_cached_query->lru_down = NULL;
|
||||
new_cached_query->expiry_time = slap_get_time() + templ->ttl;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Added query expires at %ld\n",
|
||||
(long) new_cached_query->expiry_time, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Added query expires at %ld\n",
|
||||
(long) new_cached_query->expiry_time, 0, 0 );
|
||||
#endif
|
||||
new_query = (Query*)new_cached_query;
|
||||
|
||||
new_query->base.bv_val = ch_strdup(query->base.bv_val);
|
||||
new_query->base.bv_len = query->base.bv_len;
|
||||
new_query->scope = query->scope;
|
||||
new_query->filter = query->filter;
|
||||
new_query->attrs = query->attrs;
|
||||
|
||||
/* Adding a query */
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Lock AQ index = %d\n",
|
||||
template_index, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Lock AQ index = %d\n",
|
||||
template_index, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_wlock(&templ->t_rwlock);
|
||||
if (templ->query == NULL)
|
||||
templ->query_last = new_cached_query;
|
||||
else
|
||||
templ->query->prev = new_cached_query;
|
||||
new_cached_query->next = templ->query;
|
||||
new_cached_query->prev = NULL;
|
||||
templ->query = new_cached_query;
|
||||
templ->no_of_queries++;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "TEMPLATE %d QUERIES++ %d\n",
|
||||
template_index, templ->no_of_queries, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "TEMPLATE %d QUERIES++ %d\n",
|
||||
template_index, templ->no_of_queries, 0 );
|
||||
#endif
|
||||
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Unlock AQ index = %d \n",
|
||||
template_index, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Unlock AQ index = %d \n",
|
||||
template_index, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
|
||||
|
||||
/* Adding on top of LRU list */
|
||||
ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
|
||||
add_query_on_top(qm, new_cached_query);
|
||||
ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
|
||||
|
||||
}
|
||||
|
||||
/* remove bottom query of LRU list from the query cache */
|
||||
char* cache_replacement(query_manager* qm)
|
||||
{
|
||||
char* result = (char*)(malloc(40));
|
||||
CachedQuery* bottom;
|
||||
QueryTemplate* templ;
|
||||
CachedQuery* query_curr;
|
||||
int temp_id;
|
||||
|
||||
ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
|
||||
bottom = qm->lru_bottom;
|
||||
|
||||
if (!bottom) {
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG ( BACK_META, DETAIL1,
|
||||
"Cache replacement invoked without "
|
||||
"any query in LRU list\n", 0, 0, 0 );
|
||||
#else
|
||||
Debug ( LDAP_DEBUG_ANY,
|
||||
"Cache replacement invoked without "
|
||||
"any query in LRU list\n", 0, 0, 0 );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
temp_id = bottom->template_id;
|
||||
remove_query(qm, bottom);
|
||||
ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
|
||||
|
||||
strcpy(result, bottom->q_uuid);
|
||||
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Lock CR index = %d\n", temp_id, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Lock CR index = %d\n", temp_id, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_wlock(&(qm->templates[temp_id].t_rwlock));
|
||||
remove_from_template(bottom, (qm->templates+temp_id));
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "TEMPLATE %d QUERIES-- %d\n",
|
||||
temp_id, qm->templates[temp_id].no_of_queries, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "TEMPLATE %d QUERIES-- %d\n",
|
||||
temp_id, qm->templates[temp_id].no_of_queries, 0 );
|
||||
#endif
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1, "Unlock CR index = %d\n", temp_id, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "Unlock CR index = %d\n", temp_id, 0, 0 );
|
||||
#endif
|
||||
ldap_pvt_thread_rdwr_wunlock(&(qm->templates[temp_id].t_rwlock));
|
||||
free_query(bottom);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
remove_from_template (CachedQuery* qc, QueryTemplate* template)
|
||||
{
|
||||
if (!qc->prev && !qc->next) {
|
||||
template->query_last = template->query = NULL;
|
||||
} else if (qc->prev == NULL) {
|
||||
qc->next->prev = NULL;
|
||||
template->query = qc->next;
|
||||
} else if (qc->next == NULL) {
|
||||
qc->prev->next = NULL;
|
||||
template->query_last = qc->prev;
|
||||
} else {
|
||||
qc->next->prev = qc->prev;
|
||||
qc->prev->next = qc->next;
|
||||
}
|
||||
|
||||
template->no_of_queries--;
|
||||
}
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/socket.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/time.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "ldif.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
#include "ldap_pvt.h"
|
||||
#undef ldap_debug /* silence a warning in ldap-int.h */
|
||||
#include "ldap_log.h"
|
||||
#include "../../../libraries/libldap/ldap-int.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
static int
|
||||
remove_func (
|
||||
Operation *op,
|
||||
SlapReply *rs
|
||||
);
|
||||
|
||||
struct query_info {
|
||||
int freed;
|
||||
int deleted;
|
||||
struct berval* uuid;
|
||||
struct timeval tv;
|
||||
enum type_of_result err;
|
||||
};
|
||||
|
||||
int
|
||||
remove_query_data (
|
||||
Operation *op,
|
||||
SlapReply *rs,
|
||||
struct berval* query_uuid,
|
||||
struct exception* result)
|
||||
{
|
||||
struct query_info info;
|
||||
char filter_str[64];
|
||||
Operation op_tmp = *op;
|
||||
Filter *filter;
|
||||
long timediff;
|
||||
SlapReply sreply = {REP_RESULT};
|
||||
slap_callback cb = { remove_func, NULL };
|
||||
|
||||
sreply.sr_entry = NULL;
|
||||
sreply.sr_nentries = 0;
|
||||
snprintf(filter_str, sizeof(filter_str), "(queryid=%s)",
|
||||
query_uuid->bv_val);
|
||||
filter = str2filter(filter_str);
|
||||
info.uuid = query_uuid;
|
||||
info.freed = 0;
|
||||
info.deleted = 0;
|
||||
info.err = SUCCESS;
|
||||
cb.sc_private = &info;
|
||||
|
||||
op_tmp.o_tag = LDAP_REQ_SEARCH;
|
||||
op_tmp.o_protocol = LDAP_VERSION3;
|
||||
op_tmp.o_callback = &cb;
|
||||
op_tmp.o_time = slap_get_time();
|
||||
op_tmp.o_do_not_cache = 1;
|
||||
|
||||
op_tmp.o_req_dn = op->o_bd->be_suffix[0];
|
||||
op_tmp.o_req_ndn = op->o_bd->be_nsuffix[0];
|
||||
op_tmp.ors_scope = LDAP_SCOPE_SUBTREE;
|
||||
op_tmp.ors_deref = LDAP_DEREF_NEVER;
|
||||
op_tmp.ors_slimit = 0;
|
||||
op_tmp.ors_tlimit = 0;
|
||||
op_tmp.ors_filter = filter;
|
||||
op_tmp.ors_filterstr.bv_val = filter_str;
|
||||
op_tmp.ors_filterstr.bv_len = strlen(filter_str);
|
||||
op_tmp.ors_attrs = NULL;
|
||||
op_tmp.ors_attrsonly = 0;
|
||||
|
||||
op->o_bd->be_search( &op_tmp, &sreply );
|
||||
|
||||
result->type = info.err;
|
||||
result->rc = info.deleted;
|
||||
|
||||
return info.freed;
|
||||
}
|
||||
|
||||
static int
|
||||
remove_func (
|
||||
Operation *op,
|
||||
SlapReply *rs
|
||||
)
|
||||
{
|
||||
struct query_info *info = op->o_callback->sc_private;
|
||||
int count = 0;
|
||||
int size;
|
||||
long timediff;
|
||||
Modifications *mod;
|
||||
|
||||
Attribute *attr;
|
||||
Operation op_tmp = *op;
|
||||
|
||||
SlapReply sreply = {REP_RESULT};
|
||||
|
||||
if (rs->sr_type == REP_RESULT)
|
||||
return 0;
|
||||
|
||||
size = get_entry_size(rs->sr_entry, 0, NULL);
|
||||
|
||||
for (attr = rs->sr_entry->e_attrs; attr!= NULL; attr = attr->a_next) {
|
||||
if (attr->a_desc == slap_schema.si_ad_queryid) {
|
||||
for (count=0; attr->a_vals[count].bv_val; count++)
|
||||
;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
info->err = REMOVE_ERR;
|
||||
return 0;
|
||||
}
|
||||
if (count == 1) {
|
||||
info->freed += size;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
|
||||
size, attr->a_vals[0].bv_val, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "DELETING ENTRY SIZE=%d TEMPLATE=%s\n",
|
||||
size, attr->a_vals[0].bv_val, 0 );
|
||||
#endif
|
||||
|
||||
op_tmp.o_req_dn = rs->sr_entry->e_name;
|
||||
op_tmp.o_req_ndn = rs->sr_entry->e_nname;
|
||||
|
||||
if (op->o_bd->be_delete(&op_tmp, rs)) {
|
||||
info->err = REMOVE_ERR;
|
||||
} else {
|
||||
info->deleted++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
mod = (Modifications*)malloc(sizeof(Modifications));
|
||||
mod->sml_op = LDAP_MOD_DELETE;
|
||||
mod->sml_type.bv_len = sizeof("queryid");
|
||||
mod->sml_type.bv_val = "queryid";
|
||||
mod->sml_desc = slap_schema.si_ad_queryid;
|
||||
mod->sml_bvalues = (struct berval*) malloc( 2 * sizeof( struct berval) );
|
||||
ber_dupbv(mod->sml_bvalues, info->uuid);
|
||||
mod->sml_bvalues[1].bv_val = NULL;
|
||||
mod->sml_bvalues[1].bv_len = 0;
|
||||
mod->sml_next = NULL;
|
||||
#ifdef NEW_LOGGING
|
||||
LDAP_LOG( BACK_META, DETAIL1,
|
||||
"REMOVING TEMP ATTR : TEMPLATE=%s\n",
|
||||
attr->a_vals[0].bv_val, 0, 0 );
|
||||
#else
|
||||
Debug( LDAP_DEBUG_ANY, "REMOVING TEMP ATTR : TEMPLATE=%s\n",
|
||||
attr->a_vals[0].bv_val, 0, 0 );
|
||||
#endif
|
||||
|
||||
op_tmp.o_req_dn = rs->sr_entry->e_name;
|
||||
op_tmp.o_req_ndn = rs->sr_entry->e_nname;
|
||||
op_tmp.orm_modlist = mod;
|
||||
|
||||
if (op->o_bd->be_modify( &op_tmp, &sreply )) {
|
||||
info->err = REMOVE_ERR;
|
||||
}
|
||||
|
||||
info->freed += LDIF_SIZE_NEEDED(9, (strlen(info->uuid->bv_val)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,290 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/socket.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/time.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
#include "ldap_pvt.h"
|
||||
#undef ldap_debug /* silence a warning in ldap-int.h */
|
||||
#include "ldap_log.h"
|
||||
#include "../../../libraries/libldap/ldap-int.h"
|
||||
|
||||
#include "slap.h"
|
||||
#include "back-meta.h"
|
||||
|
||||
static char* invert_string(char* string);
|
||||
static struct berval* merge_init_final(struct berval*, struct berval*, struct berval*);
|
||||
static int strings_containment(struct berval* stored, struct berval* incoming);
|
||||
|
||||
/* find and remove string2 from string1
|
||||
* from start if position = 1,
|
||||
* from end if position = 3,
|
||||
* from anywhere if position = 2
|
||||
*/
|
||||
|
||||
int
|
||||
find_and_remove(struct berval* ber1, struct berval* ber2, int position)
|
||||
{
|
||||
char* temp;
|
||||
int len;
|
||||
int ret=0;
|
||||
|
||||
char* arg1, *arg2;
|
||||
char* string1=ber1->bv_val;
|
||||
char* string2=ber2->bv_val;
|
||||
|
||||
if (string2 == NULL)
|
||||
return 1;
|
||||
if (string1 == NULL)
|
||||
return 0;
|
||||
|
||||
if (position == 3) {
|
||||
arg1 = invert_string(string1);
|
||||
arg2 = invert_string(string2);
|
||||
} else {
|
||||
arg1 = string1;
|
||||
arg2 = string2;
|
||||
}
|
||||
|
||||
temp = strstr(arg1, arg2);
|
||||
len = strlen(arg2);
|
||||
|
||||
if (!temp)
|
||||
return 0;
|
||||
|
||||
switch (position) {
|
||||
case 1:
|
||||
if (temp == arg1) {
|
||||
string1 += len;
|
||||
ret = 1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
string1 = temp+len;
|
||||
ret = 1;
|
||||
break;
|
||||
case 3:
|
||||
temp = strstr(arg1, arg2);
|
||||
len = strlen(arg2);
|
||||
if (temp == arg1) {
|
||||
/*arg1 += len;*/
|
||||
string1 = invert_string(arg1+len);
|
||||
free(arg1);
|
||||
free(arg2);
|
||||
ret = 1;
|
||||
} else {
|
||||
free(arg1);
|
||||
free(arg2);
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
temp = (char*) malloc( strlen( string1 ) + 1 );
|
||||
strcpy( temp, string1 );
|
||||
free( ber1->bv_val );
|
||||
ber1->bv_val = temp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char*
|
||||
invert_string( char* string )
|
||||
{
|
||||
int len = strlen(string);
|
||||
int i;
|
||||
|
||||
char* inverted = (char*)(malloc(len+1));
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
inverted[i] = string[len-i-1];
|
||||
|
||||
inverted[len] ='\0';
|
||||
|
||||
return inverted;
|
||||
}
|
||||
|
||||
struct berval*
|
||||
merge_init_final(struct berval* init, struct berval* any, struct berval* final)
|
||||
{
|
||||
struct berval* merged, *temp;
|
||||
int i, any_count, count;
|
||||
|
||||
for (any_count=0; any && any[any_count].bv_val; any_count++)
|
||||
;
|
||||
|
||||
count = any_count;
|
||||
|
||||
if (init->bv_val)
|
||||
count++;
|
||||
if (final->bv_val)
|
||||
count++;
|
||||
|
||||
merged = (struct berval*)(malloc((count+1)*sizeof(struct berval)));
|
||||
temp = merged;
|
||||
|
||||
if (init->bv_val) {
|
||||
ber_dupbv(temp, init);
|
||||
temp++;
|
||||
}
|
||||
|
||||
for (i=0; i<any_count; i++) {
|
||||
ber_dupbv(temp, any);
|
||||
any++;
|
||||
temp++;
|
||||
}
|
||||
|
||||
if (final->bv_val){
|
||||
ber_dupbv(temp, final);
|
||||
temp++;
|
||||
}
|
||||
temp->bv_val = NULL;
|
||||
temp->bv_len = 0;
|
||||
return merged;
|
||||
}
|
||||
|
||||
int
|
||||
strings_containment(struct berval* stored, struct berval* incoming)
|
||||
{
|
||||
struct berval* element;
|
||||
int k=0;
|
||||
int j, rc = 0;
|
||||
|
||||
for ( element=stored; element->bv_val != NULL; element++ ) {
|
||||
for (j = k; incoming[j].bv_val != NULL; j++) {
|
||||
if (find_and_remove(&(incoming[j]), element, 2)) {
|
||||
k = j;
|
||||
rc = 1;
|
||||
break;
|
||||
}
|
||||
rc = 0;
|
||||
}
|
||||
if ( rc ) {
|
||||
continue;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
substr_containment_substr(Filter* stored, Filter* incoming)
|
||||
{
|
||||
int i;
|
||||
int k=0;
|
||||
int rc;
|
||||
int any_count = 0;
|
||||
|
||||
struct berval* init_incoming = (struct berval*)(malloc(sizeof(struct berval)));
|
||||
struct berval* final_incoming = (struct berval*)(malloc(sizeof(struct berval)));
|
||||
struct berval* any_incoming = NULL;
|
||||
struct berval* remaining_incoming;
|
||||
struct berval* any_element;
|
||||
|
||||
if ((!(incoming->f_sub_initial.bv_val) && (stored->f_sub_initial.bv_val))
|
||||
|| (!(incoming->f_sub_final.bv_val) && (stored->f_sub_final.bv_val)))
|
||||
return 0;
|
||||
|
||||
|
||||
ber_dupbv(init_incoming, &(incoming->f_sub_initial));
|
||||
ber_dupbv(final_incoming, &(incoming->f_sub_final));
|
||||
|
||||
if (incoming->f_sub_any) {
|
||||
for ( any_count=0; incoming->f_sub_any[any_count].bv_val != NULL;
|
||||
any_count++ )
|
||||
;
|
||||
|
||||
any_incoming = (struct berval*)malloc((any_count+1) *
|
||||
sizeof(struct berval));
|
||||
|
||||
for (i=0; i<any_count; i++) {
|
||||
ber_dupbv(&(any_incoming[i]), &(incoming->f_sub_any[i]));
|
||||
}
|
||||
any_incoming[any_count].bv_val = NULL;
|
||||
any_incoming[any_count].bv_len = 0;
|
||||
}
|
||||
|
||||
if (find_and_remove(init_incoming,
|
||||
&(stored->f_sub_initial), 1) && find_and_remove(final_incoming,
|
||||
&(stored->f_sub_final), 3))
|
||||
{
|
||||
if (stored->f_sub_any == NULL) {
|
||||
rc = 1;
|
||||
goto final;
|
||||
}
|
||||
remaining_incoming = merge_init_final(init_incoming,
|
||||
any_incoming, final_incoming);
|
||||
rc = strings_containment(stored->f_sub_any, remaining_incoming);
|
||||
goto final;
|
||||
}
|
||||
rc = 0;
|
||||
final:
|
||||
/*
|
||||
ber_bvfree(init_incoming);
|
||||
ber_bvfree(final_incoming);
|
||||
if (any_incoming) {
|
||||
for (i=0; i < any_count; i++)
|
||||
free(any_incoming[i].bv_val);
|
||||
free(any_incoming);
|
||||
}
|
||||
*/
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
substr_containment_equality(Filter* stored, Filter* incoming)
|
||||
{
|
||||
|
||||
struct berval* incoming_val = (struct berval*)(malloc(2*sizeof(struct berval)));
|
||||
int rc;
|
||||
|
||||
ber_dupbv(incoming_val, &(incoming->f_av_value));
|
||||
incoming_val[1].bv_val = NULL;
|
||||
incoming_val[1].bv_len = 0;
|
||||
|
||||
if (find_and_remove(incoming_val,
|
||||
&(stored->f_sub_initial), 1) && find_and_remove(incoming_val,
|
||||
&(stored->f_sub_final), 3)) {
|
||||
if (stored->f_sub_any == NULL){
|
||||
rc = 1;
|
||||
goto final;
|
||||
}
|
||||
rc = strings_containment(stored->f_sub_any, incoming_val);
|
||||
goto final;
|
||||
}
|
||||
rc=0;
|
||||
final:
|
||||
/*
|
||||
if(incoming_val[0].bv_val)
|
||||
free(incoming_val[0].bv_val);
|
||||
free(incoming_val);
|
||||
*/
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -1,247 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software based, in part, on existing OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#include "portable.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/socket.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/time.h>
|
||||
|
||||
#include "slap.h"
|
||||
#include "../back-ldap/back-ldap.h"
|
||||
#include "back-meta.h"
|
||||
#undef ldap_debug /* silence a warning in ldap-int.h */
|
||||
#include "../../../libraries/libldap/ldap-int.h"
|
||||
|
||||
void
|
||||
filter2template(
|
||||
Filter *f,
|
||||
struct berval *fstr,
|
||||
AttributeName** filter_attrs,
|
||||
int* filter_cnt,
|
||||
struct exception* result )
|
||||
{
|
||||
int i;
|
||||
Filter *p;
|
||||
struct berval tmp;
|
||||
ber_len_t len;
|
||||
const char* text;
|
||||
|
||||
/*
|
||||
* FIXME: should we use an assert here?
|
||||
*/
|
||||
if ( f == NULL ) {
|
||||
ber_str2bv( "No filter!", sizeof("No filter!")-1, 1, fstr );
|
||||
result->type = FILTER_ERR;
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( f->f_choice ) {
|
||||
case LDAP_FILTER_EQUALITY:
|
||||
fstr->bv_len = f->f_av_desc->ad_cname.bv_len +
|
||||
( sizeof("(=)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=)",
|
||||
f->f_av_desc->ad_cname.bv_val );
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt + 2)*sizeof(AttributeName));
|
||||
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[*filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_av_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_av_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt)++;
|
||||
break;
|
||||
case LDAP_FILTER_GE:
|
||||
fstr->bv_len = f->f_av_desc->ad_cname.bv_len +
|
||||
+ ( sizeof("(>=)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=)",
|
||||
f->f_av_desc->ad_cname.bv_val);
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt + 2)*sizeof(AttributeName));
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_av_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_av_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt)++;
|
||||
|
||||
break;
|
||||
|
||||
case LDAP_FILTER_LE:
|
||||
fstr->bv_len = f->f_av_desc->ad_cname.bv_len +
|
||||
+ ( sizeof("(<=)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=)",
|
||||
f->f_av_desc->ad_cname.bv_val);
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt + 2)*sizeof(AttributeName));
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_av_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_av_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt++);
|
||||
|
||||
break;
|
||||
|
||||
case LDAP_FILTER_APPROX:
|
||||
fstr->bv_len = f->f_av_desc->ad_cname.bv_len +
|
||||
+ ( sizeof("(~=)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=)",
|
||||
f->f_av_desc->ad_cname.bv_val);
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt + 2)*sizeof(AttributeName));
|
||||
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_av_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_av_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt)++;
|
||||
|
||||
break;
|
||||
|
||||
case LDAP_FILTER_SUBSTRINGS:
|
||||
fstr->bv_len = f->f_sub_desc->ad_cname.bv_len +
|
||||
( sizeof("(=)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=)",
|
||||
f->f_sub_desc->ad_cname.bv_val );
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt + 2)*sizeof(AttributeName));
|
||||
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_av_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_av_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt)++;
|
||||
|
||||
break;
|
||||
|
||||
case LDAP_FILTER_PRESENT:
|
||||
fstr->bv_len = f->f_desc->ad_cname.bv_len +
|
||||
( sizeof("(=*)") - 1 );
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
|
||||
f->f_desc->ad_cname.bv_val );
|
||||
|
||||
*filter_attrs = (AttributeName *)ch_realloc(*filter_attrs,
|
||||
(*filter_cnt+2)*sizeof(AttributeName));
|
||||
|
||||
#if 0 /* ? */
|
||||
ber_dupbv(&(*filter_attrs)[filter_cnt].an_name,
|
||||
&f->f_av_desc->ad_cname);
|
||||
#endif
|
||||
|
||||
(*filter_attrs)[*filter_cnt].an_name = f->f_desc->ad_cname;
|
||||
(*filter_attrs)[*filter_cnt].an_desc = NULL;
|
||||
slap_bv2ad(&f->f_desc->ad_cname,
|
||||
&(*filter_attrs)[*filter_cnt].an_desc, &text);
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_val = NULL;
|
||||
(*filter_attrs)[*filter_cnt+1].an_name.bv_len = 0;
|
||||
(*filter_cnt)++;
|
||||
|
||||
break;
|
||||
|
||||
case LDAP_FILTER_AND:
|
||||
case LDAP_FILTER_OR:
|
||||
case LDAP_FILTER_NOT:
|
||||
fstr->bv_len = sizeof("(%)") - 1;
|
||||
fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
|
||||
|
||||
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
|
||||
f->f_choice == LDAP_FILTER_AND ? '&' :
|
||||
f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
|
||||
|
||||
for ( p = f->f_list; p != NULL; p = p->f_next ) {
|
||||
len = fstr->bv_len;
|
||||
|
||||
filter2template( p, &tmp, filter_attrs, filter_cnt,
|
||||
result);
|
||||
if (result->type != SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
fstr->bv_len += tmp.bv_len;
|
||||
fstr->bv_val = ch_realloc( fstr->bv_val,
|
||||
fstr->bv_len + 1 );
|
||||
|
||||
snprintf( &fstr->bv_val[len-1], tmp.bv_len + 2,
|
||||
/*"("*/ "%s)", tmp.bv_val );
|
||||
|
||||
ch_free( tmp.bv_val );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
ber_str2bv( "(?=unknown)", sizeof("(?=unknown)")-1, 1, fstr );
|
||||
result->type = FILTER_ERR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,210 +0,0 @@
|
|||
/* $OpenLDAP$ */
|
||||
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
*
|
||||
* Copyright 1999-2003 The OpenLDAP Foundation.
|
||||
* Portions Copyright 2003 IBM Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
/* ACKNOWLEDGEMENTS:
|
||||
* This work was initially developed by the Apurva Kumar for inclusion
|
||||
* in OpenLDAP Software.
|
||||
*/
|
||||
|
||||
#ifndef META_CACHE_H
|
||||
#define META_CACHE_H
|
||||
#include "slap.h"
|
||||
|
||||
/* cache specific errors */
|
||||
enum type_of_result {
|
||||
SUCCESS,
|
||||
CONN_ERR,
|
||||
RESULT_ERR,
|
||||
FILTER_ERR,
|
||||
REWRITING_ERR,
|
||||
MERGE_ERR,
|
||||
REMOVE_ERR,
|
||||
SLIMIT_ERR,
|
||||
ABANDON_ERR,
|
||||
CREATE_ENTRY_ERR,
|
||||
TIMEOUT_ERR,
|
||||
SIZE_ERR,
|
||||
GET_SIZE_ERR
|
||||
};
|
||||
|
||||
|
||||
struct exception {
|
||||
enum type_of_result type;
|
||||
int rc;
|
||||
};
|
||||
|
||||
/* query cache structs */
|
||||
/* query */
|
||||
|
||||
typedef struct Query_s {
|
||||
Filter* filter; /* Search Filter */
|
||||
AttributeName* attrs; /* Projected attributes */
|
||||
struct berval base; /* Search Base */
|
||||
int scope; /* Search scope */
|
||||
} Query;
|
||||
|
||||
/* struct representing a cached query */
|
||||
typedef struct cached_query_s {
|
||||
Query query; /* LDAP query */
|
||||
char* q_uuid; /* query identifier */
|
||||
int template_id; /* template of the query */
|
||||
time_t expiry_time; /* time till the query is considered valid */
|
||||
struct cached_query_s *next; /* next query in the template */
|
||||
struct cached_query_s *prev; /* previous query in the template */
|
||||
struct cached_query_s *lru_up; /* previous query in the LRU list */
|
||||
struct cached_query_s *lru_down; /* next query in the LRU list */
|
||||
} CachedQuery;
|
||||
|
||||
/* struct representing a query template
|
||||
* e.g. template string = &(cn=)(mail=)
|
||||
*/
|
||||
typedef struct query_template_s {
|
||||
char* querystr; /* Filter string corresponding to the QT */
|
||||
char* base; /* Search base */
|
||||
int attr_set_index; /* determines the projected attributes */
|
||||
|
||||
CachedQuery* query; /* most recent query cached for the template */
|
||||
CachedQuery* query_last; /* oldest query cached for the template */
|
||||
|
||||
int no_of_queries; /* Total number of queries in the template */
|
||||
long ttl; /* TTL for the queries of this template */
|
||||
ldap_pvt_thread_rdwr_t t_rwlock; /* Rd/wr lock for accessing queries in the template */
|
||||
} QueryTemplate;
|
||||
|
||||
/*
|
||||
* Represents a set of projected attributes and any
|
||||
* supersets among all specified sets of attributes.
|
||||
*/
|
||||
|
||||
struct attr_set {
|
||||
AttributeName* attrs; /* specifies the set */
|
||||
int count; /* number of attributes */
|
||||
int* ID_array; /* array of indices of supersets of 'attrs' */
|
||||
};
|
||||
|
||||
struct query_manager_s;
|
||||
|
||||
/* prototypes for functions for 1) query containment
|
||||
* 2) query addition, 3) cache replacement
|
||||
*/
|
||||
typedef int (*QCfunc)(struct query_manager_s*, Query*, int );
|
||||
typedef void (*AddQueryfunc)(struct query_manager_s*, Query*, int, char*, struct exception* );
|
||||
typedef char* (*CRfunc)(struct query_manager_s* );
|
||||
|
||||
/* LDAP query cache */
|
||||
typedef struct query_manager_s {
|
||||
struct attr_set* attr_sets; /* possible sets of projected attributes */
|
||||
QueryTemplate* templates; /* cacheable templates */
|
||||
|
||||
CachedQuery* lru_top; /* top and bottom of LRU list */
|
||||
CachedQuery* lru_bottom;
|
||||
|
||||
ldap_pvt_thread_mutex_t lru_mutex; /* mutex for accessing LRU list */
|
||||
|
||||
/* Query cache methods */
|
||||
QCfunc qcfunc; /* Query containment*/
|
||||
CRfunc crfunc; /* cache replacement */
|
||||
AddQueryfunc addfunc; /* add query */
|
||||
} query_manager;
|
||||
|
||||
/* LDAP query cache manager */
|
||||
typedef struct cache_manager_s {
|
||||
unsigned long cache_size; /* current cache size (bytes) */
|
||||
unsigned long thresh_hi; /* cache capacity (bytes) */
|
||||
unsigned long thresh_lo; /* lower threshold for cache replacement */
|
||||
unsigned long num_cached_queries; /* total number of cached queries */
|
||||
unsigned long max_queries; /* upper bound on # of cached queries */
|
||||
int caching;
|
||||
|
||||
int numattrsets; /* number of attribute sets */
|
||||
int numtemplates; /* number of cacheable templates */
|
||||
int total_entries; /* total number of entries cached */
|
||||
int num_entries_limit; /* max # of entries in a cacheable query */
|
||||
int threads; /* number of threads currently in meta_back_search */
|
||||
|
||||
int cc_period; /* interval between successive consistency checks (sec) */
|
||||
int cc_thread_started;
|
||||
ldap_pvt_thread_t cc_thread;
|
||||
|
||||
ldap_pvt_thread_mutex_t cache_mutex;
|
||||
ldap_pvt_thread_mutex_t remove_mutex;
|
||||
ldap_pvt_thread_mutex_t cc_mutex;
|
||||
|
||||
query_manager* qm; /* query cache managed by the cache manager */
|
||||
} cache_manager;
|
||||
|
||||
/* search-cache.c */
|
||||
int
|
||||
meta_back_cache_search(
|
||||
Operation *op,
|
||||
SlapReply *rs
|
||||
);
|
||||
|
||||
/* config-cache.c */
|
||||
int
|
||||
meta_back_cache_config(
|
||||
BackendDB *be,
|
||||
const char *fname,
|
||||
int lineno,
|
||||
int argc,
|
||||
char **argv
|
||||
);
|
||||
|
||||
/* query-cache.c */
|
||||
int query_containment(query_manager*, Query*, int);
|
||||
void add_query(query_manager*, Query*, int, char*, struct exception*);
|
||||
char* cache_replacement(query_manager*);
|
||||
void remove_from_template (CachedQuery*, QueryTemplate*);
|
||||
void remove_query (query_manager*, CachedQuery*);
|
||||
void free_query (CachedQuery*);
|
||||
|
||||
/* substring.c */
|
||||
int substr_containment_substr(Filter*, Filter*);
|
||||
int substr_containment_equality(Filter*, Filter*);
|
||||
|
||||
/* template.c */
|
||||
void
|
||||
filter2template( Filter *f,
|
||||
struct berval *fstr,
|
||||
AttributeName** filter_attrs,
|
||||
int* filter_cnt,
|
||||
struct exception* result
|
||||
);
|
||||
|
||||
/* merge.c */
|
||||
|
||||
int
|
||||
merge_entry (
|
||||
Operation *op,
|
||||
SlapReply *rs,
|
||||
struct berval *query_uuid,
|
||||
struct exception *result
|
||||
);
|
||||
|
||||
int
|
||||
get_entry_size(Entry* e,
|
||||
int size_init,
|
||||
struct exception* result
|
||||
);
|
||||
|
||||
/* remove.c */
|
||||
int
|
||||
remove_query_data (
|
||||
Operation* conn,
|
||||
SlapReply *rs,
|
||||
struct berval* query_uuid,
|
||||
struct exception* result
|
||||
);
|
||||
#endif
|
||||
|
|
@ -565,10 +565,6 @@ meta_back_db_config(
|
|||
fname, lineno, argc, argv );
|
||||
/* anything else */
|
||||
} else {
|
||||
if ( meta_back_cache_config( be, fname, lineno, argc, argv ) == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf( stderr,
|
||||
"%s: line %d: unknown directive \"%s\" in meta database definition"
|
||||
" (ignored)\n",
|
||||
|
|
|
|||
|
|
@ -154,69 +154,24 @@ meta_back_db_init(
|
|||
struct metainfo *li;
|
||||
|
||||
struct rewrite_info *rwinfo;
|
||||
cache_manager *cm;
|
||||
query_manager *qm;
|
||||
|
||||
rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
|
||||
if ( rwinfo == NULL ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cm = (cache_manager *)ch_malloc(sizeof(cache_manager));
|
||||
if ( cm == NULL ) {
|
||||
rewrite_info_delete( &rwinfo );
|
||||
return -1;
|
||||
}
|
||||
|
||||
qm = (query_manager*)ch_malloc(sizeof(query_manager));
|
||||
if ( qm == NULL ) {
|
||||
rewrite_info_delete( &rwinfo );
|
||||
ch_free( cm );
|
||||
return -1;
|
||||
}
|
||||
|
||||
cm->caching = 0;
|
||||
cm->qm = qm;
|
||||
cm->numattrsets = 0;
|
||||
cm->numtemplates = 0;
|
||||
cm->num_entries_limit = 5;
|
||||
cm->cache_size = 0;
|
||||
cm->thresh_hi = 500000;
|
||||
cm->thresh_lo = 700000;
|
||||
cm->num_cached_queries = 0;
|
||||
cm->total_entries = 0;
|
||||
cm->max_queries = 10000;
|
||||
cm->threads = 0;
|
||||
cm->cc_thread_started = 0;
|
||||
cm->cc_period = 1000;
|
||||
|
||||
qm->attr_sets = NULL;
|
||||
qm->templates = NULL;
|
||||
qm->lru_top = NULL;
|
||||
qm->lru_bottom = NULL;
|
||||
|
||||
qm->qcfunc = query_containment;
|
||||
qm->crfunc = cache_replacement;
|
||||
qm->addfunc = add_query;
|
||||
ldap_pvt_thread_mutex_init(&qm->lru_mutex);
|
||||
|
||||
ldap_pvt_thread_mutex_init(&cm->cache_mutex);
|
||||
ldap_pvt_thread_mutex_init(&cm->remove_mutex);
|
||||
ldap_pvt_thread_mutex_init( &cm->cc_mutex );
|
||||
|
||||
li = ch_calloc( 1, sizeof( struct metainfo ) );
|
||||
if ( li == NULL ) {
|
||||
rewrite_info_delete( &rwinfo );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* At present the default is no default target;
|
||||
* this may change
|
||||
*/
|
||||
li->defaulttarget = META_DEFAULT_TARGET_NONE;
|
||||
li->cm = cm;
|
||||
li->rwinfo = rwinfo;
|
||||
/* FIXME: what about qm ? */
|
||||
|
||||
ldap_pvt_thread_mutex_init( &li->conn_mutex );
|
||||
ldap_pvt_thread_mutex_init( &li->cache.mutex );
|
||||
|
|
|
|||
|
|
@ -131,12 +131,6 @@ meta_back_search( Operation *op, SlapReply *rs )
|
|||
int isroot = 0;
|
||||
dncookie dc;
|
||||
|
||||
cache_manager* cm = li->cm;
|
||||
|
||||
if (cm->caching) {
|
||||
return meta_back_cache_search(op, rs);
|
||||
}
|
||||
|
||||
/*
|
||||
* controls are set in ldap_back_dobind()
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue