Esempio n. 1
0
        //<summary> Read a command string and transform it into a series of
        //Tasks to be run by the TorInstances. </summary>
        //<param name="commandString"> The string which indicates which tasks to
        //execute on what host, passed from the client. </param>
        public static Task[] parseCommandString(string commandString)
        {
            Task[] retTasks;
            string taskList   = "";
            String targetHost = "";

            string[] taskStrs;
            int      i;

            for (i = 0; i < commandString.Length && commandString[i] != ':'; i++)
            {
                taskList += commandString[i];
            }

            targetHost = (commandString.Substring(i + 1, commandString.Length - (i + 1))).Trim();

            if (Uri.CheckHostName(targetHost) == UriHostNameType.Unknown)
            {
                throw new ArgumentException("Invalid target hostname: '" + targetHost + "' in " + commandString);
            }

            taskStrs = taskList.Split(',');
            if (taskStrs.Length < 1)
            {
                throw new ArgumentException("Invalid task list: '" + taskList + "' -- no tasks parsed in" + commandString);
            }
            else
            {
                retTasks = new Task[taskStrs.Length];
            }

            for (int l = 0; l < taskStrs.Length; l++)
            {
                switch (taskStrs[l].ToLower())
                {
                case "dns":
                    retTasks[l] = new DnsTask(new DnsTransaction.QuestionRecord(targetHost, DnsTransaction.QTYPE.A, DnsTransaction.RCLASS.IN));
                    break;

                case "whois":
                    retTasks[l] = new WhoisTask(targetHost);
                    break;

                default:
                    throw new ArgumentException("Unknown task type: '" + taskStrs[l].ToLower() + "' in " + commandString);
                }
            }
            return(retTasks);
        }
Esempio n. 2
0
        //<summary> Read a command string and transform it into a series of
        //Tasks to be run by the TorInstances. </summary>
        //<param name="commandString"> The string which indicates which tasks to
        //execute on what host, passed from the client. </param>
        public static Task[] parseCommandString(string commandString)
        {
            Task[] retTasks;
            string taskList = "";
            String targetHost = "";
            string[] taskStrs;
            int i;

            for(i = 0; i < commandString.Length && commandString[i] != ':'; i++){
                taskList += commandString[i];
            }

            targetHost = (commandString.Substring(i+1, commandString.Length-(i+1))).Trim();

            if (Uri.CheckHostName(targetHost) == UriHostNameType.Unknown){
                throw new ArgumentException("Invalid target hostname: '"+targetHost+"' in "+commandString);
            }

            taskStrs = taskList.Split(',');
            if (taskStrs.Length < 1){
                throw new ArgumentException("Invalid task list: '"+taskList+"' -- no tasks parsed in"+commandString);
            }
            else {
                retTasks = new Task[taskStrs.Length];
            }

            for(int l = 0; l < taskStrs.Length; l++){
                switch(taskStrs[l].ToLower()){
                    case "dns":
                        retTasks[l] = new DnsTask(new DnsTransaction.QuestionRecord(targetHost, DnsTransaction.QTYPE.A, DnsTransaction.RCLASS.IN));
                        break;
                    case "whois":
                        retTasks[l] = new WhoisTask(targetHost);
                        break;
                    default:
                        throw new ArgumentException("Unknown task type: '"+taskStrs[l].ToLower()+"' in "+commandString);
                }
            }
            return retTasks;
        }