]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/sssvlv.c
ITS#6850
[openldap] / servers / slapd / overlays / sssvlv.c
index a8ded053a03bc445052065707a14c1afa3b557b2..bb779e6c76a65e4f85567cac50f72413dcfcc57f 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2009-2010 The OpenLDAP Foundation.
+ * Copyright 2009-2011 The OpenLDAP Foundation.
  * Portions copyright 2009 Symas Corporation.
  * All rights reserved.
  *
@@ -164,11 +164,13 @@ static int node_cmp( const void* val1, const void* val2 )
 {
        sort_node *sn1 = (sort_node *)val1;
        sort_node *sn2 = (sort_node *)val2;
-       assert( sort_conns[sn1->sn_conn] && sort_conns[sn1->sn_conn][sn1->sn_session]
-               && sort_conns[sn1->sn_conn][sn1->sn_session]->so_ctrl );
-       sort_ctrl *sc = sort_conns[sn1->sn_conn][sn1->sn_session]->so_ctrl;
+       sort_ctrl *sc;
        MatchingRule *mr;
        int i, cmp = 0;
+       assert( sort_conns[sn1->sn_conn]
+               && sort_conns[sn1->sn_conn][sn1->sn_session]
+               && sort_conns[sn1->sn_conn][sn1->sn_session]->so_ctrl );
+       sc = sort_conns[sn1->sn_conn][sn1->sn_session]->so_ctrl;
 
        for ( i=0; cmp == 0 && i<sc->sc_nkeys; i++ ) {
                if ( BER_BVISNULL( &sn1->sn_vals[i] )) {
@@ -339,6 +341,23 @@ static int pack_sss_response_control(
        return rs->sr_err;
 }
 
+/* Return the session id or -1 if unknown */
+static int find_session_by_so(
+       int svi_max_percon,
+       int conn_id,
+       sort_op *so )
+{
+       int sess_id;
+       if (so == NULL) {
+               return -1;
+       }
+       for (sess_id = 0; sess_id < svi_max_percon; sess_id++) {
+               if ( sort_conns[conn_id] && sort_conns[conn_id][sess_id] == so )
+                       return sess_id;
+       }
+       return -1;
+}
+
 /* Return the session id or -1 if unknown */
 static int find_session_by_context(
        int svi_max_percon,
@@ -377,14 +396,13 @@ static int find_next_session(
 static void free_sort_op( Connection *conn, sort_op *so )
 {
        int sess_id;
-       PagedResultsCookie ps_cookie = (PagedResultsCookie) so->so_tree;
        if ( so->so_tree ) {
                tavl_free( so->so_tree, ch_free );
                so->so_tree = NULL;
        }
 
        ldap_pvt_thread_mutex_lock( &sort_conns_mutex );
-       sess_id = find_session_by_context( so->so_info->svi_max_percon, conn->c_conn_idx, so->so_vcontext, ps_cookie );
+       sess_id = find_session_by_so( so->so_info->svi_max_percon, conn->c_conn_idx, so );
        sort_conns[conn->c_conn_idx][sess_id] = NULL;
        so->so_info->svi_num--;
        ldap_pvt_thread_mutex_unlock( &sort_conns_mutex );
@@ -490,7 +508,7 @@ range_err:
                        sc->sc_nkeys * sizeof(struct berval), op->o_tmpmemctx );
                sn->sn_vals = (struct berval *)(sn+1);
                sn->sn_conn = op->o_conn->c_conn_idx;
-               sn->sn_session = find_session_by_context( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, vc->vc_context, NO_PS_COOKIE );
+               sn->sn_session = find_session_by_so( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so );
                sn->sn_vals[0] = bv;
                for (i=1; i<sc->sc_nkeys; i++) {
                        BER_BVZERO( &sn->sn_vals[i] );
@@ -729,7 +747,7 @@ static int sssvlv_op_response(
                op->o_tmpfree( sn, op->o_tmpmemctx );
                sn = sn2;
                sn->sn_conn = op->o_conn->c_conn_idx;
-               sn->sn_session = find_session_by_context( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so->so_vcontext, (PagedResultsCookie) so->so_tree );
+               sn->sn_session = find_session_by_so( so->so_info->svi_max_percon, op->o_conn->c_conn_idx, so );
 
                /* Insert into the AVL tree */
                tavl_insert(&(so->so_tree), sn, node_insert, avl_dup_error);
@@ -1274,10 +1292,6 @@ static int sssvlv_db_init(
                if ( rc != LDAP_SUCCESS ) {
                        Debug( LDAP_DEBUG_ANY, "Failed to register VLV Request control '%s' (%d)\n",
                                LDAP_CONTROL_VLVREQUEST, rc, 0 );
-#ifdef SLAP_CONFIG_DELETE
-                       overlay_unregister_control( be, LDAP_CONTROL_SORTREQUEST );
-#endif /* SLAP_CONFIG_DELETE */
-                       unregister_supported_control( LDAP_CONTROL_SORTREQUEST );
                        return rc;
                }
        }
@@ -1313,10 +1327,6 @@ static int sssvlv_db_destroy(
                ldap_pvt_thread_mutex_destroy( &sort_conns_mutex );
        }
 
-       if ( ov_count == 0 ) {
-               unregister_supported_control( LDAP_CONTROL_SORTREQUEST );
-       }
-       
        if ( si ) {
                ch_free( si );
                on->on_bi.bi_private = NULL;