Пример #1
0
        /// <summary> Returns the next result as an LdapEntry.
        ///
        /// If automatic referral following is disabled or if a referral
        /// was not followed, next() will throw an LdapReferralException
        /// when the referral is received.
        ///
        /// </summary>
        /// <returns> The next search result as an LdapEntry.
        ///
        /// </returns>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>
        /// <exception> LdapReferralException A referral was received and not
        /// followed.
        /// </exception>
        public virtual LdapEntry next()
        {
            if (completed && (entryIndex >= entryCount) && (referenceIndex >= referenceCount))
            {
                throw new ArgumentOutOfRangeException("LdapSearchResults.next() no more results");
            }
            // Check if the enumeration is empty and must be reloaded
            resetVectors();

            object element = null;

            // Check for Search References & deliver to app as they come in
            // We only get here if not following referrals/references
            if (referenceIndex < referenceCount)
            {
                string[] refs             = (string[])(references[referenceIndex++]);
                LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_NOFOLLOW);
                rex.setReferrals(refs);
                throw rex;
            }
            else if (entryIndex < entryCount)
            {
                // Check for Search Entries and the Search Result
                element = entries[entryIndex++];
                if (element is LdapResponse)
                {
                    // Search done w/bad status
                    if (((LdapResponse)element).hasException())
                    {
                        LdapResponse lr = (LdapResponse)element;
                        ReferralInfo ri = lr.ActiveReferral;

                        if (ri != null)
                        {
                            // Error attempting to follow a search continuation reference
                            LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_ERROR, lr.Exception);
                            rex.setReferrals(ri.ReferralList);
                            rex.FailedReferral = ri.ReferralUrl.ToString();
                            throw rex;
                        }
                    }
                    // Throw an exception if not success
                    ((LdapResponse)element).chkResultCode();
                }
                else if (element is LdapException)
                {
                    throw (LdapException)element;
                }
            }
            else
            {
                // If not a Search Entry, Search Result, or search continuation
                // we are very confused.
                // LdapSearchResults.next(): No entry found & request is not complete
                throw new LdapException(ExceptionMessages.REFERRAL_LOCAL, new object[] { "next" }, LdapException.LOCAL_ERROR, (string)null);
            }
            return((LdapEntry)element);
        }
Пример #2
0
        /// <summary> Private implementation of getResponse.
        /// Has an Integer object as a parameter so we can distinguish
        /// the null and the message number case
        /// </summary>
        //		private LdapMessage getResponse(System.Int32 msgid)
        private LdapMessage getResponse(Integer32 msgid)
        {
            object         resp;
            RfcLdapMessage message;
            LdapMessage    response;

            if ((resp = agent.getLdapMessage(msgid)) == null)
            {
                // blocks
                return(null); // no messages from this agent
            }
            // Local error occurred, contains a LocalException
            if (resp is LdapResponse)
            {
                return((LdapMessage)resp);
            }
            // Normal message handling
            message = (RfcLdapMessage)resp;
            switch (message.Type)
            {
            case LdapMessage.SEARCH_RESPONSE:
                response = new LdapSearchResult(message);
                break;

            case LdapMessage.SEARCH_RESULT_REFERENCE:
                response = new LdapSearchResultReference(message);
                break;

            case LdapMessage.EXTENDED_RESPONSE:
                ExtResponseFactory fac = new ExtResponseFactory();
                response = ExtResponseFactory.convertToExtendedResponse(message);
                break;

            case LdapMessage.INTERMEDIATE_RESPONSE:
                response = IntermediateResponseFactory.convertToIntermediateResponse(message);
                break;

            default:
                response = new LdapResponse(message);
                break;
            }
            return(response);
        }