Represents a queue of incoming asynchronous messages from the server. It is the common interface for {@link LdapResponseQueue} and {@link LdapSearchQueue}.
Ejemplo n.º 1
0
 private void cleanup()
 {
     stopTimer(); // Make sure timer stopped
     try
     {
         acceptReplies = false;
         conn?.removeMessage(this);
         // Empty out any accumuluated replies
         if (replies != null)
         {
             while (replies.Count != 0)
             {
                 var temp_object = replies[0];
                 replies.RemoveAt(0);
                 object generatedAux = temp_object;
             }
         }
     }
     catch (Exception ex)
     {
         // nothing
     }
     // Let GC clean up this stuff, leave name in case finalized is called
     conn = null;
     msg  = null;
     // agent = null;  // leave this reference
     queue = null;
     //replies = null; //leave this since we use it as a semaphore
     bindprops = null;
 }
Ejemplo n.º 2
0
		/// <summary> Merges two message queues.  It appends the current and
		/// future contents from another queue to this one.
		/// 
		/// After the operation, queue2.getMessageIDs()
		/// returns an empty array, and its outstanding responses
		/// have been removed and appended to this queue.
		/// 
		/// </summary>
		/// <param name="queue2">   The queue that is merged from.  Following
		/// the merge, this queue object will no
		/// longer receive any data, and calls made
		/// to its methods will fail with a RuntimeException.
		/// The queue can be reactivated by using it in an 
		/// Ldap request, after which it will receive responses
		/// for that request..
		/// </param>
		public virtual void  merge(LdapMessageQueue queue2)
		{
			LdapResponseQueue q = (LdapResponseQueue) queue2;
			agent.merge(q.MessageAgent);
			
			return ;
		}
 private void cleanup()
 {
     stopTimer(); // Make sure timer stopped
     try
     {
         acceptReplies = false;
         if (conn != null)
         {
             conn.removeMessage(this);
         }
         // Empty out any accumuluated replies
         if (replies != null)
         {
             while (!(replies.Count == 0))
             {
                 object temp_object;
                 temp_object = replies[0];
                 replies.RemoveAt(0);
                 var generatedAux = temp_object;
             }
         }
     }
     catch (Exception ex)
     {
         LogManager.GetCurrentClassLogger().Warn("Exception swallowed", ex);
     }
     _stackTraceCleanup = Environment.StackTrace;
     // Let GC clean up this stuff, leave name in case finalized is called
     conn = null;
     msg  = null;
     // agent = null;  // leave this reference
     queue = null;
     //replies = null; //leave this since we use it as a semaphore
     bindprops = null;
 }
Ejemplo n.º 4
0
        /// <summary> Merges two message queues.  It appends the current and
        /// future contents from another queue to this one.
        ///
        /// After the operation, queue2.getMessageIDs()
        /// returns an empty array, and its outstanding responses
        /// have been removed and appended to this queue.
        ///
        /// </summary>
        /// <param name="queue2">   The queue that is merged from.  Following
        /// the merge, this queue object will no
        /// longer receive any data, and calls made
        /// to its methods will fail with a RuntimeException.
        /// The queue can be reactivated by using it in an
        /// Ldap request, after which it will receive responses
        /// for that request..
        /// </param>
        public virtual void  merge(LdapMessageQueue queue2)
        {
            LdapSearchQueue q = (LdapSearchQueue)queue2;

            agent.merge(q.MessageAgent);

            return;
        }
Ejemplo n.º 5
0
        /// <summary> Send a request to the server.  A Message class is created
        /// for the specified request which causes the message to be sent.
        /// The request is added to the list of messages being managed by
        /// this agent.
        ///
        /// </summary>
        /// <param name="conn">the connection that identifies the server.
        ///
        /// </param>
        /// <param name="msg">the LdapMessage to send
        ///
        /// </param>
        /// <param name="timeOut">the interval to wait for the message to complete or
        /// <code>null</code> if infinite.
        /// </param>
        /// <param name="queue">the LdapMessageQueue associated with this request.
        /// </param>
        /* package */
        internal void sendMessage(Connection conn, LdapMessage msg, int timeOut, LdapMessageQueue queue, BindProperties bindProps)
        {
            // creating a messageInfo causes the message to be sent
            // and a timer to be started if needed.
            Message message = new Message(msg, timeOut, conn, this, queue, bindProps);

            messages.Add(message);
            message.sendMessage(); // Now send message to server
        }
Ejemplo n.º 6
0
        private BindProperties bindprops;               // Bind properties if a bind request

        internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue, BindProperties bindprops)
        {
            InitBlock();
            this.msg       = msg;
            this.conn      = conn;
            this.agent     = agent;
            this.queue     = queue;
            this.mslimit   = mslimit;
            msgId          = msg.MessageID;
            this.bindprops = bindprops;
        }
Ejemplo n.º 7
0
        private bool waitForReply_Renamed_Field = true; // true if wait for reply

        #endregion Fields

        #region Constructors

        internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue, BindProperties bindprops)
        {
            InitBlock();
            this.msg = msg;
            this.conn = conn;
            this.agent = agent;
            this.queue = queue;
            this.mslimit = mslimit;
            this.msgId = msg.MessageID;
            this.bindprops = bindprops;
            return ;
        }
        private bool _waitForReplyRenamedField = true; // true if wait for reply

        internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue,
                         BindProperties bindprops)
        {
            _conn = conn ?? throw new ArgumentNullException(nameof(conn));

            _stackTraceCreation = Environment.StackTrace;
            _replies            = new MessageVector(5, 5);
            Request             = msg;
            MessageAgent        = agent;
            _queue     = queue;
            _mslimit   = mslimit;
            MessageId  = msg.MessageId;
            _bindprops = bindprops;
        }
        private BindProperties bindprops;               // Bind properties if a bind request

        internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue,
                         BindProperties bindprops)
        {
            if (conn == null)
            {
                throw new ArgumentNullException(nameof(conn));
            }
            _stackTraceCreation = Environment.StackTrace;
            InitBlock();
            this.msg       = msg;
            this.conn      = conn;
            this.agent     = agent;
            this.queue     = queue;
            this.mslimit   = mslimit;
            msgId          = msg.MessageID;
            this.bindprops = bindprops;
        }
Ejemplo n.º 10
0
		/// <summary> Abandons all outstanding operations managed by the queue.
		/// 
		/// All operations in progress, which are managed by the specified
		/// queue, are abandoned.
		/// 
		/// </summary>
		/// <param name="queue">    The queue returned from an asynchronous request.
		/// All outstanding operations managed by the queue
		/// are abandoned, and the queue is emptied.
		/// 
		/// </param>
		/// <param name="cons">    The contraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual void  Abandon(LdapMessageQueue queue, LdapConstraints cons)
		{
			if (queue != null)
			{
				MessageAgent agent;
				if (queue is LdapSearchQueue)
				{
					agent = queue.MessageAgent;
				}
				else
				{
					agent = queue.MessageAgent;
				}
				int[] msgIds = agent.MessageIDs;
				for (int i = 0; i < msgIds.Length; i++)
				{
					agent.Abandon(msgIds[i], cons);
				}
			}
			return ;
		}
    protected void StartEventPolling(
				 LdapMessageQueue queue,
				 LdapConnection conn,
				 int msgid)
    {
      // validate the argument values
      if ( (queue == null)
	   || (conn == null))
      {
	throw new ArgumentException("No parameter can be Null.");
      }

      if (null == m_objEventsGenerator)
      {
	m_objEventsGenerator =  new EventsGenerator(this, queue, conn, msgid);
	m_objEventsGenerator.SleepTime = sleep_interval;

	m_objEventsGenerator.StartEventPolling();
      }
    } // end of method StartEventPolling
      public EventsGenerator(LdapEventSource objEventSource,
			     LdapMessageQueue queue,
			     LdapConnection conn,
			     int msgid)
      {
	m_objLdapEventSource = objEventSource;
	searchqueue = queue;
	ldapconnection = conn;
	messageid = msgid;
	sleep_time = DEFAULT_SLEEP_TIME;
      } // end of Constructor
Ejemplo n.º 13
0
		/// <summary> Follow referrals if necessary referral following enabled.
		/// This function is called only by synchronous requests.
		/// Search responses come here only if referral following is
		/// enabled and if we are processing a SearchResultReference
		/// or a Response with a status of REFERRAL, i.e. we are
		/// going to follow a referral.
		/// 
		/// This functions recursively follows a referral until a result
		/// is returned or until the hop limit is reached.
		/// 
		/// </summary>
		/// <param name="queue">The LdapResponseQueue for this request
		/// 
		/// </param>
		/// <param name="cons">The constraints that apply to the request
		/// 
		/// </param>
		/// <param name="msg">The referral or search reference response message
		/// 
		/// </param>
		/// <param name="initialReferrals">The referral array returned from the
		/// initial request.
		/// 
		/// </param>
		/// <param name="hopCount">the number of hops already used while
		/// following this referral
		/// 
		/// </param>
		/// <param name="searchReference">true if the message is a search reference
		/// 
		/// </param>
		/// <param name="connectionList">An optional array list used to store
		/// the LdapConnection objects used in following the referral.
		/// 
		/// </param>
		/// <returns> The array list used to store the all LdapConnection objects
		/// used in following the referral.  The list will be empty
		/// if there were none.
		/// 
		/// </returns>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		/* package */
		internal virtual System.Collections.ArrayList chaseReferral(LdapMessageQueue queue, LdapConstraints cons, LdapMessage msg, System.String[] initialReferrals, int hopCount, bool searchReference, System.Collections.ArrayList connectionList)
		{
			System.Collections.ArrayList connList = connectionList;
			LdapConnection rconn = null; // new conn for following referral
			ReferralInfo rinfo = null; // referral info
			LdapMessage origMsg;
			
			// Get a place to store new connections
			if (connList == null)
			{
				connList = new System.Collections.ArrayList(cons.HopLimit);
			}
			// Following referrals or search reference
			System.String[] refs; // referral list
			if (initialReferrals != null)
			{
				// Search continuation reference from a search request
				refs = initialReferrals;
				origMsg = msg.RequestingMessage;
			}
			else
			{
				// Not a search request
				LdapResponse resp = (LdapResponse) queue.getResponse();
				if (resp.ResultCode != LdapException.REFERRAL)
				{
					// Not referral result,throw Exception if nonzero result
					resp.chkResultCode();
					return connList;
				}
				// We have a referral response
				refs = resp.Referrals;
				origMsg = resp.RequestingMessage;
			}
			LdapUrl refUrl; // referral represented as URL
			try
			{
				// increment hop count, check max hops
				if (hopCount++ > cons.HopLimit)
				{
					throw new LdapLocalException("Max hops exceeded", LdapException.REFERRAL_LIMIT_EXCEEDED);
				}
				// Get a connection to follow the referral
				rinfo = getReferralConnection(refs);
				rconn = rinfo.ReferralConnection;
				refUrl = rinfo.ReferralUrl;
				connList.Add(rconn);
				
				
				// rebuild msg into new msg changing msgID,dn,scope,filter
				LdapMessage newMsg = rebuildRequest(origMsg, refUrl, searchReference);
				
				
				// Send new message on new connection
				try
				{
					MessageAgent agent;
					if (queue is LdapResponseQueue)
					{
						agent = queue.MessageAgent;
					}
					else
					{
						agent = queue.MessageAgent;
					}
					agent.sendMessage(rconn.Connection, newMsg, defSearchCons.TimeLimit, queue, null);
				}
				catch (InterThreadException ex)
				{
					// Error ending request to referred server
					LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERRAL_SEND, LdapException.CONNECT_ERROR, null, ex);
					rex.setReferrals(initialReferrals);
					ReferralInfo ref_Renamed = rconn.Connection.ActiveReferral;
					rex.FailedReferral = ref_Renamed.ReferralUrl.ToString();
					throw rex;
				}
				
				if (initialReferrals == null)
				{
					// For operation results, when all responses are complete,
					// the stack unwinds back to the original and returns
					// to the application.
					// An exception is thrown for an error
					connList = chaseReferral(queue, cons, null, null, hopCount, false, connList);
				}
				else
				{
					// For search, just return to LdapSearchResults object
					return connList;
				}
			}
			catch (System.Exception ex)
			{
				
				if (ex is LdapReferralException)
				{
					throw (LdapReferralException) ex;
				}
				else
				{
					
					// Set referral list and failed referral
					LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERRAL_ERROR, ex);
					rex.setReferrals(refs);
					if (rinfo != null)
					{
						rex.FailedReferral = rinfo.ReferralUrl.ToString();
					}
					else
					{
						rex.FailedReferral = refs[refs.Length - 1];
					}
					throw rex;
				}
			}
			return connList;
		}
Ejemplo n.º 14
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 ;
		}
Ejemplo n.º 15
0
		/// <summary> Sends an Ldap request to a directory server.
		/// 
		/// The specified the Ldap request is sent to the directory server
		/// associated with this connection. An Ldap request object is an
		/// {@link LdapMessage} with the operation type set to one of the request
		/// types. You can build a request by using the request classes found in this
		/// package
		/// 
		/// You should note that, since Ldap requests sent to the server
		/// using sendRequest are asynchronous, automatic referral following
		/// does not apply to these requests.
		/// 
		/// </summary>
		/// <param name="request">The Ldap request to send to the directory server.
		/// </param>
		/// <param name="queue">   The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// </param>
		/// <param name="cons">   The constraints that apply to this request
		/// </param>
		/// <exception>     LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// 
		/// </exception>
		/// <seealso cref="LdapMessage.Type">
		/// </seealso>
		/// <seealso cref="RfcLdapMessage.isRequest">
		/// </seealso>
		public virtual LdapMessageQueue SendRequest(LdapMessage request, LdapMessageQueue queue, LdapConstraints cons)
		{
			
			
			if (!request.Request)
			{
				throw new System.SystemException("Object is not a request message");
			}
			
			if (cons == null)
			{
				cons = defSearchCons;
			}
			
			// Get the correct queue for a search request
			MessageAgent agent;
			LdapMessageQueue myqueue = queue;
			if (myqueue == null)
			{
				agent = new MessageAgent();
				if (request.Type == LdapMessage.SEARCH_REQUEST)
				{
					myqueue = new LdapSearchQueue(agent);
				}
				else
				{
					myqueue = new LdapResponseQueue(agent);
				}
			}
			else
			{
				if (request.Type == LdapMessage.SEARCH_REQUEST)
				{
					agent = queue.MessageAgent;
				}
				else
				{
					agent = queue.MessageAgent;
				}
			}
			
			try
			{
				agent.sendMessage(conn, request, cons.TimeLimit, myqueue, null);
			}
			catch (LdapException lex)
			{
				throw lex;
			}
			return myqueue;
		}
Ejemplo n.º 16
0
 private void cleanup()
 {
     stopTimer(); // Make sure timer stopped
     try
     {
         acceptReplies = false;
         if (conn != null)
         {
             conn.removeMessage(this);
         }
         // Empty out any accumuluated replies
         if (replies != null)
         {
             while (!(replies.Count == 0))
             {
                 System.Object temp_object;
                 temp_object = replies[0];
                 replies.RemoveAt(0);
                 System.Object generatedAux = temp_object;
             }
         }
     }
     catch (System.Exception ex)
     {
         // nothing
     }
     // Let GC clean up this stuff, leave name in case finalized is called
     conn = null;
     msg = null;
     // agent = null;  // leave this reference
     queue = null;
     //replies = null; //leave this since we use it as a semaphore
     bindprops = null;
     return ;
 }
Ejemplo n.º 17
0
		/// <summary> Abandons all outstanding operations managed by the queue.
		/// 
		/// All operations in progress, which are managed by the specified queue,
		/// are abandoned.
		/// 
		/// </summary>
		/// <param name="queue">    The queue returned from an asynchronous request.
		/// All outstanding operations managed by the queue
		/// are abandoned, and the queue is emptied.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual void  Abandon(LdapMessageQueue queue)
		{
			Abandon(queue, defSearchCons);
			return ;
		}
Ejemplo n.º 18
0
 /// <summary> Send a request to the server.  A Message class is created
 /// for the specified request which causes the message to be sent.
 /// The request is added to the list of messages being managed by
 /// this agent.
 /// 
 /// </summary>
 /// <param name="conn">the connection that identifies the server.
 /// 
 /// </param>
 /// <param name="msg">the LdapMessage to send
 /// 
 /// </param>
 /// <param name="timeOut">the interval to wait for the message to complete or
 /// <code>null</code> if infinite.
 /// </param>
 /// <param name="queue">the LdapMessageQueue associated with this request.
 /// </param>
 /* package */
 internal void sendMessage(Connection conn, LdapMessage msg, int timeOut, LdapMessageQueue queue, BindProperties bindProps)
 {
     // creating a messageInfo causes the message to be sent
     // and a timer to be started if needed.
     Message message = new Message(msg, timeOut, conn, this, queue, bindProps);
     messages.Add(message);
     message.sendMessage(); // Now send message to server
     return ;
 }
Ejemplo n.º 19
0
		/// <summary> Sends an Ldap request to a directory server.
		/// 
		/// The specified the Ldap request is sent to the directory server
		/// associated with this connection using default constraints. An Ldap
		/// request object is a subclass {@link LdapMessage} with the operation
		/// type set to one of the request types. You can build a request by using
		/// the request classes found in this package
		/// 
		/// You should note that, since Ldap requests sent to the server
		/// using sendRequest are asynchronous, automatic referral following
		/// does not apply to these requests.
		/// 
		/// </summary>
		/// <param name="request">The Ldap request to send to the directory server.
		/// </param>
		/// <param name="queue">   The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// </param>
		/// <exception>     LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// 
		/// </exception>
		/// <seealso cref="LdapMessage.Type">
		/// </seealso>
		/// <seealso cref="RfcLdapMessage.isRequest">
		/// </seealso>
		public virtual LdapMessageQueue SendRequest(LdapMessage request, LdapMessageQueue queue)
		{
			return SendRequest(request, queue, null);
		}
Ejemplo n.º 20
0
        /// <summary> Merges two message queues.  It appends the current and
        /// future contents from another queue to this one.
        ///
        /// After the operation, queue2.getMessageIDs()
        /// returns an empty array, and its outstanding responses
        /// have been removed and appended to this queue.
        ///
        /// </summary>
        /// <param name="queue2">   The queue that is merged from.  Following
        /// the merge, this queue object will no
        /// longer receive any data, and calls made
        /// to its methods will fail with a RuntimeException.
        /// The queue can be reactivated by using it in an
        /// Ldap request, after which it will receive responses
        /// for that request..
        /// </param>
        public virtual void merge(LdapMessageQueue queue2)
        {
            LdapResponseQueue q = (LdapResponseQueue)queue2;

            agent.merge(q.MessageAgent);
        }