A message received from an LdapServer in response to an asynchronous request.
Inheritance: LdapMessage
Example #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, null);
            }
            return((LdapEntry)element);
        }
Example #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(int?msgid)
        {
            object      resp;
            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 ldapResponse)
            {
                return(ldapResponse);
            }

            // Normal message handling
            var message = (RfcLdapMessage)resp;

            switch (message.Type)
            {
            case LdapMessage.SearchResponse:
                response = new LdapSearchResult(message);
                break;

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

            case LdapMessage.ExtendedResponse:
                response = ExtResponseFactory.ConvertToExtendedResponse(message);
                break;

            case LdapMessage.IntermediateResponse:
                response = IntermediateResponseFactory.ConvertToIntermediateResponse(message);
                break;

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

            return(response);
        }
        /// <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)
        {
            System.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);
        }
Example #4
0
		/// <summary> Check the result code and throw an exception if needed.
		/// 
		/// If referral following is enabled, checks if we need to
		/// follow a referral
		/// 
		/// </summary>
		/// <param name="queue">- the message queue of the current response
		/// 
		/// </param>
		/// <param name="cons">- the constraints that apply to the request
		/// 
		/// </param>
		/// <param name="response">- the LdapResponse to check
		/// </param>
		private void  chkResultCode(LdapMessageQueue queue, LdapConstraints cons, LdapResponse response)
		{
			if ((response.ResultCode == LdapException.REFERRAL) && cons.ReferralFollowing)
			{
				// Perform referral following and return
				System.Collections.ArrayList refConn = null;
				try
				{
					chaseReferral(queue, cons, response, response.Referrals, 0, false, null);
				}
				finally
				{
					releaseReferralConnections(refConn);
				}
			}
			else
			{
				// Throws exception for non success result
				response.chkResultCode();
			}
			return ;
		}
        /// <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)
        {
            System.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;
        }