예제 #1
0
        void identHTTP()
        {
            int    place;
            string possibleName = readFromPosToChar(analyse, 6, '\r', out place);

            if (possibleName.Contains(" HTTP/1"))
            {
                //then its 1 or 1.1
                rData.name = readFromPosToChar(analyse, 6, ' ', out place);
                string http = readFromPosToChar(analyse, place, '\r', out place);
                if (http == " HTTP/1.0")
                {
                    Protocol = pFlags.h0; //0.9?
                }
                else if (http == " HTTP/1.1")
                {
                    Protocol = pFlags.h1; //0.9?
                }
            }
            else
            {
                Protocol   = pFlags.h9; //0.9?
                rData.name = possibleName;
            }
        }
예제 #2
0
 public void resetCachedData()
 {
     initialised    = false;
     analyse        = "";
     Protocol       = pFlags.whois;
     rData.location = "";
     rData.name     = "";
     rData.nameOnly = false;
     error          = false;
 }
예제 #3
0
        public pFlags Protocol = pFlags.whois; //set default protocol

        public ProtocolParsing(string[] args)
        {
            bool pF = false, hF = false;                       //Port Flag (changed), Host Flag (changed)
            bool skipNext = false;                             //skip next data item (as it belongs to the last flag)

            List <string> RemainingData = new List <string>(); //Data that's left once flags are removed.

            foreach (string arg in args)
            {
                if ((arg == "" || arg == " " || arg == "\0") && (RemainingData.Count == 1 || RemainingData.Count == 2))
                {
                    System.Environment.Exit(1);
                }
                if (skipNext != true)
                {
                    switch (arg)
                    {
                    case "-help":
                        help = true;
                        break;

                    case "-h9":
                        Protocol = pFlags.h9;
                        break;

                    case "-h0":
                        Protocol = pFlags.h0;
                        break;

                    case "-h1":
                        Protocol = pFlags.h1;
                        break;

                    case "-h":
                        skipNext = true;
                        hF       = true;
                        break;

                    case "-p":
                        skipNext = true;
                        pF       = true;
                        break;

                    default:
                        RemainingData.Add(arg);
                        break;
                    }
                }
                else
                {
                    if (hF == true) //Set new host.
                    {
                        NetInterface.host = arg;
                        hF = false;
                    }
                    if (pF == true) //Set new port
                    {
                        int newPort;
                        NetInterface.port = int.TryParse(arg, out newPort) ? newPort : 43;
                        pF = false;
                    }
                    skipNext = false;
                }
            }
            rData.nameOnly = true;
            if (RemainingData.Count != 0 && help == false)
            {
                rData.name = RemainingData[0];
                if (RemainingData.Count > 1)
                {
                    rData.location = RemainingData[1];
                    rData.nameOnly = false;
                }
            }
            else
            {
                help = true;
            }
            if (help == true && RemainingData.Count == 0)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("(c)AndyWM, 2015. ACW University of Hull - 1415\n\n");
                Console.Write("--------------------------------------------\n");
                Console.Write("location is a location look_up client\n\n");
                Console.Write("USAGE: \n");
                Console.Write("  1. location <name> [location] [-h9] [-h0] [-h1] [-h host] [-p port]\n");
                Console.Write("  2. location <-help>\n\n");
                Console.Write("  <name> : look up name on server");
                Console.Write("  [location] : updates <name>'s location\n");
                Console.Write("  [-h9] : send via HTTP0.9 Protocol\n");
                Console.Write("  [-h0] : send via HTTP1.0 Protocol\n");
                Console.Write("  [-h1] : send via HTTP1.0 Protocol\n");
                Console.Write("  [-h host] : send to host\n");
                Console.Write("  [-p port] : send to port at host\n");
                Console.Write("  <-help> : displays help\n");
                Console.Write("  If multiple https are set, the last set will be used\n");
                Console.Write("  If set, [location] MUST follow <name>\n");
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
예제 #4
0
        public void formatForRead()
        {
            int lastPos;

            string conditional = analyse;

            if (conditional.Length >= 3)
            {
                conditional = analyse.Substring(0, 5);
            }
            else
            {
                conditional = "";
            }
            if (conditional == "GET /" || conditional == "PUT /")
            {                                          //pad to make all modes the same length.
                analyse     = " " + analyse;
                conditional = analyse.Substring(0, 5); // GET /
            }
            if (analyse.Length > 6)
            {
                conditional = analyse.Substring(0, 6);

                if (conditional == " GET /")
                {//don't parse for location and ID HTTP version.
                    rData.nameOnly = true;
                    identHTTP();
                }

                if (conditional == "POST /" || conditional == " PUT /")
                {//prase for location and ID HTTP version.
                    rData.nameOnly = false;
                    identHTTP();
                    rData.location = readFromPosToChar(analyse, analyse.Length - 3, '\n', out lastPos, true); //ignore terminating \r\n. Grab the Sequence between that and the last \n.
                }
            }

            if (Protocol != pFlags.h0 && Protocol != pFlags.h1 && Protocol != pFlags.h9)
            {
                string what = analyse.Substring(analyse.Length - 2, 2);
                if (analyse.Substring(analyse.Length - 2, 2) == "\r\n")
                {
                    Protocol = pFlags.whois;
                    if (readFromPosToChar(analyse, 0, ' ', out lastPos) == "")
                    {
                        rData.nameOnly = true;
                    }

                    if (rData.nameOnly)
                    {
                        rData.name = analyse.Substring(0, analyse.Length - 2);
                    }
                    else
                    {
                        //set request info.
                        rData.name     = readFromPosToChar(analyse, 0, ' ', out lastPos);
                        rData.location = readFromPosToChar(analyse, lastPos + 1, '\r', out lastPos);
                    }
                }
            }
        }