- if (!IS_PSEARCH) {
- if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
- if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
- struct berval cookie;
- slap_compose_sync_cookie( sop, &cookie, search_context_csn,
- sop->o_sync_state.sid, sop->o_sync_state.rid );
-
- if ( sync_send_present_mode ) {
- rs->sr_err = LDAP_SUCCESS;
- rs->sr_rspoid = LDAP_SYNC_INFO;
- rs->sr_ctrls = NULL;
- slap_send_syncinfo( sop, rs,
- LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
-
- } else {
- if ( !no_sync_state_change ) {
- int slog_found = 0;
- ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
- LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
- o_ps_link )
- {
- if ( ps_list->o_sync_slog_size > 0 ) {
- if ( ps_list->o_sync_state.sid ==
- sop->o_sync_state.sid )
- {
- slog_found = 1;
- break;
- }
- }
- }
-
- if ( slog_found ) {
- rs->sr_err = LDAP_SUCCESS;
- rs->sr_rspoid = NULL;
- rs->sr_ctrls = NULL;
- slap_send_session_log( op, ps_list, rs );
- }
- ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
- }
-
- rs->sr_err = LDAP_SUCCESS;
- rs->sr_rspoid = LDAP_SYNC_INFO;
- rs->sr_ctrls = NULL;
- slap_send_syncinfo( sop, rs,
- LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
- }
-
- if ( cookie.bv_val ) ch_free( cookie.bv_val );
-
- } else {
- /* refreshOnly mode */
- struct berval cookie;
- slap_compose_sync_cookie( sop, &cookie, search_context_csn,
- sop->o_sync_state.sid, sop->o_sync_state.rid );
-
- if ( sync_send_present_mode ) {
- slap_build_sync_done_ctrl( sop, rs, ctrls,
- num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
-
- } else {
- if ( !no_sync_state_change ) {
- int slog_found = 0;
- ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
- LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
- o_ps_link )
- {
- if ( ps_list->o_sync_slog_size > 0 ) {
- if ( ps_list->o_sync_state.sid ==
- sop->o_sync_state.sid ) {
- slog_found = 1;
- break;
- }
- }
- }
-
- if ( slog_found ) {
- slap_send_session_log( op, ps_list, rs );
- }
- ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
- }
-
- slap_build_sync_done_ctrl( sop, rs, ctrls,
- num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
- }
-
- rs->sr_ctrls = ctrls;
- rs->sr_ref = rs->sr_v2ref;
- rs->sr_err = (rs->sr_v2ref == NULL)
- ? LDAP_SUCCESS : LDAP_REFERRAL;
- rs->sr_rspoid = NULL;
- send_ldap_result( sop, rs );
- if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
- slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
- sop->o_tmpmemctx );
- }
- slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
- ctrls[num_ctrls] = NULL;
- if ( cookie.bv_val ) ch_free( cookie.bv_val );
- }
-
- } else {
- rs->sr_ctrls = NULL;
- rs->sr_ref = rs->sr_v2ref;
- rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
- rs->sr_rspoid = NULL;
- if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
- send_paged_response( sop, rs, NULL, 0 );
- } else {
- send_ldap_result( sop, rs );
- }
- }