Ejemplo n.º 1
0
        /// <summary>
        /// Dispatches the command to the client control port and produces a <typeparamref name="T" /> response result.
        /// </summary>
        /// <param name="connection">The control connection where the command should be dispatched.</param>
        /// <returns>
        /// A <typeparamref name="T" /> object instance containing the response data.
        /// </returns>
        protected override GetConfResponse Dispatch(Connection connection)
        {
            StringBuilder builder = new StringBuilder("getconf");

            foreach (string name in configurations)
            {
                builder.Append(' ');
                builder.Append(name);
            }

            if (connection.Write(builder.ToString()))
            {
                ConnectionResponse response = connection.Read();

                if (!response.Success)
                {
                    return(new GetConfResponse(false, null));
                }

                ResponsePairs values = new ResponsePairs(response.Responses.Count);

                foreach (string value in response.Responses)
                {
                    string[] parts = value.Split(new[] { '=' }, 2);
                    string   name  = parts[0].Trim();

                    if (parts.Length != 2)
                    {
                        values[name] = null;
                    }
                    else
                    {
                        values[name] = parts[1].Trim();
                    }
                }

                return(new GetConfResponse(true, values));
            }

            return(new GetConfResponse(false, null));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetConfResponse"/> class.
 /// </summary>
 /// <param name="success">A value indicating whether the command was received and processed successfully.</param>
 /// <param name="values">The values received from the tor control connection.</param>
 public GetConfResponse(bool success, ResponsePairs values) : base(success)
 {
     this.values = values;
 }