Ejemplo n.º 1
0
 public void ProcessFile()
 {
     /** only input files are cyclops format right now. **/
     if (Filename.IndexOf("yclops") >= 0)
     {
         ProcessCyclopsFile();
     }
     else if (Filename.EndsWith(".txt"))
     {
         ProcessCadiaFile();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the HTTP request
        /// </summary>
        /// <param name="line">HTTP request string</param>
        private void ParseRequestLine(string line)
        {
            XmlConfigurator.Configure();
            if (String.IsNullOrWhiteSpace(line))
            {
                throw new ArgumentException();
            }
            string[] requestWords = line.Split(' ');
            if (requestWords.Length != 3)
            {
                throw new ArgumentException();
            }

            Methods method;

            if (!Methods.TryParse(requestWords[0], out method))
            {
                errorLog.Error("Only GET requests are supported");
                throw new MethodException("Only GET requests are supported", "Method");
            }
            Method = method;

            Filename = requestWords[1];
            Filename = Uri.UnescapeDataString(Filename);
            Filename = Filename.Replace('+', ' ');

            int position = Filename.IndexOf('?');

            if (position >= 0)
            {
                string query = Filename.Substring(position + 1);
                IDictionary <string, string> dict = ReadingRequest.ParseQuery(query);
                if (dict != null)
                {
                    GetArguments = dict;
                }
                Filename = Filename.Substring(0, position);
            }

            if (Filename.Equals("/"))
            {
                Filename = INDEX_FILENAME;
            }

            Protocol = requestWords[2];

            string[] protocolWords = Protocol.Split('/');
            if (protocolWords.Length != 2)
            {
                errorLog.Error("Invalid protocol format");
                throw new ProtocolException("Invalid protocol format", "protocolWords");
            }
            if (!protocolWords[0].Equals("HTTP"))
            {
                errorLog.Error("Only HTTP is supported");
                throw new ProtocolException("Only HTTP is supported", "protocolWords[0]");
            }

            try
            {
                decimal protocolVersion = decimal.Parse(protocolWords[1]);
                if (protocolVersion < 1)
                {
                    errorLog.Error("Invalid HTTP version");
                    throw new ProtocolException("Invalid HTTP version", "protocolVersion");
                }
            }
            catch (FormatException)
            {
                errorLog.Error("Invalid HTTP version format");
                throw new ProtocolException("Invalid HTTP version format", "protocolVersion");
            }
        }