Lines Matching defs:ld

46 static int check_response_queue( LDAP *ld, int msgid, int all,
48 static int ldap_abandoned( LDAP *ld, int msgid );
49 static int ldap_mark_abandoned( LDAP *ld, int msgid );
50 static int wait4msg( LDAP *ld, int msgid, int all, int unlock_permitted,
52 static int read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc,
54 static void check_for_refs( LDAP *ld, LDAPRequest *lr, BerElement *ber,
56 static int build_result_ber( LDAP *ld, BerElement **berp, LDAPRequest *lr );
57 static void merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr );
59 static int cldap_select1( LDAP *ld, struct timeval *timeout );
61 static void link_pend( LDAP *ld, LDAPPend *lp );
63 static void unlink_pend( LDAP *ld, LDAPPend *lp );
64 static int unlink_msg( LDAP *ld, int msgid, int all );
84 LDAP *ld,
95 if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
99 LDAP_MUTEX_LOCK( ld, LDAP_RESULT_LOCK );
101 rc = nsldapi_result_nolock(ld, msgid, all, 1, timeout, result);
103 LDAP_MUTEX_UNLOCK( ld, LDAP_RESULT_LOCK );
110 nsldapi_result_nolock( LDAP *ld, int msgid, int all, int unlock_permitted,
126 LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
130 if ( check_response_queue( ld, msgid, all, 1, result ) != 0 ) {
131 LDAP_SET_LDERRNO( ld, LDAP_SUCCESS, NULL, NULL );
134 rc = wait4msg( ld, msgid, all, unlock_permitted, timeout,
141 if ( ld->ld_memcache != NULL && NSLDAPI_SEARCH_RELATED_RESULT( rc ) &&
143 ldap_memcache_append( ld, (*result)->lm_msgid,
162 check_response_queue( LDAP *ld, int msgid, int all, int do_abandon_check,
173 LDAP_MUTEX_LOCK( ld, LDAP_RESP_LOCK );
174 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm ) {
177 if ( do_abandon_check && ldap_abandoned( ld, lm->lm_msgid ) ) {
178 ldap_mark_abandoned( ld, lm->lm_msgid );
181 ld->ld_responses = lm->lm_next;
206 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
223 || (( lr = nsldapi_find_request_by_msgid( ld, lm->lm_msgid ))
225 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
235 ld->ld_responses = lm->lm_next;
241 ld->ld_responses = lm->lm_chain;
242 ld->ld_responses->lm_next = lm->lm_next;
250 ld->ld_responses = lm->lm_next;
260 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
271 wait4msg( LDAP *ld, int msgid, int all, int unlock_permitted,
289 LDAPDebug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
295 if ( ld->ld_cache_on && ld->ld_cache_result != NULL ) {
296 /* if ( unlock_permitted ) LDAP_MUTEX_UNLOCK( ld ); */
297 LDAP_MUTEX_LOCK( ld, LDAP_CACHE_LOCK );
298 rc = (ld->ld_cache_result)( ld, msgid, all, timeout, result );
299 LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
300 /* if ( unlock_permitted ) LDAP_MUTEX_LOCK( ld ); */
304 if ( ld->ld_cache_strategy == LDAP_CACHE_LOCALDB ) {
305 LDAP_SET_LDERRNO( ld, LDAP_TIMEOUT, NULL, NULL );
315 LDAP_MUTEX_LOCK( ld, LDAP_REQ_LOCK );
316 if (( lr = nsldapi_find_request_by_msgid( ld, msgid ))
318 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
319 LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL,
326 nsldapi_free_request( ld, lr, 1 );
327 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
328 LDAP_SET_LDERRNO( ld, LDAP_SERVER_DOWN, NULL, NULL );
331 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
352 nsldapi_dump_connection( ld, ld->ld_conns, 1 );
353 nsldapi_dump_requests_and_responses( ld );
356 LDAP_MUTEX_LOCK( ld, LDAP_CONN_LOCK );
357 LDAP_MUTEX_LOCK( ld, LDAP_REQ_LOCK );
358 for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
361 rc = read1msg( ld, msgid, all, lc->lconn_sb,
366 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
367 LDAP_MUTEX_UNLOCK( ld, LDAP_CONN_LOCK );
370 rc = nsldapi_iostatus_poll( ld, tvp );
376 LDAP_GET_ERRNO( ld ), 0, 0 );
381 if ( rc == 0 || ( rc == -1 && (( ld->ld_options &
383 LDAP_GET_ERRNO( ld ) != EINTR ))) {
387 LDAP_SET_LDERRNO( ld, (rc == -1 ?
391 LDAP_MUTEX_LOCK( ld, LDAP_REQ_LOCK );
392 nsldapi_connection_lost_nolock( ld,
394 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
403 LDAP_MUTEX_LOCK( ld, LDAP_CONN_LOCK );
404 LDAP_MUTEX_LOCK( ld, LDAP_REQ_LOCK );
405 for ( lc = ld->ld_conns; rc == -2 && lc != NULL;
410 nsldapi_iostatus_is_read_ready( ld,
412 rc = read1msg( ld, msgid, all,
415 else if (ld->ld_options & LDAP_BITOPT_ASYNC) {
418 && nsldapi_iostatus_is_write_ready( ld,
420 rc = nsldapi_ber_flush( ld, lc->lconn_sb, lr->lr_ber, 0, 1 );
427 nsldapi_iostatus_interest_read( ld, lc->lconn_sb );
430 LDAP_SET_LDERRNO( ld, LDAP_SERVER_DOWN, NULL, NULL );
431 nsldapi_free_request( ld, lr, 0 );
432 nsldapi_free_connection( ld, lc, NULL, NULL,
439 LDAP_MUTEX_UNLOCK( ld, LDAP_REQ_LOCK );
440 LDAP_MUTEX_UNLOCK( ld, LDAP_CONN_LOCK );
453 check_response_queue( ld, msgid, all, 0, result ) != 0 ) {
454 LDAP_SET_LDERRNO( ld, LDAP_SUCCESS, NULL, NULL );
470 LDAP_SET_LDERRNO( ld, LDAP_TIMEOUT, NULL,
479 LDAPDebug( LDAP_DEBUG_TRACE, "wait4msg: %ld secs to go\n",
493 read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc,
514 if ( lc->lconn_ber == NULLBER && nsldapi_alloc_ber_with_options( ld,
523 LDAP_SET_ERRNO( ld, 0 );
528 terrno = LDAP_GET_ERRNO( ld );
532 LDAP_SET_LDERRNO( ld, (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
535 nsldapi_connection_lost_nolock( ld, sb );
549 LDAP_SET_LDERRNO( ld, LDAP_DECODING_ERROR, NULL, NULL );
554 if ( ldap_abandoned( ld, (int)id ) ) {
561 } else if (( lr = nsldapi_find_request_by_msgid( ld, id )) == NULL ) {
563 "no request for response with msgid %ld (tossing)\n",
571 LDAP_SET_LDERRNO( ld, LDAP_DECODING_ERROR, NULL, NULL );
574 LDAPDebug( LDAP_DEBUG_TRACE, "got %s msgid %ld, original id %d\n",
589 check_for_refs( ld, lr, ber, lc->lconn_version, &reftotal,
624 if ( LDAP_SUCCESS == nsldapi_parse_result( ld,
648 merge_error_info( ld, lr->lr_parent, lr );
669 "request %ld done\n", id, 0, 0 );
679 if ( build_result_ber( ld, &ber, lr )
687 nsldapi_free_request( ld, lr, 1 );
701 LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
714 if ( ld->ld_cache_on ) {
715 nsldapi_add_result_to_cache( ld, new );
730 LDAP_SET_LDERRNO( ld, LDAP_SUCCESS, NULL,
744 LDAP_MUTEX_LOCK( ld, LDAP_RESP_LOCK );
745 for ( l = ld->ld_responses; l != NULL; l = l->lm_next ) {
754 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
756 LDAP_SET_LDERRNO( ld, LDAP_SUCCESS, NULL, NULL );
760 new->lm_next = ld->ld_responses;
761 ld->ld_responses = new;
765 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
767 POST( ld, new->lm_msgid, new );
806 ld->ld_responses = new;
836 ld->ld_responses = new;
866 ld->ld_responses = l->lm_chain;
877 ld->ld_responses = l->lm_next;
883 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
884 LDAP_SET_LDERRNO( ld, LDAP_SUCCESS, NULL, NULL );
887 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
897 check_for_refs( LDAP *ld, LDAPRequest *lr, BerElement *ber,
908 && ( ld->ld_options & LDAP_BITOPT_REFERRALS ) == 0 )) {
914 err = nsldapi_parse_reference( ld, ber, &v3refs, NULL );
918 err = nsldapi_parse_result( ld, lr->lr_res_msgtype, ber,
929 err = nsldapi_chase_v3_refs( ld, lr, v3refs,
937 err = nsldapi_chase_v2_referrals( ld, lr, &errstr,
984 build_result_ber( LDAP *ld, BerElement **berp, LDAPRequest *lr )
991 if (( err = nsldapi_alloc_ber_with_options( ld, &ber ))
1015 merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
1023 (void)nsldapi_append_referral( ld, &parentr->lr_res_error,
1055 cldap_select1( LDAP *ld, struct timeval *timeout )
1059 NSLDAPIIOStatus *iosp = ld->ld_iostatus;
1080 FD_SET( ld->ld_sbp->sb_sd, &readfds );
1088 pollfds[0].lpoll_fd = ld->ld_sbp->sb_sd;
1089 pollfds[0].lpoll_arg = ld->ld_sbp->sb_arg;
1092 rc = ld->ld_extpoll_fn( pollfds, 1, nsldapi_tv2ms( timeout ),
1093 ld->ld_ext_session_arg );
1107 cldap_select1( LDAP *ld, struct timeval *timeout )
1110 return( tcpselect( ld->ld_sbp->sb_sd, timeout ));
1118 cldap_select1( LDAP *ld, struct timeval *timeout )
1124 FD_SET( ld->ld_sbp->sb_sd, &readfds );
1126 if ( NSLDAPI_IO_TYPE_STANDARD == ld->ldiou_type &&
1127 NULL != ld->ld_select_fn ) {
1128 rc = ld->ld_select_fn( 1, &readfds, 0, 0, timeout );
1129 } else if ( NSLDAPI_IO_TYPE_EXTENDED == ld->ldiou_type &&
1130 NULL != ld->ld_extselect_fn ) {
1131 rc = ld->ld_extselect_fn( ld->ld_ext_session_arg, 1, &readfds, 0,
1168 ldap_msgdelete( LDAP *ld, int msgid )
1175 if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
1180 LDAP_MUTEX_LOCK( ld, LDAP_RESP_LOCK );
1181 for ( lm = ld->ld_responses; lm != NULL; lm = lm->lm_next ) {
1189 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
1194 ld->ld_responses = lm->lm_next;
1197 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );
1213 ldap_abandoned( LDAP *ld, int msgid )
1217 LDAP_MUTEX_LOCK( ld, LDAP_ABANDON_LOCK );
1218 if ( ld->ld_abandoned == NULL )
1220 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1224 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
1225 if ( ld->ld_abandoned[i] == msgid )
1227 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1231 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1237 ldap_mark_abandoned( LDAP *ld, int msgid )
1241 LDAP_MUTEX_LOCK( ld, LDAP_ABANDON_LOCK );
1242 if ( ld->ld_abandoned == NULL )
1244 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1248 for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
1249 if ( ld->ld_abandoned[i] == msgid )
1252 if ( ld->ld_abandoned[i] == -1 )
1254 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1258 for ( ; ld->ld_abandoned[i] != -1; i++ ) {
1259 ld->ld_abandoned[i] = ld->ld_abandoned[i + 1];
1262 LDAP_MUTEX_UNLOCK( ld, LDAP_ABANDON_LOCK );
1269 cldap_getmsg( LDAP *ld, struct timeval *timeout, BerElement **ber )
1275 if ( ld->ld_sbp->sb_ber.ber_ptr >= ld->ld_sbp->sb_ber.ber_end ) {
1276 rc = cldap_select1( ld, timeout );
1278 LDAP_SET_LDERRNO( ld, (rc == -1 ? LDAP_SERVER_DOWN :
1285 if ( (tag = ber_get_next( ld->ld_sbp, &len, ber ))
1287 LDAP_SET_LDERRNO( ld, (tag == LBER_DEFAULT ? LDAP_SERVER_DOWN :
1297 nsldapi_post_result( LDAP *ld, int msgid, LDAPMessage *result )
1302 "nsldapi_post_result(ld=0x%x, msgid=%d, result=0x%x)\n",
1303 ld, msgid, result );
1304 LDAP_MUTEX_LOCK( ld, LDAP_PEND_LOCK );
1309 for( lp = ld->ld_pend; lp != NULL; lp = lp->lp_next )
1326 for( lp = ld->ld_pend; lp != NULL; lp = lp->lp_next )
1343 LDAP_MUTEX_UNLOCK( ld, LDAP_PEND_LOCK );
1344 LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL,
1350 link_pend( ld, newlp );
1362 LDAP_SEMA_POST( ld, lp );
1365 LDAP_MUTEX_UNLOCK( ld, LDAP_PEND_LOCK );
1370 link_pend( LDAP *ld, LDAPPend *lp )
1372 if (( lp->lp_next = ld->ld_pend ) != NULL )
1376 ld->ld_pend = lp;
1382 unlink_pend( LDAP *ld, LDAPPend *lp )
1385 ld->ld_pend = lp->lp_next;
1396 unlink_msg( LDAP *ld, int msgid, int all )
1402 LDAP_MUTEX_LOCK( ld, LDAP_RESP_LOCK );
1403 for ( lm = ld->ld_responses; lm != NULL; lm = nextlm )
1435 ld->ld_responses = lm->lm_next;
1443 ld->ld_responses = lm->lm_chain;
1444 ld->ld_responses->lm_next = lm->lm_next;
1456 ld->ld_responses = lm->lm_next;
1470 LDAP_MUTEX_UNLOCK( ld, LDAP_RESP_LOCK );