Example #1
0
 private void HandleNextRequest()
 {
     try
     {
         m_request = m_requestqueue.Dequeue();
         if (m_request.command != null)
         {
             m_connection.WriteLine("REQUEST " + m_request.command);
         }
         else
         {
             m_connection.WriteLine("REQUEST");
         }
         byte[] requestcontent = Serializer.getRequestContent(m_request.doctype, m_request.root, m_request.answertype, m_request.content);
         m_connection.WriteContent(requestcontent);
         m_answerbuf = null;
         m_state     = State.WaitAnswer;
     }
     catch (InvalidOperationException)
     {
         //... no more requests in the queue
         m_state     = State.Idle;
         m_request   = null;
         m_answerbuf = null;
     }
 }
Example #2
0
        /* Change the password */
        private bool DoChangePassword( string oldpassword, string newpassword)
        {
            m_connection.WriteLine("CAPABILITIES");
            byte[] fln = m_connection.ReadLine();
            if (fln == null)
            {
                SetState(State.Terminated, "server closed connection");
                return false;
            }
            Console.WriteLine( "CAPABILITIES {0}", Encoding.UTF8.GetString(fln));

            // 1. The client asks to open the password change dialog:
		    m_connection.WriteLine( "PASSWD");
		    // 2. The server accepts or not:
            byte[] ln = m_connection.ReadLine();
            if (ln == null)
            {
                SetState(State.Terminated, "server closed connection");
                return false;
            }
            if (Protocol.IsCommand("ERR", ln))
            {
                SetState(State.Terminated, "password change refused: " + Protocol.CommandArg("ERR", ln));
                return false;
            }
            else if (!Protocol.IsCommand("OK", ln))
            {
                SetState(State.Terminated, "protocol error initiating password change");
                return false;
            }
		    // 3. The server sends a challenge:
            byte[] challenge = m_connection.ReadContent();
            if (challenge == null)
            {
                SetState(State.Terminated, "server closed connection");
                return false;
            }
		    // 4. The client returns a message with the password 
		    //	pair (old, new) encrypted with the challenge:
		    m_connection.WriteContent(
                Encoding.ASCII.GetBytes( 
                    PasswordChange.Message( oldpassword, Encoding.ASCII.GetString(challenge), newpassword)));

		    // 5. The server accepts the password change or not:
            ln = m_connection.ReadLine();
            if (ln == null)
            {
                SetState(State.Terminated, "server closed connection");
                return false;
            }
            if (Protocol.IsCommand("OK", ln))
            {
                return true;
            }
            else if (Protocol.IsCommand("ERR", ln))
            {
                SetState(State.Terminated, "password change error: " + Protocol.CommandArg("ERR", ln));
                return false;
            }
            else
            {
                SetState(State.Terminated, "protocol error in password change");
                return false;
            }
        }