version 1.9.2.8, 2008/02/11 23:24:25
|
version 1.10, 2005/08/26 19:42:48
|
Line 1
|
Line 1
|
/* valsort.c - sort attribute values */ |
/* valsort.c - sort attribute values */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/valsort.c,v 1.9.2.7 2007/06/08 08:13:18 hyc Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/overlays/valsort.c,v 1.9 2005/08/25 04:56:09 hyc Exp $ */ |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
* |
* |
* Copyright 2005-2008 The OpenLDAP Foundation. |
* Copyright 2005 The OpenLDAP Foundation. |
* Portions copyright 2005 Symas Corporation. |
* Portions copyright 2005 Symas Corporation. |
* All rights reserved. |
* All rights reserved. |
* |
* |
Line 212 static void
|
Line 212 static void
|
do_sort( Operation *op, Attribute *a, int beg, int num, slap_mask_t sort ) |
do_sort( Operation *op, Attribute *a, int beg, int num, slap_mask_t sort ) |
{ |
{ |
int i, j, gotnvals; |
int i, j, gotnvals; |
struct berval tmp, ntmp, *vals = NULL, *nvals; |
struct berval tmp, ntmp, *vals, *nvals; |
|
|
gotnvals = (a->a_vals != a->a_nvals ); |
gotnvals = (a->a_vals != a->a_nvals ); |
|
|
Line 272 valsort_response( Operation *op, SlapRep
|
Line 272 valsort_response( Operation *op, SlapRep
|
valsort_info *vi; |
valsort_info *vi; |
Attribute *a; |
Attribute *a; |
|
|
/* If this is not a search response, or it is a syncrepl response, |
/* We only want search responses */ |
* or the valsort control wants raw results, pass thru unmodified. |
if ( rs->sr_type != REP_SEARCH ) return SLAP_CB_CONTINUE; |
*/ |
|
if ( rs->sr_type != REP_SEARCH || |
/* If this is a syncrepl response, pass thru unmodified */ |
( _SCM(op->o_sync) > SLAP_CONTROL_IGNORED ) || |
if ( op->o_sync > SLAP_CONTROL_IGNORED ) return SLAP_CB_CONTINUE; |
( op->o_ctrlflag[valsort_cid] & SLAP_CONTROL_DATA0)) |
|
return SLAP_CB_CONTINUE; |
|
|
|
on = (slap_overinst *) op->o_bd->bd_info; |
on = (slap_overinst *) op->o_bd->bd_info; |
vi = on->on_bi.bi_private; |
vi = on->on_bi.bi_private; |
Line 314 valsort_response( Operation *op, SlapRep
|
Line 312 valsort_response( Operation *op, SlapRep
|
gotnvals = (a->a_vals != a->a_nvals ); |
gotnvals = (a->a_vals != a->a_nvals ); |
|
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
char *ptr = ber_bvchr( &a->a_nvals[i], '{' ); |
char *ptr = strchr( a->a_nvals[i].bv_val, '{' ); |
char *end = NULL; |
char *end = NULL; |
if ( !ptr ) { |
if ( !ptr ) { |
Debug(LDAP_DEBUG_TRACE, "weights missing from attr %s " |
Debug(LDAP_DEBUG_TRACE, "weights missing from attr %s " |
Line 339 valsort_response( Operation *op, SlapRep
|
Line 337 valsort_response( Operation *op, SlapRep
|
|
|
if ( a->a_vals != a->a_nvals ) { |
if ( a->a_vals != a->a_nvals ) { |
ptr = a->a_vals[i].bv_val; |
ptr = a->a_vals[i].bv_val; |
end = ber_bvchr( &a->a_vals[i], '}' ); |
end = strchr( ptr, '}' ) + 1; |
assert( end != NULL ); |
|
end++; |
|
for (;*end;) |
for (;*end;) |
*ptr++ = *end++; |
*ptr++ = *end++; |
*ptr = '\0'; |
*ptr = '\0'; |
Line 409 valsort_add( Operation *op, SlapReply *r
|
Line 405 valsort_add( Operation *op, SlapReply *r
|
if ( !a ) |
if ( !a ) |
continue; |
continue; |
for (i=0; !BER_BVISNULL( &a->a_vals[i] ); i++) { |
for (i=0; !BER_BVISNULL( &a->a_vals[i] ); i++) { |
ptr = ber_bvchr(&a->a_vals[i], '{' ); |
ptr = strchr(a->a_vals[i].bv_val, '{' ); |
if ( !ptr ) { |
if ( !ptr ) { |
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n", |
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n", |
vi->vi_ad->ad_cname.bv_val, 0, 0); |
vi->vi_ad->ad_cname.bv_val, 0, 0); |
Line 447 valsort_modify( Operation *op, SlapReply
|
Line 443 valsort_modify( Operation *op, SlapReply
|
if ( !(vi->vi_sort & VALSORT_WEIGHTED )) |
if ( !(vi->vi_sort & VALSORT_WEIGHTED )) |
continue; |
continue; |
for (ml = op->orm_modlist; ml; ml=ml->sml_next ) { |
for (ml = op->orm_modlist; ml; ml=ml->sml_next ) { |
/* Must be a Delete Attr op, so no values to consider */ |
|
if ( !ml->sml_values ) |
|
continue; |
|
if ( ml->sml_desc == vi->vi_ad ) |
if ( ml->sml_desc == vi->vi_ad ) |
break; |
break; |
} |
} |
if ( !ml ) |
if ( !ml ) |
continue; |
continue; |
for (i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++) { |
for (i=0; !BER_BVISNULL( &ml->sml_values[i] ); i++) { |
ptr = ber_bvchr(&ml->sml_values[i], '{' ); |
ptr = strchr(ml->sml_values[i].bv_val, '{' ); |
if ( !ptr ) { |
if ( !ptr ) { |
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n", |
Debug(LDAP_DEBUG_TRACE, "weight missing from attribute %s\n", |
vi->vi_ad->ad_cname.bv_val, 0, 0); |
vi->vi_ad->ad_cname.bv_val, 0, 0); |
Line 478 valsort_modify( Operation *op, SlapReply
|
Line 471 valsort_modify( Operation *op, SlapReply
|
} |
} |
|
|
static int |
static int |
valsort_db_open( |
|
BackendDB *be |
|
) |
|
{ |
|
return overlay_register_control( be, LDAP_CONTROL_VALSORT ); |
|
} |
|
|
|
static int |
|
valsort_destroy( |
valsort_destroy( |
BackendDB *be |
BackendDB *be |
) |
) |
Line 508 valsort_parseCtrl(
|
Line 493 valsort_parseCtrl(
|
SlapReply *rs, |
SlapReply *rs, |
LDAPControl *ctrl ) |
LDAPControl *ctrl ) |
{ |
{ |
ber_tag_t tag; |
if ( ctrl->ldctl_value.bv_len ) { |
BerElementBuffer berbuf; |
rs->sr_text = "valSort control value not empty"; |
BerElement *ber = (BerElement *)&berbuf; |
|
ber_int_t flag = 0; |
|
|
|
if ( ctrl->ldctl_value.bv_len == 0 ) { |
|
rs->sr_text = "valSort control value is empty (or absent)"; |
|
return LDAP_PROTOCOL_ERROR; |
|
} |
|
|
|
ber_init2( ber, &ctrl->ldctl_value, 0 ); |
|
if (( tag = ber_scanf( ber, "{b}", &flag )) == LBER_ERROR ) { |
|
rs->sr_text = "valSort control: flag decoding error"; |
|
return LDAP_PROTOCOL_ERROR; |
return LDAP_PROTOCOL_ERROR; |
} |
} |
|
|
op->o_ctrlflag[valsort_cid] = ctrl->ldctl_iscritical ? |
op->o_ctrlflag[valsort_cid] = ctrl->ldctl_iscritical ? |
SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL; |
SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL; |
if ( flag ) |
|
op->o_ctrlflag[valsort_cid] |= SLAP_CONTROL_DATA0; |
|
|
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
} |
|
|
static slap_overinst valsort; |
static slap_overinst valsort; |
|
|
int valsort_initialize( void ) |
int valsort_init() |
{ |
{ |
int rc; |
int rc; |
|
|
valsort.on_bi.bi_type = "valsort"; |
valsort.on_bi.bi_type = "valsort"; |
valsort.on_bi.bi_db_destroy = valsort_destroy; |
valsort.on_bi.bi_db_destroy = valsort_destroy; |
valsort.on_bi.bi_db_open = valsort_db_open; |
|
|
|
valsort.on_bi.bi_op_add = valsort_add; |
valsort.on_bi.bi_op_add = valsort_add; |
valsort.on_bi.bi_op_modify = valsort_modify; |
valsort.on_bi.bi_op_modify = valsort_modify; |
Line 567 int valsort_initialize( void )
|
Line 537 int valsort_initialize( void )
|
|
|
#if SLAPD_OVER_VALSORT == SLAPD_MOD_DYNAMIC |
#if SLAPD_OVER_VALSORT == SLAPD_MOD_DYNAMIC |
int init_module( int argc, char *argv[]) { |
int init_module( int argc, char *argv[]) { |
return valsort_initialize(); |
return valsort_init(); |
} |
} |
#endif |
#endif |
|
|