]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/result.c
LDAP C-API changes
[openldap] / libraries / libldap / result.c
index 1fc61004a23346e7c2d8fc8f60edf80830829813..a552c3f5435e40c6a1a4c8c9c46a722f1fe84e62 100644 (file)
@@ -27,16 +27,16 @@ static int ldap_abandoned LDAP_P(( LDAP *ld, int msgid ));
 static int ldap_mark_abandoned LDAP_P(( LDAP *ld, int msgid ));
 static int wait4msg LDAP_P(( LDAP *ld, int msgid, int all, struct timeval *timeout,
        LDAPMessage **result ));
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
 static int read1msg LDAP_P(( LDAP *ld, int msgid, int all, Sockbuf *sb, LDAPConn *lc,
        LDAPMessage **result ));
-static int build_result_ber LDAP_P(( LDAP *ld, BerElement *ber, LDAPRequest *lr ));
+static unsigned long build_result_ber LDAP_P(( LDAP *ld, BerElement *ber, LDAPRequest *lr ));
 static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ));
-#else /* LDAP_REFERRALS */
+#else /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 static int read1msg LDAP_P(( LDAP *ld, int msgid, int all, Sockbuf *sb,
        LDAPMessage **result ));
-#endif /* LDAP_REFERRALS */
-#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_REFERRALS )
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
+#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS )
 static int ldap_select1 LDAP_P(( LDAP *ld, struct timeval *timeout ));
 #endif
 
@@ -139,9 +139,9 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
        struct timeval  tv, *tvp;
        time_t          start_time = 0;
        time_t          tmp_time;
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
        LDAPConn        *lc, *nextlc;
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
 #ifdef LDAP_DEBUG
        if ( timeout == NULL ) {
@@ -149,7 +149,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                    0, 0, 0 );
        } else {
                Debug( LDAP_DEBUG_TRACE, "wait4msg (timeout %ld sec, %ld usec)\n",
-                   timeout->tv_sec, timeout->tv_usec, 0 );
+                      (long) timeout->tv_sec, (long) timeout->tv_usec, 0 );
        }
 #endif /* LDAP_DEBUG */
 
@@ -163,13 +163,15 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                    
        rc = -2;
        while ( rc == -2 ) {
-#ifndef LDAP_REFERRALS
+#ifndef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                /* hack attack */
                if ( ld->ld_sb.sb_ber.ber_ptr >= ld->ld_sb.sb_ber.ber_end ) {
                        rc = ldap_select1( ld, tvp );
 
-                       if ( rc == 0 || ( rc == -1 && (( ld->ld_options &
-                           LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) {
+                       if ( rc == 0 || ( rc == -1 && (
+                               ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+                                       == LDAP_OPT_OFF )
+                           || errno != EINTR ))) {
                                ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
                                    LDAP_TIMEOUT);
                                return( rc );
@@ -181,7 +183,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                } else {
                        rc = read1msg( ld, msgid, all, &ld->ld_sb, result );
                }
-#else /* !LDAP_REFERRALS */
+#else /* !LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #ifdef LDAP_DEBUG
                if ( ldap_debug & LDAP_DEBUG_TRACE ) {
                        ldap_dump_connection( ld, ld->ld_conns, 1 );
@@ -209,8 +211,11 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                        }
 #endif
 
-                       if ( rc == 0 || ( rc == -1 && (( ld->ld_options &
-                           LDAP_OPT_RESTART ) == 0 || errno != EINTR ))) {
+                       if ( rc == 0 || ( rc == -1 && (
+                               ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+                                       == LDAP_OPT_OFF )
+                               || errno != EINTR )))
+                       {
                                ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
                                    LDAP_TIMEOUT);
                                return( rc );
@@ -233,7 +238,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                                }
                        }
                }
-#endif /* !LDAP_REFERRALS */
+#endif /* !LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
                if ( rc == -2 && tvp != NULL ) {
                        tmp_time = time( NULL );
@@ -244,7 +249,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                        }
 
                        Debug( LDAP_DEBUG_TRACE, "wait4msg:  %ld secs to go\n",
-                               tv.tv_sec, 0, 0 );
+                              (long) tv.tv_sec, 0, 0 );
                        start_time = tmp_time;
                }
        }
@@ -255,9 +260,9 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
 
 static int
 read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
     LDAPConn *lc,
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
     LDAPMessage **result )
 {
        BerElement      ber;
@@ -265,16 +270,16 @@ read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
        long            id;
        unsigned long   tag, len;
        int             foundit = 0;
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
        LDAPRequest     *lr;
        BerElement      tmpber;
        int             rc, refer_cnt, hadref, simple_request;
        unsigned long   lderr;
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
        Debug( LDAP_DEBUG_TRACE, "read1msg\n", 0, 0, 0 );
 
-       ber_init( &ber, 0 );
+       ber_init_w_nullc( &ber, 0 );
        ldap_set_ber_options( ld, &ber );
 
        /* get the next message */
@@ -297,7 +302,7 @@ read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
                return( -2 );   /* continue looking */
        }
 
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
        if (( lr = ldap_find_request_by_msgid( ld, id )) == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                    "no request for response with msgid %ld (tossing)\n",
@@ -309,7 +314,7 @@ read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
            ( tag == LDAP_RES_SEARCH_ENTRY ) ? "entry" : "result", id,
            lr->lr_origid );
        id = lr->lr_origid;
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
        /* the message type */
        if ( (tag = ber_peek_tag( &ber, &len )) == LBER_ERROR ) {
@@ -317,7 +322,7 @@ read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
                return( -1 );
        }
 
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
        refer_cnt = 0;
        hadref = simple_request = 0;
        rc = -2;        /* default is to keep looking (no response found) */
@@ -325,8 +330,10 @@ read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
 
        if ( tag != LDAP_RES_SEARCH_ENTRY ) {
                if ( ld->ld_version >= LDAP_VERSION2 &&
-                           ( lr->lr_parent != NULL ||
-                           ( ld->ld_options & LDAP_OPT_REFERRALS ) != 0 )) {
+                       ( lr->lr_parent != NULL ||
+                       ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
+                               != LDAP_OPT_OFF ) ) )
+               {
                        tmpber = ber;   /* struct copy */
                        if ( ber_scanf( &tmpber, "{iaa}", &lderr,
                            &lr->lr_res_matched, &lr->lr_res_error )
@@ -417,7 +424,7 @@ lr->lr_res_matched ? lr->lr_res_matched : "" );
                return( rc );
        }
 
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
        /* make a new ldap message */
        if ( (new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) ))
            == NULL ) {
@@ -509,19 +516,19 @@ lr->lr_res_matched ? lr->lr_res_matched : "" );
 }
 
 
-#ifdef LDAP_REFERRALS
-static int
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
+static unsigned long
 build_result_ber( LDAP *ld, BerElement *ber, LDAPRequest *lr )
 {
        unsigned long   len;
        long            along;
 
-       ber_init( ber, 0 );
+       ber_init_w_nullc( ber, 0 );
        ldap_set_ber_options( ld, ber );
        if ( ber_printf( ber, "{it{ess}}", lr->lr_msgid,
            (long)lr->lr_res_msgtype, lr->lr_res_errno,
            lr->lr_res_matched ? lr->lr_res_matched : "",
-           lr->lr_res_error ? lr->lr_res_error : "" ) == LBER_ERROR ) {
+           lr->lr_res_error ? lr->lr_res_error : "" ) == -1 ) {
                return( LBER_ERROR );
        }
 
@@ -574,11 +581,11 @@ merge_error_info( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr )
            parentr->lr_res_error : "", parentr->lr_res_matched ?
            parentr->lr_res_matched : "" );
 }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 
 
 
-#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_REFERRALS )
+#if defined( LDAP_CONNECTIONLESS ) || !defined( LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS )
 
 static int
 ldap_select1( LDAP *ld, struct timeval *timeout )
@@ -607,7 +614,20 @@ ldap_select1( LDAP *ld, struct timeval *timeout )
        return( select( tblsize, &readfds, 0, 0, timeout ) );
 }
 
-#endif /* !LDAP_REFERRALS */
+#endif /* !LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
+
+
+int
+ldap_msgtype( LDAPMessage *lm )
+{
+       return( lm ? lm->lm_msgtype : -1 );
+}
+
+int
+ldap_msgid( LDAPMessage *lm )
+{
+       return( lm ? lm->lm_msgid : -1 );
+}
 
 
 int