- assert( c != NULL );
- assert( c->c_struct_state != SLAP_C_USED );
- assert( c->c_conn_state == SLAP_C_INVALID );
-
- if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
- c->c_dn = NULL;
- c->c_cdn = NULL;
- c->c_client_name = NULL;
- c->c_client_addr = NULL;
- c->c_ops = NULL;
- c->c_pending_ops = NULL;
- c->c_authmech = NULL;
- c->c_authstate = NULL;
-
- c->c_sb = ber_sockbuf_alloc( );
-
- /* should check status of thread calls */
- ldap_pvt_thread_mutex_init( &c->c_mutex );
- ldap_pvt_thread_mutex_init( &c->c_write_mutex );
- ldap_pvt_thread_cond_init( &c->c_write_cv );
-
- c->c_struct_state = SLAP_C_UNUSED;
- }
-
- ldap_pvt_thread_mutex_lock( &c->c_mutex );
-
- assert( c->c_struct_state == SLAP_C_UNUSED );
- assert( c->c_dn == NULL );
- assert( c->c_cdn == NULL );
- assert( c->c_client_name == NULL );
- assert( c->c_client_addr == NULL );
- assert( c->c_ops == NULL );
- assert( c->c_pending_ops == NULL );
- assert( c->c_authmech == NULL );
- assert( c->c_authstate == NULL );
-
- c->c_client_name = ch_strdup( name == NULL ? "" : name );
- c->c_client_addr = ch_strdup( addr );
-
- c->c_n_ops_received = 0;
- c->c_n_ops_executing = 0;
- c->c_n_ops_pending = 0;
- c->c_n_ops_completed = 0;
+ c->c_authmech.bv_val = NULL;
+ c->c_authmech.bv_len = 0;
+ c->c_dn.bv_val = NULL;
+ c->c_dn.bv_len = 0;
+ c->c_ndn.bv_val = NULL;
+ c->c_ndn.bv_len = 0;
+
+ c->c_listener = NULL;
+ c->c_peer_domain.bv_val = NULL;
+ c->c_peer_domain.bv_len = 0;
+ c->c_peer_name.bv_val = NULL;
+ c->c_peer_name.bv_len = 0;
+
+ LDAP_STAILQ_INIT(&c->c_ops);
+ LDAP_STAILQ_INIT(&c->c_pending_ops);
+
+ c->c_sasl_bind_mech.bv_val = NULL;
+ c->c_sasl_bind_mech.bv_len = 0;
+ c->c_sasl_done = 0;
+ c->c_sasl_authctx = NULL;
+ c->c_sasl_sockctx = NULL;
+ c->c_sasl_extra = NULL;
+ c->c_sasl_bindop = NULL;
+
+ c->c_sb = ber_sockbuf_alloc( );
+
+ {
+ ber_len_t max = sockbuf_max_incoming;
+ ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
+ }
+
+ c->c_currentber = NULL;
+
+ /* should check status of thread calls */
+ ldap_pvt_thread_mutex_init( &c->c_mutex );
+ ldap_pvt_thread_mutex_init( &c->c_write_mutex );
+ ldap_pvt_thread_cond_init( &c->c_write_cv );
+
+#ifdef LDAP_SLAPI
+ if ( slapi_plugins_used ) {
+ slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, c );
+ }
+#endif
+
+ c->c_struct_state = SLAP_C_UNUSED;
+ }
+
+ ldap_pvt_thread_mutex_lock( &c->c_mutex );
+
+ assert( c->c_struct_state == SLAP_C_UNUSED );
+ assert( c->c_authmech.bv_val == NULL );
+ assert( c->c_dn.bv_val == NULL );
+ assert( c->c_ndn.bv_val == NULL );
+ assert( c->c_listener == NULL );
+ assert( c->c_peer_domain.bv_val == NULL );
+ assert( c->c_peer_name.bv_val == NULL );
+ assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
+ assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
+ assert( c->c_sasl_bind_mech.bv_val == NULL );
+ assert( c->c_sasl_done == 0 );
+ assert( c->c_sasl_authctx == NULL );
+ assert( c->c_sasl_sockctx == NULL );
+ assert( c->c_sasl_extra == NULL );
+ assert( c->c_sasl_bindop == NULL );
+ assert( c->c_currentber == NULL );
+ assert( c->c_writewaiter == 0);
+
+ c->c_listener = listener;
+
+ if ( flags == CONN_IS_CLIENT ) {
+ c->c_conn_state = SLAP_C_CLIENT;
+ c->c_struct_state = SLAP_C_USED;
+ ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
+ ldap_pvt_thread_mutex_unlock( &c->c_mutex );
+ ldap_pvt_thread_mutex_unlock( &connections_mutex );
+
+ return 0;
+ }
+
+ ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
+ ber_str2bv( peername, 0, 1, &c->c_peer_name );
+
+ c->c_n_ops_received = 0;
+ c->c_n_ops_executing = 0;
+ c->c_n_ops_pending = 0;
+ c->c_n_ops_completed = 0;